From 6c1e82a4b74ad0c8b45c833a4409f153199d9be4 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Thu, 29 Nov 2012 11:40:46 -0500 Subject: NFSD: Forget state for a specific client Write the client's ip address to any state file and all appropriate state for that client will be forgotten. Signed-off-by: Bryan Schumaker Signed-off-by: J. Bruce Fields --- fs/nfsd/fault_inject.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'fs/nfsd/fault_inject.c') diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c index 19f9094bbb0..96ffdf55dce 100644 --- a/fs/nfsd/fault_inject.c +++ b/fs/nfsd/fault_inject.c @@ -8,9 +8,12 @@ #include #include #include +#include +#include #include #include "state.h" +#include "netns.h" struct nfsd_fault_inject_op { char *file; @@ -64,6 +67,24 @@ static void nfsd_inject_set(struct nfsd_fault_inject_op *op, u64 val) printk(KERN_INFO "NFSD: %s: found %llu", op->file, count); } +static void nfsd_inject_set_client(struct nfsd_fault_inject_op *op, + struct sockaddr_storage *addr, + size_t addr_size) +{ + char buf[INET6_ADDRSTRLEN]; + struct nfs4_client *clp; + u64 count; + + nfs4_lock_state(); + clp = nfsd_find_client(addr, addr_size); + if (clp) { + count = op->forget(clp, 0); + rpc_ntop((struct sockaddr *)&clp->cl_addr, buf, 129); + printk(KERN_INFO "NFSD [%s]: Client %s had %llu state object(s)\n", op->file, buf, count); + } + nfs4_unlock_state(); +} + static void nfsd_inject_get(struct nfsd_fault_inject_op *op, u64 *val) { nfs4_lock_state(); @@ -100,15 +121,23 @@ static ssize_t fault_inject_read(struct file *file, char __user *buf, static ssize_t fault_inject_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos) { - char write_buf[24]; + char write_buf[INET6_ADDRSTRLEN]; size_t size = min(sizeof(write_buf), len) - 1; + struct net *net = current->nsproxy->net_ns; + struct sockaddr_storage sa; 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); + write_buf[size] = '\0'; + + size = rpc_pton(net, write_buf, size, (struct sockaddr *)&sa, sizeof(sa)); + if (size > 0) + nfsd_inject_set_client(file->f_dentry->d_inode->i_private, &sa, size); + else { + 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 */ } -- cgit v1.2.3-70-g09d2