overlay: enable the index feature for overlay/hardlink tests
[xfstests-dev.git] / tests / overlay / 032
1 #! /bin/bash
2 # FS QA Test 032
3 #
4 # Test concurrent copy up of lower hardlinks.
5 #
6 # Two tasks make a metadata change concurrently on two hardlinks of a large
7 # lower inode.  The copy up should be triggers by one of the tasks and the
8 # other should be waiting for copy up to complete.  Both copy up targets
9 # should end up being upper hardlinks and both metadata changes should be
10 # applied.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
14 # Author: Amir Goldstein <amir73il@gmail.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 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48
49 # remove previous $seqres.full before test
50 rm -f $seqres.full
51
52 # real QA test starts here
53 _supported_fs overlay
54 _supported_os Linux
55 _require_scratch
56 _require_scratch_feature index
57
58 # Remove all files from previous tests
59 _scratch_mkfs
60
61 # overlay copy_up doesn't deal with sparse file well, holes will be filled by
62 # zeros, so if both hardlinks are broken on copy up, we need (2*1G) free space
63 # on $OVL_BASE_SCRATCH_MNT.
64 _require_fs_space $OVL_BASE_SCRATCH_MNT $((1024*1024*2))
65
66 # Create a large file in lower with 2 hardlinks.
67 # Make the file have non zero blocks, so copy up won't be able to do
68 # a naive sparse file copy up optimization.
69 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
70 mkdir -p $lowerdir
71 $XFS_IO_PROG -fc "pwrite 1g 4k" $lowerdir/zero >> $seqres.full
72 ln $lowerdir/zero $lowerdir/one
73 ln $lowerdir/zero $lowerdir/two
74
75 # Enable overlay index feature to prevent breaking hardlinks on copy up
76 _scratch_mount -o index=on
77
78 do_cmd()
79 {
80         echo "`date +%T` $1..." >> $seqres.full
81         eval "$1"
82         echo "`date +%T` ...$1" >> $seqres.full
83 }
84
85 # Perform one modification on each hardlink (size and owner)
86 do_cmd "echo >> $SCRATCH_MNT/one" &
87 #
88 # When hardlinks are broken and overlayfs supports concurrent copy up,
89 # $seqres.full will show that file two copy up started ~2s after file one
90 # copy up started and ended ~2s after file one copy up ended.
91 # With synchronized copy up of lower inodes, $seqres.full will show that
92 # file two copy up ended at the same time as file one copy up.
93 # Without sparse file copy up optimizations, copy of 1g on a standard disk
94 # is expected to take more than 2s.
95 # If underlying filesystem supports clone, overlay clone up with take less
96 # than 1s and this test will not be doing concurrent copy up of hardlinks,
97 # but rather consequent copy up of hardlinks.
98 #
99 sleep 2
100 do_cmd "chown 100 $SCRATCH_MNT/two" &
101
102 wait
103
104 # Expect all hardlinks to show both metadata modifications (owner and size).
105 # List <nlink> <owner> <size> <name>:
106 for f in zero one two; do
107         _ls_l -n $SCRATCH_MNT/$f | awk '{ print $2, $3, $5, $9 }' | _filter_scratch
108 done
109
110 status=0
111 exit