diff --git a/1004-fsck.xfs-try-to-replay-log-if-dirty-during-xfs_repai.patch b/1004-fsck.xfs-try-to-replay-log-if-dirty-during-xfs_repai.patch new file mode 100644 index 0000000000000000000000000000000000000000..35454846917963cd5afe0b878b9f6509dda2d036 --- /dev/null +++ b/1004-fsck.xfs-try-to-replay-log-if-dirty-during-xfs_repai.patch @@ -0,0 +1,79 @@ +From b51b816e769842f9ef422896f89b0cbbcf230b01 Mon Sep 17 00:00:00 2001 +From: Joseph Qi +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 +--- + 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 + diff --git a/xfsprogs.spec b/xfsprogs.spec index 378985953d8e158fffc6ffbd2bd61896a67513eb..90dde7d80e0f2ad16bd84936b977ab2f00a332d7 100644 --- a/xfsprogs.spec +++ b/xfsprogs.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.4 +%define anolis_release .0.5 Summary: Utilities for managing the XFS filesystem Name: xfsprogs Version: 5.0.0 @@ -109,6 +109,7 @@ Patch62: xfsprogs-5.12.0-libfrog-report-inobtcount-in-geometry.patch Patch1001: 1001-xfsprogs-gcc10.patch Patch1002: 1002-xfsprogs-add-atomic-write-support.patch Patch1003: 1003-mkfs-don-t-trample-the-gid-set-in-the-protofile.patch +Patch1004: 1004-fsck.xfs-try-to-replay-log-if-dirty-during-xfs_repai.patch # End: Anolis customized patches %description @@ -214,6 +215,7 @@ Doc pages for %{name}. %patch1001 -p1 %patch1002 -p1 %patch1003 -p1 +%patch1004 -p1 %build export tagname=CC @@ -275,6 +277,9 @@ rm -rf $RPM_BUILD_ROOT/%{_mandir}/man8/xfs_scrub* %doc doc/CHANGES README %changelog +* Mon Nov 21 2022 Joseph Qi - 5.0.0-10.0.5 +- Add fsck log replay support + * Sat Jul 16 2022 Hangbo Fan 5.0.0-10.0.4 - Add doc sub package