Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 1 | #include <linux/fault-inject.h> |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 2 | #include <linux/slab.h> |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 3 | |
| 4 | static struct { |
| 5 | struct fault_attr attr; |
| 6 | u32 ignore_gfp_wait; |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 7 | int cache_filter; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 8 | } failslab = { |
| 9 | .attr = FAULT_ATTR_INITIALIZER, |
| 10 | .ignore_gfp_wait = 1, |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 11 | .cache_filter = 0, |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 12 | }; |
| 13 | |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 14 | 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] | 15 | { |
| 16 | if (gfpflags & __GFP_NOFAIL) |
| 17 | return false; |
| 18 | |
| 19 | if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT)) |
| 20 | return false; |
| 21 | |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 22 | if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB)) |
| 23 | return false; |
| 24 | |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 25 | return should_fail(&failslab.attr, size); |
| 26 | } |
| 27 | |
| 28 | static int __init setup_failslab(char *str) |
| 29 | { |
| 30 | return setup_fault_attr(&failslab.attr, str); |
| 31 | } |
| 32 | __setup("failslab=", setup_failslab); |
| 33 | |
| 34 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 35 | static int __init failslab_debugfs_init(void) |
| 36 | { |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 37 | struct dentry *dir; |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 38 | umode_t mode = S_IFREG | S_IRUSR | S_IWUSR; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 39 | |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 40 | dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr); |
| 41 | if (IS_ERR(dir)) |
| 42 | return PTR_ERR(dir); |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 43 | |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 44 | if (!debugfs_create_bool("ignore-gfp-wait", mode, dir, |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 45 | &failslab.ignore_gfp_wait)) |
| 46 | goto fail; |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 47 | if (!debugfs_create_bool("cache-filter", mode, dir, |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 48 | &failslab.cache_filter)) |
| 49 | goto fail; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 50 | |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 51 | return 0; |
| 52 | fail: |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 53 | debugfs_remove_recursive(dir); |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 54 | |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 55 | return -ENOMEM; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | late_initcall(failslab_debugfs_init); |
| 59 | |
| 60 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |