]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
xfs: fix tests that try to access the realtime rmap inode
authorDarrick J. Wong <djwong@kernel.org>
Tue, 6 Feb 2024 00:06:44 +0000 (16:06 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 1 Nov 2024 20:41:59 +0000 (13:41 -0700)
The realtime rmap tests were added to fstests a long time ago.  Since
they were added, we decided to create a metadata file directory
structure instead of adding more fields to the superblock.  Therefore,
fix all the tests that try to access these paths.

While we're at it, fix xfs/409 to run the *online* scrub program like
it's supposed to.  xfs/408 is the fuzzer for xfs_repair testing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
common/xfs
tests/xfs/122.out
tests/xfs/333 [deleted file]
tests/xfs/333.out [deleted file]
tests/xfs/337
tests/xfs/338
tests/xfs/339
tests/xfs/340
tests/xfs/341
tests/xfs/342

index 2dd77b2bd35e47e23f4a801de8116d779fd77cf4..73616108366cde20b9588d8fe1bdd8a48b6ae5a6 100644 (file)
@@ -2110,3 +2110,44 @@ _require_xfs_rtquota_if_rtdev() {
                _notrun "Quotas probably not supported on realtime scratch device; set TEST_RTDEV"
        fi
 }
+
+# Resolve a metadata directory tree path and return the inode number.
+_scratch_metadir_lookup() {
+       local res="$(_scratch_xfs_db -c "ls -i -m $1")"
+       test "${PIPESTATUS[0]}" -eq 0 && echo "$res"
+}
+
+# Figure out which directory entry we have to change to update the rtrmap
+# inode pointer.  The last line of output is inumber field within a metadata
+# object; any previous lines are the accessor commands that must be fed to
+# xfs_db to get to the correct directory block.
+_scratch_find_rt_metadir_entry() {
+       local sfkey="$(_scratch_xfs_db -c 'path -m /rtgroups' -c print | \
+               grep "\"$1\"" | \
+               sed -e 's/.name.*$//g' -e 's/\[/\\[/g' -e 's/\]/\\]/g' )"
+       if [ -n "$sfkey" ]; then
+               echo 'path -m /rtgroups'
+               _scratch_xfs_db -c 'path -m /rtgroups' -c print | \
+                       grep "${sfkey}.inumber" | awk '{print $1}'
+               return 0
+       fi
+
+       local size=$(_scratch_xfs_db -c 'path -m /rtgroups' -c 'print core.size' | awk '{print $3}')
+       local blksz=$(_scratch_xfs_db -c 'sb 0' -c 'print blocksize' | awk '{print $3}')
+       local dirblklog=$(_scratch_xfs_db -c 'sb 0' -c 'print dirblklog' | awk '{print $3}')
+       local dirblksz=$((blksz << dirblklog ))
+       for ((fileoff = 0; fileoff < (size / dirblksz); fileoff++)); do
+               local dbkey="$(_scratch_xfs_db -c 'path -m /rtgroups' -c "dblock $fileoff" -c 'print' | \
+                       grep "\"$1\"" | \
+                       sed -e 's/.name.*$//g' -e 's/\[/\\[/g' -e 's/\]/\\]/g' )"
+               if [ -n "$dbkey" ]; then
+                       echo 'path -m /rtgroups'
+                       echo "dblock $fileoff"
+                       _scratch_xfs_db -c 'path -m /rtgroups' -c "dblock $fileoff" -c print | \
+                               grep "${dbkey}.inumber" | awk '{print $1}'
+                       return 0
+               fi
+       done
+
+       return 1
+}
index 3fbc4d4fc49ad1779bfe5926be7975efef940d26..367e1011e5f6680f4cc31a13c874390ef3698cd3 100644 (file)
@@ -50,7 +50,6 @@ offsetof(xfs_sb_t, sb_rgblklog) = 204
 offsetof(xfs_sb_t, sb_rgcount) = 272
 offsetof(xfs_sb_t, sb_rgextents) = 276
 offsetof(xfs_sb_t, sb_rootino) = 56
-offsetof(xfs_sb_t, sb_rrmapino) = 264
 offsetof(xfs_sb_t, sb_rsumino) = 72
 offsetof(xfs_sb_t, sb_sectlog) = 121
 offsetof(xfs_sb_t, sb_sectsize) = 102
diff --git a/tests/xfs/333 b/tests/xfs/333
deleted file mode 100755 (executable)
index f68f2f0..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#! /bin/bash
-# SPDX-License-Identifier: GPL-2.0
-# Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
-#
-# FS QA Test No. 333
-#
-# Set rrmapino to another inode on an non-rt rmap fs and see if repair fixes it.
-#
-. ./common/preamble
-_begin_fstest auto quick rmap realtime
-
-# Import common functions.
-. ./common/filter
-
-_require_xfs_scratch_rmapbt
-_disable_dmesg_check
-
-rm -f "$seqres.full"
-
-unset SCRATCH_RTDEV
-
-echo "Format and mount"
-_scratch_mkfs > "$seqres.full" 2>&1
-rrmapino="$(_scratch_xfs_db -c 'sb 0' -c 'p rrmapino' 2>&1)"
-test "${rrmapino}" = "field rrmapino not found" && _notrun "realtime rmapbt not supported"
-_scratch_mount
-
-echo "Create some files"
-$XFS_IO_PROG -f -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f1 >> $seqres.full
-$XFS_IO_PROG -f -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f2 >> $seqres.full
-echo garbage > $SCRATCH_MNT/f3
-ino=$(stat -c '%i' $SCRATCH_MNT/f3)
-_scratch_unmount
-
-echo "Corrupt fs"
-_scratch_xfs_db -x -c 'sb 0' -c "write rrmapino $ino" >> $seqres.full
-_try_scratch_mount 2>&1 | _filter_error_mount
-
-echo "Test done, mount should have failed"
-
-# success, all done
-status=0
-exit
diff --git a/tests/xfs/333.out b/tests/xfs/333.out
deleted file mode 100644 (file)
index b3c6987..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-QA output created by 333
-Format and mount
-Create some files
-Corrupt fs
-mount: Structure needs cleaning
-Test done, mount should have failed
index 2ba508044ba16b23301ce37fdb42084e4cd61f77..64429347fcba70f8ae79e4647786b0785e7e3892 100755 (executable)
@@ -51,7 +51,7 @@ echo "+ check fs"
 _scratch_xfs_repair -n >> $seqres.full 2>&1 || echo "xfs_repair should not fail"
 
 echo "+ corrupt image"
-_scratch_xfs_db -x -c "sb" -c "addr rrmapino" -c "addr u3.rtrmapbt.ptrs[1]" \
+_scratch_xfs_db -x -c "path -m /rtgroups/0.rmap" -c "addr u3.rtrmapbt.ptrs[1]" \
        -c "stack" -c "blocktrash -x 4096 -y 4096 -n 8 -3 -z" \
        >> $seqres.full 2>&1
 
index 9648c9df485223e43d992b8e6f551fcc2ddcd3df..713a808dc8e3dad4e2b81ef77026f27bc947e560 100755 (executable)
@@ -27,13 +27,33 @@ $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f2 >> $seqres.full
 _scratch_unmount
 
 echo "Corrupt fs"
-_scratch_xfs_db -x -c 'sb 0' -c 'addr rrmapino' \
-       -c 'write core.nlinkv2 0' -c 'write core.mode 0' -c 'sb 0' \
-       -c 'write rrmapino 0' >> $seqres.full
-_try_scratch_mount >> $seqres.full 2>&1 && echo "mount should have failed"
+readarray -t rtrmap_path < <(_scratch_find_rt_metadir_entry 0.rmap)
+
+rtrmap_accessors=()
+rtrmap_path_len="${#rtrmap_path[@]}"
+for ((i = 0; i < rtrmap_path_len - 1; i++)); do
+       rtrmap_accessors+=(-c "${rtrmap_path[i]}")
+done
+rtrmap_entry="${rtrmap_path[rtrmap_path_len - 1]}"
+test -n "$rtrmap_entry" || _fail "Could not find rtrmap metadir entry?"
+
+_scratch_xfs_db -x -c 'path -m /rtgroups/0.rmap' \
+       -c 'write core.nlinkv2 0' -c 'write core.mode 0' \
+       "${rtrmap_accessors[@]}" \
+       -c "print $rtrmap_entry" \
+       -c "write -d $rtrmap_entry 0" >> $seqres.full
+if _try_scratch_mount >> $seqres.full 2>&1; then
+       echo "mount should have failed"
+       _scratch_unmount
+else
+       # If the verifiers are working properly, the mount will fail because
+       # we fuzzed the metadata root directory.  This causes loud complaints
+       # to dmesg, so we want to ignore those.
+       _disable_dmesg_check
+fi
 
 echo "Repair fs"
-_scratch_unmount 2>&1 | _filter_scratch
+_scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
 _repair_scratch_fs >> $seqres.full 2>&1
 
 echo "Try to create more files (again)"
index 4dabe43ff298fcd968a6aac99f5c30e4db9bedea..caadf87987e4331865862d94e6be6aa7c7c1daa6 100755 (executable)
@@ -29,7 +29,8 @@ ln $SCRATCH_MNT/f3 $SCRATCH_MNT/f4
 _scratch_unmount
 
 echo "Corrupt fs"
-rrmapino=`_scratch_xfs_get_sb_field rrmapino`
+rrmapino=$(_scratch_metadir_lookup /rtgroups/0.rmap)
+test -n "$rrmapino" || _fail "Could not find rtrmap inode?"
 _scratch_xfs_set_metadata_field "u3.sfdir3.list[3].inumber.i4" $rrmapino \
        'sb 0' 'addr rootino' >> $seqres.full
 _scratch_mount
@@ -41,7 +42,7 @@ echo "Try to create more files"
 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f5 >> $seqres.full 2>&1
 
 echo "Repair fs"
-_scratch_unmount 2>&1 | _filter_scratch
+_scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
 _repair_scratch_fs >> $seqres.full 2>&1
 
 echo "Try to create more files (again)"
index 248d3233c94ed38989a3ebf95fb14e30e5fc2872..c4a23bcb1cfe706afe99d729f9f7cec3862763e1 100755 (executable)
@@ -29,16 +29,31 @@ ino=$(stat -c '%i' $SCRATCH_MNT/f3)
 _scratch_unmount
 
 echo "Corrupt fs"
-rrmapino=$(_scratch_xfs_get_sb_field rrmapino)
-_scratch_xfs_db -x -c "inode $rrmapino" \
+readarray -t rtrmap_path < <(_scratch_find_rt_metadir_entry 0.rmap)
+
+rtrmap_accessors=()
+rtrmap_path_len="${#rtrmap_path[@]}"
+for ((i = 0; i < rtrmap_path_len - 1; i++)); do
+       rtrmap_accessors+=(-c "${rtrmap_path[i]}")
+done
+rtrmap_entry="${rtrmap_path[rtrmap_path_len - 1]}"
+test -n "$rtrmap_entry" || _fail "Could not find rtrmap metadir entry?"
+
+rrmapino=$(_scratch_metadir_lookup /rtgroups/0.rmap)
+test -n "$rrmapino" || _fail "Could not find rtrmap inode?"
+_scratch_xfs_db -x -c "path -m /rtgroups/0.rmap" \
        -c 'write core.format 2' -c 'write core.size 0' \
-       -c 'write core.nblocks 0' -c 'sb 0' -c 'addr rootino' \
+       -c 'write core.nblocks 0' \
+       -c 'sb 0' -c 'addr rootino' \
+       -c "print u3.sfdir3.list[2].inumber" \
        -c "write u3.sfdir3.list[2].inumber.i4 $rrmapino" \
-       -c 'sb 0' -c "write rrmapino $ino" >> $seqres.full
+       "${rtrmap_accessors[@]}" \
+       -c "print $rtrmap_entry" \
+       -c "write $rtrmap_entry $ino" >> $seqres.full
 _try_scratch_mount >> $seqres.full 2>&1 && echo "mount should have failed"
 
 echo "Repair fs"
-_scratch_unmount 2>&1 | _filter_scratch
+_scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
 _repair_scratch_fs >> $seqres.full 2>&1
 
 echo "Try to create more files (again)"
index 9b12febf8d5c497965428945b225abe38b3f3ab5..e9aea42f429ffd17b81b06c71626a3c9eedcef3d 100755 (executable)
@@ -51,7 +51,7 @@ echo "Corrupt fs"
 fsbno=$(_scratch_xfs_db -c "inode $ino" -c 'bmap' | grep 'flag 0' | head -n 1 | \
        sed -e 's/^.*startblock \([0-9]*\) .*$/\1/g')
 
-_scratch_xfs_db -x -c 'sb 0' -c 'addr rrmapino' \
+_scratch_xfs_db -x -c 'path -m /rtgroups/0.rmap' \
        -c "write u3.rtrmapbt.ptrs[1] $fsbno" -c 'p' >> $seqres.full
 _scratch_mount
 
index 5c0e916dbe32acb59d1a87b51d01e13d98ab8cbe..3bf353dd79b29b6271b17f7e1d2556722e864753 100755 (executable)
@@ -45,9 +45,9 @@ ino=$(stat -c '%i' $SCRATCH_MNT/f3)
 _scratch_unmount
 
 echo "Corrupt fs"
-_scratch_xfs_db -c 'sb 0' -c 'addr rrmapino' -c 'p u3.rtrmapbt.ptrs[1]' >> $seqres.full
+_scratch_xfs_db -c 'path -m /rtgroups/0.rmap' -c 'p u3.rtrmapbt.ptrs[1]' >> $seqres.full
 
-fsbno=$(_scratch_xfs_db -c 'sb 0' -c 'addr rrmapino' \
+fsbno=$(_scratch_xfs_db -c 'path -m /rtgroups/0.rmap' \
        -c 'p u3.rtrmapbt.ptrs[1]' | sed -e 's/^.*://g')
 _scratch_xfs_db -x -c "inode $ino" -c "write u3.bmx[0].startblock $fsbno" >> $seqres.full
 _scratch_mount