blob: 02781121c6b019f0516be7e1fa84f996a4c4df5d [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
54 op->func(val);
55 return 0;
56}
57
58static int nfsd_inject_get(void *data, u64 *val)
59{
Weston Andros Adamson5fb35a32012-05-10 15:31:10 -040060 *val = 0;
Bryan Schumaker65178db2011-11-01 13:35:21 -040061 return 0;
62}
63
64DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n");
65
66void nfsd_fault_inject_cleanup(void)
67{
68 debugfs_remove_recursive(debug_dir);
69}
70
71int nfsd_fault_inject_init(void)
72{
73 unsigned int i;
74 struct nfsd_fault_inject_op *op;
Al Viro88187392012-03-20 06:00:24 -040075 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
Bryan Schumaker65178db2011-11-01 13:35:21 -040076
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
88fail:
89 nfsd_fault_inject_cleanup();
90 return -ENOMEM;
91}