代码拉取完成,页面将自动刷新
From b51b816e769842f9ef422896f89b0cbbcf230b01 Mon Sep 17 00:00:00 2001
From: Joseph Qi <joseph.qi@linux.alibaba.com>
Date: Thu, 10 Nov 2022 17:14:42 +0800
Subject: [PATCH] fsck.xfs: try to replay log if dirty during xfs_repair
It is possible that when the machine crashes, the fs is in inconsistent
state with the journal log not yet replayed. This can drop the machine
into the rescue shell because currently fsck.xfs does not address the
journal replay, which brings maintenance trouble.
So try to replay log if it is dirty using mount/umount way which is
suggested in xfs_repair manpage. Note that we only do this for root
device so that we don't want to touch data device.
Administrators have to enable this feature by systemd command options
fsck.mode=force and fsck.repair=yes. For other options, we leave it
behave like before, e.g. drop to the rescue shell if repair detects
any corruptions and need administators repair manually.
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
---
fsck/xfs_fsck.sh | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/fsck/xfs_fsck.sh b/fsck/xfs_fsck.sh
index 6af0f224..768611c7 100755
--- a/fsck/xfs_fsck.sh
+++ b/fsck/xfs_fsck.sh
@@ -31,10 +31,12 @@ repair2fsck_code() {
AUTO=false
FORCE=false
+REPLAY=false
while getopts ":aApyf" c
do
case $c in
- a|A|p|y) AUTO=true;;
+ a|A|p) AUTO=true;;
+ y) REPLAY=true;;
f) FORCE=true;;
esac
done
@@ -64,7 +66,32 @@ fi
if $FORCE; then
xfs_repair -e $DEV
- repair2fsck_code $?
+ error=$?
+ if [ $error -eq 2 ] && [ $REPLAY = true ]; then
+ for x in $(cat /proc/cmdline); do
+ case $x in
+ root=*)
+ ROOT="${x#root=}"
+ ;;
+ rootflags=*)
+ ROOTFLAGS="-o ${x#rootflags=}"
+ ;;
+ esac
+ done
+
+ test -b "$ROOT" || ROOT=$(blkid -t "$ROOT" -o device)
+ if [ $DEV = $ROOT ]; then
+ echo "Replaying log for $DEV"
+ mkdir -p /tmp/replay_mnt || exit 1
+ mount $DEV /tmp/replay_mnt $ROOTFLAGS || exit 1
+ umount /tmp/replay_mnt
+ rm -d /tmp/replay_mnt
+
+ xfs_repair -e $DEV
+ error=$?
+ fi
+ fi
+ repair2fsck_code $error
exit $?
fi
--
2.24.4
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。