4 # failcmd.sh - run a command with injecting slab/page allocation failures
8 # failcmd.sh [<options>] command [arguments]
11 # Run command with injecting slab/page allocation failures by fault
14 # NOTE: you need to run this script as root.
20 Usage: $0 [options] command [arguments]
25 likelihood of failure injection, in percent.
30 specifies how many times failures may happen at most.
33 --oom-kill-allocating-task=value
34 set /proc/sys/vm/oom_kill_allocating_task to specified value
35 before running the command.
39 Display a usage message and exit
41 --interval=value, --space=value, --verbose=value, --task-filter=value,
42 --stacktrace-depth=value, --require-start=value, --require-end=value,
43 --reject-start=value, --reject-end=value, --ignore-gfp-wait=value
44 See Documentation/fault-injection/fault-injection.txt for more
50 fail_page_alloc options:
51 --ignore-gfp-highmem=value, --min-order=value
55 The following values for FAILCMD_TYPE are recognized:
58 inject slab allocation failures
60 inject page allocation failures
62 If FAILCMD_TYPE is not defined, then failslab is used.
66 if [ $UID != 0 ]; then
67 echo must be run as root >&2
71 DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3}'`
73 if [ ! -d "$DEBUGFS" ]; then
74 echo debugfs is not mounted >&2
78 FAILCMD_TYPE=${FAILCMD_TYPE:-failslab}
79 FAULTATTR=$DEBUGFS/$FAILCMD_TYPE
81 if [ ! -d $FAULTATTR ]; then
82 echo $FAILCMD_TYPE is not available >&2
86 LONGOPTS=probability:,interval:,times:,space:,verbose:,task-filter:
87 LONGOPTS=$LONGOPTS,stacktrace-depth:,require-start:,require-end:
88 LONGOPTS=$LONGOPTS,reject-start:,reject-end:,oom-kill-allocating-task:,help
90 if [ $FAILCMD_TYPE = failslab ]; then
91 LONGOPTS=$LONGOPTS,ignore-gfp-wait:,cache-filter:
92 elif [ $FAILCMD_TYPE = fail_page_alloc ]; then
93 LONGOPTS=$LONGOPTS,ignore-gfp-wait:,ignore-gfp-highmem:,min-order:
96 TEMP=`getopt -o p:i:t:s:v:h --long $LONGOPTS -n 'failcmd.sh' -- "$@"`
107 echo N > $FAULTATTR/task-filter
108 echo 0 > $FAULTATTR/probability
109 echo 1 > $FAULTATTR/times
114 oom_kill_allocating_task_saved=`cat /proc/sys/vm/oom_kill_allocating_task`
119 echo $oom_kill_allocating_task_saved \
120 > /proc/sys/vm/oom_kill_allocating_task
126 declare -i oom_kill_allocating_task=1
127 declare task_filter=Y
128 declare -i probability=1
138 echo $2 > $FAULTATTR/interval
146 echo $2 > $FAULTATTR/space
150 echo $2 > $FAULTATTR/verbose
158 echo $2 > $FAULTATTR/stacktrace-depth
162 echo $2 > $FAULTATTR/require-start
166 echo $2 > $FAULTATTR/require-end
170 echo $2 > $FAULTATTR/reject-start
174 echo $2 > $FAULTATTR/reject-end
177 --oom-kill-allocating-task)
178 oom_kill_allocating_task=$2
182 echo $2 > $FAULTATTR/ignore-gfp-wait
186 echo $2 > $FAULTATTR/cache_filter
189 --ignore-gfp-highmem)
190 echo $2 > $FAULTATTR/ignore-gfp-highmem
194 echo $2 > $FAULTATTR/min-order
209 [ -z "$1" ] && exit 0
211 echo $oom_kill_allocating_task > /proc/sys/vm/oom_kill_allocating_task
212 echo $task_filter > $FAULTATTR/task-filter
213 echo $probability > $FAULTATTR/probability
214 echo $times > $FAULTATTR/times
216 trap "restore_values" SIGINT SIGTERM EXIT
218 cmd="echo 1 > /proc/self/make-it-fail && exec $@"