From patchwork Fri Feb 23 12:03:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yangerkun X-Patchwork-Id: 10237493 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 6C0D4602A0 for ; Fri, 23 Feb 2018 11:54:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5966C2953F for ; Fri, 23 Feb 2018 11:54:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BF8529542; Fri, 23 Feb 2018 11:54:22 +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 9A3212953F for ; Fri, 23 Feb 2018 11:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751089AbeBWLyV (ORCPT ); Fri, 23 Feb 2018 06:54:21 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:35771 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750935AbeBWLyU (ORCPT ); Fri, 23 Feb 2018 06:54:20 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8A1DDFA9BC63; Fri, 23 Feb 2018 19:54:05 +0800 (CST) Received: from 138.huawei.com (10.175.124.28) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Fri, 23 Feb 2018 19:53:56 +0800 From: yangerkun To: , CC: , , , , , , Subject: [xfstests PATCH] overlay: add origin test for fsck.overlay Date: Fri, 23 Feb 2018 20:03:25 +0800 Message-ID: <20180223120325.33255-1-yangerkun@huawei.com> X-Mailer: git-send-email 2.13.6 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 origin xattr in file or dir of overlayfs. Signed-off-by: yangerkun --- tests/overlay/057 | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/057.out | 6 ++ tests/overlay/group | 1 + 3 files changed, 207 insertions(+) create mode 100644 tests/overlay/057 create mode 100644 tests/overlay/057.out diff --git a/tests/overlay/057 b/tests/overlay/057 new file mode 100644 index 00000000..c2299c4f --- /dev/null +++ b/tests/overlay/057 @@ -0,0 +1,200 @@ +#! /bin/bash +# FS QA Test 057 +# +# Test fsck.overlay how to deal with origin xattr in overlayfs. +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Huawei. All Rights Reserved. + +# 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 +. ./common/attr + +#remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test start here +_supported_fs overlay +_supported_os Linux +_require_scratch_nocheck +_require_attrs +_require_command "$FSCK_OVERLAY_PROG" fsck.overlay + +# Remove all files from previous tests +_scratch_mkfs + +create_origin() +{ + local lowerdir=$1 + local upperdir=$2 + local workdir=$3 + + mkdir $lowerdir/testdir + touch $lowerdir/testfile + + _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir + + # Copy up files and directory + touch $SCRATCH_MNT/{testdir,testfile} + $UMOUNT_PROG $SCRATCH_MNT +} + +# Get the origin xattr of file or dir, maybe null +get_origin() +{ + local target=$1 + local value + + value=`$GETFATTR_PROG --absolute-names --only-values -n \ + $OVL_XATTR_ORIGIN $target 2>&1` + [ $? -eq 1 ] && return 1 + + if [ -n "$value" ] + then + value=`echo $value | base64` + echo "0s"${value} + else + echo "" + fi + return 0 +} + +set_origin() +{ + local target=$1 + local value=$2 + + if [ -n "$value" ] + then + $SETFATTR_PROG -n $OVL_XATTR_ORIGIN -v $value $target + else + $SETFATTR_PROG -n $OVL_XATTR_ORIGIN $target + fi +} + +# Value of origin equals to the expect value?(1 : equal, 0 : not equal) +check_origin() +{ + local target=$1 + local expres=$2 + local expect=$3 + local origin + + origin=`get_origin $target` + if [ $? -eq 1 ] + then + [ $expect -eq 0 ] || echo "Missing origin xattr" + else + [ "$origin" == "$expres" ] && ( [ $expect -eq 1 ] \ + || echo "Invalid origin xattr" ) + fi +} + +# 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 valid origin xattr created when copyup, should not remove +make_test_dirs +echo "valid origin" +create_origin $lowerdir $upperdir $workdir +origin1=`get_origin $upperdir/testdir` +origin2=`get_origin $upperdir/testfile` +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + echo "fsck should not fail" +check_origin $upperdir/testdir "$origin1" 1 +check_origin $upperdir/testfile "$origin2" 1 + +# Test invalid origin xattr point to a missing lower target, should remove +make_test_dirs +echo "invalid origin" +create_origin $lowerdir $upperdir $workdir +rm -rf $lowerdir/{testfile,testdir} +origin1=`get_origin $upperdir/testdir` +origin2=`get_origin $upperdir/testfile` +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + echo "fsck should not fail" +check_origin $upperdir/testdir "$origin1" 0 +check_origin $upperdir/testfile "$origin2" 0 + +# Test invalid origin xattr when there is no lower layer, should remove +make_test_dirs +echo "invalid origin(2)" +create_origin $lowerdir2 $lowerdir $workdir +origin1=`get_origin $lowerdir/testdir` +origin2=`get_origin $lowerdir/testfile` +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + echo "fsck should not fail" +check_origin $lowerdir/testdir "$origin1" 0 +check_origin $lowerdir/testfile "$origin2" 0 + +# Test invalid origin xattr which value of origin has changed, should remove +make_test_dirs +echo "invalid origin(3)" +create_origin $lowerdir $upperdir $workdir +origin=`get_origin $upperdir/testdir` +set_origin $upperdir/testdir $"origin"${origin} +origin=`get_origin $upperdir/testfile` +set_origin $upperdir/testfile $"origin"${origin} +origin1=`get_origin $upperdir/testdir` +origin2=`get_origin $upperdir/testfile` +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + echo "fsck should not fail" +check_origin $upperdir/testdir "$origin1" 0 +check_origin $upperdir/testfile "$origin2" 0 + +# Test valid origin xattr which the value is NULL +make_test_dirs +echo "valid origin(2)" +create_origin $lowerdir $upperdir $workdir +set_origin $upperdir/testdir "" +set_origin $upperdir/testfile "" +origin1=`get_origin $upperdir/testdir` +origin2=`get_origin $upperdir/testfile` +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + echo "fsck should not fail" +check_origin $upperdir/testdir "$origin1" 1 +check_origin $upperdir/testfile "$origin2" 1 + +# sucess, all done +status=0 +exit diff --git a/tests/overlay/057.out b/tests/overlay/057.out new file mode 100644 index 00000000..7c375880 --- /dev/null +++ b/tests/overlay/057.out @@ -0,0 +1,6 @@ +QA output created by 057 +valid origin +invalid origin +invalid origin(2) +invalid origin(3) +valid origin(2) diff --git a/tests/overlay/group b/tests/overlay/group index 65f1fe63..b595a003 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -59,3 +59,4 @@ 054 auto quick copyup redirect exportfs 055 auto quick copyup redirect exportfs nonsamefs 056 auto quick fsck +057 auto quick fsck