Commit bc0c9079 authored by Olga Kornievskaia's avatar Olga Kornievskaia Committed by Anna Schumaker
Browse files

NFS handle COPY reply CB_OFFLOAD call race



It's possible that server replies back with CB_OFFLOAD call and
COPY reply at the same time such that client will process
CB_OFFLOAD before reply to COPY. For that keep a list of pending
callback stateids received and then before waiting on completion
check the pending list.

Cleanup any pending copies on the client shutdown.

Signed-off-by: default avatarOlga Kornievskaia <kolga@netapp.com>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent 62164f31
Loading
Loading
Loading
Loading
+14 −3
Original line number Original line Diff line number Diff line
@@ -681,11 +681,12 @@ __be32 nfs4_callback_offload(void *data, void *dummy,
	struct cb_offloadargs *args = data;
	struct cb_offloadargs *args = data;
	struct nfs_server *server;
	struct nfs_server *server;
	struct nfs4_copy_state *copy;
	struct nfs4_copy_state *copy;
	bool found = false;


	spin_lock(&cps->clp->cl_lock);
	rcu_read_lock();
	rcu_read_lock();
	list_for_each_entry_rcu(server, &cps->clp->cl_superblocks,
	list_for_each_entry_rcu(server, &cps->clp->cl_superblocks,
				client_link) {
				client_link) {
		spin_lock(&server->nfs_client->cl_lock);
		list_for_each_entry(copy, &server->ss_copies, copies) {
		list_for_each_entry(copy, &server->ss_copies, copies) {
			if (memcmp(args->coa_stateid.other,
			if (memcmp(args->coa_stateid.other,
					copy->stateid.other,
					copy->stateid.other,
@@ -693,13 +694,23 @@ __be32 nfs4_callback_offload(void *data, void *dummy,
				continue;
				continue;
			nfs4_copy_cb_args(copy, args);
			nfs4_copy_cb_args(copy, args);
			complete(&copy->completion);
			complete(&copy->completion);
			spin_unlock(&server->nfs_client->cl_lock);
			found = true;
			goto out;
			goto out;
		}
		}
		spin_unlock(&server->nfs_client->cl_lock);
	}
	}
out:
out:
	rcu_read_unlock();
	rcu_read_unlock();
	if (!found) {
		copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
		if (!copy) {
			spin_unlock(&cps->clp->cl_lock);
			return htonl(NFS4ERR_SERVERFAULT);
		}
		memcpy(&copy->stateid, &args->coa_stateid, NFS4_STATEID_SIZE);
		nfs4_copy_cb_args(copy, args);
		list_add_tail(&copy->copies, &cps->clp->pending_cb_stateids);
	}
	spin_unlock(&cps->clp->cl_lock);


	return 0;
	return 0;
}
}
+20 −2
Original line number Original line Diff line number Diff line
@@ -138,14 +138,31 @@ static int handle_async_copy(struct nfs42_copy_res *res,
{
{
	struct nfs4_copy_state *copy;
	struct nfs4_copy_state *copy;
	int status = NFS4_OK;
	int status = NFS4_OK;
	bool found_pending = false;

	spin_lock(&server->nfs_client->cl_lock);
	list_for_each_entry(copy, &server->nfs_client->pending_cb_stateids,
				copies) {
		if (memcmp(&res->write_res.stateid, &copy->stateid,
				NFS4_STATEID_SIZE))
			continue;
		found_pending = true;
		list_del(&copy->copies);
		break;
	}
	if (found_pending) {
		spin_unlock(&server->nfs_client->cl_lock);
		goto out;
	}


	copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
	copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
	if (!copy)
	if (!copy) {
		spin_unlock(&server->nfs_client->cl_lock);
		return -ENOMEM;
		return -ENOMEM;
	}
	memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
	memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
	init_completion(&copy->completion);
	init_completion(&copy->completion);


	spin_lock(&server->nfs_client->cl_lock);
	list_add_tail(&copy->copies, &server->ss_copies);
	list_add_tail(&copy->copies, &server->ss_copies);
	spin_unlock(&server->nfs_client->cl_lock);
	spin_unlock(&server->nfs_client->cl_lock);


@@ -153,6 +170,7 @@ static int handle_async_copy(struct nfs42_copy_res *res,
	spin_lock(&server->nfs_client->cl_lock);
	spin_lock(&server->nfs_client->cl_lock);
	list_del_init(&copy->copies);
	list_del_init(&copy->copies);
	spin_unlock(&server->nfs_client->cl_lock);
	spin_unlock(&server->nfs_client->cl_lock);
out:
	res->write_res.count = copy->count;
	res->write_res.count = copy->count;
	memcpy(&res->write_res.verifier, &copy->verf, sizeof(copy->verf));
	memcpy(&res->write_res.verifier, &copy->verf, sizeof(copy->verf));
	status = -copy->error;
	status = -copy->error;
+15 −0
Original line number Original line Diff line number Diff line
@@ -156,9 +156,23 @@ nfs4_shutdown_ds_clients(struct nfs_client *clp)
	}
	}
}
}


static void
nfs4_cleanup_callback(struct nfs_client *clp)
{
	struct nfs4_copy_state *cp_state;

	while (!list_empty(&clp->pending_cb_stateids)) {
		cp_state = list_entry(clp->pending_cb_stateids.next,
					struct nfs4_copy_state, copies);
		list_del(&cp_state->copies);
		kfree(cp_state);
	}
}

void nfs41_shutdown_client(struct nfs_client *clp)
void nfs41_shutdown_client(struct nfs_client *clp)
{
{
	if (nfs4_has_session(clp)) {
	if (nfs4_has_session(clp)) {
		nfs4_cleanup_callback(clp);
		nfs4_shutdown_ds_clients(clp);
		nfs4_shutdown_ds_clients(clp);
		nfs4_destroy_session(clp->cl_session);
		nfs4_destroy_session(clp->cl_session);
		nfs4_destroy_clientid(clp);
		nfs4_destroy_clientid(clp);
@@ -202,6 +216,7 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init)
#if IS_ENABLED(CONFIG_NFS_V4_1)
#if IS_ENABLED(CONFIG_NFS_V4_1)
	init_waitqueue_head(&clp->cl_lock_waitq);
	init_waitqueue_head(&clp->cl_lock_waitq);
#endif
#endif
	INIT_LIST_HEAD(&clp->pending_cb_stateids);
	return clp;
	return clp;


error:
error:
+1 −0
Original line number Original line Diff line number Diff line
@@ -121,6 +121,7 @@ struct nfs_client {
#endif
#endif


	struct net		*cl_net;
	struct net		*cl_net;
	struct list_head	pending_cb_stateids;
};
};


/*
/*