LGTM, want to send this to the upstream list to start that discussion? --D ________________________________________ From: Srikanth C S <srikanth.c.s@xxxxxxxxxx> Sent: Monday, October 10, 2022 08:24 To: linux-xfs@xxxxxxxxxxxxxxx; Darrick Wong Cc: Rajesh Sivaramasubramaniom; Junxiao Bi Subject: [PATCH] fsck.xfs: mount/umount xfs fs to replay log before running xfs_repair fsck.xfs does xfs_repair -e if fsck.mode=force is set. It is possible that when the machine crashes, the fs is in inconsistent state with the journal log not yet replayed. This can put the machine into rescue shell. To address this problem, mount and umount the fs before running xfs_repair. Run xfs_repair -e when fsck.mode=force and repair=auto or yes. If fsck.mode=force and fsck.repair=no, run xfs_repair -n without replaying the logs. Signed-off-by: Srikanth C S <srikanth.c.s@xxxxxxxxxx> --- fsck/xfs_fsck.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fsck/xfs_fsck.sh b/fsck/xfs_fsck.sh index 6af0f22..21a8c19 100755 --- a/fsck/xfs_fsck.sh +++ b/fsck/xfs_fsck.sh @@ -63,8 +63,24 @@ if [ -n "$PS1" -o -t 0 ]; then fi if $FORCE; then - xfs_repair -e $DEV - repair2fsck_code $? + if $AUTO; then + xfs_repair -e $DEV + error=$? + if [ $error -eq 2 ]; then + echo "Replaying log for $DEV" + mkdir -p /tmp/tmp_mnt + mount $DEV /tmp/tmp_mnt + umount /tmp/tmp_mnt + xfs_repair -e $DEV + error=$? + rmdir /tmp/tmp_mnt + fi + else + #fsck.mode=force is set but fsck.repair=no + xfs_repair -n $DEV + error=$? + fi + repair2fsck_code $error exit $? fi -- 1.8.3.1