From patchwork Tue Jul 29 20:34:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4642571 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 EDE91C0338 for ; Tue, 29 Jul 2014 20:35:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01D7020142 for ; Tue, 29 Jul 2014 20:35:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 099FA20145 for ; Tue, 29 Jul 2014 20:35:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754409AbaG2UfH (ORCPT ); Tue, 29 Jul 2014 16:35:07 -0400 Received: from mail-qg0-f45.google.com ([209.85.192.45]:48239 "EHLO mail-qg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754408AbaG2UfE (ORCPT ); Tue, 29 Jul 2014 16:35:04 -0400 Received: by mail-qg0-f45.google.com with SMTP id f51so294006qge.18 for ; Tue, 29 Jul 2014 13:35:03 -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=/p5s2Ap0mEoz4XxtoZ/64qmYoo+Ft3Pf3KXVhI8uGP0=; b=b/glUzEvRvKDalrXNMWl/Q17JqvGyKphrBtTKGwryYM++LsCS5nCh9fwQZzCOkvf7t ag2CDcSToSl4I2HUtAnLE4I8iNuDJ1pqWihioEUhhhDiyvBA+WVkxoEkUsGLw6u7BhIK DkSy9+2/Sxy4Q6aO/G7W/1CaRVCOA3lJ+dnFO2GgRSfMZOkviqetk/k0XF0mTbUnao74 tQRMfKgo0vr1SbLCWdDJnJ8i2AzyYNJpH2s+b0vAnVA1cHUfk1OTYX45qRPTEZJlqbmV ovfKZ4uwIrufSumOuhdtx0kjWzg+FZ5WYNvZbGsoHXsdPTxR4ZJnDy5iWGHkQWR0gwK8 6gag== X-Gm-Message-State: ALoCoQm2E0Bmz273UFKZdooLIn91YhgyN0jbY9PyOoyf6inoo4HtzsOAP8tdDiX/wINePhIfIWgu X-Received: by 10.140.107.4 with SMTP id g4mr7101197qgf.100.1406666103790; Tue, 29 Jul 2014 13:35:03 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 98sm74611qgh.5.2014.07.29.13.35.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jul 2014 13:35:02 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@infradead.org Subject: [PATCH v2 23/38] nfsd: clean up lockowner refcounting when finding them Date: Tue, 29 Jul 2014 16:34:06 -0400 Message-Id: <1406666061-14175-24-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406666061-14175-1-git-send-email-jlayton@primarydata.com> References: <1406666061-14175-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 Ensure that when finding or creating a lockowner, that we get a reference to it. For now, we also take an extra reference when a lockowner is created that can be put when release_lockowner is called, but we'll remove that in a later patch once we change how references are held. Since we no longer destroy lockowners in the event of an error in nfsd4_lock, we must change how the seqid gets bumped in the lk_is_new case. Instead of doing so on creation, do it manually in nfsd4_lock. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index ec93f27fe64f..3b56431590c2 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4754,6 +4754,7 @@ find_lockowner_str(clientid_t *clid, struct xdr_netobj *owner, continue; if (!same_owner_str(so, owner, clid)) continue; + atomic_inc(&so->so_count); return lockowner(so); } return NULL; @@ -4787,9 +4788,7 @@ alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, str return NULL; INIT_LIST_HEAD(&lo->lo_owner.so_stateids); lo->lo_owner.so_is_open_owner = 0; - /* It is the openowner seqid that will be incremented in encode in the - * case of new lockowners; so increment the lock seqid manually: */ - lo->lo_owner.so_seqid = lock->lk_new_lock_seqid + 1; + lo->lo_owner.so_seqid = lock->lk_new_lock_seqid; lo->lo_owner.so_ops = &lockowner_ops; list_add(&lo->lo_owner.so_strhash, &nn->ownerstr_hashtbl[strhashval]); return lo; @@ -4895,6 +4894,7 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new) { + __be32 status; struct nfs4_file *fi = ost->st_stid.sc_file; struct nfs4_openowner *oo = openowner(ost->st_stateowner); struct nfs4_client *cl = oo->oo_owner.so_client; @@ -4910,19 +4910,26 @@ 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; if (!cstate->minorversion && lock->lk_new_lock_seqid != lo->lo_owner.so_seqid) - return nfserr_bad_seqid; + goto out; } *lst = find_or_create_lock_stateid(lo, fi, inode, ost, new); if (*lst == NULL) { release_lockowner_if_empty(lo); - return nfserr_jukebox; + status = nfserr_jukebox; + goto out; } - return nfs_ok; + status = nfs_ok; +out: + nfs4_put_stateowner(&lo->lo_owner); + return status; } /* @@ -4941,9 +4948,9 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct file_lock *file_lock = NULL; struct file_lock *conflock = NULL; __be32 status = 0; - bool new_state = false; int lkflg; int err; + bool new = false; struct net *net = SVC_NET(rqstp); struct nfsd_net *nn = net_generic(net, nfsd_net_id); @@ -4986,7 +4993,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, &lock->v.new.clientid)) goto out; status = lookup_or_create_lock_state(cstate, open_stp, lock, - &lock_stp, &new_state); + &lock_stp, &new); } else { status = nfs4_preprocess_seqid_op(cstate, lock->lk_old_lock_seqid, @@ -5085,12 +5092,24 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, out: if (filp) fput(filp); - if (lock_stp) + if (lock_stp) { + /* Bump seqid manually if the 4.0 replay owner is openowner */ + if (cstate->replay_owner && + cstate->replay_owner != &lock_sop->lo_owner && + seqid_mutating_err(ntohl(status))) + lock_sop->lo_owner.so_seqid++; + + /* + * If this is a new, never-before-used stateid, and we are + * returning an error, then just go ahead and release it. + */ + if (status && new) + release_lock_stateid(lock_stp); + nfs4_put_stid(&lock_stp->st_stid); + } if (open_stp) nfs4_put_stid(&open_stp->st_stid); - if (status && new_state) - release_lock_stateid(lock_stp); nfsd4_bump_seqid(cstate, status); nfs4_unlock_state(); if (file_lock) @@ -5125,7 +5144,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_lockt *lockt) { struct file_lock *file_lock = NULL; - struct nfs4_lockowner *lo; + struct nfs4_lockowner *lo = NULL; __be32 status; struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); @@ -5188,6 +5207,8 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nfs4_set_lock_denied(file_lock, &lockt->lt_denied); } out: + if (lo) + nfs4_put_stateowner(&lo->lo_owner); nfs4_unlock_state(); if (file_lock) locks_free_lock(file_lock);