Commit 4d505568 authored by Krzysztof Karas's avatar Krzysztof Karas Committed by Tomasz Zawadzki
Browse files

lib/init: split spdk_rpc_initialize into smaller functions



Next patch will introduce a new API to handle initializing multiple
instances of servers (instead of a single instance per application).
Most of the new function will overlap with the existing code, so we
should move it to smaller functions to avoid duplication.

This also reduces the number of operations performed by
spdk_rpc_initialize().

Change-Id: Ib898af5e48399dbe5799e11446ac02f536a13fd2
Signed-off-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21320


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent da50ac95
Loading
Loading
Loading
Loading
+34 −16
Original line number Diff line number Diff line
@@ -64,10 +64,38 @@ rpc_opts_get_default(struct spdk_rpc_opts *opts, size_t size)
#undef SET_FIELD
}

int
spdk_rpc_initialize(const char *listen_addr, const struct spdk_rpc_opts *_opts)
static int
rpc_verify_opts_and_methods(const struct spdk_rpc_opts *opts)
{
	if (!spdk_rpc_verify_methods()) {
		return -EINVAL;
	}

	if (opts != NULL && opts->size == 0) {
		SPDK_ERRLOG("size in the options structure should not be zero\n");
		return -EINVAL;
	}

	return 0;
}

static void
rpc_set_spdk_log_opts(const struct spdk_rpc_opts *_opts)
{
	struct spdk_rpc_opts opts;

	rpc_opts_get_default(&opts, sizeof(opts));
	if (_opts != NULL) {
		rpc_opts_copy(&opts, _opts, _opts->size);
	}

	spdk_jsonrpc_set_log_file(opts.log_file);
	spdk_jsonrpc_set_log_level(opts.log_level);
}

int
spdk_rpc_initialize(const char *listen_addr, const struct spdk_rpc_opts *opts)
{
	int rc;

	if (listen_addr == NULL) {
@@ -75,13 +103,9 @@ spdk_rpc_initialize(const char *listen_addr, const struct spdk_rpc_opts *_opts)
		return 0;
	}

	if (!spdk_rpc_verify_methods()) {
		return -EINVAL;
	}

	if (_opts != NULL && _opts->size == 0) {
		SPDK_ERRLOG("size in the options structure should not be zero\n");
		return -EINVAL;
	rc = rpc_verify_opts_and_methods(opts);
	if (rc) {
		return rc;
	}

	/* Listen on the requested address */
@@ -93,13 +117,7 @@ spdk_rpc_initialize(const char *listen_addr, const struct spdk_rpc_opts *_opts)
		return 0;
	}

	rpc_opts_get_default(&opts, sizeof(opts));
	if (_opts != NULL) {
		rpc_opts_copy(&opts, _opts, _opts->size);
	}

	spdk_jsonrpc_set_log_file(opts.log_file);
	spdk_jsonrpc_set_log_level(opts.log_level);
	rpc_set_spdk_log_opts(opts);

	/* Register a poller to periodically check for RPCs */
	g_rpc_poller = SPDK_POLLER_REGISTER(rpc_subsystem_poll, NULL, RPC_SELECT_INTERVAL);