generic/520: Remove sync in clean_dir
[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 _supported_os Linux
54 _require_test
55 _require_scratch_nocheck
56 _require_dm_target snapshot
57 _require_command $LVM_PROG lvm
58
59 echo "Silence is golden"
60 rm -f $seqres.full
61
62 vgname=vg_$seq
63 lvname=base_$seq
64 snapname=snap_$seq
65 mnt=$TEST_DIR/mnt_$seq
66 mkdir -p $mnt
67
68 # make sure there's enough disk space for 256M lv, test for 300M here in case
69 # lvm uses some space for metadata
70 _scratch_mkfs_sized $((300 * 1024 * 1024)) >>$seqres.full 2>&1
71 $LVM_PROG vgcreate -f $vgname $SCRATCH_DEV >>$seqres.full 2>&1
72 # We use yes pipe instead of 'lvcreate --yes' because old version of lvm
73 # (like 2.02.95 in RHEL6) don't support --yes option
74 yes | $LVM_PROG lvcreate -L 256M -n $lvname $vgname >>$seqres.full 2>&1
75 # wait for lvcreation to fully complete
76 $UDEV_SETTLE_PROG >>$seqres.full 2>&1
77
78 # _mkfs_dev exits the test on failure, this can make sure lv is created in
79 # above vgcreate/lvcreate steps
80 _mkfs_dev /dev/mapper/$vgname-$lvname
81
82 # create a 4M snapshot
83 $LVM_PROG lvcreate -s -L 4M -n $snapname $vgname/$lvname >>$seqres.full 2>&1 || \
84         _fail "Failed to create snapshot"
85
86 _mount /dev/mapper/$vgname-$snapname $mnt
87
88 # write 5M data to the snapshot
89 $XFS_IO_PROG -fc "pwrite 0 5m" -c fsync $mnt/testfile >>$seqres.full 2>&1
90
91 # _check_dmesg will check for WARNINGs/BUGs in dmesg
92 status=0
93 exit