bus/vmbus: add cleanup support

Message ID 1679427105-31644-1-git-send-email-longli@linuxonhyperv.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series bus/vmbus: add cleanup support |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-unit-testing success Testing PASS

Commit Message

Long Li March 21, 2023, 7:31 p.m. UTC
  From: Long Li <longli@microsoft.com>

Implement VMBUS cleanup callback from eal_cleanup().

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/bus/vmbus/vmbus_common.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
  

Comments

Thomas Monjalon June 6, 2023, 2:27 p.m. UTC | #1
21/03/2023 20:31, longli@linuxonhyperv.com:
> From: Long Li <longli@microsoft.com>
> 
> Implement VMBUS cleanup callback from eal_cleanup().
> 
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/bus/vmbus/vmbus_common.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
> index 8d32d66504..a6277bfc06 100644
> --- a/drivers/bus/vmbus/vmbus_common.c
> +++ b/drivers/bus/vmbus/vmbus_common.c
> @@ -188,6 +188,34 @@ rte_vmbus_probe(void)
>  	return (probed && probed == failed) ? -1 : 0;
>  }
>  
> +static int
> +rte_vmbus_cleanup(void)
> +{
> +	struct rte_vmbus_device *dev, *tmp_dev;
> +	int error = 0;
> +
> +	RTE_TAILQ_FOREACH_SAFE(dev, &rte_vmbus_bus.device_list, next, tmp_dev) {
> +
> +		const struct rte_vmbus_driver *drv = dev->driver;
> +		int ret;
> +
> +		if (!drv || !drv->remove)

Changed to "== NULL" comparisons for the style :)

> +			continue;
> +
> +		ret = drv->remove(dev);
> +		if (ret < 0)
> +			error = -1;
> +
> +		rte_vmbus_unmap_device(dev);
> +
> +		dev->driver = NULL;
> +		dev->device.driver = NULL;
> +		free(dev);
> +	}
> +
> +	return error;
> +}

Applied, thanks.
  

Patch

diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index 8d32d66504..a6277bfc06 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -188,6 +188,34 @@  rte_vmbus_probe(void)
 	return (probed && probed == failed) ? -1 : 0;
 }
 
+static int
+rte_vmbus_cleanup(void)
+{
+	struct rte_vmbus_device *dev, *tmp_dev;
+	int error = 0;
+
+	RTE_TAILQ_FOREACH_SAFE(dev, &rte_vmbus_bus.device_list, next, tmp_dev) {
+
+		const struct rte_vmbus_driver *drv = dev->driver;
+		int ret;
+
+		if (!drv || !drv->remove)
+			continue;
+
+		ret = drv->remove(dev);
+		if (ret < 0)
+			error = -1;
+
+		rte_vmbus_unmap_device(dev);
+
+		dev->driver = NULL;
+		dev->device.driver = NULL;
+		free(dev);
+	}
+
+	return error;
+}
+
 static int
 vmbus_parse(const char *name, void *addr)
 {
@@ -285,6 +313,7 @@  struct rte_vmbus_bus rte_vmbus_bus = {
 	.bus = {
 		.scan = rte_vmbus_scan,
 		.probe = rte_vmbus_probe,
+		.cleanup = rte_vmbus_cleanup,
 		.find_device = vmbus_find_device,
 		.parse = vmbus_parse,
 	},