1 #include <linux/fault-inject.h>
2 #include <linux/slab.h>
5 struct fault_attr attr
;
6 bool ignore_gfp_reclaim
;
9 .attr
= FAULT_ATTR_INITIALIZER
,
10 .ignore_gfp_reclaim
= true,
11 .cache_filter
= false,
14 bool should_failslab(size_t size
, gfp_t gfpflags
, unsigned long cache_flags
)
16 if (gfpflags
& __GFP_NOFAIL
)
19 if (failslab
.ignore_gfp_reclaim
&& (gfpflags
& __GFP_RECLAIM
))
22 if (failslab
.cache_filter
&& !(cache_flags
& SLAB_FAILSLAB
))
25 return should_fail(&failslab
.attr
, size
);
28 static int __init
setup_failslab(char *str
)
30 return setup_fault_attr(&failslab
.attr
, str
);
32 __setup("failslab=", setup_failslab
);
34 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
35 static int __init
failslab_debugfs_init(void)
38 umode_t mode
= S_IFREG
| S_IRUSR
| S_IWUSR
;
40 dir
= fault_create_debugfs_attr("failslab", NULL
, &failslab
.attr
);
44 if (!debugfs_create_bool("ignore-gfp-wait", mode
, dir
,
45 &failslab
.ignore_gfp_reclaim
))
47 if (!debugfs_create_bool("cache-filter", mode
, dir
,
48 &failslab
.cache_filter
))
53 debugfs_remove_recursive(dir
);
58 late_initcall(failslab_debugfs_init
);
60 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */