2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # This test is motivated by an fsync issue discovered in btrfs.
8 # The issue was that the fsync log replay code did not remove xattrs that were
9 # deleted before the inode was fsynced. So verify that if we delete a xattr from
10 # a file and then fsync the file, after log replay the file does not have that
11 # xattr anymore. Also test the case where a file is fsynced, one of its xattrs
12 # is removed, a hard link to that file is created and the fsync log is committed
13 # by issuing an fsync on another file. This indirect case should also result in
14 # not having the xattr anymore after the fsync log is replayed.
16 # The btrfs issue was fixed by the following linux kernel patch:
18 # Btrfs: remove deleted xattrs on fsync log replay
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
26 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
41 # real QA test starts here
44 _require_dm_target flakey
49 _scratch_mkfs >> $seqres.full 2>&1
50 _require_metadata_journaling $SCRATCH_DEV
54 # Create out test file and add 3 xattrs to it.
55 touch $SCRATCH_MNT/foobar
56 $SETFATTR_PROG -n user.attr1 -v val1 $SCRATCH_MNT/foobar
57 $SETFATTR_PROG -n user.attr2 -v val2 $SCRATCH_MNT/foobar
58 $SETFATTR_PROG -n user.attr3 -v val3 $SCRATCH_MNT/foobar
60 # Make sure everything is durably persisted.
63 # Now delete the second xattr and fsync the inode.
64 $SETFATTR_PROG -x user.attr2 $SCRATCH_MNT/foobar
65 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
67 _flakey_drop_and_remount
69 # After the fsync log is replayed, the file should have only 2 xattrs, the ones
70 # named user.attr1 and user.attr3. The btrfs fsync log replay bug left the file
71 # with the 3 xattrs that we had before deleting the second one and fsyncing the
73 echo "xattr names and values after first fsync log replay:"
74 _getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
76 # Now write some data to our file, fsync it, remove the first xattr, add a new
77 # hard link to our file and commit the fsync log by fsyncing some other new
78 # file. This is to verify that after log replay our first xattr does not exist
80 echo "hello world!" >> $SCRATCH_MNT/foobar
81 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
82 $SETFATTR_PROG -x user.attr1 $SCRATCH_MNT/foobar
83 ln $SCRATCH_MNT/foobar $SCRATCH_MNT/foobar_link
84 touch $SCRATCH_MNT/qwerty
85 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/qwerty
87 _flakey_drop_and_remount
89 # Now only the xattr with name user.attr3 should be set in our file.
90 echo "xattr names and values after second fsync log replay:"
91 _getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch