nvmf: Move the nvmf_tgt app init and start functions out of main().

Added a new function spdk_nvmf_tgt_start() that initializes and
starts the nvmf app. The main function now only parses the command
line args and calls into spdk_nvmf_tgt_start().

Change-Id: I886a4021762a11c3c1f6ebfff5ed72adc409a34e
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Prashanth Nayak 2017-04-03 12:56:50 -07:00 committed by Daniel Verkamp
parent 0b56a5b4cf
commit b512e01a50
4 changed files with 164 additions and 130 deletions

View File

@ -40,7 +40,7 @@ APP = nvmf_tgt
CFLAGS += $(ENV_CFLAGS)
C_SRCS := conf.c nvmf_tgt.c nvmf_rpc.c
C_SRCS := conf.c nvmf_main.c nvmf_tgt.c nvmf_rpc.c
SPDK_LIB_LIST = nvmf event log trace conf util bdev copy rpc jsonrpc json
SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc

156
app/nvmf_tgt/nvmf_main.c Normal file
View File

@ -0,0 +1,156 @@
/*-
* 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.
*/
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include "spdk/env.h"
#include "nvmf_tgt.h"
#include "spdk/event.h"
#include "spdk/log.h"
#define SPDK_NVMF_BUILD_ETC "/usr/local/etc/nvmf"
#define SPDK_NVMF_DEFAULT_CONFIG SPDK_NVMF_BUILD_ETC "/nvmf.conf"
static void
usage(void)
{
struct spdk_app_opts opts;
spdk_app_opts_init(&opts);
printf("nvmf [options]\n");
printf("options:\n");
printf(" -c config - config file (default %s)\n", SPDK_NVMF_DEFAULT_CONFIG);
printf(" -e mask - tracepoint group mask for spdk trace buffers (default 0x0)\n");
printf(" -m mask - core mask for DPDK\n");
printf(" -i shared memory ID (optional)\n");
printf(" -l facility - use specific syslog facility (default %s)\n",
opts.log_facility);
printf(" -n channel number of memory channels used for DPDK\n");
printf(" -p core master (primary) core for DPDK\n");
printf(" -s size memory size in MB for DPDK\n");
spdk_tracelog_usage(stdout, "-t");
printf(" -v - verbose (enable warnings)\n");
printf(" -H - show this usage\n");
printf(" -d - disable coredump file enabling\n");
}
int
main(int argc, char **argv)
{
int ch;
int rc;
struct spdk_app_opts opts = {};
/* default value in opts */
spdk_app_opts_init(&opts);
opts.name = "nvmf";
opts.config_file = SPDK_NVMF_DEFAULT_CONFIG;
opts.max_delay_us = 1000; /* 1 ms */
while ((ch = getopt(argc, argv, "c:de:i:l: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 'l':
opts.log_facility = optarg;
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
if (rc < 0) {
fprintf(stderr, "unknown flag\n");
usage();
exit(EXIT_FAILURE);
}
#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.dpdk_mem_channel = atoi(optarg);
break;
case 'p':
opts.dpdk_master_core = atoi(optarg);
break;
case 's':
opts.dpdk_mem_size = atoi(optarg);
break;
case 'e':
opts.tpoint_group_mask = optarg;
break;
case 'q':
spdk_g_notice_stderr_flag = 0;
break;
case 'D':
case 'H':
default:
usage();
exit(EXIT_SUCCESS);
}
}
if (spdk_g_notice_stderr_flag == 1 &&
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);
}
rc = spdk_nvmf_tgt_start(&opts);
return rc;
}

View File

@ -48,9 +48,6 @@
#include "spdk/log.h"
#include "spdk/nvme.h"
#define SPDK_NVMF_BUILD_ETC "/usr/local/etc/nvmf"
#define SPDK_NVMF_DEFAULT_CONFIG SPDK_NVMF_BUILD_ETC "/nvmf.conf"
static struct spdk_poller *g_acceptor_poller = NULL;
static TAILQ_HEAD(, nvmf_tgt_subsystem) g_subsystems = TAILQ_HEAD_INITIALIZER(g_subsystems);
@ -271,32 +268,6 @@ nvmf_tgt_shutdown_subsystem_by_nqn(const char *nqn)
return -1;
}
static void
usage(void)
{
struct spdk_app_opts opts;
spdk_app_opts_init(&opts);
printf("nvmf [options]\n");
printf("options:\n");
printf(" -c config - config file (default %s)\n", SPDK_NVMF_DEFAULT_CONFIG);
printf(" -e mask - tracepoint group mask for spdk trace buffers (default 0x0)\n");
printf(" -m mask - core mask for DPDK\n");
printf(" -i shared memory ID (optional)\n");
printf(" -l facility - use specific syslog facility (default %s)\n",
opts.log_facility);
printf(" -n channel number of memory channels used for DPDK\n");
printf(" -p core master (primary) core for DPDK\n");
printf(" -s size memory size in MB for DPDK\n");
spdk_tracelog_usage(stdout, "-t");
printf(" -v - verbose (enable warnings)\n");
printf(" -H - show this usage\n");
printf(" -d - disable coredump file enabling\n");
}
static void
acceptor_poll(void *arg)
{
@ -338,110 +309,13 @@ initialize_error:
spdk_app_stop(rc);
}
/*! \file
This is the main file.
*/
/*!
\brief This is the main function for the NVMf target application.
\msc
c_runtime [label="C Runtime"], nvmf [label="NVMf target"];
c_runtime=>nvmf [label="main()"];
nvmf=>nvmf [label="spdk_app_init()"];
nvmf=>nvmf [label="spdk_event_allocate()"];
nvmf=>nvmf [label="spdk_app_start()"];
nvmf=>nvmf [label="spdk_app_fini()"];
c_runtime<<nvmf;
\endmsc
*/
int
main(int argc, char **argv)
spdk_nvmf_tgt_start(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";
opts.config_file = SPDK_NVMF_DEFAULT_CONFIG;
opts.max_delay_us = 1000; /* 1 ms */
while ((ch = getopt(argc, argv, "c:de:i:l: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 'l':
opts.log_facility = optarg;
break;
case 't':
rc = spdk_log_set_trace_flag(optarg);
if (rc < 0) {
fprintf(stderr, "unknown flag\n");
usage();
exit(EXIT_FAILURE);
}
#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.dpdk_mem_channel = atoi(optarg);
break;
case 'p':
opts.dpdk_master_core = atoi(optarg);
break;
case 's':
opts.dpdk_mem_size = atoi(optarg);
break;
case 'e':
opts.tpoint_group_mask = optarg;
break;
case 'q':
spdk_g_notice_stderr_flag = 0;
break;
case 'D':
case 'H':
default:
usage();
exit(EXIT_SUCCESS);
}
}
if (spdk_g_notice_stderr_flag == 1 &&
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);
}
opts.shutdown_cb = spdk_nvmf_shutdown_cb;
spdk_app_init(&opts);
opts->shutdown_cb = spdk_nvmf_shutdown_cb;
spdk_app_init(opts);
printf("Total cores available: %d\n", rte_lcore_count());
/* Blocks until the application is exiting */

View File

@ -38,6 +38,7 @@
#include "spdk/nvmf.h"
#include "spdk/queue.h"
#include "spdk/event.h"
struct rpc_listen_address {
char *transport;
@ -85,4 +86,7 @@ spdk_nvmf_construct_subsystem(const char *name,
int
nvmf_tgt_shutdown_subsystem_by_nqn(const char *nqn);
int spdk_nvmf_tgt_start(struct spdk_app_opts *opts);
#endif