blob: 4b385a14cf96582a60e4aa3b8509a0e03cee2588 [file] [log] [blame]
Bryan Schumaker65178db2011-11-01 13:35:21 -04001/*
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 Schumaker65178db2011-11-01 13:35:21 -040013
14struct nfsd_fault_inject_op {
15 char *file;
16 void (*func)(u64);
17};
18
19static 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
42static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op);
43static struct dentry *debug_dir;
44
45static 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 Schumaker04395832012-11-29 11:40:38 -050054 nfs4_lock_state();
Bryan Schumaker65178db2011-11-01 13:35:21 -040055 op->func(val);
Bryan Schumaker04395832012-11-29 11:40:38 -050056 nfs4_unlock_state();
Bryan Schumaker65178db2011-11-01 13:35:21 -040057 return 0;
58}
59
60static int nfsd_inject_get(void *data, u64 *val)
61{
Weston Andros Adamson5fb35a32012-05-10 15:31:10 -040062 *val = 0;
Bryan Schumaker65178db2011-11-01 13:35:21 -040063 return 0;
64}
65
66DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n");
67
68void nfsd_fault_inject_cleanup(void)
69{
70 debugfs_remove_recursive(debug_dir);
71}
72
73int nfsd_fault_inject_init(void)
74{
75 unsigned int i;
76 struct nfsd_fault_inject_op *op;
Al Viro88187392012-03-20 06:00:24 -040077 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
Bryan Schumaker65178db2011-11-01 13:35:21 -040078
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
90fail:
91 nfsd_fault_inject_cleanup();
92 return -ENOMEM;
93}