From: Ophir Munk Date: Mon, 21 May 2018 07:54:33 +0000 (+0000) Subject: net/tap: fix device removal when no queue exist X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=3101191c63ab25a9d743b96cc004eec2e9a8c1cc;p=dpdk.git net/tap: fix device removal when no queue exist 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. Its only purpose is to serve as a keep-alive mechanism for the TAP device. Fixes: bf7b7f437b49 ("net/tap: create netdevice during probing") Cc: stable@dpdk.org Signed-off-by: Ophir Munk Acked-by: Keith Wiles --- diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 968b2b1c9f..01552fa4ff 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -812,6 +812,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 @@ -1385,6 +1394,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, dev->intr_handle = &pmd->intr_handle; /* Presetup the fds to -1 as being not valid */ + pmd->ka_fd = -1; for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) { pmd->rxq[i].fd = -1; pmd->txq[i].fd = -1; @@ -1397,13 +1407,17 @@ 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 == -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) @@ -1797,9 +1811,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 67c9d4beeb..c87a0b8151 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -77,6 +77,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 */