2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Chengguang Xu <cgxu519@mykernel.net>
8 # Test overlayfs copy-up function for variant sparse files.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks.
29 # remove previous $seqres.full before test.
32 # real QA test starts here.
34 # Modify as appropriate.
40 # Remove all files from previous tests
43 # We have totally 16 test files in this test.
44 # The detail as below:
45 # 1 small empty file 4K
47 # 1 small random hole file 10M
48 # 1 big random hole file 100M
50 # 12 files with variant iosize aligned holes.
51 # 2^0(K)..2^11(K) hole size files(file size = 10 * iosize)
53 # Considering both upper and lower fs will fill zero when copy-up
54 # hole area in the file, this test at least requires double disk
55 # space of the sum of above test files' size.
57 _require_fs_space $OVL_BASE_SCRATCH_MNT $((((4) + (4096) + (10 * 1024) \
58 + (100 * 1024) + (10 * (1 + 2048) * 12 / 2)) * 2))
62 echo $@ >>$seqres.full
63 eval $@ >>$seqres.full
66 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
67 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
68 testfile="copyup_sparse_test"
70 # Create a small completely empty hole file(4K).
72 do_cmd $XFS_IO_PROG -fc "\"truncate ${file_size}K\"" \
73 "${lowerdir}/${testfile}_empty_small"
75 # Create a big completely empty hole file(4M).
77 do_cmd $XFS_IO_PROG -fc "\"truncate ${file_size}K\"" \
78 "${lowerdir}/${testfile}_empty_big"
80 # Create 2^0(K)..2^11(K) hole size test files(file size = 10 * iosize).
82 # The pattern is like below, both hole and data are equal to
83 # iosize except last hole.
85 # |-- hole --|-- data --| ... |-- data --|-- hole --|
91 while [ $iosize -le $max_iosize ]; do
92 file_size=$(($iosize * 10))
93 max_pos=$(($file_size - $iosize))
95 do_cmd $XFS_IO_PROG -fc "\"truncate ${file_size}K\"" \
96 "${lowerdir}/${testfile}_iosize${iosize}K"
97 echo -e "\niosize=${iosize}K hole test write scenarios ---\n" >>$seqres.full
98 while [ $pos -lt $max_pos ]; do
99 do_cmd $XFS_IO_PROG -fc "\"pwrite ${pos}K ${iosize}K\"" \
100 "${lowerdir}/${testfile}_iosize${iosize}K"
101 pos=$(($pos + $iosize * 2))
103 iosize=$(($iosize * 2))
107 # Create test file with many random small holes(hole size is between 4K and 512K),
108 # total file size is 10M.
114 max_pos=$(($file_size - 2*$max_hole))
116 do_cmd $XFS_IO_PROG -fc "\"truncate ${file_size}K\"" \
117 "${lowerdir}/${testfile}_random_small"
119 echo -e "\nSmall random hole test write scenarios ---\n" >>$seqres.full
120 while [ $pos -le $max_pos ]; do
121 iosize=$(($RANDOM % ($max_hole - $min_hole) + $min_hole))
122 do_cmd $XFS_IO_PROG -fc "\"pwrite ${pos}K ${iosize}K\"" \
123 "${lowerdir}/${testfile}_random_small"
124 pos=$(($pos + $iosize * 2))
129 # Create test file with many random holes(hole size is between 1M and 5M),
130 # total file size is 100M.
136 max_pos=$(($file_size - 2*$max_hole))
138 do_cmd $XFS_IO_PROG -fc "\"truncate ${file_size}K\"" \
139 "${lowerdir}/${testfile}_random_big"
141 echo -e "\nBig random hole test write scenarios ---\n" >>$seqres.full
142 while [ $pos -le $max_pos ]; do
143 iosize=$(($RANDOM % ($max_hole - $min_hole) + $min_hole))
144 do_cmd $XFS_IO_PROG -fc "\"pwrite ${pos}K ${iosize}K\"" \
145 "${lowerdir}/${testfile}_random_big"
146 pos=$(($pos + $iosize * 2))
152 # Open the test files, no errors are expected.
153 echo -e "\nDoing copy-up...\n" >>$seqres.full
154 for f in $SCRATCH_MNT/*; do
155 do_cmd $XFS_IO_PROG -c "open" $f
158 echo "Silence is golden"
160 # Check all copy-up files in upper layer.
161 diff -qr ${upperdir} ${lowerdir} | tee -a $seqres.full
162 if [ $? -ne 0 ]; then
163 echo "Copy-up failed!!!"
165 echo "\n----------------------------------------" >>$seqres.full
166 echo -e "The layout of files in lowerdir\n" >>$seqres.full
167 do_cmd $FILEFRAG_PROG -k -e $lowerdir/*
168 echo "\n----------------------------------------" >>$seqres.full
169 echo -e "The layer of files in upperdir\n" >>$seqres.full
170 do_cmd $FILEFRAG_PROG -k -e $upperdir/*