common/rc: add _scratch_{u}mount_idmapped() helpers
[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 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22
23         # Tear down the lvm vg and snapshot.
24         #
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.
32         #
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
43                 sleep 2
44         done
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50
51 # real QA test starts here
52 _supported_fs generic
53 _require_test
54 _require_scratch_nocheck
55 _require_dm_target snapshot
56 _require_command $LVM_PROG lvm
57
58 echo "Silence is golden"
59 rm -f $seqres.full
60
61 vgname=vg_$seq
62 lvname=base_$seq
63 snapname=snap_$seq
64 mnt=$TEST_DIR/mnt_$seq
65 mkdir -p $mnt
66
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
76
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
80
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"
84
85 _mount /dev/mapper/$vgname-$snapname $mnt
86
87 # write 5M data to the snapshot
88 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
89
90 # _check_dmesg will check for WARNINGs/BUGs in dmesg
91 status=0
92 exit