aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/fault-injection/fault-injection.txt3
-rw-r--r--block/blk-core.c6
-rw-r--r--block/blk-timeout.c5
-rw-r--r--include/linux/fault-inject.h18
-rw-r--r--lib/fault-inject.c20
-rw-r--r--mm/failslab.c14
-rw-r--r--mm/page_alloc.c13
7 files changed, 33 insertions, 46 deletions
diff --git a/Documentation/fault-injection/fault-injection.txt b/Documentation/fault-injection/fault-injection.txt
index 7be15e44d481..82a5d250d75e 100644
--- a/Documentation/fault-injection/fault-injection.txt
+++ b/Documentation/fault-injection/fault-injection.txt
@@ -143,8 +143,7 @@ o provide a way to configure fault attributes
143 failslab, fail_page_alloc, and fail_make_request use this way. 143 failslab, fail_page_alloc, and fail_make_request use this way.
144 Helper functions: 144 Helper functions:
145 145
146 init_fault_attr_dentries(entries, attr, name); 146 fault_create_debugfs_attr(name, parent, attr);
147 void cleanup_fault_attr_dentries(entries);
148 147
149- module parameters 148- module parameters
150 149
diff --git a/block/blk-core.c b/block/blk-core.c
index b850bedad229..b627558c461f 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1368,8 +1368,10 @@ static bool should_fail_request(struct hd_struct *part, unsigned int bytes)
1368 1368
1369static int __init fail_make_request_debugfs(void) 1369static int __init fail_make_request_debugfs(void)
1370{ 1370{
1371 return init_fault_attr_dentries(&fail_make_request, 1371 struct dentry *dir = fault_create_debugfs_attr("fail_make_request",
1372 "fail_make_request"); 1372 NULL, &fail_make_request);
1373
1374 return IS_ERR(dir) ? PTR_ERR(dir) : 0;
1373} 1375}
1374 1376
1375late_initcall(fail_make_request_debugfs); 1377late_initcall(fail_make_request_debugfs);
diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index 4f0c06c7a338..780354888958 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -28,7 +28,10 @@ int blk_should_fake_timeout(struct request_queue *q)
28 28
29static int __init fail_io_timeout_debugfs(void) 29static 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
34late_initcall(fail_io_timeout_debugfs); 37late_initcall(fail_io_timeout_debugfs);
diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h
index 3ff060ac7810..c6f996f2abb6 100644
--- a/include/linux/fault-inject.h
+++ b/include/linux/fault-inject.h
@@ -25,10 +25,6 @@ struct fault_attr {
25 unsigned long reject_end; 25 unsigned long reject_end;
26 26
27 unsigned long count; 27 unsigned long count;
28
29#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
30 struct dentry *dir;
31#endif
32}; 28};
33 29
34#define FAULT_ATTR_INITIALIZER { \ 30#define FAULT_ATTR_INITIALIZER { \
@@ -45,19 +41,15 @@ bool should_fail(struct fault_attr *attr, ssize_t size);
45 41
46#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 42#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
47 43
48int init_fault_attr_dentries(struct fault_attr *attr, const char *name); 44struct dentry *fault_create_debugfs_attr(const char *name,
49void cleanup_fault_attr_dentries(struct fault_attr *attr); 45 struct dentry *parent, struct fault_attr *attr);
50 46
51#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 47#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
52 48
53static inline int init_fault_attr_dentries(struct fault_attr *attr, 49static inline struct dentry *fault_create_debugfs_attr(const char *name,
54 const char *name) 50 struct dentry *parent, struct fault_attr *attr)
55{
56 return -ENODEV;
57}
58
59static inline void cleanup_fault_attr_dentries(struct fault_attr *attr)
60{ 51{
52 return ERR_PTR(-ENODEV);
61} 53}
62 54
63#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 55#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 2577b121c7c1..f193b7796449 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -197,21 +197,15 @@ static struct dentry *debugfs_create_atomic_t(const char *name, mode_t mode,
197 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t); 197 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t);
198} 198}
199 199
200void cleanup_fault_attr_dentries(struct fault_attr *attr) 200struct dentry *fault_create_debugfs_attr(const char *name,
201{ 201 struct dentry *parent, struct fault_attr *attr)
202 debugfs_remove_recursive(attr->dir);
203}
204
205int init_fault_attr_dentries(struct fault_attr *attr, const char *name)
206{ 202{
207 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; 203 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
208 struct dentry *dir; 204 struct dentry *dir;
209 205
210 dir = debugfs_create_dir(name, NULL); 206 dir = debugfs_create_dir(name, parent);
211 if (!dir) 207 if (!dir)
212 return -ENOMEM; 208 return ERR_PTR(-ENOMEM);
213
214 attr->dir = dir;
215 209
216 if (!debugfs_create_ul("probability", mode, dir, &attr->probability)) 210 if (!debugfs_create_ul("probability", mode, dir, &attr->probability))
217 goto fail; 211 goto fail;
@@ -243,11 +237,11 @@ int init_fault_attr_dentries(struct fault_attr *attr, const char *name)
243 237
244#endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ 238#endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
245 239
246 return 0; 240 return dir;
247fail: 241fail:
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#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 247#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
diff --git a/mm/failslab.c b/mm/failslab.c
index 1ce58c201dca..0dd7b8fec71c 100644
--- a/mm/failslab.c
+++ b/mm/failslab.c
@@ -34,23 +34,23 @@ __setup("failslab=", setup_failslab);
34#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 34#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
35static int __init failslab_debugfs_init(void) 35static int __init failslab_debugfs_init(void)
36{ 36{
37 struct dentry *dir;
37 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; 38 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
38 int err;
39 39
40 err = init_fault_attr_dentries(&failslab.attr, "failslab"); 40 dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
41 if (err) 41 if (IS_ERR(dir))
42 return err; 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 &failslab.ignore_gfp_wait)) 45 &failslab.ignore_gfp_wait))
46 goto fail; 46 goto fail;
47 if (!debugfs_create_bool("cache-filter", mode, failslab.attr.dir, 47 if (!debugfs_create_bool("cache-filter", mode, dir,
48 &failslab.cache_filter)) 48 &failslab.cache_filter))
49 goto fail; 49 goto fail;
50 50
51 return 0; 51 return 0;
52fail: 52fail:
53 cleanup_fault_attr_dentries(&failslab.attr); 53 debugfs_remove_recursive(dir);
54 54
55 return -ENOMEM; 55 return -ENOMEM;
56} 56}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 1dbcf8888f14..6e8ecb6e021c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1409,14 +1409,11 @@ static int __init fail_page_alloc_debugfs(void)
1409{ 1409{
1410 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; 1410 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
1411 struct dentry *dir; 1411 struct dentry *dir;
1412 int err;
1413 1412
1414 err = init_fault_attr_dentries(&fail_page_alloc.attr, 1413 dir = fault_create_debugfs_attr("fail_page_alloc", NULL,
1415 "fail_page_alloc"); 1414 &fail_page_alloc.attr);
1416 if (err) 1415 if (IS_ERR(dir))
1417 return err; 1416 return PTR_ERR(dir);
1418
1419 dir = fail_page_alloc.attr.dir;
1420 1417
1421 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir, 1418 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
1422 &fail_page_alloc.ignore_gfp_wait)) 1419 &fail_page_alloc.ignore_gfp_wait))
@@ -1430,7 +1427,7 @@ static int __init fail_page_alloc_debugfs(void)
1430 1427
1431 return 0; 1428 return 0;
1432fail: 1429fail:
1433 cleanup_fault_attr_dentries(&fail_page_alloc.attr); 1430 debugfs_remove_recursive(dir);
1434 1431
1435 return -ENOMEM; 1432 return -ENOMEM;
1436} 1433}