@@ -166,6 +166,11 @@ struct cb_layoutrecallargs {
};
};
+struct cb_stalestatenode {
+ nfs4_stateid cbs_stateid;
+ struct list_head cb_stale_state;
+};
+
extern __be32 nfs4_callback_layoutrecall(
struct cb_layoutrecallargs *args,
void *dummy, struct cb_process_state *cps);
@@ -159,9 +159,16 @@ static u32 initiate_file_draining(struct nfs_client *clp,
{
struct inode *ino;
struct pnfs_layout_hdr *lo;
+ struct cb_stalestatenode *state_entry, *state_node;
+ struct cb_stalestatenode *tmp;
+ bool res;
u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
LIST_HEAD(free_me_list);
+ state_node = kmalloc(sizeof(cb_stalestatenode), GFP_KERNEL);
+ if (!state_node)
+ return NFS4ERR_DELAY;
+
lo = get_layout_by_fh(clp, &args->cbl_fh);
if (!lo)
return NFS4ERR_NOMATCHING_LAYOUT;
@@ -174,7 +181,24 @@ static u32 initiate_file_draining(struct nfs_client *clp,
rv = NFS4ERR_DELAY;
else
rv = NFS4ERR_NOMATCHING_LAYOUT;
+ list_for_each_entry_safe(state_entry, tmp,
+ &NFS_I(ino)->cb_stale_state_list, cb_stale_state) {
+ if (memcmp(&args->cbl_stateid, &state_entry->cbs_stateid,
+ NFS4_STATEID_OTHER_SIZE) != 0)
+ continue;
+ if (rv == NFS4ERR_NOMATCHING_LAYOUT)
+ list_del(&state_entry->cb_stale_state);
+ goto unlock;
+ }
+ if (rv == NFS4ERR_DELAY) {
+ nfs4_stateid_copy(&state_node->cbs_stateid, &args->cbl_stateid);
+ list_add(&state_node->cb_stale_state,
+ &NFS_I(ino)->cb_stale_state_list);
+ } else {
+ kfree(state_node);
+ }
pnfs_set_layout_stateid(lo, &args->cbl_stateid, true);
+unlock:
spin_unlock(&ino->i_lock);
pnfs_free_lseg_list(&free_me_list);
pnfs_put_layout_hdr(lo);
@@ -1643,6 +1643,7 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
return NULL;
nfsi->flags = 0UL;
nfsi->cache_validity = 0UL;
+ INIT_LIST_HEAD(&nfsi->cb_stale_state_list);
#ifdef CONFIG_NFS_V3_ACL
nfsi->acl_access = ERR_PTR(-EAGAIN);
nfsi->acl_default = ERR_PTR(-EAGAIN);
@@ -181,6 +181,7 @@ struct nfs_inode {
struct nfs4_cached_acl *nfs4_acl;
/* NFSv4 state */
struct list_head open_states;
+ struct list_head cb_stale_state_list;
struct nfs_delegation __rcu *delegation;
fmode_t delegation_state;
struct rw_semaphore rwsem;
If initiate_file_draining returned NFS4ERR_DELAY, all the lsegs of a file might be released before the retrying cb_layout request arriving at the client. In this situation, layoutget request of the file will use open stateid to obtain a new layout stateid. And if the retrying cb_layout request arrived at the client after the layoutget reply, new layout stateid would be overwrite by one out of date. Signed-off-by: shaobingqing <shaobingqing@bwstor.com.cn> --- fs/nfs/callback.h | 5 +++++ fs/nfs/callback_proc.c | 24 ++++++++++++++++++++++++ fs/nfs/inode.c | 1 + include/linux/nfs_fs.h | 1 + 4 files changed, 31 insertions(+), 0 deletions(-)