overlay: fix _repair_scratch_fs
authorAmir Goldstein <amir73il@gmail.com>
Tue, 28 May 2019 15:17:21 +0000 (18:17 +0300)
committerEryu Guan <guaneryu@gmail.com>
Sun, 2 Jun 2019 06:56:06 +0000 (14:56 +0800)
_repair_scratch_fs did not do the right thing for overlay.
Implement and call _repair_overlay_scratch_fs to repair
overlay filesystem and then fall through to repair base filesystem.

The only tests currentrly calling _repair_scratch_fs on a
./check -overlay run are generic/330 generic/332 in case the
base fs supports reflink. The rest of the tests calling
_repair_scratch_fs require that $SCRATCH_DEV is a block device.

Suggested-by: zhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/overlay
common/rc

index b526f24d25eb181af60a3a03d35a175df7275a9f..a71c2035ec0a47f99b756b09eaad0e756f736997 100644 (file)
@@ -320,3 +320,20 @@ _check_overlay_scratch_fs()
                "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT" \
                $OVL_BASE_MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS
 }
+
+_repair_overlay_scratch_fs()
+{
+       _overlay_fsck_dirs $OVL_BASE_SCRATCH_MNT/$OVL_LOWER \
+               $OVL_BASE_SCRATCH_MNT/$OVL_UPPER \
+               $OVL_BASE_SCRATCH_MNT/$OVL_WORK -y
+       local res=$?
+       case $res in
+       $FSCK_OK|$FSCK_NONDESTRUCT)
+               res=0
+               ;;
+       *)
+               _dump_err2 "fsck.overlay failed, err=$res"
+               ;;
+       esac
+       return $res
+}
index cedc1cfa962ea04df16fb363a6fd95d40500a0ed..d0aa36a0ff7df01943ed17b51d076fa607ff0343 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1112,8 +1112,17 @@ _repair_scratch_fs()
        return $res
         ;;
     *)
-        # Let's hope fsck -y suffices...
-        fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
+       local dev=$SCRATCH_DEV
+       local fstyp=$FSTYP
+       if [ $FSTYP = "overlay" -a -n "$OVL_BASE_SCRATCH_DEV" ]; then
+               _repair_overlay_scratch_fs
+               # Fall through to repair base fs
+               dev=$OVL_BASE_SCRATCH_DEV
+               fstyp=$OVL_BASE_FSTYP
+               $UMOUNT_PROG $OVL_BASE_SCRATCH_MNT
+       fi
+       # Let's hope fsck -y suffices...
+       fsck -t $fstyp -y $dev 2>&1
        local res=$?
        case $res in
        $FSCK_OK|$FSCK_NONDESTRUCT|$FSCK_REBOOT)