]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
NFSv4: Handle NFS4ERR_OLD_STATEID in LOCKU
authorTrond Myklebust <trondmy@gmail.com>
Fri, 20 Sep 2019 11:23:48 +0000 (07:23 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Fri, 20 Sep 2019 20:00:14 +0000 (16:00 -0400)
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>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/nfs4proc.c

index 0949bb535d7c61378c10cf9c4842b952826d1c73..11eafcfc490b93df29ec00829ccd1cde34410df7 100644 (file)
@@ -6410,6 +6410,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;
@@ -6427,7 +6463,8 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
                struct nfs_seqid *seqid)
 {
        struct nfs4_unlockdata *p;
-       struct inode *inode = lsp->ls_state->inode;
+       struct nfs4_state *state = lsp->ls_state;
+       struct inode *inode = state->inode;
 
        p = kzalloc(sizeof(*p), GFP_NOFS);
        if (p == NULL)
@@ -6443,6 +6480,9 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
        locks_init_lock(&p->fl);
        locks_copy_lock(&p->fl, fl);
        p->server = NFS_SERVER(inode);
+       spin_lock(&state->state_lock);
+       nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid);
+       spin_unlock(&state->state_lock);
        return p;
 }
 
@@ -6481,10 +6521,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:
@@ -6507,7 +6551,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;