e3625fe64e0ebddf8363c0fcf60025fa6c1ad138
[xfstests-dev.git] / tests / xfs / 284
1 #! /bin/bash
2 # FS QA Test 284
3 #
4 # Do xfs_metadump, xfs_mdrestore, xfs_copy, xfs_db, xfs_repair and mkfs.xfs
5 # on mounted XFS to make sure they refuse to proceed.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2016 Red Hat.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38         rm -f $METADUMP_FILE 2>/dev/null
39         rm -f $COPY_FILE 2>/dev/null
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # remove previous $seqres.full before test
47 rm -f $seqres.full
48
49 # real QA test starts here
50 _supported_fs xfs
51 _supported_os Linux
52 _require_test
53 _require_scratch
54
55 function filter_mounted()
56 {
57         grep "mounted" | _filter_scratch | head -1
58 }
59
60 METADUMP_FILE="${TEST_DIR}/${seq}_metadump"
61 COPY_FILE="${TEST_DIR}/${seq}_copyfile"
62
63 # Test dump a mounted device
64 # xfs_metadump should refuse to dump a mounted device
65 _scratch_mount
66 _scratch_metadump $METADUMP_FILE 2>&1 | filter_mounted
67 _scratch_unmount
68
69 # Test restore to a mounted device
70 # xfs_mdrestore should refuse to restore to a mounted device
71 _scratch_metadump $METADUMP_FILE
72 _scratch_mount
73 xfs_mdrestore $METADUMP_FILE $SCRATCH_DEV 2>&1 | filter_mounted
74 _scratch_unmount
75
76 # Test xfs_copy to a mounted device
77 # If source is mounted, xfs_copy will print a warning, but still
78 # keep on copying. If target is mounted, xfs_copy should fail.
79 $XFS_COPY_PROG $SCRATCH_DEV $COPY_FILE >/dev/null
80 _scratch_mount
81 $XFS_COPY_PROG $COPY_FILE $SCRATCH_DEV 2>&1 | filter_mounted
82 _scratch_unmount
83
84 # Test xfs_db a mounted device
85 # xfs_db a mounted device without readonly (-r) option should fail
86 _scratch_mount
87 $XFS_DB_PROG -c sb $SCRATCH_DEV 2>&1 | filter_mounted
88 _scratch_unmount
89
90 # Test mkfs.xfs a mounted device
91 # Generally mkfs will report device is mounted, but if it can't find
92 # device is mounted, it'll report device busy.
93 _scratch_mount
94 _scratch_mkfs 2>&1 | filter_mounted
95 _scratch_unmount
96
97 # Test xfs_repair (with/without modify flag) a mounted device
98 # xfs_repair (with/without modify flag) a mounted device should fail(don't
99 # test -d option at here)
100 _scratch_mount
101 _scratch_xfs_repair -n 2>&1 | filter_mounted
102 _scratch_xfs_repair 2>&1 | filter_mounted
103 _scratch_unmount
104
105 # success, all done
106 status=0
107 exit