diff options
Diffstat (limited to 'fs/nfsd/fault_inject.c')
-rw-r--r-- | fs/nfsd/fault_inject.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c new file mode 100644 index 000000000000..ce7f0758d84c --- /dev/null +++ b/fs/nfsd/fault_inject.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com> | ||
3 | * | ||
4 | * Uses debugfs to create fault injection points for client testing | ||
5 | */ | ||
6 | |||
7 | #include <linux/types.h> | ||
8 | #include <linux/fs.h> | ||
9 | #include <linux/debugfs.h> | ||
10 | #include <linux/module.h> | ||
11 | |||
12 | #include "state.h" | ||
13 | #include "fault_inject.h" | ||
14 | |||
15 | struct nfsd_fault_inject_op { | ||
16 | char *file; | ||
17 | void (*func)(u64); | ||
18 | }; | ||
19 | |||
20 | static struct nfsd_fault_inject_op inject_ops[] = { | ||
21 | { | ||
22 | .file = "forget_clients", | ||
23 | .func = nfsd_forget_clients, | ||
24 | }, | ||
25 | { | ||
26 | .file = "forget_locks", | ||
27 | .func = nfsd_forget_locks, | ||
28 | }, | ||
29 | { | ||
30 | .file = "forget_openowners", | ||
31 | .func = nfsd_forget_openowners, | ||
32 | }, | ||
33 | { | ||
34 | .file = "forget_delegations", | ||
35 | .func = nfsd_forget_delegations, | ||
36 | }, | ||
37 | { | ||
38 | .file = "recall_delegations", | ||
39 | .func = nfsd_recall_delegations, | ||
40 | }, | ||
41 | }; | ||
42 | |||
43 | static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op); | ||
44 | static struct dentry *debug_dir; | ||
45 | |||
46 | static int nfsd_inject_set(void *op_ptr, u64 val) | ||
47 | { | ||
48 | struct nfsd_fault_inject_op *op = op_ptr; | ||
49 | |||
50 | if (val == 0) | ||
51 | printk(KERN_INFO "NFSD Fault Injection: %s (all)", op->file); | ||
52 | else | ||
53 | printk(KERN_INFO "NFSD Fault Injection: %s (n = %llu)", op->file, val); | ||
54 | |||
55 | op->func(val); | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static int nfsd_inject_get(void *data, u64 *val) | ||
60 | { | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n"); | ||
65 | |||
66 | void nfsd_fault_inject_cleanup(void) | ||
67 | { | ||
68 | debugfs_remove_recursive(debug_dir); | ||
69 | } | ||
70 | |||
71 | int nfsd_fault_inject_init(void) | ||
72 | { | ||
73 | unsigned int i; | ||
74 | struct nfsd_fault_inject_op *op; | ||
75 | mode_t mode = S_IFREG | S_IRUSR | S_IWUSR; | ||
76 | |||
77 | debug_dir = debugfs_create_dir("nfsd", NULL); | ||
78 | if (!debug_dir) | ||
79 | goto fail; | ||
80 | |||
81 | for (i = 0; i < NUM_INJECT_OPS; i++) { | ||
82 | op = &inject_ops[i]; | ||
83 | if (!debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd)) | ||
84 | goto fail; | ||
85 | } | ||
86 | return 0; | ||
87 | |||
88 | fail: | ||
89 | nfsd_fault_inject_cleanup(); | ||
90 | return -ENOMEM; | ||
91 | } | ||