subsystem/nvmf: define spdk_nvmf_tgt_conf in subsystem

This is a step to prepare for deletion of conf.c.

spdk_nvmf_tgt_conf was allocated either by RPC or legacy config.

RPC still had to to allocate that because settings for subsystem
are set before subsystem itself initializes.

This patch removed both allocations and just defines that in the
subsystem. nvmf_set_config RPC can now be called multiple times,
only overwritting values that were passed.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I5438a91c1d15070f1f193e29f2000c4b58ea4816
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4662
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Tomasz Zawadzki 2020-10-14 06:20:10 -04:00 committed by Jim Harris
parent 8c66958a10
commit 6caba3e63b
4 changed files with 21 additions and 50 deletions

View File

@ -43,7 +43,6 @@
#define SPDK_NVMF_MAX_NAMESPACES (1 << 14)
struct spdk_nvmf_tgt_conf *g_spdk_nvmf_tgt_conf = NULL;
uint32_t g_spdk_nvmf_tgt_max_subsystems = 0;
static int
@ -140,32 +139,21 @@ nvmf_parse_tgt_max_subsystems(void)
return deprecated_values;
}
static struct spdk_nvmf_tgt_conf *
static int
nvmf_parse_tgt_conf(void)
{
struct spdk_nvmf_tgt_conf *conf;
struct spdk_conf_section *sp;
int rc;
conf = calloc(1, sizeof(*conf));
if (!conf) {
SPDK_ERRLOG("calloc() failed for target conf\n");
return NULL;
}
conf->acceptor_poll_rate = ACCEPT_TIMEOUT_US;
conf->admin_passthru.identify_ctrlr = false;
sp = spdk_conf_find_section(NULL, "Nvmf");
if (sp != NULL) {
rc = nvmf_read_config_file_tgt_conf(sp, conf);
rc = nvmf_read_config_file_tgt_conf(sp, &g_spdk_nvmf_tgt_conf);
if (rc) {
free(conf);
return NULL;
return -1;
}
}
return conf;
return 0;
}
static int
@ -190,16 +178,13 @@ nvmf_parse_nvmf_tgt(void)
}
}
if (!g_spdk_nvmf_tgt_conf) {
g_spdk_nvmf_tgt_conf = nvmf_parse_tgt_conf();
if (!g_spdk_nvmf_tgt_conf) {
SPDK_ERRLOG("nvmf_parse_tgt_conf() failed\n");
return -1;
}
if (nvmf_parse_tgt_conf() != 0) {
SPDK_ERRLOG("nvmf_parse_tgt_conf() failed\n");
return -1;
}
opts.max_subsystems = g_spdk_nvmf_tgt_max_subsystems;
opts.acceptor_poll_rate = g_spdk_nvmf_tgt_conf->acceptor_poll_rate;
opts.acceptor_poll_rate = g_spdk_nvmf_tgt_conf.acceptor_poll_rate;
g_spdk_nvmf_tgt = spdk_nvmf_tgt_create(&opts);
g_spdk_nvmf_tgt_max_subsystems = 0;

View File

@ -54,7 +54,7 @@ struct spdk_nvmf_tgt_conf {
struct spdk_nvmf_admin_passthru_conf admin_passthru;
};
extern struct spdk_nvmf_tgt_conf *g_spdk_nvmf_tgt_conf;
extern struct spdk_nvmf_tgt_conf g_spdk_nvmf_tgt_conf;
extern uint32_t g_spdk_nvmf_tgt_max_subsystems;

View File

@ -111,31 +111,14 @@ static void
rpc_nvmf_set_config(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_nvmf_tgt_conf *conf;
struct spdk_nvmf_tgt_conf conf;
struct spdk_json_write_ctx *w;
if (g_spdk_nvmf_tgt_conf != NULL) {
SPDK_ERRLOG("this RPC must not be called more than once.\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Must not call more than once");
return;
}
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
SPDK_ERRLOG("calloc() failed for target config\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Out of memory");
return;
}
conf->acceptor_poll_rate = ACCEPT_TIMEOUT_US;
conf->admin_passthru.identify_ctrlr = false;
memcpy(&conf, &g_spdk_nvmf_tgt_conf, sizeof(conf));
if (params != NULL) {
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_tgt_conf_decoder,
SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_conf_decoder), conf)) {
free(conf);
SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_conf_decoder), &conf)) {
SPDK_ERRLOG("spdk_json_decode_object() failed\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"Invalid parameters");
@ -143,7 +126,7 @@ rpc_nvmf_set_config(struct spdk_jsonrpc_request *request,
}
}
g_spdk_nvmf_tgt_conf = conf;
memcpy(&g_spdk_nvmf_tgt_conf, &conf, sizeof(conf));
w = spdk_jsonrpc_begin_result(request);
spdk_json_write_bool(w, true);

View File

@ -60,6 +60,11 @@ struct nvmf_tgt_poll_group {
TAILQ_ENTRY(nvmf_tgt_poll_group) link;
};
struct spdk_nvmf_tgt_conf g_spdk_nvmf_tgt_conf = {
.acceptor_poll_rate = ACCEPT_TIMEOUT_US,
.admin_passthru.identify_ctrlr = false
};
struct spdk_nvmf_tgt *g_spdk_nvmf_tgt = NULL;
static enum nvmf_tgt_state g_tgt_state;
@ -246,8 +251,6 @@ nvmf_tgt_destroy_done(void *ctx, int status)
{
g_tgt_state = NVMF_TGT_STOPPED;
free(g_spdk_nvmf_tgt_conf);
g_spdk_nvmf_tgt_conf = NULL;
nvmf_tgt_advance_state();
}
@ -366,7 +369,7 @@ nvmf_tgt_advance_state(void)
break;
case NVMF_TGT_INIT_CREATE_POLL_GROUPS:
/* Config parsed */
if (g_spdk_nvmf_tgt_conf->admin_passthru.identify_ctrlr) {
if (g_spdk_nvmf_tgt_conf.admin_passthru.identify_ctrlr) {
SPDK_NOTICELOG("Custom identify ctrlr handler enabled\n");
spdk_nvmf_set_custom_admin_cmd_hdlr(SPDK_NVME_OPC_IDENTIFY, nvmf_custom_identify_hdlr);
}
@ -443,10 +446,10 @@ nvmf_subsystem_write_config_json(struct spdk_json_write_ctx *w)
spdk_json_write_named_string(w, "method", "nvmf_set_config");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_uint32(w, "acceptor_poll_rate", g_spdk_nvmf_tgt_conf->acceptor_poll_rate);
spdk_json_write_named_uint32(w, "acceptor_poll_rate", g_spdk_nvmf_tgt_conf.acceptor_poll_rate);
spdk_json_write_named_object_begin(w, "admin_cmd_passthru");
spdk_json_write_named_bool(w, "identify_ctrlr",
g_spdk_nvmf_tgt_conf->admin_passthru.identify_ctrlr);
g_spdk_nvmf_tgt_conf.admin_passthru.identify_ctrlr);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);