Commit 1e3d25b9 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

init: Add options to spdk_rpc_initialize() for log_file/level params



Add log_file and log_level parameters to spdk_rpc_initialize() via a
new options structure spdk_rpc_opts.

spdk_rpc_initialize() calls spdk_jsonrpc_set_log_file() and
_set_log_level() with these parameters.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I084ed5b76849e06ab3419a115234d2d9b44f820b
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18830


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
parent 2087624e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,12 @@ buffers to be described there. spdk_nvmf_request_get_data() has been removed.
New APIs, `spdk_jsonrpc_set_log_level` and `spdk_jsonrpc_set_log_file`, were added to enable
logging JSON RPC calls history.

### init

Options for the JSON-RPC server initialization were added. The options are defined via the
`spdk_rpc_opts` structure and is passed to the existing API `spdk_rpc_initialize()` as a new
argument. The options include `log_file` and `log_level`.

## v23.05

### accel
+1 −1
Original line number Diff line number Diff line
@@ -265,7 +265,7 @@ spdk_fio_bdev_init_done(int rc, void *cb_arg)
{
	*(bool *)cb_arg = true;

	if (spdk_rpc_initialize(g_rpc_listen_addr) == 0) {
	if (spdk_rpc_initialize(g_rpc_listen_addr, NULL) == 0) {
		spdk_rpc_set_state(SPDK_RPC_RUNTIME);
	}
}
+3 −3
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (C) 2019 Intel Corporation.
 *   All rights reserved.
 *   Copyright (C) 2019 Intel Corporation. All rights reserved.
 *   Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 */

#include "spdk/stdinc.h"
@@ -675,7 +675,7 @@ nvmf_subsystem_init_done(int rc, void *cb_arg)
{
	fprintf(stdout, "bdev subsystem init successfully\n");

	rc = spdk_rpc_initialize(g_rpc_addr);
	rc = spdk_rpc_initialize(g_rpc_addr, NULL);
	if (rc) {
		spdk_app_stop(rc);
		return;
+25 −1
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (C) 2021 Intel Corporation.  All rights reserved.
 *   Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 */

/**
@@ -12,6 +13,8 @@

#include "spdk/stdinc.h"
#include "spdk/queue.h"
#include "spdk/log.h"
#include "spdk/assert.h"

#ifdef __cplusplus
extern "C" {
@@ -19,15 +22,36 @@ extern "C" {

#define SPDK_DEFAULT_RPC_ADDR "/var/tmp/spdk.sock"

/**
 * Structure with optional parameters for the JSON-RPC server initialization.
 */
struct spdk_rpc_opts {
	/* Size of this structure in bytes. */
	size_t size;
	/*
	 * A JSON-RPC log file pointer. The default value is NULL and used
	 * when options are omitted.
	 */
	FILE *log_file;
	/*
	 * JSON-RPC log level. Default value is SPDK_LOG_DISABLED and used
	 * when options are omitted.
	 */
	enum spdk_log_level log_level;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_rpc_opts) == 24, "Incorrect size");

/**
 * Create the SPDK JSON-RPC server and listen at the provided address. The RPC server is optional and is
 * independent of subsystem initialization. The RPC server can be started and stopped at any time.
 *
 * \param listen_addr Path to a unix domain socket to listen on
 * \param opts Options for JSON-RPC server initialization. If NULL, default values are used.
 *
 * \return Negated errno on failure. 0 on success.
 */
int spdk_rpc_initialize(const char *listen_addr);
int spdk_rpc_initialize(const char *listen_addr,
			const struct spdk_rpc_opts *opts);

/**
 * Shut down the SPDK JSON-RPC target
+3 −3
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (C) 2016 Intel Corporation. All rights reserved.
 *   Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
 *   Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 *   Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 */

#include "spdk/stdinc.h"
@@ -299,7 +299,7 @@ app_start_rpc(int rc, void *arg1)

	spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);

	rc = spdk_rpc_initialize(g_spdk_app.rpc_addr);
	rc = spdk_rpc_initialize(g_spdk_app.rpc_addr, NULL);
	if (rc) {
		spdk_app_stop(rc);
		return;
@@ -499,7 +499,7 @@ bootstrap_fn(void *arg1)
		} else {
			spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);

			rc = spdk_rpc_initialize(g_spdk_app.rpc_addr);
			rc = spdk_rpc_initialize(g_spdk_app.rpc_addr, NULL);
			if (rc) {
				spdk_app_stop(rc);
				return;
Loading