overlay: create helper _overlay_scratch_mount_dirs()
[xfstests-dev.git] / tests / overlay / 037
1 #! /bin/bash
2 # FS QA Test 037
3 #
4 # Test mount error cases with option index=on
5 #
6 # - Upper/lower mismatch
7 # - Index/upper mismatch
8 #
9 # With index=on, lowerdir and upperdir are verified using a file handle
10 # stored in trusted.overlay.origin xattr in upperdir and indexdir.
11 #
12 # Failure to verify lowerdir/upperdir on mount results in ESTALE.
13 #
14 #-----------------------------------------------------------------------
15 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
16 # Author: Amir Goldstein <amir73il@gmail.com>
17 #
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation.
21 #
22 # This program is distributed in the hope that it would be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write the Free Software Foundation,
29 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30 #-----------------------------------------------------------------------
31 #
32
33 seq=`basename $0`
34 seqres=$RESULT_DIR/$seq
35 echo "QA output created by $seq"
36
37 here=`pwd`
38 tmp=/tmp/$$
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44         cd /
45         rm -f $tmp.*
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # remove previous $seqres.full before test
53 rm -f $seqres.full
54
55 # real QA test starts here
56 _supported_fs overlay
57 _supported_os Linux
58 _require_scratch
59 _require_scratch_feature index
60
61 # Remove all files from previous tests
62 _scratch_mkfs
63
64 # Create multiple lowerdirs, upperdirs and workdir
65 lowerdir=$OVL_BASE_SCRATCH_MNT/lower
66 lowerdir2=$OVL_BASE_SCRATCH_MNT/lower2
67 upperdir=$OVL_BASE_SCRATCH_MNT/upper
68 upperdir2=$OVL_BASE_SCRATCH_MNT/upper2
69 workdir=$OVL_BASE_SCRATCH_MNT/workdir
70 mkdir -p $lowerdir $lowerdir2 $upperdir $upperdir2 $workdir
71
72 # Mount overlay with lowerdir, upperdir, workdir and index=on
73 # to store the file handles of lowerdir and upperdir in overlay.origin xattr
74 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -oindex=on
75 $UMOUNT_PROG $SCRATCH_MNT
76
77 # Try to mount an overlay with the same upperdir and different lowerdir - expect ESTALE
78 _overlay_scratch_mount_dirs $lowerdir2 $upperdir $workdir -oindex=on \
79         2>&1 | _filter_scratch
80 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
81
82 # Try to mount an overlay with the same workdir and different upperdir - expect ESTALE
83 _overlay_scratch_mount_dirs $lowerdir $upperdir2 $workdir -oindex=on \
84         2>&1 | _filter_scratch
85 $UMOUNT_PROG $SCRATCH_MNT 2>/dev/null
86
87 # Mount overlay with original lowerdir, upperdir, workdir and index=on - expect success
88 _overlay_scratch_mount_dirs $lowerdir $upperdir $workdir -oindex=on
89
90 # success, all done
91 status=0
92 exit