diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index ed1a91513..25c2fd420 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -37,6 +37,8 @@ #include "spdk/vmd.h" #include "spdk/nvme_zns.h" #include "spdk/env.h" +#include "spdk/string.h" +#include "spdk/log.h" struct ctrlr_entry { struct spdk_nvme_ctrlr *ctrlr; @@ -53,6 +55,7 @@ struct ns_entry { static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers); static TAILQ_HEAD(, ns_entry) g_namespaces = TAILQ_HEAD_INITIALIZER(g_namespaces); +static struct spdk_nvme_transport_id g_trid = {}; static bool g_vmd = false; @@ -394,21 +397,67 @@ static void usage(const char *program_name) { printf("%s [options]", program_name); - printf("\n"); + printf("\t\n"); printf("options:\n"); - printf(" -V enumerate VMD\n"); + printf("\t[-d DPDK huge memory size in MB]\n"); + printf("\t[-g use single file descriptor for DPDK memory segments]\n"); + printf("\t[-i shared memory group ID]\n"); + printf("\t[-r remote NVMe over Fabrics target address]\n"); + printf("\t[-V enumerate VMD]\n"); +#ifdef DEBUG + printf("\t[-L enable debug logging]\n"); +#else + printf("\t[-L enable debug logging (flag disabled, must reconfigure with --enable-debug)\n"); +#endif } static int -parse_args(int argc, char **argv) +parse_args(int argc, char **argv, struct spdk_env_opts *env_opts) { - int op; + int op, rc; - while ((op = getopt(argc, argv, "V")) != -1) { + spdk_nvme_trid_populate_transport(&g_trid, SPDK_NVME_TRANSPORT_PCIE); + snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN); + + while ((op = getopt(argc, argv, "d:gi:r:L:V")) != -1) { switch (op) { case 'V': g_vmd = true; break; + case 'i': + env_opts->shm_id = spdk_strtol(optarg, 10); + if (env_opts->shm_id < 0) { + fprintf(stderr, "Invalid shared memory ID\n"); + return env_opts->shm_id; + } + break; + case 'g': + env_opts->hugepage_single_segments = true; + break; + case 'r': + if (spdk_nvme_transport_id_parse(&g_trid, optarg) != 0) { + fprintf(stderr, "Error parsing transport address\n"); + return 1; + } + break; + case 'd': + env_opts->mem_size = spdk_strtol(optarg, 10); + if (env_opts->mem_size < 0) { + fprintf(stderr, "Invalid DPDK memory size\n"); + return env_opts->mem_size; + } + break; + case 'L': + rc = spdk_log_set_flag(optarg); + if (rc < 0) { + fprintf(stderr, "unknown flag\n"); + usage(argv[0]); + exit(EXIT_FAILURE); + } +#ifdef DEBUG + spdk_log_set_print_level(SPDK_LOG_DEBUG); +#endif + break; default: usage(argv[0]); return 1; @@ -423,11 +472,6 @@ int main(int argc, char **argv) int rc; struct spdk_env_opts opts; - rc = parse_args(argc, argv); - if (rc != 0) { - return rc; - } - /* * SPDK relies on an abstraction around the local environment * named env that handles memory allocation and PCI device operations. @@ -435,8 +479,12 @@ int main(int argc, char **argv) * */ spdk_env_opts_init(&opts); + rc = parse_args(argc, argv, &opts); + if (rc != 0) { + return rc; + } + opts.name = "hello_world"; - opts.shm_id = 0; if (spdk_env_init(&opts) < 0) { fprintf(stderr, "Unable to initialize SPDK env\n"); return 1; @@ -456,7 +504,7 @@ int main(int argc, char **argv) * called for each controller after the SPDK NVMe driver has completed * initializing the controller we chose to attach. */ - rc = spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL); + rc = spdk_nvme_probe(&g_trid, NULL, probe_cb, attach_cb, NULL); if (rc != 0) { fprintf(stderr, "spdk_nvme_probe() failed\n"); cleanup(); diff --git a/test/nvme/nvme.sh b/test/nvme/nvme.sh index ffde62d32..936e8b3e3 100755 --- a/test/nvme/nvme.sh +++ b/test/nvme/nvme.sh @@ -116,7 +116,7 @@ fi run_test "nvme_reset" $testdir/reset/reset -q 64 -w write -s 4096 -t 5 run_test "nvme_identify" nvme_identify run_test "nvme_perf" nvme_perf -run_test "nvme_hello_world" $SPDK_EXAMPLE_DIR/hello_world +run_test "nvme_hello_world" $SPDK_EXAMPLE_DIR/hello_world -i 0 run_test "nvme_deallocated_value" $testdir/deallocated_value/deallocated_value run_test "nvme_sgl" $testdir/sgl/sgl run_test "nvme_e2edp" $testdir/e2edp/nvme_dp diff --git a/test/nvmf/target/nvmf_vfio_user.sh b/test/nvmf/target/nvmf_vfio_user.sh index 88bb2fd18..c09d64074 100755 --- a/test/nvmf/target/nvmf_vfio_user.sh +++ b/test/nvmf/target/nvmf_vfio_user.sh @@ -51,6 +51,8 @@ for i in $(seq 1 $NUM_DEVICES); do sleep 1 $SPDK_EXAMPLE_DIR/arbitration -t 3 -r "trtype:$TEST_TRANSPORT traddr:$test_traddr subnqn:$test_subnqn" -d 256 -g sleep 1 + $SPDK_EXAMPLE_DIR/hello_world -d 256 -g -r "trtype:$TEST_TRANSPORT traddr:$test_traddr subnqn:$test_subnqn" + sleep 1 done killprocess $nvmfpid