fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 065
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. 065
6 #
7 # Test fsync on directories that got new hardlinks added to them and that point
8 # to existing inodes. The goal is to verify that after the fsync log is replayed
9 # the new hardlinks exist and the inodes have a correct link count.
10 # Also test that new hardlinks pointing to new inodes are logged and exist as
11 # well after the fsync log is replayed.
12 #
13 # This test is motivated by an issue discovered in btrfs, where the inode link
14 # counts were incorrect after the fsync log was replayed and the hardlinks for
15 # new inodes were not logged.
16 #
17 . ./common/preamble
18 _begin_fstest metadata auto quick log
19
20 # Override the default cleanup function.
21 _cleanup()
22 {
23         _cleanup_flakey
24         rm -f $tmp.*
25 }
26
27 # Import common functions.
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs generic
33 _require_scratch
34 _require_hardlinks
35 _require_dm_target flakey
36
37 _scratch_mkfs >> $seqres.full 2>&1
38 _require_metadata_journaling $SCRATCH_DEV
39 _init_flakey
40 _mount_flakey
41
42 # Create our main test file and directory.
43 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 8K" $SCRATCH_MNT/foo | _filter_xfs_io
44 mkdir $SCRATCH_MNT/mydir
45
46 # Make sure all metadata and data are durably persisted.
47 sync
48
49 # Add a hard link to 'foo' inside our test directory and fsync only the
50 # directory. The btrfs fsync implementation had a bug that caused the new
51 # directory entry to be visible after the fsync log replay but, the inode
52 # of our file remained with a link count of 1.
53 ln $SCRATCH_MNT/foo $SCRATCH_MNT/mydir/foo_2
54
55 # Add a few more links and new files.
56 # This is just to verify nothing breaks or gives incorrect results after the
57 # fsync log is replayed.
58 ln $SCRATCH_MNT/foo $SCRATCH_MNT/mydir/foo_3
59 $XFS_IO_PROG -f -c "pwrite -S 0xff 0 64K" $SCRATCH_MNT/hello | _filter_xfs_io
60 ln $SCRATCH_MNT/hello $SCRATCH_MNT/mydir/hello_2
61
62 # Add some subdirectories and new files and links to them. This is to verify
63 # that after fsyncing our top level directory 'mydir', all the subdirectories
64 # and their files/links are registered in the fsync log and exist after the
65 # fsync log is replayed.
66 mkdir -p $SCRATCH_MNT/mydir/x/y/z
67 ln $SCRATCH_MNT/foo $SCRATCH_MNT/mydir/x/y/foo_y_link
68 ln $SCRATCH_MNT/foo $SCRATCH_MNT/mydir/x/y/z/foo_z_link
69 touch $SCRATCH_MNT/mydir/x/y/z/qwerty
70
71 # Now fsync only our top directory.
72 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/mydir
73
74 # And fsync now our new file named 'hello', just to verify later that it has
75 # the expected content and that the previous fsync on the directory 'mydir' had
76 # no bad influence on this fsync.
77 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/hello
78
79 _flakey_drop_and_remount
80
81 # Verify the content of our file 'foo' remains the same as before, 8192 bytes,
82 # all with the value 0xaa.
83 echo "File 'foo' content after log replay:"
84 od -t x1 $SCRATCH_MNT/foo
85
86 # Remove the first name of our inode. Because of the directory fsync bug, the
87 # inode's link count was 1 instead of 5, so removing the 'foo' name ended up
88 # deleting the inode and the other names became stale directory entries (still
89 # visible to applications). Attempting to remove or access the remaining
90 # dentries pointing to that inode resulted in stale file handle errors and
91 # made it impossible to remove the parent directories since it was impossible
92 # for them to become empty.
93 echo "file 'foo' link count after log replay: $(stat -c %h $SCRATCH_MNT/foo)"
94 rm -f $SCRATCH_MNT/foo
95
96 # Now verify that all files, links and directories created before fsyncing our
97 # directory exist after the fsync log was replayed.
98 [ -f $SCRATCH_MNT/mydir/foo_2 ] || echo "Link mydir/foo_2 is missing"
99 [ -f $SCRATCH_MNT/mydir/foo_3 ] || echo "Link mydir/foo_3 is missing"
100 [ -f $SCRATCH_MNT/hello ] || echo "File hello is missing"
101 [ -f $SCRATCH_MNT/mydir/hello_2 ] || echo "Link mydir/hello_2 is missing"
102 [ -f $SCRATCH_MNT/mydir/x/y/foo_y_link ] || \
103         echo "Link mydir/x/y/foo_y_link is missing"
104 [ -f $SCRATCH_MNT/mydir/x/y/z/foo_z_link ] || \
105         echo "Link mydir/x/y/z/foo_z_link is missing"
106 [ -f $SCRATCH_MNT/mydir/x/y/z/qwerty ] || \
107         echo "File mydir/x/y/z/qwerty is missing"
108
109 # We expect our file here to have a size of 64Kb and all the bytes having the
110 # value 0xff.
111 echo "file 'hello' content after log replay:"
112 od -t x1 $SCRATCH_MNT/hello
113
114 # Now remove all files/links, under our test directory 'mydir', and verify we
115 # can remove all the directories.
116 rm -f $SCRATCH_MNT/mydir/x/y/z/*
117 rmdir $SCRATCH_MNT/mydir/x/y/z
118 rm -f $SCRATCH_MNT/mydir/x/y/*
119 rmdir $SCRATCH_MNT/mydir/x/y
120 rmdir $SCRATCH_MNT/mydir/x
121 rm -f $SCRATCH_MNT/mydir/*
122 rmdir $SCRATCH_MNT/mydir
123
124 # An fsck, run by the fstests framework everytime a test finishes, also detected
125 # the inconsistency and printed the following error message:
126 #
127 # root 5 inode 257 errors 2001, no inode item, link count wrong
128 #    unresolved ref dir 258 index 2 namelen 5 name foo_2 filetype 1 errors 4, no inode ref
129 #    unresolved ref dir 258 index 3 namelen 5 name foo_3 filetype 1 errors 4, no inode ref
130
131 status=0
132 exit