blob: bf6161adf6632a63d6ab6d3e4102c548fe048f68 [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;
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050016 u64 (*forget)(struct nfs4_client *, u64);
Bryan Schumaker65178db2011-11-01 13:35:21 -040017};
18
19static struct nfsd_fault_inject_op inject_ops[] = {
20 {
21 .file = "forget_clients",
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050022 .forget = nfsd_forget_client,
Bryan Schumaker65178db2011-11-01 13:35:21 -040023 },
24 {
25 .file = "forget_locks",
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050026 .forget = nfsd_forget_client_locks,
Bryan Schumaker65178db2011-11-01 13:35:21 -040027 },
28 {
29 .file = "forget_openowners",
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050030 .forget = nfsd_forget_client_openowners,
Bryan Schumaker65178db2011-11-01 13:35:21 -040031 },
32 {
33 .file = "forget_delegations",
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050034 .forget = nfsd_forget_client_delegations,
Bryan Schumaker65178db2011-11-01 13:35:21 -040035 },
36 {
37 .file = "recall_delegations",
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050038 .forget = nfsd_recall_client_delegations,
Bryan Schumaker65178db2011-11-01 13:35:21 -040039 },
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{
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050047 u64 count = 0;
Bryan Schumaker65178db2011-11-01 13:35:21 -040048 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
Bryan Schumaker04395832012-11-29 11:40:38 -050055 nfs4_lock_state();
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050056 count = nfsd_for_n_state(val, op->forget);
Bryan Schumaker04395832012-11-29 11:40:38 -050057 nfs4_unlock_state();
Bryan Schumaker8ce54e02012-11-29 11:40:43 -050058 printk(KERN_INFO "NFSD: %s: found %llu", op->file, count);
Bryan Schumaker65178db2011-11-01 13:35:21 -040059 return 0;
60}
61
62static int nfsd_inject_get(void *data, u64 *val)
63{
Weston Andros Adamson5fb35a32012-05-10 15:31:10 -040064 *val = 0;
Bryan Schumaker65178db2011-11-01 13:35:21 -040065 return 0;
66}
67
68DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n");
69
70void nfsd_fault_inject_cleanup(void)
71{
72 debugfs_remove_recursive(debug_dir);
73}
74
75int nfsd_fault_inject_init(void)
76{
77 unsigned int i;
78 struct nfsd_fault_inject_op *op;
Al Viro88187392012-03-20 06:00:24 -040079 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
Bryan Schumaker65178db2011-11-01 13:35:21 -040080
81 debug_dir = debugfs_create_dir("nfsd", NULL);
82 if (!debug_dir)
83 goto fail;
84
85 for (i = 0; i < NUM_INJECT_OPS; i++) {
86 op = &inject_ops[i];
87 if (!debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd))
88 goto fail;
89 }
90 return 0;
91
92fail:
93 nfsd_fault_inject_cleanup();
94 return -ENOMEM;
95}