fstests: check if the scratch device is an lv device for certain tests
[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 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
40                 pv_ret=$?
41                 $UDEV_SETTLE_PROG
42                 test $pv_ret -eq 0 && break
43                 sleep 2
44         done
45 }
46
47 # Import common functions.
48 . ./common/filter
49
50 # real QA test starts here
51 _supported_fs generic
52 _require_test
53 _require_scratch_nolvm
54 _require_dm_target snapshot
55 _require_command $LVM_PROG lvm
56
57 echo "Silence is golden"
58
59 vgname=vg_$seq
60 lvname=base_$seq
61 snapname=snap_$seq
62 mnt=$TEST_DIR/mnt_$seq
63 mkdir -p $mnt
64
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
74
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
78
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"
82
83 _mount /dev/mapper/$vgname-$snapname $mnt
84
85 # write 5M data to the snapshot
86 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
87
88 # _check_dmesg will check for WARNINGs/BUGs in dmesg
89 status=0
90 exit