overlay: correct fsck.overlay exit code

fsck.overlay should return correct exit code to show the file system
status after fsck, instead of return 0 means consistency and !0 means
inconsistency or something bad happened.

Fix the following three exit code after running fsck.overlay:

- Return FSCK_OK if the input file system is consistent,
- Return FSCK_NONDESTRUCT if the file system inconsistent errors
  corrected,
- Return FSCK_UNCORRECTED if the file system still have inconsistent
  errors.

This patch also add a helper function to run fsck.overlay and check
the return value is expected or not.

[amir] rename helper to _overlay_fsck_expect, split define of FSCK_*
to a seprate path.

Signed-off-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>
This commit is contained in:
zhangyi (F)
2019-05-28 18:17:22 +03:00
committed by Eryu Guan
parent d9f4cb7271
commit af3a63c4dc
4 changed files with 43 additions and 48 deletions
+9 -18
View File
@@ -96,8 +96,7 @@ echo "+ Orphan whiteout"
make_test_dirs
make_whiteout $lowerdir/foo $upperdir/{foo,bar}
_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
echo "fsck should not fail"
_overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
ls $lowerdir
ls $upperdir
@@ -107,8 +106,7 @@ make_test_dirs
touch $lowerdir2/{foo,bar}
make_whiteout $upperdir/foo $lowerdir/bar
_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p >> \
$seqres.full 2>&1 || echo "fsck should not fail"
_overlay_fsck_expect $FSCK_OK "$lowerdir:$lowerdir2" $upperdir $workdir -p
check_whiteout $upperdir/foo $lowerdir/bar
# Test orphan whiteout in opaque directory, should remove
@@ -119,8 +117,7 @@ touch $lowerdir/testdir/foo
make_opaque_dir $upperdir/testdir
make_whiteout $upperdir/testdir/foo
_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
echo "fsck should not fail"
_overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
ls $upperdir/testdir
# Test orphan whiteout whose parent path is not an merged directory,
@@ -135,8 +132,7 @@ make_whiteout $lowerdir/testdir2
make_opaque_dir $lowerdir/testdir3
make_whiteout $upperdir/{testdir1/foo,/testdir2/foo,testdir3/foo,testdir4/foo}
_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p >> \
$seqres.full 2>&1 || echo "fsck should not fail"
_overlay_fsck_expect $FSCK_NONDESTRUCT "$lowerdir:$lowerdir2" $upperdir $workdir -p
ls $upperdir/testdir1
ls $upperdir/testdir2
ls $upperdir/testdir3
@@ -150,8 +146,7 @@ touch $lowerdir/testdir/foo
make_redirect_dir $upperdir/testdir "origin"
make_whiteout $upperdir/testdir/foo
_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
echo "fsck should not fail"
_overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
ls $upperdir/testdir
# Test valid whiteout in redirect directory cover file in lower
@@ -163,8 +158,7 @@ touch $lowerdir/origin/foo
make_redirect_dir $upperdir/testdir "origin"
make_whiteout $upperdir/testdir/foo
_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
echo "fsck should not fail"
_overlay_fsck_expect $FSCK_OK $lowerdir $upperdir $workdir -p
check_whiteout $upperdir/testdir/foo
# Test valid whiteout covering lower target whose parent directory
@@ -177,8 +171,7 @@ make_redirect_dir $lowerdir/testdir "origin"
mkdir -p $upperdir/testdir/subdir
make_whiteout $upperdir/testdir/subdir/foo
_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p \
>> $seqres.full 2>&1 || echo "fsck should not fail"
_overlay_fsck_expect $FSCK_OK "$lowerdir:$lowerdir2" $upperdir $workdir -p
check_whiteout $upperdir/testdir/subdir/foo
# Test invalid whiteout in opaque subdirectory in a redirect directory,
@@ -191,8 +184,7 @@ make_redirect_dir $upperdir/testdir "origin"
make_opaque_dir $upperdir/testdir/subdir
make_whiteout $upperdir/testdir/subdir/foo
_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
echo "fsck should not fail"
_overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
ls $upperdir/testdir/subdir
# Test valid whiteout in reidrect subdirectory in a opaque directory
@@ -205,8 +197,7 @@ make_opaque_dir $upperdir/testdir
make_redirect_dir $upperdir/testdir/subdir "/origin"
make_whiteout $upperdir/testdir/subdir/foo
_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
echo "fsck should not fail"
_overlay_fsck_expect $FSCK_OK $lowerdir $upperdir $workdir -p
check_whiteout $upperdir/testdir/subdir/foo
# success, all done