linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@gmail.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v2 12/20] NFSv4: Revoke the delegation on success in nfs4_delegreturn_done()
Date: Thu, 31 Oct 2019 18:40:43 -0400	[thread overview]
Message-ID: <20191031224051.8923-13-trond.myklebust@hammerspace.com> (raw)
In-Reply-To: <20191031224051.8923-12-trond.myklebust@hammerspace.com>

If the delegation was successfully returned, then mark it as revoked.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/delegation.c | 36 ++++++++++++++++++++++++++++++++++++
 fs/nfs/delegation.h |  1 +
 fs/nfs/nfs4proc.c   |  1 +
 3 files changed, 38 insertions(+)

diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index aff2416dc277..8c176c921554 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -806,6 +806,42 @@ void nfs_remove_bad_delegation(struct inode *inode,
 }
 EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation);
 
+void nfs_delegation_mark_returned(struct inode *inode,
+		const nfs4_stateid *stateid)
+{
+	struct nfs_delegation *delegation;
+
+	if (!inode)
+		return;
+
+	rcu_read_lock();
+	delegation = rcu_dereference(NFS_I(inode)->delegation);
+	if (!delegation)
+		goto out_rcu_unlock;
+
+	spin_lock(&delegation->lock);
+	if (!nfs4_stateid_match_other(stateid, &delegation->stateid))
+		goto out_spin_unlock;
+	if (stateid->seqid) {
+		/* If delegation->stateid is newer, dont mark as returned */
+		if (nfs4_stateid_is_newer(&delegation->stateid, stateid))
+			goto out_clear_returning;
+		if (delegation->stateid.seqid != stateid->seqid)
+			delegation->stateid.seqid = stateid->seqid;
+	}
+
+	set_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
+
+out_clear_returning:
+	clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
+out_spin_unlock:
+	spin_unlock(&delegation->lock);
+out_rcu_unlock:
+	rcu_read_unlock();
+
+	nfs_inode_find_state_and_recover(inode, stateid);
+}
+
 /**
  * nfs_expire_unused_delegation_types
  * @clp: client to process
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index 74b7fb601365..15d3484be028 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -53,6 +53,7 @@ void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
 int nfs_client_return_marked_delegations(struct nfs_client *clp);
 int nfs_delegations_present(struct nfs_client *clp);
 void nfs_remove_bad_delegation(struct inode *inode, const nfs4_stateid *stateid);
+void nfs_delegation_mark_returned(struct inode *inode, const nfs4_stateid *stateid);
 
 void nfs_delegation_mark_reclaim(struct nfs_client *clp);
 void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 217885e32852..a222122e7151 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -6214,6 +6214,7 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
 		if (exception.retry)
 			goto out_restart;
 	}
+	nfs_delegation_mark_returned(data->inode, data->args.stateid);
 	data->rpc_status = task->tk_status;
 	return;
 out_restart:
-- 
2.23.0


  reply	other threads:[~2019-10-31 22:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-31 22:40 [PATCH v2 00/20] Delegation bugfixes Trond Myklebust
2019-10-31 22:40 ` [PATCH v2 01/20] NFSv4: Don't allow a cached open with a revoked delegation Trond Myklebust
2019-10-31 22:40   ` [PATCH v2 02/20] NFS: Fix an RCU lock leak in nfs4_refresh_delegation_stateid() Trond Myklebust
2019-10-31 22:40     ` [PATCH v2 03/20] NFSv4: Fix delegation handling in update_open_stateid() Trond Myklebust
2019-10-31 22:40       ` [PATCH v2 04/20] NFSv4: nfs4_callback_getattr() should ignore revoked delegations Trond Myklebust
2019-10-31 22:40         ` [PATCH v2 05/20] NFSv4: Delegation recalls should not find " Trond Myklebust
2019-10-31 22:40           ` [PATCH v2 06/20] NFSv4: fail nfs4_refresh_delegation_stateid() when the delegation was revoked Trond Myklebust
2019-10-31 22:40             ` [PATCH v2 07/20] NFS: Rename nfs_inode_return_delegation_noreclaim() Trond Myklebust
2019-10-31 22:40               ` [PATCH v2 08/20] NFSv4: Don't remove the delegation from the super_list more than once Trond Myklebust
2019-10-31 22:40                 ` [PATCH v2 09/20] NFSv4: Hold the delegation spinlock when updating the seqid Trond Myklebust
2019-10-31 22:40                   ` [PATCH v2 10/20] NFSv4: Clear the NFS_DELEGATION_REVOKED flag in nfs_update_inplace_delegation() Trond Myklebust
2019-10-31 22:40                     ` [PATCH v2 11/20] NFSv4: Update the stateid seqid in nfs_revoke_delegation() Trond Myklebust
2019-10-31 22:40                       ` Trond Myklebust [this message]
2019-10-31 22:40                         ` [PATCH v2 13/20] NFSv4: Ignore requests to return the delegation if it was revoked Trond Myklebust
2019-10-31 22:40                           ` [PATCH v2 14/20] NFSv4: Don't reclaim delegations that have been returned or revoked Trond Myklebust
2019-10-31 22:40                             ` [PATCH v2 15/20] NFSv4: nfs4_return_incompatible_delegation() should check delegation validity Trond Myklebust
2019-10-31 22:40                               ` [PATCH v2 16/20] NFSv4: Fix nfs4_inode_make_writeable() Trond Myklebust
2019-10-31 22:40                                 ` [PATCH v2 17/20] NFS: nfs_inode_find_state_and_recover() fix stateid matching Trond Myklebust
2019-10-31 22:40                                   ` [PATCH v2 18/20] NFSv4: Fix races between open and delegreturn Trond Myklebust
2019-10-31 22:40                                     ` [PATCH v2 19/20] NFSv4: Handle NFS4ERR_OLD_STATEID in delegreturn Trond Myklebust
2019-10-31 22:40                                       ` [PATCH v2 20/20] NFSv4: Don't retry the GETATTR on old stateid in nfs4_delegreturn_done() Trond Myklebust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191031224051.8923-13-trond.myklebust@hammerspace.com \
    --to=trondmy@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).