Lines Matching defs:ctx

105 app_json_config_load_done(struct load_json_config_ctx *ctx, int rc)
107 spdk_poller_unregister(&ctx->client_conn_poller);
108 if (ctx->client_conn != NULL) {
109 spdk_jsonrpc_client_close(ctx->client_conn);
112 spdk_rpc_server_finish(ctx->rpc_socket_path_temp);
115 ctx->cb_fn(rc, ctx->cb_arg);
117 free(ctx->json_data);
118 free(ctx->values);
119 free(ctx);
123 rpc_client_set_timeout(struct load_json_config_ctx *ctx, uint64_t timeout_us)
125 ctx->timeout = spdk_get_ticks() + timeout_us * spdk_get_ticks_hz() / (1000 * 1000);
129 rpc_client_check_timeout(struct load_json_config_ctx *ctx)
131 if (ctx->timeout < spdk_get_ticks()) {
161 struct load_json_config_ctx *ctx = arg;
166 assert(spdk_get_thread() == ctx->thread);
168 rc = spdk_jsonrpc_client_poll(ctx->client_conn, 0);
170 rc = rpc_client_check_timeout(ctx);
172 rpc_client_set_timeout(ctx, RPC_CLIENT_REQUEST_TIMEOUT_US);
181 app_json_config_load_done(ctx, rc);
185 resp = spdk_jsonrpc_client_get_response(ctx->client_conn);
202 if (resp->error && ctx->stop_on_error) {
204 app_json_config_load_done(ctx, -EINVAL);
207 cb = ctx->client_resp_cb;
211 ctx->client_resp_cb = NULL;
212 cb(ctx, resp);
222 struct load_json_config_ctx *ctx = _ctx;
225 rc = spdk_jsonrpc_client_poll(ctx->client_conn, 0);
228 spdk_poller_unregister(&ctx->client_conn_poller);
229 ctx->client_conn_poller = SPDK_POLLER_REGISTER(rpc_client_poller, ctx, 100);
230 app_json_config_load_subsystem(ctx);
232 rc = rpc_client_check_timeout(ctx);
234 app_json_config_load_done(ctx, rc);
244 client_send_request(struct load_json_config_ctx *ctx, struct spdk_jsonrpc_client_request *request,
249 assert(spdk_get_thread() == ctx->thread);
251 ctx->client_resp_cb = client_resp_cb;
252 rpc_client_set_timeout(ctx, RPC_CLIENT_REQUEST_TIMEOUT_US);
253 rc = spdk_jsonrpc_client_send_request(ctx->client_conn, request);
315 app_json_config_load_subsystem_config_entry_next(struct load_json_config_ctx *ctx,
321 ctx->config_it = spdk_json_next(ctx->config_it);
322 app_json_config_load_subsystem_config_entry(ctx);
329 struct load_json_config_ctx *ctx = _ctx;
338 if (ctx->config_it == NULL) {
339 SPDK_DEBUG_APP_CFG("Subsystem '%.*s': configuration done.\n", ctx->subsystem_name->len,
340 (char *)ctx->subsystem_name->start);
341 ctx->subsystems_it = spdk_json_next(ctx->subsystems_it);
343 spdk_thread_send_msg(ctx->thread, app_json_config_load_subsystem, ctx);
347 if (spdk_json_decode_object(ctx->config_it, jsonrpc_cmd_decoders,
350 app_json_config_load_done(ctx, -EINVAL);
356 if (!ctx->stop_on_error) {
358 ctx->config_it = spdk_json_next(ctx->config_it);
359 spdk_thread_send_msg(ctx->thread, app_json_config_load_subsystem_config_entry, ctx);
360 } else if (!spdk_subsystem_exists(ctx->subsystem_name_str)) {
373 cfg.method, ctx->subsystem_name_str);
375 ctx->config_it = spdk_json_next(ctx->config_it);
376 spdk_thread_send_msg(ctx->thread, app_json_config_load_subsystem_config_entry, ctx);
379 app_json_config_load_done(ctx, rc);
387 ctx->config_it = spdk_json_next(ctx->config_it);
388 spdk_thread_send_msg(ctx->thread, app_json_config_load_subsystem_config_entry, ctx);
396 ctx->config_it = spdk_json_next(ctx->config_it);
397 spdk_thread_send_msg(ctx->thread, app_json_config_load_subsystem_config_entry, ctx);
415 app_json_config_load_done(ctx, -errno);
419 w = spdk_jsonrpc_begin_request(rpc_request, ctx->rpc_request_id, NULL);
422 app_json_config_load_done(ctx, -ENOMEM);
437 rc = client_send_request(ctx, rpc_request, app_json_config_load_subsystem_config_entry_next);
439 app_json_config_load_done(ctx, -rc);
449 struct load_json_config_ctx *ctx = arg1;
452 app_json_config_load_done(ctx, rc);
460 assert(ctx != NULL);
461 if (ctx->subsystems) {
462 ctx->subsystems_it = spdk_json_array_first(ctx->subsystems);
465 app_json_config_load_subsystem(ctx);
474 * Start loading subsystem pointed by ctx->subsystems_it. This must point to the
484 * allsubsystems are walked the ctx->subsystems_it became NULL and "framework_start_init"
489 * RUNTIME RPC methods are used. When ctx->subsystems_it became NULL second time it
496 struct load_json_config_ctx *ctx = _ctx;
498 if (ctx->subsystems_it == NULL) {
499 if (ctx->initalize_subsystems && spdk_rpc_get_state() == SPDK_RPC_STARTUP) {
501 spdk_subsystem_init(subsystem_init_done, ctx);
504 app_json_config_load_done(ctx, 0);
511 if (spdk_json_decode_object(ctx->subsystems_it, subsystem_decoders,
512 SPDK_COUNTOF(subsystem_decoders), ctx)) {
514 app_json_config_load_done(ctx, -EINVAL);
518 snprintf(ctx->subsystem_name_str, sizeof(ctx->subsystem_name_str),
519 "%.*s", ctx->subsystem_name->len, (char *)ctx->subsystem_name->start);
521 SPDK_DEBUG_APP_CFG("Loading subsystem '%s' configuration\n", ctx->subsystem_name_str);
524 ctx->config_it = spdk_json_array_first(ctx->config);
525 app_json_config_load_subsystem_config_entry(ctx);
529 parse_json(void *json, ssize_t json_size, struct load_json_config_ctx *ctx)
539 ctx->json_data = calloc(1, json_size);
540 if (!ctx->json_data) {
543 memcpy(ctx->json_data, json, json_size);
544 ctx->json_data_size = json_size;
546 rc = spdk_json_parse(ctx->json_data, ctx->json_data_size, NULL, 0, &end,
553 ctx->values_cnt = rc;
554 ctx->values = calloc(ctx->values_cnt, sizeof(struct spdk_json_val));
555 if (ctx->values == NULL) {
560 rc = spdk_json_parse(ctx->json_data, ctx->json_data_size, ctx->values,
561 ctx->values_cnt, &end,
563 if ((size_t)rc != ctx->values_cnt) {
570 free(ctx->values);
578 struct load_json_config_ctx *ctx = calloc(1, sizeof(*ctx));
581 if (!ctx) {
586 ctx->cb_fn = cb_fn;
587 ctx->cb_arg = cb_arg;
588 ctx->stop_on_error = stop_on_error;
589 ctx->thread = spdk_get_thread();
590 ctx->initalize_subsystems = initalize_subsystems;
592 rc = parse_json(json, json_size, ctx);
598 rc = spdk_json_find_array(ctx->values, "subsystems", NULL, &ctx->subsystems);
602 ctx->subsystems_it = spdk_json_array_first(ctx->subsystems);
603 if (ctx->subsystems_it == NULL) {
622 rc = snprintf(ctx->rpc_socket_path_temp, sizeof(ctx->rpc_socket_path_temp),
624 if (rc >= (int)sizeof(ctx->rpc_socket_path_temp)) {
629 rc = spdk_rpc_initialize(ctx->rpc_socket_path_temp, NULL);
634 ctx->client_conn = spdk_jsonrpc_client_connect(ctx->rpc_socket_path_temp, AF_UNIX);
635 if (ctx->client_conn == NULL) {
636 SPDK_ERRLOG("Failed to connect to '%s'\n", ctx->rpc_socket_path_temp);
640 rpc_client_set_timeout(ctx, RPC_CLIENT_CONNECT_TIMEOUT_US);
641 ctx->client_conn_poller = SPDK_POLLER_REGISTER(rpc_client_connect_poller, ctx, 100);
645 app_json_config_load_done(ctx, -EINVAL);