Commit 3eadb9c5 authored by Maciej Szulik's avatar Maciej Szulik Committed by Tomasz Zawadzki
Browse files

app/event: introduce raw json data app opt



Right now, if application wants to create some JSON configuration at
run time, it would need to create and manage some temporary file,
which may be not desired.

To avoid it, introduce 2 new app options (raw json data buffer and its
size), similarly as it was recently done for spdk_subsystem_load_config.

This way of providing configuration is going to be mutually exclusive
with existing file based approach, so that SPDK app framework is not
required to resolve any conflicts between these two and it is left for
application developers.

Signed-off-by: default avatarMaciej Szulik <maciej.szulik@intel.com>
Change-Id: Id6d5a560309863e317ac99db1a08917edd75256e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22212


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
parent 035c3dc4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6,6 +6,10 @@

SPDK applications can now start with `--wait-for-rpc` and JSON configuration provided at the same time.

Struct `spdk_app_opts` was extended by `json_data` and `json_data_size` fields
allowing user to provide a buffer with JSON config as alternative to providing JSON config file path
(these fields are mutually exclusive).

### init

Function `spdk_subsystem_init_from_json_config` is deprecated and will be removed in 24.09 release.
+8 −1
Original line number Diff line number Diff line
@@ -184,8 +184,15 @@ struct spdk_app_opts {
	 * If non-NULL, a pointer to JSON RPC log file.
	 */
	FILE *rpc_log_file;

	/**
	 * Raw JSON configuration data and its size.
	 * Cannot be used simultaneously with json_config_file option.
	 */
	void *json_data;
	size_t json_data_size;
} __attribute__((packed));
SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 236, "Incorrect size");
SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 252, "Incorrect size");

/**
 * Initialize the default value of opts
+17 −1
Original line number Diff line number Diff line
@@ -596,10 +596,12 @@ app_copy_opts(struct spdk_app_opts *opts, struct spdk_app_opts *opts_user, size_
	SET_FIELD(vf_token);
	SET_FIELD(rpc_log_file);
	SET_FIELD(rpc_log_level);
	SET_FIELD(json_data);
	SET_FIELD(json_data_size);

	/* You should not remove this statement, but need to update the assert statement
	 * if you add a new field, and also add a corresponding SET_FIELD statement */
	SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 236, "Incorrect size");
	SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 252, "Incorrect size");

#undef SET_FIELD
}
@@ -855,6 +857,11 @@ spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
	g_start_arg = arg1;

	if (opts->json_config_file != NULL) {
		if (opts->json_data) {
			SPDK_ERRLOG("App opts json_config_file and json_data are mutually exclusive\n");
			return 1;
		}

		g_spdk_app.json_data = spdk_posix_file_load_from_name(opts->json_config_file,
				       &g_spdk_app.json_data_size);
		if (!g_spdk_app.json_data) {
@@ -862,6 +869,15 @@ spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
				    opts->json_config_file, spdk_strerror(errno));
			return 1;
		}
	} else if (opts->json_data) {
		g_spdk_app.json_data = calloc(1, opts->json_data_size);
		if (!g_spdk_app.json_data) {
			SPDK_ERRLOG("Failed to allocate JSON data buffer\n");
			return 1;
		}

		memcpy(g_spdk_app.json_data, opts->json_data, opts->json_data_size);
		g_spdk_app.json_data_size = opts->json_data_size;
	}

	spdk_thread_send_msg(spdk_thread_get_app_thread(), bootstrap_fn, NULL);