generic: shutdown fs after log recovery
[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 _require_scratch
61 _require_dm_target flakey
62 _require_attrs
63 _require_metadata_journaling $SCRATCH_DEV
64
65 rm -f $seqres.full
66
67 _scratch_mkfs >> $seqres.full 2>&1
68 _init_flakey
69 _mount_flakey
70
71 # Create out test file and add 3 xattrs to it.
72 touch $SCRATCH_MNT/foobar
73 $SETFATTR_PROG -n user.attr1 -v val1 $SCRATCH_MNT/foobar
74 $SETFATTR_PROG -n user.attr2 -v val2 $SCRATCH_MNT/foobar
75 $SETFATTR_PROG -n user.attr3 -v val3 $SCRATCH_MNT/foobar
76
77 # Make sure everything is durably persisted.
78 sync
79
80 # Now delete the second xattr and fsync the inode.
81 $SETFATTR_PROG -x user.attr2 $SCRATCH_MNT/foobar
82 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
83
84 _flakey_drop_and_remount
85
86 # After the fsync log is replayed, the file should have only 2 xattrs, the ones
87 # named user.attr1 and user.attr3. The btrfs fsync log replay bug left the file
88 # with the 3 xattrs that we had before deleting the second one and fsyncing the
89 # file.
90 echo "xattr names and values after first fsync log replay:"
91 $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
92
93 # Now write some data to our file, fsync it, remove the first xattr, add a new
94 # hard link to our file and commit the fsync log by fsyncing some other new
95 # file. This is to verify that after log replay our first xattr does not exist
96 # anymore.
97 echo "hello world!" >> $SCRATCH_MNT/foobar
98 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
99 $SETFATTR_PROG -x user.attr1 $SCRATCH_MNT/foobar
100 ln $SCRATCH_MNT/foobar $SCRATCH_MNT/foobar_link
101 touch $SCRATCH_MNT/qwerty
102 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/qwerty
103
104 _flakey_drop_and_remount
105
106 # Now only the xattr with name user.attr3 should be set in our file.
107 echo "xattr names and values after second fsync log replay:"
108 $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
109
110 status=0
111 exit