From patchwork Thu Jun 26 19:12:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4430391 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 45112BEEAA for ; Thu, 26 Jun 2014 19:14:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 69FFB202D1 for ; Thu, 26 Jun 2014 19:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 90841202AE for ; Thu, 26 Jun 2014 19:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751744AbaFZTOZ (ORCPT ); Thu, 26 Jun 2014 15:14:25 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:49986 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751741AbaFZTOY (ORCPT ); Thu, 26 Jun 2014 15:14:24 -0400 Received: by mail-qg0-f42.google.com with SMTP id e89so3547758qgf.1 for ; Thu, 26 Jun 2014 12:14:23 -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=djPwJQYSpjjUGZpG0+F8EgSqFKDaRFuKKx40A3l29wA=; b=laETfTJQZAkBYvbUbEtVoxBhE6LUZYf+Rz7VdPDcS/ByrSJxg23XVWosVvWZwZtY/e gH6PXFdah8HsMg4JBhNZDPDqkwmbNQSIiXquBw5qVHwceMqVS1PQ6T/LypDvKeiQ91wi g7AOQhBPdiIAy3RTQnWGUS6UAYRRLicnZXQrfxz6BoWnjCJeuC3hiGdf6KKtpqDdWL/b rBSyNPVHYVxUC2gD/mz35MggFA8lh4LBbMgrqdSdDOfexVXNCnJBS2pL2JGs5F2IV3ST AVv8XByRMdfqO1PVXfGdXQEifHP7rTrXPvieFelIHZxHk1jO/sM4E5rHKhLlfCtt4IQa fokA== X-Gm-Message-State: ALoCoQn/QMUXAWmJuNaT/Mh3IpMHKbgguaTFiErwLQodZAGxGvSinUptBygMS7xWRcb/SFfC45bt X-Received: by 10.140.32.116 with SMTP id g107mr23707184qgg.30.1403810063540; Thu, 26 Jun 2014 12:14:23 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 88sm4763039qgh.5.2014.06.26.12.14.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 12:14:22 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, Benny Halevy Subject: [PATCH v2 027/117] nfsd4: use cl_lock to synchronize all stateid idr calls Date: Thu, 26 Jun 2014 15:12:07 -0400 Message-Id: <1403810017-16062-28-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 From: Benny Halevy Currently, this is serialized by the client_mutex, which is slated for removal. Add finer-grained locking here. Signed-off-by: Benny Halevy --- fs/nfsd/nfs4state.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 4cb64d12c9bf..a2b4f2cbab42 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -346,7 +346,6 @@ static void nfs4_file_put_access(struct nfs4_file *fp, int oflag) 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; @@ -354,7 +353,11 @@ kmem_cache *slab) 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; @@ -490,9 +493,11 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv static void remove_stid(struct nfs4_stid *s) { - struct idr *stateids = &s->sc_client->cl_stateids; + struct nfs4_client *clp = s->sc_client; - idr_remove(stateids, s->sc_stateid.si_opaque.so_id); + spin_lock(&clp->cl_lock); + idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); + spin_unlock(&clp->cl_lock); } static void nfs4_free_stid(struct kmem_cache *slab, struct nfs4_stid *s) @@ -1266,7 +1271,9 @@ free_client(struct nfs4_client *clp) rpc_destroy_wait_queue(&clp->cl_cb_waitq); free_svc_cred(&clp->cl_cred); kfree(clp->cl_name.data); + spin_lock(&clp->cl_lock); idr_destroy(&clp->cl_stateids); + spin_unlock(&clp->cl_lock); kfree(clp); } @@ -1489,7 +1496,9 @@ static struct nfs4_stid *find_stateid(struct nfs4_client *cl, stateid_t *t) { struct nfs4_stid *ret; + spin_lock(&cl->cl_lock); ret = idr_find(&cl->cl_stateids, t->si_opaque.so_id); + spin_unlock(&cl->cl_lock); if (!ret || !ret->sc_type) return NULL; return ret;