From cda27398e5b382396124f8b57ad8a1a996555a75 Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Tue, 11 Jun 2019 07:55:22 -0400 Subject: [PATCH] examples/nvme/hello_world: Optional VMD enumeration New flag -V was added for VMD enabling. Change-Id: I2d090a70b9d9b2bd996467a9b3da908f6eed1062 Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457601 Reviewed-by: Paul Luse Reviewed-by: Ben Walker Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- examples/nvme/hello_world/hello_world.c | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 34913073e..6a7f4f8e9 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -34,6 +34,7 @@ #include "spdk/stdinc.h" #include "spdk/nvme.h" +#include "spdk/vmd.h" #include "spdk/env.h" struct ctrlr_entry { @@ -52,6 +53,8 @@ struct ns_entry { static struct ctrlr_entry *g_controllers = NULL; static struct ns_entry *g_namespaces = NULL; +static bool g_vmd = false; + static void register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns) { @@ -322,11 +325,44 @@ cleanup(void) } } +static void +usage(const char *program_name) +{ + printf("%s [options]", program_name); + printf("\n"); + printf("options:\n"); + printf(" -V enumerate VMD\n"); +} + +static int +parse_args(int argc, char **argv) +{ + int op; + + while ((op = getopt(argc, argv, "V")) != -1) { + switch (op) { + case 'V': + g_vmd = true; + break; + default: + usage(argv[0]); + return 1; + } + } + + return 0; +} + 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. @@ -343,6 +379,11 @@ int main(int argc, char **argv) printf("Initializing NVMe Controllers\n"); + if (g_vmd && spdk_vmd_init()) { + fprintf(stderr, "Failed to initialize VMD." + " Some NVMe devices can be unavailable.\n"); + } + /* * Start the SPDK NVMe enumeration process. probe_cb will be called * for each NVMe controller found, giving our application a choice on