2016-05-24 18:04:20 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk_internal/event.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
#include "spdk/env.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/conf.h"
|
2018-08-28 23:27:18 +00:00
|
|
|
#include "spdk/thread.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
#include "spdk/trace.h"
|
2017-11-09 20:20:56 +00:00
|
|
|
#include "spdk/string.h"
|
2018-05-02 04:28:57 +00:00
|
|
|
#include "spdk/rpc.h"
|
2018-08-14 15:37:17 +00:00
|
|
|
#include "spdk/util.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-08-14 16:53:07 +00:00
|
|
|
#include "json_config.h"
|
|
|
|
|
2018-03-30 22:38:22 +00:00
|
|
|
#define SPDK_APP_DEFAULT_LOG_LEVEL SPDK_LOG_NOTICE
|
|
|
|
#define SPDK_APP_DEFAULT_LOG_PRINT_LEVEL SPDK_LOG_INFO
|
2018-09-10 14:08:25 +00:00
|
|
|
#define SPDK_APP_DEFAULT_BACKTRACE_LOG_LEVEL SPDK_LOG_ERROR
|
2018-11-13 17:23:16 +00:00
|
|
|
#define SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES SPDK_DEFAULT_NUM_TRACE_ENTRIES
|
2017-01-05 00:02:01 +00:00
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
#define SPDK_APP_DPDK_DEFAULT_MEM_SIZE -1
|
|
|
|
#define SPDK_APP_DPDK_DEFAULT_MASTER_CORE -1
|
|
|
|
#define SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL -1
|
2017-01-05 00:02:01 +00:00
|
|
|
#define SPDK_APP_DPDK_DEFAULT_CORE_MASK "0x1"
|
2018-12-06 23:40:15 +00:00
|
|
|
#define SPDK_APP_DEFAULT_CORE_LIMIT 0x140000000 /* 5 GiB */
|
2017-01-05 00:02:01 +00:00
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
struct spdk_app {
|
|
|
|
struct spdk_conf *config;
|
2019-02-28 23:56:14 +00:00
|
|
|
const char *json_config_file;
|
|
|
|
const char *rpc_addr;
|
2017-02-01 21:34:45 +00:00
|
|
|
int shm_id;
|
2016-05-24 18:04:20 +00:00
|
|
|
spdk_app_shutdown_cb shutdown_cb;
|
|
|
|
int rc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spdk_app g_spdk_app;
|
2018-05-02 04:50:39 +00:00
|
|
|
static struct spdk_event *g_app_start_event = NULL;
|
2017-01-05 01:24:18 +00:00
|
|
|
static struct spdk_event *g_shutdown_event = NULL;
|
2017-10-25 13:58:02 +00:00
|
|
|
static int g_init_lcore;
|
2018-05-02 04:50:39 +00:00
|
|
|
static bool g_delay_subsystem_init = false;
|
2017-11-15 09:09:56 +00:00
|
|
|
static bool g_shutdown_sig_received = false;
|
2018-06-07 14:16:43 +00:00
|
|
|
static char *g_executable_name;
|
|
|
|
static struct spdk_app_opts g_default_opts;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
int
|
2017-02-01 21:34:45 +00:00
|
|
|
spdk_app_get_shm_id(void)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
2017-02-01 21:34:45 +00:00
|
|
|
return g_spdk_app.shm_id;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 13:26:44 +00:00
|
|
|
/* append one empty option to indicate the end of the array */
|
2018-08-14 15:37:17 +00:00
|
|
|
static const struct option g_cmdline_options[] = {
|
2018-07-31 13:26:44 +00:00
|
|
|
#define CONFIG_FILE_OPT_IDX 'c'
|
|
|
|
{"config", required_argument, NULL, CONFIG_FILE_OPT_IDX},
|
2018-08-28 19:26:23 +00:00
|
|
|
#define LIMIT_COREDUMP_OPT_IDX 'd'
|
|
|
|
{"limit-coredump", no_argument, NULL, LIMIT_COREDUMP_OPT_IDX},
|
2018-07-31 13:26:44 +00:00
|
|
|
#define TPOINT_GROUP_MASK_OPT_IDX 'e'
|
|
|
|
{"tpoint-group-mask", required_argument, NULL, TPOINT_GROUP_MASK_OPT_IDX},
|
|
|
|
#define SINGLE_FILE_SEGMENTS_OPT_IDX 'g'
|
|
|
|
{"single-file-segments", no_argument, NULL, SINGLE_FILE_SEGMENTS_OPT_IDX},
|
|
|
|
#define HELP_OPT_IDX 'h'
|
|
|
|
{"help", no_argument, NULL, HELP_OPT_IDX},
|
|
|
|
#define SHM_ID_OPT_IDX 'i'
|
|
|
|
{"shm-id", required_argument, NULL, SHM_ID_OPT_IDX},
|
|
|
|
#define CPUMASK_OPT_IDX 'm'
|
|
|
|
{"cpumask", required_argument, NULL, CPUMASK_OPT_IDX},
|
|
|
|
#define MEM_CHANNELS_OPT_IDX 'n'
|
|
|
|
{"mem-channels", required_argument, NULL, MEM_CHANNELS_OPT_IDX},
|
|
|
|
#define MASTER_CORE_OPT_IDX 'p'
|
|
|
|
{"master-core", required_argument, NULL, MASTER_CORE_OPT_IDX},
|
|
|
|
#define RPC_SOCKET_OPT_IDX 'r'
|
|
|
|
{"rpc-socket", required_argument, NULL, RPC_SOCKET_OPT_IDX},
|
|
|
|
#define MEM_SIZE_OPT_IDX 's'
|
|
|
|
{"mem-size", required_argument, NULL, MEM_SIZE_OPT_IDX},
|
|
|
|
#define NO_PCI_OPT_IDX 'u'
|
|
|
|
{"no-pci", no_argument, NULL, NO_PCI_OPT_IDX},
|
|
|
|
#define PCI_BLACKLIST_OPT_IDX 'B'
|
|
|
|
{"pci-blacklist", required_argument, NULL, PCI_BLACKLIST_OPT_IDX},
|
2018-11-27 07:50:57 +00:00
|
|
|
#define LOGFLAG_OPT_IDX 'L'
|
|
|
|
{"logflag", required_argument, NULL, LOGFLAG_OPT_IDX},
|
2018-07-31 13:26:44 +00:00
|
|
|
#define HUGE_UNLINK_OPT_IDX 'R'
|
|
|
|
{"huge-unlink", no_argument, NULL, HUGE_UNLINK_OPT_IDX},
|
|
|
|
#define PCI_WHITELIST_OPT_IDX 'W'
|
|
|
|
{"pci-whitelist", required_argument, NULL, PCI_WHITELIST_OPT_IDX},
|
2018-08-09 11:47:29 +00:00
|
|
|
#define SILENCE_NOTICELOG_OPT_IDX 257
|
|
|
|
{"silence-noticelog", no_argument, NULL, SILENCE_NOTICELOG_OPT_IDX},
|
2018-08-10 10:20:25 +00:00
|
|
|
#define WAIT_FOR_RPC_OPT_IDX 258
|
|
|
|
{"wait-for-rpc", no_argument, NULL, WAIT_FOR_RPC_OPT_IDX},
|
2018-11-06 06:10:11 +00:00
|
|
|
#define HUGE_DIR_OPT_IDX 259
|
|
|
|
{"huge-dir", no_argument, NULL, HUGE_DIR_OPT_IDX},
|
2018-11-13 17:23:16 +00:00
|
|
|
#define NUM_TRACE_ENTRIES_OPT_IDX 260
|
|
|
|
{"num-trace-entries", required_argument, NULL, NUM_TRACE_ENTRIES_OPT_IDX},
|
2018-12-13 13:21:46 +00:00
|
|
|
#define MAX_REACTOR_DELAY_OPT_IDX 261
|
|
|
|
{"max-delay", required_argument, NULL, MAX_REACTOR_DELAY_OPT_IDX},
|
2018-08-14 16:53:07 +00:00
|
|
|
#define JSON_CONFIG_OPT_IDX 262
|
|
|
|
{"json", required_argument, NULL, JSON_CONFIG_OPT_IDX},
|
2018-07-31 13:26:44 +00:00
|
|
|
};
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
/* Global section */
|
|
|
|
#define GLOBAL_CONFIG_TMPL \
|
|
|
|
"# Configuration file\n" \
|
|
|
|
"#\n" \
|
|
|
|
"# Please write all parameters using ASCII.\n" \
|
|
|
|
"# The parameter must be quoted if it includes whitespace.\n" \
|
|
|
|
"#\n" \
|
|
|
|
"# Configuration syntax:\n" \
|
|
|
|
"# Spaces at head of line are deleted, other spaces are as separator\n" \
|
|
|
|
"# Lines starting with '#' are comments and not evaluated.\n" \
|
|
|
|
"# Lines ending with '\\' are concatenated with the next line.\n" \
|
|
|
|
"# Bracketed keys are section keys grouping the following value keys.\n" \
|
|
|
|
"# Number of section key is used as a tag number.\n" \
|
|
|
|
"# Ex. [TargetNode1] = TargetNode section key with tag number 1\n" \
|
|
|
|
"[Global]\n" \
|
|
|
|
" Comment \"Global section\"\n" \
|
|
|
|
"\n" \
|
|
|
|
" # Users can restrict work items to only run on certain cores by\n" \
|
|
|
|
" # specifying a ReactorMask. Default is to allow work items to run\n" \
|
|
|
|
" # on all cores. Core 0 must be set in the mask if one is specified.\n" \
|
|
|
|
" # Default: 0xFFFF (cores 0-15)\n" \
|
2017-12-21 16:48:31 +00:00
|
|
|
" ReactorMask \"0x%s\"\n" \
|
2016-05-24 18:04:20 +00:00
|
|
|
"\n" \
|
|
|
|
" # Tracepoint group mask for spdk trace buffers\n" \
|
|
|
|
" # Default: 0x0 (all tracepoint groups disabled)\n" \
|
2018-08-16 05:01:26 +00:00
|
|
|
" # Set to 0xFFFF to enable all tracepoint groups.\n" \
|
2016-05-24 18:04:20 +00:00
|
|
|
" TpointGroupMask \"0x%" PRIX64 "\"\n" \
|
|
|
|
"\n" \
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_app_config_dump_global_section(FILE *fp)
|
|
|
|
{
|
2017-12-21 16:48:31 +00:00
|
|
|
struct spdk_cpuset *coremask;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (NULL == fp) {
|
2016-05-24 18:04:20 +00:00
|
|
|
return;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-12-21 16:48:31 +00:00
|
|
|
coremask = spdk_app_get_core_mask();
|
|
|
|
|
|
|
|
fprintf(fp, GLOBAL_CONFIG_TMPL, spdk_cpuset_fmt(coremask),
|
|
|
|
spdk_trace_get_tpoint_group_mask());
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_app_get_running_config(char **config_str, char *name)
|
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
|
|
|
int fd = -1;
|
|
|
|
long length = 0, ret = 0;
|
|
|
|
char vbuf[BUFSIZ];
|
|
|
|
char config_template[64];
|
|
|
|
|
|
|
|
snprintf(config_template, sizeof(config_template), "/tmp/%s.XXXXXX", name);
|
|
|
|
/* Create temporary file to hold config */
|
|
|
|
fd = mkstemp(config_template);
|
|
|
|
if (fd == -1) {
|
2017-04-17 19:24:04 +00:00
|
|
|
SPDK_ERRLOG("mkstemp failed\n");
|
2016-05-24 18:04:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fp = fdopen(fd, "wb+");
|
|
|
|
if (NULL == fp) {
|
2017-04-17 19:24:04 +00:00
|
|
|
SPDK_ERRLOG("error opening tmpfile fd = %d\n", fd);
|
2016-05-24 18:04:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Buffered IO */
|
|
|
|
setvbuf(fp, vbuf, _IOFBF, BUFSIZ);
|
|
|
|
|
|
|
|
spdk_app_config_dump_global_section(fp);
|
|
|
|
spdk_subsystem_config(fp);
|
|
|
|
|
|
|
|
length = ftell(fp);
|
|
|
|
|
|
|
|
*config_str = malloc(length + 1);
|
|
|
|
if (!*config_str) {
|
2017-12-14 00:32:48 +00:00
|
|
|
SPDK_ERRLOG("out-of-memory for config\n");
|
2016-05-24 18:04:20 +00:00
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
ret = fread(*config_str, sizeof(char), length, fp);
|
2017-12-07 23:23:48 +00:00
|
|
|
if (ret < length) {
|
2017-04-17 19:24:04 +00:00
|
|
|
SPDK_ERRLOG("short read\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
fclose(fp);
|
|
|
|
(*config_str)[length] = '\0';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-03 21:26:45 +00:00
|
|
|
void
|
|
|
|
spdk_app_start_shutdown(void)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
|
|
|
if (g_shutdown_event != NULL) {
|
|
|
|
spdk_event_call(g_shutdown_event);
|
2016-11-03 21:26:45 +00:00
|
|
|
g_shutdown_event = NULL;
|
2017-08-01 19:47:58 +00:00
|
|
|
} else {
|
|
|
|
spdk_app_stop(0);
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 21:26:45 +00:00
|
|
|
static void
|
|
|
|
__shutdown_signal(int signo)
|
|
|
|
{
|
2017-11-15 09:09:56 +00:00
|
|
|
if (!g_shutdown_sig_received) {
|
|
|
|
g_shutdown_sig_received = true;
|
|
|
|
spdk_app_start_shutdown();
|
|
|
|
}
|
2016-11-03 21:26:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
static void
|
2017-01-05 01:19:02 +00:00
|
|
|
__shutdown_event_cb(void *arg1, void *arg2)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
|
|
|
g_spdk_app.shutdown_cb();
|
|
|
|
}
|
|
|
|
|
2018-08-20 22:58:51 +00:00
|
|
|
static int
|
|
|
|
spdk_app_opts_validate(const char *app_opts)
|
|
|
|
{
|
|
|
|
int i = 0, j;
|
|
|
|
|
|
|
|
for (i = 0; app_opts[i] != '\0'; i++) {
|
|
|
|
/* ignore getopt control characters */
|
|
|
|
if (app_opts[i] == ':' || app_opts[i] == '+' || app_opts[i] == '-') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; SPDK_APP_GETOPT_STRING[j] != '\0'; j++) {
|
|
|
|
if (app_opts[i] == SPDK_APP_GETOPT_STRING[j]) {
|
|
|
|
return app_opts[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
void
|
|
|
|
spdk_app_opts_init(struct spdk_app_opts *opts)
|
|
|
|
{
|
2017-12-07 23:23:48 +00:00
|
|
|
if (!opts) {
|
2016-05-24 18:04:20 +00:00
|
|
|
return;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
memset(opts, 0, sizeof(*opts));
|
|
|
|
|
|
|
|
opts->enable_coredump = true;
|
2017-02-01 21:34:45 +00:00
|
|
|
opts->shm_id = -1;
|
2017-06-16 08:41:13 +00:00
|
|
|
opts->mem_size = SPDK_APP_DPDK_DEFAULT_MEM_SIZE;
|
|
|
|
opts->master_core = SPDK_APP_DPDK_DEFAULT_MASTER_CORE;
|
|
|
|
opts->mem_channel = SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL;
|
2016-06-12 11:34:00 +00:00
|
|
|
opts->reactor_mask = NULL;
|
2018-03-30 22:38:22 +00:00
|
|
|
opts->print_level = SPDK_APP_DEFAULT_LOG_PRINT_LEVEL;
|
2017-11-09 23:33:29 +00:00
|
|
|
opts->rpc_addr = SPDK_DEFAULT_RPC_ADDR;
|
2018-11-13 17:23:16 +00:00
|
|
|
opts->num_entries = SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES;
|
2018-05-02 04:50:39 +00:00
|
|
|
opts->delay_subsystem_init = false;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 17:33:41 +00:00
|
|
|
static int
|
|
|
|
spdk_app_setup_signal_handlers(struct spdk_app_opts *opts)
|
|
|
|
{
|
|
|
|
struct sigaction sigact;
|
|
|
|
sigset_t sigmask;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Set up custom shutdown handling if the user requested it. */
|
|
|
|
if (opts->shutdown_cb != NULL) {
|
|
|
|
g_shutdown_event = spdk_event_allocate(spdk_env_get_current_core(),
|
|
|
|
__shutdown_event_cb,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
memset(&sigact, 0, sizeof(sigact));
|
|
|
|
sigemptyset(&sigact.sa_mask);
|
|
|
|
|
|
|
|
sigact.sa_handler = SIG_IGN;
|
|
|
|
rc = sigaction(SIGPIPE, &sigact, NULL);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Install the same handler for SIGINT and SIGTERM */
|
|
|
|
sigact.sa_handler = __shutdown_signal;
|
|
|
|
|
|
|
|
rc = sigaction(SIGINT, &sigact, NULL);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("sigaction(SIGINT) failed\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
|
|
|
|
rc = sigaction(SIGTERM, &sigact, NULL);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
sigaddset(&sigmask, SIGTERM);
|
|
|
|
|
|
|
|
if (opts->usr1_handler != NULL) {
|
|
|
|
sigact.sa_handler = opts->usr1_handler;
|
|
|
|
rc = sigaction(SIGUSR1, &sigact, NULL);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("sigaction(SIGUSR1) failed\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
sigaddset(&sigmask, SIGUSR1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:31:15 +00:00
|
|
|
static void
|
2018-05-02 04:28:57 +00:00
|
|
|
spdk_app_start_application(void)
|
|
|
|
{
|
|
|
|
spdk_rpc_set_state(SPDK_RPC_RUNTIME);
|
2018-05-02 04:50:39 +00:00
|
|
|
spdk_event_call(g_app_start_event);
|
2018-05-02 04:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_app_start_rpc(void *arg1, void *arg2)
|
2017-11-06 16:31:15 +00:00
|
|
|
{
|
2019-02-28 23:56:14 +00:00
|
|
|
spdk_rpc_initialize(g_spdk_app.rpc_addr);
|
2018-05-02 04:50:39 +00:00
|
|
|
if (!g_delay_subsystem_init) {
|
|
|
|
spdk_app_start_application();
|
|
|
|
}
|
2017-11-06 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 16:53:07 +00:00
|
|
|
static void
|
2019-02-28 23:56:14 +00:00
|
|
|
_spdk_app_json_config_load(void *arg1, void *arg2)
|
2018-08-14 16:53:07 +00:00
|
|
|
{
|
2019-02-28 23:56:14 +00:00
|
|
|
struct spdk_event *event_done = arg1;
|
2018-08-14 16:53:07 +00:00
|
|
|
|
2019-02-28 23:56:14 +00:00
|
|
|
spdk_app_json_config_load(g_spdk_app.json_config_file, g_spdk_app.rpc_addr, event_done);
|
2018-08-14 16:53:07 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 09:27:27 +00:00
|
|
|
static struct spdk_conf *
|
|
|
|
spdk_app_setup_conf(const char *config_file)
|
|
|
|
{
|
|
|
|
struct spdk_conf *config;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
config = spdk_conf_allocate();
|
|
|
|
assert(config != NULL);
|
|
|
|
if (config_file) {
|
|
|
|
rc = spdk_conf_read(config, config_file);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Could not read config file %s\n", config_file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (spdk_conf_first_section(config) == NULL) {
|
|
|
|
SPDK_ERRLOG("Invalid config file %s\n", config_file);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spdk_conf_set_as_default(config);
|
|
|
|
return config;
|
|
|
|
|
|
|
|
error:
|
|
|
|
spdk_conf_free(config);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:39:37 +00:00
|
|
|
static int
|
|
|
|
spdk_app_opts_add_pci_addr(struct spdk_app_opts *opts, struct spdk_pci_addr **list, char *bdf)
|
|
|
|
{
|
|
|
|
struct spdk_pci_addr *tmp = *list;
|
|
|
|
size_t i = opts->num_pci_addr;
|
|
|
|
|
|
|
|
tmp = realloc(tmp, sizeof(*tmp) * (i + 1));
|
|
|
|
if (tmp == NULL) {
|
|
|
|
SPDK_ERRLOG("realloc error\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
*list = tmp;
|
|
|
|
if (spdk_pci_addr_parse(*list + i, bdf) < 0) {
|
|
|
|
SPDK_ERRLOG("Invalid address %s\n", bdf);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->num_pci_addr++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-03-30 09:28:17 +00:00
|
|
|
spdk_app_read_config_file_global_params(struct spdk_app_opts *opts)
|
|
|
|
{
|
|
|
|
struct spdk_conf_section *sp;
|
2018-03-30 17:39:37 +00:00
|
|
|
char *bdf;
|
|
|
|
int i, rc = 0;
|
2018-03-30 09:28:17 +00:00
|
|
|
|
|
|
|
sp = spdk_conf_find_section(NULL, "Global");
|
|
|
|
|
|
|
|
if (opts->shm_id == -1) {
|
|
|
|
if (sp != NULL) {
|
|
|
|
opts->shm_id = spdk_conf_section_get_intval(sp, "SharedMemoryID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->reactor_mask == NULL) {
|
|
|
|
if (sp && spdk_conf_section_get_val(sp, "ReactorMask")) {
|
2018-08-28 23:36:46 +00:00
|
|
|
SPDK_ERRLOG("ReactorMask config option is deprecated. Use -m/--cpumask\n"
|
|
|
|
"command line parameter instead.\n");
|
2018-03-30 09:28:17 +00:00
|
|
|
opts->reactor_mask = spdk_conf_section_get_val(sp, "ReactorMask");
|
|
|
|
} else {
|
|
|
|
opts->reactor_mask = SPDK_APP_DPDK_DEFAULT_CORE_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts->no_pci && sp) {
|
|
|
|
opts->no_pci = spdk_conf_section_get_boolval(sp, "NoPci", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->tpoint_group_mask == NULL) {
|
|
|
|
if (sp != NULL) {
|
|
|
|
opts->tpoint_group_mask = spdk_conf_section_get_val(sp, "TpointGroupMask");
|
|
|
|
}
|
|
|
|
}
|
2018-03-30 17:39:37 +00:00
|
|
|
|
|
|
|
if (sp == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
bdf = spdk_conf_section_get_nmval(sp, "PciBlacklist", i, 0);
|
|
|
|
if (!bdf) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_app_opts_add_pci_addr(opts, &opts->pci_blacklist, bdf);
|
|
|
|
if (rc != 0) {
|
|
|
|
free(opts->pci_blacklist);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
bdf = spdk_conf_section_get_nmval(sp, "PciWhitelist", i, 0);
|
|
|
|
if (!bdf) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->pci_blacklist != NULL) {
|
|
|
|
SPDK_ERRLOG("PciBlacklist and PciWhitelist cannot be used at the same time\n");
|
|
|
|
free(opts->pci_blacklist);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_app_opts_add_pci_addr(opts, &opts->pci_whitelist, bdf);
|
|
|
|
if (rc != 0) {
|
|
|
|
free(opts->pci_whitelist);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2018-03-30 09:28:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
static int
|
|
|
|
spdk_app_setup_env(struct spdk_app_opts *opts)
|
|
|
|
{
|
|
|
|
struct spdk_env_opts env_opts = {};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spdk_env_opts_init(&env_opts);
|
|
|
|
|
|
|
|
env_opts.name = opts->name;
|
|
|
|
env_opts.core_mask = opts->reactor_mask;
|
|
|
|
env_opts.shm_id = opts->shm_id;
|
|
|
|
env_opts.mem_channel = opts->mem_channel;
|
|
|
|
env_opts.master_core = opts->master_core;
|
|
|
|
env_opts.mem_size = opts->mem_size;
|
2018-05-31 22:56:16 +00:00
|
|
|
env_opts.hugepage_single_segments = opts->hugepage_single_segments;
|
2018-07-12 07:58:59 +00:00
|
|
|
env_opts.unlink_hugepage = opts->unlink_hugepage;
|
2018-11-06 06:10:11 +00:00
|
|
|
env_opts.hugedir = opts->hugedir;
|
2018-04-02 00:47:59 +00:00
|
|
|
env_opts.no_pci = opts->no_pci;
|
2018-03-30 17:39:37 +00:00
|
|
|
env_opts.num_pci_addr = opts->num_pci_addr;
|
|
|
|
env_opts.pci_blacklist = opts->pci_blacklist;
|
|
|
|
env_opts.pci_whitelist = opts->pci_whitelist;
|
2018-04-02 00:47:59 +00:00
|
|
|
|
|
|
|
rc = spdk_env_init(&env_opts);
|
2018-03-30 17:39:37 +00:00
|
|
|
free(env_opts.pci_blacklist);
|
|
|
|
free(env_opts.pci_whitelist);
|
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
if (rc < 0) {
|
2018-08-28 07:23:36 +00:00
|
|
|
fprintf(stderr, "Unable to initialize SPDK env\n");
|
2018-04-02 00:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:12:05 +00:00
|
|
|
static int
|
|
|
|
spdk_app_setup_trace(struct spdk_app_opts *opts)
|
|
|
|
{
|
|
|
|
char shm_name[64];
|
|
|
|
uint64_t tpoint_group_mask;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
if (opts->shm_id >= 0) {
|
|
|
|
snprintf(shm_name, sizeof(shm_name), "/%s_trace.%d", opts->name, opts->shm_id);
|
|
|
|
} else {
|
|
|
|
snprintf(shm_name, sizeof(shm_name), "/%s_trace.pid%d", opts->name, (int)getpid());
|
|
|
|
}
|
|
|
|
|
2018-11-13 17:23:16 +00:00
|
|
|
if (spdk_trace_init(shm_name, opts->num_entries) != 0) {
|
2018-04-02 01:12:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->tpoint_group_mask != NULL) {
|
|
|
|
errno = 0;
|
|
|
|
tpoint_group_mask = strtoull(opts->tpoint_group_mask, &end, 16);
|
|
|
|
if (*end != '\0' || errno) {
|
|
|
|
SPDK_ERRLOG("invalid tpoint mask %s\n", opts->tpoint_group_mask);
|
|
|
|
} else {
|
|
|
|
SPDK_NOTICELOG("Tracepoint Group Mask %s specified.\n", opts->tpoint_group_mask);
|
|
|
|
SPDK_NOTICELOG("Use 'spdk_trace -s %s %s %d' to capture a snapshot of events at runtime.\n",
|
|
|
|
opts->name,
|
|
|
|
opts->shm_id >= 0 ? "-i" : "-p",
|
|
|
|
opts->shm_id >= 0 ? opts->shm_id : getpid());
|
2018-09-04 19:07:34 +00:00
|
|
|
#if defined(__linux__)
|
|
|
|
SPDK_NOTICELOG("Or copy /dev/shm%s for offline analysis/debug.\n", shm_name);
|
|
|
|
#endif
|
2018-04-02 01:12:05 +00:00
|
|
|
spdk_trace_set_tpoint_group_mask(tpoint_group_mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-28 23:39:52 +00:00
|
|
|
static void
|
|
|
|
bootstrap_fn(void *arg1, void *arg2)
|
|
|
|
{
|
2019-03-01 00:00:55 +00:00
|
|
|
struct spdk_event *rpc_start_event;
|
|
|
|
struct spdk_event *config_load_event;
|
|
|
|
|
|
|
|
rpc_start_event = spdk_event_allocate(g_init_lcore, spdk_app_start_rpc,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (g_spdk_app.json_config_file) {
|
|
|
|
g_delay_subsystem_init = false;
|
|
|
|
config_load_event = spdk_event_allocate(g_init_lcore, _spdk_app_json_config_load,
|
|
|
|
rpc_start_event, NULL);
|
|
|
|
spdk_event_call(config_load_event);
|
2019-02-28 23:39:52 +00:00
|
|
|
} else {
|
|
|
|
if (!g_delay_subsystem_init) {
|
2019-03-01 00:00:55 +00:00
|
|
|
spdk_subsystem_init(rpc_start_event);
|
2019-02-28 23:39:52 +00:00
|
|
|
} else {
|
2019-03-01 00:00:55 +00:00
|
|
|
spdk_event_call(rpc_start_event);
|
2019-02-28 23:39:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
int
|
|
|
|
spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
|
2019-02-28 21:42:07 +00:00
|
|
|
void *arg1)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
2018-03-30 09:28:17 +00:00
|
|
|
struct spdk_conf *config = NULL;
|
2016-05-24 18:04:20 +00:00
|
|
|
int rc;
|
2018-08-30 08:47:56 +00:00
|
|
|
char *tty;
|
2019-02-28 23:39:52 +00:00
|
|
|
struct spdk_event *event;
|
2017-06-06 06:31:47 +00:00
|
|
|
|
|
|
|
if (!opts) {
|
|
|
|
SPDK_ERRLOG("opts should not be NULL\n");
|
2018-06-27 11:09:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!start_fn) {
|
|
|
|
SPDK_ERRLOG("start_fn should not be NULL\n");
|
2018-02-22 23:50:51 +00:00
|
|
|
return 1;
|
2017-06-06 06:31:47 +00:00
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-08-30 08:47:56 +00:00
|
|
|
tty = ttyname(STDERR_FILENO);
|
2017-11-03 23:16:34 +00:00
|
|
|
if (opts->print_level > SPDK_LOG_WARN &&
|
|
|
|
isatty(STDERR_FILENO) &&
|
2018-08-30 08:47:56 +00:00
|
|
|
tty &&
|
|
|
|
!strncmp(tty, "/dev/tty", strlen("/dev/tty"))) {
|
2017-11-03 23:16:34 +00:00
|
|
|
printf("Warning: printing stderr to console terminal without -q option specified.\n");
|
2018-08-09 11:47:29 +00:00
|
|
|
printf("Suggest using --silence-noticelog to disable logging to stderr and\n");
|
|
|
|
printf("monitor syslog, or redirect stderr to a file.\n");
|
2017-11-03 23:16:34 +00:00
|
|
|
printf("(Delaying for 10 seconds...)\n");
|
|
|
|
sleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_log_set_print_level(opts->print_level);
|
|
|
|
|
2017-04-29 02:13:48 +00:00
|
|
|
#ifndef SPDK_NO_RLIMIT
|
2016-05-24 18:04:20 +00:00
|
|
|
if (opts->enable_coredump) {
|
|
|
|
struct rlimit core_limits;
|
|
|
|
|
2018-12-06 23:40:15 +00:00
|
|
|
core_limits.rlim_cur = core_limits.rlim_max = SPDK_APP_DEFAULT_CORE_LIMIT;
|
2016-05-24 18:04:20 +00:00
|
|
|
setrlimit(RLIMIT_CORE, &core_limits);
|
|
|
|
}
|
2017-04-29 02:13:48 +00:00
|
|
|
#endif
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-03-30 09:27:27 +00:00
|
|
|
config = spdk_app_setup_conf(opts->config_file);
|
|
|
|
if (config == NULL) {
|
|
|
|
goto app_start_setup_conf_err;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:39:37 +00:00
|
|
|
if (spdk_app_read_config_file_global_params(opts) < 0) {
|
|
|
|
goto app_start_setup_conf_err;
|
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-03-30 22:38:22 +00:00
|
|
|
spdk_log_set_level(SPDK_APP_DEFAULT_LOG_LEVEL);
|
2018-09-10 14:08:25 +00:00
|
|
|
spdk_log_set_backtrace_level(SPDK_APP_DEFAULT_BACKTRACE_LOG_LEVEL);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
if (spdk_app_setup_env(opts) < 0) {
|
2018-08-28 07:23:36 +00:00
|
|
|
goto app_start_setup_conf_err;
|
2017-12-18 19:57:01 +00:00
|
|
|
}
|
2016-06-12 11:34:00 +00:00
|
|
|
|
2018-08-28 07:23:36 +00:00
|
|
|
spdk_log_open();
|
2017-12-14 23:58:00 +00:00
|
|
|
SPDK_NOTICELOG("Total cores available: %d\n", spdk_env_get_core_count());
|
2017-08-03 01:55:44 +00:00
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
/*
|
|
|
|
* If mask not specified on command line or in configuration file,
|
2016-10-20 16:37:05 +00:00
|
|
|
* reactor_mask will be 0x1 which will enable core 0 to run one
|
|
|
|
* reactor.
|
2016-05-24 18:04:20 +00:00
|
|
|
*/
|
2019-02-13 16:56:13 +00:00
|
|
|
if ((rc = spdk_reactors_init()) != 0) {
|
2019-01-17 16:11:38 +00:00
|
|
|
SPDK_ERRLOG("Reactor Initilization failed: rc = %d\n", rc);
|
2018-03-09 17:08:57 +00:00
|
|
|
goto app_start_log_close_err;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 17:08:57 +00:00
|
|
|
/*
|
2018-04-02 01:12:05 +00:00
|
|
|
* Note the call to spdk_app_setup_trace() is located here
|
2018-03-09 17:08:57 +00:00
|
|
|
* ahead of spdk_app_setup_signal_handlers().
|
|
|
|
* That's because there is not an easy/direct clean
|
|
|
|
* way of unwinding alloc'd resources that can occur
|
|
|
|
* in spdk_app_setup_signal_handlers().
|
|
|
|
*/
|
2018-04-02 01:12:05 +00:00
|
|
|
if (spdk_app_setup_trace(opts) != 0) {
|
2018-03-09 17:08:57 +00:00
|
|
|
goto app_start_log_close_err;
|
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-03-09 17:08:57 +00:00
|
|
|
if ((rc = spdk_app_setup_signal_handlers(opts)) != 0) {
|
|
|
|
goto app_start_trace_cleanup_err;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:14:15 +00:00
|
|
|
memset(&g_spdk_app, 0, sizeof(g_spdk_app));
|
|
|
|
g_spdk_app.config = config;
|
2019-02-28 23:56:14 +00:00
|
|
|
g_spdk_app.json_config_file = opts->json_config_file;
|
|
|
|
g_spdk_app.rpc_addr = opts->rpc_addr;
|
2018-03-19 16:14:15 +00:00
|
|
|
g_spdk_app.shm_id = opts->shm_id;
|
|
|
|
g_spdk_app.shutdown_cb = opts->shutdown_cb;
|
2017-06-06 06:31:47 +00:00
|
|
|
g_spdk_app.rc = 0;
|
2017-10-25 13:58:02 +00:00
|
|
|
g_init_lcore = spdk_env_get_current_core();
|
2018-05-02 04:50:39 +00:00
|
|
|
g_delay_subsystem_init = opts->delay_subsystem_init;
|
|
|
|
|
2019-02-28 23:39:52 +00:00
|
|
|
event = spdk_event_allocate(g_init_lcore, bootstrap_fn, NULL, NULL);
|
|
|
|
g_app_start_event = spdk_event_allocate(g_init_lcore, start_fn, arg1, NULL);
|
2017-06-06 06:31:47 +00:00
|
|
|
|
2019-02-28 23:39:52 +00:00
|
|
|
spdk_event_call(event);
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
/* This blocks until spdk_app_stop is called */
|
|
|
|
spdk_reactors_start();
|
|
|
|
|
|
|
|
return g_spdk_app.rc;
|
2018-03-09 17:08:57 +00:00
|
|
|
|
|
|
|
app_start_trace_cleanup_err:
|
|
|
|
spdk_trace_cleanup();
|
|
|
|
|
|
|
|
app_start_log_close_err:
|
|
|
|
spdk_log_close();
|
|
|
|
|
2018-03-30 09:27:27 +00:00
|
|
|
app_start_setup_conf_err:
|
2018-03-09 17:08:57 +00:00
|
|
|
return 1;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 14:15:17 +00:00
|
|
|
void
|
2016-05-24 18:04:20 +00:00
|
|
|
spdk_app_fini(void)
|
|
|
|
{
|
|
|
|
spdk_trace_cleanup();
|
2017-02-24 23:27:42 +00:00
|
|
|
spdk_reactors_fini();
|
2016-05-24 18:04:20 +00:00
|
|
|
spdk_conf_free(g_spdk_app.config);
|
2017-06-13 18:16:15 +00:00
|
|
|
spdk_log_close();
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 13:58:02 +00:00
|
|
|
static void
|
|
|
|
_spdk_app_stop(void *arg1, void *arg2)
|
|
|
|
{
|
|
|
|
struct spdk_event *app_stop_event;
|
|
|
|
|
2017-11-06 16:31:15 +00:00
|
|
|
spdk_rpc_finish();
|
|
|
|
|
2017-10-25 13:58:02 +00:00
|
|
|
app_stop_event = spdk_event_allocate(spdk_env_get_current_core(), spdk_reactors_stop, NULL, NULL);
|
|
|
|
spdk_subsystem_fini(app_stop_event);
|
|
|
|
}
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
void
|
|
|
|
spdk_app_stop(int rc)
|
|
|
|
{
|
2018-02-22 23:50:51 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_WARNLOG("spdk_app_stop'd on non-zero\n");
|
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
g_spdk_app.rc = rc;
|
2017-10-25 13:58:02 +00:00
|
|
|
/*
|
|
|
|
* We want to run spdk_subsystem_fini() from the same lcore where spdk_subsystem_init()
|
|
|
|
* was called.
|
|
|
|
*/
|
|
|
|
spdk_event_call(spdk_event_allocate(g_init_lcore, _spdk_app_stop, NULL, NULL));
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
|
|
|
|
static void
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(void (*app_usage)(void))
|
2017-11-09 20:20:56 +00:00
|
|
|
{
|
2018-06-07 14:16:43 +00:00
|
|
|
printf("%s [options]\n", g_executable_name);
|
2017-11-09 20:20:56 +00:00
|
|
|
printf("options:\n");
|
2018-11-08 13:12:07 +00:00
|
|
|
printf(" -c, --config <config> config file (default %s)\n",
|
|
|
|
g_default_opts.config_file != NULL ? g_default_opts.config_file : "none");
|
2018-08-14 16:53:07 +00:00
|
|
|
printf(" --json <config> JSON config file (default %s)\n",
|
|
|
|
g_default_opts.json_config_file != NULL ? g_default_opts.json_config_file : "none");
|
2018-07-31 13:26:44 +00:00
|
|
|
printf(" -d, --limit-coredump do not set max coredump size to RLIM_INFINITY\n");
|
|
|
|
printf(" -g, --single-file-segments\n");
|
|
|
|
printf(" force creating just one hugetlbfs file\n");
|
|
|
|
printf(" -h, --help show this usage\n");
|
|
|
|
printf(" -i, --shm-id <id> shared memory ID (optional)\n");
|
|
|
|
printf(" -m, --cpumask <mask> core mask for DPDK\n");
|
|
|
|
printf(" -n, --mem-channels <num> channel number of memory channels used for DPDK\n");
|
|
|
|
printf(" -p, --master-core <id> master (primary) core for DPDK\n");
|
|
|
|
printf(" -r, --rpc-socket <path> RPC listen address (default %s)\n", SPDK_DEFAULT_RPC_ADDR);
|
|
|
|
printf(" -s, --mem-size <size> memory size in MB for DPDK (default: ");
|
2018-11-06 16:40:11 +00:00
|
|
|
#ifndef __linux__
|
|
|
|
if (g_default_opts.mem_size <= 0) {
|
2017-11-09 20:20:56 +00:00
|
|
|
printf("all hugepage memory)\n");
|
2018-11-06 16:40:11 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2018-11-08 13:12:07 +00:00
|
|
|
printf("%dMB)\n", g_default_opts.mem_size >= 0 ? g_default_opts.mem_size : 0);
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
2018-08-16 11:43:38 +00:00
|
|
|
printf(" --silence-noticelog disable notice level logging to stderr\n");
|
2018-07-31 13:26:44 +00:00
|
|
|
printf(" -u, --no-pci disable PCI access\n");
|
2018-08-16 11:43:38 +00:00
|
|
|
printf(" --wait-for-rpc wait for RPCs to initialize subsystems\n");
|
2018-12-13 13:21:46 +00:00
|
|
|
printf(" --max-delay <num> maximum reactor delay (in microseconds)\n");
|
2018-07-31 13:26:44 +00:00
|
|
|
printf(" -B, --pci-blacklist <bdf>\n");
|
|
|
|
printf(" pci addr to blacklist (can be used more than once)\n");
|
|
|
|
printf(" -R, --huge-unlink unlink huge files after initialization\n");
|
|
|
|
printf(" -W, --pci-whitelist <bdf>\n");
|
|
|
|
printf(" pci addr to whitelist (-B and -W cannot be used at the same time)\n");
|
2018-11-06 06:10:11 +00:00
|
|
|
printf(" --huge-dir <path> use a specific hugetlbfs mount to reserve memory from\n");
|
2018-11-15 03:01:51 +00:00
|
|
|
printf(" --num-trace-entries <num> number of trace entries for each core, must be power of 2. (default %d)\n",
|
2018-11-13 17:23:16 +00:00
|
|
|
SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
|
2018-11-27 06:57:58 +00:00
|
|
|
spdk_log_usage(stdout, "-L");
|
2018-11-29 08:11:57 +00:00
|
|
|
spdk_trace_mask_usage(stdout, "-e");
|
2018-06-07 14:16:43 +00:00
|
|
|
if (app_usage) {
|
|
|
|
app_usage();
|
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 23:50:51 +00:00
|
|
|
spdk_app_parse_args_rvals_t
|
2017-11-09 20:20:56 +00:00
|
|
|
spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
2018-07-31 13:26:44 +00:00
|
|
|
const char *app_getopt_str, struct option *app_long_opts,
|
2019-01-08 19:40:06 +00:00
|
|
|
int (*app_parse)(int ch, char *arg),
|
2017-11-09 20:20:56 +00:00
|
|
|
void (*app_usage)(void))
|
|
|
|
{
|
2018-07-31 13:26:44 +00:00
|
|
|
int ch, rc, opt_idx, global_long_opts_len, app_long_opts_len;
|
2018-08-14 15:37:17 +00:00
|
|
|
struct option *cmdline_options;
|
|
|
|
char *cmdline_short_opts = NULL;
|
2018-08-31 16:36:52 +00:00
|
|
|
enum spdk_app_parse_args_rvals retval = SPDK_APP_PARSE_ARGS_FAIL;
|
2019-01-29 03:05:40 +00:00
|
|
|
long int tmp;
|
2017-11-09 20:20:56 +00:00
|
|
|
|
2018-06-07 14:16:43 +00:00
|
|
|
memcpy(&g_default_opts, opts, sizeof(g_default_opts));
|
2017-11-09 20:20:56 +00:00
|
|
|
|
2018-08-14 16:53:07 +00:00
|
|
|
if (opts->config_file && access(opts->config_file, R_OK) != 0) {
|
|
|
|
SPDK_WARNLOG("Can't read legacy configuration file '%s'\n", opts->config_file);
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->config_file = NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-14 16:53:07 +00:00
|
|
|
if (opts->json_config_file && access(opts->json_config_file, R_OK) != 0) {
|
|
|
|
SPDK_WARNLOG("Can't read JSON configuration file '%s'\n", opts->json_config_file);
|
|
|
|
opts->json_config_file = NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:26:44 +00:00
|
|
|
if (app_long_opts == NULL) {
|
|
|
|
app_long_opts_len = 0;
|
|
|
|
} else {
|
|
|
|
for (app_long_opts_len = 0;
|
|
|
|
app_long_opts[app_long_opts_len].name != NULL;
|
|
|
|
app_long_opts_len++);
|
|
|
|
}
|
|
|
|
|
2018-08-14 15:37:17 +00:00
|
|
|
global_long_opts_len = SPDK_COUNTOF(g_cmdline_options);
|
2018-07-31 13:26:44 +00:00
|
|
|
|
2018-08-14 15:37:17 +00:00
|
|
|
cmdline_options = calloc(global_long_opts_len + app_long_opts_len + 1, sizeof(*cmdline_options));
|
|
|
|
if (!cmdline_options) {
|
|
|
|
fprintf(stderr, "Out of memory\n");
|
|
|
|
return SPDK_APP_PARSE_ARGS_FAIL;
|
2018-07-31 13:26:44 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 15:37:17 +00:00
|
|
|
memcpy(&cmdline_options[0], g_cmdline_options, sizeof(g_cmdline_options));
|
2018-07-31 13:26:44 +00:00
|
|
|
if (app_long_opts) {
|
2018-08-14 15:37:17 +00:00
|
|
|
memcpy(&cmdline_options[global_long_opts_len], app_long_opts,
|
2018-07-31 13:26:44 +00:00
|
|
|
app_long_opts_len * sizeof(*app_long_opts));
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 22:58:51 +00:00
|
|
|
if (app_getopt_str != NULL) {
|
|
|
|
ch = spdk_app_opts_validate(app_getopt_str);
|
|
|
|
if (ch) {
|
|
|
|
fprintf(stderr, "Duplicated option '%c' between the generic and application specific spdk opts.\n",
|
|
|
|
ch);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-08-20 22:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-31 13:26:44 +00:00
|
|
|
|
2018-08-14 15:37:17 +00:00
|
|
|
cmdline_short_opts = spdk_sprintf_alloc("%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);
|
|
|
|
if (!cmdline_short_opts) {
|
|
|
|
fprintf(stderr, "Out of memory\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-07-31 13:26:44 +00:00
|
|
|
|
2018-06-07 14:16:43 +00:00
|
|
|
g_executable_name = argv[0];
|
|
|
|
|
2018-08-14 15:37:17 +00:00
|
|
|
while ((ch = getopt_long(argc, argv, cmdline_short_opts, cmdline_options, &opt_idx)) != -1) {
|
2017-11-09 20:20:56 +00:00
|
|
|
switch (ch) {
|
2018-07-31 13:26:44 +00:00
|
|
|
case CONFIG_FILE_OPT_IDX:
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->config_file = optarg;
|
|
|
|
break;
|
2018-08-14 16:53:07 +00:00
|
|
|
case JSON_CONFIG_OPT_IDX:
|
|
|
|
opts->json_config_file = optarg;
|
|
|
|
break;
|
2018-08-28 19:26:23 +00:00
|
|
|
case LIMIT_COREDUMP_OPT_IDX:
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->enable_coredump = false;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case TPOINT_GROUP_MASK_OPT_IDX:
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->tpoint_group_mask = optarg;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case SINGLE_FILE_SEGMENTS_OPT_IDX:
|
2018-02-23 08:19:09 +00:00
|
|
|
opts->hugepage_single_segments = true;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case HELP_OPT_IDX:
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
retval = SPDK_APP_PARSE_ARGS_HELP;
|
|
|
|
goto out;
|
2018-07-31 13:26:44 +00:00
|
|
|
case SHM_ID_OPT_IDX:
|
2019-02-15 14:45:35 +00:00
|
|
|
opts->shm_id = spdk_strtol(optarg, 0);
|
2019-01-29 03:05:40 +00:00
|
|
|
if (opts->shm_id < 0) {
|
|
|
|
fprintf(stderr, "Invalid shared memory ID %s\n", optarg);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-04-12 22:43:38 +00:00
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case CPUMASK_OPT_IDX:
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->reactor_mask = optarg;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case MEM_CHANNELS_OPT_IDX:
|
2019-02-15 14:45:35 +00:00
|
|
|
opts->mem_channel = spdk_strtol(optarg, 0);
|
2019-01-29 03:05:40 +00:00
|
|
|
if (opts->mem_channel < 0) {
|
|
|
|
fprintf(stderr, "Invalid memory channel %s\n", optarg);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-04-12 22:43:38 +00:00
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case MASTER_CORE_OPT_IDX:
|
2019-02-15 14:45:35 +00:00
|
|
|
opts->master_core = spdk_strtol(optarg, 0);
|
2019-01-29 03:05:40 +00:00
|
|
|
if (opts->master_core < 0) {
|
|
|
|
fprintf(stderr, "Invalid master core %s\n", optarg);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-04-12 22:43:38 +00:00
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case SILENCE_NOTICELOG_OPT_IDX:
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->print_level = SPDK_LOG_WARN;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case RPC_SOCKET_OPT_IDX:
|
2017-11-09 23:33:29 +00:00
|
|
|
opts->rpc_addr = optarg;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case MEM_SIZE_OPT_IDX: {
|
2017-12-13 19:21:28 +00:00
|
|
|
uint64_t mem_size_mb;
|
|
|
|
bool mem_size_has_prefix;
|
|
|
|
|
|
|
|
rc = spdk_parse_capacity(optarg, &mem_size_mb, &mem_size_has_prefix);
|
|
|
|
if (rc != 0) {
|
|
|
|
fprintf(stderr, "invalid memory pool size `-s %s`\n", optarg);
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2017-12-13 19:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mem_size_has_prefix) {
|
|
|
|
/* the mem size is in MB by default, so if a prefix was
|
|
|
|
* specified, we need to manually convert to MB.
|
|
|
|
*/
|
|
|
|
mem_size_mb /= 1024 * 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mem_size_mb > INT_MAX) {
|
|
|
|
fprintf(stderr, "invalid memory pool size `-s %s`\n", optarg);
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2017-12-13 19:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opts->mem_size = (int) mem_size_mb;
|
2017-11-09 20:20:56 +00:00
|
|
|
break;
|
2017-12-13 19:21:28 +00:00
|
|
|
}
|
2018-07-31 13:26:44 +00:00
|
|
|
case NO_PCI_OPT_IDX:
|
2018-04-12 22:46:04 +00:00
|
|
|
opts->no_pci = true;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case WAIT_FOR_RPC_OPT_IDX:
|
2018-05-02 04:50:39 +00:00
|
|
|
opts->delay_subsystem_init = true;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case PCI_BLACKLIST_OPT_IDX:
|
2018-03-30 17:39:37 +00:00
|
|
|
if (opts->pci_whitelist) {
|
|
|
|
free(opts->pci_whitelist);
|
2018-09-04 15:42:55 +00:00
|
|
|
opts->pci_whitelist = NULL;
|
2018-03-30 17:39:37 +00:00
|
|
|
fprintf(stderr, "-B and -W cannot be used at the same time\n");
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-03-30 17:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_app_opts_add_pci_addr(opts, &opts->pci_blacklist, optarg);
|
|
|
|
if (rc != 0) {
|
|
|
|
free(opts->pci_blacklist);
|
2018-09-04 15:42:55 +00:00
|
|
|
opts->pci_blacklist = NULL;
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-03-30 17:39:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-11-27 07:50:57 +00:00
|
|
|
case LOGFLAG_OPT_IDX:
|
2018-06-19 08:27:46 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
fprintf(stderr, "%s must be built with CONFIG_DEBUG=y for -L flag\n",
|
|
|
|
argv[0]);
|
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-06-19 08:27:46 +00:00
|
|
|
#else
|
2018-11-27 06:57:58 +00:00
|
|
|
rc = spdk_log_set_flag(optarg);
|
2018-06-19 08:27:46 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "unknown flag\n");
|
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-06-19 08:27:46 +00:00
|
|
|
}
|
|
|
|
opts->print_level = SPDK_LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
#endif
|
2018-07-31 13:26:44 +00:00
|
|
|
case HUGE_UNLINK_OPT_IDX:
|
2018-07-12 07:58:59 +00:00
|
|
|
opts->unlink_hugepage = true;
|
|
|
|
break;
|
2018-07-31 13:26:44 +00:00
|
|
|
case PCI_WHITELIST_OPT_IDX:
|
2018-03-30 17:39:37 +00:00
|
|
|
if (opts->pci_blacklist) {
|
|
|
|
free(opts->pci_blacklist);
|
2018-09-04 15:42:55 +00:00
|
|
|
opts->pci_blacklist = NULL;
|
2018-03-30 17:39:37 +00:00
|
|
|
fprintf(stderr, "-B and -W cannot be used at the same time\n");
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-03-30 17:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_app_opts_add_pci_addr(opts, &opts->pci_whitelist, optarg);
|
|
|
|
if (rc != 0) {
|
|
|
|
free(opts->pci_whitelist);
|
2018-09-04 15:42:55 +00:00
|
|
|
opts->pci_whitelist = NULL;
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-03-30 17:39:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-11-06 06:10:11 +00:00
|
|
|
case HUGE_DIR_OPT_IDX:
|
|
|
|
opts->hugedir = optarg;
|
|
|
|
break;
|
2018-11-13 17:23:16 +00:00
|
|
|
case NUM_TRACE_ENTRIES_OPT_IDX:
|
2019-01-29 03:05:40 +00:00
|
|
|
tmp = spdk_strtoll(optarg, 0);
|
|
|
|
if (tmp <= 0) {
|
2018-11-15 03:01:51 +00:00
|
|
|
fprintf(stderr, "Invalid num-trace-entries %s\n", optarg);
|
2018-11-13 17:23:16 +00:00
|
|
|
usage(app_usage);
|
|
|
|
goto out;
|
|
|
|
}
|
2019-01-29 03:05:40 +00:00
|
|
|
opts->num_entries = (uint64_t)tmp;
|
2018-11-15 03:01:51 +00:00
|
|
|
if (opts->num_entries & (opts->num_entries - 1)) {
|
|
|
|
fprintf(stderr, "num-trace-entries must be power of 2\n");
|
|
|
|
usage(app_usage);
|
|
|
|
goto out;
|
|
|
|
}
|
2018-11-13 17:23:16 +00:00
|
|
|
break;
|
2018-12-13 13:21:46 +00:00
|
|
|
case MAX_REACTOR_DELAY_OPT_IDX:
|
2019-02-13 16:56:13 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Deprecation warning: The maximum allowed latency parameter is no longer supported.\n");
|
2018-12-13 13:21:46 +00:00
|
|
|
break;
|
2017-11-09 20:20:56 +00:00
|
|
|
case '?':
|
2018-02-22 23:50:51 +00:00
|
|
|
/*
|
|
|
|
* In the event getopt() above detects an option
|
|
|
|
* in argv that is NOT in the getopt_str,
|
|
|
|
* getopt() will return a '?' indicating failure.
|
|
|
|
*/
|
2018-06-07 14:16:43 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2017-11-09 20:20:56 +00:00
|
|
|
default:
|
2019-01-08 19:40:06 +00:00
|
|
|
rc = app_parse(ch, optarg);
|
|
|
|
if (rc) {
|
|
|
|
fprintf(stderr, "Parsing application specific arguments failed: %d\n", rc);
|
|
|
|
goto out;
|
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 16:53:07 +00:00
|
|
|
if (opts->config_file && opts->json_config_file) {
|
|
|
|
fprintf(stderr, "ERROR: Legacy config and JSON config can't be used together.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->json_config_file && opts->delay_subsystem_init) {
|
|
|
|
fprintf(stderr, "ERROR: JSON configuration file can't be used together with --wait-for-rpc.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
/* TBD: Replace warning by failure when RPCs for startup are prepared. */
|
|
|
|
if (opts->config_file && opts->delay_subsystem_init) {
|
|
|
|
fprintf(stderr,
|
2018-08-10 10:20:25 +00:00
|
|
|
"WARNING: --wait-for-rpc and config file are used at the same time. "
|
2018-05-02 04:50:39 +00:00
|
|
|
"- Please be careful one options might overwrite others.\n");
|
|
|
|
}
|
|
|
|
|
2018-08-31 16:36:52 +00:00
|
|
|
retval = SPDK_APP_PARSE_ARGS_SUCCESS;
|
|
|
|
out:
|
2018-09-04 15:42:55 +00:00
|
|
|
if (retval != SPDK_APP_PARSE_ARGS_SUCCESS) {
|
|
|
|
free(opts->pci_blacklist);
|
|
|
|
opts->pci_blacklist = NULL;
|
|
|
|
free(opts->pci_whitelist);
|
|
|
|
opts->pci_whitelist = NULL;
|
|
|
|
}
|
2018-08-14 15:37:17 +00:00
|
|
|
free(cmdline_short_opts);
|
|
|
|
free(cmdline_options);
|
2018-08-31 16:36:52 +00:00
|
|
|
return retval;
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
2018-05-02 04:50:39 +00:00
|
|
|
|
2018-06-07 14:16:43 +00:00
|
|
|
void
|
|
|
|
spdk_app_usage(void)
|
|
|
|
{
|
|
|
|
if (g_executable_name == NULL) {
|
|
|
|
fprintf(stderr, "%s not valid before calling spdk_app_parse_args()\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usage(NULL);
|
|
|
|
}
|
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
static void
|
|
|
|
spdk_rpc_start_subsystem_init_cpl(void *arg1, void *arg2)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = arg1;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
spdk_app_start_application();
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_rpc_start_subsystem_init(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct spdk_event *cb_event;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"start_subsystem_init requires no parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb_event = spdk_event_allocate(g_init_lcore, spdk_rpc_start_subsystem_init_cpl,
|
|
|
|
request, NULL);
|
|
|
|
spdk_subsystem_init(cb_event);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("start_subsystem_init", spdk_rpc_start_subsystem_init, SPDK_RPC_STARTUP)
|
2018-11-08 20:24:50 +00:00
|
|
|
|
|
|
|
struct subsystem_init_poller_ctx {
|
|
|
|
struct spdk_poller *init_poller;
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_rpc_subsystem_init_poller_ctx(void *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct subsystem_init_poller_ctx *poller_ctx = ctx;
|
|
|
|
|
|
|
|
if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
|
|
|
|
w = spdk_jsonrpc_begin_result(poller_ctx->request);
|
2018-11-27 10:30:04 +00:00
|
|
|
if (w != NULL) {
|
2018-11-08 20:24:50 +00:00
|
|
|
spdk_json_write_bool(w, true);
|
2018-11-27 10:30:04 +00:00
|
|
|
spdk_jsonrpc_end_result(poller_ctx->request, w);
|
2018-11-08 20:24:50 +00:00
|
|
|
}
|
|
|
|
spdk_poller_unregister(&poller_ctx->init_poller);
|
|
|
|
free(poller_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_rpc_wait_subsystem_init(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct subsystem_init_poller_ctx *ctx;
|
|
|
|
|
|
|
|
if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
} else {
|
|
|
|
ctx = malloc(sizeof(struct subsystem_init_poller_ctx));
|
|
|
|
if (ctx == NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Unable to allocate memory for the request context\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->init_poller = spdk_poller_register(spdk_rpc_subsystem_init_poller_ctx, ctx, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("wait_subsystem_init", spdk_rpc_wait_subsystem_init,
|
|
|
|
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
|