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 lvremove -f $vgname/$snapname >>$seqres.full 2>&1
37 $LVM_PROG lvremove -f $vgname/$lvname >>$seqres.full 2>&1
38 $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
39 $LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
42 test $pv_ret -eq 0 && break
47 # Import common functions.
50 # real QA test starts here
53 _require_scratch_nolvm
54 _require_dm_target snapshot
55 _require_command $LVM_PROG lvm
57 echo "Silence is golden"
62 mnt=$TEST_DIR/mnt_$seq
65 # make sure there's enough disk space for 256M lv, test for 300M here in case
66 # lvm uses some space for metadata
67 _scratch_mkfs_sized $((300 * 1024 * 1024)) >>$seqres.full 2>&1
68 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
69 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
70 # (like 2.02.95 in RHEL6) don't support --yes option
71 yes | $LVM_PROG lvcreate -L 256M -n $lvname $vgname >>$seqres.full 2>&1
72 # wait for lvcreation to fully complete
73 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
75 # _mkfs_dev exits the test on failure, this can make sure lv is created in
76 # above vgcreate/lvcreate steps
77 _mkfs_dev /dev/mapper/$vgname-$lvname
79 # create a 4M snapshot
80 $LVM_PROG lvcreate -s -L 4M -n $snapname $vgname/$lvname >>$seqres.full 2>&1 || \
81 _fail "Failed to create snapshot"
83 _mount /dev/mapper/$vgname-$snapname $mnt
85 # write 5M data to the snapshot
86 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
88 # _check_dmesg will check for WARNINGs/BUGs in dmesg