Commit dd48c085c1cdf9446f92826f1fd451167fb6c2fd

Authored by Akinobu Mita
Committed by Linus Torvalds
1 parent f48d1915b8

fault-injection: add ability to export fault_attr in arbitrary directory

init_fault_attr_dentries() is used to export fault_attr via debugfs.
But it can only export it in debugfs root directory.

Per Forlin is working on mmc_fail_request which adds support to inject
data errors after a completed host transfer in MMC subsystem.

The fault_attr for mmc_fail_request should be defined per mmc host and
export it in debugfs directory per mmc host like
/sys/kernel/debug/mmc0/mmc_fail_request.

init_fault_attr_dentries() doesn't help for mmc_fail_request.  So this
introduces fault_create_debugfs_attr() which is able to create a
directory in the arbitrary directory and replace
init_fault_attr_dentries().

[akpm@linux-foundation.org: extraneous semicolon, per Randy]
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Tested-by: Per Forlin <per.forlin@linaro.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 7 changed files with 33 additions and 46 deletions Side-by-side Diff

Documentation/fault-injection/fault-injection.txt
... ... @@ -143,8 +143,7 @@
143 143 failslab, fail_page_alloc, and fail_make_request use this way.
144 144 Helper functions:
145 145  
146   - init_fault_attr_dentries(entries, attr, name);
147   - void cleanup_fault_attr_dentries(entries);
  146 + fault_create_debugfs_attr(name, parent, attr);
148 147  
149 148 - module parameters
150 149  
... ... @@ -1368,8 +1368,10 @@
1368 1368  
1369 1369 static int __init fail_make_request_debugfs(void)
1370 1370 {
1371   - return init_fault_attr_dentries(&fail_make_request,
1372   - "fail_make_request");
  1371 + struct dentry *dir = fault_create_debugfs_attr("fail_make_request",
  1372 + NULL, &fail_make_request);
  1373 +
  1374 + return IS_ERR(dir) ? PTR_ERR(dir) : 0;
1373 1375 }
1374 1376  
1375 1377 late_initcall(fail_make_request_debugfs);
... ... @@ -28,7 +28,10 @@
28 28  
29 29 static int __init fail_io_timeout_debugfs(void)
30 30 {
31   - return init_fault_attr_dentries(&fail_io_timeout, "fail_io_timeout");
  31 + struct dentry *dir = fault_create_debugfs_attr("fail_io_timeout",
  32 + NULL, &fail_io_timeout);
  33 +
  34 + return IS_ERR(dir) ? PTR_ERR(dir) : 0;
32 35 }
33 36  
34 37 late_initcall(fail_io_timeout_debugfs);
include/linux/fault-inject.h
... ... @@ -25,10 +25,6 @@
25 25 unsigned long reject_end;
26 26  
27 27 unsigned long count;
28   -
29   -#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
30   - struct dentry *dir;
31   -#endif
32 28 };
33 29  
34 30 #define FAULT_ATTR_INITIALIZER { \
35 31  
36 32  
... ... @@ -45,19 +41,15 @@
45 41  
46 42 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
47 43  
48   -int init_fault_attr_dentries(struct fault_attr *attr, const char *name);
49   -void cleanup_fault_attr_dentries(struct fault_attr *attr);
  44 +struct dentry *fault_create_debugfs_attr(const char *name,
  45 + struct dentry *parent, struct fault_attr *attr);
50 46  
51 47 #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
52 48  
53   -static inline int init_fault_attr_dentries(struct fault_attr *attr,
54   - const char *name)
  49 +static inline struct dentry *fault_create_debugfs_attr(const char *name,
  50 + struct dentry *parent, struct fault_attr *attr)
55 51 {
56   - return -ENODEV;
57   -}
58   -
59   -static inline void cleanup_fault_attr_dentries(struct fault_attr *attr)
60   -{
  52 + return ERR_PTR(-ENODEV);
61 53 }
62 54  
63 55 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
... ... @@ -197,22 +197,16 @@
197 197 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t);
198 198 }
199 199  
200   -void cleanup_fault_attr_dentries(struct fault_attr *attr)
  200 +struct dentry *fault_create_debugfs_attr(const char *name,
  201 + struct dentry *parent, struct fault_attr *attr)
201 202 {
202   - debugfs_remove_recursive(attr->dir);
203   -}
204   -
205   -int init_fault_attr_dentries(struct fault_attr *attr, const char *name)
206   -{
207 203 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
208 204 struct dentry *dir;
209 205  
210   - dir = debugfs_create_dir(name, NULL);
  206 + dir = debugfs_create_dir(name, parent);
211 207 if (!dir)
212   - return -ENOMEM;
  208 + return ERR_PTR(-ENOMEM);
213 209  
214   - attr->dir = dir;
215   -
216 210 if (!debugfs_create_ul("probability", mode, dir, &attr->probability))
217 211 goto fail;
218 212 if (!debugfs_create_ul("interval", mode, dir, &attr->interval))
219 213  
220 214  
... ... @@ -243,11 +237,11 @@
243 237  
244 238 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
245 239  
246   - return 0;
  240 + return dir;
247 241 fail:
248   - debugfs_remove_recursive(attr->dir);
  242 + debugfs_remove_recursive(dir);
249 243  
250   - return -ENOMEM;
  244 + return ERR_PTR(-ENOMEM);
251 245 }
252 246  
253 247 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
... ... @@ -34,23 +34,23 @@
34 34 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
35 35 static int __init failslab_debugfs_init(void)
36 36 {
  37 + struct dentry *dir;
37 38 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
38   - int err;
39 39  
40   - err = init_fault_attr_dentries(&failslab.attr, "failslab");
41   - if (err)
42   - return err;
  40 + dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
  41 + if (IS_ERR(dir))
  42 + return PTR_ERR(dir);
43 43  
44   - if (!debugfs_create_bool("ignore-gfp-wait", mode, failslab.attr.dir,
  44 + if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
45 45 &failslab.ignore_gfp_wait))
46 46 goto fail;
47   - if (!debugfs_create_bool("cache-filter", mode, failslab.attr.dir,
  47 + if (!debugfs_create_bool("cache-filter", mode, dir,
48 48 &failslab.cache_filter))
49 49 goto fail;
50 50  
51 51 return 0;
52 52 fail:
53   - cleanup_fault_attr_dentries(&failslab.attr);
  53 + debugfs_remove_recursive(dir);
54 54  
55 55 return -ENOMEM;
56 56 }
... ... @@ -1409,15 +1409,12 @@
1409 1409 {
1410 1410 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
1411 1411 struct dentry *dir;
1412   - int err;
1413 1412  
1414   - err = init_fault_attr_dentries(&fail_page_alloc.attr,
1415   - "fail_page_alloc");
1416   - if (err)
1417   - return err;
  1413 + dir = fault_create_debugfs_attr("fail_page_alloc", NULL,
  1414 + &fail_page_alloc.attr);
  1415 + if (IS_ERR(dir))
  1416 + return PTR_ERR(dir);
1418 1417  
1419   - dir = fail_page_alloc.attr.dir;
1420   -
1421 1418 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
1422 1419 &fail_page_alloc.ignore_gfp_wait))
1423 1420 goto fail;
... ... @@ -1430,7 +1427,7 @@
1430 1427  
1431 1428 return 0;
1432 1429 fail:
1433   - cleanup_fault_attr_dentries(&fail_page_alloc.attr);
  1430 + debugfs_remove_recursive(dir);
1434 1431  
1435 1432 return -ENOMEM;
1436 1433 }