fstests: fix broken _require_scratch usage
[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 _require_no_large_scratch_dev
42
43 function filter_mounted()
44 {
45         grep "mounted" | _filter_scratch | head -1
46 }
47
48 METADUMP_FILE="${TEST_DIR}/${seq}_metadump"
49 COPY_FILE="${TEST_DIR}/${seq}_copyfile"
50
51 # Test dump a mounted device
52 # xfs_metadump should refuse to dump a mounted device
53 _scratch_mkfs >> $seqres.full 2>&1
54 _scratch_mount
55 _scratch_metadump $METADUMP_FILE 2>&1 | filter_mounted
56 _scratch_unmount
57
58 # Test restore to a mounted device
59 # xfs_mdrestore should refuse to restore to a mounted device
60 _scratch_metadump $METADUMP_FILE
61 _scratch_mount
62 xfs_mdrestore $METADUMP_FILE $SCRATCH_DEV 2>&1 | filter_mounted
63 _scratch_unmount
64
65 # Test xfs_copy to a mounted device
66 # If source is mounted, xfs_copy will print a warning, but still
67 # keep on copying. If target is mounted, xfs_copy should fail.
68 $XFS_COPY_PROG $SCRATCH_DEV $COPY_FILE >/dev/null
69 _scratch_mount
70 $XFS_COPY_PROG $COPY_FILE $SCRATCH_DEV 2>&1 | filter_mounted
71 _scratch_unmount
72
73 # Test xfs_db a mounted device
74 # xfs_db a mounted device without readonly (-r) option should fail
75 _scratch_mount
76 $XFS_DB_PROG -c sb $SCRATCH_DEV 2>&1 | filter_mounted
77 _scratch_unmount
78
79 # Test mkfs.xfs a mounted device
80 # Generally mkfs will report device is mounted, but if it can't find
81 # device is mounted, it'll report device busy.
82 _scratch_mount
83 _scratch_mkfs 2>&1 | filter_mounted
84 _scratch_unmount
85
86 # Test xfs_repair (with/without modify flag) a mounted device
87 # xfs_repair (with/without modify flag) a mounted device should fail(don't
88 # test -d option at here)
89 _scratch_mount
90 _scratch_xfs_repair -n 2>&1 | filter_mounted
91 _scratch_xfs_repair 2>&1 | filter_mounted
92 _scratch_unmount
93
94 # success, all done
95 status=0
96 exit