common/fuzzy: move fuzzing helper functions here
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 21 Jan 2017 08:10:50 +0000 (00:10 -0800)
committerEryu Guan <eguan@redhat.com>
Fri, 27 Jan 2017 08:06:11 +0000 (16:06 +0800)
Move some fuzzing helper functions into a new common/fuzzy file.
We'll add a lot more fuzzing helpers in subsequent patches.

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>
common/fuzzy [new file with mode: 0644]
common/populate
tests/ext4/006
tests/xfs/083

diff --git a/common/fuzzy b/common/fuzzy
new file mode 100644 (file)
index 0000000..c3b4dc7
--- /dev/null
@@ -0,0 +1,80 @@
+##/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.
+#
+#  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
+#-----------------------------------------------------------------------
+
+# Modify various files after a fuzzing operation
+_scratch_fuzz_modify() {
+       nr="$1"
+
+       test -z "${nr}" && nr=50000
+       echo "+++ touch ${nr} files"
+       blk_sz=$(stat -f -c '%s' ${SCRATCH_MNT})
+       $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
+               setfattr -n "user.date" -v "${date}" "$f"
+               cat "/tmp/afile" >> "$f"
+               mv "$f" "$f.longer"
+       done
+       sync
+       rm -rf "/tmp/afile"
+
+       echo "+++ create files"
+       mkdir -p "${SCRATCH_MNT}/test.moo"
+       $XFS_IO_PROG -f -c 'pwrite -S 0x80 0 65536' "${SCRATCH_MNT}/test.moo/urk"
+       sync
+
+       echo "+++ remove files"
+       rm -rf "${SCRATCH_MNT}/test.moo"
+}
+
+# Try to access files after fuzzing
+_scratch_fuzz_test() {
+       echo "+++ ls -laR" >> $seqres.full
+       ls -laR "${SCRATCH_MNT}/test.1/" >/dev/null 2>&1
+
+       echo "+++ cat files" >> $seqres.full
+       (find "${SCRATCH_MNT}/test.1/" -type f -size -1048576k -print0 | xargs -0 cat) >/dev/null 2>&1
+}
+
+# Do we have an online scrub program?
+_require_scrub() {
+       case "${FSTYP}" in
+       "xfs"|"ext4")
+               test -x "$XFS_SCRUB_PROG" || _notrun "xfs_scrub not found"
+               ;;
+       *)
+               _notrun "No online scrub program for ${FSTYP}."
+               ;;
+       esac
+}
+
+# Scrub the scratch filesystem metadata (online)
+_scratch_scrub() {
+       case "${FSTYP}" in
+       "xfs"|"ext4"|"ext3"|"ext2")
+               $XFS_SCRUB_PROG -d -T -v "$@" $SCRATCH_MNT
+               ;;
+       *)
+               _fail "No online scrub program for ${FSTYP}."
+               ;;
+       esac
+}
index 1afab469aa2573108f1f0a8c005ea21f2680c16f..cf6a80b0d30f95692b6fa34ccf4557d27108d83e 100644 (file)
@@ -606,41 +606,6 @@ _scratch_populate() {
        esac
 }
 
-# Modify various files after a fuzzing operation
-_scratch_fuzz_modify() {
-       nr="$1"
-
-       test -z "${nr}" && nr=50000
-       echo "+++ touch ${nr} files"
-       blk_sz=$(stat -f -c '%s' ${SCRATCH_MNT})
-       $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
-               setfattr -n "user.date" -v "${date}" "$f"
-               cat "/tmp/afile" >> "$f"
-               mv "$f" "$f.longer"
-       done
-       sync
-       rm -rf "/tmp/afile"
-
-       echo "+++ create files"
-       mkdir -p "${SCRATCH_MNT}/test.moo"
-       $XFS_IO_PROG -f -c 'pwrite -S 0x80 0 65536' "${SCRATCH_MNT}/test.moo/urk"
-       sync
-
-       echo "+++ remove files"
-       rm -rf "${SCRATCH_MNT}/test.moo"
-}
-
-# Try to access files after fuzzing
-_scratch_fuzz_test() {
-       echo "+++ ls -laR" >> $seqres.full
-       ls -laR "${SCRATCH_MNT}/test.1/" >/dev/null 2>&1
-
-       echo "+++ cat files" >> $seqres.full
-       (find "${SCRATCH_MNT}/test.1/" -type f -size -1048576k -print0 | xargs -0 cat) >/dev/null 2>&1
-}
-
 # Fill a file system by repeatedly creating files in the given folder
 # starting with the given file size.  Files are reduced in size when
 # they can no longer fit until no more files can be created.
index 9662f50bc7320d524fe43fd119e40d54befc81e0..bb9b7e574c297d4817a83c0b3ff6e120e623fb5b 100755 (executable)
@@ -43,6 +43,7 @@ _cleanup()
 . ./common/filter
 . ./common/attr
 . ./common/populate
+. ./common/fuzzy
 
 if [ ! -x "$(which e2fuzz)" ]; then
        _notrun "Couldn't find e2fuzz"
index 39bd75fcfc7575068ef50f26eeadef2fbd69e47a..e2b5f823845de799db17faf52bc1318251c3d0fa 100755 (executable)
@@ -43,6 +43,7 @@ _cleanup()
 . ./common/filter
 . ./common/attr
 . ./common/populate
+. ./common/fuzzy
 
 # real QA test starts here
 _supported_fs xfs