[9/9] NFSv4: Handle NFS4ERR_OLD_STATEID in LOCKU
diff mbox series

Message ID 20190909140104.78818-9-trond.myklebust@hammerspace.com
State New
Headers show
Series
  • [1/9] pNFS: Ensure we do clear the return-on-close layout stateid on fatal errors
Related show

Commit Message

Trond Myklebust Sept. 9, 2019, 2:01 p.m. UTC
If a LOCKU request receives a NFS4ERR_OLD_STATEID, then bump the
seqid before resending. Ensure we only bump the seqid by 1.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/nfs4proc.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)

Comments

Olga Kornievskaia Sept. 16, 2019, 7:37 p.m. UTC | #1
Hi Trond,

I have a problem with this patch.

It sends an unlock with stateid of all zeros (gets a BAD_STATEID) and
then sends an unlock with a normal stateid. This can be seen running
nfstest_locking --nfsversion 4.1.

On Tue, Sep 10, 2019 at 4:09 AM Trond Myklebust <trondmy@gmail.com> wrote:
>
> If a LOCKU request receives a NFS4ERR_OLD_STATEID, then bump the
> seqid before resending. Ensure we only bump the seqid by 1.
>
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  fs/nfs/nfs4proc.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 43 insertions(+), 4 deletions(-)
>
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index 49f301198008..ecfaf4b1ba5d 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -6377,6 +6377,42 @@ static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *
>         return err;
>  }
>
> +/*
> + * Update the seqid of a lock stateid after receiving
> + * NFS4ERR_OLD_STATEID
> + */
> +static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst,
> +               struct nfs4_lock_state *lsp)
> +{
> +       struct nfs4_state *state = lsp->ls_state;
> +       bool ret = false;
> +
> +       spin_lock(&state->state_lock);
> +       if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid))
> +               goto out;
> +       if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst))
> +               nfs4_stateid_seqid_inc(dst);
> +       else
> +               dst->seqid = lsp->ls_stateid.seqid;
> +       ret = true;
> +out:
> +       spin_unlock(&state->state_lock);
> +       return ret;
> +}
> +
> +static bool nfs4_sync_lock_stateid(nfs4_stateid *dst,
> +               struct nfs4_lock_state *lsp)
> +{
> +       struct nfs4_state *state = lsp->ls_state;
> +       bool ret;
> +
> +       spin_lock(&state->state_lock);
> +       ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid);
> +       nfs4_stateid_copy(dst, &lsp->ls_stateid);
> +       spin_unlock(&state->state_lock);
> +       return ret;
> +}
> +
>  struct nfs4_unlockdata {
>         struct nfs_locku_args arg;
>         struct nfs_locku_res res;
> @@ -6448,10 +6484,14 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
>                                         task->tk_msg.rpc_cred);
>                         /* Fall through */
>                 case -NFS4ERR_BAD_STATEID:
> -               case -NFS4ERR_OLD_STATEID:
>                 case -NFS4ERR_STALE_STATEID:
> -                       if (!nfs4_stateid_match(&calldata->arg.stateid,
> -                                               &calldata->lsp->ls_stateid))
> +                       if (nfs4_sync_lock_stateid(&calldata->arg.stateid,
> +                                               calldata->lsp))
> +                               rpc_restart_call_prepare(task);
> +                       break;
> +               case -NFS4ERR_OLD_STATEID:
> +                       if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid,
> +                                               calldata->lsp))
>                                 rpc_restart_call_prepare(task);
>                         break;
>                 default:
> @@ -6474,7 +6514,6 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data)
>
>         if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
>                 goto out_wait;
> -       nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid);
>         if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
>                 /* Note: exit _without_ running nfs4_locku_done */
>                 goto out_no_action;
> --
> 2.21.0
>

Patch
diff mbox series

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 49f301198008..ecfaf4b1ba5d 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -6377,6 +6377,42 @@  static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *
 	return err;
 }
 
+/*
+ * Update the seqid of a lock stateid after receiving
+ * NFS4ERR_OLD_STATEID
+ */
+static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst,
+		struct nfs4_lock_state *lsp)
+{
+	struct nfs4_state *state = lsp->ls_state;
+	bool ret = false;
+
+	spin_lock(&state->state_lock);
+	if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid))
+		goto out;
+	if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst))
+		nfs4_stateid_seqid_inc(dst);
+	else
+		dst->seqid = lsp->ls_stateid.seqid;
+	ret = true;
+out:
+	spin_unlock(&state->state_lock);
+	return ret;
+}
+
+static bool nfs4_sync_lock_stateid(nfs4_stateid *dst,
+		struct nfs4_lock_state *lsp)
+{
+	struct nfs4_state *state = lsp->ls_state;
+	bool ret;
+
+	spin_lock(&state->state_lock);
+	ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid);
+	nfs4_stateid_copy(dst, &lsp->ls_stateid);
+	spin_unlock(&state->state_lock);
+	return ret;
+}
+
 struct nfs4_unlockdata {
 	struct nfs_locku_args arg;
 	struct nfs_locku_res res;
@@ -6448,10 +6484,14 @@  static void nfs4_locku_done(struct rpc_task *task, void *data)
 					task->tk_msg.rpc_cred);
 			/* Fall through */
 		case -NFS4ERR_BAD_STATEID:
-		case -NFS4ERR_OLD_STATEID:
 		case -NFS4ERR_STALE_STATEID:
-			if (!nfs4_stateid_match(&calldata->arg.stateid,
-						&calldata->lsp->ls_stateid))
+			if (nfs4_sync_lock_stateid(&calldata->arg.stateid,
+						calldata->lsp))
+				rpc_restart_call_prepare(task);
+			break;
+		case -NFS4ERR_OLD_STATEID:
+			if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid,
+						calldata->lsp))
 				rpc_restart_call_prepare(task);
 			break;
 		default:
@@ -6474,7 +6514,6 @@  static void nfs4_locku_prepare(struct rpc_task *task, void *data)
 
 	if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
 		goto out_wait;
-	nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid);
 	if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
 		/* Note: exit _without_ running nfs4_locku_done */
 		goto out_no_action;