use btrfsck to check btrfs filesystems
authorMiao Xie <miaox@cn.fujitsu.com>
Wed, 14 Dec 2011 07:35:20 +0000 (15:35 +0800)
committerChristoph Hellwig <hch@lst.de>
Wed, 4 Jan 2012 18:43:00 +0000 (18:43 +0000)
We failed to get fsck program to check the btrfs file system, it is
because btrfs uses its independent check tool which is named btrfsck
to check the file system, so the common checker -- fsck -- could not
find it, and reported there is no checker.

This patch fix it by using btrfsck directly.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
common.rc

index ed3613e1c187829e0e482ca3fcef460eb7c37bb0..6231457c017eb263b3e256a5542b03418e1780f0 100644 (file)
--- a/common.rc
+++ b/common.rc
@@ -1337,6 +1337,54 @@ _check_xfs_test_fs()
     fi
 }
 
+_check_btrfs_filesystem()
+{
+    device=$1
+
+    # If type is set, we're mounted
+    type=`_fs_type $device`
+    ok=1
+
+    if [ "$type" = "$FSTYP" ]
+    then
+        # mounted ...
+        mountpoint=`_umount_or_remount_ro $device`
+    fi
+
+    btrfsck $device >$tmp.fsck 2>&1
+    if [ $? -ne 0 ]
+    then
+        echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seq.full)"
+
+        echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$here/$seq.full
+        echo "*** fsck.$FSTYP output ***"                     >>$here/$seq.full
+        cat $tmp.fsck                                         >>$here/$seq.full
+        echo "*** end fsck.$FSTYP output"                     >>$here/$seq.full
+
+        ok=0
+    fi
+    rm -f $tmp.fsck
+
+    if [ $ok -eq 0 ]
+    then
+        echo "*** mount output ***"                             >>$here/$seq.full
+        _mount                                                  >>$here/$seq.full
+        echo "*** end mount output"                             >>$here/$seq.full
+    elif [ "$type" = "$FSTYP" ]
+    then
+       # was mounted ...
+       _mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
+       ok=$?
+    fi
+
+    if [ $ok -eq 0 ]; then
+       status=1
+       exit 1
+    fi
+
+    return 0
+}
+
 _check_test_fs()
 {
     case $FSTYP in
@@ -1349,6 +1397,9 @@ _check_test_fs()
     udf)
        # do nothing for now
        ;;
+    btrfs)
+       _check_btrfs_filesystem $TEST_DEV
+       ;;
     *)
        _check_generic_filesystem $TEST_DEV
        ;;
@@ -1375,6 +1426,9 @@ _check_scratch_fs()
     nfs*)
        # Don't know how to check an NFS filesystem, yet.
        ;;
+    btrfs)
+       _check_btrfs_filesystem $SCRATCH_DEV
+       ;;
     *)
        _check_generic_filesystem $SCRATCH_DEV
        ;;