[v5,7/7] app/testpmd: check not detaching device twice

Message ID 20181018013522.11253-8-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series replace attach/detach functions |

Checks

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

Commit Message

Thomas Monjalon Oct. 18, 2018, 1:35 a.m. UTC
  The command "port detach" is removing the EAL rte_device
of the ethdev port specified as parameter.

After detaching, the pointer, which maps a port to its device,
is resetted. This way, it is possible to check whether a port
is still associated to a (not removed) device.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-pmd/testpmd.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon Oct. 18, 2018, 1:45 a.m. UTC | #1
+Cc Bernard

18/10/2018 03:35, Thomas Monjalon:
> The command "port detach" is removing the EAL rte_device
> of the ethdev port specified as parameter.
> 
> After detaching, the pointer, which maps a port to its device,
> is resetted. This way, it is possible to check whether a port
> is still associated to a (not removed) device.
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  app/test-pmd/testpmd.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
> index f241ce363..3093d3306 100644
> --- a/app/test-pmd/testpmd.c
> +++ b/app/test-pmd/testpmd.c
> @@ -2340,8 +2340,17 @@ setup_attached_port(portid_t pi)
>  void
>  detach_port(portid_t port_id)
>  {
> +	struct rte_device *dev;
> +	portid_t sibling;
> +
>  	printf("Detaching a port...\n");
>  
> +	dev = rte_eth_devices[port_id].device;
> +	if (dev == NULL) {
> +		printf("Device already removed\n");
> +		return;
> +	}
> +
>  	if (ports[port_id].port_status != RTE_PORT_CLOSED) {
>  		if (ports[port_id].port_status != RTE_PORT_STOPPED) {
>  			printf("Port not stopped\n");
> @@ -2352,10 +2361,14 @@ detach_port(portid_t port_id)
>  			port_flow_flush(port_id);
>  	}
>  
> -	if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
> +	if (rte_dev_remove(dev) != 0) {
>  		TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
>  		return;
>  	}
> +	/* reset mapping between old ports and removed device */
> +	for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++)
> +		if (rte_eth_devices[sibling].device == dev)
> +			rte_eth_devices[sibling].device = NULL;
>  
>  	remove_unused_fwd_ports();
  

Patch

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index f241ce363..3093d3306 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2340,8 +2340,17 @@  setup_attached_port(portid_t pi)
 void
 detach_port(portid_t port_id)
 {
+	struct rte_device *dev;
+	portid_t sibling;
+
 	printf("Detaching a port...\n");
 
+	dev = rte_eth_devices[port_id].device;
+	if (dev == NULL) {
+		printf("Device already removed\n");
+		return;
+	}
+
 	if (ports[port_id].port_status != RTE_PORT_CLOSED) {
 		if (ports[port_id].port_status != RTE_PORT_STOPPED) {
 			printf("Port not stopped\n");
@@ -2352,10 +2361,14 @@  detach_port(portid_t port_id)
 			port_flow_flush(port_id);
 	}
 
-	if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) {
+	if (rte_dev_remove(dev) != 0) {
 		TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
 		return;
 	}
+	/* reset mapping between old ports and removed device */
+	for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++)
+		if (rte_eth_devices[sibling].device == dev)
+			rte_eth_devices[sibling].device = NULL;
 
 	remove_unused_fwd_ports();