From patchwork Wed Jan 31 10:26:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10193779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7E4460595 for ; Wed, 31 Jan 2018 10:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8457B285CE for ; Wed, 31 Jan 2018 10:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7918A285EF; Wed, 31 Jan 2018 10:17:50 +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=-6.9 required=2.0 tests=BAYES_00,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 00747285EC for ; Wed, 31 Jan 2018 10:17:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753371AbeAaKRt (ORCPT ); Wed, 31 Jan 2018 05:17:49 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:58659 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752935AbeAaKRp (ORCPT ); Wed, 31 Jan 2018 05:17:45 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5C1CFB6CD5D3B; Wed, 31 Jan 2018 18:17:41 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 31 Jan 2018 18:17:36 +0800 From: "zhangyi (F)" To: , CC: , , , , , Subject: [xfstests PATCH v2 4/4] overlay: add fsck.overlay impure xattr test Date: Wed, 31 Jan 2018 18:26:04 +0800 Message-ID: <20180131102604.40701-5-yi.zhang@huawei.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180131102604.40701-1-yi.zhang@huawei.com> References: <20180131102604.40701-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 Add fsck.overlay test case to test it how to deal with impure xattr in underlying directories of overlayfs. Signed-off-by: zhangyi (F) Reviewed-by: Amir Goldstein --- tests/overlay/203 | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/203.out | 4 ++ tests/overlay/group | 1 + 3 files changed, 148 insertions(+) create mode 100755 tests/overlay/203 create mode 100644 tests/overlay/203.out diff --git a/tests/overlay/203 b/tests/overlay/203 new file mode 100755 index 0000000..5441b44 --- /dev/null +++ b/tests/overlay/203 @@ -0,0 +1,143 @@ +#! /bin/bash +# FS QA Test 203 +# +# Test fsck.overlay how to deal with impure xattr in overlayfs. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Huawei. All Rights Reserved. +# Author: zhangyi (F) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +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 + +# 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 + +OVL_REDIRECT_XATTR="trusted.overlay.redirect" +OVL_IMPURE_XATTR="trusted.overlay.impure" +OVL_IMPURE_XATTR_VAL="y" + +# Create a redirect directory +make_redirect_dir() +{ + local target=$1 + local value=$2 + + mkdir -p $target + $SETFATTR_PROG -n $OVL_REDIRECT_XATTR -v $value $target +} + +# Remove impure xattr +remove_impure() +{ + local target=$1 + + $SETFATTR_PROG -x $OVL_IMPURE_XATTR $target +} + +# Check impure xattr +check_impure() +{ + local target=$1 + + value=$($GETFATTR_PROG --absolute-names --only-values -n \ + $OVL_IMPURE_XATTR $target) + + [[ $value == $OVL_IMPURE_XATTR_VAL ]] || echo "Missing impure xattr" +} + +# 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 missing impure xattr in directory which has origin targets, should fix +echo "+ Missing impure" +make_test_dirs +mkdir $lowerdir/{testdir1,testdir2} +mkdir $upperdir/{testdir1,testdir2} +touch $lowerdir/testdir1/foo +mkdir $lowerdir/testdir2/subdir +_overlay_scratch_mount_dirs $lowerdir $upperdir $workdir +touch $SCRATCH_MNT/testdir1/foo +touch $SCRATCH_MNT/testdir2/subdir +$UMOUNT_PROG $SCRATCH_MNT +remove_impure $upperdir/testdir1 +remove_impure $upperdir/testdir2 + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_impure $upperdir/testdir1 +check_impure $upperdir/testdir2 + +# Test missing impure xattr in directory which has redirect directories, +# should fix +echo "+ Missing impure(2)" +make_test_dirs +mkdir $lowerdir/origin +make_redirect_dir $upperdir/testdir/subdir "/origin" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_impure $upperdir/testdir + +# Test missing impure xattr in directory which has merge directories, +# should fix +echo "+ Missing impure(3)" +make_test_dirs +mkdir $lowerdir/testdir $upperdir/testdir + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_impure $upperdir + +# success, all done +status=0 +exit diff --git a/tests/overlay/203.out b/tests/overlay/203.out new file mode 100644 index 0000000..dd81788 --- /dev/null +++ b/tests/overlay/203.out @@ -0,0 +1,4 @@ +QA output created by 203 ++ Missing impure ++ Missing impure(2) ++ Missing impure(3) diff --git a/tests/overlay/group b/tests/overlay/group index e39b5e0..f99d89e 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -51,3 +51,4 @@ 048 auto quick copyup hardlink 201 auto quick fsck 202 auto quick fsck +203 auto quick fsck