From: Darrick J. Wong Date: Tue, 10 Mar 2026 03:51:41 +0000 (-0700) Subject: xfs: test xfs_healer can fix a filesystem X-Git-Tag: v2026.03.20~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a951e61b684cfd21afde34a8930fc9666efe68b8;p=xfstests-dev.git xfs: test xfs_healer can fix a filesystem Make sure that xfs_healer can actually fix an injected metadata corruption. Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang Signed-off-by: Zorro Lang --- diff --git a/tests/xfs/658 b/tests/xfs/658 new file mode 100755 index 00000000..5d45dbee --- /dev/null +++ b/tests/xfs/658 @@ -0,0 +1,88 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024-2026 Oracle. All Rights Reserved. +# +# FS QA Test No. 658 +# +# Ensure that autonomous self healing fixes the filesystem correctly. +# +. ./common/preamble +_begin_fstest auto selfhealing + +. ./common/filter +. ./common/fuzzy +. ./common/systemd + +_require_scrub +_require_xfs_io_command "repair" # online repair support +_require_xfs_db_command "blocktrash" +_require_command "$XFS_HEALER_PROG" "xfs_healer" +_require_command "$XFS_PROPERTY_PROG" "xfs_property" +_require_scratch + +_scratch_mkfs >> $seqres.full +_scratch_mount + +_xfs_has_feature $SCRATCH_MNT rmapbt || \ + _notrun "reverse mapping required to test directory auto-repair" +_xfs_has_feature $SCRATCH_MNT parent || \ + _notrun "parent pointers required to test directory auto-repair" +_require_xfs_healer $SCRATCH_MNT --repair + +# Configure the filesystem for automatic repair of the filesystem. +$XFS_PROPERTY_PROG $SCRATCH_MNT set autofsck=repair >> $seqres.full + +# Create a largeish directory +dblksz=$(_xfs_get_dir_blocksize "$SCRATCH_MNT") +echo testdata > $SCRATCH_MNT/a +mkdir -p "$SCRATCH_MNT/some/victimdir" +for ((i = 0; i < (dblksz / 255); i++)); do + fname="$(printf "%0255d" "$i")" + ln $SCRATCH_MNT/a $SCRATCH_MNT/some/victimdir/$fname +done + +# Did we get at least two dir blocks? +dirsize=$(stat -c '%s' $SCRATCH_MNT/some/victimdir) +test "$dirsize" -gt "$dblksz" || echo "failed to create two-block directory" + +# Break the directory, remount filesystem +_scratch_unmount +_scratch_xfs_db -x \ + -c 'path /some/victimdir' \ + -c 'bmap' \ + -c 'dblock 1' \ + -c 'blocktrash -z -0 -o 0 -x 2048 -y 2048 -n 2048' >> $seqres.full +_scratch_mount + +_scratch_invoke_xfs_healer "$tmp.healer" --repair + +# Access the broken directory to trigger a repair, then poll the directory +# for 5 seconds to see if it gets fixed without us needing to intervene. +ls $SCRATCH_MNT/some/victimdir > /dev/null 2> $tmp.err +_filter_scratch < $tmp.err +try=0 +while [ $try -lt 50 ] && grep -q 'Structure needs cleaning' $tmp.err; do + echo "try $try saw corruption" >> $seqres.full + sleep 0.1 + ls $SCRATCH_MNT/some/victimdir > /dev/null 2> $tmp.err + try=$((try + 1)) +done +echo "try $try no longer saw corruption or gave up" >> $seqres.full +_filter_scratch < $tmp.err + +# List the dirents of /victimdir to see if it stops reporting corruption +ls $SCRATCH_MNT/some/victimdir > /dev/null 2> $tmp.err +try=0 +while [ $try -lt 50 ] && grep -q 'Structure needs cleaning' $tmp.err; do + echo "retry $try still saw corruption" >> $seqres.full + sleep 0.1 + ls $SCRATCH_MNT/some/victimdir > /dev/null 2> $tmp.err + try=$((try + 1)) +done +echo "retry $try no longer saw corruption or gave up" >> $seqres.full + +# Unmount to kill the healer +_scratch_kill_xfs_healer +cat $tmp.healer >> $seqres.full + +_exit 0 diff --git a/tests/xfs/658.out b/tests/xfs/658.out new file mode 100644 index 00000000..07be79b4 --- /dev/null +++ b/tests/xfs/658.out @@ -0,0 +1,2 @@ +QA output created by 658 +ls: reading directory 'SCRATCH_MNT/some/victimdir': Structure needs cleaning