blob: 9339de5f0a915dc0526e276eddbcc5fb918fb13d [file] [log] [blame]
Akinobu Mita773ff602008-12-23 19:37:01 +09001#include <linux/fault-inject.h>
Pekka Enberg255d11b2009-03-24 11:59:21 +02002#include <linux/gfp.h>
Akinobu Mita773ff602008-12-23 19:37:01 +09003
4static 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
15bool 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
26static 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
34static 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
58late_initcall(failslab_debugfs_init);
59
60#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */