diff options
| author | Akinobu Mita <akinobu.mita@gmail.com> | 2006-12-08 05:39:47 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-08 11:29:02 -0500 |
| commit | f4f154fd920b2178382a6a24a236348e4429ebc1 (patch) | |
| tree | 0bba747eb50b5d7e18d2b828f8c707b2781d7544 /lib | |
| parent | c17bb4951752d3e0f49cd1ea9d2e868422f9e0d6 (diff) | |
[PATCH] fault injection: process filtering for fault-injection capabilities
This patch provides process filtering feature.
The process filter allows failing only permitted processes
by /proc/<pid>/make-it-fail
Please see the example that demostrates how to inject slab allocation
failures into module init/cleanup code
in Documentation/fault-injection/fault-injection.txt
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/fault-inject.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/fault-inject.c b/lib/fault-inject.c index a7cb3afd132a..03468609d701 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <linux/types.h> | 5 | #include <linux/types.h> |
| 6 | #include <linux/fs.h> | 6 | #include <linux/fs.h> |
| 7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
| 8 | #include <linux/interrupt.h> | ||
| 8 | #include <linux/fault-inject.h> | 9 | #include <linux/fault-inject.h> |
| 9 | 10 | ||
| 10 | /* | 11 | /* |
| @@ -44,6 +45,11 @@ static void fail_dump(struct fault_attr *attr) | |||
| 44 | 45 | ||
| 45 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) | 46 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) |
| 46 | 47 | ||
| 48 | static int fail_task(struct fault_attr *attr, struct task_struct *task) | ||
| 49 | { | ||
| 50 | return !in_interrupt() && task->make_it_fail; | ||
| 51 | } | ||
| 52 | |||
| 47 | /* | 53 | /* |
| 48 | * This code is stolen from failmalloc-1.0 | 54 | * This code is stolen from failmalloc-1.0 |
| 49 | * http://www.nongnu.org/failmalloc/ | 55 | * http://www.nongnu.org/failmalloc/ |
| @@ -51,6 +57,9 @@ static void fail_dump(struct fault_attr *attr) | |||
| 51 | 57 | ||
| 52 | int should_fail(struct fault_attr *attr, ssize_t size) | 58 | int should_fail(struct fault_attr *attr, ssize_t size) |
| 53 | { | 59 | { |
| 60 | if (attr->task_filter && !fail_task(attr, current)) | ||
| 61 | return 0; | ||
| 62 | |||
| 54 | if (atomic_read(&attr->times) == 0) | 63 | if (atomic_read(&attr->times) == 0) |
| 55 | return 0; | 64 | return 0; |
| 56 | 65 | ||
| @@ -135,6 +144,9 @@ void cleanup_fault_attr_dentries(struct fault_attr *attr) | |||
| 135 | debugfs_remove(attr->dentries.verbose_file); | 144 | debugfs_remove(attr->dentries.verbose_file); |
| 136 | attr->dentries.verbose_file = NULL; | 145 | attr->dentries.verbose_file = NULL; |
| 137 | 146 | ||
| 147 | debugfs_remove(attr->dentries.task_filter_file); | ||
| 148 | attr->dentries.task_filter_file = NULL; | ||
| 149 | |||
| 138 | if (attr->dentries.dir) | 150 | if (attr->dentries.dir) |
| 139 | WARN_ON(!simple_empty(attr->dentries.dir)); | 151 | WARN_ON(!simple_empty(attr->dentries.dir)); |
| 140 | 152 | ||
| @@ -169,9 +181,12 @@ int init_fault_attr_dentries(struct fault_attr *attr, const char *name) | |||
| 169 | attr->dentries.verbose_file = | 181 | attr->dentries.verbose_file = |
| 170 | debugfs_create_ul("verbose", mode, dir, &attr->verbose); | 182 | debugfs_create_ul("verbose", mode, dir, &attr->verbose); |
| 171 | 183 | ||
| 184 | attr->dentries.task_filter_file = debugfs_create_bool("task-filter", | ||
| 185 | mode, dir, &attr->task_filter); | ||
| 186 | |||
| 172 | if (!attr->dentries.probability_file || !attr->dentries.interval_file | 187 | if (!attr->dentries.probability_file || !attr->dentries.interval_file |
| 173 | || !attr->dentries.times_file || !attr->dentries.space_file | 188 | || !attr->dentries.times_file || !attr->dentries.space_file |
| 174 | || !attr->dentries.verbose_file) | 189 | || !attr->dentries.verbose_file || !attr->dentries.task_filter_file) |
| 175 | goto fail; | 190 | goto fail; |
| 176 | 191 | ||
| 177 | return 0; | 192 | return 0; |
