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.
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.
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
20 # Contact information: Oracle Corporation, 500 Oracle Parkway,
21 # Redwood Shores, CA 94065, USA, or: http://www.oracle.com/
22 #-----------------------------------------------------------------------
25 # Tests whether $FSTYP is one of the filesystems that supports error injection
26 _require_error_injection()
30 grep -q 'debug 1' /proc/fs/xfs/stat || \
31 _notrun "XFS error injection requires CONFIG_XFS_DEBUG"
34 _notrun "Error injection not supported on filesystem type: $FSTYP"
38 # Find the errortag injection knob in sysfs for a given xfs mount's
40 _find_xfs_mountdev_errortag_knob()
44 shortdev="$(_short_dev "${dev}")"
45 tagfile="/sys/fs/xfs/${shortdev}/errortag/${knob}"
47 # Some of the new sysfs errortag knobs were previously available via
51 if [ ! -w "${tagfile}" ]; then
52 tagfile="/sys/fs/xfs/${shortdev}/log/log_badcrc_factor"
56 if [ ! -w "${tagfile}" ]; then
57 tagfile="/sys/fs/xfs/${shortdev}/drop_writes"
59 if [ ! -w "${tagfile}" ]; then
60 tagfile="/sys/fs/xfs/${shortdev}/fail_writes"
70 # Requires that xfs_io inject command knows about this error type
71 _require_xfs_io_error_injection()
74 _require_error_injection
76 # Can we find the error injection knobs via the new errortag
77 # configuration mechanism?
78 knob="$(_find_xfs_mountdev_errortag_knob "${TEST_DEV}" "${type}")"
79 test -w "${knob}" && return
81 # NOTE: We can't actually test error injection here because xfs
82 # hasn't always range checked the argument to xfs_errortag_add.
83 # We also don't want to trip an error before we're ready to deal
86 $XFS_IO_PROG -x -c 'inject' $TEST_DIR | grep -q "$type" || \
87 _notrun "XFS error injection $type unknown."
90 # Inject an error into the test fs
96 knob="$(_find_xfs_mountdev_errortag_knob "${TEST_DEV}" "${type}")"
97 if [ -w "${knob}" ]; then
98 test -z "${value}" && value="default"
99 echo -n "${value}" > "${knob}"
100 elif [ -z "${value}" ] || [ "${value}" = "default" ]; then
101 $XFS_IO_PROG -x -c "inject $type" $TEST_DIR
103 _fail "Cannot inject error ${type} value ${value}."
107 # Inject an error into the scratch fs
108 _scratch_inject_error()
113 knob="$(_find_xfs_mountdev_errortag_knob "${SCRATCH_DEV}" "${type}")"
114 if [ -w "${knob}" ]; then
115 test -z "${value}" && value="default"
116 echo -n "${value}" > "${knob}"
117 elif [ -z "${value}" ] || [ "${value}" = "default" ]; then
118 $XFS_IO_PROG -x -c "inject $type" $SCRATCH_MNT
120 _fail "Cannot inject error ${type} value ${value}."
124 # Unmount and remount the scratch device, dumping the log
125 _scratch_inject_logprint()
129 if test -n "$opts"; then
134 _scratch_mount "$opts"
137 # Unmount and remount the test device, dumping the log
138 _test_inject_logprint()
142 if test -n "$opts"; then