From patchwork Thu Jun 19 14:49:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4384061 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 66738BEECB for ; Thu, 19 Jun 2014 14:52:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B22920384 for ; Thu, 19 Jun 2014 14:52:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9AE402038F for ; Thu, 19 Jun 2014 14:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758054AbaFSOwN (ORCPT ); Thu, 19 Jun 2014 10:52:13 -0400 Received: from mail-qc0-f169.google.com ([209.85.216.169]:52983 "EHLO mail-qc0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758064AbaFSOwM (ORCPT ); Thu, 19 Jun 2014 10:52:12 -0400 Received: by mail-qc0-f169.google.com with SMTP id c9so2286804qcz.28 for ; Thu, 19 Jun 2014 07:52:12 -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=m5m6FGVPR+tkTEC6cf/nspal7mrd54NN64AxvmpTzz8=; b=m8J2ns/3313TtJLz/3OTzLl7ZXC4tMWNx31JPk6W8fkzOYMPJBVIE/DDJHsv5ol9Qo JhOP5hV+AF6rHDrSl4+ZsmFNDgqFADaC1pmKaVN4qm7Cqb2OSdiEXWwtWJd0JxDYf9Cx F/IpxMrm2SKisOYjbS7yfljAMDXE59eEbz9XJ30zSsEihH/zmSG3FDxOWYnn3pY94Ns4 e+p8G0ziFckc8nIeveKaMB9GFp0L2v058oFSMvqMUxA1MaIdChWEQFy2U1Rq45Pms4J7 GHLbxF53mNa7xd4+417YxUiKAvAQZzQ0WKP5kygHUbEcOK99Y7xe6jnmrU2B0WdzNeJG d38Q== X-Gm-Message-State: ALoCoQlfUXND4z9AwY4QZ00nVn+RVsPPOX9iLAk35S1HwbVH0jg9NNHYz80ZE4MUdfqAtHrrHJQs X-Received: by 10.224.114.17 with SMTP id c17mr8117406qaq.68.1403189531950; Thu, 19 Jun 2014 07:52:11 -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.52.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jun 2014 07:52:11 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 051/104] nfsd: clean up refcounting for lockowners Date: Thu, 19 Jun 2014 10:49:57 -0400 Message-Id: <1403189450-18729-52-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 Ensure that lockowner references are only held by lockstateids and operations that are in-progress. With this, we can get rid of release_lockowner_if_empty, which will be racy once we remove client_mutex protection. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 17a1136ad0a1..a80ba729e8b3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -804,8 +804,7 @@ static void put_generic_stateid(struct nfs4_ol_stateid *stp) nfs4_put_stid(&stp->st_stid); } -static void __release_lock_stateid(struct nfs4_lockowner *lo, - struct nfs4_ol_stateid *stp) +static void release_lock_stateid(struct nfs4_ol_stateid *stp) { struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner); @@ -829,32 +828,17 @@ static void release_lockowner_stateids(struct nfs4_lockowner *lo) while (!list_empty(&lo->lo_owner.so_stateids)) { stp = list_first_entry(&lo->lo_owner.so_stateids, struct nfs4_ol_stateid, st_perstateowner); - __release_lock_stateid(lo, stp); + release_lock_stateid(stp); } } -static void release_lockowner(struct nfs4_lockowner *lo) +static void destroy_lockowner(struct nfs4_lockowner *lo) { unhash_lockowner(lo); release_lockowner_stateids(lo); nfs4_put_stateowner(&lo->lo_owner); } -static void release_lockowner_if_empty(struct nfs4_lockowner *lo) -{ - if (list_empty(&lo->lo_owner.so_stateids)) - release_lockowner(lo); -} - -static void release_lock_stateid(struct nfs4_ol_stateid *stp) -{ - struct nfs4_lockowner *lo; - - lo = lockowner(stp->st_stateowner); - __release_lock_stateid(lo, stp); - release_lockowner_if_empty(lo); -} - static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp) __releases(&open_stp->st_stateowner->so_client->cl_lock) __acquires(&open_stp->st_stateowner->so_client->cl_lock) @@ -4144,7 +4128,7 @@ nfsd4_free_lock_stateid(struct nfs4_ol_stateid *stp) if (check_for_locks(stp->st_stid.sc_file, lo)) return nfserr_locks_held; - release_lockowner_if_empty(lo); + release_lock_stateid(stp); return nfs_ok; } @@ -4789,8 +4773,6 @@ static __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, lo = alloc_init_lock_stateowner(strhashval, cl, ost, lock); if (lo == NULL) return nfserr_jukebox; - /* FIXME: extra reference for new lockowners for the client */ - atomic_inc(&lo->lo_owner.so_count); } else { /* with an existing lockowner, seqids must be the same */ status = nfserr_bad_seqid; @@ -4801,7 +4783,6 @@ static __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, *lst = find_or_create_lock_stateid(lo, fi, ost, new); if (*lst == NULL) { - release_lockowner_if_empty(lo); status = nfserr_jukebox; goto out; } @@ -5231,13 +5212,14 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, lo = lockowner(sop); /* see if there are still any locks associated with it */ list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { - if (check_for_locks(stp->st_stid.sc_file, lo)) + if (check_for_locks(stp->st_stid.sc_file, lo)) { + nfs4_put_stateowner(sop); goto out; + } } status = nfs_ok; - release_lockowner(lo); - nfs4_put_stateowner(sop); + destroy_lockowner(lo); out: nfs4_unlock_state(); return status;