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