Add linux-next specific files for 20110728
[linux-2.6/next.git] / mm / failslab.c
blob1ce58c201dca5c117456ab9d54d4dc48e7809287
1 #include <linux/fault-inject.h>
2 #include <linux/slab.h>
4 static struct {
5 struct fault_attr attr;
6 u32 ignore_gfp_wait;
7 int cache_filter;
8 } failslab = {
9 .attr = FAULT_ATTR_INITIALIZER,
10 .ignore_gfp_wait = 1,
11 .cache_filter = 0,
14 bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags)
16 if (gfpflags & __GFP_NOFAIL)
17 return false;
19 if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
20 return false;
22 if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB))
23 return false;
25 return should_fail(&failslab.attr, size);
28 static int __init setup_failslab(char *str)
30 return setup_fault_attr(&failslab.attr, str);
32 __setup("failslab=", setup_failslab);
34 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
35 static int __init failslab_debugfs_init(void)
37 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
38 int err;
40 err = init_fault_attr_dentries(&failslab.attr, "failslab");
41 if (err)
42 return err;
44 if (!debugfs_create_bool("ignore-gfp-wait", mode, failslab.attr.dir,
45 &failslab.ignore_gfp_wait))
46 goto fail;
47 if (!debugfs_create_bool("cache-filter", mode, failslab.attr.dir,
48 &failslab.cache_filter))
49 goto fail;
51 return 0;
52 fail:
53 cleanup_fault_attr_dentries(&failslab.attr);
55 return -ENOMEM;
58 late_initcall(failslab_debugfs_init);
60 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */