2016-05-24 18:04:20 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2019-11-12 17:12:00 +00:00
|
|
|
* Copyright (c) Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
|
2021-07-13 13:43:48 +00:00
|
|
|
* Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2016-05-24 18:04:20 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2019-11-12 17:12:00 +00:00
|
|
|
#include "spdk/version.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
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
#include "spdk/assert.h"
|
2017-01-12 18:25:17 +00:00
|
|
|
#include "spdk/env.h"
|
2021-03-01 21:06:04 +00:00
|
|
|
#include "spdk/init.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
#include "spdk/log.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"
|
2021-08-06 09:17:16 +00:00
|
|
|
#include "spdk/scheduler.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-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-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
|
2020-11-30 20:41:03 +00:00
|
|
|
#define SPDK_APP_DPDK_DEFAULT_MAIN_CORE -1
|
2017-01-12 18:25:17 +00:00
|
|
|
#define SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL -1
|
2017-01-05 00:02:01 +00:00
|
|
|
#define SPDK_APP_DPDK_DEFAULT_CORE_MASK "0x1"
|
2020-06-04 16:05:53 +00:00
|
|
|
#define SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR 0x200000000000
|
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 {
|
2019-02-28 23:56:14 +00:00
|
|
|
const char *json_config_file;
|
2020-02-06 12:38:46 +00:00
|
|
|
bool json_config_ignore_errors;
|
2021-01-12 12:42:33 +00:00
|
|
|
bool stopped;
|
2019-02-28 23:56:14 +00:00
|
|
|
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;
|
2019-03-04 20:52:59 +00:00
|
|
|
static spdk_msg_fn g_start_fn = NULL;
|
2019-03-01 00:03:45 +00:00
|
|
|
static void *g_start_arg = NULL;
|
2019-02-28 18:15:53 +00:00
|
|
|
static struct spdk_thread *g_app_thread = NULL;
|
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},
|
2020-11-30 20:41:03 +00:00
|
|
|
#define MAIN_CORE_OPT_IDX 'p'
|
|
|
|
{"main-core", required_argument, NULL, MAIN_CORE_OPT_IDX},
|
|
|
|
{"master-core", required_argument, NULL, MAIN_CORE_OPT_IDX}, /* deprecated */
|
2018-07-31 13:26:44 +00:00
|
|
|
#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},
|
2019-11-12 17:12:00 +00:00
|
|
|
#define VERSION_OPT_IDX 'v'
|
|
|
|
{"version", no_argument, NULL, VERSION_OPT_IDX},
|
2020-11-25 21:58:13 +00:00
|
|
|
#define PCI_BLOCKED_OPT_IDX 'B'
|
|
|
|
{"pci-blocked", required_argument, NULL, PCI_BLOCKED_OPT_IDX},
|
|
|
|
{"pci-blacklist", required_argument, NULL, PCI_BLOCKED_OPT_IDX}, /* deprecated */
|
2020-06-16 17:26:30 +00:00
|
|
|
#define LOGFLAG_OPT_IDX 'L'
|
2018-11-27 07:50:57 +00:00
|
|
|
{"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},
|
2020-11-25 21:58:13 +00:00
|
|
|
#define PCI_ALLOWED_OPT_IDX 'A'
|
|
|
|
{"pci-allowed", required_argument, NULL, PCI_ALLOWED_OPT_IDX},
|
2018-07-31 13:26:44 +00:00
|
|
|
#define PCI_WHITELIST_OPT_IDX 'W'
|
2020-11-25 21:58:13 +00:00
|
|
|
{"pci-whitelist", required_argument, NULL, PCI_WHITELIST_OPT_IDX}, /* deprecated */
|
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
|
2019-07-05 06:11:58 +00:00
|
|
|
{"huge-dir", required_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},
|
2020-02-06 12:38:46 +00:00
|
|
|
#define JSON_CONFIG_IGNORE_INIT_ERRORS_IDX 263
|
|
|
|
{"json-ignore-init-errors", no_argument, NULL, JSON_CONFIG_IGNORE_INIT_ERRORS_IDX},
|
2020-06-16 17:26:30 +00:00
|
|
|
#define IOVA_MODE_OPT_IDX 264
|
|
|
|
{"iova-mode", required_argument, NULL, IOVA_MODE_OPT_IDX},
|
2020-06-04 16:05:53 +00:00
|
|
|
#define BASE_VIRTADDR_OPT_IDX 265
|
|
|
|
{"base-virtaddr", required_argument, NULL, BASE_VIRTADDR_OPT_IDX},
|
2021-07-13 13:43:48 +00:00
|
|
|
#define ENV_CONTEXT_OPT_IDX 266
|
|
|
|
{"env-context", required_argument, NULL, ENV_CONTEXT_OPT_IDX},
|
2018-07-31 13:26:44 +00:00
|
|
|
};
|
|
|
|
|
2019-03-05 21:33:52 +00:00
|
|
|
static void
|
|
|
|
app_start_shutdown(void *ctx)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
2019-03-05 21:33:52 +00:00
|
|
|
if (g_spdk_app.shutdown_cb) {
|
|
|
|
g_spdk_app.shutdown_cb();
|
|
|
|
g_spdk_app.shutdown_cb = NULL;
|
2017-08-01 19:47:58 +00:00
|
|
|
} else {
|
|
|
|
spdk_app_stop(0);
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 21:33:52 +00:00
|
|
|
void
|
|
|
|
spdk_app_start_shutdown(void)
|
|
|
|
{
|
2019-12-18 11:41:14 +00:00
|
|
|
spdk_thread_send_critical_msg(g_app_thread, app_start_shutdown);
|
2019-03-05 21:33:52 +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
|
|
|
}
|
|
|
|
|
2018-08-20 22:58:51 +00:00
|
|
|
static int
|
2020-05-10 23:06:38 +00:00
|
|
|
app_opts_validate(const char *app_opts)
|
2018-08-20 22:58:51 +00:00
|
|
|
{
|
|
|
|
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
|
2020-11-30 11:38:37 +00:00
|
|
|
spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
2017-12-07 23:23:48 +00:00
|
|
|
if (!opts) {
|
2020-11-30 11:38:37 +00:00
|
|
|
SPDK_ERRLOG("opts should not be NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts_size) {
|
|
|
|
SPDK_ERRLOG("opts_size should not be zero value\n");
|
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
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
memset(opts, 0, opts_size);
|
|
|
|
opts->opts_size = opts_size;
|
|
|
|
|
|
|
|
#define SET_FIELD(field, value) \
|
|
|
|
if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= opts_size) { \
|
|
|
|
opts->field = value; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
SET_FIELD(enable_coredump, true);
|
|
|
|
SET_FIELD(shm_id, -1);
|
|
|
|
SET_FIELD(mem_size, SPDK_APP_DPDK_DEFAULT_MEM_SIZE);
|
|
|
|
SET_FIELD(main_core, SPDK_APP_DPDK_DEFAULT_MAIN_CORE);
|
|
|
|
SET_FIELD(mem_channel, SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL);
|
|
|
|
SET_FIELD(reactor_mask, SPDK_APP_DPDK_DEFAULT_CORE_MASK);
|
|
|
|
SET_FIELD(base_virtaddr, SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR);
|
|
|
|
SET_FIELD(print_level, SPDK_APP_DEFAULT_LOG_PRINT_LEVEL);
|
|
|
|
SET_FIELD(rpc_addr, SPDK_DEFAULT_RPC_ADDR);
|
|
|
|
SET_FIELD(num_entries, SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
|
|
|
|
SET_FIELD(delay_subsystem_init, false);
|
2021-09-02 17:11:33 +00:00
|
|
|
SET_FIELD(disable_signal_handlers, false);
|
2020-11-30 11:38:37 +00:00
|
|
|
#undef SET_FIELD
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 17:33:41 +00:00
|
|
|
static int
|
2020-05-10 23:06:38 +00:00
|
|
|
app_setup_signal_handlers(struct spdk_app_opts *opts)
|
2017-07-21 17:33:41 +00:00
|
|
|
{
|
|
|
|
struct sigaction sigact;
|
|
|
|
sigset_t sigmask;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
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 */
|
2020-05-08 06:03:22 +00:00
|
|
|
g_shutdown_sig_received = false;
|
2017-07-21 17:33:41 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:31:15 +00:00
|
|
|
static void
|
2020-05-10 23:06:38 +00:00
|
|
|
app_start_application(void)
|
2018-05-02 04:28:57 +00:00
|
|
|
{
|
2019-02-28 18:15:53 +00:00
|
|
|
assert(spdk_get_thread() == g_app_thread);
|
2019-03-01 00:03:45 +00:00
|
|
|
|
2019-03-04 20:52:59 +00:00
|
|
|
g_start_fn(g_start_arg);
|
2018-05-02 04:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 23:06:38 +00:00
|
|
|
app_start_rpc(int rc, void *arg1)
|
2017-11-06 16:31:15 +00:00
|
|
|
{
|
2019-08-07 11:42:32 +00:00
|
|
|
if (rc) {
|
|
|
|
spdk_app_stop(rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-02 19:45:59 +00:00
|
|
|
rc = spdk_rpc_initialize(g_spdk_app.rpc_addr);
|
|
|
|
if (rc) {
|
|
|
|
spdk_app_stop(rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
if (!g_delay_subsystem_init) {
|
2019-06-18 05:31:26 +00:00
|
|
|
spdk_rpc_set_state(SPDK_RPC_RUNTIME);
|
2020-05-10 23:06:38 +00:00
|
|
|
app_start_application();
|
2018-05-02 04:50:39 +00:00
|
|
|
}
|
2017-11-06 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:39:37 +00:00
|
|
|
static int
|
2020-05-10 23:06:38 +00:00
|
|
|
app_opts_add_pci_addr(struct spdk_app_opts *opts, struct spdk_pci_addr **list, char *bdf)
|
2018-03-30 17:39:37 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
static int
|
2020-05-10 23:06:38 +00:00
|
|
|
app_setup_env(struct spdk_app_opts *opts)
|
2018-04-02 00:47:59 +00:00
|
|
|
{
|
|
|
|
struct spdk_env_opts env_opts = {};
|
|
|
|
int rc;
|
|
|
|
|
2020-05-08 06:03:22 +00:00
|
|
|
if (opts == NULL) {
|
|
|
|
rc = spdk_env_init(NULL);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Unable to reinitialize SPDK env\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
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;
|
2020-11-30 20:41:03 +00:00
|
|
|
env_opts.main_core = opts->main_core;
|
2018-04-02 00:47:59 +00:00
|
|
|
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;
|
2020-11-25 21:36:02 +00:00
|
|
|
env_opts.pci_blocked = opts->pci_blocked;
|
|
|
|
env_opts.pci_allowed = opts->pci_allowed;
|
2020-08-21 01:15:14 +00:00
|
|
|
env_opts.base_virtaddr = opts->base_virtaddr;
|
2019-02-05 11:51:53 +00:00
|
|
|
env_opts.env_context = opts->env_context;
|
2020-06-16 17:26:30 +00:00
|
|
|
env_opts.iova_mode = opts->iova_mode;
|
2018-04-02 00:47:59 +00:00
|
|
|
|
|
|
|
rc = spdk_env_init(&env_opts);
|
2020-11-25 21:35:26 +00:00
|
|
|
free(env_opts.pci_blocked);
|
|
|
|
free(env_opts.pci_allowed);
|
2018-03-30 17:39:37 +00:00
|
|
|
|
2018-04-02 00:47:59 +00:00
|
|
|
if (rc < 0) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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
|
2020-05-10 23:06:38 +00:00
|
|
|
app_setup_trace(struct spdk_app_opts *opts)
|
2018-04-02 01:12:05 +00:00
|
|
|
{
|
|
|
|
char shm_name[64];
|
2021-12-01 10:23:55 +00:00
|
|
|
uint64_t tpoint_group_mask, tpoint_mask = -1ULL;
|
|
|
|
char *end = NULL, *tpoint_group_mask_str, *tpoint_group_str = NULL;
|
|
|
|
char *tp_g_str, *tpoint_group, *tpoints;
|
2018-04-02 01:12:05 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-12-03 11:04:17 +00:00
|
|
|
if (opts->tpoint_group_mask == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tpoint_group_mask_str = strdup(opts->tpoint_group_mask);
|
|
|
|
if (tpoint_group_mask_str == NULL) {
|
|
|
|
SPDK_ERRLOG("Unable to get string of tpoint group mask from opts.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Save a pointer to the original value of the tpoint group mask string
|
|
|
|
* to free later, because spdk_strsepq() modifies given char*. */
|
|
|
|
tp_g_str = tpoint_group_mask_str;
|
|
|
|
while ((tpoint_group_str = spdk_strsepq(&tpoint_group_mask_str, ",")) != NULL) {
|
2021-12-01 10:23:55 +00:00
|
|
|
if (strchr(tpoint_group_str, ':')) {
|
|
|
|
/* Get the tpoint group mask */
|
|
|
|
tpoint_group = spdk_strsepq(&tpoint_group_str, ":");
|
|
|
|
/* Get the tpoint mask inside that group */
|
|
|
|
tpoints = spdk_strsepq(&tpoint_group_str, ":");
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
tpoint_group_mask = strtoull(tpoint_group, &end, 16);
|
|
|
|
if (*end != '\0' || errno) {
|
2021-12-21 16:22:40 +00:00
|
|
|
tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group);
|
|
|
|
if (tpoint_group_mask == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2021-12-01 10:23:55 +00:00
|
|
|
}
|
|
|
|
/* Check if tpoint group mask has only one bit set.
|
|
|
|
* This is to avoid enabling individual tpoints in
|
|
|
|
* more than one tracepoint group at once. */
|
|
|
|
if (!spdk_u64_is_pow2(tpoint_group_mask)) {
|
|
|
|
SPDK_ERRLOG("Tpoint group mask: %s contains multiple tpoint groups.\n", tpoint_group);
|
|
|
|
SPDK_ERRLOG("This is not supported, to prevent from activating tpoints by mistake.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
tpoint_mask = strtoull(tpoints, &end, 16);
|
|
|
|
if (*end != '\0' || errno) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errno = 0;
|
|
|
|
tpoint_group_mask = strtoull(tpoint_group_str, &end, 16);
|
|
|
|
if (*end != '\0' || errno) {
|
2021-12-21 16:22:40 +00:00
|
|
|
tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group_str);
|
|
|
|
if (tpoint_group_mask == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2021-12-01 10:23:55 +00:00
|
|
|
}
|
|
|
|
tpoint_mask = -1ULL;
|
2021-12-03 11:04:17 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 10:23:55 +00:00
|
|
|
spdk_trace_set_tpoints(spdk_u64log2(tpoint_group_mask), tpoint_mask);
|
2021-12-03 11:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tpoint_group_str != NULL) {
|
|
|
|
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__)
|
2021-12-03 11:04:17 +00:00
|
|
|
SPDK_NOTICELOG("Or copy /dev/shm%s for offline analysis/debug.\n", shm_name);
|
2018-09-04 19:07:34 +00:00
|
|
|
#endif
|
2018-04-02 01:12:05 +00:00
|
|
|
}
|
2021-12-03 11:04:17 +00:00
|
|
|
free(tp_g_str);
|
2018-04-02 01:12:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-28 23:39:52 +00:00
|
|
|
static void
|
2019-02-28 18:15:53 +00:00
|
|
|
bootstrap_fn(void *arg1)
|
2019-02-28 23:39:52 +00:00
|
|
|
{
|
2021-03-02 19:45:59 +00:00
|
|
|
int rc;
|
|
|
|
|
2019-03-01 00:00:55 +00:00
|
|
|
if (g_spdk_app.json_config_file) {
|
|
|
|
g_delay_subsystem_init = false;
|
2021-03-02 19:34:25 +00:00
|
|
|
spdk_subsystem_init_from_json_config(g_spdk_app.json_config_file, g_spdk_app.rpc_addr,
|
|
|
|
app_start_rpc,
|
|
|
|
NULL, !g_spdk_app.json_config_ignore_errors);
|
2019-02-28 23:39:52 +00:00
|
|
|
} else {
|
|
|
|
if (!g_delay_subsystem_init) {
|
2020-05-10 23:06:38 +00:00
|
|
|
spdk_subsystem_init(app_start_rpc, NULL);
|
2019-02-28 23:39:52 +00:00
|
|
|
} else {
|
2021-03-02 19:45:59 +00:00
|
|
|
rc = spdk_rpc_initialize(g_spdk_app.rpc_addr);
|
|
|
|
if (rc) {
|
|
|
|
spdk_app_stop(rc);
|
|
|
|
return;
|
|
|
|
}
|
2019-02-28 23:39:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
static void
|
|
|
|
app_copy_opts(struct spdk_app_opts *opts, struct spdk_app_opts *opts_user, size_t opts_size)
|
|
|
|
{
|
|
|
|
spdk_app_opts_init(opts, sizeof(*opts));
|
|
|
|
opts->opts_size = opts_size;
|
|
|
|
|
|
|
|
#define SET_FIELD(field) \
|
|
|
|
if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= (opts->opts_size)) { \
|
|
|
|
opts->field = opts_user->field; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
SET_FIELD(name);
|
|
|
|
SET_FIELD(json_config_file);
|
|
|
|
SET_FIELD(json_config_ignore_errors);
|
|
|
|
SET_FIELD(rpc_addr);
|
|
|
|
SET_FIELD(reactor_mask);
|
|
|
|
SET_FIELD(tpoint_group_mask);
|
|
|
|
SET_FIELD(shm_id);
|
|
|
|
SET_FIELD(shutdown_cb);
|
|
|
|
SET_FIELD(enable_coredump);
|
|
|
|
SET_FIELD(mem_channel);
|
|
|
|
SET_FIELD(main_core);
|
|
|
|
SET_FIELD(mem_size);
|
|
|
|
SET_FIELD(no_pci);
|
|
|
|
SET_FIELD(hugepage_single_segments);
|
|
|
|
SET_FIELD(unlink_hugepage);
|
|
|
|
SET_FIELD(hugedir);
|
|
|
|
SET_FIELD(print_level);
|
|
|
|
SET_FIELD(num_pci_addr);
|
|
|
|
SET_FIELD(pci_blocked);
|
|
|
|
SET_FIELD(pci_allowed);
|
|
|
|
SET_FIELD(iova_mode);
|
|
|
|
SET_FIELD(delay_subsystem_init);
|
|
|
|
SET_FIELD(num_entries);
|
|
|
|
SET_FIELD(env_context);
|
|
|
|
SET_FIELD(log);
|
|
|
|
SET_FIELD(base_virtaddr);
|
2021-09-02 17:11:33 +00:00
|
|
|
SET_FIELD(disable_signal_handlers);
|
2020-11-30 11:38:37 +00:00
|
|
|
|
|
|
|
/* 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 */
|
2021-09-02 17:11:33 +00:00
|
|
|
SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 192, "Incorrect size");
|
2020-11-30 11:38:37 +00:00
|
|
|
|
|
|
|
#undef SET_FIELD
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
int
|
2020-11-30 11:38:37 +00:00
|
|
|
spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
|
2019-02-28 21:42:07 +00:00
|
|
|
void *arg1)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
|
|
|
int rc;
|
2018-08-30 08:47:56 +00:00
|
|
|
char *tty;
|
2019-12-20 08:05:07 +00:00
|
|
|
struct spdk_cpuset tmp_cpumask = {};
|
2020-05-08 06:03:22 +00:00
|
|
|
static bool g_env_was_setup = false;
|
2020-11-30 11:38:37 +00:00
|
|
|
struct spdk_app_opts opts_local = {};
|
|
|
|
struct spdk_app_opts *opts = &opts_local;
|
2017-06-06 06:31:47 +00:00
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
if (!opts_user) {
|
|
|
|
SPDK_ERRLOG("opts_user should not be NULL\n");
|
2018-06-27 11:09:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
if (!opts_user->opts_size) {
|
|
|
|
SPDK_ERRLOG("The opts_size in opts_user structure should not be zero value\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
app_copy_opts(opts, opts_user, opts_user->opts_size);
|
|
|
|
|
2018-06-27 11:09:50 +00:00
|
|
|
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
|
|
|
|
2019-10-08 09:10:43 +00:00
|
|
|
memset(&g_spdk_app, 0, sizeof(g_spdk_app));
|
|
|
|
g_spdk_app.json_config_file = opts->json_config_file;
|
2020-02-06 12:38:46 +00:00
|
|
|
g_spdk_app.json_config_ignore_errors = opts->json_config_ignore_errors;
|
2019-10-08 09:10:43 +00:00
|
|
|
g_spdk_app.rpc_addr = opts->rpc_addr;
|
|
|
|
g_spdk_app.shm_id = opts->shm_id;
|
|
|
|
g_spdk_app.shutdown_cb = opts->shutdown_cb;
|
|
|
|
g_spdk_app.rc = 0;
|
2021-01-12 12:42:33 +00:00
|
|
|
g_spdk_app.stopped = false;
|
2019-10-08 09:10:43 +00:00
|
|
|
|
2018-03-30 22:38:22 +00:00
|
|
|
spdk_log_set_level(SPDK_APP_DEFAULT_LOG_LEVEL);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2020-05-08 06:03:22 +00:00
|
|
|
/* Pass NULL to app_setup_env if SPDK app has been set up, in order to
|
|
|
|
* indicate that this is a reinitialization.
|
|
|
|
*/
|
|
|
|
if (app_setup_env(g_env_was_setup ? NULL : opts) < 0) {
|
2019-10-08 09:10:43 +00:00
|
|
|
return 1;
|
2017-12-18 19:57:01 +00:00
|
|
|
}
|
2016-06-12 11:34:00 +00:00
|
|
|
|
2019-05-20 22:29:45 +00:00
|
|
|
spdk_log_open(opts->log);
|
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
|
|
|
|
2019-02-13 16:56:13 +00:00
|
|
|
if ((rc = spdk_reactors_init()) != 0) {
|
2021-11-25 01:40:58 +00:00
|
|
|
SPDK_ERRLOG("Reactor Initialization failed: rc = %d\n", rc);
|
2019-10-08 09:10:50 +00:00
|
|
|
return 1;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 08:05:07 +00:00
|
|
|
spdk_cpuset_set_cpu(&tmp_cpumask, spdk_env_get_current_core(), true);
|
2019-04-26 09:04:18 +00:00
|
|
|
|
2019-02-28 18:15:53 +00:00
|
|
|
/* Now that the reactors have been initialized, we can create an
|
|
|
|
* initialization thread. */
|
2019-12-20 08:05:07 +00:00
|
|
|
g_app_thread = spdk_thread_create("app_thread", &tmp_cpumask);
|
2019-02-28 18:15:53 +00:00
|
|
|
if (!g_app_thread) {
|
|
|
|
SPDK_ERRLOG("Unable to create an spdk_thread for initialization\n");
|
2019-10-08 09:10:50 +00:00
|
|
|
return 1;
|
2019-02-28 18:15:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 17:08:57 +00:00
|
|
|
/*
|
2020-10-30 09:24:47 +00:00
|
|
|
* Disable and ignore trace setup if setting num_entries
|
|
|
|
* to be 0.
|
|
|
|
*
|
2020-05-10 23:06:38 +00:00
|
|
|
* Note the call to app_setup_trace() is located here
|
|
|
|
* ahead of app_setup_signal_handlers().
|
2018-03-09 17:08:57 +00:00
|
|
|
* That's because there is not an easy/direct clean
|
|
|
|
* way of unwinding alloc'd resources that can occur
|
2020-05-10 23:06:38 +00:00
|
|
|
* in app_setup_signal_handlers().
|
2018-03-09 17:08:57 +00:00
|
|
|
*/
|
2020-10-30 09:24:47 +00:00
|
|
|
if (opts->num_entries != 0 && app_setup_trace(opts) != 0) {
|
2019-10-08 09:10:50 +00:00
|
|
|
return 1;
|
2018-03-09 17:08:57 +00:00
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2021-09-02 17:11:33 +00:00
|
|
|
if (!opts->disable_signal_handlers && app_setup_signal_handlers(opts) != 0) {
|
2019-10-08 09:10:50 +00:00
|
|
|
return 1;
|
2018-03-09 17:08:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
g_delay_subsystem_init = opts->delay_subsystem_init;
|
2019-03-01 00:03:45 +00:00
|
|
|
g_start_fn = start_fn;
|
|
|
|
g_start_arg = arg1;
|
2018-05-02 04:50:39 +00:00
|
|
|
|
2019-02-28 18:15:53 +00:00
|
|
|
spdk_thread_send_msg(g_app_thread, bootstrap_fn, NULL);
|
2019-02-28 23:39:52 +00:00
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
/* This blocks until spdk_app_stop is called */
|
|
|
|
spdk_reactors_start();
|
|
|
|
|
2020-05-08 06:03:22 +00:00
|
|
|
g_env_was_setup = true;
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
return g_spdk_app.rc;
|
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();
|
2019-03-11 12:14:19 +00:00
|
|
|
spdk_env_fini();
|
2017-06-13 18:16:15 +00:00
|
|
|
spdk_log_close();
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 14:01:13 +00:00
|
|
|
static void
|
|
|
|
_start_subsystem_fini(void *arg1)
|
|
|
|
{
|
2021-07-08 13:27:45 +00:00
|
|
|
if (g_scheduling_in_progress) {
|
2021-01-26 14:01:13 +00:00
|
|
|
spdk_thread_send_msg(g_app_thread, _start_subsystem_fini, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_subsystem_fini(spdk_reactors_stop, NULL);
|
|
|
|
}
|
|
|
|
|
2017-10-25 13:58:02 +00:00
|
|
|
static void
|
2020-05-14 23:32:50 +00:00
|
|
|
app_stop(void *arg1)
|
2017-10-25 13:58:02 +00:00
|
|
|
{
|
2021-01-12 12:42:33 +00:00
|
|
|
if (g_spdk_app.rc == 0) {
|
|
|
|
g_spdk_app.rc = (int)(intptr_t)arg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_spdk_app.stopped) {
|
|
|
|
SPDK_NOTICELOG("spdk_app_stop called twice\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:31:15 +00:00
|
|
|
spdk_rpc_finish();
|
2021-01-12 12:42:33 +00:00
|
|
|
g_spdk_app.stopped = true;
|
2021-01-26 14:01:13 +00:00
|
|
|
_start_subsystem_fini(NULL);
|
2017-10-25 13:58:02 +00:00
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
2021-01-12 12:42:33 +00:00
|
|
|
|
2017-10-25 13:58:02 +00:00
|
|
|
/*
|
2019-02-28 18:15:53 +00:00
|
|
|
* We want to run spdk_subsystem_fini() from the same thread where spdk_subsystem_init()
|
2017-10-25 13:58:02 +00:00
|
|
|
* was called.
|
|
|
|
*/
|
2021-01-12 12:42:33 +00:00
|
|
|
spdk_thread_send_msg(g_app_thread, app_stop, (void *)(intptr_t)rc);
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
|
2021-01-09 14:46:21 +00:00
|
|
|
struct spdk_thread *
|
|
|
|
_spdk_get_app_thread(void)
|
|
|
|
{
|
|
|
|
return g_app_thread;
|
|
|
|
}
|
|
|
|
|
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");
|
2020-10-12 09:32:35 +00:00
|
|
|
printf(" -c, --config <config> JSON config file (default %s)\n",
|
|
|
|
g_default_opts.json_config_file != NULL ? g_default_opts.json_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");
|
2020-02-06 12:38:46 +00:00
|
|
|
printf(" --json-ignore-init-errors\n");
|
|
|
|
printf(" don't exit on invalid config entry\n");
|
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");
|
2021-07-13 17:34:07 +00:00
|
|
|
printf(" -m, --cpumask <mask or list> core mask (like 0xF) or core list of '[]' embraced (like [0,1,10]) for DPDK\n");
|
2018-07-31 13:26:44 +00:00
|
|
|
printf(" -n, --mem-channels <num> channel number of memory channels used for DPDK\n");
|
2020-11-30 20:41:03 +00:00
|
|
|
printf(" -p, --main-core <id> main (primary) core for DPDK\n");
|
2018-07-31 13:26:44 +00:00
|
|
|
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");
|
2020-11-25 21:58:13 +00:00
|
|
|
printf(" -B, --pci-blocked <bdf>\n");
|
|
|
|
printf(" pci addr to block (can be used more than once)\n");
|
2018-07-31 13:26:44 +00:00
|
|
|
printf(" -R, --huge-unlink unlink huge files after initialization\n");
|
2019-11-12 17:12:00 +00:00
|
|
|
printf(" -v, --version print SPDK version\n");
|
2020-11-25 21:58:13 +00:00
|
|
|
printf(" -A, --pci-allowed <bdf>\n");
|
|
|
|
printf(" pci addr to allow (-B and -A cannot be used at the same time)\n");
|
2020-11-25 11:07:23 +00:00
|
|
|
printf(" --huge-dir <path> use a specific hugetlbfs mount to reserve memory from\n");
|
|
|
|
printf(" --iova-mode <pa/va> set IOVA mode ('pa' for IOVA_PA and 'va' for IOVA_VA)\n");
|
|
|
|
printf(" --base-virtaddr <addr> the base virtual address for DPDK (default: 0x200000000000)\n");
|
|
|
|
printf(" --num-trace-entries <num> number of trace entries for each core, must be power of 2, setting 0 to disable trace (default %d)\n",
|
2018-11-13 17:23:16 +00:00
|
|
|
SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
|
2021-07-13 13:43:48 +00:00
|
|
|
printf(" --env-context Opaque context for use of the env implementation\n");
|
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->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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("Out of memory\n");
|
2018-08-14 15:37:17 +00:00
|
|
|
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) {
|
2020-05-10 23:06:38 +00:00
|
|
|
ch = app_opts_validate(app_getopt_str);
|
2018-08-20 22:58:51 +00:00
|
|
|
if (ch) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("Out of memory\n");
|
2018-08-14 15:37:17 +00:00
|
|
|
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:
|
2018-08-14 16:53:07 +00:00
|
|
|
case JSON_CONFIG_OPT_IDX:
|
|
|
|
opts->json_config_file = optarg;
|
|
|
|
break;
|
2020-02-06 12:38:46 +00:00
|
|
|
case JSON_CONFIG_IGNORE_INIT_ERRORS_IDX:
|
|
|
|
opts->json_config_ignore_errors = true;
|
|
|
|
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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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;
|
2020-11-30 20:41:03 +00:00
|
|
|
case MAIN_CORE_OPT_IDX:
|
|
|
|
opts->main_core = spdk_strtol(optarg, 0);
|
|
|
|
if (opts->main_core < 0) {
|
|
|
|
SPDK_ERRLOG("Invalid main 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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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;
|
2020-11-25 21:58:13 +00:00
|
|
|
case PCI_BLOCKED_OPT_IDX:
|
2020-11-25 21:36:02 +00:00
|
|
|
if (opts->pci_allowed) {
|
|
|
|
free(opts->pci_allowed);
|
|
|
|
opts->pci_allowed = NULL;
|
2020-11-25 21:58:13 +00:00
|
|
|
SPDK_ERRLOG("-B and -A 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
|
|
|
}
|
|
|
|
|
2020-11-25 21:36:02 +00:00
|
|
|
rc = app_opts_add_pci_addr(opts, &opts->pci_blocked, optarg);
|
2018-03-30 17:39:37 +00:00
|
|
|
if (rc != 0) {
|
2020-11-25 21:36:02 +00:00
|
|
|
free(opts->pci_blocked);
|
|
|
|
opts->pci_blocked = 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-11-27 06:57:58 +00:00
|
|
|
rc = spdk_log_set_flag(optarg);
|
2018-06-19 08:27:46 +00:00
|
|
|
if (rc < 0) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("unknown flag\n");
|
2018-06-19 08:27:46 +00:00
|
|
|
usage(app_usage);
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-06-19 08:27:46 +00:00
|
|
|
}
|
2020-10-07 14:53:50 +00:00
|
|
|
#ifdef DEBUG
|
2018-06-19 08:27:46 +00:00
|
|
|
opts->print_level = SPDK_LOG_DEBUG;
|
|
|
|
#endif
|
2020-10-15 18:13:55 +00:00
|
|
|
break;
|
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:
|
2020-11-25 21:58:13 +00:00
|
|
|
SPDK_WARNLOG("-W/--pci-whitelist is deprecated. Use -A/--pci-allowed.\n");
|
|
|
|
/* fallthrough */
|
|
|
|
case PCI_ALLOWED_OPT_IDX:
|
2020-11-25 21:36:02 +00:00
|
|
|
if (opts->pci_blocked) {
|
|
|
|
free(opts->pci_blocked);
|
|
|
|
opts->pci_blocked = NULL;
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("-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
|
|
|
}
|
|
|
|
|
2020-11-25 21:36:02 +00:00
|
|
|
rc = app_opts_add_pci_addr(opts, &opts->pci_allowed, optarg);
|
2018-03-30 17:39:37 +00:00
|
|
|
if (rc != 0) {
|
2020-11-25 21:36:02 +00:00
|
|
|
free(opts->pci_allowed);
|
|
|
|
opts->pci_allowed = NULL;
|
2018-08-31 16:36:52 +00:00
|
|
|
goto out;
|
2018-03-30 17:39:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-06-04 16:05:53 +00:00
|
|
|
case BASE_VIRTADDR_OPT_IDX:
|
|
|
|
tmp = spdk_strtoll(optarg, 0);
|
|
|
|
if (tmp <= 0) {
|
|
|
|
SPDK_ERRLOG("Invalid base-virtaddr %s\n", optarg);
|
|
|
|
usage(app_usage);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
opts->base_virtaddr = (uint64_t)tmp;
|
|
|
|
break;
|
2018-11-06 06:10:11 +00:00
|
|
|
case HUGE_DIR_OPT_IDX:
|
|
|
|
opts->hugedir = optarg;
|
|
|
|
break;
|
2020-06-16 17:26:30 +00:00
|
|
|
case IOVA_MODE_OPT_IDX:
|
|
|
|
opts->iova_mode = 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);
|
2020-10-30 09:24:47 +00:00
|
|
|
if (tmp < 0) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("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;
|
2020-10-30 09:24:47 +00:00
|
|
|
if (opts->num_entries > 0 && opts->num_entries & (opts->num_entries - 1)) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("num-trace-entries must be power of 2\n");
|
2018-11-15 03:01:51 +00:00
|
|
|
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:
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("Deprecation warning: The maximum allowed latency parameter is no longer supported.\n");
|
2018-12-13 13:21:46 +00:00
|
|
|
break;
|
2021-07-13 13:43:48 +00:00
|
|
|
case ENV_CONTEXT_OPT_IDX:
|
|
|
|
opts->env_context = optarg;
|
|
|
|
break;
|
2019-11-12 17:12:00 +00:00
|
|
|
case VERSION_OPT_IDX:
|
|
|
|
printf(SPDK_VERSION_STRING"\n");
|
|
|
|
retval = SPDK_APP_PARSE_ARGS_HELP;
|
|
|
|
goto out;
|
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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("Parsing application specific arguments failed: %d\n", rc);
|
2019-01-08 19:40:06 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2017-11-09 20:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 16:53:07 +00:00
|
|
|
if (opts->json_config_file && opts->delay_subsystem_init) {
|
2020-10-12 09:32:35 +00:00
|
|
|
SPDK_ERRLOG("JSON configuration file can't be used together with --wait-for-rpc.\n");
|
2018-08-14 16:53:07 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-11-25 21:36:02 +00:00
|
|
|
free(opts->pci_blocked);
|
|
|
|
opts->pci_blocked = NULL;
|
|
|
|
free(opts->pci_allowed);
|
|
|
|
opts->pci_allowed = NULL;
|
2018-09-04 15:42:55 +00:00
|
|
|
}
|
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) {
|
2020-04-18 12:12:43 +00:00
|
|
|
SPDK_ERRLOG("%s not valid before calling spdk_app_parse_args()\n", __func__);
|
2018-06-07 14:16:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
usage(NULL);
|
|
|
|
}
|
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
static void
|
2020-05-10 23:06:38 +00:00
|
|
|
rpc_framework_start_init_cpl(int rc, void *arg1)
|
2018-05-02 04:50:39 +00:00
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = arg1;
|
|
|
|
|
2019-02-28 18:15:53 +00:00
|
|
|
assert(spdk_get_thread() == g_app_thread);
|
2019-03-04 19:52:07 +00:00
|
|
|
|
2019-08-07 11:42:32 +00:00
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
2019-09-11 13:30:14 +00:00
|
|
|
"framework_initialization failed");
|
2019-08-07 11:42:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-18 05:31:26 +00:00
|
|
|
spdk_rpc_set_state(SPDK_RPC_RUNTIME);
|
2020-05-10 23:06:38 +00:00
|
|
|
app_start_application();
|
2018-05-02 04:50:39 +00:00
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-05-02 04:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 23:06:38 +00:00
|
|
|
rpc_framework_start_init(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-05-02 04:50:39 +00:00
|
|
|
{
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-11 13:30:14 +00:00
|
|
|
"framework_start_init requires no parameters");
|
2018-05-02 04:50:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-10 23:06:38 +00:00
|
|
|
spdk_subsystem_init(rpc_framework_start_init_cpl, request);
|
2018-05-02 04:50:39 +00:00
|
|
|
}
|
2020-05-10 23:06:38 +00:00
|
|
|
SPDK_RPC_REGISTER("framework_start_init", rpc_framework_start_init, SPDK_RPC_STARTUP)
|
2019-09-11 13:30:14 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(framework_start_init, start_subsystem_init)
|
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
|
2020-05-10 23:06:38 +00:00
|
|
|
rpc_subsystem_init_poller_ctx(void *ctx)
|
2018-11-08 20:24:50 +00:00
|
|
|
{
|
|
|
|
struct subsystem_init_poller_ctx *poller_ctx = ctx;
|
|
|
|
|
|
|
|
if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(poller_ctx->request, true);
|
2018-11-08 20:24:50 +00:00
|
|
|
spdk_poller_unregister(&poller_ctx->init_poller);
|
|
|
|
free(poller_ctx);
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:51:27 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2018-11-08 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 23:06:38 +00:00
|
|
|
rpc_framework_wait_init(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-11-08 20:24:50 +00:00
|
|
|
{
|
|
|
|
struct subsystem_init_poller_ctx *ctx;
|
|
|
|
|
|
|
|
if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2018-11-08 20:24:50 +00:00
|
|
|
} 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;
|
2020-05-10 23:06:38 +00:00
|
|
|
ctx->init_poller = SPDK_POLLER_REGISTER(rpc_subsystem_init_poller_ctx, ctx, 0);
|
2018-11-08 20:24:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-10 23:06:38 +00:00
|
|
|
SPDK_RPC_REGISTER("framework_wait_init", rpc_framework_wait_init,
|
2018-11-08 20:24:50 +00:00
|
|
|
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
|
2019-09-11 13:35:41 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(framework_wait_init, wait_subsystem_init)
|