iscsi, nvmf, vhost: break out arg parsing into separate functions

This prepares for moving all of the common app framework argument
parsing into a library that can be used by all app framework based
applications.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ibbfb08ac687acf3201c4a3e808edbe770213a6f0

Reviewed-on: https://review.gerrithub.io/385928
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Jim Harris 2017-11-06 09:58:29 -07:00 committed by Daniel Verkamp
parent 1b306f4b54
commit 0489bcb137
3 changed files with 155 additions and 131 deletions

View File

@ -39,6 +39,8 @@
#include "spdk/log.h"
#include "spdk/net.h"
static int g_daemon_mode = 0;
static void
spdk_sigusr1(int signo __attribute__((__unused__)))
{
@ -86,12 +88,70 @@ spdk_startup(void *arg1, void *arg2)
}
}
static void
iscsi_parse_args(int argc, char **argv, struct spdk_app_opts *opts)
{
int ch, rc;
while ((ch = getopt(argc, argv, "bc:de:i:m:n:p:qs:t:H")) != -1) {
switch (ch) {
case 'd':
opts->enable_coredump = false;
break;
case 'c':
opts->config_file = optarg;
break;
case 'i':
opts->shm_id = atoi(optarg);
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
if (rc < 0) {
fprintf(stderr, "unknown flag\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
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]);
exit(EXIT_FAILURE);
#endif
break;
case 'e':
opts->tpoint_group_mask = optarg;
break;
case 'q':
opts->print_level = SPDK_LOG_WARN;
break;
case 'm':
opts->reactor_mask = optarg;
break;
case 'n':
opts->mem_channel = atoi(optarg);
break;
case 'p':
opts->master_core = atoi(optarg);
break;
case 's':
opts->mem_size = atoi(optarg);
break;
case 'b':
g_daemon_mode = 1;
break;
case 'H':
default:
usage(argv[0]);
exit(EXIT_SUCCESS);
}
}
}
int
main(int argc, char **argv)
{
int ch;
int rc;
int daemon_mode = 0;
struct spdk_app_opts opts = {};
/* default value in opts structure */
@ -102,61 +162,9 @@ main(int argc, char **argv)
}
opts.name = "iscsi";
while ((ch = getopt(argc, argv, "bc:de:i:m:n:p:qs:t:H")) != -1) {
switch (ch) {
case 'd':
opts.enable_coredump = false;
break;
case 'c':
opts.config_file = optarg;
break;
case 'i':
opts.shm_id = atoi(optarg);
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
if (rc < 0) {
fprintf(stderr, "unknown flag\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
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]);
exit(EXIT_FAILURE);
#endif
break;
case 'e':
opts.tpoint_group_mask = optarg;
break;
case 'q':
opts.print_level = SPDK_LOG_WARN;
break;
case 'm':
opts.reactor_mask = optarg;
break;
case 'n':
opts.mem_channel = atoi(optarg);
break;
case 'p':
opts.master_core = atoi(optarg);
break;
case 's':
opts.mem_size = atoi(optarg);
break;
case 'b':
daemon_mode = 1;
break;
case 'H':
default:
usage(argv[0]);
exit(EXIT_SUCCESS);
}
}
iscsi_parse_args(argc, argv, &opts);
if (daemon_mode) {
if (g_daemon_mode) {
if (daemon(1, 0) < 0) {
SPDK_ERRLOG("Start iscsi target daemon faild.\n");
exit(EXIT_FAILURE);

View File

@ -65,11 +65,67 @@ usage(void)
printf(" -d - disable coredump file enabling\n");
}
static void
nvmf_parse_args(int argc, char **argv, struct spdk_app_opts *opts)
{
int ch, rc;
while ((ch = getopt(argc, argv, "c:de:i:m:n:p:qs:t:DH")) != -1) {
switch (ch) {
case 'd':
opts->enable_coredump = false;
break;
case 'c':
opts->config_file = optarg;
break;
case 'i':
opts->shm_id = atoi(optarg);
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
if (rc < 0) {
fprintf(stderr, "unknown flag\n");
usage();
exit(EXIT_FAILURE);
}
opts->print_level = SPDK_LOG_DEBUG;
#ifndef DEBUG
fprintf(stderr, "%s must be rebuilt with CONFIG_DEBUG=y for -t flag.\n",
argv[0]);
usage();
exit(EXIT_FAILURE);
#endif
break;
case 'm':
opts->reactor_mask = optarg;
break;
case 'n':
opts->mem_channel = atoi(optarg);
break;
case 'p':
opts->master_core = atoi(optarg);
break;
case 's':
opts->mem_size = atoi(optarg);
break;
case 'e':
opts->tpoint_group_mask = optarg;
break;
case 'q':
opts->print_level = SPDK_LOG_WARN;
break;
case 'D':
case 'H':
default:
usage();
exit(EXIT_SUCCESS);
}
}
}
int
main(int argc, char **argv)
{
int ch;
int rc;
struct spdk_app_opts opts = {};
@ -81,57 +137,7 @@ main(int argc, char **argv)
}
opts.max_delay_us = 1000; /* 1 ms */
while ((ch = getopt(argc, argv, "c:de:i:m:n:p:qs:t:DH")) != -1) {
switch (ch) {
case 'd':
opts.enable_coredump = false;
break;
case 'c':
opts.config_file = optarg;
break;
case 'i':
opts.shm_id = atoi(optarg);
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
if (rc < 0) {
fprintf(stderr, "unknown flag\n");
usage();
exit(EXIT_FAILURE);
}
opts.print_level = SPDK_LOG_DEBUG;
#ifndef DEBUG
fprintf(stderr, "%s must be rebuilt with CONFIG_DEBUG=y for -t flag.\n",
argv[0]);
usage();
exit(EXIT_FAILURE);
#endif
break;
case 'm':
opts.reactor_mask = optarg;
break;
case 'n':
opts.mem_channel = atoi(optarg);
break;
case 'p':
opts.master_core = atoi(optarg);
break;
case 's':
opts.mem_size = atoi(optarg);
break;
case 'e':
opts.tpoint_group_mask = optarg;
break;
case 'q':
opts.print_level = SPDK_LOG_WARN;
break;
case 'D':
case 'H':
default:
usage();
exit(EXIT_SUCCESS);
}
}
nvmf_parse_args(argc, argv, &opts);
rc = spdk_nvmf_tgt_start(&opts);

View File

@ -44,6 +44,9 @@
#define SPDK_VHOST_DEFAULT_ENABLE_COREDUMP true
#define SPDK_VHOST_DEFAULT_MEM_SIZE 1024
static const char *g_socket_path = NULL;
static const char *g_pid_path = NULL;
static void
vhost_app_opts_init(struct spdk_app_opts *opts)
{
@ -94,54 +97,50 @@ save_pid(const char *pid_path)
fclose(pid_file);
}
int
main(int argc, char *argv[])
static void
vhost_parse_args(int argc, char **argv, struct spdk_app_opts *opts)
{
struct spdk_app_opts opts = {};
int ch;
int rc;
const char *socket_path = NULL;
const char *pid_path = NULL;
int ch, rc;
vhost_app_opts_init(&opts);
vhost_app_opts_init(opts);
while ((ch = getopt(argc, argv, "c:de:f:i:m:Np:qs:S:t:h")) != -1) {
switch (ch) {
case 'c':
opts.config_file = optarg;
opts->config_file = optarg;
break;
case 'd':
opts.enable_coredump = false;
opts->enable_coredump = false;
break;
case 'e':
opts.tpoint_group_mask = optarg;
opts->tpoint_group_mask = optarg;
break;
case 'f':
pid_path = optarg;
g_pid_path = optarg;
break;
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
case 'i':
opts.shm_id = strtoul(optarg, NULL, 10);
opts->shm_id = strtoul(optarg, NULL, 10);
break;
case 'm':
opts.reactor_mask = optarg;
opts->reactor_mask = optarg;
break;
case 'N':
opts.no_pci = true;
opts->no_pci = true;
break;
case 'p':
opts.master_core = strtoul(optarg, NULL, 10);
opts->master_core = strtoul(optarg, NULL, 10);
break;
case 'q':
opts.print_level = SPDK_LOG_WARN;
opts->print_level = SPDK_LOG_WARN;
break;
case 's':
opts.mem_size = strtoul(optarg, NULL, 10);
opts->mem_size = strtoul(optarg, NULL, 10);
break;
case 'S':
socket_path = optarg;
g_socket_path = optarg;
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
@ -150,7 +149,7 @@ main(int argc, char *argv[])
usage(argv[0]);
exit(EXIT_FAILURE);
}
opts.print_level = SPDK_LOG_DEBUG;
opts->print_level = SPDK_LOG_DEBUG;
#ifndef DEBUG
fprintf(stderr, "%s must be rebuilt with CONFIG_DEBUG=y for -t flag.\n",
argv[0]);
@ -164,15 +163,26 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
}
if (pid_path) {
save_pid(pid_path);
int
main(int argc, char *argv[])
{
struct spdk_app_opts opts = {};
int rc;
vhost_app_opts_init(&opts);
vhost_parse_args(argc, argv, &opts);
if (g_pid_path) {
save_pid(g_pid_path);
}
opts.shutdown_cb = spdk_vhost_shutdown_cb;
/* Blocks until the application is exiting */
rc = spdk_app_start(&opts, spdk_vhost_startup, (void *)socket_path, NULL);
rc = spdk_app_start(&opts, spdk_vhost_startup, (void *)g_socket_path, NULL);
spdk_app_fini();