From patchwork Thu Jun 19 14:49:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4383811 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 AAB99BEEAA for ; Thu, 19 Jun 2014 14:51:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B9DC120384 for ; Thu, 19 Jun 2014 14:51:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEE4320394 for ; Thu, 19 Jun 2014 14:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757998AbaFSOvh (ORCPT ); Thu, 19 Jun 2014 10:51:37 -0400 Received: from mail-qc0-f170.google.com ([209.85.216.170]:64670 "EHLO mail-qc0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757959AbaFSOvh (ORCPT ); Thu, 19 Jun 2014 10:51:37 -0400 Received: by mail-qc0-f170.google.com with SMTP id l6so2323785qcy.1 for ; Thu, 19 Jun 2014 07:51:36 -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=xeajk3PLBcW9CuQWu6TjHL9aXdl7+1TWNqN6Y1to9+o=; b=ky2bHPumTqJTVH5dhKm002TQButZowA4uSpdHwIym7OvdhMctRS18y4agXuMXGdVEt yafu1lrLmdWN0tiYDpq+y8ZnnAQAXrSbrAI0wqTq9CyCCcymNa1x52swv47KaTA4qK5k DGEja8vWqY8T3hajAFhpuLgQysMMxHGBOeDZ78p+0qJ9wx988kHCm3EEttFJ4IC6ZtCy AOk5I7ShHdYf+KnEGzgr3jWui4mbjtp280HrFa7HCfTqg8cs6HL27ieRa0DO3EU0eX1o EgTIL1xTI5hSTUF1qLLCpw/015S0iuO0wPVLIUF408XEhEtVhzthx/TgUZwuNgstiTBQ C15Q== X-Gm-Message-State: ALoCoQl62U4d1wtP1+CCt3BVrs6vOKJSib7Ll10FKJKBfxAGvST0DDJGW4yoiw/s+Q2eIpL68f+p X-Received: by 10.224.68.2 with SMTP id t2mr7607967qai.71.1403189496437; Thu, 19 Jun 2014 07:51:36 -0700 (PDT) Received: from tlielax.poochiereds.net (cpe-107-015-124-230.nc.res.rr.com. [107.15.124.230]) by mx.google.com with ESMTPSA id r60sm3364044qgd.26.2014.06.19.07.51.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jun 2014 07:51:35 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 027/104] NFSd: Cleanup the freeing of stateids Date: Thu, 19 Jun 2014 10:49:33 -0400 Message-Id: <1403189450-18729-28-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1403189450-18729-1-git-send-email-jlayton@primarydata.com> References: <1403189450-18729-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 Add a ->free() callback to the struct nfs4_stid, so that we can release a reference to the stid without caring about the contents. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4state.c | 62 +++++++++++++++++++++++++++++++++++------------------ fs/nfsd/state.h | 2 ++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 827e749e258e..b0e22d1ea6df 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -70,6 +70,7 @@ static u64 current_sessionid = 1; /* forward declarations */ static int check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner); +static void nfs4_free_generic_stateid(struct nfs4_stid *stid); /* Locking: */ @@ -441,8 +442,15 @@ static void nfs4_file_put_access(struct nfs4_file *fp, u32 access, u32 deny) __nfs4_file_put_access(fp, oflag); } -static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct -kmem_cache *slab) +static void nfs4_free_stid(struct kmem_cache *slab, struct nfs4_stid *s) +{ + if (s->sc_file) + put_nfs4_file(s->sc_file); + kmem_cache_free(slab, s); +} + +static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, + struct kmem_cache *slab) { struct nfs4_stid *stid; int new_id; @@ -481,7 +489,22 @@ out_free: static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp) { - return openlockstateid(nfs4_alloc_stid(clp, stateid_slab)); + struct nfs4_stid *stid; + struct nfs4_ol_stateid *stp; + + stid = nfs4_alloc_stid(clp, stateid_slab); + if (!stid) + return NULL; + + stp = openlockstateid(stid); + stp->st_stid.sc_free = nfs4_free_generic_stateid; + return stp; +} + +static void nfs4_free_deleg(struct nfs4_stid *stid) +{ + nfs4_free_stid(deleg_slab, stid); + num_delegations--; } static struct nfs4_delegation * @@ -495,6 +518,8 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv dp = delegstateid(nfs4_alloc_stid(clp, deleg_slab)); if (dp == NULL) return dp; + + dp->dl_stid.sc_free = nfs4_free_deleg; /* * delegation seqid's are never incremented. The 4.1 special * meaning of seqid 0 isn't meaningful, really, but let's avoid @@ -518,30 +543,21 @@ static void remove_stid_locked(struct nfs4_client *clp, struct nfs4_stid *s) idr_remove(&clp->cl_stateids, s->sc_stateid.si_opaque.so_id); } -static void nfs4_free_stid(struct kmem_cache *slab, struct nfs4_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) +static void nfs4_put_stid(struct nfs4_stid *s) { struct nfs4_client *clp = s->sc_client; if (!atomic_dec_and_lock(&s->sc_count, &clp->cl_lock)) - return false; + return; remove_stid_locked(clp, s); spin_unlock(&clp->cl_lock); - nfs4_free_stid(slab, s); - return true; + s->sc_free(s); } void nfs4_put_delegation(struct nfs4_delegation *dp) { - if (nfs4_put_stid(deleg_slab, &dp->dl_stid)) - num_delegations--; + nfs4_put_stid(&dp->dl_stid); } static void nfs4_put_deleg_lease(struct nfs4_file *fp) @@ -753,14 +769,17 @@ static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) list_del(&stp->st_perstateowner); } -static void close_generic_stateid(struct nfs4_ol_stateid *stp) +static void nfs4_free_generic_stateid(struct nfs4_stid *stid) { + struct nfs4_ol_stateid *stp = openlockstateid(stid); + release_all_access(stp); + nfs4_free_stid(stateid_slab, stid); } static void put_generic_stateid(struct nfs4_ol_stateid *stp) { - nfs4_put_stid(stateid_slab, &stp->st_stid); + nfs4_put_stid(&stp->st_stid); } static void __release_lock_stateid(struct nfs4_lockowner *lo, @@ -774,7 +793,6 @@ static void __release_lock_stateid(struct nfs4_lockowner *lo, file = find_any_file(stp->st_stid.sc_file); if (file) filp_close(file, (fl_owner_t)lo); - close_generic_stateid(stp); put_generic_stateid(stp); } @@ -832,7 +850,6 @@ static void unhash_open_stateid(struct nfs4_ol_stateid *stp) { unhash_generic_stateid(stp); release_open_stateid_locks(stp); - close_generic_stateid(stp); } static void release_open_stateid(struct nfs4_ol_stateid *stp) @@ -4322,8 +4339,11 @@ static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s) oo->oo_last_closed_stid = s; /* * In the 4.0 case we need to keep the owners around a - * little while to handle CLOSE replay. + * little while to handle CLOSE replay. We still do need + * to release any file access that is held by them + * before returning however. */ + release_all_access(s); if (list_empty(&oo->oo_owner.so_stateids)) move_to_close_lru(oo, clp->net); } diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 78ed70bd666d..f5dee9e8550a 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -86,6 +86,8 @@ struct nfs4_stid { stateid_t sc_stateid; struct nfs4_client *sc_client; struct nfs4_file *sc_file; + + void (*sc_free)(struct nfs4_stid *); }; struct nfs4_delegation {