tracing: x86, mmiotrace: only register for die notifier when tracer active
[linux-2.6] / mm / failslab.c
1 #include <linux/fault-inject.h>
2 #include <linux/gfp.h>
3
4 static struct {
5         struct fault_attr attr;
6         u32 ignore_gfp_wait;
7 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
8         struct dentry *ignore_gfp_wait_file;
9 #endif
10 } failslab = {
11         .attr = FAULT_ATTR_INITIALIZER,
12         .ignore_gfp_wait = 1,
13 };
14
15 bool should_failslab(size_t size, gfp_t gfpflags)
16 {
17         if (gfpflags & __GFP_NOFAIL)
18                 return false;
19
20         if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
21                 return false;
22
23         return should_fail(&failslab.attr, size);
24 }
25
26 static int __init setup_failslab(char *str)
27 {
28         return setup_fault_attr(&failslab.attr, str);
29 }
30 __setup("failslab=", setup_failslab);
31
32 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
33
34 static int __init failslab_debugfs_init(void)
35 {
36         mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
37         struct dentry *dir;
38         int err;
39
40         err = init_fault_attr_dentries(&failslab.attr, "failslab");
41         if (err)
42                 return err;
43         dir = failslab.attr.dentries.dir;
44
45         failslab.ignore_gfp_wait_file =
46                 debugfs_create_bool("ignore-gfp-wait", mode, dir,
47                                       &failslab.ignore_gfp_wait);
48
49         if (!failslab.ignore_gfp_wait_file) {
50                 err = -ENOMEM;
51                 debugfs_remove(failslab.ignore_gfp_wait_file);
52                 cleanup_fault_attr_dentries(&failslab.attr);
53         }
54
55         return err;
56 }
57
58 late_initcall(failslab_debugfs_init);
59
60 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */