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)
223 local options=("$SCRATCH_DEV")
224 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
225 options+=("$SCRATCH_LOGDEV")
226 $XFS_ADMIN_PROG "$@" "${options[@]}"
229 _scratch_xfs_logprint()
232 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
233 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
234 $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
240 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
241 TEST_OPTIONS="-l$TEST_LOGDEV"
242 $XFS_LOGPRINT_PROG $TEST_OPTIONS $* $TEST_DEV
248 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
249 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
250 [ "$LARGE_SCRATCH_DEV" = yes ] && \
251 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
252 _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
255 _scratch_xfs_repair()
258 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
259 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
260 [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
261 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
262 $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
265 # this test requires the projid32bit feature to be available in mkfs.xfs.
267 _require_projid32bit()
269 _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
270 || _notrun "mkfs.xfs doesn't have projid32bit feature"
273 _require_projid16bit()
275 _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
276 || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
279 # this test requires the crc feature to be available in mkfs.xfs
281 _require_xfs_mkfs_crc()
283 _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
284 || _notrun "mkfs.xfs doesn't have crc feature"
287 # this test requires the xfs kernel support crc feature
291 _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
292 _try_scratch_mount >/dev/null 2>&1 \
293 || _notrun "Kernel doesn't support crc feature"
297 # this test requires the xfs kernel support crc feature on scratch device
299 _require_scratch_xfs_crc()
301 _scratch_mkfs_xfs >/dev/null 2>&1
302 _try_scratch_mount >/dev/null 2>&1 \
303 || _notrun "Kernel doesn't support crc feature"
304 $XFS_INFO_PROG $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
308 # this test requires the finobt feature to be available in mkfs.xfs
310 _require_xfs_mkfs_finobt()
312 _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
313 || _notrun "mkfs.xfs doesn't have finobt feature"
316 # this test requires the xfs kernel support finobt feature
318 _require_xfs_finobt()
320 _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
321 _try_scratch_mount >/dev/null 2>&1 \
322 || _notrun "Kernel doesn't support finobt feature"
326 # this test requires xfs sysfs attribute support
333 if [ ! -e $sysfsdir ]; then
334 _notrun "no kernel support for XFS sysfs attributes"
337 if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
338 _notrun "sysfs attribute '$attr' is not supported"
342 # this test requires the xfs sparse inode feature
344 _require_xfs_sparse_inodes()
346 _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
347 || _notrun "mkfs.xfs does not support sparse inodes"
348 _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
349 _try_scratch_mount >/dev/null 2>&1 \
350 || _notrun "kernel does not support sparse inodes"
354 # check that xfs_db supports a specific command
355 _require_xfs_db_command()
357 if [ $# -ne 1 ]; then
358 echo "Usage: _require_xfs_db_command command" 1>&2
363 _scratch_mkfs_xfs >/dev/null 2>&1
364 _scratch_xfs_db -x -c "help" | grep $command > /dev/null || \
365 _notrun "xfs_db $command support is missing"
368 # Does the filesystem mounted from a particular device support scrub?
369 _supports_xfs_scrub()
371 local mountpoint="$1"
374 if [ -z "$device" ] || [ -z "$mountpoint" ]; then
375 echo "Usage: _supports_xfs_scrub mountpoint device"
379 if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
383 test "$FSTYP" = "xfs" || return 1
384 test -x "$XFS_SCRUB_PROG" || return 1
386 # Probe for kernel support...
387 $XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1
388 $XFS_IO_PROG -c "scrub probe" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
390 # Scrub can't run on norecovery mounts
391 _fs_options "$device" | grep -q "norecovery" && return 1
396 # run xfs_check and friends on a FS.
397 _check_xfs_filesystem()
399 if [ $# -ne 3 ]; then
400 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
404 extra_mount_options=""
408 if [ -f $device ]; then
412 if [ "$2" != "none" ]; then
413 extra_log_options="-l$2"
414 extra_mount_options="-ologdev=$2"
417 if [ "$3" != "none" ]; then
418 extra_rt_options="-r$3"
419 extra_mount_options=$extra_mount_options" -ortdev=$3"
421 extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
423 [ "$FSTYP" != xfs ] && return 0
425 type=`_fs_type $device`
428 # Run online scrub if we can.
429 mntpt="$(_is_dev_mounted $device)"
430 if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
431 "$XFS_SCRUB_PROG" $scrubflag -v -d -n $mntpt > $tmp.scrub 2>&1
432 if [ $? -ne 0 ]; then
433 _log_err "_check_xfs_filesystem: filesystem on $device failed scrub"
434 echo "*** xfs_scrub $scrubflag -v -d -n output ***" >> $seqres.full
435 cat $tmp.scrub >> $seqres.full
436 echo "*** end xfs_scrub output" >> $serqres.full
442 if [ "$type" = "xfs" ]; then
444 mountpoint=`_umount_or_remount_ro $device`
447 $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
448 | tee $tmp.logprint | grep -q "<CLEAN>"
449 if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]; then
450 _log_err "_check_xfs_filesystem: filesystem on $device has dirty log"
451 echo "*** xfs_logprint -t output ***" >>$seqres.full
452 cat $tmp.logprint >>$seqres.full
453 echo "*** end xfs_logprint output" >>$seqres.full
458 # xfs_check runs out of memory on large files, so even providing the test
459 # option (-t) to avoid indexing the free space trees doesn't make it pass on
460 # large filesystems. Avoid it.
461 if [ "$LARGE_SCRATCH_DEV" != yes ]; then
462 _xfs_check $extra_log_options $device 2>&1 > $tmp.fs_check
464 if [ -s $tmp.fs_check ]; then
465 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (c)"
466 echo "*** xfs_check output ***" >>$seqres.full
467 cat $tmp.fs_check >>$seqres.full
468 echo "*** end xfs_check output" >>$seqres.full
473 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
474 if [ $? -ne 0 ]; then
475 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (r)"
476 echo "*** xfs_repair -n output ***" >>$seqres.full
477 cat $tmp.repair >>$seqres.full
478 echo "*** end xfs_repair output" >>$seqres.full
482 rm -f $tmp.fs_check $tmp.logprint $tmp.repair
484 # Optionally test the index rebuilding behavior.
485 if [ -n "$TEST_XFS_REPAIR_REBUILD" ]; then
486 $XFS_REPAIR_PROG $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
487 if [ $? -ne 0 ]; then
488 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)"
489 echo "*** xfs_repair output ***" >>$seqres.full
490 cat $tmp.repair >>$seqres.full
491 echo "*** end xfs_repair output" >>$seqres.full
497 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
498 if [ $? -ne 0 ]; then
499 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify)"
500 echo "*** xfs_repair -n output ***" >>$seqres.full
501 cat $tmp.repair >>$seqres.full
502 echo "*** end xfs_repair output" >>$seqres.full
509 if [ $ok -eq 0 ]; then
510 echo "*** mount output ***" >>$seqres.full
511 _mount >>$seqres.full
512 echo "*** end mount output" >>$seqres.full
513 elif [ "$type" = "xfs" ]; then
514 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
517 if [ $ok -eq 0 ]; then
519 if [ "$iam" != "check" ]; then
532 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
533 TEST_LOG="$TEST_LOGDEV"
535 [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
536 TEST_RT="$TEST_RTDEV"
538 _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
542 _require_xfs_test_rmapbt()
546 if [ "$($XFS_INFO_PROG "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
547 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
551 _require_xfs_scratch_rmapbt()
555 _scratch_mkfs > /dev/null
557 if [ "$($XFS_INFO_PROG "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
559 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
581 $XFS_IO_PROG -c "bmap -${param}lpv" "$file" | grep -c "$@"
584 # Reset all xfs error handling attributes, set them to original
587 # Only one argument, and it's mandatory:
588 # - dev: device name, e.g. $SCRATCH_DEV
590 # Note: this function only works for XFS
591 _reset_xfs_sysfs_error_handling()
595 if [ ! -b "$dev" -o "$FSTYP" != "xfs" ]; then
596 _fail "Usage: reset_xfs_sysfs_error_handling <device>"
599 _set_fs_sysfs_attr $dev error/fail_at_unmount 1
600 echo -n "error/fail_at_unmount="
601 _get_fs_sysfs_attr $dev error/fail_at_unmount
603 # Make sure all will be configured to retry forever by default, except
604 # for ENODEV, which is an unrecoverable error, so it will be configured
605 # to not retry on error by default.
606 for e in default EIO ENOSPC; do
607 _set_fs_sysfs_attr $dev \
608 error/metadata/${e}/max_retries -1
609 echo -n "error/metadata/${e}/max_retries="
610 _get_fs_sysfs_attr $dev error/metadata/${e}/max_retries
612 _set_fs_sysfs_attr $dev \
613 error/metadata/${e}/retry_timeout_seconds 0
614 echo -n "error/metadata/${e}/retry_timeout_seconds="
615 _get_fs_sysfs_attr $dev \
616 error/metadata/${e}/retry_timeout_seconds
620 # Skip if we are running an older binary without the stricter input checks.
621 # Make multiple checks to be sure that there is no regression on the one
622 # selected feature check, which would skew the result.
624 # At first, make a common function that runs the tests and returns
625 # number of failed cases.
626 _xfs_mkfs_validation_check()
628 local tmpfile=`mktemp`
629 local cmd="$MKFS_XFS_PROG -f -N -d file,name=$tmpfile,size=1g"
631 $cmd -s size=8s >/dev/null 2>&1
634 $cmd -l version=2,su=260k >/dev/null 2>&1
641 # Skip the test if all calls passed - mkfs accepts invalid input
642 _require_xfs_mkfs_validation()
644 _xfs_mkfs_validation_check
645 if [ "$?" -eq 0 ]; then
646 _notrun "Requires newer mkfs with stricter input checks: the oldest supported version of xfsprogs is 4.7."
650 # The opposite of _require_xfs_mkfs_validation.
651 _require_xfs_mkfs_without_validation()
653 _xfs_mkfs_validation_check
654 if [ "$?" -ne 0 ]; then
655 _notrun "Requires older mkfs without strict input checks: the last supported version of xfsprogs is 4.5."
659 # XFS ability to change UUIDs on V5/CRC filesystems
663 # This will create a crc fs on $SCRATCH_DEV
666 _scratch_xfs_db -x -c "uuid restore" 2>&1 \
667 | grep -q "invalid UUID\|supported on V5 fs" \
668 && _notrun "Userspace doesn't support meta_uuid feature"
670 _scratch_xfs_db -x -c "uuid generate" >/dev/null 2>&1
672 _try_scratch_mount >/dev/null 2>&1 \
673 || _notrun "Kernel doesn't support meta_uuid feature"
677 # this test requires mkfs.xfs have case-insensitive naming support
678 _require_xfs_mkfs_ciname()
680 _scratch_mkfs_xfs_supported -n version=ci >/dev/null 2>&1 \
681 || _notrun "need case-insensitive naming support in mkfs.xfs"
684 # XFS_DEBUG requirements
687 if grep -q "debug 0" /proc/fs/xfs/stat; then
688 _notrun "Require XFS built with CONFIG_XFS_DEBUG"
691 _require_no_xfs_debug()
693 if grep -q "debug 1" /proc/fs/xfs/stat; then
694 _notrun "Require XFS built without CONFIG_XFS_DEBUG"
698 # Require that assertions will not crash the system.
700 # Assertions would always crash the system if XFS assert fatal was enabled
701 # (CONFIG_XFS_ASSERT_FATAL=y). If a test is designed to trigger an assertion,
702 # skip the test on a CONFIG_XFS_ASSERT_FATAL built XFS by default. Note:
703 # CONFIG_XFS_ASSERT_FATAL can be disabled by setting bug_on_assert to zero if
704 # we want test to run.
705 _require_no_xfs_bug_on_assert()
707 if [ -f /sys/fs/xfs/debug/bug_on_assert ]; then
708 grep -q "1" /sys/fs/xfs/debug/bug_on_assert && \
709 _notrun "test requires XFS bug_on_assert to be off, turn it off to run the test"
711 # Note: Prior to the creation of CONFIG_XFS_ASSERT_FATAL (and
712 # the sysfs knob bug_on_assert), assertions would always crash
713 # the system if XFS debug was enabled (CONFIG_XFS_DEBUG=y). If
714 # a test is designed to trigger an assertion and the test
715 # designer does not want to hang fstests, skip the test.
716 _require_no_xfs_debug
720 # Get a metadata field
721 # The first arg is the field name
722 # The rest of the arguments are xfs_db commands to find the metadata.
723 _scratch_xfs_get_metadata_field()
728 local grep_key="$(echo "${key}" | tr '[]()' '....')"
732 cmds+=("-c" "${arg}")
734 _scratch_xfs_db "${cmds[@]}" -c "print ${key}" | grep "^${grep_key}" | \
738 # Set a metadata field
739 # The first arg is the field name
740 # The second arg is the new value
741 # The rest of the arguments are xfs_db commands to find the metadata.
742 _scratch_xfs_set_metadata_field()
751 cmds+=("-c" "${arg}")
755 _scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- ${value}"
756 _scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
757 _scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"
760 _scratch_xfs_get_sb_field()
762 _scratch_xfs_get_metadata_field "$1" "sb 0"
765 _scratch_xfs_set_sb_field()
767 _scratch_xfs_set_metadata_field "$1" "$2" "sb 0"
770 # Before xfsprogs commit 4222d000ed("db: write via array indexing doesn't
771 # work"), xfs_db command to write a specific AGFL index doesn't work. It's a
772 # bug in a diagnostic tool that is only used by XFS developers as a test
773 # infrastructure, so it's fine to treat it as a infrastructure dependency as
774 # all other _require rules.
775 _require_xfs_db_write_array()
780 touch $TEST_DIR/$seq.img
781 $MKFS_XFS_PROG -d file,name=$TEST_DIR/$seq.img,size=512m >/dev/null 2>&1
782 $XFS_DB_PROG -x -c "agfl 0" -c "write bno[32] 78" $TEST_DIR/$seq.img \
784 $XFS_DB_PROG -x -c "agfl 0" -c "print bno[32]" $TEST_DIR/$seq.img \
785 | grep -q "bno\[32\] = 78" && supported=1
786 rm -f $TEST_DIR/$seq.img
787 [ $supported -eq 0 ] && _notrun "xfs_db write can't support array"
790 _require_xfs_spaceman_command()
793 echo "Usage: _require_xfs_spaceman_command command [switch]" 1>&2
799 local param_checked=0
802 _require_command "$XFS_SPACEMAN_PROG" "xfs_spaceman"
804 testfile=$TEST_DIR/$$.xfs_spaceman
808 testio=`$XFS_SPACEMAN_PROG -c "health $param" $TEST_DIR 2>&1`
812 testio=`$XFS_SPACEMAN_PROG -c "help $command" $TEST_DIR 2>&1`
815 rm -f $testfile 2>&1 > /dev/null
816 echo $testio | grep -q "not found" && \
817 _notrun "xfs_spaceman $command support is missing"
818 echo $testio | grep -q "Operation not supported" && \
819 _notrun "xfs_spaceman $command failed (old kernel/wrong fs?)"
820 echo $testio | grep -q "Invalid" && \
821 _notrun "xfs_spaceman $command failed (old kernel/wrong fs/bad args?)"
822 echo $testio | grep -q "foreign file active" && \
823 _notrun "xfs_spaceman $command not supported on $FSTYP"
824 echo $testio | grep -q "Inappropriate ioctl for device" && \
825 _notrun "xfs_spaceman $command support is missing (missing ioctl?)"
826 echo $testio | grep -q "Function not implemented" && \
827 _notrun "xfs_spaceman $command support is missing (missing syscall?)"
829 [ -n "$param" ] || return
831 if [ $param_checked -eq 0 ]; then
832 $XFS_SPACEMAN_PROG -c "help $command" | grep -q "^ $param --" || \
833 _notrun "xfs_spaceman $command doesn't support $param"
837 _scratch_get_sfdir_prefix() {
840 for prefix in "u.sfdir3" "u.sfdir2" "u3.sfdir3"; do
841 if [ -n "$(_scratch_xfs_get_metadata_field \
842 "${prefix}.hdr.parent.i4" \
843 "inode ${dir_ino}")" ]; then
848 _scratch_xfs_db -c "inode ${dir_ino}" -c 'p' >> $seqres.full
852 _scratch_get_bmx_prefix() {
855 for prefix in "u3.bmx" "u.bmx"; do
856 if [ -n "$(_scratch_xfs_get_metadata_field \
857 "${prefix}[0].startblock" \
858 "inode ${ino}")" ]; then
863 _scratch_xfs_db -c "inode ${ino}" -c 'p' >> $seqres.full
868 # Ensures that we don't pass any mount options incompatible with XFS v4
870 _force_xfsv4_mount_options()
875 # Can't have group and project quotas in XFS v4
876 echo "$MOUNT_OPTIONS" | egrep -q "(gquota|grpquota|grpjquota=|gqnoenforce)" && gquota=1
877 echo "$MOUNT_OPTIONS" | egrep -q "(\bpquota|prjquota|pqnoenforce)" && pquota=1
879 if [ $gquota -gt 0 ] && [ $pquota -gt 0 ]; then
880 export MOUNT_OPTIONS=$(echo $MOUNT_OPTIONS \
881 | sed -e 's/gquota/QUOTA/g' \
882 -e 's/grpquota/QUOTA/g' \
883 -e 's/grpjquota=[^, ]/QUOTA/g' \
884 -e 's/gqnoenforce/QUOTA/g' \
885 -e "s/QUOTA/defaults/g")
887 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seqres.full
890 # Find AG count of mounted filesystem
893 $XFS_INFO_PROG "$1" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g'
896 # Wipe the superblock of each XFS AGs
897 _try_wipe_scratch_xfs()
904 # Try to wipe each SB if there's an existed XFS
905 agcount=`_scratch_xfs_get_sb_field agcount 2>/dev/null`
906 agsize=`_scratch_xfs_get_sb_field agblocks 2>/dev/null`
907 dbsize=`_scratch_xfs_get_sb_field blocksize 2>/dev/null`
908 if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then
909 for ((i = 0; i < agcount; i++)); do
910 $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \
911 $SCRATCH_DEV >/dev/null;
915 # Try to wipe each SB by default mkfs.xfs geometry
916 local tmp=`mktemp -u`
917 unset agcount agsize dbsize
918 _scratch_mkfs_xfs -N 2>/dev/null | perl -ne '
919 if (/^meta-data=.*\s+agcount=(\d+), agsize=(\d+) blks/) {
920 print STDOUT "agcount=$1\nagsize=$2\n";
922 if (/^data\s+=\s+bsize=(\d+)\s/) {
923 print STDOUT "dbsize=$1\n";
927 if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then
928 for ((i = 0; i < agcount; i++)); do
929 $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \
930 $SCRATCH_DEV >/dev/null;