generic: _require_dm_target() helper
[xfstests-dev.git] / tests / generic / 066
1 #! /bin/bash
2 # FS QA Test No. 066
3 #
4 # This test is motivated by an fsync issue discovered in btrfs.
5 # The issue was that the fsync log replay code did not remove xattrs that were
6 # deleted before the inode was fsynced. So verify that if we delete a xattr from
7 # a file and then fsync the file, after log replay the file does not have that
8 # xattr anymore. Also test the case where a file is fsynced, one of its xattrs
9 # is removed, a hard link to that file is created and the fsync log is committed
10 # by issuing an fsync on another file. This indirect case should also result in
11 # not having the xattr anymore after the fsync log is replayed.
12 #
13 # The btrfs issue was fixed by the following linux kernel patch:
14 #
15 #  Btrfs: remove deleted xattrs on fsync log replay
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
19 # Author: Filipe Manana <fdmanana@suse.com>
20 #
21 # This program is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU General Public License as
23 # published by the Free Software Foundation.
24 #
25 # This program is distributed in the hope that it would be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28 # GNU General Public License for more details.
29 #
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write the Free Software Foundation,
32 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
33 #-----------------------------------------------------------------------
34 #
35
36 seq=`basename $0`
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
39
40 here=`pwd`
41 tmp=/tmp/$$
42 status=1        # failure is the default!
43
44 _cleanup()
45 {
46         _cleanup_flakey
47         rm -f $tmp.*
48 }
49 trap "_cleanup; exit \$status" 0 1 2 3 15
50
51 # get standard environment, filters and checks
52 . ./common/rc
53 . ./common/filter
54 . ./common/dmflakey
55 . ./common/attr
56
57 # real QA test starts here
58 _supported_fs generic
59 _supported_os Linux
60 _need_to_be_root
61 _require_scratch
62 _require_dm_target flakey
63 _require_attrs
64 _require_metadata_journaling $SCRATCH_DEV
65
66 _crash_and_mount()
67 {
68         # Simulate a crash/power loss.
69         _load_flakey_table $FLAKEY_DROP_WRITES
70         _unmount_flakey
71         _load_flakey_table $FLAKEY_ALLOW_WRITES
72         _mount_flakey
73 }
74
75 rm -f $seqres.full
76
77 _scratch_mkfs >> $seqres.full 2>&1
78 _init_flakey
79 _mount_flakey
80
81 # Create out test file and add 3 xattrs to it.
82 touch $SCRATCH_MNT/foobar
83 $SETFATTR_PROG -n user.attr1 -v val1 $SCRATCH_MNT/foobar
84 $SETFATTR_PROG -n user.attr2 -v val2 $SCRATCH_MNT/foobar
85 $SETFATTR_PROG -n user.attr3 -v val3 $SCRATCH_MNT/foobar
86
87 # Make sure everything is durably persisted.
88 sync
89
90 # Now delete the second xattr and fsync the inode.
91 $SETFATTR_PROG -x user.attr2 $SCRATCH_MNT/foobar
92 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
93
94 _crash_and_mount
95
96 # After the fsync log is replayed, the file should have only 2 xattrs, the ones
97 # named user.attr1 and user.attr3. The btrfs fsync log replay bug left the file
98 # with the 3 xattrs that we had before deleting the second one and fsyncing the
99 # file.
100 echo "xattr names and values after first fsync log replay:"
101 $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
102
103 # Now write some data to our file, fsync it, remove the first xattr, add a new
104 # hard link to our file and commit the fsync log by fsyncing some other new
105 # file. This is to verify that after log replay our first xattr does not exist
106 # anymore.
107 echo "hello world!" >> $SCRATCH_MNT/foobar
108 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
109 $SETFATTR_PROG -x user.attr1 $SCRATCH_MNT/foobar
110 ln $SCRATCH_MNT/foobar $SCRATCH_MNT/foobar_link
111 touch $SCRATCH_MNT/qwerty
112 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/qwerty
113
114 _crash_and_mount
115
116 # Now only the xattr with name user.attr3 should be set in our file.
117 echo "xattr names and values after second fsync log replay:"
118 $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
119
120 status=0
121 exit