diff mbox

[dpdk-dev,v7,09/14] eal/pci: Add a function to remove the entry of devargs list

Message ID 1423470639-15744-10-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Tetsuya Mukawa Feb. 9, 2015, 8:30 a.m. UTC
The function removes the specified devargs entry from devargs_list.
Also, the patch adds sanity checking to rte_eal_devargs_add().

v5:
- Change function definition of rte_eal_devargs_remove().
v4:
- Fix sanity check code.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/common/eal_common_devargs.c  | 60 +++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_devargs.h | 21 ++++++++++
 2 files changed, 81 insertions(+)
diff mbox

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 4c7d11a..5b1ac8e 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -44,6 +44,35 @@ 
 struct rte_devargs_list devargs_list =
 	TAILQ_HEAD_INITIALIZER(devargs_list);
 
+
+/* find a entry specified by pci address or device name */
+static struct rte_devargs *
+rte_eal_devargs_find(enum rte_devtype devtype, void *args)
+{
+	struct rte_devargs *devargs;
+
+	if (args == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+		switch (devtype) {
+		case RTE_DEVTYPE_WHITELISTED_PCI:
+		case RTE_DEVTYPE_BLACKLISTED_PCI:
+			if (eal_compare_pci_addr(&devargs->pci.addr, args) == 0)
+				goto found;
+			break;
+		case RTE_DEVTYPE_VIRTUAL:
+			if (memcmp(&devargs->virtual.drv_name, args,
+			    strlen((char *)args)) == 0)
+				goto found;
+			break;
+		}
+	}
+	return NULL;
+found:
+	return devargs;
+}
+
 /* store a whitelist parameter for later parsing */
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
@@ -87,6 +116,12 @@  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 			free(devargs);
 			return -1;
 		}
+		/* make sure there is no same entry */
+		if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) {
+			RTE_LOG(ERR, EAL,
+				"device already registered: <%s>\n", buf);
+			return -1;
+		}
 		break;
 	case RTE_DEVTYPE_VIRTUAL:
 		/* save driver name */
@@ -98,6 +133,12 @@  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 			free(devargs);
 			return -1;
 		}
+		/* make sure there is no same entry */
+		if (rte_eal_devargs_find(devtype, &devargs->virtual.drv_name)) {
+			RTE_LOG(ERR, EAL,
+				"device already registered: <%s>\n", buf);
+			return -1;
+		}
 		break;
 	}
 
@@ -105,6 +146,25 @@  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	return 0;
 }
 
+/* remove it from the devargs_list */
+int
+rte_eal_devargs_remove(enum rte_devtype devtype, void *args)
+{
+	struct rte_devargs *devargs;
+
+	if (args == NULL)
+		return -EINVAL;
+
+	devargs = rte_eal_devargs_find(devtype, args);
+	if (devargs == NULL) {
+		RTE_LOG(ERR, EAL, "device not found\n");
+		return -ENODEV;
+	}
+
+	TAILQ_REMOVE(&devargs_list, devargs, next);
+	return 0;
+}
+
 /* count the number of devices of a specified type */
 unsigned int
 rte_eal_devargs_type_count(enum rte_devtype devtype)
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 9f9c98f..6d9763b 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -123,6 +123,27 @@  extern struct rte_devargs_list devargs_list;
 int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str);
 
 /**
+ * Remove a device from the user device list
+ *
+ * For PCI devices, the format of arguments string is "PCI_ADDR". It shouldn't
+ * involve parameters for the device. Example: "08:00.1".
+ *
+ * For virtual devices, the format of arguments string is "DRIVER_NAME*". It
+ * shouldn't involve parameters for the device. Example: "eth_ring". The
+ * validity of the driver name is not checked by this function, it is done
+ * when closing the drivers.
+ *
+ * @param devtype
+ *   The type of the device.
+ * @param name
+ *   The name of the device.
+ *
+ * @return
+ *   - 0 on success, negative on error
+ */
+int rte_eal_devargs_remove(enum rte_devtype devtype, void *args);
+
+/**
  * Count the number of user devices of a specified type
  *
  * @param devtype