8dce6b33935c1d0ee7d136f21e63a90af07e5da2
[xfstests-dev.git] / tests / overlay / 029
1 #! /bin/bash
2 # FS QA Test 029
3 #
4 # There are dirs/files in lower dir and upper dir before
5 # mounting overlayfs. After mounting, use dir in overlayfs
6 # mountpoint as lowerdir to mount another overlayfs, then
7 # access old files through the second overlayfs. It was
8 # not working, kernel commit below fixed it.
9 #
10 # c4fcfc1619ea ovl: fix d_real() for stacked fs
11 #
12 # This reproducer was originally written by
13 #     Miklos Szeredi <mszeredi@redhat.com>
14 #
15 #-----------------------------------------------------------------------
16 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
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         $UMOUNT_PROG $tmp/mnt
46         rm -rf $tmp
47         rm -f $tmp.*
48 }
49
50 # get standard environment, filters and checks
51 . ./common/rc
52 . ./common/filter
53
54 # remove previous $seqres.full before test
55 rm -f $seqres.full
56
57 # real QA test starts here
58
59 # Modify as appropriate.
60 _supported_fs overlay
61 _supported_os Linux
62 _require_scratch
63
64 # Remove all files from previous tests
65 _scratch_mkfs
66
67 # Preparing files
68 upperdir=$SCRATCH_DEV/$OVL_UPPER
69 lowerdir=$SCRATCH_DEV/$OVL_LOWER
70 mkdir -p $upperdir/up
71 echo foo > $upperdir/up/foo
72 mkdir -p $lowerdir/low
73 echo bar > $lowerdir/low/bar
74
75 # mount overlay in SCRATCH_MNT
76 _scratch_mount
77
78 mkdir -p $tmp/{upper,mnt,work}
79 # mount overlay again using upper dir from SCRATCH_MNT dir
80 _overlay_mount_dirs $SCRATCH_MNT/up $tmp/{upper,work} \
81   overlay $tmp/mnt
82 # accessing file in the second mount
83 cat $tmp/mnt/foo
84 $UMOUNT_PROG $tmp/mnt
85
86 # mount overlay again using lower dir from SCRATCH_MNT dir
87 _overlay_mount_dirs $SCRATCH_MNT/low $tmp/{upper,work} \
88   overlay $tmp/mnt
89 cat $tmp/mnt/bar
90 $UMOUNT_PROG $tmp/mnt
91
92 # mount overlay again using SCRATCH_MNT dir
93 _overlay_mount_dirs $SCRATCH_MNT/ $tmp/{upper,work} \
94   overlay $tmp/mnt
95 cat $tmp/mnt/up/foo
96 cat $tmp/mnt/low/bar
97
98 # success, all done
99 status=0
100 exit