##/bin/bash
-
-# Routines for fuzzing and scrubbing a filesystem.
-#
-#-----------------------------------------------------------------------
-# Copyright (c) 2017 Oracle. All Rights Reserved.
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2017 Oracle. All Rights Reserved.
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-# USA
-#-----------------------------------------------------------------------
+# Routines for fuzzing and scrubbing a filesystem.
# Modify various files after a fuzzing operation
_scratch_fuzz_modify() {
$XFS_IO_PROG -f -c "pwrite -S 0x63 0 ${blk_sz}" "/tmp/afile" > /dev/null
date="$(date)"
find "${SCRATCH_MNT}/" -type f 2> /dev/null | head -n "${nr}" | while read f; do
+ # try to remove append, immutable (and even dax) flag if exists
+ $XFS_IO_PROG -rc 'chattr -x -i -a' "$f" > /dev/null 2>&1
setfattr -n "user.date" -v "${date}" "$f"
cat "/tmp/afile" >> "$f"
mv "$f" "$f.longer"
# 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...)
-# Third arg is the repair mode (online, offline, both)
+# Third arg is the repair mode (online, offline, both, none)
__scratch_xfs_fuzz_field_test() {
field="$1"
fuzzverb="$2"
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.
- echo "++ Online scrub"
- if [ "$1" != "sb 0" ]; then
- _scratch_scrub -n -a 1 -e continue 2>&1
- res=$?
- test $res -eq 0 && \
- (>&2 echo "scrub didn't fail with ${field} = ${fuzzverb}.")
+ if [ "${repair}" != "none" ]; then
+ echo "++ Online scrub"
+ if [ "$1" != "sb 0" ]; then
+ _scratch_scrub -n -a 1 -e continue 2>&1
+ res=$?
+ test $res -eq 0 && \
+ (>&2 echo "scrub didn't fail with ${field} = ${fuzzverb}.")
+ fi
fi
# Try fixing the filesystem online?!
fi
# See if repair finds a clean fs
- echo "+ Make sure error is gone (offline)"
- _scratch_xfs_repair -n 2>&1
- res=$?
- test $res -ne 0 && \
- (>&2 echo "offline re-scrub ($res) with ${field} = ${fuzzverb}.")
+ if [ "${repair}" != "none" ]; then
+ echo "+ Make sure error is gone (offline)"
+ _scratch_xfs_repair -n 2>&1
+ res=$?
+ test $res -ne 0 && \
+ (>&2 echo "offline re-scrub ($res) with ${field} = ${fuzzverb}.")
+ fi
# See if scrub finds a clean fs
echo "+ Make sure error is gone (online)"
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.
- 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}.")
+ 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!
fi
# See if repair finds a clean fs
- 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}.")
+ 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
}
# Make sure we have all the pieces we need for field fuzzing
echo "Verbs we propose to fuzz with:"
echo $(echo "${verbs}")
+ # Always capture full core dumps from crashing tools
+ ulimit -c unlimited
+
echo "${fields}" | while read field; do
echo "${verbs}" | while read fuzzverb; do
__scratch_xfs_fuzz_mdrestore