From 3e636be1cef7a1e9739c128e182ac7bbd33e5422 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Mon, 13 Dec 2021 10:39:43 -0700 Subject: [PATCH] lsvmd: use spdk_pci_for_each_device API Signed-off-by: Jim Harris Change-Id: I1ff5bea00f4b08bf879a3c726689b74f616c1c70 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10658 Reviewed-by: Konrad Sztyber Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- examples/vmd/lsvmd/lsvmd.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/vmd/lsvmd/lsvmd.c b/examples/vmd/lsvmd/lsvmd.c index b083bc049..45b815b6e 100644 --- a/examples/vmd/lsvmd/lsvmd.c +++ b/examples/vmd/lsvmd/lsvmd.c @@ -66,11 +66,26 @@ parse_args(int argc, char **argv) return 0; } +static void +print_device(void *ctx, struct spdk_pci_device *pci_device) +{ + char addr_buf[128]; + int rc; + + 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"); + return; + } + + printf("%s\n", addr_buf); + } +} + int main(int argc, char **argv) { struct spdk_env_opts opts; - struct spdk_pci_device *pci_device; - char addr_buf[128]; int rc; rc = parse_args(argc, argv); @@ -91,18 +106,7 @@ int main(int argc, char **argv) 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); - } - } + spdk_pci_for_each_device(NULL, print_device); spdk_vmd_fini();