3 # Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 # common functions for excersizing hole punches with extent size hints etc.
21 # source dmap_scratch_mount etc.
25 echo "# spawning test file with $*"
27 local file_size=`expr $2 \* $blksize`
28 local extent_size_hint=`expr $3 \* $blksize`
30 local reserve_space=$5
32 if [ $extent_size_hint -ne 0 ]; then
33 echo "+ setting extent size hint to $extent_size_hint"
35 -c "extsize $extent_size_hint" \
38 # print extent size hint for $test_file
43 if [ "$reserve_space" == "noresv" ]; then
44 echo "+ not using resvsp at file creation"
46 -c "truncate $file_size" \
50 -c "truncate $file_size" \
51 -c "resvsp 0 $file_size" \
57 echo "# punching with $*"
58 # punch or bite the ear off $test_file to create a hole
60 local punch_offset=`expr $2 \* $blksize`
61 local punch_size=`expr $3 \* $blksize`
62 local punch_type=$4 # u for unresvsp, d for dm_punch
65 if [ "$punch_type" == "u" ]; then
66 echo "+ hole punch using unresvsp"
68 -c "unresvsp $punch_offset $punch_size" \
71 if [ "$punch_type" == "d" ]; then
72 echo "+ hole punch using dmapi punch_hole"
73 ${DMAPI_QASUITE1_DIR}cmd/punch_hole -o $punch_offset -l $punch_size \
74 ${SCRATCH_MNT}/$test_file
79 echo "# writing with $*"
81 local write_offset=`expr $2 \* $blksize`
82 local write_size=`expr $3 \* $blksize`
86 -c "pwrite $write_offset $write_size" \
91 echo "# showing file state $*"
100 echo "# testing $* ..."
102 # all points and sizes below are in terms of filesystem blocks
103 local extsize_hint_blks=$2 # extent size hint in FS blocks, 0=do not set
104 local file_size_blks=$3 # the file size in blocks
105 local punch_points_blks=( $4 ) # array of places to punch holes in the file
106 local punch_sizes_blks=( $5 ) # array of size of each punch in blocks
107 local punch_types=( $6 ) # array of u=unresvsp or d=dm_punch
108 local write_points_blks=( $7 ) # array of places to pwrite in the file
109 local write_sizes_blks=( $8 ) # array of size of each write
111 local punch_write_order=( $9 ) # array of punch/write operation order
112 # e.g. "w p w w p" means: do 1st write...
113 # then 1st punch, 2nd & 3rd write, 2nd punch
114 local resvsp=${10} # if "noresv" then don't resvsp on file create
115 local filename=punch_test_file
118 umount $SCRATCH_MNT >/dev/null 2>&1
120 _scratch_mkfs_xfs -bsize=$blksize >/dev/null 2>&1 \
121 || _fail "mkfs failed"
123 local this_punch_type=""
124 local dmap_punch_used=0
125 for this_punch_type in "${punch_types[@]}"; do
126 [ "$this_punch_type" == "d" ] && dmap_punch_used=1
128 if [ $dmap_punch_used -ne 0 ]; then
129 # a punch type of dm_punch has been specified, do a dmapi mount
130 echo "+ mounting with dmapi enabled"
133 # only unresvsp punch type is used, just do a normal mount
134 _scratch_mount || _fail "mount failed"
139 # check a size is specified for each punch
140 [ ${#punch_points_blks[*]} -eq ${#punch_sizes_blks[*]} ] \
141 || _fail "num punch points given does not equal num punch sizes"
143 # check a type is specified for each punch
144 [ ${#punch_points_blks[*]} -eq ${#punch_types[*]} ] \
145 || _fail "num punch points given does not equal num punch types"
147 # check a size is specified for each write
148 [ ${#write_points_blks[*]} -eq ${#write_sizes_blks[*]} ] \
149 || _fail "num write points given does not equal num write sizes"
151 # check punch_write_order operations match number of punches + writes
152 local total_pw_operations=`expr ${#punch_points_blks[*]} + ${#write_points_blks[*]}`
153 [ $total_pw_operations -eq ${#punch_write_order[*]} ] \
154 || _fail "punch_write_order ops doesn't match number of punches + writes"
156 # create the file and setup extent size hint
157 _spawn_test_file $blksize $file_size_blks $extsize_hint_blks $filename $resvsp
159 # do the writes and punches
163 for operation in "${punch_write_order[@]}"; do
164 if [ "$operation" == "p" ]; then
165 _do_punch $blksize ${punch_points_blks[$punch_index]} \
166 ${punch_sizes_blks[$punch_index]} ${punch_types[$punch_index]} \
168 punch_index=`expr $punch_index + 1`
170 if [ "$operation" == "w" ]; then
171 _do_write $blksize ${write_points_blks[$write_index]} \
172 ${write_sizes_blks[$write_index]} $filename
173 write_index=`expr $write_index + 1`
176 _do_bmap $filename # print out the state of the file
187 split(range, bounds, "[\\[ \\.\\]]");
191 if (type != prev_type) {
193 printf("%u]:%s\n", low - 1, prev_type);
194 printf("%u: [%u..", out_count++, low);
200 printf("%u]:%s\n", high, prev_type);
211 $5 ~ /0x[[:xdigit:]]*8[[:xdigit:]]{2}/ {
212 print $1, $2, "unwritten";
215 $5 ~ /0x[[:xdigit:]]+/ {
216 print $1, $2, "data";
221 # Filters fiemap output to only print the
222 # file offset column and whether or not
223 # it is an extent or a hole
224 _filter_hole_fiemap()
231 $5 ~ /0x[[:xdigit:]]+/ {
232 print $1, $2, "extent";
245 print $1, $2, "unwritten";
260 # test the different corner cases for zeroing a range:
263 # 2. into allocated space
264 # 3. into unwritten space
266 # 5. hole -> unwritten
268 # 7. data -> unwritten
269 # 8. unwritten -> hole
270 # 9. unwritten -> data
271 # 10. hole -> data -> hole
272 # 11. data -> hole -> data
273 # 12. unwritten -> data -> unwritten
274 # 13. data -> unwritten -> data
275 # 14. data -> hole @ EOF
276 # 15. data -> hole @ 0
277 # 16. data -> cache cold ->hole
278 # 17. data -> hole in single block file
280 # Test file is removed, created and sync'd between tests.
282 # Use -k flag to keep the file between tests. This will
283 # test the handling of pre-existing holes.
285 # Use the -d flag to not sync the file between tests.
286 # This will test the handling of delayed extents
288 # Use the -u flag to not run unwritten tests.
289 # This will eliminate some unnecessary information.
291 _test_generic_punch()
298 while getopts 'dku' OPTION
312 shift $(($OPTIND - 1))
316 zero_cmd=$3 #if not testing zero just set to punch
321 echo " 1. into a hole"
322 if [ "$remove_testfile" ]; then
325 $XFS_IO_PROG -f -c "truncate 20k" \
326 -c "$zero_cmd 4k 8k" \
327 -c "$map_cmd -v" $testfile | $filter_cmd
328 [ $? -ne 0 ] && die_now
329 _md5_checksum $testfile
331 echo " 2. into allocated space"
332 if [ "$remove_testfile" ]; then
335 $XFS_IO_PROG -f -c "truncate 20k" \
336 -c "pwrite 0 20k" $sync_cmd \
337 -c "$zero_cmd 4k 8k" \
338 -c "$map_cmd -v" $testfile | $filter_cmd
339 [ $? -ne 0 ] && die_now
340 _md5_checksum $testfile
342 if [ "$unwritten_tests" ]; then
343 echo " 3. into unwritten space"
344 if [ "$remove_testfile" ]; then
347 $XFS_IO_PROG -f -c "truncate 20k" \
348 -c "$alloc_cmd 0 20k" \
349 -c "$zero_cmd 4k 8k" \
350 -c "$map_cmd -v" $testfile | $filter_cmd
351 [ $? -ne 0 ] && die_now
352 _md5_checksum $testfile
355 echo " 4. hole -> data"
356 if [ "$remove_testfile" ]; then
359 $XFS_IO_PROG -f -c "truncate 20k" \
360 -c "pwrite 8k 8k" $sync_cmd \
361 -c "$zero_cmd 4k 8k" \
362 -c "$map_cmd -v" $testfile | $filter_cmd
363 [ $? -ne 0 ] && die_now
364 _md5_checksum $testfile
366 if [ "$unwritten_tests" ]; then
367 echo " 5. hole -> unwritten"
368 if [ "$remove_testfile" ]; then
371 $XFS_IO_PROG -f -c "truncate 20k" \
372 -c "$alloc_cmd 8k 8k" \
373 -c "$zero_cmd 4k 8k" \
374 -c "$map_cmd -v" $testfile | $filter_cmd
375 [ $? -ne 0 ] && die_now
376 _md5_checksum $testfile
379 echo " 6. data -> hole"
380 if [ "$remove_testfile" ]; then
383 $XFS_IO_PROG -f -c "truncate 20k" \
384 -c "pwrite 0 8k" $sync_cmd \
385 -c "$zero_cmd 4k 8k" \
386 -c "$map_cmd -v" $testfile | $filter_cmd
387 [ $? -ne 0 ] && die_now
388 _md5_checksum $testfile
390 if [ "$unwritten_tests" ]; then
391 echo " 7. data -> unwritten"
392 if [ "$remove_testfile" ]; then
395 $XFS_IO_PROG -f -c "truncate 20k" \
396 -c "pwrite 0 8k" $sync_cmd \
397 -c "$alloc_cmd 8k 8k" \
398 -c "$zero_cmd 4k 8k" \
399 -c "$map_cmd -v" $testfile | $filter_cmd
400 [ $? -ne 0 ] && die_now
401 _md5_checksum $testfile
403 echo " 8. unwritten -> hole"
404 if [ "$remove_testfile" ]; then
407 $XFS_IO_PROG -f -c "truncate 20k" \
408 -c "$alloc_cmd 0 8k" \
409 -c "$zero_cmd 4k 8k" \
410 -c "$map_cmd -v" $testfile | $filter_cmd
411 [ $? -ne 0 ] && die_now
412 _md5_checksum $testfile
414 echo " 9. unwritten -> data"
415 if [ "$remove_testfile" ]; then
418 $XFS_IO_PROG -f -c "truncate 20k" \
419 -c "$alloc_cmd 0 8k" \
420 -c "pwrite 8k 8k" $sync_cmd \
421 -c "$zero_cmd 4k 8k" \
422 -c "$map_cmd -v" $testfile | $filter_cmd
423 [ $? -ne 0 ] && die_now
424 _md5_checksum $testfile
427 echo " 10. hole -> data -> hole"
428 if [ "$remove_testfile" ]; then
431 $XFS_IO_PROG -f -c "truncate 20k" \
432 -c "pwrite 8k 4k" $sync_cmd \
433 -c "$zero_cmd 4k 12k" \
434 -c "$map_cmd -v" $testfile | $filter_cmd
435 [ $? -ne 0 ] && die_now
436 _md5_checksum $testfile
438 echo " 11. data -> hole -> data"
439 if [ "$remove_testfile" ]; then
442 $XFS_IO_PROG -f -c "truncate 20k" \
443 -c "$alloc_cmd 0 20k" \
445 -c "pwrite 12k 8k" $sync_cmd \
446 -c "$punch_cmd 8k 4k" \
447 -c "$zero_cmd 4k 12k" \
448 -c "$map_cmd -v" $testfile | $filter_cmd
449 [ $? -ne 0 ] && die_now
450 _md5_checksum $testfile
452 if [ "$unwritten_tests" ]; then
453 echo " 12. unwritten -> data -> unwritten"
454 if [ "$remove_testfile" ]; then
457 $XFS_IO_PROG -f -c "truncate 20k" \
458 -c "$alloc_cmd 0 20k" \
459 -c "pwrite 8k 4k" $sync_cmd \
460 -c "$zero_cmd 4k 12k" \
461 -c "$map_cmd -v" $testfile | $filter_cmd
462 [ $? -ne 0 ] && die_now
463 _md5_checksum $testfile
465 echo " 13. data -> unwritten -> data"
466 if [ "$remove_testfile" ]; then
469 $XFS_IO_PROG -f -c "truncate 20k" \
470 -c "$alloc_cmd 0 20k" \
471 -c "pwrite 0k 8k" $sync_cmd \
472 -c "pwrite 12k 8k" -c "fsync" \
473 -c "$zero_cmd 4k 12k" \
474 -c "$map_cmd -v" $testfile | $filter_cmd
475 [ $? -ne 0 ] && die_now
476 _md5_checksum $testfile
479 echo " 14. data -> hole @ EOF"
481 $XFS_IO_PROG -f -c "truncate 20k" \
482 -c "pwrite 0 20k" $sync_cmd \
483 -c "$zero_cmd 12k 8k" \
484 -c "$map_cmd -v" $testfile | $filter_cmd
485 [ $? -ne 0 ] && die_now
486 _md5_checksum $testfile
488 echo " 15. data -> hole @ 0"
489 if [ "$remove_testfile" ]; then
492 $XFS_IO_PROG -f -c "truncate 20k" \
493 -c "pwrite 0 20k" $sync_cmd \
494 -c "$zero_cmd 0k 8k" \
495 -c "$map_cmd -v" $testfile | $filter_cmd
496 [ $? -ne 0 ] && die_now
497 _md5_checksum $testfile
499 echo " 16. data -> cache cold ->hole"
500 if [ "$remove_testfile" ]; then
504 cp $testfile $testfile.2
506 $XFS_IO_PROG -f -c "truncate 20k" \
507 -c "pwrite 8k 12k" -c "fsync" $testfile.2 \
509 $XFS_IO_PROG -f -c "truncate 20k" \
510 -c "pwrite 0 20k" $sync_cmd \
511 -c "$zero_cmd 0k 8k" \
513 -c "$map_cmd -v" $testfile | $filter_cmd
514 diff $testfile $testfile.2
515 [ $? -ne 0 ] && die_now
517 _md5_checksum $testfile
519 echo " 17. data -> hole in single block file"
520 if [ "$remove_testfile" ]; then
523 block_size=`stat -f $TEST_DIR | grep "Block size" | cut -d " " -f3`
524 $XFS_IO_PROG -f -c "truncate $block_size" \
525 -c "pwrite 0 $block_size" $sync_cmd \
526 -c "$zero_cmd 128 128" \
527 -c "$map_cmd -v" $testfile | $filter_cmd
528 [ $? -ne 0 ] && die_now
529 _md5_checksum $testfile