fstests: use udevadm settle after pvremove
[xfstests-dev.git] / tests / generic / 081
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 081
6 #
7 # Test I/O error path by fully filling an dm snapshot.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         local pv_ret
16         cd /
17         rm -f $tmp.*
18
19         # Tear down the lvm vg and snapshot.
20         #
21         # NOTE: We do the unmount and {vg,pv}remove in a loop here because
22         # dmeventd could be configured to unmount the filesystem automatically
23         # after the IO errors.  That is racy with the umount we're trying to do
24         # here because there's a window in which the directory tree has been
25         # removed from the mount namespaces (so the umount call here sees no
26         # mount and exits) but the filesystem hasn't yet released the block
27         # device, which causes the vgremove here to fail.
28         #
29         # We "solve" the race by repeating the umount/lvm teardown until the
30         # block device goes away, because we cannot exit this test without
31         # removing the lvm devices from the scratch device -- this will cause
32         # other tests to fail.
33         while test -e /dev/mapper/$vgname-$snapname || \
34               test -e /dev/mapper/$vgname-$lvname; do
35                 $UMOUNT_PROG $mnt >> $seqres.full 2>&1
36                 $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
37                 $LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
38                 pv_ret=$?
39                 $UDEV_SETTLE_PROG
40                 test $pv_ret -eq 0 && break
41                 sleep 2
42         done
43 }
44
45 # Import common functions.
46 . ./common/filter
47
48 # real QA test starts here
49 _supported_fs generic
50 _require_test
51 _require_scratch_nocheck
52 _require_dm_target snapshot
53 _require_command $LVM_PROG lvm
54
55 echo "Silence is golden"
56
57 vgname=vg_$seq
58 lvname=base_$seq
59 snapname=snap_$seq
60 mnt=$TEST_DIR/mnt_$seq
61 mkdir -p $mnt
62
63 # make sure there's enough disk space for 256M lv, test for 300M here in case
64 # lvm uses some space for metadata
65 _scratch_mkfs_sized $((300 * 1024 * 1024)) >>$seqres.full 2>&1
66 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
67 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
68 # (like 2.02.95 in RHEL6) don't support --yes option
69 yes | $LVM_PROG lvcreate -L 256M -n $lvname $vgname >>$seqres.full 2>&1
70 # wait for lvcreation to fully complete
71 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
72
73 # _mkfs_dev exits the test on failure, this can make sure lv is created in
74 # above vgcreate/lvcreate steps
75 _mkfs_dev /dev/mapper/$vgname-$lvname
76
77 # create a 4M snapshot
78 $LVM_PROG lvcreate -s -L 4M -n $snapname $vgname/$lvname >>$seqres.full 2>&1 || \
79         _fail "Failed to create snapshot"
80
81 _mount /dev/mapper/$vgname-$snapname $mnt
82
83 # write 5M data to the snapshot
84 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
85
86 # _check_dmesg will check for WARNINGs/BUGs in dmesg
87 status=0
88 exit