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.
13 # The btrfs issue was fixed by the following linux kernel patch:
15 # Btrfs: remove deleted xattrs on fsync log replay
17 #-----------------------------------------------------------------------
18 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
19 # Author: Filipe Manana <fdmanana@suse.com>
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.
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.
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 #-----------------------------------------------------------------------
37 seqres=$RESULT_DIR/$seq
38 echo "QA output created by $seq"
42 status=1 # failure is the default!
49 trap "_cleanup; exit \$status" 0 1 2 3 15
51 # get standard environment, filters and checks
57 # real QA test starts here
61 _require_dm_target flakey
66 _scratch_mkfs >> $seqres.full 2>&1
67 _require_metadata_journaling $SCRATCH_DEV
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
77 # Make sure everything is durably persisted.
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
84 _flakey_drop_and_remount
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
90 echo "xattr names and values after first fsync log replay:"
91 $GETFATTR_PROG --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
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
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
104 _flakey_drop_and_remount
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