xfs: force file creation to the data device for certain layout tests
[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 _require_scratch_nocheck
35 _require_attrs trusted
36 _require_command "$FSCK_OVERLAY_PROG" fsck.overlay
37
38 OVL_XATTR_IMPURE_VAL=y
39
40 # remove all files from previous tests
41 _scratch_mkfs
42
43 # Create a redirect directory
44 make_redirect_dir()
45 {
46         local target=$1
47         local value=$2
48
49         mkdir -p $target
50         $SETFATTR_PROG -n $OVL_XATTR_REDIRECT -v $value $target
51 }
52
53 # Remove impure xattr
54 remove_impure()
55 {
56         local target=$1
57
58         $SETFATTR_PROG -x $OVL_XATTR_IMPURE $target
59 }
60
61 # Check impure xattr
62 check_impure()
63 {
64         local target=$1
65
66         value=$(_getfattr --absolute-names --only-values -n \
67                 $OVL_XATTR_IMPURE $target)
68
69         [[ "$value" == "$OVL_XATTR_IMPURE_VAL" ]] || echo "Missing impure xattr"
70 }
71
72 # Create test directories
73 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
74 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
75 upperdir=$OVL_BASE_SCRATCH_MNT/upper
76 workdir=$OVL_BASE_SCRATCH_MNT/workdir
77
78 make_test_dirs()
79 {
80         rm -rf $lowerdir $lowerdir2 $upperdir $workdir
81         mkdir -p $lowerdir $lowerdir2 $upperdir $workdir
82 }
83
84 # Test missing impure xattr in directory which has origin targets, should fix
85 echo "+ Missing impure"
86 make_test_dirs
87 mkdir $lowerdir/{testdir1,testdir2}
88 mkdir $upperdir/{testdir1,testdir2}
89 touch $lowerdir/testdir1/foo
90 mkdir $lowerdir/testdir2/subdir
91 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir
92 touch $SCRATCH_MNT/testdir1/foo
93 touch $SCRATCH_MNT/testdir2/subdir
94 $UMOUNT_PROG $SCRATCH_MNT
95 remove_impure $upperdir/testdir1
96 remove_impure $upperdir/testdir2
97
98 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
99 check_impure $upperdir/testdir1
100 check_impure $upperdir/testdir2
101
102 # Test missing impure xattr in directory which has redirect directories,
103 # should fix
104 echo "+ Missing impure(2)"
105 make_test_dirs
106 mkdir $lowerdir/origin
107 make_redirect_dir $upperdir/testdir/subdir "/origin"
108
109 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
110 check_impure $upperdir/testdir
111
112 # Test missing impure xattr in directory which has merge directories,
113 # should fix
114 echo "+ Missing impure(3)"
115 make_test_dirs
116 mkdir $lowerdir/testdir $upperdir/testdir
117
118 _overlay_fsck_expect $FSCK_NONDESTRUCT $lowerdir $upperdir $workdir -p
119 check_impure $upperdir
120
121 # success, all done
122 status=0
123 exit