iscsi: Make get_iscsi_connections RPC asynchronous

iSCSI poll groups are bind to SPDK thread through IO channel now.

This patch changes get_iscsi_connections RPC from synchronous to
asynchronous by using spdk_for_each_channel.

Core ID was removed from the output of the RPC but thread name
is added to the output of the RPC in this patch.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I20fdb7f11434acf838a89435ba5052b19869181c
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463569
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-07-30 14:13:34 +09:00 committed by Jim Harris
parent 9a17b539f9
commit b3cf508f56
2 changed files with 49 additions and 12 deletions

View File

@ -1535,5 +1535,8 @@ spdk_iscsi_conn_info_json(struct spdk_json_write_ctx *w, struct spdk_iscsi_conn
spdk_json_write_named_string(w, "target_node_name", conn->target_short_name);
spdk_json_write_named_string(w, "thread_name",
spdk_thread_get_name(spdk_get_thread()));
spdk_json_write_object_end(w);
}

View File

@ -877,13 +877,42 @@ invalid:
}
SPDK_RPC_REGISTER("delete_portal_group", spdk_rpc_delete_portal_group, SPDK_RPC_RUNTIME)
struct rpc_get_iscsi_connections_ctx {
struct spdk_jsonrpc_request *request;
struct spdk_json_write_ctx *w;
};
static void
rpc_get_iscsi_connections_done(struct spdk_io_channel_iter *i, int status)
{
struct rpc_get_iscsi_connections_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
spdk_json_write_array_end(ctx->w);
spdk_jsonrpc_end_result(ctx->request, ctx->w);
free(ctx);
}
static void
rpc_get_iscsi_connections(struct spdk_io_channel_iter *i)
{
struct rpc_get_iscsi_connections_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i);
struct spdk_iscsi_poll_group *pg = spdk_io_channel_get_ctx(ch);
struct spdk_iscsi_conn *conn;
STAILQ_FOREACH(conn, &pg->connections, link) {
spdk_iscsi_conn_info_json(ctx->w, conn);
}
spdk_for_each_channel_continue(i, 0);
}
static void
spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_json_write_ctx *w;
struct spdk_iscsi_conn *conns = g_conns_array;
int i;
struct rpc_get_iscsi_connections_ctx *ctx;
if (params != NULL) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
@ -891,17 +920,22 @@ spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_request *request,
return;
}
w = spdk_jsonrpc_begin_result(request);
spdk_json_write_array_begin(w);
for (i = 0; i < MAX_ISCSI_CONNECTIONS; i++) {
struct spdk_iscsi_conn *c = &conns[i];
spdk_iscsi_conn_info_json(w, c);
ctx = calloc(1, sizeof(struct rpc_get_iscsi_connections_ctx));
if (ctx == NULL) {
SPDK_ERRLOG("Failed to allocate rpc_get_iscsi_conns_ctx struct\n");
spdk_jsonrpc_send_error_response(request, -ENOMEM, spdk_strerror(ENOMEM));
return;
}
spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w);
ctx->request = request;
ctx->w = spdk_jsonrpc_begin_result(request);
spdk_json_write_array_begin(ctx->w);
spdk_for_each_channel(&g_spdk_iscsi,
rpc_get_iscsi_connections,
ctx,
rpc_get_iscsi_connections_done);
}
SPDK_RPC_REGISTER("get_iscsi_connections", spdk_rpc_get_iscsi_connections, SPDK_RPC_RUNTIME)