fstests: filter redundant output by getfattr
[xfstests-dev.git] / tests / shared / 002
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 002
6 #
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
11 # values.
12 #
13 # This test is motivated by a bug found in btrfs.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22
23 _cleanup()
24 {
25         _cleanup_flakey
26         rm -f $tmp.*
27 }
28 trap "_cleanup; exit \$status" 0 1 2 3 15
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/dmflakey
34 . ./common/attr
35
36 # real QA test starts here
37
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
43 _supported_os Linux
44 _require_scratch
45 _require_dm_target flakey
46 _require_attrs
47
48 rm -f $seqres.full
49
50 _scratch_mkfs >> $seqres.full 2>&1
51 _require_metadata_journaling $SCRATCH_DEV
52 _init_flakey
53 _mount_flakey
54
55 # Create the test file with some initial data and make sure everything is
56 # durably persisted.
57 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" $SCRATCH_MNT/foo | _filter_xfs_io
58 sync
59
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).
65 num_xattrs=2000
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
69 done
70
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.
73 sync
74
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" \
81                 -c "fsync" \
82                 $SCRATCH_MNT/foo | _filter_xfs_io
83
84 _flakey_drop_and_remount
85
86 echo "File content after crash and log replay:"
87 od -t x1 $SCRATCH_MNT/foo
88
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)"
92         echo -n "$name="
93         _getfattr --absolute-names -n $name --only-values $SCRATCH_MNT/foo
94         echo
95 done
96
97 status=0
98 exit