17992a398054682c1a358190cf55b9bbe04d4067
[xfstests-dev.git] / tests / overlay / 005
1 #! /bin/bash
2 # FS QA Test 005
3 #
4 # Memleak in overlayfs copy-up error handling path leads to panic
5 # when unmount the underlying fs.
6 # Kernel commit ab79efab0 fixed this issue.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2016 Red Hat Inc. All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -f $tmp.*
39         _destroy_loop_device $fs_loop_dev
40         _destroy_loop_device $upper_loop_dev
41         rm -f $lower_img
42         rm -f $upper_img
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48
49 # remove previous $seqres.full before test
50 rm -f $seqres.full
51
52 # real QA test starts here
53
54 # Modify as appropriate.
55 _supported_fs overlay
56 _supported_os Linux
57 _require_scratch
58 _require_loop
59
60 # Remove all files from previous tests
61 _scratch_mkfs
62
63 # setup loop images fs for overlayfs
64 lower_img=${OVL_BASE_SCRATCH_MNT}/${seq}.$$.img
65 $XFS_IO_PROG -f -c "truncate 120m" $lower_img >>$seqres.full 2>&1
66 fs_loop_dev=`_create_loop_device $lower_img`
67 $MKFS_XFS_PROG -f -n ftype=1 $fs_loop_dev >>$seqres.full 2>&1
68
69 # only 20m for upper dir
70 upper_img=${OVL_BASE_SCRATCH_MNT}/$$.${seq}.img
71 $XFS_IO_PROG -f -c "truncate 20m" $upper_img >>$seqres.full 2>&1
72 upper_loop_dev=`_create_loop_device $upper_img`
73 $MKFS_XFS_PROG -f -n ftype=1 $upper_loop_dev >>$seqres.full 2>&1
74
75 # mount underlying xfs
76 mkdir -p ${OVL_BASE_SCRATCH_MNT}/lowermnt
77 mkdir -p ${OVL_BASE_SCRATCH_MNT}/uppermnt
78 $MOUNT_PROG $fs_loop_dev ${OVL_BASE_SCRATCH_MNT}/lowermnt
79 $MOUNT_PROG $upper_loop_dev ${OVL_BASE_SCRATCH_MNT}/uppermnt
80
81 # prepare dirs
82 mkdir -p ${OVL_BASE_SCRATCH_MNT}/lowermnt/lower
83 mkdir -p ${OVL_BASE_SCRATCH_MNT}/uppermnt/upper
84 mkdir -p ${OVL_BASE_SCRATCH_MNT}/uppermnt/work
85
86 lowerd=${OVL_BASE_SCRATCH_MNT}/lowermnt/lower
87 upperd=${OVL_BASE_SCRATCH_MNT}/uppermnt/upper
88 workd=${OVL_BASE_SCRATCH_MNT}/uppermnt/work
89
90 # Create test file in lower dir, with too big a size for
91 # upper dir to copy up.
92 $XFS_IO_PROG -f -c "truncate 48m" ${lowerd}/test_file \
93         >>$seqres.full 2>&1
94
95 # mount new overlayfs
96 _overlay_scratch_mount_dirs $lowerd $upperd $workd
97
98 # the open call triggers copy-up and it will fail ENOSPC
99 $XFS_IO_PROG -f -c "o" ${SCRATCH_MNT}/test_file \
100         >>$seqres.full 2>&1
101
102 # unmount overlayfs
103 $UMOUNT_PROG $SCRATCH_MNT
104
105 # unmount undelying xfs, this tiggers panic if memleak happens
106 $UMOUNT_PROG ${OVL_BASE_SCRATCH_MNT}/uppermnt
107 $UMOUNT_PROG ${OVL_BASE_SCRATCH_MNT}/lowermnt
108
109 # success, all done
110 echo "Silence is golden"
111 status=0
112 exit