Return-Path: linux-nfs-owner@vger.kernel.org Received: from mail-ig0-f179.google.com ([209.85.213.179]:56020 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754307AbaDRSp6 (ORCPT ); Fri, 18 Apr 2014 14:45:58 -0400 Received: by mail-ig0-f179.google.com with SMTP id hl10so937472igb.12 for ; Fri, 18 Apr 2014 11:45:58 -0700 (PDT) From: Trond Myklebust To: Bruce Fields Cc: linux-nfs@vger.kernel.org Subject: [PATCH 33/70] NFSd: Ensure atomicity of stateid destruction and idr tree removal Date: Fri, 18 Apr 2014 14:44:27 -0400 Message-Id: <1397846704-14567-34-git-send-email-trond.myklebust@primarydata.com> In-Reply-To: <1397846704-14567-33-git-send-email-trond.myklebust@primarydata.com> References: <1397846704-14567-1-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-2-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-3-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-4-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-5-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-6-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-7-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-8-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-9-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-10-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-11-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-12-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-13-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-14-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-15-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-16-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-17-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-18-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-19-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-20-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-21-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-22-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-23-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-24-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-25-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-26-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-27-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-28-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-29-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-30-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-31-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-32-git-send-email-trond.myklebust@primarydata.com> <1397846704-14567-33-git-send-email-trond.myklebust@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org List-ID: Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4state.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 7b897ff03a27..f463aaf9cd13 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -461,31 +461,37 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv return dp; } -static void remove_stid(struct nfs4_stid *s) +static void remove_stid_locked(struct nfs4_client *clp, struct nfs4_stid *s) { - struct nfs4_client *clp = s->sc_client; struct idr *stateids = &clp->cl_stateids; - spin_lock(&clp->cl_lock); idr_remove(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) { - remove_stid(s); if (s->sc_file) put_nfs4_file(s->sc_file); kmem_cache_free(slab, s); } +static bool nfs4_put_stid(struct kmem_cache *slab, struct nfs4_stid *s) +{ + struct nfs4_client *clp = s->sc_client; + + if (!atomic_dec_and_lock(&s->sc_count, &clp->cl_lock)) + return false; + remove_stid_locked(clp, s); + spin_unlock(&clp->cl_lock); + nfs4_free_stid(slab, s); + return true; +} + void nfs4_put_delegation(struct nfs4_delegation *dp) { - if (atomic_dec_and_test(&dp->dl_stid.sc_count)) { - nfs4_free_stid(deleg_slab, &dp->dl_stid); + if (nfs4_put_stid(deleg_slab, &dp->dl_stid)) num_delegations--; - } } /* Call under fp->fi_lock */ @@ -712,9 +718,7 @@ static void close_generic_stateid(struct nfs4_ol_stateid *stp) static void put_generic_stateid(struct nfs4_ol_stateid *stp) { - if (!atomic_dec_and_test(&stp->st_stid.sc_count)) - return; - nfs4_free_stid(stateid_slab, &stp->st_stid); + nfs4_put_stid(stateid_slab, &stp->st_stid); } static void __release_lock_stateid(struct nfs4_lockowner *lo, -- 1.9.0