overlay: add fsck.overlay basic tests
v3 cover overlay: add fsck.overlay basic tests
Hi all:
Here is the third version of test cases for the upcoming fsck.overlay, corresponding to fsck.overlay v4 (will post to github repository soon). Test fsck.overlay check and fix inconsistency of whiteout and redirect/impure xattr.
Changes since v2:
- Modify some minor suggestions from Amir and Vivek, and simplify code in all three test cases.
- Fix duplicate redirect xattr test in 202.
- Add impure xattr test case of general merge directory in 'no impure' parent directory.
- Fix fs check failure in other overlay fs test cases. PS: The multi-lowers problem in overlay/010 also appears in many other tests, _require_scratch() will mis-check the pre-defined underlying dirs (not the real test dirs). I think they also need to be modified as this patch(06/07) does to check the correct dirs, and I can fix them if you think necessary.
------
Changes since v1:
- Fix _check_scratch_fs hook.
- Remove valid/invalid opaque xattr test.
- Add whiteout test cases of valid/invalid whiteouts in opaque/redirect parent directory.
- Add impure xattr test.
zhangyi (F) (7):
overlay: add filesystem check helper
overlay: add fsck.overlay whiteout test
overlay: add fsck.overlay redirect directory test
overlay: add fsck.overlay impure xattr test overlay/003: fix fs check failure overlay/010: fix fs check failure overlay/019: fix fs check failure
common/config | 1 + common/overlay | 80 +++++++++++++++++ common/rc | 4 +- tests/overlay/003 | 1 - tests/overlay/010 | 11 +-- tests/overlay/019 | 2 +- tests/overlay/201 | 232 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/201.out | 10 +++ tests/overlay/202 | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/202.out | 10 +++ tests/overlay/203 | 143 ++++++++++++++++++++++++++++++ tests/overlay/203.out | 4 + tests/overlay/group | 3 + 13 files changed, 732 insertions(+), 9 deletions(-) create mode 100755 tests/overlay/201 create mode 100644 tests/overlay/201.out create mode 100755 tests/overlay/202 create mode 100644 tests/overlay/202.out create mode 100755 tests/overlay/203 create mode 100644 tests/overlay/203.out
Signature · 1 line
2.5.0
PATCH v3 1/7 overlay: add filesystem check helper
Add filesystem check helpers for the upcoming fsck.overlay utility, and hook them to _check_test_fs and _check_scratch_fs. This helper works only if fsck.overlay exists.
[ _check_test_fs/_check_scratch_fs part picked from Amir's patch, thanks ]
--- common/config | 1 + common/overlay | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/rc | 4 +-- 3 files changed, 83 insertions(+), 2 deletions(-)
common/config +1 -0
@@ -236,6 +236,7 @@ case "$HOSTOS" in export MKFS_REISER4_PROG="`set_prog_path mkfs.reiser4`" export E2FSCK_PROG="`set_prog_path e2fsck`" export TUNE2FS_PROG="`set_prog_path tune2fs`" + export FSCK_OVERLAY_PROG="`set_prog_path fsck.overlay`" ;; esac
common/overlay +80 -0
83 lines not on this page · raw message
common/rc +2 -2
@@ -2537,7 +2537,7 @@ _check_test_fs() # no way to check consistency for GlusterFS ;; overlay) - # no way to check consistency for overlay + _check_overlay_test_fs ;; pvfs2) ;;
@@ -2592,7 +2592,7 @@ _check_scratch_fs() # no way to check consistency for GlusterFS ;; overlay) - # no way to check consistency for overlay + _check_overlay_scratch_fs ;; pvfs2) ;;
Signature · 1 line
2.9.5
PATCH v3 2/7 overlay: add fsck.overlay whiteout test
In reply to zhangyi (F)Add fsck.overlay test case to test it how to deal with orphan/valid whiteouts in underlying directories of overlayfs.
--- tests/overlay/201 | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/201.out | 10 +++ tests/overlay/group | 1 + 3 files changed, 243 insertions(+) create mode 100755 tests/overlay/201 create mode 100644 tests/overlay/201.out
tests/overlay/201 new file +232 -0
@@ -0,0 +1,232 @@ +#! /bin/bash +# FS QA Test 201 +# +# Test fsck.overlay how to deal with whiteouts in overlayfs. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Huawei. All Rights Reserved. +# Author: zhangyi (F) <[email protected]> +# +# 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 +_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" + +# Check whiteout +check_whiteout() +{ + for arg in $* + do + local ttype=`stat -c "%F:%t,%T" $arg` + + [[ $ttype == "character special file:0,0" ]] || \ + echo "Valid whiteout removed incorrectly" + done +} + +# Create a whiteout +make_whiteout() +{ + for arg in $* + do + mknod $arg c 0 0 + done +} + +# Create an opaque directory +make_opaque_dir() +{ + local target=$1 + + mkdir -p $target + $SETFATTR_PROG -n $OVL_OPAQUE_XATTR -v $OVL_OPAQUE_XATTR_VAL $target +} + +# 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 +} + +# 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 orphan whiteout in lower and upper layer, should remove +echo "+ Orphan whiteout" +make_test_dirs +make_whiteout $lowerdir/foo $upperdir/{foo,bar} + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +ls $lowerdir +ls $upperdir + +# Test valid whiteout covering lower target, should not remove +echo "+ Valid whiteout" +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 || _fail "fsck should not fail" +check_whiteout $upperdir/foo $lowerdir/bar + +# Test orphan whiteout in opaque directory, should remove +echo "+ Orphan whiteout(2)" +make_test_dirs +mkdir $lowerdir/testdir +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 || \ + _fail "fsck should not fail" +ls $upperdir/testdir + +# Test orphan whiteout whose parent path is not an merged directory, +# should remove +echo "+ Orphan whiteout(3)" +make_test_dirs +mkdir $lowerdir2/{testdir1,testdir2,testdir3} +touch $lowerdir2/{testdir1/foo,testdir2/foo,testdir3/foo} +mkdir $upperdir/{testdir1,testdir2,testdir3,testdir4} +touch $lowerdir/testdir1 +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 || _fail "fsck should not fail" +ls $upperdir/testdir1 +ls $upperdir/testdir2 +ls $upperdir/testdir3 +ls $upperdir/testdir4 + +# Test orphan whiteout in redirect directory, should remove +echo "+ Orphan whiteout(4)" +make_test_dirs +mkdir $lowerdir/{testdir,origin} +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 || \ + _fail "fsck should not fail" +ls $upperdir/testdir + +# Test valid whiteout in redirect directory cover file in lower +# redirect origin directory, should not remove +echo "+ Valid whiteout(2)" +make_test_dirs +mkdir $lowerdir/origin +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 || \ + _fail "fsck should not fail" +check_whiteout $upperdir/testdir/foo + +# Test valid whiteout covering lower target whose parent directory +# merge with a redirect directory in the middle layer, should not remove. +echo "+ Valid whiteout(3)" +make_test_dirs +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 + +_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p \ + >> $seqres.full 2>&1 || _fail "fsck should not fail" +check_whiteout $upperdir/testdir/subdir/foo + +# Test invalid whiteout in opaque subdirectory in a redirect directory, +# should remove +echo "+ Orphan whiteout(5)" +make_test_dirs +mkdir -p $lowerdir/origin/subdir +touch $lowerdir/origin/subdir/foo +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 || \ + _fail "fsck should not fail" +ls $upperdir/testdir/subdir + +# Test valid whiteout in reidrect subdirectory in a opaque directory +# covering lower target, should not remove +echo "+ Valid whiteout(4)" +make_test_dirs +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 + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_whiteout $upperdir/testdir/subdir/foo + +# success, all done +status=0 +exit
tests/overlay/201.out new file +10 -0
@@ -0,0 +1,10 @@ +QA output created by 201 ++ Orphan whiteout ++ Valid whiteout ++ Orphan whiteout(2) ++ Orphan whiteout(3) ++ Orphan whiteout(4) ++ Valid whiteout(2) ++ Valid whiteout(3) ++ Orphan whiteout(5) ++ Valid whiteout(4)
tests/overlay/group +1 -0
@@ -49,3 +49,4 @@ 044 auto quick copyup hardlink nonsamefs 047 auto quick copyup hardlink 048 auto quick copyup hardlink +201 auto quick fsck
Signature · 1 line
2.9.5
Re: [PATCH v3 2/7] overlay: add fsck.overlay whiteout test
Quoted 4 lines · zhangyi (F)
Add fsck.overlay test case to test it how to deal with orphan/valid whiteouts in underlying directories of overlayfs.
Signed-off-by zhangyi (F) <[email protected]>
Looks good.
Quoted 274 lines
--- tests/overlay/201 | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/201.out | 10 +++ tests/overlay/group | 1 + 3 files changed, 243 insertions(+) create mode 100755 tests/overlay/201 create mode 100644 tests/overlay/201.outtests/overlay/201 new file +232
-0@@ -0,0 +1,232 @@ +#! /bin/bash +# FS QA Test 201 +# +# Test fsck.overlay how to deal with whiteouts in overlayfs. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Huawei. All Rights Reserved. +# Author: zhangyi (F) <[email protected]> +# +# 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 +_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" + +# Check whiteout +check_whiteout() +{ + for arg in $* + do + local ttype=`stat -c "%F:%t,%T" $arg` + + [[ $ttype == "character special file:0,0" ]] || \ + echo "Valid whiteout removed incorrectly" + done +} + +# Create a whiteout +make_whiteout() +{ + for arg in $* + do + mknod $arg c 0 0 + done +} + +# Create an opaque directory +make_opaque_dir() +{ + local target=$1 + + mkdir -p $target + $SETFATTR_PROG -n $OVL_OPAQUE_XATTR -v $OVL_OPAQUE_XATTR_VAL $target +} + +# 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 +} + +# 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 orphan whiteout in lower and upper layer, should remove +echo "+ Orphan whiteout" +make_test_dirs +make_whiteout $lowerdir/foo $upperdir/{foo,bar} + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +ls $lowerdir +ls $upperdir + +# Test valid whiteout covering lower target, should not remove +echo "+ Valid whiteout" +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 || _fail "fsck should not fail" +check_whiteout $upperdir/foo $lowerdir/bar + +# Test orphan whiteout in opaque directory, should remove +echo "+ Orphan whiteout(2)" +make_test_dirs +mkdir $lowerdir/testdir +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 || \ + _fail "fsck should not fail" +ls $upperdir/testdir + +# Test orphan whiteout whose parent path is not an merged directory, +# should remove +echo "+ Orphan whiteout(3)" +make_test_dirs +mkdir $lowerdir2/{testdir1,testdir2,testdir3} +touch $lowerdir2/{testdir1/foo,testdir2/foo,testdir3/foo} +mkdir $upperdir/{testdir1,testdir2,testdir3,testdir4} +touch $lowerdir/testdir1 +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 || _fail "fsck should not fail" +ls $upperdir/testdir1 +ls $upperdir/testdir2 +ls $upperdir/testdir3 +ls $upperdir/testdir4 + +# Test orphan whiteout in redirect directory, should remove +echo "+ Orphan whiteout(4)" +make_test_dirs +mkdir $lowerdir/{testdir,origin} +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 || \ + _fail "fsck should not fail" +ls $upperdir/testdir + +# Test valid whiteout in redirect directory cover file in lower +# redirect origin directory, should not remove +echo "+ Valid whiteout(2)" +make_test_dirs +mkdir $lowerdir/origin +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 || \ + _fail "fsck should not fail" +check_whiteout $upperdir/testdir/foo + +# Test valid whiteout covering lower target whose parent directory +# merge with a redirect directory in the middle layer, should not remove. +echo "+ Valid whiteout(3)" +make_test_dirs +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 + +_overlay_fsck_dirs "$lowerdir:$lowerdir2" $upperdir $workdir -p \ + >> $seqres.full 2>&1 || _fail "fsck should not fail" +check_whiteout $upperdir/testdir/subdir/foo + +# Test invalid whiteout in opaque subdirectory in a redirect directory, +# should remove +echo "+ Orphan whiteout(5)" +make_test_dirs +mkdir -p $lowerdir/origin/subdir +touch $lowerdir/origin/subdir/foo +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 || \ + _fail "fsck should not fail" +ls $upperdir/testdir/subdir + +# Test valid whiteout in reidrect subdirectory in a opaque directory +# covering lower target, should not remove +echo "+ Valid whiteout(4)" +make_test_dirs +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 + +_overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \ + _fail "fsck should not fail" +check_whiteout $upperdir/testdir/subdir/foo + +# success, all done +status=0 +exittests/overlay/201.out new file +10
-0@@ -0,0 +1,10 @@ +QA output created by 201 ++ Orphan whiteout ++ Valid whiteout ++ Orphan whiteout(2) ++ Orphan whiteout(3) ++ Orphan whiteout(4) ++ Valid whiteout(2) ++ Valid whiteout(3) ++ Orphan whiteout(5) ++ Valid whiteout(4)tests/overlay/group +1
-1@@ -49,3 +49,4 @@ 044 auto quick copyup hardlink nonsamefs 047 auto quick copyup hardlink 048 auto quick copyup hardlink +201 auto quick fsck --2.9.5
PATCH v3 3/7 overlay: add fsck.overlay redirect directory test
In reply to zhangyi (F)Add fsck.overlay test case to test it how to deal with invalid/valid/ duplicate redirect xattr in underlying directories of overlayfs.
--- 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
tests/overlay/202 new file +240 -0
@@ -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) <[email protected]> +# +# 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
tests/overlay/202.out new file +10 -0
@@ -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)
tests/overlay/group +1 -0
@@ -50,3 +50,4 @@ 047 auto quick copyup hardlink 048 auto quick copyup hardlink 201 auto quick fsck +202 auto quick fsck
Signature · 1 line
2.9.5
Re: [PATCH v3 3/7] overlay: add fsck.overlay redirect directory test
Quoted 4 lines · zhangyi (F)
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) <[email protected]>
Looks good, with some minor comments
Quoted 156 lines
--- 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.outtests/overlay/202 new file +142
-0@@ -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) <[email protected]> +# +# 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" +
tests/overlay/202 line 152
Quoted 10 lines
tests/overlay/202 new file +10
-0+_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
I got spoiled from previous tests ;-) please use make_whiteout helper here as well.
Quoted 40 lines
tests/overlay/202 new file +40
-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"
tests/overlay/202 line 202
Quoted 10 lines
tests/overlay/202 new file +10
-0+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 || \
When using -y, better add a comment with the expected questions for whom Yes is the answer (even though one might deduce that from the expected results)
tests/overlay/202 line 208
Quoted 6 lines
tests/overlay/202 new file +6
-0+ _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
Better say "either of the duplicates" for clarity
Quoted 18 lines
tests/overlay/202 new file +18
-0+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
tests/overlay/202 line 236
Quoted 10 lines
tests/overlay/202 new file +10
-0+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
Maybe also worth to have $lowerdir/testdir and check_opaque $upperdir/testdir in this case? or add another case?
Quoted 32 lines
tests/overlay/202 new file +4
-0+ +# success, all done +status=0 +exittests/overlay/202.out new file +10
-0@@ -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)tests/overlay/group +1
-1@@ -50,3 +50,4 @@ 047 auto quick copyup hardlink 048 auto quick copyup hardlink 201 auto quick fsck +202 auto quick fsck --2.9.5
PATCH v3 4/7 overlay: add fsck.overlay impure xattr test
In reply to zhangyi (F)Add fsck.overlay test case to test it how to deal with impure xattr in underlying directories of overlayfs.
--- 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
tests/overlay/203 new file +143 -0
@@ -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) <[email protected]> +# +# 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 +_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
tests/overlay/203.out new file +4 -0
@@ -0,0 +1,4 @@ +QA output created by 203 ++ Missing impure ++ Missing impure(2) ++ Missing impure(3)
tests/overlay/group +1 -0
@@ -51,3 +51,4 @@ 048 auto quick copyup hardlink 201 auto quick fsck 202 auto quick fsck +203 auto quick fsck
Signature · 1 line
2.9.5
Re: [PATCH v3 4/7] overlay: add fsck.overlay impure xattr test
Quoted 4 lines · zhangyi (F)
Add fsck.overlay test case to test it how to deal with impure xattr in underlying directories of overlayfs.
Signed-off-by zhangyi (F) <[email protected]>
Looks good
Quoted 179 lines
--- 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.outtests/overlay/203 new file +143
-0@@ -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) <[email protected]> +# +# 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 +_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 +exittests/overlay/203.out new file +4
-0@@ -0,0 +1,4 @@ +QA output created by 203 ++ Missing impure ++ Missing impure(2) ++ Missing impure(3)tests/overlay/group +1
-1@@ -51,3 +51,4 @@ 048 auto quick copyup hardlink 201 auto quick fsck 202 auto quick fsck +203 auto quick fsck --2.9.5
PATCH v3 5/7 overlay/003: fix fs check failure
In reply to zhangyi (F)_check_overlay_scratch_fs() will check lowerdir of overlay filesystem, this case remove this directory after test will lead to check failure, and it is not really necessary to remove this directory, so keep this directory.
--- tests/overlay/003 | 1 - 1 file changed, 1 deletion(-)
tests/overlay/003 +0 -1
@@ -92,7 +92,6 @@ ls ${SCRATCH_MNT}/ # unmount overlayfs but not base fs $UMOUNT_PROG $SCRATCH_MNT -rm -rf $lowerdir echo "Silence is golden" # success, all done status=0
Signature · 1 line
2.9.5
Re: [PATCH v3 5/7] overlay/003: fix fs check failure
Quoted 6 lines · zhangyi (F)
_check_overlay_scratch_fs()will check lowerdir of overlay filesystem, this case remove this directory after test will lead to check failure, and it is not really necessary to remove this directory, so keep this directory.Signed-off-by zhangyi (F) <[email protected]>
Looks correct,
Amir.
Quoted 19 lines
--- tests/overlay/003 | 1 - 1 file changed, 1 deletion(-)tests/overlay/003 +0
-2@@ -92,7 +92,6 @@ ls ${SCRATCH_MNT}/ # unmount overlayfs but not base fs $UMOUNT_PROG $SCRATCH_MNT -rm -rf $lowerdir echo "Silence is golden" # success, all done status=0 --2.9.5
PATCH v3 6/7 overlay/010: fix fs check failure
In reply to zhangyi (F)This test use ovl_lower.1/ovl_lower.2 and ovl_upper in scratch filesystem as underlying directories of overlay filesystem, but _check_overlay_scratch_fs() only check ovl_lower and ovl_upper directories. So whiteout "testdir" in ovl_upper becomes an orphan whiteout, which will lead to fsck.overlay check failure.
This patch change to invoke _overlay_check_dirs() to check real test dirs instead of pre-defined common dirs.
--- tests/overlay/010 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tests/overlay/010 +6 -5
@@ -48,17 +48,17 @@ rm -f $seqres.full # real QA test starts here _supported_fs overlay _supported_os Linux -_require_scratch +_require_scratch_nocheck # Remove all files from previous tests _scratch_mkfs # Need two lower dirs in this test, and we mount overlay ourselves, # create upper and workdir as well -lowerdir1=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.1 -lowerdir2=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.2 -upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER -workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK +lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1 +lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2 +upperdir=$OVL_BASE_SCRATCH_MNT/upper +workdir=$OVL_BASE_SCRATCH_MNT/work mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir # One lowerdir contains test dir and test files, the other contains whiteout
@@ -70,6 +70,7 @@ mknod $lowerdir2/testdir/a c 0 0 _overlay_scratch_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir rm -rf $SCRATCH_MNT/testdir +_overlay_check_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir # success, all done echo "Silence is golden" status=0
Signature · 1 line
2.9.5
Re: [PATCH v3 6/7] overlay/010: fix fs check failure
Quoted 10 lines · zhangyi (F)
This test use ovl_lower.1/ovl_lower.2 and
ovl_upperin scratch filesystem as underlying directories of overlay filesystem, but_check_overlay_scratch_fs()only checkovl_lowerandovl_upperdirectories. So whiteout "testdir" inovl_upperbecomes an orphan whiteout, which will lead to fsck.overlay check failure.This patch change to invoke
_overlay_check_dirs()to check real test dirs instead of pre-defined common dirs.Signed-off-by zhangyi (F) <[email protected]>
Looks correct
Amir.
Quoted 42 lines
--- tests/overlay/010 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)tests/overlay/010 +6
-6@@ -48,17 +48,17 @@ rm -f $seqres.full # real QA test starts here _supported_fs overlay _supported_os Linux -_require_scratch +_require_scratch_nocheck # Remove all files from previous tests _scratch_mkfs # Need two lower dirs in this test, and we mount overlay ourselves, # create upper and workdir as well -lowerdir1=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.1 -lowerdir2=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER.2 -upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER -workdir=$OVL_BASE_SCRATCH_MNT/$OVL_WORK +lowerdir1=$OVL_BASE_SCRATCH_MNT/lower1 +lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2 +upperdir=$OVL_BASE_SCRATCH_MNT/upper +workdir=$OVL_BASE_SCRATCH_MNT/work mkdir -p $lowerdir1 $lowerdir2 $upperdir $workdir # One lowerdir contains test dir and test files, the other contains whiteout@@ -70,6 +70,7 @@ mknod $lowerdir2/testdir/a c 0 0 _overlay_scratch_mount_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir rm -rf $SCRATCH_MNT/testdir +_overlay_check_dirs "$lowerdir2:$lowerdir1" $upperdir $workdir # success, all done echo "Silence is golden" status=0 --2.9.5
PATCH v3 7/7 overlay/019: fix fs check failure
In reply to zhangyi (F)This is a stability test, fsstress will create a lot of orphan whiteouts in lowerdir, which will lead to inconsistency of overlay image and fs check failure. No need to check this manual craft file system, so just skip fs check.
--- tests/overlay/019 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/overlay/019 +1 -1
@@ -46,7 +46,7 @@ rm -f $seqres.full # real QA test starts here _supported_fs overlay _supported_os Linux -_require_scratch +_require_scratch_nocheck # Remove all files from previous tests _scratch_mkfs
Signature · 1 line
2.9.5
Re: [PATCH v3 7/7] overlay/019: fix fs check failure
Quoted 6 lines · zhangyi (F)
This is a stability test, fsstress will create a lot of orphan whiteouts in lowerdir, which will lead to inconsistency of overlay image and fs check failure. No need to check this manual craft file system, so just skip fs check.
Signed-off-by zhangyi (F) <[email protected]>
Looks correct
Quoted 20 lines
--- tests/overlay/019 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/overlay/019 +1
-2@@ -46,7 +46,7 @@ rm -f $seqres.full # real QA test starts here _supported_fs overlay _supported_os Linux -_require_scratch +_require_scratch_nocheck # Remove all files from previous tests _scratch_mkfs --2.9.5
Quoted 7 lines · zhangyi (F)
Hi all:
Here is the third version of test cases for the upcoming fsck.overlay, corresponding to fsck.overlay v4 (will post to github repository soon). Test fsck.overlay check and fix inconsistency of whiteout and redirect/impure xattr.
Quoted 12 lines
Changes since v2:
- Modify some minor suggestions from Amir and Vivek, and simplify code in all three test cases.
- Fix duplicate redirect xattr test in 202.
- Add impure xattr test case of general merge directory in 'no impure' parent directory.
- Fix fs check failure in other overlay fs test cases. PS: The multi-lowers problem in overlay/010 also appears in many other tests,_require_scratch()will mis-check the pre-defined underlying dirs (not the real test dirs). I think they also need to be modified as this patch(06/07) does to check the correct dirs, and I can fix them if you think necessary.
Yes, please do.
Thinking out loud, we could use a helper _require_overlay_scratch_dirs for tests that use _overlay_scratch_mount_dirs and not _scratch_mount. That helper will actually be a wrapper to _require_scratch_nocheck, but with a comment that explains why, because usually, _require_scratch_nocheck means that test leaves filesystem corrupt and that is not the case here.
Thanks,
Amir.
Quoted 44 lines
------
Changes since v1:
- Fix
_check_scratch_fshook.
- Remove valid/invalid opaque xattr test.
- Add whiteout test cases of valid/invalid whiteouts in opaque/redirect parent directory.
- Add impure xattr test.zhangyi (F) (7):
overlay: add filesystem check helper
overlay: add fsck.overlay whiteout test
overlay: add fsck.overlay redirect directory test
overlay: add fsck.overlay impure xattr test overlay/003: fix fs check failure overlay/010: fix fs check failure overlay/019: fix fs check failurecommon/config | 1 + common/overlay | 80 +++++++++++++++++ common/rc | 4 +- tests/overlay/003 | 1 - tests/overlay/010 | 11 +-- tests/overlay/019 | 2 +- tests/overlay/201 | 232 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/201.out | 10 +++ tests/overlay/202 | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/202.out | 10 +++ tests/overlay/203 | 143 ++++++++++++++++++++++++++++++ tests/overlay/203.out | 4 + tests/overlay/group | 3 + 13 files changed, 732 insertions(+), 9 deletions(-) create mode 100755 tests/overlay/201 create mode 100644 tests/overlay/201.out create mode 100755 tests/overlay/202 create mode 100644 tests/overlay/202.out create mode 100755 tests/overlay/203 create mode 100644 tests/overlay/203.out--
2.5.0
On 2018/1/13 3:19, Amir Goldstein Wrote:
Quoted 21 lines · zhangyi (F)
Quoted 7 lines
Hi all:
Here is the third version of test cases for the upcoming fsck.overlay, corresponding to fsck.overlay v4 (will post to github repository soon). Test fsck.overlay check and fix inconsistency of whiteout and redirect/impure xattr.
Quoted 12 lines
Changes since v2:
- Modify some minor suggestions from Amir and Vivek, and simplify code in all three test cases.
- Fix duplicate redirect xattr test in 202.
- Add impure xattr test case of general merge directory in 'no impure' parent directory.
- Fix fs check failure in other overlay fs test cases. PS: The multi-lowers problem in overlay/010 also appears in many other tests,_require_scratch()will mis-check the pre-defined underlying dirs (not the real test dirs). I think they also need to be modified as this patch(06/07) does to check the correct dirs, and I can fix them if you think necessary.
Quoted 8 lines
Yes, please do.
Thinking out loud, we could use a helper_require_overlay_scratch_dirsfor tests that use_overlay_scratch_mount_dirsand not_scratch_mount. That helper will actually be a wrapper to_require_scratch_nocheck, but with a comment that explains why, because usually,_require_scratch_nocheckmeans that test leaves filesystem corrupt and that is not the case here.
This makes sense, will do.
Thanks,
Yi.