From d7794a2017622e2c056b95825f787f555722572d Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 29 Nov 2012 11:40:45 -0500 Subject: [PATCH] --- yaml --- r: 347699 b: refs/heads/master c: d7cc431edd0a6c69a88b5ff1e304af50bfb2270e h: refs/heads/master i: 347697: 17fb9b780d016eee2a0c59fe6659318ed07d9dc5 347695: 9f7d58ff671be1b1291e3880f3750cf2c9c5fcee v: v3 --- [refs] | 2 +- trunk/fs/nfsd/fault_inject.c | 56 +++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/[refs] b/[refs] index 9476efaac4fc..002b3487871a 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 184c18471f7d0963ad5752692c4b441a546d88f1 +refs/heads/master: d7cc431edd0a6c69a88b5ff1e304af50bfb2270e diff --git a/trunk/fs/nfsd/fault_inject.c b/trunk/fs/nfsd/fault_inject.c index 545f8e4ed101..19f9094bbb07 100644 --- a/trunk/fs/nfsd/fault_inject.c +++ b/trunk/fs/nfsd/fault_inject.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "state.h" @@ -48,10 +49,9 @@ static struct nfsd_fault_inject_op inject_ops[] = { static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op); static struct dentry *debug_dir; -static int nfsd_inject_set(void *op_ptr, u64 val) +static void nfsd_inject_set(struct nfsd_fault_inject_op *op, u64 val) { u64 count = 0; - struct nfsd_fault_inject_op *op = op_ptr; if (val == 0) printk(KERN_INFO "NFSD Fault Injection: %s (all)", op->file); @@ -62,19 +62,61 @@ static int nfsd_inject_set(void *op_ptr, u64 val) count = nfsd_for_n_state(val, op->forget); nfs4_unlock_state(); printk(KERN_INFO "NFSD: %s: found %llu", op->file, count); - return 0; } -static int nfsd_inject_get(void *op_ptr, u64 *val) +static void nfsd_inject_get(struct nfsd_fault_inject_op *op, u64 *val) { - struct nfsd_fault_inject_op *op = op_ptr; nfs4_lock_state(); *val = nfsd_for_n_state(0, op->print); nfs4_unlock_state(); - return 0; } -DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n"); +static ssize_t fault_inject_read(struct file *file, char __user *buf, + size_t len, loff_t *ppos) +{ + static u64 val; + char read_buf[25]; + size_t size, ret; + loff_t pos = *ppos; + + if (!pos) + nfsd_inject_get(file->f_dentry->d_inode->i_private, &val); + size = scnprintf(read_buf, sizeof(read_buf), "%llu\n", val); + + if (pos < 0) + return -EINVAL; + if (pos >= size || !len) + return 0; + if (len > size - pos) + len = size - pos; + ret = copy_to_user(buf, read_buf + pos, len); + if (ret == len) + return -EFAULT; + len -= ret; + *ppos = pos + len; + return len; +} + +static ssize_t fault_inject_write(struct file *file, const char __user *buf, + size_t len, loff_t *ppos) +{ + char write_buf[24]; + size_t size = min(sizeof(write_buf), len) - 1; + u64 val; + + if (copy_from_user(write_buf, buf, size)) + return -EFAULT; + + val = simple_strtoll(write_buf, NULL, 0); + nfsd_inject_set(file->f_dentry->d_inode->i_private, val); + return len; /* on success, claim we got the whole input */ +} + +static const struct file_operations fops_nfsd = { + .owner = THIS_MODULE, + .read = fault_inject_read, + .write = fault_inject_write, +}; void nfsd_fault_inject_cleanup(void) {