blob: c5f88f240ddcfc26a8cb2b2fadf66a3345102a5f [file] [log] [blame]
Akinobu Mita773ff602008-12-23 19:37:01 +09001#include <linux/fault-inject.h>
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +03002#include <linux/slab.h>
Akinobu Mita773ff602008-12-23 19:37:01 +09003
4static struct {
5 struct fault_attr attr;
6 u32 ignore_gfp_wait;
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +03007 int cache_filter;
Akinobu Mita773ff602008-12-23 19:37:01 +09008#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
9 struct dentry *ignore_gfp_wait_file;
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030010 struct dentry *cache_filter_file;
Akinobu Mita773ff602008-12-23 19:37:01 +090011#endif
12} failslab = {
13 .attr = FAULT_ATTR_INITIALIZER,
14 .ignore_gfp_wait = 1,
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030015 .cache_filter = 0,
Akinobu Mita773ff602008-12-23 19:37:01 +090016};
17
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030018bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags)
Akinobu Mita773ff602008-12-23 19:37:01 +090019{
20 if (gfpflags & __GFP_NOFAIL)
21 return false;
22
23 if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
24 return false;
25
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030026 if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB))
27 return false;
28
Akinobu Mita773ff602008-12-23 19:37:01 +090029 return should_fail(&failslab.attr, size);
30}
31
32static int __init setup_failslab(char *str)
33{
34 return setup_fault_attr(&failslab.attr, str);
35}
36__setup("failslab=", setup_failslab);
37
38#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
Akinobu Mita773ff602008-12-23 19:37:01 +090039static int __init failslab_debugfs_init(void)
40{
41 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
42 struct dentry *dir;
43 int err;
44
45 err = init_fault_attr_dentries(&failslab.attr, "failslab");
46 if (err)
47 return err;
48 dir = failslab.attr.dentries.dir;
49
50 failslab.ignore_gfp_wait_file =
51 debugfs_create_bool("ignore-gfp-wait", mode, dir,
52 &failslab.ignore_gfp_wait);
53
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030054 failslab.cache_filter_file =
55 debugfs_create_bool("cache-filter", mode, dir,
56 &failslab.cache_filter);
57
58 if (!failslab.ignore_gfp_wait_file ||
59 !failslab.cache_filter_file) {
Akinobu Mita773ff602008-12-23 19:37:01 +090060 err = -ENOMEM;
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030061 debugfs_remove(failslab.cache_filter_file);
Akinobu Mita773ff602008-12-23 19:37:01 +090062 debugfs_remove(failslab.ignore_gfp_wait_file);
63 cleanup_fault_attr_dentries(&failslab.attr);
64 }
65
66 return err;
67}
68
69late_initcall(failslab_debugfs_init);
70
71#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */