xfs: fix blocktrash fuzzers

The blocktrash fuzz tests for xfs will try to mount and write to the
filesystem after corrupting it.  However, the mount may not necessarily
succeed, in which case we must not write junk to the root filesystem.
Use the new _try_scratch_mount to guard against that.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
This commit is contained in:
Darrick J. Wong
2018-05-01 08:40:17 -07:00
committed by Eryu Guan
parent e2fd1a080e
commit 0828657542
22 changed files with 148 additions and 126 deletions
+7 -6
View File
@@ -93,13 +93,14 @@ done
# Try to append to files; this should fail # Try to append to files; this should fail
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
for x in `seq 1 64`; do for x in `seq 1 64`; do
$XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
done done
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+9 -8
View File
@@ -91,15 +91,16 @@ for ag in $(seq 1 $((agcount - 1))) 0; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
broken=0 broken=0
for x in `seq 65 70`; do for x in `seq 65 70`; do
touch "${TESTFILE}.${x}" 2> /dev/null || broken=1 touch "${TESTFILE}.${x}" 2> /dev/null || broken=1
done done
echo "broken: ${broken}" echo "broken: ${broken}"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+7 -6
View File
@@ -92,13 +92,14 @@ done
# Try to append to files; this should fail # Try to append to files; this should fail
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
for x in `seq 1 64`; do for x in `seq 1 64`; do
$XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
done done
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+7 -6
View File
@@ -92,13 +92,14 @@ done
# Try to append to files; this should fail # Try to append to files; this should fail
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
for x in `seq 1 64`; do for x in `seq 1 64`; do
$XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
done done
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+7 -6
View File
@@ -92,13 +92,14 @@ done
# Try to append to files; this should fail # Try to append to files; this should fail
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
for x in `seq 1 64`; do for x in `seq 1 64`; do
$XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
done done
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+9 -8
View File
@@ -91,15 +91,16 @@ for ag in $(seq 1 $((agcount - 1))) 0; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
broken=0 broken=0
for x in `seq 65 70`; do for x in `seq 65 70`; do
touch "${TESTFILE}.${x}" 2> /dev/null || broken=1 touch "${TESTFILE}.${x}" 2> /dev/null || broken=1
done done
echo "broken: ${broken}" echo "broken: ${broken}"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+9 -8
View File
@@ -94,15 +94,16 @@ for ag in $(seq 1 $((agcount - 1))) 0; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
broken=0 broken=0
for x in `seq 65 70`; do for x in `seq 65 70`; do
touch "${TESTFILE}.${x}" 2> /dev/null || broken=1 touch "${TESTFILE}.${x}" 2> /dev/null || broken=1
done done
echo "broken: ${broken}" echo "broken: ${broken}"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -82,12 +82,13 @@ echo "+ corrupt dir"
_scratch_xfs_db -x -c "inode ${inode}" -c 'dblock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full _scratch_xfs_db -x -c "inode ${inode}" -c 'dblock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -87,12 +87,13 @@ while true; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -82,12 +82,13 @@ echo "+ corrupt dir"
_scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${leaf_lblk}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full _scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${leaf_lblk}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -87,12 +87,13 @@ while true; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -87,12 +87,13 @@ while true; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -87,12 +87,13 @@ while true; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+6 -5
View File
@@ -87,12 +87,13 @@ while true; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify dir" echo "+ modify dir"
rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory" rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory" mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+12 -11
View File
@@ -90,18 +90,19 @@ seq "${inode}" "$((inode + 64))" | while read ino; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
broken=0 broken=0
for x in `seq 1 64`; do for x in `seq 1 64`; do
stat "${TESTFILE}.${x}" >> $seqres.full 2>&1 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
test $? -ne 0 && broken=1 test $? -ne 0 && broken=1
touch "${TESTFILE}.${x}" >> $seqres.full 2>&1 touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
test $? -ne 0 && broken=1 test $? -ne 0 && broken=1
done done
echo "broken: ${broken}" echo "broken: ${broken}"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+8 -7
View File
@@ -79,14 +79,15 @@ echo "+ corrupt image"
_scratch_xfs_db -x -c "inode ${inode}" -c "addr u.bmbt.ptrs[1]" -c "addr u3.bmbt.ptrs[1]" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full _scratch_xfs_db -x -c "inode ${inode}" -c "addr u.bmbt.ptrs[1]" -c "addr u3.bmbt.ptrs[1]" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify files" echo "+ modify files"
before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")" before="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
$XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" -c 'fsync' "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")" after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
test "${before}" -eq "${after}" || _fail "pwrite should fail on corrupt bmbt" test "${before}" -eq "${after}" || _fail "pwrite should fail on corrupt bmbt"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+4 -3
View File
@@ -78,9 +78,10 @@ echo "+ corrupt image"
_scratch_xfs_db -x -c "inode ${inode}" -c "dblock 0" -c "stack" -c "blocktrash -x 32 -o 256 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full _scratch_xfs_db -x -c "inode ${inode}" -c "dblock 0" -c "stack" -c "blocktrash -x 32 -o 256 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken" cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+5 -4
View File
@@ -87,11 +87,12 @@ echo "+ corrupt xattr"
_scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full _scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify xattr" echo "+ modify xattr"
setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr" setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+5 -4
View File
@@ -87,11 +87,12 @@ echo "+ corrupt xattr"
_scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -o +32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full _scratch_xfs_db -x -c "inode ${inode}" -c 'ablock 0' -c "stack" -c "blocktrash -x 32 -o +32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify xattr" echo "+ modify xattr"
setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr" setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1
+5 -4
View File
@@ -92,11 +92,12 @@ while true; do
done done
echo "+ mount image" echo "+ mount image"
_scratch_mount if _try_scratch_mount >> $seqres.full 2>&1; then
echo "+ modify xattr" echo "+ modify xattr"
setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr" setfattr -x "user.x00000000" "${SCRATCH_MNT}/attrfile" 2> /dev/null && _fail "modified corrupt xattr"
umount "${SCRATCH_MNT}" umount "${SCRATCH_MNT}"
fi
echo "+ repair fs" echo "+ repair fs"
_scratch_xfs_repair >> $seqres.full 2>&1 _scratch_xfs_repair >> $seqres.full 2>&1

Some files were not shown because too many files have changed in this diff Show More