sched: Fix proc_sched_set_task()
[deliverable/linux.git] / mm / failslab.c
1 #include <linux/fault-inject.h>
2 #include <linux/gfp.h>
3 #include <linux/slab.h>
4
5 static struct {
6 struct fault_attr attr;
7 u32 ignore_gfp_wait;
8 int cache_filter;
9 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
10 struct dentry *ignore_gfp_wait_file;
11 struct dentry *cache_filter_file;
12 #endif
13 } failslab = {
14 .attr = FAULT_ATTR_INITIALIZER,
15 .ignore_gfp_wait = 1,
16 .cache_filter = 0,
17 };
18
19 bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags)
20 {
21 if (gfpflags & __GFP_NOFAIL)
22 return false;
23
24 if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
25 return false;
26
27 if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB))
28 return false;
29
30 return should_fail(&failslab.attr, size);
31 }
32
33 static int __init setup_failslab(char *str)
34 {
35 return setup_fault_attr(&failslab.attr, str);
36 }
37 __setup("failslab=", setup_failslab);
38
39 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
40 static int __init failslab_debugfs_init(void)
41 {
42 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
43 struct dentry *dir;
44 int err;
45
46 err = init_fault_attr_dentries(&failslab.attr, "failslab");
47 if (err)
48 return err;
49 dir = failslab.attr.dentries.dir;
50
51 failslab.ignore_gfp_wait_file =
52 debugfs_create_bool("ignore-gfp-wait", mode, dir,
53 &failslab.ignore_gfp_wait);
54
55 failslab.cache_filter_file =
56 debugfs_create_bool("cache-filter", mode, dir,
57 &failslab.cache_filter);
58
59 if (!failslab.ignore_gfp_wait_file ||
60 !failslab.cache_filter_file) {
61 err = -ENOMEM;
62 debugfs_remove(failslab.cache_filter_file);
63 debugfs_remove(failslab.ignore_gfp_wait_file);
64 cleanup_fault_attr_dentries(&failslab.attr);
65 }
66
67 return err;
68 }
69
70 late_initcall(failslab_debugfs_init);
71
72 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
This page took 0.03289 seconds and 5 git commands to generate.