Add helpers to get a rte_bus object details.
This will be used externally.
Internal users may still dereference a rte_bus object.

Signed-off-by: David Marchand <david.march...@redhat.com>
---
Changes since RFC v1:
- changed approach: only external users are updated,

---
 app/test-pmd/config.c                        |  4 +--
 app/test-pmd/testpmd.c                       |  4 +--
 app/test/test_devargs.c                      |  4 +--
 examples/multi_process/hotplug_mp/commands.c |  4 +--
 lib/eal/common/eal_common_bus.c              | 26 ++++++++++++--------
 lib/eal/include/rte_bus.h                    | 14 +++++++++++
 lib/eal/version.map                          |  3 +++
 7 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index d988429f24..7bd28ee3e8 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -642,7 +642,7 @@ device_infos_display(const char *identifier)
                if (identifier && da.bus != next)
                        continue;
 
-               snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
+               snprintf(devstr, sizeof(devstr), "bus=%s", rte_bus_name(next));
                RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
 
                        if (!dev->driver)
@@ -653,7 +653,7 @@ device_infos_display(const char *identifier)
                                continue;
                        printf("\n%s Infos for device %s %s\n",
                               info_border, dev->name, info_border);
-                       printf("Bus name: %s", dev->bus->name);
+                       printf("Bus name: %s", rte_bus_name(dev->bus));
                        printf("\nDriver name: %s", dev->driver->name);
                        printf("\nDevargs: %s",
                               dev->devargs ? dev->devargs->args : "");
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 510e0be624..c7d1fa2719 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3507,9 +3507,9 @@ detach_devargs(char *identifier)
                }
        }
 
-       if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) {
+       if (rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name) != 0) {
                TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n",
-                           da.name, da.bus->name);
+                           da.name, rte_bus_name(da.bus));
                rte_devargs_reset(&da);
                return;
        }
diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c
index 16621285d2..ac5bc34c18 100644
--- a/app/test/test_devargs.c
+++ b/app/test/test_devargs.c
@@ -98,9 +98,9 @@ test_valid_devargs_cases(const struct devargs_case *list, 
size_t n)
                              list[i].bus_kv) != 0)
                        goto fail;
                if (list[i].bus != NULL &&
-                   strcmp(da.bus->name, list[i].bus) != 0) {
+                   strcmp(rte_bus_name(da.bus), list[i].bus) != 0) {
                        printf("rte_devargs_parse(%s) bus name (%s) not 
expected (%s)\n",
-                              list[i].devargs, da.bus->name, list[i].bus);
+                              list[i].devargs, rte_bus_name(da.bus), 
list[i].bus);
                        goto fail;
                }
                if ((list[i].class_kv > 0 || list[i].class != NULL) &&
diff --git a/examples/multi_process/hotplug_mp/commands.c 
b/examples/multi_process/hotplug_mp/commands.c
index da8b5e5924..88f44e00a0 100644
--- a/examples/multi_process/hotplug_mp/commands.c
+++ b/examples/multi_process/hotplug_mp/commands.c
@@ -126,7 +126,7 @@ static void cmd_dev_attach_parsed(void *parsed_result,
                return;
        }
 
-       if (!rte_eal_hotplug_add(da.bus->name, da.name, da.args))
+       if (!rte_eal_hotplug_add(rte_bus_name(da.bus), da.name, da.args))
                cmdline_printf(cl, "attached device %s\n", da.name);
        else
                cmdline_printf(cl, "failed to attached device %s\n",
@@ -173,7 +173,7 @@ static void cmd_dev_detach_parsed(void *parsed_result,
        }
 
        printf("detaching...\n");
-       if (!rte_eal_hotplug_remove(da.bus->name, da.name))
+       if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name))
                cmdline_printf(cl, "detached device %s\n",
                        da.name);
        else
diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c
index baa5b532af..cbf382f967 100644
--- a/lib/eal/common/eal_common_bus.c
+++ b/lib/eal/common/eal_common_bus.c
@@ -16,11 +16,17 @@
 static struct rte_bus_list rte_bus_list =
        TAILQ_HEAD_INITIALIZER(rte_bus_list);
 
+const char *
+rte_bus_name(const struct rte_bus *bus)
+{
+       return bus->name;
+}
+
 void
 rte_bus_register(struct rte_bus *bus)
 {
        RTE_VERIFY(bus);
-       RTE_VERIFY(bus->name && strlen(bus->name));
+       RTE_VERIFY(rte_bus_name(bus) && strlen(rte_bus_name(bus)));
        /* A bus should mandatorily have the scan implemented */
        RTE_VERIFY(bus->scan);
        RTE_VERIFY(bus->probe);
@@ -29,14 +35,14 @@ rte_bus_register(struct rte_bus *bus)
        RTE_VERIFY(!bus->plug || bus->unplug);
 
        TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
-       RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name);
+       RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", rte_bus_name(bus));
 }
 
 void
 rte_bus_unregister(struct rte_bus *bus)
 {
        TAILQ_REMOVE(&rte_bus_list, bus, next);
-       RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", bus->name);
+       RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", rte_bus_name(bus));
 }
 
 /* Scan all the buses for registered devices */
@@ -50,7 +56,7 @@ rte_bus_scan(void)
                ret = bus->scan();
                if (ret)
                        RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n",
-                               bus->name);
+                               rte_bus_name(bus));
        }
 
        return 0;
@@ -64,7 +70,7 @@ rte_bus_probe(void)
        struct rte_bus *bus, *vbus = NULL;
 
        TAILQ_FOREACH(bus, &rte_bus_list, next) {
-               if (!strcmp(bus->name, "vdev")) {
+               if (!strcmp(rte_bus_name(bus), "vdev")) {
                        vbus = bus;
                        continue;
                }
@@ -72,14 +78,14 @@ rte_bus_probe(void)
                ret = bus->probe();
                if (ret)
                        RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
-                               bus->name);
+                               rte_bus_name(bus));
        }
 
        if (vbus) {
                ret = vbus->probe();
                if (ret)
                        RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
-                               vbus->name);
+                               rte_bus_name(vbus));
        }
 
        return 0;
@@ -92,7 +98,7 @@ bus_dump_one(FILE *f, struct rte_bus *bus)
        int ret;
 
        /* For now, dump only the bus name */
-       ret = fprintf(f, " %s\n", bus->name);
+       ret = fprintf(f, " %s\n", rte_bus_name(bus));
 
        /* Error in case of inability in writing to stream */
        if (ret < 0)
@@ -163,7 +169,7 @@ cmp_bus_name(const struct rte_bus *bus, const void *_name)
 {
        const char *name = _name;
 
-       return strcmp(bus->name, name);
+       return strcmp(rte_bus_name(bus), name);
 }
 
 struct rte_bus *
@@ -213,7 +219,7 @@ rte_bus_get_iommu_class(void)
 
                bus_iova_mode = bus->get_iommu_class();
                RTE_LOG(DEBUG, EAL, "Bus %s wants IOVA as '%s'\n",
-                       bus->name,
+                       rte_bus_name(bus),
                        bus_iova_mode == RTE_IOVA_DC ? "DC" :
                        (bus_iova_mode == RTE_IOVA_PA ? "PA" : "VA"));
                if (bus_iova_mode == RTE_IOVA_PA)
diff --git a/lib/eal/include/rte_bus.h b/lib/eal/include/rte_bus.h
index 17edaa37c9..3848b44db0 100644
--- a/lib/eal/include/rte_bus.h
+++ b/lib/eal/include/rte_bus.h
@@ -266,6 +266,20 @@ struct rte_bus {
 
 };
 
+/**
+ * Retrieve a bus name.
+ *
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @param bus
+ *   A pointer to a rte_bus structure.
+ * @return
+ *   A pointer to the bus name string.
+ */
+__rte_experimental
+const char *rte_bus_name(const struct rte_bus *bus);
+
 /**
  * Register a Bus handler.
  *
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 1f293e768b..aa53064db1 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -424,6 +424,9 @@ EXPERIMENTAL {
        rte_thread_self;
        rte_thread_set_affinity_by_id;
        rte_thread_set_priority;
+
+       # added in 22.11
+       rte_bus_name;
 };
 
 INTERNAL {
-- 
2.36.1

Reply via email to