87fc9bbc54fb3caf564c9ac545c6b42bb7b51a79
[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 # Use non-default scratch underlying overlay dirs, we need to check
58 # them explicity after test.
59 _require_scratch_nocheck
60 _require_loop
61
62 # Remove all files from previous tests
63 _scratch_mkfs
64
65 # setup loop images fs for overlayfs
66 lower_img=${OVL_BASE_SCRATCH_MNT}/${seq}.$$.img
67 $XFS_IO_PROG -f -c "truncate 120m" $lower_img >>$seqres.full 2>&1
68 fs_loop_dev=`_create_loop_device $lower_img`
69 $MKFS_XFS_PROG -f -n ftype=1 $fs_loop_dev >>$seqres.full 2>&1
70
71 # only 20m for upper dir
72 upper_img=${OVL_BASE_SCRATCH_MNT}/$$.${seq}.img
73 $XFS_IO_PROG -f -c "truncate 20m" $upper_img >>$seqres.full 2>&1
74 upper_loop_dev=`_create_loop_device $upper_img`
75 $MKFS_XFS_PROG -f -n ftype=1 $upper_loop_dev >>$seqres.full 2>&1
76
77 # mount underlying xfs
78 mkdir -p ${OVL_BASE_SCRATCH_MNT}/lowermnt
79 mkdir -p ${OVL_BASE_SCRATCH_MNT}/uppermnt
80 $MOUNT_PROG $fs_loop_dev ${OVL_BASE_SCRATCH_MNT}/lowermnt
81 $MOUNT_PROG $upper_loop_dev ${OVL_BASE_SCRATCH_MNT}/uppermnt
82
83 # prepare dirs
84 mkdir -p ${OVL_BASE_SCRATCH_MNT}/lowermnt/lower
85 mkdir -p ${OVL_BASE_SCRATCH_MNT}/uppermnt/upper
86 mkdir -p ${OVL_BASE_SCRATCH_MNT}/uppermnt/work
87
88 lowerd=${OVL_BASE_SCRATCH_MNT}/lowermnt/lower
89 upperd=${OVL_BASE_SCRATCH_MNT}/uppermnt/upper
90 workd=${OVL_BASE_SCRATCH_MNT}/uppermnt/work
91
92 # Create test file in lower dir, with too big a size for
93 # upper dir to copy up.
94 $XFS_IO_PROG -f -c "truncate 48m" ${lowerd}/test_file \
95         >>$seqres.full 2>&1
96
97 # mount new overlayfs
98 _overlay_scratch_mount_dirs $lowerd $upperd $workd
99
100 # the open call triggers copy-up and it will fail ENOSPC
101 $XFS_IO_PROG -f -c "o" ${SCRATCH_MNT}/test_file \
102         >>$seqres.full 2>&1
103
104 # unmount overlayfs
105 $UMOUNT_PROG $SCRATCH_MNT
106
107 # check overlayfs
108 _overlay_check_scratch_dirs $lowerd $upperd $workd
109
110 # unmount undelying xfs, this tiggers panic if memleak happens
111 $UMOUNT_PROG ${OVL_BASE_SCRATCH_MNT}/uppermnt
112 $UMOUNT_PROG ${OVL_BASE_SCRATCH_MNT}/lowermnt
113
114 # success, all done
115 echo "Silence is golden"
116 status=0
117 exit