2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
7 # Test I/O error path by fully filling an dm snapshot.
10 _begin_fstest auto quick
12 # Override the default cleanup function.
19 # Tear down the lvm vg and snapshot.
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.
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
40 test $pv_ret -eq 0 && break
45 # Import common functions.
48 # real QA test starts here
51 _require_scratch_nocheck
52 _require_dm_target snapshot
53 _require_command $LVM_PROG lvm
55 echo "Silence is golden"
60 mnt=$TEST_DIR/mnt_$seq
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
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
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"
81 _mount /dev/mapper/$vgname-$snapname $mnt
83 # write 5M data to the snapshot
84 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
86 # _check_dmesg will check for WARNINGs/BUGs in dmesg