2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2016 Oracle. All Rights Reserved.
5 # Routines for injecting errors into filesystems
9 # Tests whether $FSTYP is one of the filesystems that supports error injection
10 _require_error_injection()
14 grep -q 'debug 1' /proc/fs/xfs/stat || \
15 _notrun "XFS error injection requires CONFIG_XFS_DEBUG"
18 _notrun "Error injection not supported on filesystem type: $FSTYP"
22 # Find the errortag injection knob in sysfs for a given xfs mount's
24 _find_xfs_mountdev_errortag_knob()
28 shortdev="$(_short_dev "${dev}")"
29 tagfile="/sys/fs/xfs/${shortdev}/errortag/${knob}"
31 # Some of the new sysfs errortag knobs were previously available via
35 if [ ! -w "${tagfile}" ]; then
36 tagfile="/sys/fs/xfs/${shortdev}/log/log_badcrc_factor"
40 if [ ! -w "${tagfile}" ]; then
41 tagfile="/sys/fs/xfs/${shortdev}/drop_writes"
43 if [ ! -w "${tagfile}" ]; then
44 tagfile="/sys/fs/xfs/${shortdev}/fail_writes"
54 # Requires that xfs_io inject command knows about this error type
55 _require_xfs_io_error_injection()
58 _require_error_injection
60 # Can we find the error injection knobs via the new errortag
61 # configuration mechanism?
62 knob="$(_find_xfs_mountdev_errortag_knob "${TEST_DEV}" "${type}")"
63 test -w "${knob}" && return
65 # NOTE: We can't actually test error injection here because xfs
66 # hasn't always range checked the argument to xfs_errortag_add.
67 # We also don't want to trip an error before we're ready to deal
70 $XFS_IO_PROG -x -c 'inject' $TEST_DIR | grep -q "$type" || \
71 _notrun "XFS error injection $type unknown."
74 # Inject an error into the test fs
80 knob="$(_find_xfs_mountdev_errortag_knob "${TEST_DEV}" "${type}")"
81 if [ -w "${knob}" ]; then
82 test -z "${value}" && value="default"
83 echo -n "${value}" > "${knob}"
84 elif [ -z "${value}" ] || [ "${value}" = "default" ]; then
85 $XFS_IO_PROG -x -c "inject $type" $TEST_DIR
87 _fail "Cannot inject error ${type} value ${value}."
91 # Inject an error into the scratch fs
92 _scratch_inject_error()
97 knob="$(_find_xfs_mountdev_errortag_knob "${SCRATCH_DEV}" "${type}")"
98 if [ -w "${knob}" ]; then
99 test -z "${value}" && value="default"
100 echo -n "${value}" > "${knob}"
101 elif [ -z "${value}" ] || [ "${value}" = "default" ]; then
102 $XFS_IO_PROG -x -c "inject $type" $SCRATCH_MNT
104 _fail "Cannot inject error ${type} value ${value}."
108 # Unmount and remount the scratch device, dumping the log
109 _scratch_inject_logprint()
113 if test -n "$opts"; then
118 _scratch_mount "$opts"
121 # Unmount and remount the test device, dumping the log
122 _test_inject_logprint()
126 if test -n "$opts"; then