From patchwork Tue Oct 16 07:45:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10643185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CC8F3C13 for ; Tue, 16 Oct 2018 07:32:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3860298E5 for ; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6BB329A1E; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6BA229A21 for ; Tue, 16 Oct 2018 07:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbeJPPVn (ORCPT ); Tue, 16 Oct 2018 11:21:43 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14077 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726962AbeJPPVn (ORCPT ); Tue, 16 Oct 2018 11:21:43 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C7B42B9779879; Tue, 16 Oct 2018 15:32:32 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.399.0; Tue, 16 Oct 2018 15:32:24 +0800 From: "zhangyi (F)" To: , CC: , , , Subject: [PATCH v2 1/4] overlay: correct fsck.overlay exit code Date: Tue, 16 Oct 2018 15:45:56 +0800 Message-ID: <20181016074559.24728-2-yi.zhang@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181016074559.24728-1-yi.zhang@huawei.com> References: <20181016074559.24728-1-yi.zhang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: zhangyi (F) --- common/overlay | 29 +++++++++++++++++++++++++++++ tests/overlay/045 | 27 +++++++++------------------ tests/overlay/046 | 36 ++++++++++++------------------------ tests/overlay/056 | 9 +++------ 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/common/overlay b/common/overlay index b526f24..4cc2829 100644 --- a/common/overlay +++ b/common/overlay @@ -12,6 +12,16 @@ export OVL_XATTR_NLINK="trusted.overlay.nlink" export OVL_XATTR_UPPER="trusted.overlay.upper" export OVL_XATTR_METACOPY="trusted.overlay.metacopy" +# Export exit code used by fsck.overlay program +export FSCK_OK=0 +export FSCK_NONDESTRUCT=1 +export FSCK_REBOOT=2 +export FSCK_UNCORRECTED=4 +export FSCK_ERROR=8 +export FSCK_USAGE=16 +export FSCK_CANCELED=32 +export FSCK_LIBRARY=128 + # helper function to do the actual overlayfs mount operation _overlay_mount_dirs() { @@ -193,6 +203,25 @@ _overlay_fsck_dirs() -o workdir=$workdir $* } +# Run fsck and check the return value +_run_check_fsck() +{ + # The first arguments is the expected fsck program exit code, the + # remaining arguments are the input parameters of the fsck program. + local expect_ret=$1 + local lowerdir=$2 + local upperdir=$3 + local workdir=$4 + shift 4 + + _overlay_fsck_dirs $lowerdir $upperdir $workdir $* >> \ + $seqres.full 2>&1 + fsck_ret=$? + + [[ "$fsck_ret" == "$expect_ret" ]] || \ + echo "fsck return unexpected value:$expect_ret,$fsck_ret" +} + _overlay_check_dirs() { local lowerdir=$1 diff --git a/tests/overlay/045 b/tests/overlay/045 index acc7087..ed23258 100755 --- a/tests/overlay/045 +++ b/tests/overlay/045 @@ -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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $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" +_run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_whiteout $upperdir/testdir/subdir/foo # success, all done diff --git a/tests/overlay/046 b/tests/overlay/046 index 6338a38..21645c1 100755 --- a/tests/overlay/046 +++ b/tests/overlay/046 @@ -121,8 +121,7 @@ echo "+ Invalid redirect" make_test_dirs make_redirect_dir $upperdir/testdir "invalid" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p check_no_redirect $upperdir/testdir # Test invalid redirect xattr point to a file origin, should remove @@ -131,8 +130,7 @@ make_test_dirs touch $lowerdir/origin make_redirect_dir $upperdir/testdir "origin" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p check_no_redirect $upperdir/testdir # Test valid redirect xattr point to a directory origin in the same directory, @@ -143,8 +141,7 @@ mkdir $lowerdir/origin make_whiteout $upperdir/origin make_redirect_dir $upperdir/testdir "origin" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir "origin" # Test valid redirect xattr point to a directory origin in different directories @@ -155,8 +152,7 @@ mkdir $lowerdir/origin make_whiteout $upperdir/origin make_redirect_dir $upperdir/testdir1/testdir2 "/origin" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir1/testdir2 "/origin" # Test valid redirect xattr but missing whiteout to cover lower target, @@ -166,8 +162,7 @@ make_test_dirs mkdir $lowerdir/origin make_redirect_dir $upperdir/testdir "origin" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir "origin" check_whiteout $upperdir/origin @@ -178,8 +173,7 @@ mkdir $lowerdir/{testdir1,testdir2} make_redirect_dir $upperdir/testdir1 "testdir2" make_redirect_dir $upperdir/testdir2 "testdir1" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir1 "testdir2" check_redirect $upperdir/testdir2 "testdir1" @@ -191,8 +185,7 @@ mkdir $lowerdir/testdir make_redirect_dir $upperdir/testdir "invalid" # Question get yes answer: Should set opaque dir ? -_overlay_fsck_dirs $lowerdir $upperdir $workdir -y >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -y check_no_redirect $upperdir/testdir check_opaque $upperdir/testdir @@ -205,12 +198,10 @@ make_redirect_dir $lowerdir/testdir1 "origin" make_redirect_dir $lowerdir/testdir2 "origin" make_redirect_dir $upperdir/testdir3 "origin" -_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p >> \ - $seqres.full 2>&1 && echo "fsck should fail" +_run_check_fsck $FSCK_UNCORRECTED "$lowerdir:$lowerdir2" $upperdir $workdir -p # Question get yes answer: Duplicate redirect directory, remove xattr ? -_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -y >> \ - $seqres.full 2>&1 || echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT "$lowerdir:$lowerdir2" $upperdir $workdir -y redirect_1=`check_redirect $lowerdir/testdir1 "origin" 2>/dev/null` redirect_2=`check_redirect $lowerdir/testdir2 "origin" 2>/dev/null` [[ $redirect_1 == $redirect_2 ]] && echo "Redirect xattr incorrect" @@ -223,12 +214,10 @@ make_test_dirs mkdir $lowerdir/origin $upperdir/origin make_redirect_dir $upperdir/testdir "origin" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 && \ - echo "fsck should fail" +_run_check_fsck $FSCK_UNCORRECTED $lowerdir $upperdir $workdir -p # Question get yes answer: Duplicate redirect directory, remove xattr ? -_overlay_fsck_dirs $lowerdir $upperdir $workdir -y >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -y check_no_redirect $upperdir/testdir # Test duplicate redirect xattr with lower same name directory exists, @@ -240,8 +229,7 @@ make_redirect_dir $upperdir/testdir "invalid" # Question one get yes answer: Duplicate redirect directory, remove xattr? # Question two get yes answer: Should set opaque dir ? -_overlay_fsck_dirs $lowerdir $upperdir $workdir -y >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -y check_no_redirect $upperdir/testdir check_opaque $upperdir/testdir diff --git a/tests/overlay/056 b/tests/overlay/056 index 44ffb54..8679b55 100755 --- a/tests/overlay/056 +++ b/tests/overlay/056 @@ -96,8 +96,7 @@ $UMOUNT_PROG $SCRATCH_MNT remove_impure $upperdir/testdir1 remove_impure $upperdir/testdir2 -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p check_impure $upperdir/testdir1 check_impure $upperdir/testdir2 @@ -108,8 +107,7 @@ make_test_dirs mkdir $lowerdir/origin make_redirect_dir $upperdir/testdir/subdir "/origin" -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p check_impure $upperdir/testdir # Test missing impure xattr in directory which has merge directories, @@ -118,8 +116,7 @@ echo "+ Missing impure(3)" make_test_dirs mkdir $lowerdir/testdir $upperdir/testdir -_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ - echo "fsck should not fail" +_run_check_fsck $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p check_impure $upperdir # success, all done From patchwork Tue Oct 16 07:45:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10643177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54FC9925 for ; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3649529A02 for ; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 270F329A39; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D4BA29A02 for ; Tue, 16 Oct 2018 07:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726649AbeJPPVm (ORCPT ); Tue, 16 Oct 2018 11:21:42 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14081 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726968AbeJPPVl (ORCPT ); Tue, 16 Oct 2018 11:21:41 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D484653581369; Tue, 16 Oct 2018 15:32:32 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.399.0; Tue, 16 Oct 2018 15:32:25 +0800 From: "zhangyi (F)" To: , CC: , , , Subject: [PATCH v2 2/4] overlay: fix exit code for some fsck.overlay valid cases Date: Tue, 16 Oct 2018 15:45:57 +0800 Message-ID: <20181016074559.24728-3-yi.zhang@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181016074559.24728-1-yi.zhang@huawei.com> References: <20181016074559.24728-1-yi.zhang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some valid test cases about fsck.overlay may be not valid enough now, they lose the impure xattr on the parent directory of the simluated redirect directory, and lose the whiteout which use to cover the origin lower object. Then fsck.overlay will fix these two inconsistency which are not those test cases want to cover, thus it will lead to fsck.overlay return FSCK_NONDESTRUCT instead of FSCK_OK. Fix these by complement the missing overlay related features. Signed-off-by: zhangyi (F) --- tests/overlay/045 | 19 ++++++++++++++++--- tests/overlay/046 | 13 +++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/overlay/045 b/tests/overlay/045 index ed23258..ffca47f 100755 --- a/tests/overlay/045 +++ b/tests/overlay/045 @@ -37,6 +37,7 @@ _require_attrs _require_command "$FSCK_OVERLAY_PROG" fsck.overlay OVL_XATTR_OPAQUE_VAL=y +OVL_XATTR_IMPURE_VAL=y # remove all files from previous tests _scratch_mkfs @@ -69,6 +70,15 @@ make_opaque_dir() $SETFATTR_PROG -n $OVL_XATTR_OPAQUE -v $OVL_XATTR_OPAQUE_VAL $target } +# Create impure directories +make_impure_dir() +{ + for dir in $*; do + mkdir -p $dir + $SETFATTR_PROG -n $OVL_XATTR_IMPURE -v $OVL_XATTR_IMPURE_VAL $dir + done +} + # Create a redirect directory make_redirect_dir() { @@ -155,8 +165,9 @@ echo "+ Valid whiteout(2)" make_test_dirs mkdir $lowerdir/origin touch $lowerdir/origin/foo +make_impure_dir $upperdir make_redirect_dir $upperdir/testdir "origin" -make_whiteout $upperdir/testdir/foo +make_whiteout $upperdir/origin $upperdir/testdir/foo _run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_whiteout $upperdir/testdir/foo @@ -169,7 +180,8 @@ mkdir -p $lowerdir2/origin/subdir touch $lowerdir2/origin/subdir/foo make_redirect_dir $lowerdir/testdir "origin" mkdir -p $upperdir/testdir/subdir -make_whiteout $upperdir/testdir/subdir/foo +make_whiteout $lowerdir/origin $upperdir/testdir/subdir/foo +make_impure_dir $upperdir/testdir $upperdir _run_check_fsck $FSCK_OK "$lowerdir:$lowerdir2" $upperdir $workdir -p check_whiteout $upperdir/testdir/subdir/foo @@ -195,7 +207,8 @@ mkdir $lowerdir/origin touch $lowerdir/origin/foo make_opaque_dir $upperdir/testdir make_redirect_dir $upperdir/testdir/subdir "/origin" -make_whiteout $upperdir/testdir/subdir/foo +make_whiteout $upperdir/origin $upperdir/testdir/subdir/foo +make_impure_dir $upperdir/testdir _run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_whiteout $upperdir/testdir/subdir/foo diff --git a/tests/overlay/046 b/tests/overlay/046 index 21645c1..ea4b14f 100755 --- a/tests/overlay/046 +++ b/tests/overlay/046 @@ -40,6 +40,16 @@ _require_command "$FSCK_OVERLAY_PROG" fsck.overlay _scratch_mkfs OVL_XATTR_OPAQUE_VAL=y +OVL_XATTR_IMPURE_VAL=y + +# Create impure directories +make_impure_dir() +{ + for dir in $*; do + mkdir -p $dir + $SETFATTR_PROG -n $OVL_XATTR_IMPURE -v $OVL_XATTR_IMPURE_VAL $dir + done +} # Create a redirect directory make_redirect_dir() @@ -140,6 +150,7 @@ make_test_dirs mkdir $lowerdir/origin make_whiteout $upperdir/origin make_redirect_dir $upperdir/testdir "origin" +make_impure_dir $upperdir _run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir "origin" @@ -151,6 +162,7 @@ make_test_dirs mkdir $lowerdir/origin make_whiteout $upperdir/origin make_redirect_dir $upperdir/testdir1/testdir2 "/origin" +make_impure_dir $upperdir/testdir1 _run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir1/testdir2 "/origin" @@ -172,6 +184,7 @@ make_test_dirs mkdir $lowerdir/{testdir1,testdir2} make_redirect_dir $upperdir/testdir1 "testdir2" make_redirect_dir $upperdir/testdir2 "testdir1" +make_impure_dir $upperdir _run_check_fsck $FSCK_OK $lowerdir $upperdir $workdir -p check_redirect $upperdir/testdir1 "testdir2" From patchwork Tue Oct 16 07:45:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10643183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 029453CF1 for ; Tue, 16 Oct 2018 07:32:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB41F299F7 for ; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF891298E5; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C724299F7 for ; Tue, 16 Oct 2018 07:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726978AbeJPPVm (ORCPT ); Tue, 16 Oct 2018 11:21:42 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14080 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726649AbeJPPVl (ORCPT ); Tue, 16 Oct 2018 11:21:41 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D0839E1805B86; Tue, 16 Oct 2018 15:32:32 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.399.0; Tue, 16 Oct 2018 15:32:25 +0800 From: "zhangyi (F)" To: , CC: , , , Subject: [PATCH v2 3/4] overlay: add fsck.overlay stress test Date: Tue, 16 Oct 2018 15:45:58 +0800 Message-ID: <20181016074559.24728-4-yi.zhang@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181016074559.24728-1-yi.zhang@huawei.com> References: <20181016074559.24728-1-yi.zhang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a test case for fsck.overlay which runs on the underlying directories created by fsstress (contain a lot of fs objects) to find potential stability issue. Signed-off-by: zhangyi (F) --- tests/overlay/062 | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/062.out | 2 ++ tests/overlay/group | 1 + 3 files changed, 87 insertions(+) create mode 100755 tests/overlay/062 create mode 100644 tests/overlay/062.out diff --git a/tests/overlay/062 b/tests/overlay/062 new file mode 100755 index 0000000..f818562 --- /dev/null +++ b/tests/overlay/062 @@ -0,0 +1,84 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2018 Huawei. All Rights Reserved. +# +# FS QA Test No. 062 +# +# Stress test: test fsck.overlay running on the underlying dirs +# which were created by fsstress. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/attr + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_supported_os Linux +_require_scratch_nocheck +_require_command "$FSCK_OVERLAY_PROG" fsck.overlay + +# remove all files from previous tests +_scratch_mkfs + +# Create an underlying layer which contain a lot of random objects +create_layer() +{ + for dir in $*; do + seed=$RANDOM + echo "create random file system objects in $dir with seed $seed" \ + >> $seqres.full + + $FSSTRESS_PROG -s $seed -d $dir -z \ + -f creat=20 -f link=10 -f mkdir=20 -f mknod=10 \ + -f rename=10 -f setxattr=10 -f symlink=10 -f write=10 \ + -p 4 -n 500 -l50 > /dev/null 2>&1 + done +} + + +# Create test directories +lowerdir=$OVL_BASE_SCRATCH_MNT/$seq-ovl-lower +lowerdir2=$OVL_BASE_SCRATCH_MNT/$seq-ovl-lower2 +upperdir=$OVL_BASE_SCRATCH_MNT/$seq-ovl-upper +workdir=$OVL_BASE_SCRATCH_MNT/$seq-ovl-workdir + +make_test_dirs() +{ + rm -rf $lowerdir $lowerdir2 $upperdir $workdir + mkdir -p $lowerdir $lowerdir2 $upperdir $workdir +} + + +# Test stability, should not crash and should not fail on "yes" mode. +make_test_dirs +create_layer $lowerdir2 $lowerdir $upperdir + +_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -y >> \ + $seqres.full 2>&1 + +[[ "$?" == "$FSCK_OK" || "$?" == "$FSCK_NONDESTRUCT" ]] || \ + echo "fsck return unexpected $?" + +# success, all done +echo "Silence is golden" +status=0 +exit diff --git a/tests/overlay/062.out b/tests/overlay/062.out new file mode 100644 index 0000000..a1578f4 --- /dev/null +++ b/tests/overlay/062.out @@ -0,0 +1,2 @@ +QA output created by 062 +Silence is golden diff --git a/tests/overlay/group b/tests/overlay/group index ccc71f3..b308427 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -64,3 +64,4 @@ 059 auto quick copyup 060 auto quick metacopy 061 auto quick copyup +062 auto stress fsck From patchwork Tue Oct 16 07:45:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10643181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D92AC14E2 for ; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCA5B298E5 for ; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B124129A02; Tue, 16 Oct 2018 07:32:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DD4E29A0F for ; Tue, 16 Oct 2018 07:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbeJPPVm (ORCPT ); Tue, 16 Oct 2018 11:21:42 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14079 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726976AbeJPPVm (ORCPT ); Tue, 16 Oct 2018 11:21:42 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C2878AD3F3E10; Tue, 16 Oct 2018 15:32:32 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.399.0; Tue, 16 Oct 2018 15:32:26 +0800 From: "zhangyi (F)" To: , CC: , , , Subject: [PATCH v2 4/4] overlay: add fsck.overlay exception tests Date: Tue, 16 Oct 2018 15:45:59 +0800 Message-ID: <20181016074559.24728-5-yi.zhang@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181016074559.24728-1-yi.zhang@huawei.com> References: <20181016074559.24728-1-yi.zhang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce some exception test cases for fsck.overlay which runs on invalid/unnormal underlying dirs or invalid input parameters to test exception handling processes. This patch also change _overlay_fsck_dirs() helper function to be able to receive empty underlying dir arguments, which is used by this test to cover the case of incomplete underlying dirs. Signed-off-by: zhangyi (F) --- common/overlay | 8 +- tests/overlay/063 | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/063.out | 10 +++ tests/overlay/group | 1 + 4 files changed, 234 insertions(+), 2 deletions(-) create mode 100755 tests/overlay/063 create mode 100644 tests/overlay/063.out diff --git a/common/overlay b/common/overlay index 4cc2829..2896594 100644 --- a/common/overlay +++ b/common/overlay @@ -195,12 +195,16 @@ _overlay_fsck_dirs() local lowerdir=$1 local upperdir=$2 local workdir=$3 + local dirs="" shift 3 [[ ! -x "$FSCK_OVERLAY_PROG" ]] && return 0 - $FSCK_OVERLAY_PROG -o lowerdir=$lowerdir -o upperdir=$upperdir \ - -o workdir=$workdir $* + [[ -n "$lowerdir" ]] && dirs=$(echo -n "-o lowerdir=$lowerdir") + [[ -n "$upperdir" ]] && dirs=$(echo -n "$dirs -o upperdir=$upperdir") + [[ -n "$workdir" ]] && dirs=$(echo -n "$dirs -o workdir=$workdir") + + $FSCK_OVERLAY_PROG $dirs $* } # Run fsck and check the return value diff --git a/tests/overlay/063 b/tests/overlay/063 new file mode 100755 index 0000000..e2c771a --- /dev/null +++ b/tests/overlay/063 @@ -0,0 +1,217 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2018 Huawei. All Rights Reserved. +# +# FS QA Test No. 063 +# +# Exception test: test fsck.overlay runs on invalid underlying +# dirs or with invalid input options. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + $CHATTR_PROG -i $upperdir/testdir + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/attr + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_supported_os Linux +_require_scratch_nocheck +_require_attrs +_require_command "$FSCK_OVERLAY_PROG" fsck.overlay +_require_chattr i + +# remove all files from previous tests +_scratch_mkfs + +# Create a whiteout +make_whiteout() +{ + for arg in $*; do + mknod $arg c 0 0 + done +} + +# Create a redirect directory +make_redirect_dir() +{ + local target=$1 + local value=$2 + + mkdir -p $target + $SETFATTR_PROG -n $OVL_XATTR_REDIRECT -v $value $target +} + +# Create test directories +lowerdir=$OVL_BASE_SCRATCH_MNT/lower +lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2 +upperdir=$OVL_BASE_SCRATCH_MNT/upper +workdir=$OVL_BASE_SCRATCH_MNT/workdir + +make_test_dirs() +{ + rm -rf $lowerdir $lowerdir2 $upperdir $workdir + mkdir -p $lowerdir $lowerdir2 $upperdir $workdir +} + +# Test incomplete underlying dirs, should fail +echo "+ Invalid input" +make_test_dirs + +none_dir="" + +_run_check_fsck $FSCK_USAGE $lowerdir "$none_dir" "$none_dir" +_run_check_fsck $FSCK_USAGE $lowerdir $upperdir "$none_dir" +_run_check_fsck $FSCK_USAGE "$none_dir" $upperdir $workdir + + +# Test invalid underlying dirs, should fail +echo "+ Invalid input(2)" +make_test_dirs + +invalid_dir=$OVL_BASE_SCRATCH_MNT/invalid_dir + +_run_check_fsck $FSCK_ERROR $lowerdir $upperdir $invalid_dir +_run_check_fsck $FSCK_ERROR $lowerdir $invalid_dir $workdir +_run_check_fsck $FSCK_ERROR $invalid_dir $upperdir $workdir + + +# Test conflict input options, should fail +echo "+ Invalid input(3)" +make_test_dirs + +_run_check_fsck $FSCK_USAGE $lowerdir $upperdir $workdir -pn +_run_check_fsck $FSCK_USAGE $lowerdir $upperdir $workdir -yn +_run_check_fsck $FSCK_USAGE $lowerdir $upperdir $workdir -py +_run_check_fsck $FSCK_USAGE $lowerdir $upperdir $workdir -pyn + + +# Test upperdir and workdir belong to different base filesystems, should fail +echo "+ Invalid workdir" +make_test_dirs + +test_workdir=$OVL_BASE_TEST_DIR/work +mkdir -p $test_workdir +_run_check_fsck $FSCK_ERROR $lowerdir $upperdir $test_workdir +rm -rf $test_workdir + + +# Test upperdir is subdir of workdir and vice versa, should fail +echo "+ Invalid workdir(2)" +make_test_dirs + +test_workdir=$upperdir/work +test_upperdir=$workdir/upper +mkdir -p $test_workdir $test_upperdir + +_run_check_fsck $FSCK_ERROR $lowerdir $upperdir $test_workdir +_run_check_fsck $FSCK_ERROR $lowerdir $test_upperdir $workdir + + +# Test upper layer is read-only, should fail in "!no" mode, and should +# return the real consistent result in "no" mode. +echo "+ Upper read-only" +make_test_dirs + +test_lowerdir=$OVL_BASE_TEST_DIR/lower +mkdir -p $test_lowerdir + +# Let upper layer read-only +$MOUNT_PROG -o remount,ro $OVL_BASE_SCRATCH_MNT > /dev/null 2>&1 +# Refuse to check read-only upper layer +_run_check_fsck $FSCK_ERROR $test_lowerdir $upperdir $workdir +_run_check_fsck $FSCK_ERROR $test_lowerdir $upperdir $workdir -p +_run_check_fsck $FSCK_ERROR $test_lowerdir $upperdir $workdir -y +# Allow to use "no" mode scan read-only upper layer +_run_check_fsck $FSCK_OK $test_lowerdir $upperdir $workdir -n +$MOUNT_PROG -o remount,rw $OVL_BASE_SCRATCH_MNT > /dev/null 2>&1 + +# Make a simple inconsistency on the upper layer and expect return failure +make_whiteout $upperdir/invalid +$MOUNT_PROG -o remount,ro $OVL_BASE_SCRATCH_MNT > /dev/null 2>&1 +_run_check_fsck $FSCK_UNCORRECTED $test_lowerdir $upperdir $workdir -n +$MOUNT_PROG -o remount,rw $OVL_BASE_SCRATCH_MNT > /dev/null 2>&1 +rm -rf $test_lowerdir + + +# Test lower layer is read-only, should sacn each layer and return +# the real consistent result. +echo "+ Lower read-only" +make_test_dirs + +test_lowerdir=$OVL_BASE_TEST_DIR/lower +mkdir -p $test_lowerdir + +# Let lower layer read-only +$MOUNT_PROG -o remount,ro $OVL_BASE_TEST_DIR > /dev/null 2>&1 +# Allow check read-only lower layers in all modes +_run_check_fsck $FSCK_OK $test_lowerdir $upperdir $workdir -p +$MOUNT_PROG -o remount,rw $OVL_BASE_TEST_DIR > /dev/null 2>&1 + +# Make a simple inconsistency on the read-only lower layer and expect +# return failure. +make_whiteout $test_lowerdir/invalid +$MOUNT_PROG -o remount,ro $OVL_BASE_TEST_DIR > /dev/null 2>&1 +_run_check_fsck $FSCK_UNCORRECTED $test_lowerdir $upperdir $workdir -p +$MOUNT_PROG -o remount,rw $OVL_BASE_TEST_DIR > /dev/null 2>&1 +rm -rf $test_lowerdir + + +# Test one of the lower layers is read-only, should sacn each layer and +# return the real consistent result. +echo "+ Lower read-only(2)" +make_test_dirs + +test_lowerdir=$OVL_BASE_TEST_DIR/lower +mkdir -p $test_lowerdir + +# Let lower layer read-only +$MOUNT_PROG -o remount,ro $OVL_BASE_TEST_DIR > /dev/null 2>&1 +# Make a simple inconsistency on the bottom read-write lower layer +# and expect return success (consistent middle read-only layer should +# not affect the result). +make_whiteout $lowerdir2/invalid +_run_check_fsck $FSCK_NONDESTRUCT $test_lowerdir:$lowerdir2 $upperdir $workdir -p +$MOUNT_PROG -o remount,rw $OVL_BASE_TEST_DIR > /dev/null 2>&1 + +# Make a simple inconsistency on the middle read-only lower layer +# and expect return failure. +make_whiteout $test_lowerdir/invalid +$MOUNT_PROG -o remount,ro $OVL_BASE_TEST_DIR > /dev/null 2>&1 +_run_check_fsck $FSCK_UNCORRECTED $test_lowerdir:$lowerdir2 $upperdir $workdir -p +$MOUNT_PROG -o remount,rw $OVL_BASE_TEST_DIR > /dev/null 2>&1 +rm -rf $test_lowerdir + + +# Test encounter error when try to fix some inconsistency, should fail +echo "+ Encounter error" +make_test_dirs + +# Make a simple inconsistency and set immutable flag to simulate fix error +make_redirect_dir $upperdir/testdir "invalid" + +$CHATTR_PROG +i $upperdir/testdir +_run_check_fsck $(($FSCK_UNCORRECTED+$FSCK_ERROR)) $lowerdir $upperdir $workdir -p +$CHATTR_PROG -i $upperdir/testdir + +# success, all done +status=0 +exit diff --git a/tests/overlay/063.out b/tests/overlay/063.out new file mode 100644 index 0000000..2c5dd37 --- /dev/null +++ b/tests/overlay/063.out @@ -0,0 +1,10 @@ +QA output created by 063 ++ Invalid input ++ Invalid input(2) ++ Invalid input(3) ++ Invalid workdir ++ Invalid workdir(2) ++ Upper read-only ++ Lower read-only ++ Lower read-only(2) ++ Encounter error diff --git a/tests/overlay/group b/tests/overlay/group index b308427..668329d 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -65,3 +65,4 @@ 060 auto quick metacopy 061 auto quick copyup 062 auto stress fsck +063 auto quick fsck