fstests: check if the scratch device is an lv device for certain tests
[xfstests-dev.git] / tests / generic / 081
index 8334ec930364cc4a1bf45b1cd97b30e559152bb9..22ac94de538304b44aebd235115e48289754181f 100755 (executable)
@@ -1,59 +1,60 @@
 #! /bin/bash
-# FS QA Test No. 081
-#
-# Test I/O error path by fully filling an dm snapshot.
-#
-#-----------------------------------------------------------------------
+# SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# FS QA Test No. 081
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#-----------------------------------------------------------------------
+# Test I/O error path by fully filling an dm snapshot.
 #
+. ./common/preamble
+_begin_fstest auto quick
 
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
-
-here=`pwd`
-tmp=/tmp/$$
-status=1       # failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
+# Override the default cleanup function.
 _cleanup()
 {
+       local pv_ret
        cd /
        rm -f $tmp.*
-       # lvm may have umounted it on I/O error, but in case it does not
-       $UMOUNT_PROG $mnt >/dev/null 2>&1
-       $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
-       $LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
+
+       # Tear down the lvm vg and snapshot.
+       #
+       # NOTE: We do the unmount and {vg,pv}remove in a loop here because
+       # dmeventd could be configured to unmount the filesystem automatically
+       # after the IO errors.  That is racy with the umount we're trying to do
+       # here because there's a window in which the directory tree has been
+       # removed from the mount namespaces (so the umount call here sees no
+       # mount and exits) but the filesystem hasn't yet released the block
+       # device, which causes the vgremove here to fail.
+       #
+       # We "solve" the race by repeating the umount/lvm teardown until the
+       # block device goes away, because we cannot exit this test without
+       # removing the lvm devices from the scratch device -- this will cause
+       # other tests to fail.
+       while test -e /dev/mapper/$vgname-$snapname || \
+             test -e /dev/mapper/$vgname-$lvname; do
+               $UMOUNT_PROG $mnt >> $seqres.full 2>&1
+               $LVM_PROG lvremove -f $vgname/$snapname >>$seqres.full 2>&1
+               $LVM_PROG lvremove -f $vgname/$lvname >>$seqres.full 2>&1
+               $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
+               $LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
+               pv_ret=$?
+               $UDEV_SETTLE_PROG
+               test $pv_ret -eq 0 && break
+               sleep 2
+       done
 }
 
-# get standard environment, filters and checks
-. ./common/rc
+# Import common functions.
 . ./common/filter
 
 # real QA test starts here
 _supported_fs generic
-_supported_os Linux
 _require_test
-_require_scratch_nocheck
+_require_scratch_nolvm
 _require_dm_target snapshot
 _require_command $LVM_PROG lvm
 
 echo "Silence is golden"
-rm -f $seqres.full
 
 vgname=vg_$seq
 lvname=base_$seq
@@ -65,7 +66,9 @@ mkdir -p $mnt
 # lvm uses some space for metadata
 _scratch_mkfs_sized $((300 * 1024 * 1024)) >>$seqres.full 2>&1
 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
-$LVM_PROG lvcreate --yes -L 256M -n $lvname $vgname >>$seqres.full 2>&1
+# We use yes pipe instead of 'lvcreate --yes' because old version of lvm
+# (like 2.02.95 in RHEL6) don't support --yes option
+yes | $LVM_PROG lvcreate -L 256M -n $lvname $vgname >>$seqres.full 2>&1
 # wait for lvcreation to fully complete
 $UDEV_SETTLE_PROG >>$seqres.full 2>&1