[dpdk-dev,v2,09/15] devargs: add busname string field

Message ID 20170714211213.34436-10-jblunck@infradead.org (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jan Blunck July 14, 2017, 9:12 p.m. UTC
  This adds the busname as a string to struct rte_devargs. This is a generic
replacement for enum rte_devtype without tightly coupling rte_devargs to
the rte_bus structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_devargs.c  | 9 +++++++++
 lib/librte_eal/common/include/rte_devargs.h | 2 ++
 test/test/test_devargs.c                    | 2 ++
 3 files changed, 13 insertions(+)
  

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index b5273287e..588df1410 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -128,6 +128,15 @@  rte_eal_devargs_parse(const char *dev, struct rte_devargs *da)
 		}
 	}
 	da->bus = bus;
+
+	/* Store bus name */
+	ret = snprintf(da->busname, sizeof(da->busname), "%s", bus->name);
+	if (ret < 0 || ret >= (int)sizeof(da->busname)) {
+		RTE_LOG(ERR, EAL, "Invalid bus name: \"%s\"\n", bus->name);
+		ret = -EINVAL;
+		goto fail;
+	}
+
 	ret = 0;
 
 fail:
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 41db817cc..8dafb167e 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -79,6 +79,8 @@  struct rte_devargs {
 	enum rte_devtype type;
 	/** Bus handle for the device. */
 	struct rte_bus *bus;
+	/** Name of the bus the device belongs to. */
+	char busname[RTE_DEV_NAME_MAX_LEN];
 	/** Name of the device. */
 	char name[RTE_DEV_NAME_MAX_LEN];
 	/** Arguments string as given by user or "" for no argument. */
diff --git a/test/test/test_devargs.c b/test/test/test_devargs.c
index 178c3b243..9e0ff5995 100644
--- a/test/test/test_devargs.c
+++ b/test/test/test_devargs.c
@@ -135,6 +135,8 @@  test_devargs(void)
 	if (devargs != NULL)
 		goto fail;
 	devargs = &devargs_stack;
+	if (strcmp(devargs->busname, "pci") != 0)
+		goto fail;
 	if (strcmp(devargs->name, "08:00.1") != 0)
 		goto fail;
 	if (!devargs->args || strcmp(devargs->args, "foo=bar") != 0)