1 #include <linux/fault-inject.h>
3 #include <linux/slab.h>
6 struct fault_attr attr
;
9 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
10 struct dentry
*ignore_gfp_wait_file
;
11 struct dentry
*cache_filter_file
;
14 .attr
= FAULT_ATTR_INITIALIZER
,
19 bool should_failslab(size_t size
, gfp_t gfpflags
, unsigned long cache_flags
)
21 if (gfpflags
& __GFP_NOFAIL
)
24 if (failslab
.ignore_gfp_wait
&& (gfpflags
& __GFP_WAIT
))
27 if (failslab
.cache_filter
&& !(cache_flags
& SLAB_FAILSLAB
))
30 return should_fail(&failslab
.attr
, size
);
33 static int __init
setup_failslab(char *str
)
35 return setup_fault_attr(&failslab
.attr
, str
);
37 __setup("failslab=", setup_failslab
);
39 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
40 static int __init
failslab_debugfs_init(void)
42 mode_t mode
= S_IFREG
| S_IRUSR
| S_IWUSR
;
46 err
= init_fault_attr_dentries(&failslab
.attr
, "failslab");
49 dir
= failslab
.attr
.dentries
.dir
;
51 failslab
.ignore_gfp_wait_file
=
52 debugfs_create_bool("ignore-gfp-wait", mode
, dir
,
53 &failslab
.ignore_gfp_wait
);
55 failslab
.cache_filter_file
=
56 debugfs_create_bool("cache-filter", mode
, dir
,
57 &failslab
.cache_filter
);
59 if (!failslab
.ignore_gfp_wait_file
||
60 !failslab
.cache_filter_file
) {
62 debugfs_remove(failslab
.cache_filter_file
);
63 debugfs_remove(failslab
.ignore_gfp_wait_file
);
64 cleanup_fault_attr_dentries(&failslab
.attr
);
70 late_initcall(failslab_debugfs_init
);
72 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */