xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / generic / 090
1 #! /bin/bash
2 # FS QA Test No. 090
3 #
4 # Test that after syncing the filesystem, adding a hard link to a file,
5 # syncing the filesystem again, doing a write to the file that increases
6 # its size and then doing a fsync against that file, durably persists the
7 # data written to the file. That is, after log/journal replay, the data
8 # is available.
9 #
10 # This test is motivated by a bug found in btrfs.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
15 #
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.
19 #
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.
24 #
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 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38
39 _cleanup()
40 {
41         _cleanup_flakey
42         rm -f $tmp.*
43 }
44 trap "_cleanup; exit \$status" 0 1 2 3 15
45
46 # get standard environment, filters and checks
47 . ./common/rc
48 . ./common/filter
49 . ./common/dmflakey
50
51 # real QA test starts here
52 _supported_fs generic
53 _supported_os Linux
54 _require_scratch
55 _require_dm_target flakey
56 _require_metadata_journaling $SCRATCH_DEV
57
58 rm -f $seqres.full
59
60 _scratch_mkfs >> $seqres.full 2>&1
61 _init_flakey
62 _mount_flakey
63
64 # Create the test file with some initial data and then fsync it.
65 # The fsync here is only needed to trigger the issue in btrfs, as it causes the
66 # the flag BTRFS_INODE_NEEDS_FULL_SYNC to be removed from the btrfs inode.
67 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 32k" \
68                 -c "fsync" \
69                 $SCRATCH_MNT/foo | _filter_xfs_io
70 sync
71
72 # Add a hard link to our file.
73 # On btrfs this sets the flag BTRFS_INODE_COPY_EVERYTHING on the btrfs inode,
74 # which is a necessary condition to trigger the issue.
75 ln $SCRATCH_MNT/foo $SCRATCH_MNT/bar
76
77 # Sync the filesystem to force a commit of the current btrfs transaction, this
78 # is a necessary condition to trigger the bug on btrfs.
79 sync
80
81 # Now append more data to our file, increasing its size, and fsync the file.
82 # In btrfs because the inode flag BTRFS_INODE_COPY_EVERYTHING was set and the
83 # write path did not update the inode item in the btree nor the delayed inode
84 # item (in memory structure) in the current transaction (created by the fsync
85 # handler), the fsync did not record the inode's new i_size in the fsync
86 # log/journal. This made the data unavailable after the fsync log/journal is
87 # replayed.
88 $XFS_IO_PROG -c "pwrite -S 0xbb 32K 32K" \
89                 -c "fsync" \
90                 $SCRATCH_MNT/foo | _filter_xfs_io
91
92 echo "File content after fsync and before crash:"
93 od -t x1 $SCRATCH_MNT/foo
94
95 _flakey_drop_and_remount
96
97 echo "File content after crash and log replay:"
98 od -t x1 $SCRATCH_MNT/foo
99
100 status=0
101 exit