Print this page
12181 zvol swap tests should avoid grep -w


  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  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]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  30 # Copyright 2016 Nexenta Systems, Inc.

  31 #
  32 
  33 . $STF_SUITE/include/libtest.shlib
  34 . $STF_SUITE/tests/functional/zvol/zvol_common.shlib
  35 
  36 #
  37 # DESCRIPTION:
  38 # Verify the ability to take snapshots of zvols used as dump or swap.
  39 #
  40 # STRATEGY:
  41 # 1. Create a ZFS volume
  42 # 2. Set the volume as dump or swap
  43 # 3. Verify creating a snapshot of the zvol succeeds.
  44 #
  45 
  46 verify_runnable "global"
  47 
  48 volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL)
  49 
  50 function cleanup
  51 {
  52         typeset dumpdev=$(get_dumpdevice)
  53         if [[ $dumpdev != $savedumpdev ]] ; then
  54                 safe_dumpadm $savedumpdev
  55         fi
  56 
  57         swap -l | grep -w $voldev > /dev/null 2>&1

  58         if (( $? == 0 ));  then
  59                 log_must swap -d $voldev
  60         fi
  61 
  62         typeset snap
  63         for snap in snap0 snap1 ; do
  64                 if datasetexists $TESTPOOL/$TESTVOL@$snap ; then
  65                         log_must zfs destroy $TESTPOOL/$TESTVOL@$snap
  66                 fi
  67         done
  68         zfs set volsize=$volsize $TESTPOOL/$TESTVOL
  69 }
  70 
  71 function verify_snapshot
  72 {
  73         typeset volume=$1
  74 
  75         log_must zfs snapshot $volume@snap0
  76         log_must zfs snapshot $volume@snap1
  77         log_must datasetexists $volume@snap0 $volume@snap1




  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  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]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  30 # Copyright 2016 Nexenta Systems, Inc.
  31 # Copyright 2020 Joyent, Inc.
  32 #
  33 
  34 . $STF_SUITE/include/libtest.shlib
  35 . $STF_SUITE/tests/functional/zvol/zvol_common.shlib
  36 
  37 #
  38 # DESCRIPTION:
  39 # Verify the ability to take snapshots of zvols used as dump or swap.
  40 #
  41 # STRATEGY:
  42 # 1. Create a ZFS volume
  43 # 2. Set the volume as dump or swap
  44 # 3. Verify creating a snapshot of the zvol succeeds.
  45 #
  46 
  47 verify_runnable "global"
  48 
  49 volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL)
  50 
  51 function cleanup
  52 {
  53         typeset dumpdev=$(get_dumpdevice)
  54         if [[ $dumpdev != $savedumpdev ]] ; then
  55                 safe_dumpadm $savedumpdev
  56         fi
  57 
  58         swap -l | awk 'NR > 1 { print $1 }' | \
  59             grep "^$voldev\$" > /dev/null 2>&1
  60         if (( $? == 0 ));  then
  61                 log_must swap -d $voldev
  62         fi
  63 
  64         typeset snap
  65         for snap in snap0 snap1 ; do
  66                 if datasetexists $TESTPOOL/$TESTVOL@$snap ; then
  67                         log_must zfs destroy $TESTPOOL/$TESTVOL@$snap
  68                 fi
  69         done
  70         zfs set volsize=$volsize $TESTPOOL/$TESTVOL
  71 }
  72 
  73 function verify_snapshot
  74 {
  75         typeset volume=$1
  76 
  77         log_must zfs snapshot $volume@snap0
  78         log_must zfs snapshot $volume@snap1
  79         log_must datasetexists $volume@snap0 $volume@snap1