2 # XFS specific common functions.
10 [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
11 [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
12 [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
14 # calculate the size of the file we need to allocate.
15 # Default free space in the FS is 50GB, but you can specify more via
16 # SCRATCH_DEV_EMPTY_SPACE
17 file_size=$(($fs_size - 50*1024*1024*1024))
18 file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
20 # mount the filesystem, create the file, unmount it
21 _try_scratch_mount 2>&1 >$tmp_dir/mnt.err
23 if [ $status -ne 0 ]; then
25 cat $tmp_dir/mnt.err >&2
26 rm -f $tmp_dir/mnt.err
29 rm -f $tmp_dir/mnt.err
32 -c "truncate $file_size" \
33 -c "falloc -k 0 $file_size" \
35 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
36 export NUM_SPACE_FILES=1
39 if [ $status -ne 0 ]; then
40 echo "large file prealloc failed"
41 cat $tmp_dir/mnt.err >&2
47 _scratch_mkfs_xfs_opts()
51 # remove metadata related mkfs options if mkfs.xfs doesn't them
52 if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
53 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+\S\+//g"`
58 echo "$MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts"
62 _scratch_mkfs_xfs_supported()
68 $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
71 # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
72 # $mkfs_opts, try again without $MKFS_OPTIONS
73 if [ $mkfs_status -ne 0 -a -n "$mkfs_opts" ]; then
74 $MKFS_XFS_PROG -N $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
80 # Returns the minimum XFS log size, in units of log blocks.
81 _scratch_find_xfs_min_logblocks()
83 local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
85 # The smallest log size we can specify is 2M (XFS_MIN_LOG_BYTES) so
86 # pass that in and see if mkfs succeeds or tells us what is the
88 local XFS_MIN_LOG_BYTES=2097152
90 # Try formatting the filesystem with all the options given and the
91 # minimum log size. We hope either that this succeeds or that mkfs
92 # tells us the required minimum log size for the feature set.
94 # We cannot use _scratch_do_mkfs because it will retry /any/ failed
95 # mkfs with MKFS_OPTIONS removed even if the only "failure" was that
96 # the log was too small.
97 local extra_mkfs_options="$* -N -l size=$XFS_MIN_LOG_BYTES"
98 eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
99 2>$tmp.mkfserr 1>$tmp.mkfsstd
102 # If the format fails for a reason other than the log being too small,
103 # try again without MKFS_OPTIONS because that's what _scratch_do_mkfs
104 # will do if we pass in the log size option.
105 if [ $mkfs_status -ne 0 ] &&
106 ! grep -q 'log size.*too small, minimum' $tmp.mkfserr; then
107 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
108 2>$tmp.mkfserr 1>$tmp.mkfsstd
112 # mkfs suceeded, so we must pick out the log block size to do the
114 if [ $mkfs_status -eq 0 ]; then
115 blksz="$(grep '^log.*bsize' $tmp.mkfsstd | \
116 sed -e 's/log.*bsize=\([0-9]*\).*$/\1/g')"
117 echo $((XFS_MIN_LOG_BYTES / blksz))
118 rm -f $tmp.mkfsstd $tmp.mkfserr
122 # Usually mkfs will tell us the minimum log size...
123 if grep -q 'minimum size is' $tmp.mkfserr; then
124 grep 'minimum size is' $tmp.mkfserr | \
125 sed -e 's/^.*minimum size is \([0-9]*\) blocks/\1/g'
126 rm -f $tmp.mkfsstd $tmp.mkfserr
130 # Don't know what to do, so fail
131 echo "Cannot determine minimum log size" >&2
132 cat $tmp.mkfsstd >> $seqres.full
133 cat $tmp.mkfserr >> $seqres.full
134 rm -f $tmp.mkfsstd $tmp.mkfserr
139 local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
140 local mkfs_filter="sed -e '/less than device physical sector/d' \
141 -e '/switching to logical sector/d' \
142 -e '/Default configuration/d'"
143 local tmp=`mktemp -u`
146 _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
149 grep -q crc=0 $tmp.mkfsstd && _force_xfsv4_mount_options
151 if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
152 # manually parse the mkfs output to get the fs size in bytes
154 fs_size=`cat $tmp.mkfsstd | perl -ne '
155 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
157 print STDOUT "$size\n";
159 _setup_large_xfs_fs $fs_size
163 # output mkfs stdout and stderr
166 rm -f $tmp.mkfserr $tmp.mkfsstd
171 # xfs_check script is planned to be deprecated. But, we want to
172 # be able to invoke "xfs_check" behavior in xfstests in order to
173 # maintain the current verification levels.
178 USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
181 while getopts "b:fi:l:stvV" c; do
186 i) OPTS=$OPTS"-i "$OPTARG" ";;
187 b) OPTS=$OPTS"-b "$OPTARG" ";;
188 f) DBOPTS=$DBOPTS" -f";;
189 l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
190 V) $XFS_DB_PROG -p xfs_check -V
198 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
208 _scratch_xfs_db_options()
211 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
212 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
213 echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
218 $XFS_DB_PROG "$@" $(_scratch_xfs_db_options)
221 _scratch_xfs_logprint()
224 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
225 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
226 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
232 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
233 TEST_OPTIONS="-l$TEST_LOGDEV"
234 $XFS_LOGPRINT_PROG $TEST_OPTIONS $* $TEST_DEV
240 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
241 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
242 [ "$LARGE_SCRATCH_DEV" = yes ] && \
243 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
244 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
247 _scratch_xfs_repair()
250 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
251 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
252 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
253 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
254 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
257 # this test requires the projid32bit feature to be available in mkfs.xfs.
259 _require_projid32bit()
261 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
262 || _notrun "mkfs.xfs doesn't have projid32bit feature"
265 _require_projid16bit()
267 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
268 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
271 # this test requires the crc feature to be available in mkfs.xfs
273 _require_xfs_mkfs_crc()
275 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
276 || _notrun "mkfs.xfs doesn't have crc feature"
279 # this test requires the xfs kernel support crc feature
283 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
284 _try_scratch_mount >/dev/null 2>&1 \
285 || _notrun "Kernel doesn't support crc feature"
289 # this test requires the xfs kernel support crc feature on scratch device
291 _require_scratch_xfs_crc()
293 _scratch_mkfs_xfs >/dev/null 2>&1
294 _try_scratch_mount >/dev/null 2>&1 \
295 || _notrun "Kernel doesn't support crc feature"
296 $XFS_INFO_PROG $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
300 # this test requires the finobt feature to be available in mkfs.xfs
302 _require_xfs_mkfs_finobt()
304 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
305 || _notrun "mkfs.xfs doesn't have finobt feature"
308 # this test requires the xfs kernel support finobt feature
310 _require_xfs_finobt()
312 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
313 _try_scratch_mount >/dev/null 2>&1 \
314 || _notrun "Kernel doesn't support finobt feature"
318 # this test requires xfs sysfs attribute support
325 if [ ! -e $sysfsdir ]; then
326 _notrun "no kernel support for XFS sysfs attributes"
329 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
330 _notrun "sysfs attribute '$attr' is not supported"
334 # this test requires the xfs sparse inode feature
336 _require_xfs_sparse_inodes()
338 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
339 || _notrun "mkfs.xfs does not support sparse inodes"
340 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
341 _try_scratch_mount >/dev/null 2>&1 \
342 || _notrun "kernel does not support sparse inodes"
346 # check that xfs_db supports a specific command
347 _require_xfs_db_command()
349 if [ $# -ne 1 ]; then
350 echo "Usage: _require_xfs_db_command command" 1>&2
355 _scratch_mkfs_xfs >/dev/null 2>&1
356 _scratch_xfs_db -x -c "help" | grep $command > /dev/null || \
357 _notrun "xfs_db $command support is missing"
360 # Does the filesystem mounted from a particular device support scrub?
361 _supports_xfs_scrub()
363 local mountpoint="$1"
366 if [ -z "$device" ] || [ -z "$mountpoint" ]; then
367 echo "Usage: _supports_xfs_scrub mountpoint device"
371 if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
375 test "$FSTYP" = "xfs" || return 1
376 test -x "$XFS_SCRUB_PROG" || return 1
378 # Probe for kernel support...
379 $XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1
380 $XFS_IO_PROG -c "scrub probe" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
382 # Scrub can't run on norecovery mounts
383 _fs_options "$device" | grep -q "norecovery" && return 1
388 # run xfs_check and friends on a FS.
389 _check_xfs_filesystem()
391 if [ $# -ne 3 ]; then
392 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
396 extra_mount_options=""
400 if [ -f $device ]; then
404 if [ "$2" != "none" ]; then
405 extra_log_options="-l$2"
406 extra_mount_options="-ologdev=$2"
409 if [ "$3" != "none" ]; then
410 extra_rt_options="-r$3"
411 extra_mount_options=$extra_mount_options" -ortdev=$3"
413 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
415 [ "$FSTYP" != xfs ] && return 0
417 type=`_fs_type $device`
420 # Run online scrub if we can.
421 mntpt="$(_is_dev_mounted $device)"
422 if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
423 "$XFS_SCRUB_PROG" $scrubflag -v -d -n $mntpt > $tmp.scrub 2>&1
424 if [ $? -ne 0 ]; then
425 _log_err "_check_xfs_filesystem: filesystem on $device failed scrub"
426 echo "*** xfs_scrub $scrubflag -v -d -n output ***" >> $seqres.full
427 cat $tmp.scrub >> $seqres.full
428 echo "*** end xfs_scrub output" >> $serqres.full
434 if [ "$type" = "xfs" ]; then
436 mountpoint=`_umount_or_remount_ro $device`
439 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
440 | tee $tmp.logprint | grep -q "<CLEAN>"
441 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]; then
442 _log_err "_check_xfs_filesystem: filesystem on $device has dirty log"
443 echo "*** xfs_logprint -t output ***" >>$seqres.full
444 cat $tmp.logprint >>$seqres.full
445 echo "*** end xfs_logprint output" >>$seqres.full
450 # xfs_check runs out of memory on large files, so even providing the test
451 # option (-t) to avoid indexing the free space trees doesn't make it pass on
452 # large filesystems. Avoid it.
453 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
454 _xfs_check $extra_log_options $device 2>&1 > $tmp.fs_check
456 if [ -s $tmp.fs_check ]; then
457 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (c)"
458 echo "*** xfs_check output ***" >>$seqres.full
459 cat $tmp.fs_check >>$seqres.full
460 echo "*** end xfs_check output" >>$seqres.full
465 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
466 if [ $? -ne 0 ]; then
467 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (r)"
468 echo "*** xfs_repair -n output ***" >>$seqres.full
469 cat $tmp.repair >>$seqres.full
470 echo "*** end xfs_repair output" >>$seqres.full
474 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
476 # Optionally test the index rebuilding behavior.
477 if [ -n "$TEST_XFS_REPAIR_REBUILD" ]; then
478 $XFS_REPAIR_PROG $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
479 if [ $? -ne 0 ]; then
480 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)"
481 echo "*** xfs_repair output ***" >>$seqres.full
482 cat $tmp.repair >>$seqres.full
483 echo "*** end xfs_repair output" >>$seqres.full
489 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
490 if [ $? -ne 0 ]; then
491 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify)"
492 echo "*** xfs_repair -n output ***" >>$seqres.full
493 cat $tmp.repair >>$seqres.full
494 echo "*** end xfs_repair output" >>$seqres.full
501 if [ $ok -eq 0 ]; then
502 echo "*** mount output ***" >>$seqres.full
503 _mount >>$seqres.full
504 echo "*** end mount output" >>$seqres.full
505 elif [ "$type" = "xfs" ]; then
506 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
509 if [ $ok -eq 0 ]; then
511 if [ "$iam" != "check" ]; then
524 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
525 TEST_LOG="$TEST_LOGDEV"
527 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
528 TEST_RT="$TEST_RTDEV"
530 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
534 _require_xfs_test_rmapbt()
538 if [ "$($XFS_INFO_PROG "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
539 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
543 _require_xfs_scratch_rmapbt()
547 _scratch_mkfs > /dev/null
549 if [ "$($XFS_INFO_PROG "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
551 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
573 $XFS_IO_PROG -c "bmap -${param}lpv" "$file" | grep -c "$@"
576 # Reset all xfs error handling attributes, set them to original
579 # Only one argument, and it's mandatory:
580 # - dev: device name, e.g. $SCRATCH_DEV
582 # Note: this function only works for XFS
583 _reset_xfs_sysfs_error_handling()
587 if [ ! -b "$dev" -o "$FSTYP" != "xfs" ]; then
588 _fail "Usage: reset_xfs_sysfs_error_handling <device>"
591 _set_fs_sysfs_attr $dev error/fail_at_unmount 1
592 echo -n "error/fail_at_unmount="
593 _get_fs_sysfs_attr $dev error/fail_at_unmount
595 # Make sure all will be configured to retry forever by default, except
596 # for ENODEV, which is an unrecoverable error, so it will be configured
597 # to not retry on error by default.
598 for e in default EIO ENOSPC; do
599 _set_fs_sysfs_attr $dev \
600 error/metadata/${e}/max_retries -1
601 echo -n "error/metadata/${e}/max_retries="
602 _get_fs_sysfs_attr $dev error/metadata/${e}/max_retries
604 _set_fs_sysfs_attr $dev \
605 error/metadata/${e}/retry_timeout_seconds 0
606 echo -n "error/metadata/${e}/retry_timeout_seconds="
607 _get_fs_sysfs_attr $dev \
608 error/metadata/${e}/retry_timeout_seconds
612 # Skip if we are running an older binary without the stricter input checks.
613 # Make multiple checks to be sure that there is no regression on the one
614 # selected feature check, which would skew the result.
616 # At first, make a common function that runs the tests and returns
617 # number of failed cases.
618 _xfs_mkfs_validation_check()
620 local tmpfile=`mktemp`
621 local cmd="$MKFS_XFS_PROG -f -N -d file,name=$tmpfile,size=1g"
623 $cmd -s size=8s >/dev/null 2>&1
626 $cmd -l version=2,su=260k >/dev/null 2>&1
633 # Skip the test if all calls passed - mkfs accepts invalid input
634 _require_xfs_mkfs_validation()
636 _xfs_mkfs_validation_check
637 if [ "$?" -eq 0 ]; then
638 _notrun "Requires newer mkfs with stricter input checks: the oldest supported version of xfsprogs is 4.7."
642 # The opposite of _require_xfs_mkfs_validation.
643 _require_xfs_mkfs_without_validation()
645 _xfs_mkfs_validation_check
646 if [ "$?" -ne 0 ]; then
647 _notrun "Requires older mkfs without strict input checks: the last supported version of xfsprogs is 4.5."
651 # XFS ability to change UUIDs on V5/CRC filesystems
655 # This will create a crc fs on $SCRATCH_DEV
658 _scratch_xfs_db -x -c "uuid restore" 2>&1 \
659 | grep -q "invalid UUID\|supported on V5 fs" \
660 && _notrun "Userspace doesn't support meta_uuid feature"
662 _scratch_xfs_db -x -c "uuid generate" >/dev/null 2>&1
664 _try_scratch_mount >/dev/null 2>&1 \
665 || _notrun "Kernel doesn't support meta_uuid feature"
669 # this test requires mkfs.xfs have case-insensitive naming support
670 _require_xfs_mkfs_ciname()
672 _scratch_mkfs_xfs_supported -n version=ci >/dev/null 2>&1 \
673 || _notrun "need case-insensitive naming support in mkfs.xfs"
676 # XFS_DEBUG requirements
679 if grep -q "debug 0" /proc/fs/xfs/stat; then
680 _notrun "Require XFS built with CONFIG_XFS_DEBUG"
683 _require_no_xfs_debug()
685 if grep -q "debug 1" /proc/fs/xfs/stat; then
686 _notrun "Require XFS built without CONFIG_XFS_DEBUG"
690 # Require that assertions will not crash the system.
692 # Assertions would always crash the system if XFS assert fatal was enabled
693 # (CONFIG_XFS_ASSERT_FATAL=y). If a test is designed to trigger an assertion,
694 # skip the test on a CONFIG_XFS_ASSERT_FATAL built XFS by default. Note:
695 # CONFIG_XFS_ASSERT_FATAL can be disabled by setting bug_on_assert to zero if
696 # we want test to run.
697 _require_no_xfs_bug_on_assert()
699 if [ -f /sys/fs/xfs/debug/bug_on_assert ]; then
700 grep -q "1" /sys/fs/xfs/debug/bug_on_assert && \
701 _notrun "test requires XFS bug_on_assert to be off, turn it off to run the test"
703 # Note: Prior to the creation of CONFIG_XFS_ASSERT_FATAL (and
704 # the sysfs knob bug_on_assert), assertions would always crash
705 # the system if XFS debug was enabled (CONFIG_XFS_DEBUG=y). If
706 # a test is designed to trigger an assertion and the test
707 # designer does not want to hang fstests, skip the test.
708 _require_no_xfs_debug
712 # Get a metadata field
713 # The first arg is the field name
714 # The rest of the arguments are xfs_db commands to find the metadata.
715 _scratch_xfs_get_metadata_field()
720 local grep_key="$(echo "${key}" | tr '[]()' '....')"
724 cmds+=("-c" "${arg}")
726 _scratch_xfs_db "${cmds[@]}" -c "print ${key}" | grep "^${grep_key}" | \
730 # Set a metadata field
731 # The first arg is the field name
732 # The second arg is the new value
733 # The rest of the arguments are xfs_db commands to find the metadata.
734 _scratch_xfs_set_metadata_field()
743 cmds+=("-c" "${arg}")
747 _scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- ${value}"
748 _scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
749 _scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"
752 _scratch_xfs_get_sb_field()
754 _scratch_xfs_get_metadata_field "$1" "sb 0"
757 _scratch_xfs_set_sb_field()
759 _scratch_xfs_set_metadata_field "$1" "$2" "sb 0"
762 # Before xfsprogs commit 4222d000ed("db: write via array indexing doesn't
763 # work"), xfs_db command to write a specific AGFL index doesn't work. It's a
764 # bug in a diagnostic tool that is only used by XFS developers as a test
765 # infrastructure, so it's fine to treat it as a infrastructure dependency as
766 # all other _require rules.
767 _require_xfs_db_write_array()
772 touch $TEST_DIR/$seq.img
773 $MKFS_XFS_PROG -d file,name=$TEST_DIR/$seq.img,size=512m >/dev/null 2>&1
774 $XFS_DB_PROG -x -c "agfl 0" -c "write bno[32] 78" $TEST_DIR/$seq.img \
776 $XFS_DB_PROG -x -c "agfl 0" -c "print bno[32]" $TEST_DIR/$seq.img \
777 | grep -q "bno\[32\] = 78" && supported=1
778 rm -f $TEST_DIR/$seq.img
779 [ $supported -eq 0 ] && _notrun "xfs_db write can't support array"
782 _require_xfs_spaceman_command()
785 echo "Usage: _require_xfs_spaceman_command command [switch]" 1>&2
791 local param_checked=0
794 _require_command "$XFS_SPACEMAN_PROG" "xfs_spaceman"
796 testfile=$TEST_DIR/$$.xfs_spaceman
800 testio=`$XFS_SPACEMAN_PROG -c "health $param" $TEST_DIR 2>&1`
804 testio=`$XFS_SPACEMAN_PROG -c "help $command" $TEST_DIR 2>&1`
807 rm -f $testfile 2>&1 > /dev/null
808 echo $testio | grep -q "not found" && \
809 _notrun "xfs_spaceman $command support is missing"
810 echo $testio | grep -q "Operation not supported" && \
811 _notrun "xfs_spaceman $command failed (old kernel/wrong fs?)"
812 echo $testio | grep -q "Invalid" && \
813 _notrun "xfs_spaceman $command failed (old kernel/wrong fs/bad args?)"
814 echo $testio | grep -q "foreign file active" && \
815 _notrun "xfs_spaceman $command not supported on $FSTYP"
816 echo $testio | grep -q "Inappropriate ioctl for device" && \
817 _notrun "xfs_spaceman $command support is missing (missing ioctl?)"
818 echo $testio | grep -q "Function not implemented" && \
819 _notrun "xfs_spaceman $command support is missing (missing syscall?)"
821 [ -n "$param" ] || return
823 if [ $param_checked -eq 0 ]; then
824 $XFS_SPACEMAN_PROG -c "help $command" | grep -q "^ $param --" || \
825 _notrun "xfs_spaceman $command doesn't support $param"
829 _scratch_get_sfdir_prefix() {
832 for prefix in "u.sfdir3" "u.sfdir2" "u3.sfdir3"; do
833 if [ -n "$(_scratch_xfs_get_metadata_field \
834 "${prefix}.hdr.parent.i4" \
835 "inode ${dir_ino}")" ]; then
840 _scratch_xfs_db -c "inode ${dir_ino}" -c 'p' >> $seqres.full
844 _scratch_get_bmx_prefix() {
847 for prefix in "u3.bmx" "u.bmx"; do
848 if [ -n "$(_scratch_xfs_get_metadata_field \
849 "${prefix}[0].startblock" \
850 "inode ${ino}")" ]; then
855 _scratch_xfs_db -c "inode ${ino}" -c 'p' >> $seqres.full
860 # Ensures that we don't pass any mount options incompatible with XFS v4
862 _force_xfsv4_mount_options()
867 # Can't have group and project quotas in XFS v4
868 echo "$MOUNT_OPTIONS" | egrep -q "(gquota|grpquota|grpjquota=|gqnoenforce)" && gquota=1
869 echo "$MOUNT_OPTIONS" | egrep -q "(\bpquota|prjquota|pqnoenforce)" && pquota=1
871 if [ $gquota -gt 0 ] && [ $pquota -gt 0 ]; then
872 export MOUNT_OPTIONS=$(echo $MOUNT_OPTIONS \
873 | sed -e 's/gquota/QUOTA/g' \
874 -e 's/grpquota/QUOTA/g' \
875 -e 's/grpjquota=[^, ]/QUOTA/g' \
876 -e 's/gqnoenforce/QUOTA/g' \
877 -e "s/QUOTA/defaults/g")
879 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seqres.full
882 # Find AG count of mounted filesystem
885 $XFS_INFO_PROG "$1" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g'
888 # Wipe the superblock of each XFS AGs
889 _try_wipe_scratch_xfs()
896 # Try to wipe each SB if there's an existed XFS
897 agcount=`_scratch_xfs_get_sb_field agcount 2>/dev/null`
898 agsize=`_scratch_xfs_get_sb_field agblocks 2>/dev/null`
899 dbsize=`_scratch_xfs_get_sb_field blocksize 2>/dev/null`
900 if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then
901 for ((i = 0; i < agcount; i++)); do
902 $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \
903 $SCRATCH_DEV >/dev/null;
907 # Try to wipe each SB by default mkfs.xfs geometry
908 local tmp=`mktemp -u`
909 unset agcount agsize dbsize
910 _scratch_mkfs_xfs -N 2>/dev/null | perl -ne '
911 if (/^meta-data=.*\s+agcount=(\d+), agsize=(\d+) blks/) {
912 print STDOUT "agcount=$1\nagsize=$2\n";
914 if (/^data\s+=\s+bsize=(\d+)\s/) {
915 print STDOUT "dbsize=$1\n";
919 if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then
920 for ((i = 0; i < agcount; i++)); do
921 $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \
922 $SCRATCH_DEV >/dev/null;