overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / overlay / 056
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Huawei.  All Rights Reserved.
4 #
5 # FS QA Test No. 056
6 #
7 # Test fsck.overlay how to deal with impure xattr in overlayfs.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs overlay
34 _supported_os Linux
35 _require_scratch_nocheck
36 _require_attrs
37 _require_command "$FSCK_OVERLAY_PROG" fsck.overlay
38
39 OVL_XATTR_IMPURE_VAL=y
40
41 # remove all files from previous tests
42 _scratch_mkfs
43
44 # Create a redirect directory
45 make_redirect_dir()
46 {
47         local target=$1
48         local value=$2
49
50         mkdir -p $target
51         $SETFATTR_PROG -n $OVL_XATTR_REDIRECT -v $value $target
52 }
53
54 # Remove impure xattr
55 remove_impure()
56 {
57         local target=$1
58
59         $SETFATTR_PROG -x $OVL_XATTR_IMPURE $target
60 }
61
62 # Check impure xattr
63 check_impure()
64 {
65         local target=$1
66
67         value=$(_getfattr --absolute-names --only-values -n \
68                 $OVL_XATTR_IMPURE $target)
69
70         [[ "$value" == "$OVL_XATTR_IMPURE_VAL" ]] || echo "Missing impure xattr"
71 }
72
73 # Create test directories
74 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
75 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
76 upperdir=$OVL_BASE_SCRATCH_MNT/upper
77 workdir=$OVL_BASE_SCRATCH_MNT/workdir
78
79 make_test_dirs()
80 {
81         rm -rf $lowerdir $lowerdir2 $upperdir $workdir
82         mkdir -p $lowerdir $lowerdir2 $upperdir $workdir
83 }
84
85 # Test missing impure xattr in directory which has origin targets, should fix
86 echo "+ Missing impure"
87 make_test_dirs
88 mkdir $lowerdir/{testdir1,testdir2}
89 mkdir $upperdir/{testdir1,testdir2}
90 touch $lowerdir/testdir1/foo
91 mkdir $lowerdir/testdir2/subdir
92 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir
93 touch $SCRATCH_MNT/testdir1/foo
94 touch $SCRATCH_MNT/testdir2/subdir
95 $UMOUNT_PROG $SCRATCH_MNT
96 remove_impure $upperdir/testdir1
97 remove_impure $upperdir/testdir2
98
99 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
100 check_impure $upperdir/testdir1
101 check_impure $upperdir/testdir2
102
103 # Test missing impure xattr in directory which has redirect directories,
104 # should fix
105 echo "+ Missing impure(2)"
106 make_test_dirs
107 mkdir $lowerdir/origin
108 make_redirect_dir $upperdir/testdir/subdir "/origin"
109
110 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
111 check_impure $upperdir/testdir
112
113 # Test missing impure xattr in directory which has merge directories,
114 # should fix
115 echo "+ Missing impure(3)"
116 make_test_dirs
117 mkdir $lowerdir/testdir $upperdir/testdir
118
119 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
120 check_impure $upperdir
121
122 # success, all done
123 status=0
124 exit