mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
common/xfs: refactor xfs_scrub presence testing
Move all the requirements checking for xfs_scrub into a helper function. Make sure the helper properly detects the presence of the scrub ioctl and situations where we can't run scrub (e.g. norecovery). Refactor the existing three xfs_scrub call sites to use the helper to check if it's appropriate to run scrub. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Eryu Guan <eguan@redhat.com> Signed-off-by: Eryu Guan <eguan@redhat.com>
This commit is contained in:
committed by
Eryu Guan
parent
4b69106b60
commit
5cd65cb761
@@ -88,9 +88,9 @@ Preparing system for tests:
|
|||||||
run xfs_repair -n to check the filesystem; xfs_repair to rebuild
|
run xfs_repair -n to check the filesystem; xfs_repair to rebuild
|
||||||
metadata indexes; and xfs_repair -n (a third time) to check the
|
metadata indexes; and xfs_repair -n (a third time) to check the
|
||||||
results of the rebuilding.
|
results of the rebuilding.
|
||||||
- set TEST_XFS_SCRUB=1 to have _check_xfs_filesystem run
|
- xfs_scrub, if present, will always check the test and scratch
|
||||||
xfs_scrub -vd to scrub the filesystem metadata online before
|
filesystems if they are still online at the end of the test.
|
||||||
unmounting to run the offline check.
|
It is no longer necessary to set TEST_XFS_SCRUB.
|
||||||
- setenv LOGWRITES_DEV to a block device to use for power fail
|
- setenv LOGWRITES_DEV to a block device to use for power fail
|
||||||
testing.
|
testing.
|
||||||
|
|
||||||
|
|||||||
@@ -2077,7 +2077,7 @@ _require_xfs_io_command()
|
|||||||
_notrun "xfs_io $command support is missing"
|
_notrun "xfs_io $command support is missing"
|
||||||
;;
|
;;
|
||||||
"scrub"|"repair")
|
"scrub"|"repair")
|
||||||
testio=`$XFS_IO_PROG -x -c "$command test 0" $TEST_DIR 2>&1`
|
testio=`$XFS_IO_PROG -x -c "$command probe 0" $TEST_DIR 2>&1`
|
||||||
echo $testio | grep -q "Inappropriate ioctl" && \
|
echo $testio | grep -q "Inappropriate ioctl" && \
|
||||||
_notrun "xfs_io $command support is missing"
|
_notrun "xfs_io $command support is missing"
|
||||||
;;
|
;;
|
||||||
|
|||||||
+34
-7
@@ -298,6 +298,30 @@ _require_xfs_db_command()
|
|||||||
_notrun "xfs_db $command support is missing"
|
_notrun "xfs_db $command support is missing"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Does the filesystem mounted from a particular device support scrub?
|
||||||
|
_supports_xfs_scrub()
|
||||||
|
{
|
||||||
|
local mountpoint="$1"
|
||||||
|
local device="$2"
|
||||||
|
|
||||||
|
if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
|
||||||
|
echo "Usage: _supports_xfs_scrub mountpoint device"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
test "$FSTYP" = "xfs" || return 1
|
||||||
|
test -x "$XFS_SCRUB_PROG" || return 1
|
||||||
|
|
||||||
|
# Probe for kernel support...
|
||||||
|
$XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1
|
||||||
|
$XFS_IO_PROG -c "scrub probe 0" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
|
||||||
|
|
||||||
|
# Scrub can't run on norecovery mounts
|
||||||
|
_fs_options "$device" | grep -q "norecovery" && return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
# run xfs_check and friends on a FS.
|
# run xfs_check and friends on a FS.
|
||||||
_check_xfs_filesystem()
|
_check_xfs_filesystem()
|
||||||
{
|
{
|
||||||
@@ -330,14 +354,17 @@ _check_xfs_filesystem()
|
|||||||
type=`_fs_type $device`
|
type=`_fs_type $device`
|
||||||
ok=1
|
ok=1
|
||||||
|
|
||||||
if [ "$type" = "xfs" ]; then
|
# Run online scrub if we can.
|
||||||
if [ -n "$TEST_XFS_SCRUB" ] && [ -x "$XFS_SCRUB_PROG" ]; then
|
mntpt="$(_is_mounted $device)"
|
||||||
"$XFS_SCRUB_PROG" $scrubflag -v -d -n $device >>$seqres.full
|
if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
|
||||||
if [ $? -ne 0 ]; then
|
"$XFS_SCRUB_PROG" $scrubflag -v -d -n $device >>$seqres.full 2>&1
|
||||||
_log_err "filesystem on $device failed scrub"
|
if [ $? -ne 0 ]; then
|
||||||
ok=0
|
_log_err "filesystem on $device failed scrub"
|
||||||
fi
|
ok=0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$type" = "xfs" ]; then
|
||||||
# mounted ...
|
# mounted ...
|
||||||
mountpoint=`_umount_or_remount_ro $device`
|
mountpoint=`_umount_or_remount_ro $device`
|
||||||
fi
|
fi
|
||||||
|
|||||||
+2
-10
@@ -136,10 +136,8 @@ echo "Test XFS online scrub, if applicable"
|
|||||||
|
|
||||||
# Only run this on xfs if xfs_scrub is available and has the unicode checker
|
# Only run this on xfs if xfs_scrub is available and has the unicode checker
|
||||||
check_xfs_scrub() {
|
check_xfs_scrub() {
|
||||||
# Ignore non-XFS fs or no scrub program...
|
[ "$FSTYP" == "xfs" ] || return 1
|
||||||
if [ "${FSTYP}" != "xfs" ] || [ ! -x "${XFS_SCRUB_PROG}" ]; then
|
_supports_xfs_scrub "$SCRATCH_MNT" "$SCRATCH_DEV" || return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We only care if xfs_scrub has unicode string support...
|
# We only care if xfs_scrub has unicode string support...
|
||||||
if ! type ldd > /dev/null 2>&1 || \
|
if ! type ldd > /dev/null 2>&1 || \
|
||||||
@@ -147,12 +145,6 @@ check_xfs_scrub() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Does the ioctl work?
|
|
||||||
if $XFS_IO_PROG -x -c "scrub probe 0" $SCRATCH_MNT 2>&1 | \
|
|
||||||
grep -q "Inappropriate ioctl"; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-10
@@ -132,10 +132,8 @@ echo "Test XFS online scrub, if applicable"
|
|||||||
|
|
||||||
# Only run this on xfs if xfs_scrub is available and has the unicode checker
|
# Only run this on xfs if xfs_scrub is available and has the unicode checker
|
||||||
check_xfs_scrub() {
|
check_xfs_scrub() {
|
||||||
# Ignore non-XFS fs or no scrub program...
|
[ "$FSTYP" == "xfs" ] || return 1
|
||||||
if [ "${FSTYP}" != "xfs" ] || [ ! -x "${XFS_SCRUB_PROG}" ]; then
|
_supports_xfs_scrub "$SCRATCH_MNT" "$SCRATCH_DEV" || return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We only care if xfs_scrub has unicode string support...
|
# We only care if xfs_scrub has unicode string support...
|
||||||
if ! type ldd > /dev/null 2>&1 || \
|
if ! type ldd > /dev/null 2>&1 || \
|
||||||
@@ -143,12 +141,6 @@ check_xfs_scrub() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Does the ioctl work?
|
|
||||||
if $XFS_IO_PROG -x -c "scrub probe 0" $SCRATCH_MNT 2>&1 | \
|
|
||||||
grep -q "Inappropriate ioctl"; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user