Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 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" |
Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 13 | |
| 14 | struct nfsd_fault_inject_op { |
| 15 | char *file; |
| 16 | void (*func)(u64); |
| 17 | }; |
| 18 | |
| 19 | static struct nfsd_fault_inject_op inject_ops[] = { |
| 20 | { |
| 21 | .file = "forget_clients", |
| 22 | .func = nfsd_forget_clients, |
| 23 | }, |
| 24 | { |
| 25 | .file = "forget_locks", |
| 26 | .func = nfsd_forget_locks, |
| 27 | }, |
| 28 | { |
| 29 | .file = "forget_openowners", |
| 30 | .func = nfsd_forget_openowners, |
| 31 | }, |
| 32 | { |
| 33 | .file = "forget_delegations", |
| 34 | .func = nfsd_forget_delegations, |
| 35 | }, |
| 36 | { |
| 37 | .file = "recall_delegations", |
| 38 | .func = nfsd_recall_delegations, |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op); |
| 43 | static struct dentry *debug_dir; |
| 44 | |
| 45 | static int nfsd_inject_set(void *op_ptr, u64 val) |
| 46 | { |
| 47 | struct nfsd_fault_inject_op *op = op_ptr; |
| 48 | |
| 49 | if (val == 0) |
| 50 | printk(KERN_INFO "NFSD Fault Injection: %s (all)", op->file); |
| 51 | else |
| 52 | printk(KERN_INFO "NFSD Fault Injection: %s (n = %llu)", op->file, val); |
| 53 | |
Bryan Schumaker | 0439583 | 2012-11-29 11:40:38 -0500 | [diff] [blame^] | 54 | nfs4_lock_state(); |
Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 55 | op->func(val); |
Bryan Schumaker | 0439583 | 2012-11-29 11:40:38 -0500 | [diff] [blame^] | 56 | nfs4_unlock_state(); |
Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int nfsd_inject_get(void *data, u64 *val) |
| 61 | { |
Weston Andros Adamson | 5fb35a3 | 2012-05-10 15:31:10 -0400 | [diff] [blame] | 62 | *val = 0; |
Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n"); |
| 67 | |
| 68 | void nfsd_fault_inject_cleanup(void) |
| 69 | { |
| 70 | debugfs_remove_recursive(debug_dir); |
| 71 | } |
| 72 | |
| 73 | int nfsd_fault_inject_init(void) |
| 74 | { |
| 75 | unsigned int i; |
| 76 | struct nfsd_fault_inject_op *op; |
Al Viro | 8818739 | 2012-03-20 06:00:24 -0400 | [diff] [blame] | 77 | umode_t mode = S_IFREG | S_IRUSR | S_IWUSR; |
Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 78 | |
| 79 | debug_dir = debugfs_create_dir("nfsd", NULL); |
| 80 | if (!debug_dir) |
| 81 | goto fail; |
| 82 | |
| 83 | for (i = 0; i < NUM_INJECT_OPS; i++) { |
| 84 | op = &inject_ops[i]; |
| 85 | if (!debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd)) |
| 86 | goto fail; |
| 87 | } |
| 88 | return 0; |
| 89 | |
| 90 | fail: |
| 91 | nfsd_fault_inject_cleanup(); |
| 92 | return -ENOMEM; |
| 93 | } |