[v2] net/tap: release port upon close
diff mbox series

Message ID 1600343273-22432-1-git-send-email-wangyunjian@huawei.com
State Superseded
Delegated to: Ferruh Yigit
Headers show
Series
  • [v2] net/tap: release port upon close
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot warning Travis build: failed
ci/iol-testing success Testing PASS
ci/checkpatch success coding style OK

Commit Message

wangyunjian Sept. 17, 2020, 11:47 a.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

Set RTE_ETH_DEV_CLOSE_REMOVE upon probe so all the private
resources for the port can be freed by rte_eth_dev_close().

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
   Remove redundant check and assignment suggested
   by Ferruh Yigit and Thomas Monjalon
---
 drivers/net/tap/rte_eth_tap.c | 43 +++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 20 deletions(-)

Comments

Ferruh Yigit Sept. 29, 2020, 4:56 p.m. UTC | #1
On 9/17/2020 12:47 PM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> Set RTE_ETH_DEV_CLOSE_REMOVE upon probe so all the private
> resources for the port can be freed by rte_eth_dev_close().
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v2:
>     Remove redundant check and assignment suggested
>     by Ferruh Yigit and Thomas Monjalon

Hi Yunjian,

There is a newer version of the tap close in the patchset related to the ethdev 
close updates:
https://patches.dpdk.org/patch/79086/

I will update this one as 'Superseded', can you please check the above one?

Thanks,
ferruh
wangyunjian Sept. 30, 2020, 12:58 a.m. UTC | #2
> -----Original Message-----
> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com]
> Sent: Wednesday, September 30, 2020 12:56 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: keith.wiles@intel.com; thomas@monjalon.net; Lilijun (Jerry)
> <jerry.lilijun@huawei.com>; xudingke <xudingke@huawei.com>
> Subject: Re: [dpdk-dev] [PATCH v2] net/tap: release port upon close
> 
> On 9/17/2020 12:47 PM, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > Set RTE_ETH_DEV_CLOSE_REMOVE upon probe so all the private resources
> > for the port can be freed by rte_eth_dev_close().
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> > v2:
> >     Remove redundant check and assignment suggested
> >     by Ferruh Yigit and Thomas Monjalon
> 
> Hi Yunjian,
> 
> There is a newer version of the tap close in the patchset related to the ethdev
> close updates:
> https://patches.dpdk.org/patch/79086/
> 
> I will update this one as 'Superseded', can you please check the above one?
> 

OK, I will check and test it.

Thanks,
Yunjian

> Thanks,
> ferruh

Patch
diff mbox series

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 339f24bf8..3844994a3 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -72,6 +72,10 @@ 
 
 static int tap_devices_count;
 
+static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {
+	"UNKNOWN", "TUN", "TAP"
+};
+
 static const char *valid_arguments[] = {
 	ETH_TAP_IFACE_ARG,
 	ETH_TAP_REMOTE_ARG,
@@ -1074,6 +1078,23 @@  tap_dev_close(struct rte_eth_dev *dev)
 		close(internals->ka_fd);
 		internals->ka_fd = -1;
 	}
+
+	/* mac_addrs must not be freed alone because part of dev_private */
+	dev->data->mac_addrs = NULL;
+
+	internals = dev->data->dev_private;
+	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
+		tuntap_types[internals->type], rte_socket_id());
+
+	if (internals->ioctl_sock != -1) {
+		close(internals->ioctl_sock);
+		internals->ioctl_sock = -1;
+	}
+	rte_free(dev->process_private);
+	dev->process_private = NULL;
+	if (tap_devices_count == 1)
+		rte_mp_action_unregister(TAP_MP_KEY);
+	tap_devices_count--;
 	/*
 	 * Since TUN device has no more opened file descriptors
 	 * it will be removed from kernel
@@ -1800,10 +1821,6 @@  static const struct eth_dev_ops ops = {
 	.filter_ctrl            = tap_dev_filter_ctrl,
 };
 
-static const char *tuntap_types[ETH_TUNTAP_TYPE_MAX] = {
-	"UNKNOWN", "TUN", "TAP"
-};
-
 static int
 eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 		   char *remote_iface, struct rte_ether_addr *mac_addr,
@@ -1854,7 +1871,7 @@  eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,
 	/* Setup some default values */
 	data = dev->data;
 	data->dev_private = pmd;
-	data->dev_flags = RTE_ETH_DEV_INTR_LSC;
+	data->dev_flags = RTE_ETH_DEV_INTR_LSC | RTE_ETH_DEV_CLOSE_REMOVE;
 	data->numa_node = numa_node;
 
 	data->dev_link = pmd_link;
@@ -2446,30 +2463,16 @@  static int
 rte_pmd_tap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
-	struct pmd_internals *internals;
 
 	/* find the ethdev entry */
 	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
-		return -ENODEV;
-
-	/* mac_addrs must not be freed alone because part of dev_private */
-	eth_dev->data->mac_addrs = NULL;
+		return 0;
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return rte_eth_dev_release_port(eth_dev);
 
 	tap_dev_close(eth_dev);
-
-	internals = eth_dev->data->dev_private;
-	TAP_LOG(DEBUG, "Closing %s Ethernet device on numa %u",
-		tuntap_types[internals->type], rte_socket_id());
-
-	close(internals->ioctl_sock);
-	rte_free(eth_dev->process_private);
-	if (tap_devices_count == 1)
-		rte_mp_action_unregister(TAP_MP_KEY);
-	tap_devices_count--;
 	rte_eth_dev_release_port(eth_dev);
 
 	return 0;