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