~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/fault-injection/failcmd.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/fault-injection/failcmd.sh (Version linux-6.12-rc7) and /tools/testing/fault-injection/failcmd.sh (Version linux-5.17.15)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3 #                                                   3 #
  4 # NAME                                              4 # NAME
  5 #       failcmd.sh - run a command with inject      5 #       failcmd.sh - run a command with injecting slab/page allocation failures
  6 #                                                   6 #
  7 # SYNOPSIS                                          7 # SYNOPSIS
  8 #       failcmd.sh --help                           8 #       failcmd.sh --help
  9 #       failcmd.sh [<options>] command [argume      9 #       failcmd.sh [<options>] command [arguments]
 10 #                                                  10 #
 11 # DESCRIPTION                                      11 # DESCRIPTION
 12 #       Run command with injecting slab/page a     12 #       Run command with injecting slab/page allocation failures by fault
 13 #       injection.                                 13 #       injection.
 14 #                                                  14 #
 15 #       NOTE: you need to run this script as r     15 #       NOTE: you need to run this script as root.
 16 #                                                  16 #
 17                                                    17 
 18 usage()                                            18 usage()
 19 {                                                  19 {
 20         cat >&2 <<EOF                              20         cat >&2 <<EOF
 21 Usage: $0 [options] command [arguments]            21 Usage: $0 [options] command [arguments]
 22                                                    22 
 23 OPTIONS                                            23 OPTIONS
 24         -p percent                                 24         -p percent
 25         --probability=percent                      25         --probability=percent
 26                 likelihood of failure injectio     26                 likelihood of failure injection, in percent.
 27                 Default value is 1                 27                 Default value is 1
 28                                                    28 
 29         -t value                                   29         -t value
 30         --times=value                              30         --times=value
 31                 specifies how many times failu     31                 specifies how many times failures may happen at most.
 32                 Default value is 1                 32                 Default value is 1
 33                                                    33 
 34         --oom-kill-allocating-task=value           34         --oom-kill-allocating-task=value
 35                 set /proc/sys/vm/oom_kill_allo     35                 set /proc/sys/vm/oom_kill_allocating_task to specified value
 36                 before running the command.        36                 before running the command.
 37                 Default value is 1                 37                 Default value is 1
 38                                                    38 
 39         -h, --help                                 39         -h, --help
 40                 Display a usage message and ex     40                 Display a usage message and exit
 41                                                    41 
 42         --interval=value, --space=value, --ver     42         --interval=value, --space=value, --verbose=value, --task-filter=value,
 43         --stacktrace-depth=value, --require-st     43         --stacktrace-depth=value, --require-start=value, --require-end=value,
 44         --reject-start=value, --reject-end=val     44         --reject-start=value, --reject-end=value, --ignore-gfp-wait=value
 45                 See Documentation/fault-inject     45                 See Documentation/fault-injection/fault-injection.rst for more
 46                 information                        46                 information
 47                                                    47 
 48         failslab options:                          48         failslab options:
 49         --cache-filter=value                       49         --cache-filter=value
 50                                                    50 
 51         fail_page_alloc options:                   51         fail_page_alloc options:
 52         --ignore-gfp-highmem=value, --min-orde     52         --ignore-gfp-highmem=value, --min-order=value
 53                                                    53 
 54 ENVIRONMENT                                        54 ENVIRONMENT
 55         FAILCMD_TYPE                               55         FAILCMD_TYPE
 56                 The following values for FAILC     56                 The following values for FAILCMD_TYPE are recognized:
 57                                                    57 
 58                 failslab                           58                 failslab
 59                         inject slab allocation     59                         inject slab allocation failures
 60                 fail_page_alloc                    60                 fail_page_alloc
 61                         inject page allocation     61                         inject page allocation failures
 62                                                    62 
 63                 If FAILCMD_TYPE is not defined     63                 If FAILCMD_TYPE is not defined, then failslab is used.
 64 EOF                                                64 EOF
 65 }                                                  65 }
 66                                                    66 
 67 exit_if_not_hex() {                            << 
 68     local value="$1"                           << 
 69     if ! [[ $value =~ ^0x[0-9a-fA-F]+$ ]]; the << 
 70         echo "Error: The provided value '$valu << 
 71         exit 1                                 << 
 72     fi                                         << 
 73 }                                              << 
 74                                                << 
 75 if [ $UID != 0 ]; then                             67 if [ $UID != 0 ]; then
 76         echo must be run as root >&2               68         echo must be run as root >&2
 77         exit 1                                     69         exit 1
 78 fi                                                 70 fi
 79                                                    71 
 80 DEBUGFS=`mount -t debugfs | head -1 | awk '{ p     72 DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3}'`
 81                                                    73 
 82 if [ ! -d "$DEBUGFS" ]; then                       74 if [ ! -d "$DEBUGFS" ]; then
 83         echo debugfs is not mounted >&2            75         echo debugfs is not mounted >&2
 84         exit 1                                     76         exit 1
 85 fi                                                 77 fi
 86                                                    78 
 87 FAILCMD_TYPE=${FAILCMD_TYPE:-failslab}             79 FAILCMD_TYPE=${FAILCMD_TYPE:-failslab}
 88 FAULTATTR=$DEBUGFS/$FAILCMD_TYPE                   80 FAULTATTR=$DEBUGFS/$FAILCMD_TYPE
 89                                                    81 
 90 if [ ! -d $FAULTATTR ]; then                       82 if [ ! -d $FAULTATTR ]; then
 91         echo $FAILCMD_TYPE is not available >&     83         echo $FAILCMD_TYPE is not available >&2
 92         exit 1                                     84         exit 1
 93 fi                                                 85 fi
 94                                                    86 
 95 LONGOPTS=probability:,interval:,times:,space:,     87 LONGOPTS=probability:,interval:,times:,space:,verbose:,task-filter:
 96 LONGOPTS=$LONGOPTS,stacktrace-depth:,require-s     88 LONGOPTS=$LONGOPTS,stacktrace-depth:,require-start:,require-end:
 97 LONGOPTS=$LONGOPTS,reject-start:,reject-end:,o     89 LONGOPTS=$LONGOPTS,reject-start:,reject-end:,oom-kill-allocating-task:,help
 98                                                    90 
 99 if [ $FAILCMD_TYPE = failslab ]; then              91 if [ $FAILCMD_TYPE = failslab ]; then
100         LONGOPTS=$LONGOPTS,ignore-gfp-wait:,ca     92         LONGOPTS=$LONGOPTS,ignore-gfp-wait:,cache-filter:
101 elif [ $FAILCMD_TYPE = fail_page_alloc ]; then     93 elif [ $FAILCMD_TYPE = fail_page_alloc ]; then
102         LONGOPTS=$LONGOPTS,ignore-gfp-wait:,ig     94         LONGOPTS=$LONGOPTS,ignore-gfp-wait:,ignore-gfp-highmem:,min-order:
103 fi                                                 95 fi
104                                                    96 
105 TEMP=`getopt -o p:i:t:s:v:h --long $LONGOPTS -     97 TEMP=`getopt -o p:i:t:s:v:h --long $LONGOPTS -n 'failcmd.sh' -- "$@"`
106                                                    98 
107 if [ $? != 0 ]; then                               99 if [ $? != 0 ]; then
108         usage                                     100         usage
109         exit 1                                    101         exit 1
110 fi                                                102 fi
111                                                   103 
112 eval set -- "$TEMP"                               104 eval set -- "$TEMP"
113                                                   105 
114 fault_attr_default()                              106 fault_attr_default()
115 {                                                 107 {
116         echo N > $FAULTATTR/task-filter           108         echo N > $FAULTATTR/task-filter
117         echo 0 > $FAULTATTR/probability           109         echo 0 > $FAULTATTR/probability
118         echo 1 > $FAULTATTR/times                 110         echo 1 > $FAULTATTR/times
119 }                                                 111 }
120                                                   112 
121 fault_attr_default                                113 fault_attr_default
122                                                   114 
123 oom_kill_allocating_task_saved=`cat /proc/sys/    115 oom_kill_allocating_task_saved=`cat /proc/sys/vm/oom_kill_allocating_task`
124                                                   116 
125 restore_values()                                  117 restore_values()
126 {                                                 118 {
127         fault_attr_default                        119         fault_attr_default
128         echo $oom_kill_allocating_task_saved \    120         echo $oom_kill_allocating_task_saved \
129                 > /proc/sys/vm/oom_kill_alloca    121                 > /proc/sys/vm/oom_kill_allocating_task
130 }                                                 122 }
131                                                   123 
132 #                                                 124 #
133 # Default options                                 125 # Default options
134 #                                                 126 #
135 declare -i oom_kill_allocating_task=1             127 declare -i oom_kill_allocating_task=1
136 declare task_filter=Y                             128 declare task_filter=Y
137 declare -i probability=1                          129 declare -i probability=1
138 declare -i times=1                                130 declare -i times=1
139                                                   131 
140 while true; do                                    132 while true; do
141         case "$1" in                              133         case "$1" in
142         -p|--probability)                         134         -p|--probability)
143                 probability=$2                    135                 probability=$2
144                 shift 2                           136                 shift 2
145                 ;;                                137                 ;;
146         -i|--interval)                            138         -i|--interval)
147                 echo $2 > $FAULTATTR/interval     139                 echo $2 > $FAULTATTR/interval
148                 shift 2                           140                 shift 2
149                 ;;                                141                 ;;
150         -t|--times)                               142         -t|--times)
151                 times=$2                          143                 times=$2
152                 shift 2                           144                 shift 2
153                 ;;                                145                 ;;
154         -s|--space)                               146         -s|--space)
155                 echo $2 > $FAULTATTR/space        147                 echo $2 > $FAULTATTR/space
156                 shift 2                           148                 shift 2
157                 ;;                                149                 ;;
158         -v|--verbose)                             150         -v|--verbose)
159                 echo $2 > $FAULTATTR/verbose      151                 echo $2 > $FAULTATTR/verbose
160                 shift 2                           152                 shift 2
161                 ;;                                153                 ;;
162         --task-filter)                            154         --task-filter)
163                 task_filter=$2                    155                 task_filter=$2
164                 shift 2                           156                 shift 2
165                 ;;                                157                 ;;
166         --stacktrace-depth)                       158         --stacktrace-depth)
167                 echo $2 > $FAULTATTR/stacktrac    159                 echo $2 > $FAULTATTR/stacktrace-depth
168                 shift 2                           160                 shift 2
169                 ;;                                161                 ;;
170         --require-start)                          162         --require-start)
171                 exit_if_not_hex "$2"           << 
172                 echo $2 > $FAULTATTR/require-s    163                 echo $2 > $FAULTATTR/require-start
173                 shift 2                           164                 shift 2
174                 ;;                                165                 ;;
175         --require-end)                            166         --require-end)
176                 exit_if_not_hex "$2"           << 
177                 echo $2 > $FAULTATTR/require-e    167                 echo $2 > $FAULTATTR/require-end
178                 shift 2                           168                 shift 2
179                 ;;                                169                 ;;
180         --reject-start)                           170         --reject-start)
181                 exit_if_not_hex "$2"           << 
182                 echo $2 > $FAULTATTR/reject-st    171                 echo $2 > $FAULTATTR/reject-start
183                 shift 2                           172                 shift 2
184                 ;;                                173                 ;;
185         --reject-end)                             174         --reject-end)
186                 exit_if_not_hex "$2"           << 
187                 echo $2 > $FAULTATTR/reject-en    175                 echo $2 > $FAULTATTR/reject-end
188                 shift 2                           176                 shift 2
189                 ;;                                177                 ;;
190         --oom-kill-allocating-task)               178         --oom-kill-allocating-task)
191                 oom_kill_allocating_task=$2       179                 oom_kill_allocating_task=$2
192                 shift 2                           180                 shift 2
193                 ;;                                181                 ;;
194         --ignore-gfp-wait)                        182         --ignore-gfp-wait)
195                 echo $2 > $FAULTATTR/ignore-gf    183                 echo $2 > $FAULTATTR/ignore-gfp-wait
196                 shift 2                           184                 shift 2
197                 ;;                                185                 ;;
198         --cache-filter)                           186         --cache-filter)
199                 echo $2 > $FAULTATTR/cache_fil    187                 echo $2 > $FAULTATTR/cache_filter
200                 shift 2                           188                 shift 2
201                 ;;                                189                 ;;
202         --ignore-gfp-highmem)                     190         --ignore-gfp-highmem)
203                 echo $2 > $FAULTATTR/ignore-gf    191                 echo $2 > $FAULTATTR/ignore-gfp-highmem
204                 shift 2                           192                 shift 2
205                 ;;                                193                 ;;
206         --min-order)                              194         --min-order)
207                 echo $2 > $FAULTATTR/min-order    195                 echo $2 > $FAULTATTR/min-order
208                 shift 2                           196                 shift 2
209                 ;;                                197                 ;;
210         -h|--help)                                198         -h|--help)
211                 usage                             199                 usage
212                 exit 0                            200                 exit 0
213                 shift                             201                 shift
214                 ;;                                202                 ;;
215         --)                                       203         --)
216                 shift                             204                 shift
217                 break                             205                 break
218                 ;;                                206                 ;;
219         esac                                      207         esac
220 done                                              208 done
221                                                   209 
222 [ -z "$1" ] && exit 0                             210 [ -z "$1" ] && exit 0
223                                                   211 
224 echo $oom_kill_allocating_task > /proc/sys/vm/    212 echo $oom_kill_allocating_task > /proc/sys/vm/oom_kill_allocating_task
225 echo $task_filter > $FAULTATTR/task-filter        213 echo $task_filter > $FAULTATTR/task-filter
226 echo $probability > $FAULTATTR/probability        214 echo $probability > $FAULTATTR/probability
227 echo $times > $FAULTATTR/times                    215 echo $times > $FAULTATTR/times
228                                                   216 
229 trap "restore_values" SIGINT SIGTERM EXIT         217 trap "restore_values" SIGINT SIGTERM EXIT
230                                                   218 
231 cmd="echo 1 > /proc/self/make-it-fail && exec     219 cmd="echo 1 > /proc/self/make-it-fail && exec $@"
232 bash -c "$cmd"                                    220 bash -c "$cmd"
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php