generic/402: Drop useless fail message
[xfstests-dev.git] / tests / generic / 059
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. 059
6 #
7 # This test is motivated by an fsync issue discovered in btrfs.
8 # The issue was that after punching a hole for a small range, which affected
9 # only a partial page, an fsync operation would have no effect at all. This was
10 # because for this particular case the btrfs hole punching implementation did
11 # not update some btrfs specific inode metadata that is required to determine
12 # if an fsync operation needs to update the fsync log. For this to happen, it
13 # was also necessary that in the transaction where the hole punching was
14 # performed, and before the fsync operation, no other operation that modified
15 # the file (or its metadata) was performed.
16 #
17 # The btrfs issue was fixed by the following linux kernel patch:
18 #
19 #  Btrfs: add missing inode update when punching hole
20 #
21 # Also test the mtime and ctime properties of the file change after punching
22 # holes with ranges that operate only on a single block of the file.
23 #
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31
32 _cleanup()
33 {
34         _cleanup_flakey
35         rm -f $tmp.*
36 }
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/dmflakey
43
44 # real QA test starts here
45 _supported_fs generic
46 _require_scratch
47 _require_dm_target flakey
48 _require_xfs_io_command "fpunch"
49
50 rm -f $seqres.full
51
52 _scratch_mkfs >> $seqres.full 2>&1
53 _require_metadata_journaling $SCRATCH_DEV
54 _init_flakey
55 _mount_flakey
56
57 # Create our test file.
58 $XFS_IO_PROG -f -c "pwrite -S 0x22 -b 16K 0 16K" \
59         $SCRATCH_MNT/foo | _filter_xfs_io
60
61 # Fsync the file, this makes btrfs update some btrfs inode specific fields
62 # that are used to track if the inode needs to be written/updated to the fsync
63 # log or not. After this fsync, the new values for those fields indicate that
64 # a subsequent fsync does not need to touch the fsync log.
65 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
66
67 # Force a commit of the current transaction. After this point, any operation
68 # that modifies the data or metadata of our file, should update those fields in
69 # the btrfs inode with values that make the next fsync operation write to the
70 # fsync log.
71 sync
72
73 # Sleep for 1 second, because we want to check that the next punch operations we
74 # do update the file's mtime and ctime.
75 sleep 1
76
77 mtime_before=$(stat -c %Y $SCRATCH_MNT/foo)
78 ctime_before=$(stat -c %Z $SCRATCH_MNT/foo)
79
80 # Punch a hole in our file. This small range affects only 1 page.
81 # This made the btrfs hole punching implementation write only some zeroes in
82 # one page, but it did not update the btrfs inode fields used to determine if
83 # the next fsync needs to write to the fsync log.
84 $XFS_IO_PROG -c "fpunch 8000 4K" $SCRATCH_MNT/foo
85
86 # Another variation of the previously mentioned case.
87 $XFS_IO_PROG -c "fpunch 15000 100" $SCRATCH_MNT/foo
88
89 # Now fsync the file. This was a no-operation because the previous hole punch
90 # operation didn't update the inode's fields mentioned before, so they remained
91 # with the values they had after the first fsync - that is, they indicate that
92 # it is not needed to write to fsync log.
93 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
94
95 echo "File content before:"
96 od -t x1 $SCRATCH_MNT/foo
97
98 _flakey_drop_and_remount
99
100 # Because the last fsync didn't do anything, here the file content matched what
101 # it was after the first fsync, before the holes were punched, and not what it
102 # was after the holes were punched.
103 echo "File content after:"
104 od -t x1 $SCRATCH_MNT/foo
105
106 mtime_after=$(stat -c %Y $SCRATCH_MNT/foo)
107 ctime_after=$(stat -c %Z $SCRATCH_MNT/foo)
108
109 [ $mtime_after -gt $mtime_before ] || \
110         echo "mtime did not increase (before: $mtime_before after: $mtime_after"
111 [ $ctime_after -gt $ctime_before ] || \
112         echo "ctime did not increase (before: $ctime_before after: $ctime_after"
113
114 status=0
115 exit