8ecc2901f7e9ff6e8f3dd6fa90f0eb600edfb356
[xfstests-dev.git] / common / inject
1 ##/bin/bash
2 # Routines for injecting errors into filesystems
3 #-----------------------------------------------------------------------
4 #  Copyright (c) 2016 Oracle.  All Rights Reserved.
5 #  This program is free software; you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation; either version 2 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 #  USA
19 #
20 #  Contact information: Oracle Corporation, 500 Oracle Parkway,
21 #  Redwood Shores, CA 94065, USA, or: http://www.oracle.com/
22 #-----------------------------------------------------------------------
23 . ./common/log
24
25 # Tests whether $FSTYP is one of the filesystems that supports error injection
26 _require_error_injection()
27 {
28         case "$FSTYP" in
29         "xfs")
30                 grep -q 'debug 1' /proc/fs/xfs/stat || \
31                         _notrun "XFS error injection requires CONFIG_XFS_DEBUG"
32                 ;;
33         *)
34                 _notrun "Error injection not supported on filesystem type: $FSTYP"
35         esac
36 }
37
38 # Requires that xfs_io inject command knows about this error type
39 _require_xfs_io_error_injection()
40 {
41         type="$1"
42         _require_error_injection
43
44         # NOTE: We can't actually test error injection here because xfs
45         # hasn't always range checked the argument to xfs_errortag_add.
46         # We also don't want to trip an error before we're ready to deal
47         # with it.
48
49         $XFS_IO_PROG -x -c 'inject' $TEST_DIR | grep -q "$type" || \
50                 _notrun "XFS error injection $type unknown."
51 }
52
53 # Inject an error into the test fs
54 _test_inject_error()
55 {
56         type="$1"
57
58         $XFS_IO_PROG -x -c "inject $type" $TEST_DIR
59 }
60
61 # Inject an error into the scratch fs
62 _scratch_inject_error()
63 {
64         type="$1"
65
66         $XFS_IO_PROG -x -c "inject $type" $SCRATCH_MNT
67 }
68
69 # Unmount and remount the scratch device, dumping the log
70 _scratch_inject_logprint()
71 {
72         local opts="$1"
73
74         if test -n "$opts"; then
75                 opts="-o $opts"
76         fi
77         _scratch_unmount
78         _scratch_dump_log
79         _scratch_mount "$opts"
80 }
81
82 # Unmount and remount the test device, dumping the log
83 _test_inject_logprint()
84 {
85         local opts="$1"
86
87         if test -n "$opts"; then
88                 opts="-o $opts"
89         fi
90         _test_unmount
91         _test_dump_log
92         _test_mount "$opts"
93 }