2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
7 # Test concurrent copy up of lower hardlinks.
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
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # get standard environment, filters and checks
33 # remove previous $seqres.full before test
36 # real QA test starts here
39 _require_scratch_feature index
41 # Remove all files from previous tests
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))
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
54 $XFS_IO_PROG -fc "pwrite 1g 4k" $lowerdir/zero >> $seqres.full
55 ln $lowerdir/zero $lowerdir/one
56 ln $lowerdir/zero $lowerdir/two
58 # Enable overlay index feature to prevent breaking hardlinks on copy up
59 _scratch_mount -o index=on
63 echo "`date +%T` $1..." >> $seqres.full
65 echo "`date +%T` ...$1" >> $seqres.full
68 # Perform one modification on each hardlink (size and owner)
69 do_cmd "echo >> $SCRATCH_MNT/one" &
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.
83 do_cmd "chown 100 $SCRATCH_MNT/two" &
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