linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <trond.myklebust@primarydata.com>
To: anna.schumaker@netapp.com
Cc: linux-nfs@vger.kernel.org, Oleg Drokin <green@linuxhacker.ru>
Subject: [PATCH v5 11/25] NFSv4.1: Ensure we always run TEST/FREE_STATEID on locks
Date: Sat, 17 Sep 2016 01:13:19 -0400	[thread overview]
Message-ID: <1474089213-104014-12-git-send-email-trond.myklebust@primarydata.com> (raw)
In-Reply-To: <1474089213-104014-11-git-send-email-trond.myklebust@primarydata.com>

Right now, we're only running TEST/FREE_STATEID on the locks if
the open stateid recovery succeeds. The protocol requires us to
always do so.
The fix would be to move the call to TEST/FREE_STATEID and do it
before we attempt open recovery.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 fs/nfs/nfs4proc.c | 92 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 52 insertions(+), 40 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 3c1b8cb7dd95..33ca6d768bd2 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2486,6 +2486,45 @@ static void nfs41_check_delegation_stateid(struct nfs4_state *state)
 }
 
 /**
+ * nfs41_check_expired_locks - possibly free a lock stateid
+ *
+ * @state: NFSv4 state for an inode
+ *
+ * Returns NFS_OK if recovery for this stateid is now finished.
+ * Otherwise a negative NFS4ERR value is returned.
+ */
+static int nfs41_check_expired_locks(struct nfs4_state *state)
+{
+	int status, ret = NFS_OK;
+	struct nfs4_lock_state *lsp;
+	struct nfs_server *server = NFS_SERVER(state->inode);
+
+	if (!test_bit(LK_STATE_IN_USE, &state->flags))
+		goto out;
+	list_for_each_entry(lsp, &state->lock_states, ls_locks) {
+		if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
+			struct rpc_cred *cred = lsp->ls_state->owner->so_cred;
+
+			status = nfs41_test_and_free_expired_stateid(server,
+					&lsp->ls_stateid,
+					cred);
+			trace_nfs4_test_lock_stateid(state, lsp, status);
+			if (status == -NFS4ERR_EXPIRED ||
+			    status == -NFS4ERR_BAD_STATEID) {
+				clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
+				if (!recover_lost_locks)
+					set_bit(NFS_LOCK_LOST, &lsp->ls_flags);
+			} else if (status != NFS_OK) {
+				ret = status;
+				break;
+			}
+		}
+	};
+out:
+	return ret;
+}
+
+/**
  * nfs41_check_open_stateid - possibly free an open stateid
  *
  * @state: NFSv4 state for an inode
@@ -2522,6 +2561,9 @@ static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
 	int status;
 
 	nfs41_check_delegation_stateid(state);
+	status = nfs41_check_expired_locks(state);
+	if (status != NFS_OK)
+		return status;
 	status = nfs41_check_open_stateid(state);
 	if (status != NFS_OK)
 		status = nfs4_open_expired(sp, state);
@@ -6125,49 +6167,19 @@ out:
 }
 
 #if defined(CONFIG_NFS_V4_1)
-/**
- * nfs41_check_expired_locks - possibly free a lock stateid
- *
- * @state: NFSv4 state for an inode
- *
- * Returns NFS_OK if recovery for this stateid is now finished.
- * Otherwise a negative NFS4ERR value is returned.
- */
-static int nfs41_check_expired_locks(struct nfs4_state *state)
-{
-	int status, ret = NFS_OK;
-	struct nfs4_lock_state *lsp;
-	struct nfs_server *server = NFS_SERVER(state->inode);
-
-	list_for_each_entry(lsp, &state->lock_states, ls_locks) {
-		if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
-			struct rpc_cred *cred = lsp->ls_state->owner->so_cred;
-
-			status = nfs41_test_and_free_expired_stateid(server,
-					&lsp->ls_stateid,
-					cred);
-			trace_nfs4_test_lock_stateid(state, lsp, status);
-			if (status == -NFS4ERR_EXPIRED ||
-			    status == -NFS4ERR_BAD_STATEID)
-				clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
-			else if (status != NFS_OK) {
-				ret = status;
-				break;
-			}
-		}
-	};
-
-	return ret;
-}
-
 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
 {
-	int status = NFS_OK;
+	struct nfs4_lock_state *lsp;
+	int status;
 
-	if (test_bit(LK_STATE_IN_USE, &state->flags))
-		status = nfs41_check_expired_locks(state);
-	if (status != NFS_OK)
-		status = nfs4_lock_expired(state, request);
+	status = nfs4_set_lock_state(state, request);
+	if (status != 0)
+		return status;
+	lsp = request->fl_u.nfs4_fl.owner;
+	if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) ||
+	    test_bit(NFS_LOCK_LOST, &lsp->ls_flags))
+		return 0;
+	status = nfs4_lock_expired(state, request);
 	return status;
 }
 #endif
-- 
2.7.4


  reply	other threads:[~2016-09-17  5:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-17  5:13 [PATCH v5 00/25] Fix delegation behaviour when server revokes some state Trond Myklebust
2016-09-17  5:13 ` [PATCH v5 01/25] NFSv4.1: Don't deadlock the state manager on the SEQUENCE status flags Trond Myklebust
2016-09-17  5:13   ` [PATCH v5 02/25] NFSv4: Don't report revoked delegations as valid in nfs_have_delegation() Trond Myklebust
2016-09-17  5:13     ` [PATCH v5 03/25] NFSv4.1: Don't check delegations that are already marked as revoked Trond Myklebust
2016-09-17  5:13       ` [PATCH v5 04/25] NFSv4.1: Allow test_stateid to handle session errors without waiting Trond Myklebust
2016-09-17  5:13         ` [PATCH v5 05/25] NFSv4.1: Add a helper function to deal with expired stateids Trond Myklebust
2016-09-17  5:13           ` [PATCH v5 06/25] NFSv4.x: Allow callers of nfs_remove_bad_delegation() to specify a stateid Trond Myklebust
2016-09-17  5:13             ` [PATCH v5 07/25] NFSv4.1: Test delegation stateids when server declares "some state revoked" Trond Myklebust
2016-09-17  5:13               ` [PATCH v5 08/25] NFSv4.1: Deal with server reboots during delegation expiration recovery Trond Myklebust
2016-09-17  5:13                 ` [PATCH v5 09/25] NFSv4.1: Don't recheck delegations that have already been checked Trond Myklebust
2016-09-17  5:13                   ` [PATCH v5 10/25] NFSv4.1: Allow revoked stateids to skip the call to TEST_STATEID Trond Myklebust
2016-09-17  5:13                     ` Trond Myklebust [this message]
2016-09-17  5:13                       ` [PATCH v5 12/25] NFSv4.1: FREE_STATEID can be asynchronous Trond Myklebust
2016-09-17  5:13                         ` [PATCH v5 13/25] NFSv4.1: Ensure we call FREE_STATEID if needed on close/delegreturn/locku Trond Myklebust
2016-09-17  5:13                           ` [PATCH v5 14/25] NFSv4: Ensure we don't re-test revoked and freed stateids Trond Myklebust
2016-09-17  5:13                             ` [PATCH v5 15/25] NFSv4: nfs_inode_find_delegation_state_and_recover() should check all stateids Trond Myklebust
2016-09-17  5:13                               ` [PATCH v5 16/25] NFSv4: nfs4_do_handle_exception() handle revoke/expiry of a single stateid Trond Myklebust
2016-09-17  5:13                                 ` [PATCH v5 17/25] NFSv4: nfs4_handle_delegation_recall_error() handle expiration as revoke case Trond Myklebust
2016-09-17  5:13                                   ` [PATCH v5 18/25] NFSv4: nfs4_handle_setlk_error() " Trond Myklebust
2016-09-17  5:13                                     ` [PATCH v5 19/25] NFSv4.1: nfs4_layoutget_handle_exception handle revoked state Trond Myklebust
2016-09-17  5:13                                       ` [PATCH v5 20/25] NFSv4: Pass the stateid to the exception handler in nfs4_read/write_done_cb Trond Myklebust
2016-09-17  5:13                                         ` [PATCH v5 21/25] NFSv4: Fix a race in nfs_inode_reclaim_delegation() Trond Myklebust
2016-09-17  5:13                                           ` [PATCH v5 22/25] NFSv4: Fix a race when updating an open_stateid Trond Myklebust
2016-09-17  5:13                                             ` [PATCH v5 23/25] NFS: Always call nfs_inode_find_state_and_recover() when revoking a delegation Trond Myklebust
2016-09-17  5:13                                               ` [PATCH v5 24/25] NFSv4: Don't test open_stateid unless it is set Trond Myklebust
2016-09-17  5:13                                                 ` [PATCH v5 25/25] NFSv4: Mark the lock and open stateids as invalid after freeing them Trond Myklebust
2016-09-17 18:04 ` [PATCH v5 00/25] Fix delegation behaviour when server revokes some state Oleg Drokin
2016-09-17 18:18   ` Trond Myklebust
2016-09-17 19:16     ` Oleg Drokin
2016-09-17 19:32       ` Trond Myklebust
2016-09-17 21:45         ` Trond Myklebust
2016-09-17 21:55           ` Oleg Drokin
2016-09-17 21:59             ` Trond Myklebust
2016-09-18  1:19               ` Oleg Drokin
2016-09-18 16:23                 ` Oleg Drokin
2016-09-18 22:38                   ` Trond Myklebust
2016-09-18 22:44                     ` Oleg Drokin
2016-09-18 23:08                       ` Trond Myklebust
2016-09-18 23:30                         ` Oleg Drokin

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=1474089213-104014-12-git-send-email-trond.myklebust@primarydata.com \
    --to=trond.myklebust@primarydata.com \
    --cc=anna.schumaker@netapp.com \
    --cc=green@linuxhacker.ru \
    --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).