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 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
23 # Tear down the lvm vg and snapshot.
25 # NOTE: We do the unmount and {vg,pv}remove in a loop here because
26 # dmeventd could be configured to unmount the filesystem automatically
27 # after the IO errors. That is racy with the umount we're trying to do
28 # here because there's a window in which the directory tree has been
29 # removed from the mount namespaces (so the umount call here sees no
30 # mount and exits) but the filesystem hasn't yet released the block
31 # device, which causes the vgremove here to fail.
33 # We "solve" the race by repeating the umount/lvm teardown until the
34 # block device goes away, because we cannot exit this test without
35 # removing the lvm devices from the scratch device -- this will cause
36 # other tests to fail.
37 while test -e /dev/mapper/$vgname-$snapname || \
38 test -e /dev/mapper/$vgname-$lvname; do
39 $UMOUNT_PROG $mnt >> $seqres.full 2>&1
40 $LVM_PROG vgremove -f $vgname >>$seqres.full 2>&1
41 $LVM_PROG pvremove -f $SCRATCH_DEV >>$seqres.full 2>&1
42 test $? -eq 0 && break
47 # get standard environment, filters and checks
51 # real QA test starts here
54 _require_scratch_nocheck
55 _require_dm_target snapshot
56 _require_command $LVM_PROG lvm
58 echo "Silence is golden"
64 mnt=$TEST_DIR/mnt_$seq
67 # make sure there's enough disk space for 256M lv, test for 300M here in case
68 # lvm uses some space for metadata
69 _scratch_mkfs_sized $((300 * 1024 * 1024)) >>$seqres.full 2>&1
70 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
71 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
72 # (like 2.02.95 in RHEL6) don't support --yes option
73 yes | $LVM_PROG lvcreate -L 256M -n $lvname $vgname >>$seqres.full 2>&1
74 # wait for lvcreation to fully complete
75 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
77 # _mkfs_dev exits the test on failure, this can make sure lv is created in
78 # above vgcreate/lvcreate steps
79 _mkfs_dev /dev/mapper/$vgname-$lvname
81 # create a 4M snapshot
82 $LVM_PROG lvcreate -s -L 4M -n $snapname $vgname/$lvname >>$seqres.full 2>&1 || \
83 _fail "Failed to create snapshot"
85 _mount /dev/mapper/$vgname-$snapname $mnt
87 # write 5M data to the snapshot
88 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
90 # _check_dmesg will check for WARNINGs/BUGs in dmesg