[dpdk-dev,v3,2/3] dev: remove vdev function dependency

Message ID aba9df09efaa3a92e2c3fa0ec3dcf485e3ebbdff.1496876926.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Gaëtan Rivet June 7, 2017, 11:58 p.m. UTC
  Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_dev.c | 50 ++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 20 deletions(-)
  

Comments

Thomas Monjalon June 21, 2017, 2:42 p.m. UTC | #1
08/06/2017 01:58, Gaetan Rivet:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/eal_common_dev.c | 50 ++++++++++++++++++++--------------
>  1 file changed, 30 insertions(+), 20 deletions(-)

It's difficult to understand this patch.
Please add some explanations.
And it may be better to insert or merge it in the first
attach/detach series.
  

Patch

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 8ef9b98..247c9c1 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -43,6 +43,7 @@ 
 #include <rte_debug.h>
 #include <rte_devargs.h>
 #include <rte_log.h>
+#include <rte_errno.h>
 
 #include "eal_private.h"
 
@@ -61,6 +62,8 @@  static int cmp_detached_dev_name(const struct rte_device *dev,
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	struct rte_device *dev;
+	struct rte_bus *bus;
+	struct rte_devargs da;
 	int ret;
 
 	if (name == NULL || devargs == NULL) {
@@ -70,30 +73,37 @@  int rte_eal_dev_attach(const char *name, const char *devargs)
 
 	dev = rte_bus_find_device(NULL, cmp_detached_dev_name, name);
 	if (dev) {
-		struct rte_bus *bus;
-
 		bus = rte_bus_find_by_device(dev);
-		if (!bus) {
-			RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n",
+	} else {
+		char da_str[snprintf(NULL, 0, "%s,%s", name, devargs) + 1];
+
+		/*
+		 * If we haven't found a bus device the user meant to hotplug
+		 * a device instead.
+		 */
+		snprintf(da_str, sizeof(da_str), "%s,%s", name, devargs);
+		ret = rte_eal_devargs_parse(da_str, &da);
+		if (ret) {
+			RTE_LOG(ERR, EAL, "Could not parse device (%s)\n",
 				name);
-			return -EINVAL;
-		}
-
-		if (!bus->plug) {
-			RTE_LOG(ERR, EAL, "Bus function not supported\n");
-			return -ENOTSUP;
+			return ret;
 		}
-
-		ret = (bus->plug(dev->devargs) == NULL);
-		goto out;
+		bus = da.bus;
 	}
-
-	/*
-	 * If we haven't found a bus device the user meant to "hotplug" a
-	 * virtual device instead.
-	 */
-	ret = rte_vdev_init(name, devargs);
-out:
+	if (bus == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n",
+			name);
+		return -EINVAL;
+	}
+	if (bus->plug == NULL) {
+		RTE_LOG(ERR, EAL, "Device hotplug not supported on this bus\n");
+		return -ENOTSUP;
+	}
+	if (dev == NULL)
+		dev = bus->plug(&da);
+	else
+		dev = bus->plug(dev->devargs);
+	ret = dev ? 0 : -rte_errno;
 	if (ret)
 		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
 			name);