overlay: renumber tests after merge
[xfstests-dev.git] / tests / overlay / 056
1 #! /bin/bash
2 # FS QA Test No. 056
3 #
4 # Test fsck.overlay how to deal with impure xattr in overlayfs.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2018 Huawei.  All Rights Reserved.
8 # Author: zhangyi (F) <yi.zhang@huawei.com>
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43 . ./common/attr
44
45 # remove previous $seqres.full before test
46 rm -f $seqres.full
47
48 # real QA test starts here
49 _supported_fs overlay
50 _supported_os Linux
51 _require_scratch_nocheck
52 _require_attrs
53 _require_command "$FSCK_OVERLAY_PROG" fsck.overlay
54
55 OVL_XATTR_IMPURE_VAL=y
56
57 # remove all files from previous tests
58 _scratch_mkfs
59
60 # Create a redirect directory
61 make_redirect_dir()
62 {
63         local target=$1
64         local value=$2
65
66         mkdir -p $target
67         $SETFATTR_PROG -n $OVL_XATTR_REDIRECT -v $value $target
68 }
69
70 # Remove impure xattr
71 remove_impure()
72 {
73         local target=$1
74
75         $SETFATTR_PROG -x $OVL_XATTR_IMPURE $target
76 }
77
78 # Check impure xattr
79 check_impure()
80 {
81         local target=$1
82
83         value=$($GETFATTR_PROG --absolute-names --only-values -n \
84                 $OVL_XATTR_IMPURE $target)
85
86         [[ "$value" == "$OVL_XATTR_IMPURE_VAL" ]] || echo "Missing impure xattr"
87 }
88
89 # Create test directories
90 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
91 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
92 upperdir=$OVL_BASE_SCRATCH_MNT/upper
93 workdir=$OVL_BASE_SCRATCH_MNT/workdir
94
95 make_test_dirs()
96 {
97         rm -rf $lowerdir $lowerdir2 $upperdir $workdir
98         mkdir -p $lowerdir $lowerdir2 $upperdir $workdir
99 }
100
101 # Test missing impure xattr in directory which has origin targets, should fix
102 echo "+ Missing impure"
103 make_test_dirs
104 mkdir $lowerdir/{testdir1,testdir2}
105 mkdir $upperdir/{testdir1,testdir2}
106 touch $lowerdir/testdir1/foo
107 mkdir $lowerdir/testdir2/subdir
108 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir
109 touch $SCRATCH_MNT/testdir1/foo
110 touch $SCRATCH_MNT/testdir2/subdir
111 $UMOUNT_PROG $SCRATCH_MNT
112 remove_impure $upperdir/testdir1
113 remove_impure $upperdir/testdir2
114
115 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
116         echo "fsck should not fail"
117 check_impure $upperdir/testdir1
118 check_impure $upperdir/testdir2
119
120 # Test missing impure xattr in directory which has redirect directories,
121 # should fix
122 echo "+ Missing impure(2)"
123 make_test_dirs
124 mkdir $lowerdir/origin
125 make_redirect_dir $upperdir/testdir/subdir "/origin"
126
127 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
128         echo "fsck should not fail"
129 check_impure $upperdir/testdir
130
131 # Test missing impure xattr in directory which has merge directories,
132 # should fix
133 echo "+ Missing impure(3)"
134 make_test_dirs
135 mkdir $lowerdir/testdir $upperdir/testdir
136
137 _overlay_fsck_dirs $lowerdir $upperdir $workdir -p >> $seqres.full 2>&1 || \
138         echo "fsck should not fail"
139 check_impure $upperdir
140
141 # success, all done
142 status=0
143 exit