xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 284
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat.  All Rights Reserved.
4 #
5 # FS QA Test 284
6 #
7 # Do xfs_metadump, xfs_mdrestore, xfs_copy, xfs_db, xfs_repair and mkfs.xfs
8 # on mounted XFS to make sure they refuse to proceed.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23         rm -f $METADUMP_FILE 2>/dev/null
24         rm -f $COPY_FILE 2>/dev/null
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs xfs
36 _supported_os Linux
37 # xfs_copy does not support realtime devices
38 _require_no_realtime
39 _require_test
40 _require_scratch
41
42 function filter_mounted()
43 {
44         grep "mounted" | _filter_scratch | head -1
45 }
46
47 METADUMP_FILE="${TEST_DIR}/${seq}_metadump"
48 COPY_FILE="${TEST_DIR}/${seq}_copyfile"
49
50 # Test dump a mounted device
51 # xfs_metadump should refuse to dump a mounted device
52 _scratch_mount
53 _scratch_metadump $METADUMP_FILE 2>&1 | filter_mounted
54 _scratch_unmount
55
56 # Test restore to a mounted device
57 # xfs_mdrestore should refuse to restore to a mounted device
58 _scratch_metadump $METADUMP_FILE
59 _scratch_mount
60 xfs_mdrestore $METADUMP_FILE $SCRATCH_DEV 2>&1 | filter_mounted
61 _scratch_unmount
62
63 # Test xfs_copy to a mounted device
64 # If source is mounted, xfs_copy will print a warning, but still
65 # keep on copying. If target is mounted, xfs_copy should fail.
66 $XFS_COPY_PROG $SCRATCH_DEV $COPY_FILE >/dev/null
67 _scratch_mount
68 $XFS_COPY_PROG $COPY_FILE $SCRATCH_DEV 2>&1 | filter_mounted
69 _scratch_unmount
70
71 # Test xfs_db a mounted device
72 # xfs_db a mounted device without readonly (-r) option should fail
73 _scratch_mount
74 $XFS_DB_PROG -c sb $SCRATCH_DEV 2>&1 | filter_mounted
75 _scratch_unmount
76
77 # Test mkfs.xfs a mounted device
78 # Generally mkfs will report device is mounted, but if it can't find
79 # device is mounted, it'll report device busy.
80 _scratch_mount
81 _scratch_mkfs 2>&1 | filter_mounted
82 _scratch_unmount
83
84 # Test xfs_repair (with/without modify flag) a mounted device
85 # xfs_repair (with/without modify flag) a mounted device should fail(don't
86 # test -d option at here)
87 _scratch_mount
88 _scratch_xfs_repair -n 2>&1 | filter_mounted
89 _scratch_xfs_repair 2>&1 | filter_mounted
90 _scratch_unmount
91
92 # success, all done
93 status=0
94 exit