2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that after syncing the filesystem, adding many xattrs to a file, syncing
8 # the filesystem again, writing to the file and then doing a fsync against that
9 # file, all the xattrs still exists after a power failure. That is, after the
10 # fsync log/journal is replayed, the xattrs still exist and with the correct
13 # This test is motivated by a bug found in btrfs.
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
28 trap "_cleanup; exit \$status" 0 1 2 3 15
30 # get standard environment, filters and checks
36 # real QA test starts here
38 # We create a lot of xattrs for a single file. Only btrfs and xfs are currently
39 # able to store such a large mount of xattrs per file, other filesystems such
40 # as ext3/4 and f2fs for example, fail with ENOSPC even if we attempt to add
41 # less than 1000 xattrs with very small values.
42 _supported_fs btrfs xfs
45 _require_dm_target flakey
50 _scratch_mkfs >> $seqres.full 2>&1
51 _require_metadata_journaling $SCRATCH_DEV
55 # Create the test file with some initial data and make sure everything is
57 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" $SCRATCH_MNT/foo | _filter_xfs_io
60 # Add many small xattrs to our file.
61 # We create such a large amount because it's needed to trigger the issue found
62 # in btrfs - we need to have an amount that causes the fs to have at least 3
63 # btree leafs with xattrs stored in them, and it must work on any leaf size
64 # (maximum leaf/node size is 64Kb).
66 for ((i = 1; i <= $num_xattrs; i++)); do
67 name="user.attr_$(printf "%04d" $i)"
68 $SETFATTR_PROG -n $name -v "val_$(printf "%04d" $i)" $SCRATCH_MNT/foo
71 # Sync the filesystem to force a commit of the current btrfs transaction, this
72 # is a necessary condition to trigger the bug on btrfs.
75 # Now update our file's data and fsync the file.
76 # After a successful fsync, if the fsync log/journal is replayed we expect to
77 # see all the xattrs we added before with the same values (and the updated file
78 # data of course). Btrfs used to delete some of these xattrs when it replayed
79 # its fsync log/journal.
80 $XFS_IO_PROG -c "pwrite -S 0xbb 8K 16K" \
82 $SCRATCH_MNT/foo | _filter_xfs_io
84 _flakey_drop_and_remount
86 echo "File content after crash and log replay:"
87 od -t x1 $SCRATCH_MNT/foo
89 echo "File xattrs after crash and log replay:"
90 for ((i = 1; i <= $num_xattrs; i++)); do
91 name="user.attr_$(printf "%04d" $i)"
93 _getfattr --absolute-names -n $name --only-values $SCRATCH_MNT/foo