From patchwork Fri Dec 24 01:32:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 431231 X-Patchwork-Delegate: Trond.Myklebust@netapp.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBO1X4vu009587 for ; Fri, 24 Dec 2010 01:33:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752442Ab0LXBc6 (ORCPT ); Thu, 23 Dec 2010 20:32:58 -0500 Received: from mail-iw0-f174.google.com ([209.85.214.174]:60343 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752527Ab0LXBc5 (ORCPT ); Thu, 23 Dec 2010 20:32:57 -0500 Received: by mail-iw0-f174.google.com with SMTP id 9so6655796iwn.19 for ; Thu, 23 Dec 2010 17:32:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:subject:to:cc :date:message-id:in-reply-to:references:user-agent:mime-version :content-type:content-transfer-encoding; bh=U4c5T1u7rwxkwjwqODL5v3ZFH1ABzNd+AOOl67YowUk=; b=R2fcLDbA3Akla+sThBrNr8ob6IevND4IHqSp3VZRFQlF5g0M/vMNqWitJSkEsicfLt 5Rm2Kn5s8vVw6s3AmvLhxzepkpV8XhrT4Uv6bl/zTb2VIUJNEVTsuiG/UTsug1JML5/5 /0PELzdj7/iiXyeXdVhR25t9SVGnKV51KBr+Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:subject:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; b=WQdGqjSOUaKYXcSz0pQ88CUAh6UBbG4tpRc3Yupqe8eQTUR+pOST51zAAS6Yg2gGr8 5WPErwbnVtj1qb9WlVegYmi4H0bziDfqtDxmS+6czzzbloPsZb6WWJSzz9aVXhiCHR+d r2/5HkB00Ce/8xDPygJ8o9zBoIDqgdeyK9zUw= Received: by 10.42.224.2 with SMTP id im2mr7487376icb.53.1293154377486; Thu, 23 Dec 2010 17:32:57 -0800 (PST) Received: from matisse.1015granger.net ([99.26.161.222]) by mx.google.com with ESMTPS id i2sm7202274icv.3.2010.12.23.17.32.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 23 Dec 2010 17:32:56 -0800 (PST) From: Chuck Lever Subject: [PATCH 3/4] NFS: Introduce nfs_detach_delegations() To: trond.myklebust@netapp.com Cc: linux-nfs@vger.kernel.org Date: Thu, 23 Dec 2010 20:32:54 -0500 Message-ID: <20101224013254.2445.26108.stgit@matisse.1015granger.net> In-Reply-To: <20101224012636.2445.41411.stgit@matisse.1015granger.net> References: <20101224012636.2445.41411.stgit@matisse.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 24 Dec 2010 01:33:26 +0000 (UTC) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 1fd62fc..521d71b 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -175,9 +175,9 @@ static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation return inode; } -static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, - const nfs4_stateid *stateid, - struct nfs_client *clp) +static struct nfs_delegation * +nfs_detach_delegation_locked(struct nfs_inode *nfsi, + struct nfs_client *clp) { struct nfs_delegation *delegation = rcu_dereference_protected(nfsi->delegation, @@ -185,22 +185,29 @@ static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfs if (delegation == NULL) goto nomatch; + spin_lock(&delegation->lock); - if (stateid != NULL && memcmp(delegation->stateid.data, stateid->data, - sizeof(delegation->stateid.data)) != 0) - goto nomatch_unlock; list_del_rcu(&delegation->super_list); delegation->inode = NULL; nfsi->delegation_state = 0; rcu_assign_pointer(nfsi->delegation, NULL); spin_unlock(&delegation->lock); return delegation; -nomatch_unlock: - spin_unlock(&delegation->lock); nomatch: return NULL; } +static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi, + struct nfs_client *clp) +{ + struct nfs_delegation *delegation; + + spin_lock(&clp->cl_lock); + delegation = nfs_detach_delegation_locked(nfsi, clp); + spin_unlock(&clp->cl_lock); + return delegation; +} + /* * Set up a delegation on an inode */ @@ -246,7 +253,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct delegation = NULL; goto out; } - freeme = nfs_detach_delegation_locked(nfsi, NULL, clp); + freeme = nfs_detach_delegation_locked(nfsi, clp); } list_add_rcu(&delegation->super_list, &clp->cl_delegations); nfsi->delegation_state = delegation->type; @@ -307,9 +314,7 @@ restart: inode = nfs_delegation_grab_inode(delegation); if (inode == NULL) continue; - spin_lock(&clp->cl_lock); - delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL, clp); - spin_unlock(&clp->cl_lock); + delegation = nfs_detach_delegation(NFS_I(inode), clp); rcu_read_unlock(); if (delegation != NULL) { filemap_flush(inode->i_mapping); @@ -338,9 +343,7 @@ void nfs_inode_return_delegation_noreclaim(struct inode *inode) struct nfs_delegation *delegation; if (rcu_access_pointer(nfsi->delegation) != NULL) { - spin_lock(&clp->cl_lock); - delegation = nfs_detach_delegation_locked(nfsi, NULL, clp); - spin_unlock(&clp->cl_lock); + delegation = nfs_detach_delegation(nfsi, clp); if (delegation != NULL) nfs_do_return_delegation(inode, delegation, 0); } @@ -354,9 +357,7 @@ int nfs_inode_return_delegation(struct inode *inode) int err = 0; if (rcu_access_pointer(nfsi->delegation) != NULL) { - spin_lock(&clp->cl_lock); - delegation = nfs_detach_delegation_locked(nfsi, NULL, clp); - spin_unlock(&clp->cl_lock); + delegation = nfs_detach_delegation(nfsi, clp); if (delegation != NULL) { nfs_wb_all(inode); err = __nfs_inode_return_delegation(inode, delegation, 1); @@ -530,9 +531,7 @@ restart: inode = nfs_delegation_grab_inode(delegation); if (inode == NULL) continue; - spin_lock(&clp->cl_lock); - delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL, clp); - spin_unlock(&clp->cl_lock); + delegation = nfs_detach_delegation(NFS_I(inode), clp); rcu_read_unlock(); if (delegation != NULL) nfs_free_delegation(delegation);