Skip to content

Commit 0e0cb35

Browse files
trondmyamschuma-ntap
authored andcommitted
NFSv4: Handle NFS4ERR_OLD_STATEID in CLOSE/OPEN_DOWNGRADE
If a CLOSE or OPEN_DOWNGRADE operation 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>
1 parent e217e82 commit 0e0cb35

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

fs/nfs/nfs4_fs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,6 @@ extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
491491
extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
492492
const struct nfs_lock_context *, nfs4_stateid *,
493493
const struct cred **);
494-
extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst,
495-
struct nfs4_state *state);
496494
extern bool nfs4_copy_open_stateid(nfs4_stateid *dst,
497495
struct nfs4_state *state);
498496

fs/nfs/nfs4proc.c

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,75 @@ nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task)
33133313
return pnfs_wait_on_layoutreturn(inode, task);
33143314
}
33153315

3316+
/*
3317+
* Update the seqid of an open stateid
3318+
*/
3319+
static void nfs4_sync_open_stateid(nfs4_stateid *dst,
3320+
struct nfs4_state *state)
3321+
{
3322+
__be32 seqid_open;
3323+
u32 dst_seqid;
3324+
int seq;
3325+
3326+
for (;;) {
3327+
if (!nfs4_valid_open_stateid(state))
3328+
break;
3329+
seq = read_seqbegin(&state->seqlock);
3330+
if (!nfs4_state_match_open_stateid_other(state, dst)) {
3331+
nfs4_stateid_copy(dst, &state->open_stateid);
3332+
if (read_seqretry(&state->seqlock, seq))
3333+
continue;
3334+
break;
3335+
}
3336+
seqid_open = state->open_stateid.seqid;
3337+
if (read_seqretry(&state->seqlock, seq))
3338+
continue;
3339+
3340+
dst_seqid = be32_to_cpu(dst->seqid);
3341+
if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0)
3342+
dst->seqid = seqid_open;
3343+
break;
3344+
}
3345+
}
3346+
3347+
/*
3348+
* Update the seqid of an open stateid after receiving
3349+
* NFS4ERR_OLD_STATEID
3350+
*/
3351+
static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst,
3352+
struct nfs4_state *state)
3353+
{
3354+
__be32 seqid_open;
3355+
u32 dst_seqid;
3356+
bool ret;
3357+
int seq;
3358+
3359+
for (;;) {
3360+
ret = false;
3361+
if (!nfs4_valid_open_stateid(state))
3362+
break;
3363+
seq = read_seqbegin(&state->seqlock);
3364+
if (!nfs4_state_match_open_stateid_other(state, dst)) {
3365+
if (read_seqretry(&state->seqlock, seq))
3366+
continue;
3367+
break;
3368+
}
3369+
seqid_open = state->open_stateid.seqid;
3370+
if (read_seqretry(&state->seqlock, seq))
3371+
continue;
3372+
3373+
dst_seqid = be32_to_cpu(dst->seqid);
3374+
if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) >= 0)
3375+
dst->seqid = cpu_to_be32(dst_seqid + 1);
3376+
else
3377+
dst->seqid = seqid_open;
3378+
ret = true;
3379+
break;
3380+
}
3381+
3382+
return ret;
3383+
}
3384+
33163385
struct nfs4_closedata {
33173386
struct inode *inode;
33183387
struct nfs4_state *state;
@@ -3387,7 +3456,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
33873456
break;
33883457
case -NFS4ERR_OLD_STATEID:
33893458
/* Did we race with OPEN? */
3390-
if (nfs4_refresh_open_stateid(&calldata->arg.stateid,
3459+
if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid,
33913460
state))
33923461
goto out_restart;
33933462
goto out_release;
@@ -3456,8 +3525,8 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
34563525
} else if (is_rdwr)
34573526
calldata->arg.fmode |= FMODE_READ|FMODE_WRITE;
34583527

3459-
if (!nfs4_valid_open_stateid(state) ||
3460-
!nfs4_refresh_open_stateid(&calldata->arg.stateid, state))
3528+
nfs4_sync_open_stateid(&calldata->arg.stateid, state);
3529+
if (!nfs4_valid_open_stateid(state))
34613530
call_close = 0;
34623531
spin_unlock(&state->owner->so_lock);
34633532

fs/nfs/nfs4state.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,22 +1015,6 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst,
10151015
return ret;
10161016
}
10171017

1018-
bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
1019-
{
1020-
bool ret;
1021-
int seq;
1022-
1023-
do {
1024-
ret = false;
1025-
seq = read_seqbegin(&state->seqlock);
1026-
if (nfs4_state_match_open_stateid_other(state, dst)) {
1027-
dst->seqid = state->open_stateid.seqid;
1028-
ret = true;
1029-
}
1030-
} while (read_seqretry(&state->seqlock, seq));
1031-
return ret;
1032-
}
1033-
10341018
bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
10351019
{
10361020
bool ret;

0 commit comments

Comments
 (0)