4 # Test that after syncing the filesystem, adding many xattrs to a file, syncing
5 # the filesystem again, writing to the file and then doing a fsync against that
6 # file, all the xattrs still exists after a power failure. That is, after the
7 # fsync log/journal is replayed, the xattrs still exist and with the correct
10 # This test is motivated by a bug found in btrfs.
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #-----------------------------------------------------------------------
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
37 status=1 # failure is the default!
44 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
52 # real QA test starts here
54 # We create a lot of xattrs for a single file. Only btrfs and xfs are currently
55 # able to store such a large mount of xattrs per file, other filesystems such
56 # as ext3/4 and f2fs for example, fail with ENOSPC even if we attempt to add
57 # less than 1000 xattrs with very small values.
58 _supported_fs btrfs xfs
61 _require_dm_target flakey
63 _require_metadata_journaling $SCRATCH_DEV
67 _scratch_mkfs >> $seqres.full 2>&1
71 # Create the test file with some initial data and make sure everything is
73 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" $SCRATCH_MNT/foo | _filter_xfs_io
76 # Add many small xattrs to our file.
77 # We create such a large amount because it's needed to trigger the issue found
78 # in btrfs - we need to have an amount that causes the fs to have at least 3
79 # btree leafs with xattrs stored in them, and it must work on any leaf size
80 # (maximum leaf/node size is 64Kb).
82 for ((i = 1; i <= $num_xattrs; i++)); do
83 name="user.attr_$(printf "%04d" $i)"
84 $SETFATTR_PROG -n $name -v "val_$(printf "%04d" $i)" $SCRATCH_MNT/foo
87 # Sync the filesystem to force a commit of the current btrfs transaction, this
88 # is a necessary condition to trigger the bug on btrfs.
91 # Now update our file's data and fsync the file.
92 # After a successful fsync, if the fsync log/journal is replayed we expect to
93 # see all the xattrs we added before with the same values (and the updated file
94 # data of course). Btrfs used to delete some of these xattrs when it replayed
95 # its fsync log/journal.
96 $XFS_IO_PROG -c "pwrite -S 0xbb 8K 16K" \
98 $SCRATCH_MNT/foo | _filter_xfs_io
100 _flakey_drop_and_remount
102 echo "File content after crash and log replay:"
103 od -t x1 $SCRATCH_MNT/foo
105 echo "File xattrs after crash and log replay:"
106 for ((i = 1; i <= $num_xattrs; i++)); do
107 name="user.attr_$(printf "%04d" $i)"
109 $GETFATTR_PROG --absolute-names -n $name --only-values $SCRATCH_MNT/foo