Fix OPEN/CLOSE races
Subsystems (2)
v7 cover Fix OPEN/CLOSE races
v2:
- Fix a sleep-while-atomic issue
- Clean up.
- Add a tracepoint to help document wait incidents.
v3:
- Fix a state update issue
v4:
- Fix a race due to setting the state->flags before waiting on another compound (can cause issues if the other compound has an OPEN_DOWNGRADE).
- Fix stateid seqid wraparound.
v5:
- Fix race with wakeup after clearing NFS_STATE_CHANGE_WAIT
- Fix CLOSE, DELEGRETURN and LAYOUTRETURN issues with NFS4ERR_OLD_STATEID, which were causing stateid leakage
- cleanups
- Fix a typo in nfs_rename...
v6:
- Fix a compile issue when CONFIG_NFS_V4_1=n
v7:
- Fix a typo in nfs4_refresh_open_stateid (thanks Andrew Elble)
- Minor cleanups in nfs4_close_done, nfs4_delegreturn_done, nfs4_layoutreturn_done.
Trond Myklebust (10):
NFSv4: Fix OPEN / CLOSE race
NFSv4: Add a tracepoint to document open stateid updates
NFSv4: Fix open create exclusive when the server reboots
NFS: Fix a typo in nfs_rename()
NFSv4: Retry CLOSE and DELEGRETURN on NFS4ERR_OLD_STATEID.
NFSv4: Don't try to CLOSE if the stateid 'other' field has changed
pNFS: Retry NFS4ERR_OLD_STATEID errors in layoutreturn-on-close
NFSv4: Retry NFS4ERR_OLD_STATEID errors in layoutreturn
NFSv4: cleanup nfs4_close_done
NFSv4: Clean up nfs4_delegreturn_done
fs/nfs/delegation.c | 27 +++++ fs/nfs/delegation.h | 1 + fs/nfs/dir.c | 2 +- fs/nfs/nfs4_fs.h | 7 ++ fs/nfs/nfs4proc.c | 292 +++++++++++++++++++++++++++++++++++++--------------- fs/nfs/nfs4state.c | 26 ++++- fs/nfs/nfs4trace.h | 2 + fs/nfs/pnfs.c | 18 ++++ fs/nfs/pnfs.h | 5 + 9 files changed, 293 insertions(+), 87 deletions(-)
Signature · 1 line
2.13.6
PATCH v7 1/10 NFSv4: Fix OPEN / CLOSE race
Ben Coddington has noted the following race between OPEN and CLOSE on a single client.
Process 1 Process 2 Server
========= ========= ======
1) OPEN file
2) OPEN file
3) Process OPEN (1) seqid=1
4) Process OPEN (2) seqid=2
5) Reply OPEN (2)
6) Receive reply (2)
7) new stateid, seqid=2
8) CLOSE file, using
stateid w/ seqid=2
9) Reply OPEN (1)
10( Process CLOSE (8)
11) Reply CLOSE (8)
12) Forget stateid
file closed
13) Receive reply (7)
14) Forget stateid
file closed.
15) Receive reply (1).
16) New stateid seqid=1
is really the same
stateid that was
closed.
IOW: the reply to the first OPEN is delayed. Since "Process 2" does not wait before closing the file, and it does not cache the closed stateid, then when the delayed reply is finally received, it is treated as setting up a new stateid by the client.
The fix is to ensure that the client processes the OPEN and CLOSE calls in the same order in which the server processed them.
This commit ensures that we examine the seqid of the stateid returned by OPEN. If it is a new stateid, we assume the seqid must be equal to the value 1, and that each state transition increments the seqid value by 1 (See RFC7530, Section 9.1.4.2, and RFC5661, Section 8.2.2).
If the tracker sees that an OPEN returns with a seqid that is greater than the cached seqid + 1, then it bumps a flag to ensure that the caller waits for the RPCs carrying the missing seqids to complete.
Note that there can still be pathologies where the server crashes before it can even send us the missing seqids. Since the OPEN call is still holding a slot when it waits here, that could cause the recovery to stall forever. To avoid that, we time out after a 5 second wait.
--- fs/nfs/nfs4_fs.h | 3 ++ fs/nfs/nfs4proc.c | 153 +++++++++++++++++++++++++++++++++++++++++------------ fs/nfs/nfs4state.c | 1 + 3 files changed, 122 insertions(+), 35 deletions(-)
fs/nfs/nfs4_fs.h +3 -0
@@ -162,6 +162,7 @@ enum {NFS_STATE_POSIX_LOCKS ,/* Posix locks are supported */ NFS_STATE_RECOVERY_FAILED ,/* OPEN stateid state recovery failed */ NFS_STATE_MAY_NOTIFY_LOCK ,/* server may CB_NOTIFY_LOCK */ + NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */ }; struct nfs4_state {
@@ -185,6 +186,8 @@ struct nfs4_state {unsigned int n_rdwr;/* Number of read/write references */ fmode_t state;/* State on the server (R,W, or RW) */ atomic_t count; + +wait_queue_head_t waitq; };
fs/nfs/nfs4proc.c +118 -35
223 lines not on this page · raw message
fs/nfs/nfs4state.c +1 -0
@@ -645,6 +645,7 @@ nfs4_alloc_open_state(void)INIT_LIST_HEAD (&state->lock_states);spin_lock_init (&state->state_lock);seqlock_init (&state->seqlock); +init_waitqueue_head (&state->waitq);return state; }
Signature · 1 line
2.13.6
PATCH v7 2/10 NFSv4: Add a tracepoint to document open stateid updates
--- fs/nfs/nfs4proc.c | 3 +++ fs/nfs/nfs4trace.h | 2 ++ 2 files changed, 5 insertions(+)
fs/nfs/nfs4proc.c +3 -0
@@ -1481,6 +1481,7 @@ static void nfs_clear_open_stateid_locked(struct nfs4_state *state,if (test_bit (NFS_DELEGATED_STATE , &state->flags) ==0 )nfs4_stateid_copy (&state->stateid, stateid);nfs4_stateid_copy (&state->open_stateid, stateid); +trace_nfs4_open_stateid_update (state->inode, stateid,0 ); out:nfs_state_log_update_open_stateid (state); }
@@ -1524,6 +1525,7 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state,write_sequnlock (&state->seqlock);spin_unlock (&state->owner->so_lock);rcu_read_unlock (); +trace_nfs4_open_stateid_update_wait (state->inode, stateid,0 );if (!signal_pending (current)) {if (schedule_timeout (5 *HZ ) ==0 ) status = -EAGAIN ;
@@ -1545,6 +1547,7 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state,if (test_bit (NFS_DELEGATED_STATE , &state->flags) ==0 )nfs4_stateid_copy (&state->stateid, stateid);nfs4_stateid_copy (&state->open_stateid, stateid); +trace_nfs4_open_stateid_update (state->inode, stateid, status); } static void nfs_state_set_open_stateid(struct nfs4_state *state,
fs/nfs/nfs4trace.h +2 -0
@@ -1066,6 +1066,8 @@ DECLARE_EVENT_CLASS(nfs4_inode_stateid_event,DEFINE_NFS4_INODE_STATEID_EVENT (nfs4_setattr);DEFINE_NFS4_INODE_STATEID_EVENT (nfs4_delegreturn); +DEFINE_NFS4_INODE_STATEID_EVENT (nfs4_open_stateid_update); +DEFINE_NFS4_INODE_STATEID_EVENT (nfs4_open_stateid_update_wait); DECLARE_EVENT_CLASS(nfs4_getattr_event, TP_PROTO(
Signature · 1 line
2.13.6
PATCH v7 3/10 NFSv4: Fix open create exclusive when the server reboots
If the server that does not implement NFSv4.1 persistent session semantics reboots while we are performing an exclusive create, then the return value of NFS4ERR_DELAY when we replay the open during the grace period causes us to lose the verifier. When the grace period expires, and we present a new verifier, the server will then correctly reply NFS4ERR_EXIST.
This commit ensures that we always present the same verifier when replaying the OPEN.
--- fs/nfs/nfs4proc.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-)
fs/nfs/nfs4proc.c +26 -15
@@ -1088,6 +1088,12 @@ struct nfs4_opendata {int rpc_status; }; +struct nfs4_open_createattrs { +struct nfs4_label *label; +struct iattr *sattr; +const __u32 verf[2 ]; +}; +static bool nfs4_clear_cap_atomic_open_v1 (struct nfs_server *server,int err,struct nfs4_exception *exception) {
@@ -1157,8 +1163,7 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p)static struct nfs4_opendata *nfs4_opendata_alloc (struct dentry *dentry,struct nfs4_state_owner *sp,fmode_t fmode,int flags, -const struct iattr *attrs, -struct nfs4_label *label, +const struct nfs4_open_createattrs *c,enum open_claim_type4 claim,gfp_t gfp_mask) {
@@ -1166,6 +1171,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,struct inode *dir =d_inode (parent);struct nfs_server *server =NFS_SERVER (dir);struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *,gfp_t ); +struct nfs4_label *label = (c !=NULL ) ? c->label :NULL ;struct nfs4_opendata *p; p =kzalloc (sizeof (*p), gfp_mask);
@@ -1231,15 +1237,11 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,case NFS4_OPEN_CLAIM_DELEG_PREV_FH : p->o_arg.fh =NFS_FH (d_inode (dentry)); } -if (attrs !=NULL && attrs->ia_valid !=0 ) { -__u32 verf[2 ]; - +if (c !=NULL && c->sattr !=NULL && c->sattr->ia_valid !=0 ) { p->o_arg.u.attrs = &p->attrs; -memcpy (&p->attrs, attrs,sizeof (p->attrs)); +memcpy (&p->attrs, c->sattr,sizeof (p->attrs)); - verf[0 ] = jiffies; - verf[1 ] = current->pid; -memcpy (p->o_arg.u.verifier.data, verf, +memcpy (p->o_arg.u.verifier.data, c->verf,sizeof (p->o_arg.u.verifier.data)); } p->c_arg.fh = &p->o_res.fh;
@@ -1891,7 +1893,7 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_contextstruct nfs4_opendata *opendata; opendata =nfs4_opendata_alloc (ctx->dentry, state->owner,0 ,0 , -NULL ,NULL , claim,GFP_NOFS ); +NULL , claim,GFP_NOFS );if (opendata ==NULL )return ERR_PTR (-ENOMEM ); opendata->state = state;
@@ -2822,8 +2824,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,static int _nfs4_do_open (struct inode *dir,struct nfs_open_context *ctx,int flags, -struct iattr *sattr, -struct nfs4_label *label, +const struct nfs4_open_createattrs *c,int *opened) {struct nfs4_state_owner *sp;
@@ -2835,6 +2836,8 @@ static int _nfs4_do_open(struct inode *dir,struct nfs4_threshold **ctx_th = &ctx->mdsthreshold;fmode_t fmode = ctx->mode & (FMODE_READ |FMODE_WRITE |FMODE_EXEC );enum open_claim_type4 claim =NFS4_OPEN_CLAIM_NULL ; +struct iattr *sattr = c->sattr; +struct nfs4_label *label = c->label;struct nfs4_label *olabel =NULL ;int status;
@@ -2853,8 +2856,8 @@ static int _nfs4_do_open(struct inode *dir, status = -ENOMEM ;if (d_really_is_positive (dentry)) claim =NFS4_OPEN_CLAIM_FH ; - opendata =nfs4_opendata_alloc (dentry, sp, fmode, flags, sattr, - label, claim,GFP_KERNEL ); + opendata =nfs4_opendata_alloc (dentry, sp, fmode, flags, + c, claim,GFP_KERNEL );if (opendata ==NULL ) goto err_put_state_owner;
@@ -2935,10 +2938,18 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir,struct nfs_server *server =NFS_SERVER (dir);struct nfs4_exception exception = { };struct nfs4_state *res; +struct nfs4_open_createattrs c = { + .label = label, + .sattr = sattr, + .verf = { + [0 ] = (__u32 )jiffies, + [1 ] = (__u32 )current->pid, + }, + };int status; do { - status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened); + status = _nfs4_do_open(dir, ctx, flags, &c, opened); res = ctx->state; trace_nfs4_open_file(ctx, flags, status); if (status == 0)
Signature · 1 line
2.13.6
PATCH v7 4/10 NFS: Fix a typo in nfs_rename()
On successful rename, the "old_dentry" is retained and is attached to the "new_dir", so we need to call nfs_set_verifier() accordingly.
--- fs/nfs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/dir.c +1 -1
@@ -2064,7 +2064,7 @@ int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,* should mark the directories for revalidation. */ d_move (old_dentry, new_dentry); -nfs_set_verifier (new_dentry, +nfs_set_verifier (old_dentry,nfs_save_change_attribute (new_dir)); }else if (error == -ENOENT )nfs_dentry_handle_enoent (old_dentry);
Signature · 1 line
2.13.6
PATCH v7 5/10 NFSv4: Retry CLOSE and DELEGRETURN on NFS4ERR_OLD_STATEID.
If we're racing with an OPEN, then retry the operation instead of declaring it a success.
--- fs/nfs/delegation.c | 27 +++++++++++++++++++++++++++ fs/nfs/delegation.h | 1 + fs/nfs/nfs4_fs.h | 2 ++ fs/nfs/nfs4proc.c | 21 +++++++++++++++++++-- fs/nfs/nfs4state.c | 16 ++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-)
fs/nfs/delegation.c +27 -0
@@ -1041,6 +1041,33 @@ int nfs_delegations_present(struct nfs_client *clp) }/** +* nfs4_refresh_delegation_stateid - Update delegation stateid seqid +* @dst: stateid to refresh +* @inode: inode to check +* +* Returns "true" and updates "dst->seqid" * if inode had a delegation +* that matches our delegation stateid. Otherwise "false" is returned. +*/ +bool nfs4_refresh_delegation_stateid (nfs4_stateid *dst,struct inode *inode) +{ +struct nfs_delegation *delegation; +bool ret = false; +if (!inode) + goto out; + +rcu_read_lock (); + delegation =rcu_dereference (NFS_I (inode)->delegation); +if (delegation !=NULL && +nfs4_stateid_match_other (dst, &delegation->stateid)) { + dst->seqid = delegation->stateid.seqid; +return ret; + } +rcu_read_unlock (); +out: +return ret; +} + +/** * nfs4_copy_delegation_stateid - Copy inode's state ID information * @inode: inode to check * @flags: delegation type requirement
fs/nfs/delegation.h +1 -0
@@ -62,6 +62,7 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4int nfs4_open_delegation_recall (struct nfs_open_context *ctx,struct nfs4_state *state,const nfs4_stateid *stateid,fmode_t type);int nfs4_lock_delegation_recall (struct file_lock *fl,struct nfs4_state *state,const nfs4_stateid *stateid);bool nfs4_copy_delegation_stateid (struct inode *inode,fmode_t flags,nfs4_stateid *dst,struct rpc_cred **cred); +bool nfs4_refresh_delegation_stateid (nfs4_stateid *dst,struct inode *inode);void nfs_mark_delegation_referenced (struct nfs_delegation *delegation);int nfs4_have_delegation (struct inode *inode,fmode_t flags);
fs/nfs/nfs4_fs.h +2 -0
@@ -461,6 +461,8 @@ extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);extern int nfs4_select_rw_stateid (struct nfs4_state *,fmode_t ,const struct nfs_lock_context *,nfs4_stateid *,struct rpc_cred **); +extern bool nfs4_refresh_open_stateid (nfs4_stateid *dst, +struct nfs4_state *state);extern struct nfs_seqid *nfs_alloc_seqid (struct nfs_seqid_counter *counter,gfp_t gfp_mask);extern int nfs_wait_on_sequence (struct nfs_seqid *seqid,struct rpc_task *task);
fs/nfs/nfs4proc.c +19 -2
@@ -3198,13 +3198,21 @@ static void nfs4_close_done(struct rpc_task *task, void *data) }break ; +case -NFS4ERR_OLD_STATEID : +/* Did we race with OPEN? */ +if (nfs4_refresh_open_stateid (&calldata->arg.stateid, + state)) { + task->tk_status =0 ; +rpc_restart_call_prepare (task); + } + goto out_release;case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_STALE_STATEID :case -NFS4ERR_EXPIRED :nfs4_free_revoked_stateid (server, &calldata->arg.stateid, task->tk_msg.rpc_cred); -case -NFS4ERR_OLD_STATEID : +/* Fallthrough */ case -NFS4ERR_BAD_STATEID :if (!nfs4_stateid_match (&calldata->arg.stateid, &state->open_stateid)) {
@@ -3213,6 +3221,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data) }if (calldata->arg.fmode ==0 )break ; +/* Fallthrough */ default :if (nfs4_async_handle_error (task, server, state,NULL ) == -EAGAIN ) {rpc_restart_call_prepare (task);
@@ -5809,11 +5818,19 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)nfs4_free_revoked_stateid (data->res.server, data->args.stateid, task->tk_msg.rpc_cred); +/* Fallthrough */ case -NFS4ERR_BAD_STATEID : -case -NFS4ERR_OLD_STATEID :case -NFS4ERR_STALE_STATEID : task->tk_status =0 ;break ; +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_delegation_stateid (&data->stateid, data->inode)) { + task->tk_status =0 ; +rpc_restart_call_prepare (task); +return ; + } + task->tk_status =0 ; +break ;case -NFS4ERR_ACCESS :if (data->args.bitmask) { data->args.bitmask =NULL ;
fs/nfs/nfs4state.c +16 -0
@@ -986,6 +986,22 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst,return ret; } +bool nfs4_refresh_open_stateid (nfs4_stateid *dst,struct nfs4_state *state) +{ +bool ret; +int seq; + +do { + ret = false; + seq =read_seqbegin (&state->seqlock); +if (nfs4_state_match_open_stateid_other (state, dst)) { + dst->seqid = state->open_stateid.seqid; + ret = true; + } + }while (read_seqretry (&state->seqlock, seq)); +return ret; +} +static void nfs4_copy_open_stateid (nfs4_stateid *dst,struct nfs4_state *state) {const nfs4_stateid *src;
Signature · 1 line
2.13.6
PATCH v7 6/10 NFSv4: Don't try to CLOSE if the stateid 'other' field has changed
If the stateid is no longer recognised on the server, either due to a restart, or due to a competing CLOSE call, then we do not have to retry. Any open contexts that triggered a reopen of the file, will also act as triggers for any CLOSE for the updated stateids.
--- fs/nfs/nfs4_fs.h | 2 ++ fs/nfs/nfs4proc.c | 14 ++++---------- fs/nfs/nfs4state.c | 9 +++++++-- 3 files changed, 13 insertions(+), 12 deletions(-)
fs/nfs/nfs4_fs.h +2 -0
@@ -463,6 +463,8 @@ extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, struct rpc_cred **);extern bool nfs4_refresh_open_stateid (nfs4_stateid *dst,struct nfs4_state *state); +extern bool nfs4_copy_open_stateid (nfs4_stateid *dst, +struct nfs4_state *state);extern struct nfs_seqid *nfs_alloc_seqid (struct nfs_seqid_counter *counter,gfp_t gfp_mask);extern int nfs_wait_on_sequence (struct nfs_seqid *seqid,struct rpc_task *task);
fs/nfs/nfs4proc.c +4 -10
@@ -3214,14 +3214,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data) task->tk_msg.rpc_cred);/* Fallthrough */ case -NFS4ERR_BAD_STATEID : -if (!nfs4_stateid_match (&calldata->arg.stateid, - &state->open_stateid)) { -rpc_restart_call_prepare (task); - goto out_release; - } -if (calldata->arg.fmode ==0 ) -break ; -/* Fallthrough */ +break ;default :if (nfs4_async_handle_error (task, server, state,NULL ) == -EAGAIN ) {rpc_restart_call_prepare (task);
@@ -3253,7 +3246,6 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) is_rdwr =test_bit (NFS_O_RDWR_STATE , &state->flags); is_rdonly =test_bit (NFS_O_RDONLY_STATE , &state->flags); is_wronly =test_bit (NFS_O_WRONLY_STATE , &state->flags); -nfs4_stateid_copy (&calldata->arg.stateid, &state->open_stateid);/* Calculate the change in open mode */ calldata->arg.fmode =0 ;if (state->n_rdwr ==0 ) {
@@ -3271,7 +3263,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) calldata->arg.fmode |=FMODE_READ |FMODE_WRITE ;if (!nfs4_valid_open_stateid (state) || -test_bit (NFS_OPEN_STATE , &state->flags) ==0 ) + !nfs4_refresh_open_stateid (&calldata->arg.stateid, state)) call_close =0 ;spin_unlock (&state->owner->so_lock);
@@ -3365,6 +3357,8 @@ int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) calldata->inode = state->inode; calldata->state = state; calldata->arg.fh =NFS_FH (state->inode); +if (!nfs4_copy_open_stateid (&calldata->arg.stateid, state)) + goto out_free_calldata;/* Serialization for the sequence id */ alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; calldata->arg.seqid =alloc_seqid (&state->owner->so_seqid, gfp_mask);
fs/nfs/nfs4state.c +7 -2
@@ -1002,18 +1002,23 @@ bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)return ret; } -static void nfs4_copy_open_stateid (nfs4_stateid *dst,struct nfs4_state *state) +bool nfs4_copy_open_stateid (nfs4_stateid *dst,struct nfs4_state *state) { +bool ret;const nfs4_stateid *src;int seq;do { + ret = false; src = &zero_stateid; seq =read_seqbegin (&state->seqlock); -if (test_bit (NFS_OPEN_STATE , &state->flags)) +if (test_bit (NFS_OPEN_STATE , &state->flags)) { src = &state->open_stateid; + ret = true; + }nfs4_stateid_copy (dst, src); }while (read_seqretry (&state->seqlock, seq)); +return ret; }/*
Signature · 1 line
2.13.6
PATCH v7 7/10 pNFS: Retry NFS4ERR_OLD_STATEID errors in layoutreturn-on-close
If our layoutreturn on close operation returns an NFS4ERR_OLD_STATEID, then try to update the stateid and retry. We know that there should be no further LAYOUTGET requests being launched.
--- fs/nfs/nfs4proc.c | 18 ++++++++++++++++-- fs/nfs/pnfs.c | 18 ++++++++++++++++++ fs/nfs/pnfs.h | 5 +++++ 3 files changed, 39 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +16 -2
@@ -3165,11 +3165,18 @@ static void nfs4_close_done(struct rpc_task *task, void *data) calldata->arg.lr_args =NULL ; calldata->res.lr_res =NULL ;break ; +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_layout_stateid (&calldata->arg.lr_args->stateid, + calldata->inode)) { + calldata->res.lr_ret =0 ; +rpc_restart_call_prepare (task); +return ; + } +/* Fallthrough */ case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_DELEG_REVOKED :case -NFS4ERR_EXPIRED :case -NFS4ERR_BAD_STATEID : -case -NFS4ERR_OLD_STATEID :case -NFS4ERR_UNKNOWN_LAYOUTTYPE :case -NFS4ERR_WRONG_CRED : calldata->arg.lr_args =NULL ;
@@ -5787,11 +5794,18 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) data->args.lr_args =NULL ; data->res.lr_res =NULL ;break ; +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_layout_stateid (&data->args.lr_args->stateid, + data->inode)) { + data->res.lr_ret =0 ; +rpc_restart_call_prepare (task); +return ; + } +/* Fallthrough */ case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_DELEG_REVOKED :case -NFS4ERR_EXPIRED :case -NFS4ERR_BAD_STATEID : -case -NFS4ERR_OLD_STATEID :case -NFS4ERR_UNKNOWN_LAYOUTTYPE :case -NFS4ERR_WRONG_CRED : data->args.lr_args =NULL ;
fs/nfs/pnfs.c +18 -0
@@ -355,6 +355,24 @@ pnfs_clear_lseg_state(struct pnfs_layout_segment *lseg, }/* +* Update the seqid of a layout stateid +*/ +bool nfs4_refresh_layout_stateid (nfs4_stateid *dst,struct inode *inode) +{ +struct pnfs_layout_hdr *lo; +bool ret = false; + +spin_lock (&inode->i_lock); + lo =NFS_I (inode)->layout; +if (lo &&nfs4_stateid_match_other (dst, &lo->plh_stateid)) { + dst->seqid = lo->plh_stateid.seqid; + ret = true; + } +spin_unlock (&inode->i_lock); +return ret; +} + +/* * Mark a pnfs_layout_hdr and all associated layout segments as invalid * * In order to continue using the pnfs_layout_hdr, a full recovery
fs/nfs/pnfs.h +5 -0
@@ -251,6 +251,7 @@ int pnfs_destroy_layouts_byfsid(struct nfs_client *clp, bool is_recall);int pnfs_destroy_layouts_byclid (struct nfs_client *clp,bool is_recall); +bool nfs4_refresh_layout_stateid (nfs4_stateid *dst,struct inode *inode);void pnfs_put_layout_hdr (struct pnfs_layout_hdr *lo); void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
@@ -764,6 +765,10 @@ static inline void nfs4_pnfs_v3_ds_connect_unload(void) { } +bool nfs4_refresh_layout_stateid (nfs4_stateid *dst,struct inode *inode) +{ +return false; +}#endif /* CONFIG_NFS_V4_1 */ #if IS_ENABLED (CONFIG_NFS_V4_2 )
Signature · 1 line
2.13.6
PATCH v7 8/10 NFSv4: Retry NFS4ERR_OLD_STATEID errors in layoutreturn
If our layoutreturn returns an NFS4ERR_OLD_STATEID, then try to update the stateid and retry.
--- fs/nfs/nfs4proc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/nfs/nfs4proc.c +12 -3
@@ -8766,18 +8766,27 @@ static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) server =NFS_SERVER (lrp->args.inode);switch (task->tk_status) { +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_layout_stateid (&lrp->args.stateid, + lrp->args.inode)) + goto out_restart; +/* Fallthrough */ default : task->tk_status =0 ; +/* Fallthrough */ case 0 :break ;case -NFS4ERR_DELAY :if (nfs4_async_handle_error (task, server,NULL ,NULL ) != -EAGAIN )break ; -nfs4_sequence_free_slot (&lrp->res.seq_res); -rpc_restart_call_prepare (task); -return ; + goto out_restart; }dprintk ("<-- %s\n" , __func__); +return ; +out_restart: + task->tk_status =0 ; +nfs4_sequence_free_slot (&lrp->res.seq_res); +rpc_restart_call_prepare (task); }static void nfs4_layoutreturn_release (void *calldata)
Signature · 1 line
2.13.6
PATCH v7 9/10 NFSv4: cleanup nfs4_close_done
--- fs/nfs/nfs4proc.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
fs/nfs/nfs4proc.c +16 -19
@@ -3167,11 +3167,8 @@ static void nfs4_close_done(struct rpc_task *task, void *data)break ;case -NFS4ERR_OLD_STATEID :if (nfs4_refresh_layout_stateid (&calldata->arg.lr_args->stateid, - calldata->inode)) { - calldata->res.lr_ret =0 ; -rpc_restart_call_prepare (task); -return ; - } + calldata->inode)) + goto lr_restart;/* Fallthrough */ case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_DELEG_REVOKED :
@@ -3181,9 +3178,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data)case -NFS4ERR_WRONG_CRED : calldata->arg.lr_args =NULL ; calldata->res.lr_res =NULL ; - calldata->res.lr_ret =0 ; -rpc_restart_call_prepare (task); -return ; + goto lr_restart; } }
@@ -3199,19 +3194,15 @@ static void nfs4_close_done(struct rpc_task *task, void *data)if (calldata->arg.bitmask !=NULL ) { calldata->arg.bitmask =NULL ; calldata->res.fattr =NULL ; - task->tk_status =0 ; -rpc_restart_call_prepare (task); - goto out_release; + goto out_restart; }break ;case -NFS4ERR_OLD_STATEID :/* Did we race with OPEN? */ if (nfs4_refresh_open_stateid (&calldata->arg.stateid, - state)) { - task->tk_status =0 ; -rpc_restart_call_prepare (task); - } + state)) + goto out_restart; goto out_release;case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_STALE_STATEID :
@@ -3223,17 +3214,23 @@ static void nfs4_close_done(struct rpc_task *task, void *data)case -NFS4ERR_BAD_STATEID :break ;default : -if (nfs4_async_handle_error (task, server, state,NULL ) == -EAGAIN ) { -rpc_restart_call_prepare (task); - goto out_release; - } +if (nfs4_async_handle_error (task, server, state,NULL ) == -EAGAIN ) + goto out_restart; }nfs_clear_open_stateid (state, &calldata->arg.stateid, res_stateid, calldata->arg.fmode); out_release: + task->tk_status =0 ;nfs_release_seqid (calldata->arg.seqid);nfs_refresh_inode (calldata->inode, &calldata->fattr);dprintk ("%s: done, ret = %d!\n" , __func__, task->tk_status); +return ; +lr_restart: + calldata->res.lr_ret =0 ; +out_restart: + task->tk_status =0 ; +rpc_restart_call_prepare (task); + goto out_release; }static void nfs4_close_prepare (struct rpc_task *task,void *data)
Signature · 1 line
2.13.6
PATCH v7 10/10 NFSv4: Clean up nfs4_delegreturn_done
--- fs/nfs/nfs4proc.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
fs/nfs/nfs4proc.c +14 -18
@@ -5793,11 +5793,8 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)break ;case -NFS4ERR_OLD_STATEID :if (nfs4_refresh_layout_stateid (&data->args.lr_args->stateid, - data->inode)) { - data->res.lr_ret =0 ; -rpc_restart_call_prepare (task); -return ; - } + data->inode)) + goto lr_restart;/* Fallthrough */ case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_DELEG_REVOKED :
@@ -5807,9 +5804,7 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)case -NFS4ERR_WRONG_CRED : data->args.lr_args =NULL ; data->res.lr_res =NULL ; - data->res.lr_ret =0 ; -rpc_restart_call_prepare (task); -return ; + goto lr_restart; } }
@@ -5829,29 +5824,30 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) task->tk_status =0 ;break ;case -NFS4ERR_OLD_STATEID : -if (nfs4_refresh_delegation_stateid (&data->stateid, data->inode)) { - task->tk_status =0 ; -rpc_restart_call_prepare (task); -return ; - } +if (nfs4_refresh_delegation_stateid (&data->stateid, data->inode)) + goto out_restart; task->tk_status =0 ;break ;case -NFS4ERR_ACCESS :if (data->args.bitmask) { data->args.bitmask =NULL ; data->res.fattr =NULL ; - task->tk_status =0 ; -rpc_restart_call_prepare (task); -return ; + goto out_restart; } +/* Fallthrough */ default :if (nfs4_async_handle_error (task, data->res.server,NULL ,NULL ) == -EAGAIN ) { -rpc_restart_call_prepare (task); -return ; + goto out_restart; } } data->rpc_status = task->tk_status; +return ; +lr_restart: + data->res.lr_ret =0 ; +out_restart: + task->tk_status =0 ; +rpc_restart_call_prepare (task); }static void nfs4_delegreturn_release (void *calldata)
Signature · 1 line
2.13.6
Re: [PATCH v7 07/10] pNFS: Retry NFS4ERR_OLD_STATEID errors in layoutreturn-on-close
In reply to Trond MyklebustHi Trond,
Quoted 97 lines · Trond Myklebust
If our layoutreturn on close operation returns an
NFS4ERR_OLD_STATEID, then try to update the stateid and retry. We know that there should be no further LAYOUTGET requests being launched.Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4proc.c | 18 ++++++++++++++++-- fs/nfs/pnfs.c | 18 ++++++++++++++++++ fs/nfs/pnfs.h | 5 +++++ 3 files changed, 39 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +16
-2@@ -3165,11 +3165,18 @@ static void nfs4_close_done(struct rpc_task *task, void *data) calldata->arg.lr_args =NULL ; calldata->res.lr_res =NULL ;break ; +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_layout_stateid (&calldata->arg.lr_args->stateid, + calldata->inode)) { + calldata->res.lr_ret =0 ; +rpc_restart_call_prepare (task); +return ; + } +/* Fallthrough */ case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_DELEG_REVOKED :case -NFS4ERR_EXPIRED :case -NFS4ERR_BAD_STATEID : -case -NFS4ERR_OLD_STATEID :case -NFS4ERR_UNKNOWN_LAYOUTTYPE :case -NFS4ERR_WRONG_CRED : calldata->arg.lr_args =NULL ;@@ -5787,11 +5794,18 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) data->args.lr_args =NULL ; data->res.lr_res =NULL ;break ; +case -NFS4ERR_OLD_STATEID : +if (nfs4_refresh_layout_stateid (&data->args.lr_args->stateid, + data->inode)) { + data->res.lr_ret =0 ; +rpc_restart_call_prepare (task); +return ; + } +/* Fallthrough */ case -NFS4ERR_ADMIN_REVOKED :case -NFS4ERR_DELEG_REVOKED :case -NFS4ERR_EXPIRED :case -NFS4ERR_BAD_STATEID : -case -NFS4ERR_OLD_STATEID :case -NFS4ERR_UNKNOWN_LAYOUTTYPE :case -NFS4ERR_WRONG_CRED : data->args.lr_args =NULL ;fs/nfs/pnfs.c +18
-0@@ -355,6 +355,24 @@ pnfs_clear_lseg_state(struct pnfs_layout_segment *lseg, }/* +* Update the seqid of a layout stateid +*/ +bool nfs4_refresh_layout_stateid (nfs4_stateid *dst,struct inode *inode) +{ +struct pnfs_layout_hdr *lo; +bool ret = false; + +spin_lock (&inode->i_lock); + lo =NFS_I (inode)->layout; +if (lo &&nfs4_stateid_match_other (dst, &lo->plh_stateid)) { + dst->seqid = lo->plh_stateid.seqid; + ret = true; + } +spin_unlock (&inode->i_lock); +return ret; +} + +/* * Mark a pnfs_layout_hdr and all associated layout segments as invalid * * In order to continue using the pnfs_layout_hdr, a full recovery fs/nfs/pnfs.h +1
-0@@ -251,6 +251,7 @@ int pnfs_destroy_layouts_byfsid(struct nfs_client *clp, bool is_recall);int pnfs_destroy_layouts_byclid (struct nfs_client *clp,bool is_recall); +bool nfs4_refresh_layout_stateid (nfs4_stateid *dst,struct inode *inode);void pnfs_put_layout_hdr (struct pnfs_layout_hdr *lo); void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
fs/nfs/pnfs.h static inline void nfs4_pnfs_v3_ds_connect_unload(void) · line 771
Quoted 7 lines
fs/nfs/pnfs.h +4
-0@@ -764,6 +765,10 @@ static inline void nfs4_pnfs_v3_ds_connect_unload(void) { } +bool nfs4_refresh_layout_stateid (nfs4_stateid *dst,struct inode *inode) +{ +return false; +}
Shouldn't this be static & inline? I'm seeing a bunch of "multiple definitions" errors with v4.1 disabled.
Thanks
Anna
Quoted 4 lines
fs/nfs/pnfs.h +0
-0#endif /* CONFIG_NFS_V4_1 */ #if IS_ENABLED (CONFIG_NFS_V4_2 )
Re: [PATCH v7 07/10] pNFS: Retry NFS4ERR_OLD_STATEID errors in layoutreturn-on-close
T24gTW9uLCAyMDE3LTExLTA2IGF0IDE0OjI3IC0wNTAwLCBBbm5hIFNjaHVtYWtlciB3cm90ZToN Cj4gSGkgVHJvbmQsDQo+IA0KPiBPbiAxMS8wNi8yMDE3IDEwOjI3IEFNLCBUcm9uZCBNeWtsZWJ1 c3Qgd3JvdGU6DQo+ID4gK2Jvb2wgbmZzNF9yZWZyZXNoX2xheW91dF9zdGF0ZWlkKG5mczRfc3Rh dGVpZCAqZHN0LCBzdHJ1Y3QgaW5vZGUNCj4gPiAqaW5vZGUpDQo+ID4gK3sNCj4gPiArCXJldHVy biBmYWxzZTsNCj4gPiArfQ0KPiANCj4gU2hvdWxkbid0IHRoaXMgYmUgc3RhdGljICYgaW5saW5l PyAgSSdtIHNlZWluZyBhIGJ1bmNoIG9mICJtdWx0aXBsZQ0KPiBkZWZpbml0aW9ucyIgZXJyb3Jz IHdpdGggdjQuMSBkaXNhYmxlZC4NCj4gDQoNCkkgY2xlYXJseSBuZWVkIGEgdmFjYXRpb24uLi4g 4pi6DQpGaW5hbCByZXNlbmQsIEkgaG9wZS4uLg0KDQotLSANClRyb25kIE15a2xlYnVzdA0KTGlu dXggTkZTIGNsaWVudCBtYWludGFpbmVyLCBQcmltYXJ5RGF0YQ0KdHJvbmQubXlrbGVidXN0QHBy aW1hcnlkYXRhLmNvbQ0K