1 #!/usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   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.
   8 #
   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.
  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) 2012 by Delphix. All rights reserved.
  30 #
  31 
  32 #
  33 # Copyright (c) 2013 by Delphix. All rights reserved.
  34 #
  35 
  36 . $STF_SUITE/include/libtest.shlib
  37 . $STF_SUITE/tests/functional/inuse/inuse.cfg
  38 
  39 #
  40 # DESCRIPTION:
  41 # ZFS will not interfere with devices that are in use by ufsdump or
  42 # ufsrestore.
  43 #
  44 # STRATEGY:
  45 # 1. newfs a disk
  46 # 2. mount the disk
  47 # 3. create files and dirs on disk
  48 # 4. umount the disk
  49 # 5. ufsdump this disk to a backup disk
  50 # 6. Try to create a ZFS pool with same disk (also as a spare device)
  51 # 7. ufsrestore the disk from backup
  52 # 8. try to create a zpool during the ufsrestore
  53 #
  54 
  55 verify_runnable "global"
  56 
  57 function cleanup
  58 {
  59         poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
  60 
  61         poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
  62 
  63         log_note "Kill off ufsdump process if still running"
  64         $KILL -0 $PIDUFSDUMP > /dev/null 2>&1 && \
  65             log_must $KILL -9 $PIDUFSDUMP  > /dev/null 2>&1
  66         #
  67         # Note: It would appear that ufsdump spawns a number of processes
  68         # which are not killed when the $PIDUFSDUMP is whacked.  So best bet
  69         # is to find the rest of the them and deal with them individually.
  70         #
  71         for all in `$PGREP ufsdump`
  72         do
  73                 $KILL -9 $all > /dev/null 2>&1
  74         done
  75 
  76         log_note "Kill off ufsrestore process if still running"
  77         $KILL -0 $PIDUFSRESTORE > /dev/null 2>&1 && \
  78             log_must $KILL -9 $PIDUFSRESTORE  > /dev/null 2>&1
  79 
  80         ismounted $UFSMP ufs && log_must $UMOUNT $UFSMP
  81 
  82         $RM -rf $UFSMP
  83         $RM -rf $TESTDIR
  84 
  85         #
  86         # Tidy up the disks we used.
  87         #
  88         log_must cleanup_devices $vdisks $sdisks
  89 }
  90 
  91 log_assert "Ensure ZFS does not interfere with devices that are in use by " \
  92     "ufsdump or ufsrestore"
  93 
  94 log_onexit cleanup
  95 
  96 typeset bigdir="${UFSMP}/bigdirectory"
  97 typeset restored_files="${UFSMP}/restored_files"
  98 typeset -i dirnum=0
  99 typeset -i filenum=0
 100 typeset cwd=""
 101 
 102 for num in 0 1 2; do
 103         eval typeset slice=\${FS_SIDE$num}
 104         disk=${slice%s*}
 105         slice=${slice##*s}
 106         if [[ $WRAPPER == *"smi"* && $disk == ${saved_disk} ]]; then
 107                 cyl=$(get_endslice $disk ${saved_slice})
 108                 log_must set_partition $slice "$cyl" $FS_SIZE $disk
 109         else
 110                 log_must set_partition $slice "" $FS_SIZE $disk
 111         fi
 112         saved_disk=$disk
 113         saved_slice=$slice
 114 done
 115 
 116 log_note "Make a ufs filesystem on source $rawdisk1"
 117 $ECHO "y" | $NEWFS -v $rawdisk1 > /dev/null 2>&1
 118 (($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1"
 119 
 120 log_must $MKDIR -p $UFSMP
 121 
 122 log_note "mount source $disk1 on $UFSMP"
 123 log_must $MOUNT $disk1 $UFSMP
 124 
 125 log_note "Now create some directories and files to be ufsdump'ed"
 126 while (($dirnum <= 2)); do
 127         log_must $MKDIR $bigdir${dirnum}
 128         while (( $filenum <= 2 )); do
 129                 $FILE_WRITE -o create -f $bigdir${dirnum}/file${filenum} \
 130                     -b $BLOCK_SIZE -c $BLOCK_COUNT
 131                 if [[ $? -ne 0 ]]; then
 132                         if [[ $dirnum -lt 3 ]]; then
 133                                 log_fail "$FILE_WRITE only wrote" \
 134                                     "<(( $dirnum * 3 + $filenum ))>" \
 135                                     "files, this is not enough"
 136                         fi
 137                 fi
 138                 ((filenum = filenum + 1))
 139         done
 140         filenum=0
 141         ((dirnum = dirnum + 1))
 142 done
 143 
 144 log_must $UMOUNT $UFSMP
 145 
 146 log_note "Start ufsdump in the background"
 147 log_note "$UFSDUMP 0bf 512 $rawdisk0 $disk1"
 148 $UFSDUMP 0bf 512 $rawdisk0 $disk1 &
 149 PIDUFSDUMP=$!
 150 
 151 log_note "Attempt to zpool the source device in use by ufsdump"
 152 log_mustnot $ZPOOL create $TESTPOOL1 "$disk1"
 153 log_mustnot poolexists $TESTPOOL1
 154 
 155 log_note "Attempt to take the source device in use by ufsdump as spare device"
 156 log_mustnot $ZPOOL create $TESTPOOL1 "$FS_SIDE2" spare "$disk1"
 157 log_mustnot poolexists $TESTPOOL1
 158 
 159 wait $PIDUFSDUMP
 160 typeset -i retval=$?
 161 (($retval != 0)) && log_fail "$UFSDUMP failed with error code $ret_val"
 162 
 163 log_must $MOUNT $disk1 $UFSMP
 164 
 165 log_must $RM -rf $UFSMP/*
 166 log_must $MKDIR $restored_files
 167 
 168 cwd=$PWD
 169 log_must cd $restored_files
 170 log_note "Start ufsrestore in the background from the target device"
 171 log_note "$UFSRESTORE rbf 512 $rawdisk0"
 172 $UFSRESTORE rbf 512 $rawdisk0 &
 173 PIDUFSRESTORE=$!
 174 log_must cd $cwd
 175 
 176 log_note "Attempt to zpool the restored device in use by ufsrestore"
 177 log_mustnot $ZPOOL create -f $TESTPOOL2 "$disk1"
 178 log_mustnot poolexists $TESTPOOL2
 179 
 180 log_note "Attempt to take the restored device in use by ufsrestore as spare" \
 181     "device"
 182 log_mustnot $ZPOOL create -f $TESTPOOL2 "$FS_SIDE2" spare "$disk1"
 183 log_mustnot poolexists $TESTPOOL2
 184 
 185 log_pass "Unable to zpool over a device in use by ufsdump or ufsrestore"