diff options
author | Darrick J. Wong <djwong@kernel.org> | 2022-12-30 14:19:40 -0800 |
---|---|---|
committer | Zorro Lang <zlang@kernel.org> | 2023-02-25 21:09:52 +0800 |
commit | 11c44462c122a7f842992d09b4844d9987019573 (patch) | |
tree | 1e7ed8a91dc9c31a5eec0aef76d57d7de8a05da9 /common/fuzzy | |
parent | 19327c1a0ed373caa3ea666417a5f7449dca6ea3 (diff) |
common/fuzzy: hoist the post-repair fs modification step
Hoist the code that tries to modify an fs after repairing our fuzz
damage into a separate function, so that we can further simplify the
caller.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'common/fuzzy')
-rw-r--r-- | common/fuzzy | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/common/fuzzy b/common/fuzzy index eb5343b0..02b9607a 100644 --- a/common/fuzzy +++ b/common/fuzzy @@ -338,6 +338,47 @@ __scratch_xfs_fuzz_field_both() { return 0 } +# Assess the state of the filesystem after a repair strategy has been run by +# trying to make changes to it. +_scratch_xfs_fuzz_field_modifyfs() { + local fuzz_action="$1" + local repair="$2" + + # Try to mount the filesystem + echo "+ Make sure error is gone (online)" + _try_scratch_mount 2>&1 + res=$? + if [ $res -eq 0 ]; then + # Make sure online scrub says the filesystem is clean now + if [ "${repair}" != "none" ]; then + echo "++ Online scrub" + _scratch_scrub -n -e continue 2>&1 + res=$? + test $res -ne 0 && \ + (>&2 echo "online re-scrub ($res) with ${field} = ${fuzzverb}.") + fi + fi + + # Try modifying the filesystem again + __fuzz_notify "++ Try to write filesystem again" + _scratch_fuzz_modify 100 2>&1 + __scratch_xfs_fuzz_unmount + else + (>&2 echo "re-mount failed ($res) with ${fuzz_action}.") + fi + + # See if repair finds a clean fs + if [ "${repair}" != "none" ]; then + echo "+ Re-check the filesystem (offline)" + _scratch_xfs_repair -n 2>&1 + res=$? + test $res -ne 0 && \ + (>&2 echo "re-repair failed ($res) with ${field} = ${fuzzverb}.") + fi + + return 0 +} + # Fuzz one field of some piece of metadata. # First arg is the field name # Second arg is the fuzz verb (ones, zeroes, random, add, sub...) @@ -381,39 +422,9 @@ __scratch_xfs_fuzz_field_test() { esac test $res -eq 0 || return $res - # See if scrub finds a clean fs - echo "+ Make sure error is gone (online)" - _try_scratch_mount 2>&1 - res=$? - if [ $res -eq 0 ]; then - # Try an online scrub unless we're fuzzing ag 0's sb, - # which scrub doesn't know how to fix. - if [ "${repair}" != "none" ]; then - echo "++ Online scrub" - if [ "$1" != "sb 0" ]; then - _scratch_scrub -n -e continue 2>&1 - res=$? - test $res -ne 0 && \ - (>&2 echo "online re-scrub ($res) with ${field} = ${fuzzverb}.") - fi - fi - - # Try modifying the filesystem again! - __fuzz_notify "++ Try to write filesystem again" - _scratch_fuzz_modify 100 2>&1 - __scratch_xfs_fuzz_unmount - else - (>&2 echo "re-mount failed ($res) with ${field} = ${fuzzverb}.") - fi - - # See if repair finds a clean fs - if [ "${repair}" != "none" ]; then - echo "+ Re-check the filesystem (offline)" - _scratch_xfs_repair -n 2>&1 - res=$? - test $res -ne 0 && \ - (>&2 echo "re-repair failed ($res) with ${field} = ${fuzzverb}.") - fi + # See what happens when we modify the fs + _scratch_xfs_fuzz_field_modifyfs "${fuzz_action}" "${repair}" + return $? } # Make sure we have all the pieces we need for field fuzzing |