From patchwork Wed Jul 30 12:27:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4648041 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 869529F36A for ; Wed, 30 Jul 2014 12:28:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D170200E9 for ; Wed, 30 Jul 2014 12:28:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5650220121 for ; Wed, 30 Jul 2014 12:28:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754727AbaG3M2I (ORCPT ); Wed, 30 Jul 2014 08:28:08 -0400 Received: from mail-qa0-f43.google.com ([209.85.216.43]:51298 "EHLO mail-qa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754671AbaG3M2H (ORCPT ); Wed, 30 Jul 2014 08:28:07 -0400 Received: by mail-qa0-f43.google.com with SMTP id w8so1167521qac.2 for ; Wed, 30 Jul 2014 05:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ZIbN+IrJ+nuSFtHO8wWfunXnpXfN5YoyQVrU19Kszcg=; b=Nmy6O8qjmay1gaVjocYThlb8fyMIVAiXZRcCi+z9t3oXMSWOya4eu4JgpEXk6T7iVh FNL6gbJORekHgvuK1j1SY9di2b6ii5QZzXFyYrGAVqvnIR7aqkzDTAVzHEV6U1MdnhZX eajUXAL4eKcKP3jat3CG99JHiB4htkaE8Epw3D8GKuo6Xw7NWLNuS6Tmw/LbLFpjiuz6 L4wJRno1e+QtD3iQZx+eRVlbrq1FZrE0ZyYlyh/AESZNGO/0GmHXrrU1YxVweGMwwB7a +tqlQDRJOl/wnUYRU1l9fRbFLlnPwNmREgtQH8KRKZSr5PJDlNw9Y63L5dedGRiiF4IN t0dA== X-Gm-Message-State: ALoCoQmPFFwQVWduafPdzjRm9yU30uZK4BkvWtXnMZsNt98eiSjRqiMyUvGnjQWEbH5NgSkYn9I/ X-Received: by 10.224.122.83 with SMTP id k19mr6316662qar.78.1406723286054; Wed, 30 Jul 2014 05:28:06 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id t23sm2384767qge.13.2014.07.30.05.28.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jul 2014 05:28:05 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@infradead.org Subject: [PATCH 15/37] nfsd: abstract out the get and set routines into the fault injection ops Date: Wed, 30 Jul 2014 08:27:16 -0400 Message-Id: <1406723258-8512-16-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406723258-8512-1-git-send-email-jlayton@primarydata.com> References: <1406723258-8512-1-git-send-email-jlayton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we've added more granular locking in other places, it's time to address the fault injection code. This code is currently quite reliant on the client_mutex for protection. Start to change this by adding a new set of fault injection op vectors. For now they all use the legacy ones. In later patches we'll add new routines that can deal with more granular locking. Also, move some of the printk routines into the callers to make the results of the operations more uniform. Signed-off-by: Jeff Layton --- fs/nfsd/fault_inject.c | 129 ++++++++++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c index f1333fc35b33..b1159900d934 100644 --- a/fs/nfsd/fault_inject.c +++ b/fs/nfsd/fault_inject.c @@ -17,79 +17,50 @@ struct nfsd_fault_inject_op { char *file; + u64 (*get)(struct nfsd_fault_inject_op *); + u64 (*set_val)(struct nfsd_fault_inject_op *, u64); + u64 (*set_clnt)(struct nfsd_fault_inject_op *, + struct sockaddr_storage *, size_t); u64 (*forget)(struct nfs4_client *, u64); u64 (*print)(struct nfs4_client *, u64); }; -static struct nfsd_fault_inject_op inject_ops[] = { - { - .file = "forget_clients", - .forget = nfsd_forget_client, - .print = nfsd_print_client, - }, - { - .file = "forget_locks", - .forget = nfsd_forget_client_locks, - .print = nfsd_print_client_locks, - }, - { - .file = "forget_openowners", - .forget = nfsd_forget_client_openowners, - .print = nfsd_print_client_openowners, - }, - { - .file = "forget_delegations", - .forget = nfsd_forget_client_delegations, - .print = nfsd_print_client_delegations, - }, - { - .file = "recall_delegations", - .forget = nfsd_recall_client_delegations, - .print = nfsd_print_client_delegations, - }, -}; - -static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op); static struct dentry *debug_dir; -static void nfsd_inject_set(struct nfsd_fault_inject_op *op, u64 val) +static u64 nfsd_inject_set(struct nfsd_fault_inject_op *op, u64 val) { - u64 count = 0; - - if (val == 0) - printk(KERN_INFO "NFSD Fault Injection: %s (all)", op->file); - else - printk(KERN_INFO "NFSD Fault Injection: %s (n = %llu)", op->file, val); + u64 count; nfs4_lock_state(); count = nfsd_for_n_state(val, op->forget); nfs4_unlock_state(); - printk(KERN_INFO "NFSD: %s: found %llu", op->file, count); + return count; } -static void nfsd_inject_set_client(struct nfsd_fault_inject_op *op, +static u64 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; + u64 count = 0; nfs4_lock_state(); clp = nfsd_find_client(addr, addr_size); - if (clp) { + if (clp) count = op->forget(clp, 0); - rpc_ntop((struct sockaddr *)&clp->cl_addr, buf, sizeof(buf)); - printk(KERN_INFO "NFSD [%s]: Client %s had %llu state object(s)\n", op->file, buf, count); - } nfs4_unlock_state(); + return count; } -static void nfsd_inject_get(struct nfsd_fault_inject_op *op, u64 *val) +static u64 nfsd_inject_get(struct nfsd_fault_inject_op *op) { + u64 count; + nfs4_lock_state(); - *val = nfsd_for_n_state(0, op->print); + count = nfsd_for_n_state(0, op->print); nfs4_unlock_state(); + + return count; } static ssize_t fault_inject_read(struct file *file, char __user *buf, @@ -99,9 +70,10 @@ static ssize_t fault_inject_read(struct file *file, char __user *buf, char read_buf[25]; size_t size; loff_t pos = *ppos; + struct nfsd_fault_inject_op *op = file_inode(file)->i_private; if (!pos) - nfsd_inject_get(file_inode(file)->i_private, &val); + val = op->get(op); size = scnprintf(read_buf, sizeof(read_buf), "%llu\n", val); return simple_read_from_buffer(buf, len, ppos, read_buf, size); @@ -114,6 +86,7 @@ static ssize_t fault_inject_write(struct file *file, const char __user *buf, size_t size = min(sizeof(write_buf) - 1, len); struct net *net = current->nsproxy->net_ns; struct sockaddr_storage sa; + struct nfsd_fault_inject_op *op = file_inode(file)->i_private; u64 val; char *nl; @@ -129,11 +102,20 @@ static ssize_t fault_inject_write(struct file *file, const char __user *buf, } size = rpc_pton(net, write_buf, size, (struct sockaddr *)&sa, sizeof(sa)); - if (size > 0) - nfsd_inject_set_client(file_inode(file)->i_private, &sa, size); - else { + if (size > 0) { + val = op->set_clnt(op, &sa, size); + if (val) + pr_info("NFSD [%s]: Client %s had %llu state object(s)\n", + op->file, write_buf, val); + } else { val = simple_strtoll(write_buf, NULL, 0); - nfsd_inject_set(file_inode(file)->i_private, val); + if (val == 0) + pr_info("NFSD Fault Injection: %s (all)", op->file); + else + pr_info("NFSD Fault Injection: %s (n = %llu)", + op->file, val); + val = op->set_val(op, val); + pr_info("NFSD: %s: found %llu", op->file, val); } return len; /* on success, claim we got the whole input */ } @@ -149,6 +131,51 @@ void nfsd_fault_inject_cleanup(void) debugfs_remove_recursive(debug_dir); } +static struct nfsd_fault_inject_op inject_ops[] = { + { + .file = "forget_clients", + .get = nfsd_inject_get, + .set_val = nfsd_inject_set, + .set_clnt = nfsd_inject_set_client, + .forget = nfsd_forget_client, + .print = nfsd_print_client, + }, + { + .file = "forget_locks", + .get = nfsd_inject_get, + .set_val = nfsd_inject_set, + .set_clnt = nfsd_inject_set_client, + .forget = nfsd_forget_client_locks, + .print = nfsd_print_client_locks, + }, + { + .file = "forget_openowners", + .get = nfsd_inject_get, + .set_val = nfsd_inject_set, + .set_clnt = nfsd_inject_set_client, + .forget = nfsd_forget_client_openowners, + .print = nfsd_print_client_openowners, + }, + { + .file = "forget_delegations", + .get = nfsd_inject_get, + .set_val = nfsd_inject_set, + .set_clnt = nfsd_inject_set_client, + .forget = nfsd_forget_client_delegations, + .print = nfsd_print_client_delegations, + }, + { + .file = "recall_delegations", + .get = nfsd_inject_get, + .set_val = nfsd_inject_set, + .set_clnt = nfsd_inject_set_client, + .forget = nfsd_recall_client_delegations, + .print = nfsd_print_client_delegations, + }, +}; + +#define NUM_INJECT_OPS (sizeof(inject_ops)/sizeof(struct nfsd_fault_inject_op)) + int nfsd_fault_inject_init(void) { unsigned int i;