From patchwork Thu Jun 26 19:21:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4431171 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9135ABEEAA for ; Thu, 26 Jun 2014 19:22:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 98F4C2028D for ; Thu, 26 Jun 2014 19:22:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B68DF201BA for ; Thu, 26 Jun 2014 19:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751891AbaFZTVy (ORCPT ); Thu, 26 Jun 2014 15:21:54 -0400 Received: from mail-qc0-f175.google.com ([209.85.216.175]:46442 "EHLO mail-qc0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbaFZTVx (ORCPT ); Thu, 26 Jun 2014 15:21:53 -0400 Received: by mail-qc0-f175.google.com with SMTP id i8so3533368qcq.6 for ; Thu, 26 Jun 2014 12:21:52 -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=Q5jdGeuhXCmVhNd3laKBxSJ+zh+bWyII5R2Jun9G9EQ=; b=LgnwXlBUGcixYBoN819LsMTWb39Jik7YiD6gn/vQdFMFGGduZ3NXNZRXbRfLrt3Csc pgnWyw0rd0jZvkmbJVa9SvidGc56WE2SXlnFNrnIklhfpZ9Wz81+8mir/AdMdU0abHbF yX/EC0WNLhYgB2l2FDfX9kZ0NRxErMztWdsQ3UPPlk2GASRuGdOoxModwbeHFvMTUv8+ kmyyQVSGnSgLMfSUqB5Wwx8s47t9IV5EGjjtvWPNeO4Cj8+ahKrpEL6E4imFa5TVQQEq IM9L3GrwpjjlUFzsYzv2pAttSlGVffaYE9wbAuXy6kLajQn+6iIhJucGFQblMC2hlDqC TTTw== X-Gm-Message-State: ALoCoQlgeanQn/uIGUAP9Djfg2C8uxKXLqOKypFGdHOjOdFxOJW6Jurvklj9QC2DL7H3uyw3EJ84 X-Received: by 10.140.32.116 with SMTP id g107mr23775100qgg.30.1403810512648; Thu, 26 Jun 2014 12:21:52 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id k76sm4765555qgd.38.2014.06.26.12.21.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 12:21:51 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 100/117] nfsd: add more granular locking to forget_locks fault injector Date: Thu, 26 Jun 2014 15:21:08 -0400 Message-Id: <1403810485-16497-17-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> References: <1403810017-16062-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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 ...instead of relying on the client_mutex. Signed-off-by: Jeff Layton --- fs/nfsd/fault_inject.c | 8 ++- fs/nfsd/nfs4state.c | 136 +++++++++++++++++++++++++++++++++++++++++++++---- fs/nfsd/state.h | 7 ++- 3 files changed, 135 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c index 76ecdff37ea2..a444d821d2a5 100644 --- a/fs/nfsd/fault_inject.c +++ b/fs/nfsd/fault_inject.c @@ -140,11 +140,9 @@ static struct nfsd_fault_inject_op inject_ops[] = { }, { .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, + .get = nfsd_inject_print_locks, + .set_val = nfsd_inject_forget_locks, + .set_clnt = nfsd_inject_forget_client_locks, }, { .file = "forget_openowners", diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index c26ecd4ad3b2..ab5858e272b8 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5690,6 +5690,16 @@ nfs4_check_open_reclaim(clientid_t *clid, } #ifdef CONFIG_NFSD_FAULT_INJECTION +static void +put_client(struct nfs4_client *clp) +{ + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + + spin_lock(&nn->client_lock); + atomic_dec(&clp->cl_refcount); + spin_unlock(&nn->client_lock); +} + u64 nfsd_inject_print_clients(struct nfsd_fault_inject_op *op) { @@ -5777,6 +5787,22 @@ static void nfsd_print_count(struct nfs4_client *clp, unsigned int count, printk(KERN_INFO "NFS Client: %s has %u %s\n", buf, count, type); } +static void +nfsd_inject_add_lock_to_list(struct nfs4_ol_stateid *lst, + struct list_head *collect) +{ + struct nfs4_client *clp = lst->st_stid.sc_client; + struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, + nfsd_net_id); + + if (!collect) + return; + + lockdep_assert_held(&nn->client_lock); + atomic_inc(&clp->cl_refcount); + list_add(&lst->st_locks, collect); +} + static u64 nfsd_foreach_client_lock(struct nfs4_client *clp, u64 max, struct list_head *collect, void (*func)(struct nfs4_ol_stateid *)) @@ -5786,6 +5812,7 @@ static u64 nfsd_foreach_client_lock(struct nfs4_client *clp, u64 max, struct nfs4_ol_stateid *lst, *lst_next; u64 count = 0; + spin_lock(&clp->cl_lock); list_for_each_entry(oop, &clp->cl_openowners, oo_perclient) { list_for_each_entry_safe(stp, st_next, &oop->oo_owner.so_stateids, st_perstateowner) { @@ -5793,31 +5820,122 @@ static u64 nfsd_foreach_client_lock(struct nfs4_client *clp, u64 max, &stp->st_locks, st_locks) { if (func) { func(lst); - if (collect) - list_add(&lst->st_locks, - collect); + nfsd_inject_add_lock_to_list(lst, + collect); } - if (++count == max) - return count; + ++count; + /* + * Despite the fact that these functions deal + * with 64-bit integers for "count", we must + * ensure that it doesn't blow up the + * clp->cl_refcount. Throw a warning if we + * start to approach INT_MAX here. + */ + WARN_ON_ONCE(count == (INT_MAX / 2)); + if (count == max) + goto out; } } } +out: + spin_unlock(&clp->cl_lock); return count; } -u64 nfsd_forget_client_locks(struct nfs4_client *clp, u64 max) +static u64 +nfsd_collect_client_locks(struct nfs4_client *clp, struct list_head *collect, + u64 max) { - return nfsd_foreach_client_lock(clp, max, NULL, release_lock_stateid); + return nfsd_foreach_client_lock(clp, max, collect, unhash_lock_stateid); } -u64 nfsd_print_client_locks(struct nfs4_client *clp, u64 max) +static u64 +nfsd_print_client_locks(struct nfs4_client *clp) { - u64 count = nfsd_foreach_client_lock(clp, max, NULL, NULL); + u64 count = nfsd_foreach_client_lock(clp, 0, NULL, NULL); nfsd_print_count(clp, count, "locked files"); return count; } +u64 +nfsd_inject_print_locks(struct nfsd_fault_inject_op *op) +{ + struct nfs4_client *clp; + u64 count = 0; + struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, + nfsd_net_id); + + if (!nfsd_netns_ready(nn)) + return 0; + + spin_lock(&nn->client_lock); + list_for_each_entry(clp, &nn->client_lru, cl_lru) + count += nfsd_print_client_locks(clp); + spin_unlock(&nn->client_lock); + + return count; +} + +static void +nfsd_reap_locks(struct list_head *reaplist) +{ + struct nfs4_client *clp; + struct nfs4_ol_stateid *stp, *next; + + list_for_each_entry_safe(stp, next, reaplist, st_locks) { + list_del_init(&stp->st_locks); + clp = stp->st_stid.sc_client; + put_generic_stateid(stp); + put_client(clp); + } +} + +u64 +nfsd_inject_forget_client_locks(struct nfsd_fault_inject_op *op, + struct sockaddr_storage *addr, size_t addr_size) +{ + unsigned int count = 0; + struct nfs4_client *clp; + struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, + nfsd_net_id); + LIST_HEAD(reaplist); + + if (!nfsd_netns_ready(nn)) + return count; + + spin_lock(&nn->client_lock); + clp = nfsd_find_client(addr, addr_size); + if (clp) + count = nfsd_collect_client_locks(clp, &reaplist, 0); + spin_unlock(&nn->client_lock); + nfsd_reap_locks(&reaplist); + return count; +} + +u64 +nfsd_inject_forget_locks(struct nfsd_fault_inject_op *op, u64 max) +{ + u64 count = 0; + struct nfs4_client *clp; + struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, + nfsd_net_id); + LIST_HEAD(reaplist); + + if (!nfsd_netns_ready(nn)) + return count; + + spin_lock(&nn->client_lock); + list_for_each_entry(clp, &nn->client_lru, cl_lru) { + count += nfsd_collect_client_locks(clp, &reaplist, max - count); + if (max != 0 && count >= max) + break; + } + spin_unlock(&nn->client_lock); + nfsd_reap_locks(&reaplist); + return count; +} + static u64 nfsd_foreach_client_open(struct nfs4_client *clp, u64 max, void (*func)(struct nfs4_openowner *)) { struct nfs4_openowner *oop, *next; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 4fe973bbb68f..12ffe33662f1 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -478,12 +478,15 @@ u64 nfsd_inject_forget_client(struct nfsd_fault_inject_op *, struct sockaddr_storage *, size_t); u64 nfsd_inject_forget_clients(struct nfsd_fault_inject_op *, u64); -u64 nfsd_forget_client_locks(struct nfs4_client*, u64); +u64 nfsd_inject_print_locks(struct nfsd_fault_inject_op *); +u64 nfsd_inject_forget_client_locks(struct nfsd_fault_inject_op *, + struct sockaddr_storage *, size_t); +u64 nfsd_inject_forget_locks(struct nfsd_fault_inject_op *, u64); + u64 nfsd_forget_client_openowners(struct nfs4_client *, u64); u64 nfsd_forget_client_delegations(struct nfs4_client *, u64); u64 nfsd_recall_client_delegations(struct nfs4_client *, u64); -u64 nfsd_print_client_locks(struct nfs4_client *, u64); u64 nfsd_print_client_openowners(struct nfs4_client *, u64); u64 nfsd_print_client_delegations(struct nfs4_client *, u64); #else /* CONFIG_NFSD_FAULT_INJECTION */