]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
xfs/113: fix failure to corrupt the entire directory
authorDarrick J. Wong <djwong@kernel.org>
Tue, 26 Nov 2024 01:21:18 +0000 (17:21 -0800)
committerZorro Lang <zlang@kernel.org>
Thu, 28 Nov 2024 13:39:49 +0000 (21:39 +0800)
This test tries to corrupt the data blocks of a directory, but it
doesn't take into account the fact that __populate_check_xfs_dir can
remove enough entries to cause sparse holes in the directory.  If that
happens, this "file data block is unmapped" logic will cause the
corruption loop to exit early.  Then we can add to the directory, which
causes the test to fail.

Instead, create a list of mappable dir block offsets, and run 100
corruptions at a time to reduce the amount of time we spend initializing
xfs_db.  This fixes the regressions that I see with 32k/64k block sizes.

Cc: fstests@vger.kernel.org # v2022.05.01
Fixes: c8e6dbc8812653 ("xfs: test directory metadata corruption checking and repair")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
tests/xfs/113

index 094ab71f2aefecb391a90d3389bbdaed711c69e0..22ac8c3fd51b807efb623cda336bde7cc04c8301 100755 (executable)
@@ -52,13 +52,34 @@ _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail
 echo "+ check dir"
 __populate_check_xfs_dir "${inode}" btree
 
+dir_data_offsets() {
+       _scratch_xfs_db -c "inode ${inode}" -c 'bmap' | \
+               awk -v leaf_lblk=$leaf_lblk \
+               '{
+                       if ($3 >= leaf_lblk)
+                               exit;
+                       for (i = 0; i < $8; i++)
+                               printf("%d\n", $3 + i);
+               }'
+}
+
 echo "+ corrupt dir"
-loff=0
-while true; do
-       _scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${loff}" -c "stack" | grep -q 'file data block is unmapped' && break
-       _scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${loff}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
-       loff="$((loff + 1))"
-done
+subcommands=()
+while read loff; do
+       # run 100 commands at a time
+       if [ "${#subcommands[@]}" -lt 600 ]; then
+               subcommands+=(-c "inode ${inode}")
+               subcommands+=(-c "dblock ${loff}")
+               subcommands+=(-c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}")
+               continue
+       fi
+
+       _scratch_xfs_db -x "${subcommands[@]}" >> $seqres.full
+       subcommands=()
+done < <(dir_data_offsets)
+if [ "${#subcommands[@]}" -gt 0 ]; then
+       _scratch_xfs_db -x "${subcommands[@]}" >> $seqres.full
+fi
 
 echo "+ mount image && modify dir"
 if _try_scratch_mount >> $seqres.full 2>&1; then