Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 1 | #include <linux/fault-inject.h> |
Pekka Enberg | 255d11b | 2009-03-24 11:59:21 +0200 | [diff] [blame] | 2 | #include <linux/gfp.h> |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 3 | #include <linux/slab.h> |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 4 | |
| 5 | static struct { |
| 6 | struct fault_attr attr; |
| 7 | u32 ignore_gfp_wait; |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 8 | int cache_filter; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 9 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
| 10 | struct dentry *ignore_gfp_wait_file; |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 11 | struct dentry *cache_filter_file; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 12 | #endif |
| 13 | } failslab = { |
| 14 | .attr = FAULT_ATTR_INITIALIZER, |
| 15 | .ignore_gfp_wait = 1, |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 16 | .cache_filter = 0, |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 17 | }; |
| 18 | |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 19 | bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags) |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 20 | { |
| 21 | if (gfpflags & __GFP_NOFAIL) |
| 22 | return false; |
| 23 | |
| 24 | if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT)) |
| 25 | return false; |
| 26 | |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 27 | if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB)) |
| 28 | return false; |
| 29 | |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 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 |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 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 | |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 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) { |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 61 | err = -ENOMEM; |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame^] | 62 | debugfs_remove(failslab.cache_filter_file); |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 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 */ |