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"
|
|
|
|
#include "spdk/trace.h"
|
2017-11-09 20:20:56 +00:00
|
|
|
#include "spdk/string.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
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
|
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"
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
struct spdk_app {
|
|
|
|
struct spdk_conf *config;
|
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;
|
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;
|
2017-11-15 09:09:56 +00:00
|
|
|
static bool g_shutdown_sig_received = false;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-11-06 16:31:15 +00:00
|
|
|
static spdk_event_fn g_app_start_fn;
|
|
|
|
static void *g_app_start_arg1;
|
|
|
|
static void *g_app_start_arg2;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* 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" \
|
|
|
|
" # Set to 0xFFFFFFFFFFFFFFFF to enable all tracepoint groups.\n" \
|
|
|
|
" 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-08-16 19:51:25 +00:00
|
|
|
opts->max_delay_us = 0;
|
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;
|
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
|
|
|
|
start_rpc(void *arg1, void *arg2)
|
|
|
|
{
|
2017-11-09 23:33:29 +00:00
|
|
|
const char *rpc_addr = arg1;
|
|
|
|
|
|
|
|
spdk_rpc_initialize(rpc_addr);
|
2017-11-06 16:31:15 +00:00
|
|
|
g_app_start_fn(g_app_start_arg1, g_app_start_arg2);
|
|
|
|
}
|
|
|
|
|
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 09:28:17 +00:00
|
|
|
static void
|
|
|
|
spdk_app_read_config_file_global_params(struct spdk_app_opts *opts)
|
|
|
|
{
|
|
|
|
struct spdk_conf_section *sp;
|
|
|
|
|
|
|
|
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")) {
|
|
|
|
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-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;
|
|
|
|
env_opts.no_pci = opts->no_pci;
|
|
|
|
|
|
|
|
rc = spdk_env_init(&env_opts);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to initialize SPDK env\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_trace_init(shm_name) != 0) {
|
|
|
|
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());
|
|
|
|
spdk_trace_set_tpoint_group_mask(tpoint_group_mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
int
|
|
|
|
spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
|
|
|
|
void *arg1, void *arg2)
|
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-04-02 01:12:05 +00:00
|
|
|
struct spdk_event *app_start_event;
|
2017-06-06 06:31:47 +00:00
|
|
|
|
|
|
|
if (!opts) {
|
|
|
|
SPDK_ERRLOG("opts 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
|
|
|
|
2017-11-03 23:16:34 +00:00
|
|
|
if (opts->print_level > SPDK_LOG_WARN &&
|
|
|
|
isatty(STDERR_FILENO) &&
|
|
|
|
!strncmp(ttyname(STDERR_FILENO), "/dev/tty", strlen("/dev/tty"))) {
|
|
|
|
printf("Warning: printing stderr to console terminal without -q option specified.\n");
|
|
|
|
printf("Suggest using -q to disable logging to stderr and monitor syslog, or\n");
|
|
|
|
printf("redirect stderr to a file.\n");
|
|
|
|
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;
|
|
|
|
|
|
|
|
core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY;
|
|
|
|
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 09:28:17 +00:00
|
|
|
spdk_app_read_config_file_global_params(opts);
|
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);
|
2017-06-13 18:16:15 +00:00
|
|
|
spdk_log_open();
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
if (spdk_app_setup_env(opts) < 0) {
|
2018-03-09 17:08:57 +00:00
|
|
|
goto app_start_log_close_err;
|
2017-12-18 19:57:01 +00:00
|
|
|
}
|
2016-06-12 11:34:00 +00:00
|
|
|
|
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
|
|
|
*/
|
2018-02-22 23:50:51 +00:00
|
|
|
if ((rc = spdk_reactors_init(opts->max_delay_us)) != 0) {
|
2017-04-17 19:24:04 +00:00
|
|
|
SPDK_ERRLOG("Invalid reactor mask.\n");
|
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;
|
|
|
|
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();
|
2017-11-06 16:31:15 +00:00
|
|
|
g_app_start_fn = start_fn;
|
|
|
|
g_app_start_arg1 = arg1;
|
|
|
|
g_app_start_arg2 = arg2;
|
2017-11-09 23:33:29 +00:00
|
|
|
app_start_event = spdk_event_allocate(g_init_lcore, start_rpc, (void *)opts->rpc_addr, NULL);
|
2017-06-06 06:31:47 +00:00
|
|
|
|
2017-10-16 12:05:17 +00:00
|
|
|
spdk_subsystem_init(app_start_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
|
|
|
|
usage(char *executable_name, struct spdk_app_opts *default_opts, void (*app_usage)(void))
|
|
|
|
{
|
|
|
|
printf("%s [options]\n", executable_name);
|
|
|
|
printf("options:\n");
|
|
|
|
printf(" -c config config file (default %s)\n", default_opts->config_file);
|
|
|
|
printf(" -d disable coredump file enabling\n");
|
|
|
|
printf(" -e mask tracepoint group mask for spdk trace buffers (default 0x0)\n");
|
2018-02-23 08:19:09 +00:00
|
|
|
printf(" -g force creating just one hugetlbfs file\n");
|
2017-11-09 20:20:56 +00:00
|
|
|
printf(" -h show this usage\n");
|
|
|
|
printf(" -i shared memory ID (optional)\n");
|
|
|
|
printf(" -m mask core mask for DPDK\n");
|
|
|
|
printf(" -n channel number of memory channels used for DPDK\n");
|
|
|
|
printf(" -p core master (primary) core for DPDK\n");
|
|
|
|
printf(" -q disable notice level logging to stderr\n");
|
2017-11-09 23:33:29 +00:00
|
|
|
printf(" -r RPC listen address (default %s)\n", SPDK_DEFAULT_RPC_ADDR);
|
2017-11-09 20:20:56 +00:00
|
|
|
printf(" -s size memory size in MB for DPDK (default: ");
|
|
|
|
if (default_opts->mem_size > 0) {
|
|
|
|
printf("%dMB)\n", default_opts->mem_size);
|
|
|
|
} else {
|
|
|
|
printf("all hugepage memory)\n");
|
|
|
|
}
|
2018-04-23 00:11:55 +00:00
|
|
|
printf(" -u disable PCI access.\n");
|
2017-11-09 20:20:56 +00:00
|
|
|
spdk_tracelog_usage(stdout, "-t");
|
|
|
|
app_usage();
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
const char *app_getopt_str, void (*app_parse)(int ch, char *arg),
|
|
|
|
void (*app_usage)(void))
|
|
|
|
{
|
|
|
|
int ch, rc;
|
|
|
|
struct spdk_app_opts default_opts;
|
|
|
|
char *getopt_str;
|
2018-02-22 23:50:51 +00:00
|
|
|
spdk_app_parse_args_rvals_t rval = SPDK_APP_PARSE_ARGS_SUCCESS;
|
2017-11-09 20:20:56 +00:00
|
|
|
|
|
|
|
memcpy(&default_opts, opts, sizeof(default_opts));
|
|
|
|
|
|
|
|
if (opts->config_file && access(opts->config_file, F_OK) != 0) {
|
|
|
|
opts->config_file = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
getopt_str = spdk_sprintf_alloc("%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);
|
|
|
|
if (getopt_str == NULL) {
|
|
|
|
fprintf(stderr, "Could not allocate getopt_str in %s()\n", __func__);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_early_fail;
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, getopt_str)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
opts->config_file = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
opts->enable_coredump = false;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
opts->tpoint_group_mask = optarg;
|
|
|
|
break;
|
2018-02-23 08:19:09 +00:00
|
|
|
case 'g':
|
|
|
|
opts->hugepage_single_segments = true;
|
|
|
|
break;
|
2017-11-09 20:20:56 +00:00
|
|
|
case 'h':
|
|
|
|
usage(argv[0], &default_opts, app_usage);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_HELP;
|
|
|
|
goto parse_done;
|
2017-11-09 20:20:56 +00:00
|
|
|
case 'i':
|
2018-04-12 22:43:38 +00:00
|
|
|
if (optarg == NULL) {
|
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->shm_id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
opts->reactor_mask = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
2018-04-12 22:43:38 +00:00
|
|
|
if (optarg == NULL) {
|
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->mem_channel = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'p':
|
2018-04-12 22:43:38 +00:00
|
|
|
if (optarg == NULL) {
|
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
opts->master_core = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
opts->print_level = SPDK_LOG_WARN;
|
|
|
|
break;
|
2017-11-09 23:33:29 +00:00
|
|
|
case 'r':
|
|
|
|
opts->rpc_addr = optarg;
|
|
|
|
break;
|
2017-12-13 19:21:28 +00:00
|
|
|
case 's': {
|
|
|
|
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);
|
|
|
|
usage(argv[0], &default_opts, app_usage);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
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);
|
|
|
|
usage(argv[0], &default_opts, app_usage);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
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
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
case 't':
|
|
|
|
rc = spdk_log_set_trace_flag(optarg);
|
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "unknown flag\n");
|
|
|
|
usage(argv[0], &default_opts, app_usage);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
|
|
|
opts->print_level = SPDK_LOG_DEBUG;
|
|
|
|
#ifndef DEBUG
|
|
|
|
fprintf(stderr, "%s must be built with CONFIG_DEBUG=y for -t flag\n",
|
|
|
|
argv[0]);
|
|
|
|
usage(argv[0], &default_opts, app_usage);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
|
|
|
#else
|
2017-11-09 20:20:56 +00:00
|
|
|
break;
|
2018-02-22 23:50:51 +00:00
|
|
|
#endif
|
2018-04-12 22:46:04 +00:00
|
|
|
case 'u':
|
|
|
|
opts->no_pci = true;
|
|
|
|
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.
|
|
|
|
*/
|
2017-11-09 20:20:56 +00:00
|
|
|
usage(argv[0], &default_opts, app_usage);
|
2018-02-22 23:50:51 +00:00
|
|
|
rval = SPDK_APP_PARSE_ARGS_FAIL;
|
|
|
|
goto parse_done;
|
2017-11-09 20:20:56 +00:00
|
|
|
default:
|
|
|
|
app_parse(ch, optarg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 23:50:51 +00:00
|
|
|
parse_done:
|
2017-11-09 20:20:56 +00:00
|
|
|
free(getopt_str);
|
|
|
|
|
2018-02-22 23:50:51 +00:00
|
|
|
parse_early_fail:
|
|
|
|
return rval;
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|