From 4f011ef7c38661cfb9d3139988e557ab1fe36a85 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 16 Oct 2019 11:48:03 +0200 Subject: [PATCH] examples/lsvmd: list VMD devices This example application only enumerated VMD devices but didn't do anything else. Now it goes over all PCI devices and prints those behind the VMD. Change-Id: I6134088e820a90c203200294540cb8174b1a492e Signed-off-by: Konrad Sztyber Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471480 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Wojciech Malikowski --- examples/vmd/lsvmd/lsvmd.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/vmd/lsvmd/lsvmd.c b/examples/vmd/lsvmd/lsvmd.c index 7f1e92dac..d8eef6255 100644 --- a/examples/vmd/lsvmd/lsvmd.c +++ b/examples/vmd/lsvmd/lsvmd.c @@ -33,6 +33,7 @@ #include "spdk/stdinc.h" #include "spdk/log.h" +#include "spdk/env.h" #include "spdk/vmd.h" struct spdk_pci_addr g_probe_addr; @@ -68,8 +69,11 @@ parse_args(int argc, char **argv) int main(int argc, char **argv) { struct spdk_env_opts opts; - int rc = parse_args(argc, argv); + struct spdk_pci_device *pci_device; + char addr_buf[128]; + int rc; + rc = parse_args(argc, argv); if (rc != 0) { return rc; } @@ -83,10 +87,22 @@ int main(int argc, char **argv) } rc = spdk_vmd_init(); - if (rc) { SPDK_ERRLOG("No VMD Controllers found\n"); } + for (pci_device = spdk_pci_get_first_device(); pci_device != NULL; + pci_device = spdk_pci_get_next_device(pci_device)) { + if (strcmp(spdk_pci_device_get_type(pci_device), "vmd") == 0) { + rc = spdk_pci_addr_fmt(addr_buf, sizeof(addr_buf), &pci_device->addr); + if (rc != 0) { + fprintf(stderr, "Failed to format VMD's PCI address\n"); + continue; + } + + printf("%s\n", addr_buf); + } + } + return rc; }