10 Star 0 Fork 19

src-anolis-os / xfsprogs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1004-fsck.xfs-try-to-replay-log-if-dirty-during-xfs_repai.patch 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
josephhz 提交于 2022-11-21 14:19 . fsck: add log replay support
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
1
https://gitee.com/src-anolis-os/xfsprogs.git
git@gitee.com:src-anolis-os/xfsprogs.git
src-anolis-os
xfsprogs
xfsprogs
a8

搜索帮助