5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
26 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 # Use is subject to license terms.
29 # ident "@(#)zvol_common.kshlib 1.6 09/06/22 SMI"
32 . $STF_SUITE/include/libtest.kshlib
35 # Create a simple zvol volume
37 # Where disk_device: is the name of the disk to be used
38 # volume_size: is the size of the volume, e.g. 2G
40 function default_zvol_setup # disk_device volume_size
47 create_pool $TESTPOOL "$disk"
49 log_must $ZFS create -V $size $TESTPOOL/$TESTVOL
51 if [[ -n $DUMPADM ]]; then
52 if is_dumpswap_supported $TESTPOOL ; then
53 set_dumpsize $TESTPOOL/$TESTVOL
59 # Destroy the default zvol which was setup using
60 # default_zvol_setup().
62 function default_zvol_cleanup
64 if datasetexists $TESTPOOL/$TESTVOL ; then
65 log_must $ZFS destroy $TESTPOOL/$TESTVOL
68 destroy_pool $TESTPOOL
72 # Check if the given pool support "Swap and crash dumps"
74 function is_dumpswap_supported #pool
78 if [[ -z $pool ]] ; then
79 log_fail "No pool given."
82 typeset -i SPA_VER_DUMPSWAP=10
83 typeset -i vp=$(get_pool_prop version $pool)
85 if (( vp >= SPA_VER_DUMPSWAP )) ; then
92 function get_dumpdevice
94 typeset ret=$($DUMPADM | $GREP "Dump device:" | $AWK '{print $3}')
102 if [[ -z $volume ]] ; then
103 log_note "No volume specified."
107 log_must $ZFS set volsize=64m $volume
109 output=$($DUMPADM -d /dev/zvol/$volume 2>&1 | \
110 $TAIL -1 | $AWK '{print $3}')
112 if [[ -n $output ]]; then
113 (( output = output / 1024 / 1024 ))
114 (( output = output + output / 5 ))
115 log_must $ZFS set volsize=${output}m $volume
120 function safe_dumpadm
124 if [[ -z $device || $device == "none" ]] ; then
125 log_note "No dump device volume specified."
128 if [[ $device == "/dev/zvol/"* ]] ; then
129 typeset volume=${device#/dev/zvol/}
131 log_must $DUMPADM -d $device
134 if ! is_swap_inuse $device ; then
135 log_must $SWAP -a $device
137 log_must $DUMPADM -d swap
141 function is_zvol_dumpified
145 if [[ -z $volume ]] ; then
146 log_note "No volume specified."
150 $ZDB -dddd $volume 2 | $GREP "dumpsize" > /dev/null 2>&1
154 function is_swap_inuse
158 if [[ -z $device ]] ; then
159 log_note "No device specified."
163 $SWAP -l | $GREP -w $device > /dev/null 2>&1