From patchwork Wed Jul 30 01:34:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4644061 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 4DEDD9F440 for ; Wed, 30 Jul 2014 01:35:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61FFD2012B for ; Wed, 30 Jul 2014 01:35:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FB7B20142 for ; Wed, 30 Jul 2014 01:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752191AbaG3Be6 (ORCPT ); Tue, 29 Jul 2014 21:34:58 -0400 Received: from mail-qg0-f43.google.com ([209.85.192.43]:40532 "EHLO mail-qg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754491AbaG3Be5 (ORCPT ); Tue, 29 Jul 2014 21:34:57 -0400 Received: by mail-qg0-f43.google.com with SMTP id a108so665254qge.16 for ; Tue, 29 Jul 2014 18:34:57 -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=x6E+2jKuUEd8L6RNLgdhJiYlGUlo0YYBLqzT1enWe+w=; b=nIUxe3vdPpBF3qDrDOXbtjgU0A8isk2PeP/osWOj1dMogMLpilAvEZlC5MDHPrbFyJ QH0XXVBWXrLsq5WC8ImvTZu2aZGwap724Dt1cTJ/V9QjLbMIy4rMnr3WvYEfrgy3B3vW ZW03qrgiF2Z+pqnKCl66CPwluhEfkvfLijENwYCHB7Ts6Muav1H89KcGhvcCVM6n2kpz d377K1YaTMN8hxLvm9GHKcRc6yWbOYQ94R+w5L50NEELz4ilvdcQ+A0I/7qAlVxEklak D4zqQvZFdhw9/CkRFLSnCL0PfaWtS6IN6FZ3Z0bJre6P1eYlsWNPuW6vn2wC48xy73lz 6qXA== X-Gm-Message-State: ALoCoQlZPik6px5nVQ3f9lcHZPkuta69ACVQvbEW7/b59iXlXUlCociepwRUTQytklrrQ2Gb9FCl X-Received: by 10.224.16.212 with SMTP id p20mr1247222qaa.1.1406684096999; Tue, 29 Jul 2014 18:34:56 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 81sm860946qgw.21.2014.07.29.18.34.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jul 2014 18:34:55 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@infradead.org Subject: [PATCH v3 05/38] nfsd4: use cl_lock to synchronize all stateid idr calls Date: Tue, 29 Jul 2014 21:34:10 -0400 Message-Id: <1406684083-19736-6-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406684083-19736-1-git-send-email-jlayton@primarydata.com> References: <1406684083-19736-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 Currently, this is serialized by the client_mutex, which is slated for removal. Add finer-grained locking here. Also, do some cleanup around find_stateid to prepare for taking references. Signed-off-by: Trond Myklebust Signed-off-by: Benny Halevy Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/nfsd/nfs4state.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 344cd1ac3f67..bb37cc4dd573 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -467,7 +467,6 @@ static void nfs4_file_put_access(struct nfs4_file *fp, u32 access) static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab) { - struct idr *stateids = &cl->cl_stateids; struct nfs4_stid *stid; int new_id; @@ -475,7 +474,11 @@ static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, if (!stid) return NULL; - new_id = idr_alloc_cyclic(stateids, stid, 0, 0, GFP_KERNEL); + idr_preload(GFP_KERNEL); + spin_lock(&cl->cl_lock); + new_id = idr_alloc_cyclic(&cl->cl_stateids, stid, 0, 0, GFP_NOWAIT); + spin_unlock(&cl->cl_lock); + idr_preload_end(); if (new_id < 0) goto out_free; stid->sc_client = cl; @@ -635,9 +638,12 @@ nfs4_put_stid(struct nfs4_stid *s) struct nfs4_file *fp = s->sc_file; struct nfs4_client *clp = s->sc_client; - if (!atomic_dec_and_test(&s->sc_count)) + might_lock(&clp->cl_lock); + + if (!atomic_dec_and_lock(&s->sc_count, &clp->cl_lock)) return; idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); + spin_unlock(&clp->cl_lock); s->sc_free(s); if (fp) put_nfs4_file(fp); @@ -1652,7 +1658,8 @@ static void gen_confirm(struct nfs4_client *clp) memcpy(clp->cl_confirm.data, verf, sizeof(clp->cl_confirm.data)); } -static struct nfs4_stid *find_stateid(struct nfs4_client *cl, stateid_t *t) +static struct nfs4_stid * +find_stateid_locked(struct nfs4_client *cl, stateid_t *t) { struct nfs4_stid *ret; @@ -1662,16 +1669,28 @@ static struct nfs4_stid *find_stateid(struct nfs4_client *cl, stateid_t *t) return ret; } -static struct nfs4_stid *find_stateid_by_type(struct nfs4_client *cl, stateid_t *t, char typemask) +static struct nfs4_stid * +find_stateid(struct nfs4_client *cl, stateid_t *t) +{ + struct nfs4_stid *ret; + + spin_lock(&cl->cl_lock); + ret = find_stateid_locked(cl, t); + spin_unlock(&cl->cl_lock); + return ret; +} + +static struct nfs4_stid * +find_stateid_by_type(struct nfs4_client *cl, stateid_t *t, char typemask) { struct nfs4_stid *s; - s = find_stateid(cl, t); - if (!s) - return NULL; - if (typemask & s->sc_type) - return s; - return NULL; + spin_lock(&cl->cl_lock); + s = find_stateid_locked(cl, t); + if (s != NULL && !(typemask & s->sc_type)) + s = NULL; + spin_unlock(&cl->cl_lock); + return s; } static struct nfs4_client *create_client(struct xdr_netobj name,