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