From patchwork Wed Jul 30 01:34:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4644101 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 13E899F36A for ; Wed, 30 Jul 2014 01:35:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A2142012B for ; Wed, 30 Jul 2014 01:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 539232012D for ; Wed, 30 Jul 2014 01:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754614AbaG3BfH (ORCPT ); Tue, 29 Jul 2014 21:35:07 -0400 Received: from mail-qg0-f52.google.com ([209.85.192.52]:57966 "EHLO mail-qg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751895AbaG3BfF (ORCPT ); Tue, 29 Jul 2014 21:35:05 -0400 Received: by mail-qg0-f52.google.com with SMTP id f51so637541qge.39 for ; Tue, 29 Jul 2014 18:35:04 -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=4mBIrrJ3zH2Sl5AW1gAvr/YtoVNYw49NKO3GCm711+U=; b=nDGZH+/BD1rG54YTmYIh3mZlUmmfi9mX1zkeX4gEHV6VHYfedsO+5r5hvwpF+MlxGe Jt/9iZpliZHhg5ESPZBEU9SIySDggHMhu/fmPfN4Gf7JZ13lF0M85yPEBXaBYBx61RDg E6h1qB/jtHTwCI4gfM/J2+R8+uUrLsw6mOA8xqj9HPHTZzD1l+FwsC2JGAvGgYm1StvB J9/RpZfU4Rk3FML9G2utgbLFCeIkf4fVkKqDFiT9EvpvizPZHQwBSyAaIx/MqGWBzKZ+ gtoag2JNwHTZQxm7ol+DI5WvOBR7by6BH2PEk0S3yUD3NiCvbbdPRZDZuMKO1iH8CNN8 NiXg== X-Gm-Message-State: ALoCoQk/m8kG7TUyfIpdzBhQuMAV6tWYbeffUrFbBx1k0H9ZMjda08ymxyujY1AAQkb1t7yHfiV0 X-Received: by 10.140.42.10 with SMTP id b10mr1194514qga.82.1406684104549; Tue, 29 Jul 2014 18:35:04 -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.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jul 2014 18:35:03 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@infradead.org, Trond Myklebust Subject: [PATCH v3 10/38] nfsd: Add reference counting to lock stateids Date: Tue, 29 Jul 2014 21:34:15 -0400 Message-Id: <1406684083-19736-11-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 From: Trond Myklebust Ensure that nfsd4_lock() references the lock stateid while it is manipulating it. Not currently necessary, but will be once the client_mutex is removed. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4state.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index f4c7bf96c9fd..1ddf4da0023d 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4729,6 +4729,7 @@ init_lock_stateid(struct nfs4_ol_stateid *stp, struct nfs4_lockowner *lo, lockdep_assert_held(&clp->cl_lock); + atomic_inc(&stp->st_stid.sc_count); stp->st_stid.sc_type = NFS4_LOCK_STID; stp->st_stateowner = &lo->lo_owner; get_nfs4_file(fp); @@ -4753,8 +4754,10 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp) lockdep_assert_held(&clp->cl_lock); list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) { - if (lst->st_stid.sc_file == fp) + if (lst->st_stid.sc_file == fp) { + atomic_inc(&lst->st_stid.sc_count); return lst; + } } return NULL; } @@ -4856,7 +4859,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, { struct nfs4_openowner *open_sop = NULL; struct nfs4_lockowner *lock_sop = NULL; - struct nfs4_ol_stateid *lock_stp; + struct nfs4_ol_stateid *lock_stp = NULL; struct nfs4_file *fp; struct file *filp = NULL; struct file_lock *file_lock = NULL; @@ -4910,11 +4913,15 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; status = lookup_or_create_lock_state(cstate, open_stp, lock, &lock_stp, &new_state); - } else + } else { status = nfs4_preprocess_seqid_op(cstate, lock->lk_old_lock_seqid, &lock->lk_old_lock_stateid, NFS4_LOCK_STID, &lock_stp, nn); + /* FIXME: move into nfs4_preprocess_seqid_op */ + if (!status) + atomic_inc(&lock_stp->st_stid.sc_count); + } if (status) goto out; lock_sop = lockowner(lock_stp->st_stateowner); @@ -5007,6 +5014,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, out: if (filp) fput(filp); + if (lock_stp) + nfs4_put_stid(&lock_stp->st_stid); if (status && new_state) release_lock_stateid(lock_stp); nfsd4_bump_seqid(cstate, status);