common/xfs: wipe the XFS superblock of each AGs
PATCH v3 1/1 common/xfs: wipe the XFS superblock of each AGs
xfs/030 always fails after d0e484ac699f ("check: wipe scratch devices between tests") get merged.
Due to xfs/030 does a sized(100m) mkfs. Before we merge above commit, mkfs.xfs detects an old primary superblock, it will write zeroes to all superblocks before formatting the new filesystem. But this won't be done if we wipe the first superblock(by merging above commit).
That means if we make a (smaller) sized xfs after wipefs, those *old* superblocks which created by last time mkfs.xfs will be left on disk. Then when we do xfs_repair, if xfs_repair can't find the first SB, it will go to find those *old* SB at first. When it finds them, everyting goes wrong.
So I try to wipe each XFS superblock if there's a XFS ondisk, then try to erase superblock of each XFS AG by default mkfs.xfs geometry. Thanks Darrick J. Wong helped to analyze this issue.
---
Hi,
All changes in V3 is under:
# Try to wipe each SB by default mkfs.xfs geometry
...
...
Thanks,
Zorro
common/rc | 8 ++++++++ common/xfs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
common/rc +8 -0
@@ -4045,6 +4045,14 @@ _try_wipe_scratch_devs() { test -x "$WIPEFS_PROG" || return 0 + # Do specified filesystem wipe at first + case "$FSTYP" in + "xfs") + _try_wipe_scratch_xfs + ;; + esac + + # Then do wipefs on all scratch devices for dev in $SCRATCH_DEV_POOL $SCRATCH_DEV $SCRATCH_LOGDEV $SCRATCH_RTDEV; do test -b $dev && $WIPEFS_PROG -a $dev done
common/xfs +40 -0
@@ -884,3 +884,43 @@ _xfs_mount_agcount() { $XFS_INFO_PROG "$1" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g' } + +# Wipe the superblock of each XFS AGs +_try_wipe_scratch_xfs() +{ + local num='^[0-9]+$' + local agcount + local agsize + local dbsize + + # Try to wipe each SB if there's an existed XFS + agcount=`_scratch_xfs_get_sb_field agcount 2>/dev/null` + agsize=`_scratch_xfs_get_sb_field agblocks 2>/dev/null` + dbsize=`_scratch_xfs_get_sb_field blocksize 2>/dev/null` + if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then + for ((i = 0; i < agcount; i++)); do + $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \ + $SCRATCH_DEV >/dev/null; + done + fi + + # Try to wipe each SB by default mkfs.xfs geometry + local tmp=`mktemp -u` + unset agcount agsize dbsize + _scratch_mkfs_xfs -N 2>/dev/null | perl -ne ' + if (/^meta-data=.*\s+agcount=(\d+), agsize=(\d+) blks/) { + print STDOUT "agcount=$1\nagsize=$2\n"; + } + if (/^data\s+=\s+bsize=(\d+)\s/) { + print STDOUT "dbsize=$1\n"; + }' > $tmp.mkfs + + . $tmp.mkfs + if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then + for ((i = 0; i < agcount; i++)); do + $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \ + $SCRATCH_DEV >/dev/null; + done + fi + rm -f $tmp.mkfs +}
Signature · 1 line
2.20.1
Quoted 14 lines · Zorro Lang
xfs/030 always fails after
d0e484ac699f("check: wipe scratch devices between tests") get merged.Due to xfs/030 does a sized(100m) mkfs. Before we merge above commit, mkfs.xfs detects an old primary superblock, it will write zeroes to all superblocks before formatting the new filesystem. But this won't be done if we wipe the first superblock(by merging above commit).
That means if we make a (smaller) sized xfs after wipefs, those *old* superblocks which created by last time mkfs.xfs will be left on disk. Then when we do
xfs_repair, ifxfs_repaircan't find the first SB, it will go to find those *old* SB at first. When it finds them, everyting goes wrong.
Quoted 6 lines
So I try to wipe each XFS superblock if there's a XFS ondisk, then try to erase superblock of each XFS AG by default mkfs.xfs geometry. Thanks Darrick J. Wong helped to analyze this issue.
Reported-by Yang Xu <[email protected]>Signed-off-by Zorro Lang <[email protected]>
Looks ok to me,
--D
Quoted 86 lines
---
Hi,
All changes in V3 is under:
# Try to wipe each SB by default mkfs.xfs geometry
...
...Thanks,
Zorrocommon/rc | 8 ++++++++ common/xfs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)common/rc +8
-0@@ -4045,6 +4045,14 @@ _try_wipe_scratch_devs() { test -x "$WIPEFS_PROG" || return 0 + # Do specified filesystem wipe at first + case "$FSTYP" in + "xfs") + _try_wipe_scratch_xfs + ;; + esac + + # Then do wipefs on all scratch devices for dev in $SCRATCH_DEV_POOL $SCRATCH_DEV $SCRATCH_LOGDEV $SCRATCH_RTDEV; do test -b $dev && $WIPEFS_PROG -a $dev donecommon/xfs +40
-0@@ -884,3 +884,43 @@ _xfs_mount_agcount() { $XFS_INFO_PROG "$1" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g' } + +# Wipe the superblock of each XFS AGs +_try_wipe_scratch_xfs() +{ + local num='^[0-9]+$' + local agcount + local agsize + local dbsize + + # Try to wipe each SB if there's an existed XFS + agcount=`_scratch_xfs_get_sb_field agcount 2>/dev/null` + agsize=`_scratch_xfs_get_sb_field agblocks 2>/dev/null` + dbsize=`_scratch_xfs_get_sb_field blocksize 2>/dev/null` + if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then + for ((i = 0; i < agcount; i++)); do + $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \ + $SCRATCH_DEV >/dev/null; + done + fi + + # Try to wipe each SB by default mkfs.xfs geometry + local tmp=`mktemp -u` + unset agcount agsize dbsize + _scratch_mkfs_xfs -N 2>/dev/null | perl -ne ' + if (/^meta-data=.*\s+agcount=(\d+), agsize=(\d+) blks/) { + print STDOUT "agcount=$1\nagsize=$2\n"; + } + if (/^data\s+=\s+bsize=(\d+)\s/) { + print STDOUT "dbsize=$1\n"; + }' > $tmp.mkfs + + . $tmp.mkfs + if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then + for ((i = 0; i < agcount; i++)); do + $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \ + $SCRATCH_DEV >/dev/null; + done + fi + rm -f $tmp.mkfs +}Signature · 1 line
2.20.1