d986ef27dc56b677819a05dfe14016d78746c59e
[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
57 # Remove all files from previous tests
58 _scratch_mkfs
59
60 # overlay copy_up doesn't deal with sparse file well, holes will be filled by
61 # zeros, so if both hardlinks are broken on copy up, we need (2*1G) free space
62 # on $OVL_BASE_SCRATCH_MNT.
63 _require_fs_space $OVL_BASE_SCRATCH_MNT $((1024*1024*2))
64
65 # Create a large file in lower with 2 hardlinks.
66 # Make the file have non zero blocks, so copy up won't be able to do
67 # a naive sparse file copy up optimization.
68 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
69 mkdir -p $lowerdir
70 $XFS_IO_PROG -fc "pwrite 1g 4k" $lowerdir/zero >> $seqres.full
71 ln $lowerdir/zero $lowerdir/one
72 ln $lowerdir/zero $lowerdir/two
73
74 _scratch_mount
75
76 do_cmd()
77 {
78         echo "`date +%T` $1..." >> $seqres.full
79         eval "$1"
80         echo "`date +%T` ...$1" >> $seqres.full
81 }
82
83 # Perform one modification on each hardlink (size and owner)
84 do_cmd "echo >> $SCRATCH_MNT/one" &
85 #
86 # When hardlinks are broken and overlayfs supports concurrent copy up,
87 # $seqres.full will show that file two copy up started ~2s after file one
88 # copy up started and ended ~2s after file one copy up ended.
89 # With synchronized copy up of lower inodes, $seqres.full will show that
90 # file two copy up ended at the same time as file one copy up.
91 # Without sparse file copy up optimizations, copy of 1g on a standard disk
92 # is expected to take more than 2s.
93 # If underlying filesystem supports clone, overlay clone up with take less
94 # than 1s and this test will not be doing concurrent copy up of hardlinks,
95 # but rather consequent copy up of hardlinks.
96 #
97 sleep 2
98 do_cmd "chown 100 $SCRATCH_MNT/two" &
99
100 wait
101
102 # Expect all hardlinks to show both metadata modifications (owner and size).
103 # List <nlink> <owner> <size> <name>:
104 for f in zero one two; do
105         _ls_l -n $SCRATCH_MNT/$f | awk '{ print $2, $3, $5, $9 }' | _filter_scratch
106 done
107
108 status=0
109 exit