[dpdk-dev] [PATCH v2 2/3] dev: remove vdev function dependency

Gaetan Rivet gaetan.rivet at 6wind.com
Thu Jun 1 12:12:01 CEST 2017


Signed-off-by: Gaetan Rivet <gaetan.rivet at 6wind.com>
---
 lib/librte_eal/common/eal_common_dev.c | 49 +++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 968c66e..c286628 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -61,6 +61,7 @@ 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;
 	int ret;
 
 	if (name == NULL || devargs == NULL) {
@@ -69,31 +70,35 @@ 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;
-
+	if (dev)
 		bus = rte_bus_find_by_device(dev);
-		if (!bus) {
-			RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n",
-				name);
-			return -EINVAL;
-		}
-
-		if (!bus->plug) {
-			RTE_LOG(ERR, EAL, "Bus function not supported\n");
-			return -ENOTSUP;
-		}
-
+	else
+		bus = rte_bus_from_dev(name);
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n",
+			name);
+		return -EINVAL;
+	}
+	if (!bus->plug) {
+		RTE_LOG(ERR, EAL, "Device hotplug not supported on this bus\n");
+		return -ENOTSUP;
+	}
+	if (!dev) {
+		struct rte_devargs da;
+		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)
+			return ret;
+		ret = bus->plug(&da);
+	} else {
 		ret = bus->plug(dev->devargs);
-		goto out;
 	}
-
-	/*
-	 * 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 (ret)
 		RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n",
 			name);
-- 
2.1.4



More information about the dev mailing list