generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 085
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 085
6 #
7 # Exercise fs freeze/unfreeze and mount/umount race, which could lead to
8 # use-after-free oops.
9 #
10 # This commit fixed the issue:
11 # 1494583 fix get_active_super()/umount() race
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26         cleanup_dmdev
27 }
28
29 cleanup_dmdev()
30 {
31         # in case it's still suspended and/or mounted
32         $DMSETUP_PROG resume $lvdev >/dev/null 2>&1
33         $UMOUNT_PROG $lvdev >/dev/null 2>&1
34
35         $DMSETUP_PROG remove $node >>$seqres.full 2>&1
36         $DMSETUP_PROG mknodes >/dev/null 2>&1
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # real QA test starts here
44 _supported_fs generic
45 _supported_os Linux
46 _require_scratch
47 _require_block_device $SCRATCH_DEV
48 _require_dm_target linear
49 _require_freeze
50
51 setup_dmdev()
52 {
53         table="0 $size_in_sector linear $SCRATCH_DEV 0"
54         $DMSETUP_PROG create $node --table "$table" >>$seqres.full 2>&1 && \
55         $DMSETUP_PROG mknodes >/dev/null 2>&1
56         return $?
57 }
58
59 rm -f $seqres.full
60 echo "Silence is golden"
61
62 size=$((256 * 1024 * 1024))
63 size_in_sector=$((size / 512))
64 _scratch_mkfs_sized $size >>$seqres.full 2>&1
65
66 node=$seq-test
67 lvdev=/dev/mapper/$node
68 setup_dmdev || _fail "setup dm device failed"
69
70 # take use of dmsetup suspend to freeze the fs.
71 # xfs_freeze/fsfreeze cannot be used in this test, because it can possibly
72 # freeze the root fs of the host when SCRATCH_MNT is not mounted
73 #
74 # And the results of the racing commands (suspend/resume, mount/umount) are not
75 # important, as long as they're racing with each other. So just throw away the
76 # outputs and ignore the results.
77 for ((i=0; i<100; i++)); do
78         $DMSETUP_PROG suspend $lvdev >/dev/null 2>&1
79         $DMSETUP_PROG resume $lvdev >/dev/null 2>&1
80 done &
81 pid=$!
82 for ((i=0; i<100; i++)); do
83         $MOUNT_PROG $lvdev $SCRATCH_MNT >/dev/null 2>&1
84         $UMOUNT_PROG $lvdev >/dev/null 2>&1
85 done &
86 pid="$pid $!"
87
88 wait $pid
89
90 status=0
91 exit