DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1] net/tap: keep device alive when no queues exist
@ 2018-05-16 16:10 Ophir Munk
  2018-05-17  9:47 ` [dpdk-dev] [PATCH v2] net/tap: fix device removal " Ophir Munk
  0 siblings, 1 reply; 11+ messages in thread
From: Ophir Munk @ 2018-05-16 16:10 UTC (permalink / raw)
  To: dev, Pascal Mazon, Keith Wiles
  Cc: Thomas Monjalon, Olga Shern, Ophir Munk, Shahaf Shuler

TAP device is created following its first queue creation. Multiple
queues can be added or removed over time. In Linux terminology those
are file descriptors which are opened or closed over time. As long as
the number of opened file descriptors is positive - TAP device will
appear as a Linux device. In case all queues are released (the
equivalent of all file descriptors being closed) the TAP device will
be removed. This can lead to abnormalities in different scenarios
where the TAP device should exist even if all its queues are released.
In order to make TAP existence independent of its number of queues -
an extra file descriptor is opened on TAP creation and is closed on
TAP closure. It's only purpose is to serve as a keep-alive mechanism
for the TAP device.

Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
---
 drivers/net/tap/rte_eth_tap.c | 31 ++++++++++++++++++++++++-------
 drivers/net/tap/rte_eth_tap.h |  1 +
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index c006d07..6901edc 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -929,6 +929,15 @@ tap_dev_close(struct rte_eth_dev *dev)
 		ioctl(internals->ioctl_sock, SIOCSIFFLAGS,
 				&internals->remote_initial_flags);
 	}
+
+	if (internals->ka_fd != -1) {
+		close(internals->ka_fd);
+		internals->ka_fd = -1;
+	}
+	/*
+	 * Since TUN device has no more opened file descriptors
+	 * it will be removed from kernel
+	 */
 }
 
 static void
@@ -1561,13 +1570,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 			rte_memcpy(&pmd->eth_addr, mac_addr, sizeof(*mac_addr));
 	}
 
-	/* Immediately create the netdevice (this will create the 1st queue). */
-	/* rx queue */
-	if (tap_setup_queue(dev, pmd, 0, 1) == -1)
-		goto error_exit;
-	/* tx queue */
-	if (tap_setup_queue(dev, pmd, 0, 0) == -1)
+	/*
+	 * Allocate a TUN device keep-alive file descriptor that will only be
+	 * closed when the TUN device itself is closed or removed.
+	 * This keep-alive file descriptor will guarantee that the TUN device
+	 * exists even when all of its queues are closed
+	 */
+	pmd->ka_fd = tun_alloc(pmd);
+	if (pmd->ka_fd < 0) {
+		pmd->ka_fd = -1;
+		TAP_LOG(ERR, "Unable to create %s interface", tuntap_name);
 		goto error_exit;
+	}
 
 	ifr.ifr_mtu = dev->data->mtu;
 	if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0)
@@ -1961,9 +1975,12 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 
 	close(internals->ioctl_sock);
 	rte_free(eth_dev->data->dev_private);
-
 	rte_eth_dev_release_port(eth_dev);
 
+	if (internals->ka_fd != -1) {
+		close(internals->ka_fd);
+		internals->ka_fd = -1;
+	}
 	return 0;
 }
 
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index babe42d..575dce4 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -81,6 +81,7 @@ struct pmd_internals {
 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
 	struct rte_intr_handle intr_handle;          /* LSC interrupt handle. */
+	int ka_fd;                        /* keep-alive file descriptor */
 };
 
 /* tap_intr.c */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-05-23  5:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-16 16:10 [dpdk-dev] [PATCH v1] net/tap: keep device alive when no queues exist Ophir Munk
2018-05-17  9:47 ` [dpdk-dev] [PATCH v2] net/tap: fix device removal " Ophir Munk
2018-05-17 12:59   ` Wiles, Keith
2018-05-18  8:38     ` Ophir Munk
2018-05-18  8:27   ` [dpdk-dev] [PATCH v3] " Ophir Munk
2018-05-21  7:54     ` [dpdk-dev] [PATCH v4] " Ophir Munk
2018-05-21 12:52       ` Wiles, Keith
2018-05-21 15:12         ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2018-05-23  4:50       ` [dpdk-dev] " Varghese, Vipin
2018-05-23  4:53         ` Wiles, Keith
2018-05-23  5:22           ` Varghese, Vipin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).