From patchwork Wed Jul 30 01:34:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4644191 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 C3B25C0338 for ; Wed, 30 Jul 2014 01:35:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D92A72012B for ; Wed, 30 Jul 2014 01:35:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1E332012D for ; Wed, 30 Jul 2014 01:35:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754742AbaG3Bf2 (ORCPT ); Tue, 29 Jul 2014 21:35:28 -0400 Received: from mail-qa0-f50.google.com ([209.85.216.50]:63711 "EHLO mail-qa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754741AbaG3Bf0 (ORCPT ); Tue, 29 Jul 2014 21:35:26 -0400 Received: by mail-qa0-f50.google.com with SMTP id s7so579920qap.37 for ; Tue, 29 Jul 2014 18:35:26 -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=FYjciT5x2/8Y9aB+S9S4CyX1Nuz84KXvcCxcB16x74U=; b=T0BS/Tc/71EmxwYYV5LhJT8wOYJ+Dk9H26r4ULLBBHxKBOQpyuDD1JJ2uUSjITmhTM zaOowefkaMDbDqO0KiE39tMdFDME4H/Ly9eFlwl7DkGVsx9jfYNq0+xzaN7xTRe6KkRB CLgpXFNIHW+aqo1Y3J4Emd2QVfBztNzWTnrgxSUmmB5eGYP8q0TWMADT3cl1wTCnG9xM gWRXJOo/K0lAdmUU/iRMofFvqPEkYRt49AzQ/shRASXiN+X2VlfKTYCx1fy3PRCUqFE7 cLQZJh/ObvX1q0cf1X9ZwGupuxINfQWi9MOPVHY7yqu4PMbh20OKqAGWbwksU6JV37IW yh5Q== X-Gm-Message-State: ALoCoQmHx4IUGWNmdvco+RpyHWY4SOzZWZxgN3WGl26uAnTq6CUUlQCo9Zxd9eJKbH9s5DsR9jaI X-Received: by 10.224.123.80 with SMTP id o16mr1167752qar.21.1406684126145; Tue, 29 Jul 2014 18:35:26 -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.35.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jul 2014 18:35:25 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@infradead.org Subject: [PATCH v3 24/38] nfsd: add an operation for unhashing a stateowner Date: Tue, 29 Jul 2014 21:34:29 -0400 Message-Id: <1406684083-19736-25-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 Allow stateowners to be unhashed and destroyed when the last reference is put. The unhashing must be idempotent. In a future patch, we'll add some locking around it, but for now it's only protected by the client_mutex. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 49 +++++++++++++++++++++++++++++++++++++------------ fs/nfsd/state.h | 1 + 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index eaa5f9ebf444..906c8604de30 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -894,6 +894,7 @@ static void nfs4_put_stateowner(struct nfs4_stateowner *sop) { if (!atomic_dec_and_test(&sop->so_count)) return; + sop->so_ops->so_unhash(sop); kfree(sop->so_owner.data); sop->so_ops->so_free(sop); } @@ -944,9 +945,13 @@ static void __release_lock_stateid(struct nfs4_ol_stateid *stp) static void unhash_lockowner(struct nfs4_lockowner *lo) { + list_del_init(&lo->lo_owner.so_strhash); +} + +static void release_lockowner_stateids(struct nfs4_lockowner *lo) +{ struct nfs4_ol_stateid *stp; - list_del(&lo->lo_owner.so_strhash); while (!list_empty(&lo->lo_owner.so_stateids)) { stp = list_first_entry(&lo->lo_owner.so_stateids, struct nfs4_ol_stateid, st_perstateowner); @@ -957,6 +962,7 @@ static void unhash_lockowner(struct nfs4_lockowner *lo) static void release_lockowner(struct nfs4_lockowner *lo) { unhash_lockowner(lo); + release_lockowner_stateids(lo); nfs4_put_stateowner(&lo->lo_owner); } @@ -1006,15 +1012,8 @@ static void release_open_stateid(struct nfs4_ol_stateid *stp) static void unhash_openowner(struct nfs4_openowner *oo) { - struct nfs4_ol_stateid *stp; - - list_del(&oo->oo_owner.so_strhash); - list_del(&oo->oo_perclient); - while (!list_empty(&oo->oo_owner.so_stateids)) { - stp = list_first_entry(&oo->oo_owner.so_stateids, - struct nfs4_ol_stateid, st_perstateowner); - release_open_stateid(stp); - } + list_del_init(&oo->oo_owner.so_strhash); + list_del_init(&oo->oo_perclient); } static void release_last_closed_stateid(struct nfs4_openowner *oo) @@ -1027,9 +1026,21 @@ static void release_last_closed_stateid(struct nfs4_openowner *oo) } } +static void release_openowner_stateids(struct nfs4_openowner *oo) +{ + struct nfs4_ol_stateid *stp; + + while (!list_empty(&oo->oo_owner.so_stateids)) { + stp = list_first_entry(&oo->oo_owner.so_stateids, + struct nfs4_ol_stateid, st_perstateowner); + release_open_stateid(stp); + } +} + static void release_openowner(struct nfs4_openowner *oo) { unhash_openowner(oo); + release_openowner_stateids(oo); list_del(&oo->oo_close_lru); release_last_closed_stateid(oo); nfs4_put_stateowner(&oo->oo_owner); @@ -2994,6 +3005,13 @@ static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, u list_add(&oo->oo_perclient, &clp->cl_openowners); } +static void nfs4_unhash_openowner(struct nfs4_stateowner *so) +{ + struct nfs4_openowner *oo = openowner(so); + + unhash_openowner(oo); +} + static void nfs4_free_openowner(struct nfs4_stateowner *so) { struct nfs4_openowner *oo = openowner(so); @@ -3002,7 +3020,8 @@ static void nfs4_free_openowner(struct nfs4_stateowner *so) } static const struct nfs4_stateowner_operations openowner_ops = { - .so_free = nfs4_free_openowner, + .so_unhash = nfs4_unhash_openowner, + .so_free = nfs4_free_openowner, }; static struct nfs4_openowner * @@ -4760,6 +4779,11 @@ find_lockowner_str(clientid_t *clid, struct xdr_netobj *owner, return NULL; } +static void nfs4_unhash_lockowner(struct nfs4_stateowner *sop) +{ + unhash_lockowner(lockowner(sop)); +} + static void nfs4_free_lockowner(struct nfs4_stateowner *sop) { struct nfs4_lockowner *lo = lockowner(sop); @@ -4768,7 +4792,8 @@ static void nfs4_free_lockowner(struct nfs4_stateowner *sop) } static const struct nfs4_stateowner_operations lockowner_ops = { - .so_free = nfs4_free_lockowner, + .so_unhash = nfs4_unhash_lockowner, + .so_free = nfs4_free_lockowner, }; /* diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 9cba295812f6..232246039db0 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -335,6 +335,7 @@ struct nfs4_replay { struct nfs4_stateowner; struct nfs4_stateowner_operations { + void (*so_unhash)(struct nfs4_stateowner *); void (*so_free)(struct nfs4_stateowner *); };