xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 066
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. 066
6 #
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.
15 #
16 # The btrfs issue was fixed by the following linux kernel patch:
17 #
18 #  Btrfs: remove deleted xattrs on fsync log replay
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27
28 _cleanup()
29 {
30         _cleanup_flakey
31         rm -f $tmp.*
32 }
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38 . ./common/dmflakey
39 . ./common/attr
40
41 # real QA test starts here
42 _supported_fs generic
43 _require_scratch
44 _require_dm_target flakey
45 _require_attrs
46
47 rm -f $seqres.full
48
49 _scratch_mkfs >> $seqres.full 2>&1
50 _require_metadata_journaling $SCRATCH_DEV
51 _init_flakey
52 _mount_flakey
53
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
59
60 # Make sure everything is durably persisted.
61 sync
62
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
66
67 _flakey_drop_and_remount
68
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
72 # file.
73 echo "xattr names and values after first fsync log replay:"
74 _getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
75
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
79 # anymore.
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
86
87 _flakey_drop_and_remount
88
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
92
93 status=0
94 exit