From patchwork Fri Jan 12 12:05:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10160359 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 07DD1602D8 for ; Fri, 12 Jan 2018 11:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE4F5289A5 for ; Fri, 12 Jan 2018 11:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0779289AC; Fri, 12 Jan 2018 11:59:45 +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 2A7BB289A5 for ; Fri, 12 Jan 2018 11:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933254AbeALL7o (ORCPT ); Fri, 12 Jan 2018 06:59:44 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:4190 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932976AbeALL7n (ORCPT ); Fri, 12 Jan 2018 06:59:43 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5067B8590731A; Fri, 12 Jan 2018 19:59:27 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Fri, 12 Jan 2018 19:59:21 +0800 From: "zhangyi (F)" To: , CC: , , , , , Subject: [PATCH v3 3/7] overlay: add fsck.overlay redirect directory test Date: Fri, 12 Jan 2018 20:05:29 +0800 Message-ID: <20180112120533.6099-4-yi.zhang@huawei.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180112120533.6099-1-yi.zhang@huawei.com> References: <20180112120533.6099-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 invalid/valid/ duplicate redirect xattr in underlying directories of overlayfs. Signed-off-by: zhangyi (F) --- tests/overlay/202 | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/202.out | 10 +++ tests/overlay/group | 1 + 3 files changed, 251 insertions(+) create mode 100755 tests/overlay/202 create mode 100644 tests/overlay/202.out diff --git a/tests/overlay/202 b/tests/overlay/202 new file mode 100755 index 0000000..84a7bad --- /dev/null +++ b/tests/overlay/202 @@ -0,0 +1,240 @@ +#! /bin/bash +# FS QA Test 202 +# +# Test fsck.overlay how to deal with redirect 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 +. ./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 +_require_attrs +_require_command "$FSCK_OVERLAY_PROG" fsck.overlay + +# remove all files from previous tests +_scratch_mkfs + +OVL_REDIRECT_XATTR="trusted.overlay.redirect" +OVL_OPAQUE_XATTR="trusted.overlay.opaque" +OVL_OPAQUE_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 +} + +# Check redirect xattr +check_redirect() +{ + local target=$1 + local expect=$2 + + value=$($GETFATTR_PROG --absolute-names --only-values -n \ + $OVL_REDIRECT_XATTR $target) + + [[ $value == $expect ]] || echo "Redirect xattr incorrect" +} + +check_no_redirect() +{ + local target=$1 + + value=$($GETFATTR_PROG --absolute-names -d -m \ + $OVL_REDIRECT_XATTR $target) + + [[ -z "$value" ]] || echo "Redirect xattr not empty" +} + +# Check opaque xattr +check_opaque() +{ + local target=$1 + + value=$($GETFATTR_PROG --absolute-names --only-values -n \ + $OVL_OPAQUE_XATTR $target) + + [[ $value == $OVL_OPAQUE_XATTR_VAL ]] || echo "Opaque xattr incorrect" +} + +# Check whiteout +check_whiteout() +{ + local target=$1 + + target_type=`stat -c "%F:%t,%T" $target` + + [[ $target_type == "character special file:0,0" ]] || \ + echo "Whiteout missing" +} + +# 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 invalid redirect xattr point to a nonexistent origin, should remove +echo "+ Invalid redirect" +make_test_dirs +make_redirect_dir $upperdir/testdir "invalid" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_no_redirect $upperdir/testdir + +# Test invalid redirect xattr point to a file origin, should remove +echo "+ Invalid redirect(2)" +make_test_dirs +touch $lowerdir/origin +make_redirect_dir $upperdir/testdir "origin" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_no_redirect $upperdir/testdir + +# Test valid redirect xattr point to a directory origin in the same directory, +# should not remove +echo "+ Valid redirect" +make_test_dirs +mkdir $lowerdir/origin +mknod $upperdir/origin c 0 0 +make_redirect_dir $upperdir/testdir "origin" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_redirect $upperdir/testdir "origin" + +# Test valid redirect xattr point to a directory origin in different directories +# should not remove +echo "+ Valid redirect(2)" +make_test_dirs +mkdir $lowerdir/origin +mknod $upperdir/origin c 0 0 +make_redirect_dir $upperdir/testdir1/testdir2 "/origin" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_redirect $upperdir/testdir1/testdir2 "/origin" + +# Test valid redirect xattr but missing whiteout to cover lower target, +# should fix whiteout +echo "+ Missing whiteout" +make_test_dirs +mkdir $lowerdir/origin +make_redirect_dir $upperdir/testdir "origin" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_redirect $upperdir/testdir "origin" +check_whiteout $upperdir/origin + +# Test valid redirect xattrs exchanged by rename, should not remove +echo "+ Valid redirect(3)" +make_test_dirs +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 || \ + _fail "fsck should not fail" +check_redirect $upperdir/testdir1 "testdir2" +check_redirect $upperdir/testdir2 "testdir1" + +# Test invalid redirect xattr with lower same name directory exists, +# should remove invalid redirect xattr and set opaque in yes mode +echo "+ Invalid redirect(3)" +make_test_dirs +mkdir $lowerdir/testdir +make_redirect_dir $upperdir/testdir "invalid" + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -y >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_no_redirect $upperdir/testdir +check_opaque $upperdir/testdir + +# Test duplicate redirect xattrs point to one origin, should fail in +# auto mode, and should remove the duplicate one in yes mode +echo "+ Duplicate redirect" +make_test_dirs +mkdir $lowerdir2/origin +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 && _fail "fsck should fail" +_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -y >> \ + $seqres.full 2>&1 || _fail "fsck should not fail" +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" +check_no_redirect $upperdir/testdir3 + +# Test duplicate redirect xattr duplicate with merge directory, should +# fail in auto mode, and should remove the redirect directory in yes mode +echo "+ Duplicate redirect(2)" +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 && \ + _fail "fsck should fail" +_overlay_fsck_dirs $lowerdir $upperdir $workdir -y >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_no_redirect $upperdir/testdir + +# success, all done +status=0 +exit diff --git a/tests/overlay/202.out b/tests/overlay/202.out new file mode 100644 index 0000000..8473336 --- /dev/null +++ b/tests/overlay/202.out @@ -0,0 +1,10 @@ +QA output created by 202 ++ Invalid redirect ++ Invalid redirect(2) ++ Valid redirect ++ Valid redirect(2) ++ Missing whiteout ++ Valid redirect(3) ++ Invalid redirect(3) ++ Duplicate redirect ++ Duplicate redirect(2) diff --git a/tests/overlay/group b/tests/overlay/group index 7c5fcbb..e39b5e0 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -50,3 +50,4 @@ 047 auto quick copyup hardlink 048 auto quick copyup hardlink 201 auto quick fsck +202 auto quick fsck