Commit 0489bcb1 authored by Jim Harris's avatar Jim Harris Committed by Daniel Verkamp
Browse files

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: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ibbfb08ac687acf3201c4a3e808edbe770213a6f0

Reviewed-on: https://review.gerrithub.io/385928


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent 1b306f4b
Loading
Loading
Loading
Loading
+34 −26
Original line number Diff line number Diff line
@@ -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,32 +88,21 @@ spdk_startup(void *arg1, void *arg2)
	}
}

int
main(int argc, char **argv)
static void
iscsi_parse_args(int argc, char **argv, struct spdk_app_opts *opts)
{
	int ch;
	int rc;
	int daemon_mode = 0;
	struct spdk_app_opts opts = {};

	/* default value in opts structure */
	spdk_app_opts_init(&opts);

	if (access(SPDK_ISCSI_DEFAULT_CONFIG, F_OK) == 0) {
		opts.config_file = SPDK_ISCSI_DEFAULT_CONFIG;
	}
	opts.name = "iscsi";
	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;
			opts->enable_coredump = false;
			break;
		case 'c':
			opts.config_file = optarg;
			opts->config_file = optarg;
			break;
		case 'i':
			opts.shm_id = atoi(optarg);
			opts->shm_id = atoi(optarg);
			break;
		case 't':
			rc = spdk_log_set_trace_flag(optarg);
@@ -120,7 +111,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 built with CONFIG_DEBUG=y for -t flag\n",
				argv[0]);
@@ -129,25 +120,25 @@ main(int argc, char **argv)
#endif
			break;
		case 'e':
			opts.tpoint_group_mask = optarg;
			opts->tpoint_group_mask = optarg;
			break;
		case 'q':
			opts.print_level = SPDK_LOG_WARN;
			opts->print_level = SPDK_LOG_WARN;
			break;
		case 'm':
			opts.reactor_mask = optarg;
			opts->reactor_mask = optarg;
			break;
		case 'n':
			opts.mem_channel = atoi(optarg);
			opts->mem_channel = atoi(optarg);
			break;
		case 'p':
			opts.master_core = atoi(optarg);
			opts->master_core = atoi(optarg);
			break;
		case 's':
			opts.mem_size = atoi(optarg);
			opts->mem_size = atoi(optarg);
			break;
		case 'b':
			daemon_mode = 1;
			g_daemon_mode = 1;
			break;
		case 'H':
		default:
@@ -155,8 +146,25 @@ main(int argc, char **argv)
			exit(EXIT_SUCCESS);
		}
	}
}

int
main(int argc, char **argv)
{
	int rc;
	struct spdk_app_opts opts = {};

	/* default value in opts structure */
	spdk_app_opts_init(&opts);

	if (access(SPDK_ISCSI_DEFAULT_CONFIG, F_OK) == 0) {
		opts.config_file = SPDK_ISCSI_DEFAULT_CONFIG;
	}
	opts.name = "iscsi";

	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);
+30 −24
Original line number Diff line number Diff line
@@ -65,32 +65,21 @@ usage(void)
	printf(" -d         - disable coredump file enabling\n");
}


int
main(int argc, char **argv)
static void
nvmf_parse_args(int argc, char **argv, struct spdk_app_opts *opts)
{
	int ch;
	int rc;
	struct spdk_app_opts opts = {};

	/* default value in opts */
	spdk_app_opts_init(&opts);
	opts.name = "nvmf";
	if (access(SPDK_NVMF_DEFAULT_CONFIG, F_OK) == 0) {
		opts.config_file = SPDK_NVMF_DEFAULT_CONFIG;
	}
	opts.max_delay_us = 1000; /* 1 ms */
	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;
			opts->enable_coredump = false;
			break;
		case 'c':
			opts.config_file = optarg;
			opts->config_file = optarg;
			break;
		case 'i':
			opts.shm_id = atoi(optarg);
			opts->shm_id = atoi(optarg);
			break;
		case 't':
			rc = spdk_log_set_trace_flag(optarg);
@@ -99,7 +88,7 @@ main(int argc, char **argv)
				usage();
				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]);
@@ -108,22 +97,22 @@ main(int argc, char **argv)
#endif
			break;
		case 'm':
			opts.reactor_mask = optarg;
			opts->reactor_mask = optarg;
			break;
		case 'n':
			opts.mem_channel = atoi(optarg);
			opts->mem_channel = atoi(optarg);
			break;
		case 'p':
			opts.master_core = atoi(optarg);
			opts->master_core = atoi(optarg);
			break;
		case 's':
			opts.mem_size = atoi(optarg);
			opts->mem_size = atoi(optarg);
			break;
		case 'e':
			opts.tpoint_group_mask = optarg;
			opts->tpoint_group_mask = optarg;
			break;
		case 'q':
			opts.print_level = SPDK_LOG_WARN;
			opts->print_level = SPDK_LOG_WARN;
			break;
		case 'D':
		case 'H':
@@ -132,6 +121,23 @@ main(int argc, char **argv)
			exit(EXIT_SUCCESS);
		}
	}
}

int
main(int argc, char **argv)
{
	int rc;
	struct spdk_app_opts opts = {};

	/* default value in opts */
	spdk_app_opts_init(&opts);
	opts.name = "nvmf";
	if (access(SPDK_NVMF_DEFAULT_CONFIG, F_OK) == 0) {
		opts.config_file = SPDK_NVMF_DEFAULT_CONFIG;
	}
	opts.max_delay_us = 1000; /* 1 ms */

	nvmf_parse_args(argc, argv, &opts);

	rc = spdk_nvmf_tgt_start(&opts);

+33 −23
Original line number Diff line number Diff line
@@ -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);
		}
	}
}

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 (pid_path) {
		save_pid(pid_path);
	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();