NFSv4.x recover from pre-mature loss of openstateid

Ever since the commit 0e0cb35b41, it's possible to lose an open stateid
while retrying a CLOSE due to ERR_OLD_STATEID. Once that happens,
operations that require openstateid fail with EAGAIN which is propagated
to the application then tests like generic/446 and generic/168 fail with
"Resource temporarily unavailable".

Instead of returning this error, initiate state recovery when possible to
recover the open stateid and then try calling nfs4_select_rw_stateid()
again.

Fixes: 0e0cb35b41 ("NFSv4: Handle NFS4ERR_OLD_STATEID in CLOSE/OPEN_DOWNGRADE")
Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Olga Kornievskaia 2019-12-18 16:50:42 -05:00 committed by Anna Schumaker
parent 62a1573fcf
commit d826e5b827
3 changed files with 30 additions and 10 deletions

View File

@ -61,8 +61,11 @@ static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
status = nfs4_set_rw_stateid(&args.falloc_stateid, lock->open_context, status = nfs4_set_rw_stateid(&args.falloc_stateid, lock->open_context,
lock, FMODE_WRITE); lock, FMODE_WRITE);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
}
res.falloc_fattr = nfs_alloc_fattr(); res.falloc_fattr = nfs_alloc_fattr();
if (!res.falloc_fattr) if (!res.falloc_fattr)
@ -287,9 +290,12 @@ static ssize_t _nfs42_proc_copy(struct file *src,
} else { } else {
status = nfs4_set_rw_stateid(&args->src_stateid, status = nfs4_set_rw_stateid(&args->src_stateid,
src_lock->open_context, src_lock, FMODE_READ); src_lock->open_context, src_lock, FMODE_READ);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
} }
}
status = nfs_filemap_write_and_wait_range(file_inode(src)->i_mapping, status = nfs_filemap_write_and_wait_range(file_inode(src)->i_mapping,
pos_src, pos_src + (loff_t)count - 1); pos_src, pos_src + (loff_t)count - 1);
if (status) if (status)
@ -297,8 +303,11 @@ static ssize_t _nfs42_proc_copy(struct file *src,
status = nfs4_set_rw_stateid(&args->dst_stateid, dst_lock->open_context, status = nfs4_set_rw_stateid(&args->dst_stateid, dst_lock->open_context,
dst_lock, FMODE_WRITE); dst_lock, FMODE_WRITE);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
}
status = nfs_sync_inode(dst_inode); status = nfs_sync_inode(dst_inode);
if (status) if (status)
@ -546,8 +555,11 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx, status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx,
FMODE_READ); FMODE_READ);
nfs_put_lock_context(l_ctx); nfs_put_lock_context(l_ctx);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
}
status = nfs4_call_sync(src_server->client, src_server, &msg, status = nfs4_call_sync(src_server->client, src_server, &msg,
&args->cna_seq_args, &res->cnr_seq_res, 0); &args->cna_seq_args, &res->cnr_seq_res, 0);
@ -618,8 +630,11 @@ static loff_t _nfs42_proc_llseek(struct file *filep,
status = nfs4_set_rw_stateid(&args.sa_stateid, lock->open_context, status = nfs4_set_rw_stateid(&args.sa_stateid, lock->open_context,
lock, FMODE_READ); lock, FMODE_READ);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
}
status = nfs_filemap_write_and_wait_range(inode->i_mapping, status = nfs_filemap_write_and_wait_range(inode->i_mapping,
offset, LLONG_MAX); offset, LLONG_MAX);
@ -994,13 +1009,18 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f,
status = nfs4_set_rw_stateid(&args.src_stateid, src_lock->open_context, status = nfs4_set_rw_stateid(&args.src_stateid, src_lock->open_context,
src_lock, FMODE_READ); src_lock, FMODE_READ);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
}
status = nfs4_set_rw_stateid(&args.dst_stateid, dst_lock->open_context, status = nfs4_set_rw_stateid(&args.dst_stateid, dst_lock->open_context,
dst_lock, FMODE_WRITE); dst_lock, FMODE_WRITE);
if (status) if (status) {
if (status == -EAGAIN)
status = -NFS4ERR_BAD_STATEID;
return status; return status;
}
res.dst_fattr = nfs_alloc_fattr(); res.dst_fattr = nfs_alloc_fattr();
if (!res.dst_fattr) if (!res.dst_fattr)

View File

@ -3251,6 +3251,8 @@ static int _nfs4_do_setattr(struct inode *inode,
nfs_put_lock_context(l_ctx); nfs_put_lock_context(l_ctx);
if (status == -EIO) if (status == -EIO)
return -EBADF; return -EBADF;
else if (status == -EAGAIN)
goto zero_stateid;
} else { } else {
zero_stateid: zero_stateid:
nfs4_stateid_copy(&arg->stateid, &zero_stateid); nfs4_stateid_copy(&arg->stateid, &zero_stateid);

View File

@ -1998,8 +1998,6 @@ lookup_again:
trace_pnfs_update_layout(ino, pos, count, trace_pnfs_update_layout(ino, pos, count,
iomode, lo, lseg, iomode, lo, lseg,
PNFS_UPDATE_LAYOUT_INVALID_OPEN); PNFS_UPDATE_LAYOUT_INVALID_OPEN);
if (status != -EAGAIN)
goto out_unlock;
spin_unlock(&ino->i_lock); spin_unlock(&ino->i_lock);
nfs4_schedule_stateid_recovery(server, ctx->state); nfs4_schedule_stateid_recovery(server, ctx->state);
pnfs_clear_first_layoutget(lo); pnfs_clear_first_layoutget(lo);