Blame 0052-99fs-lib-fs-lib.sh-fsck-btrfs-via-mounting-like-xfs.patch

Harald Hoyer 55891e
From 662ed0a13f4b497352fe9b6a1d243f06e45c4f3d Mon Sep 17 00:00:00 2001
Harald Hoyer 55891e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 55891e
Date: Thu, 22 Sep 2011 15:12:14 +0200
Harald Hoyer 55891e
Subject: [PATCH] 99fs-lib/fs-lib.sh: fsck btrfs via mounting like xfs
Harald Hoyer 55891e
Harald Hoyer 55891e
btrfsck is only for manual repairing your filesystem
Harald Hoyer 55891e
---
Harald Hoyer 55891e
 modules.d/99fs-lib/fs-lib.sh |   33 ++++++++++++++++++++++++++++++++-
Harald Hoyer 55891e
 1 files changed, 32 insertions(+), 1 deletions(-)
Harald Hoyer 55891e
Harald Hoyer 55891e
diff --git a/modules.d/99fs-lib/fs-lib.sh b/modules.d/99fs-lib/fs-lib.sh
Harald Hoyer 55891e
index f7b20dd..edb5852 100755
Harald Hoyer 55891e
--- a/modules.d/99fs-lib/fs-lib.sh
Harald Hoyer 55891e
+++ b/modules.d/99fs-lib/fs-lib.sh
Harald Hoyer 55891e
@@ -59,7 +59,7 @@ fsck_able() {
Harald Hoyer 55891e
             ;;
Harald Hoyer 55891e
         btrfs)
Harald Hoyer 55891e
             type btrfsck >/dev/null 2>&1 &&
Harald Hoyer 55891e
-            _drv="_drv=btrfsck fsck_drv_com" &&
Harald Hoyer 55891e
+            _drv="_drv=none fsck_drv_btrfs" &&
Harald Hoyer 55891e
             return 0
Harald Hoyer 55891e
             ;;
Harald Hoyer 55891e
         *)
Harald Hoyer 55891e
@@ -104,6 +104,37 @@ fsck_drv_xfs() {
Harald Hoyer 55891e
     return $_ret
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
+fsck_drv_btrfs() {
Harald Hoyer 55891e
+    local _ret
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+    # fs must be cleanly mounted (and umounted) first, before attempting any
Harald Hoyer 55891e
+    # btrfs tools - if this works, nothing else should be needed
Harald Hoyer 55891e
+    # note, that user is always dropped into the shell, if the filesystem is
Harald Hoyer 55891e
+    # not mountable or if -f flag is found among _fop
Harald Hoyer 55891e
+    mkdir -p /tmp/.btrfs
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+    info "trying to mount $_dev"
Harald Hoyer 55891e
+    if mount -t btrfs "$_dev" "/tmp/.btrfs" >/dev/null 2>&1; then
Harald Hoyer 55891e
+        _ret=0
Harald Hoyer 55891e
+        info "btrfs: $_dev is clean"
Harald Hoyer 55891e
+        umount "$_dev" >/dev/null 2>&1
Harald Hoyer 55891e
+    else
Harald Hoyer 55891e
+        _ret=4
Harald Hoyer 55891e
+        warn "*** $_dev is unmountable"
Harald Hoyer 55891e
+    fi
Harald Hoyer 55891e
+    if [ $_ret -gt 0 ] || strstr "$_fop" "-f"; then
Harald Hoyer 55891e
+        warn "*** Dropping you to a shell. You have"
Harald Hoyer 55891e
+        warn "*** btrfsck available."
Harald Hoyer 55891e
+        warn "*** Note that if btrfs didn't mount properly, it's"
Harald Hoyer 55891e
+        warn "*** probably pretty serious condition."
Harald Hoyer 55891e
+        emergency_shell -n "(Repair filesystem)"
Harald Hoyer 55891e
+    fi
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+    rm -r /tmp/.btrfs
Harald Hoyer 55891e
+    return $_ret
Harald Hoyer 55891e
+}
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+
Harald Hoyer 55891e
 # common code for checkers that follow usual subset of options and return codes
Harald Hoyer 55891e
 fsck_drv_com() {
Harald Hoyer 55891e
     local _ret