Skip to contentSkip to conversation

nic/tap: fix tap docs for device name

PATCH Superseded Keith Wiles 3 participants 31 messages Feb 2, 2017 – Feb 7, 2017 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 nic/tap: fix tap docs for device name

---
 doc/guides/nics/tap.rst | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
doc/guides/nics/tap.rst +7 -7
index 622b9e7..2ab60ff 100644
@@ -45,18 +45,18 @@ device.
 These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
-``--vdev=net_tap`` option on the DPDK application command line. Each
-``--vdev=net_tap`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap0`` option on the DPDK application command line. Each
+``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
 and so on.
 
 The interfaced name can be changed by adding the ``iface=foo0``, for example::
 
-   --vdev=net_tap,iface=foo0 --vdev=net_tap,iface=foo1, ...
+   --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
 Also the speed of the interface can be changed from 10G to whatever number
 needed, but the interface does not enforce that speed, for example::
 
-   --vdev=net_tap,iface=foo0,speed=25000
+   --vdev=net_tap0,iface=foo0,speed=25000
 
 After the DPDK application is started you can send and receive packets on the
 interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
@@ -97,7 +97,7 @@ following::
 
     sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -l 1-5 -n 4        \
      --proc-type auto --log-level 8 --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap --vdev=net_tap -b 05:00.0 -b 05:00.1                    \
+     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
      -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
      -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
      -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
@@ -131,6 +131,6 @@ time with ``start all``. The command ``str`` is an alias for ``start all`` and
 
 While running you should see the 64 byte counters increasing to verify the
 traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use the pktgen ``help``
+size of the packets after you stop the traffic. Use pktgen ``help``
 command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup.
+load commands at startup in command line or Lua script in pktgen.
Signature · 1 line
2.8.0.GIT
#1 lore raw

PATCH 2/5 net/tap: fix multi-queue support

---
 drivers/net/tap/rte_eth_tap.c | 93 ++++++++++++++++++++++---------------------
 1 file changed, 48 insertions(+), 45 deletions(-)
drivers/net/tap/rte_eth_tap.c +48 -45
index 3f179c3..9ed7a87 100644
@@ -115,10 +115,9 @@ struct pmd_internals {
  * supplied name.
  */
 static int
-tun_alloc(char *name)
+tun_alloc(char *name, uint16_t qid)
 {
 	struct ifreq ifr;
-	unsigned int features;
 	int fd;
 
 	memset(&ifr, 0, sizeof(struct ifreq));
@@ -133,55 +132,57 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
-	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
-		goto error;
-	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	/* This can only be done once per interface */
+	if (qid == 0) {
+		unsigned int features;
+
+		/* Grab the TUN features to verify we can work */
+		if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
+			RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
+			goto error;
+		}
+		RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
 
 #ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
-			RTE_PMD_TAP_MAX_QUEUES);
-	}
+		if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
+			RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
+			goto error;
+		} else if ((features & IFF_ONE_QUEUE) &&
+				(RTE_PMD_TAP_MAX_QUEUES == 1)) {
+			ifr.ifr_flags |= IFF_ONE_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		} else {
+			ifr.ifr_flags |= IFF_MULTI_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
+				RTE_PMD_TAP_MAX_QUEUES);
+		}
 #else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	}
+		if (RTE_PMD_TAP_MAX_QUEUES > 1) {
+			RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
+			goto error;
+		} else {
+			ifr.ifr_flags |= IFF_ONE_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		}
 #endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
-	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
-			ifr.ifr_name);
-		perror("TUNSETIFF");
-		goto error;
-	}
+		/* Set the TUN/TAP configuration and get the name if needed */
+		if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
+			RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+				ifr.ifr_name);
+			perror("TUNSETIFF");
+			goto error;
+		}
 
-	/* Always set the file descriptor to non-blocking */
-	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set to nonblocking\n");
-		perror("F_SETFL, NONBLOCK");
-		goto error;
+		/* Always set the file descriptor to non-blocking */
+		if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+			RTE_LOG(WARNING, PMD, "Unable to set %s to nonblocking\n",
+				ifr.ifr_name);
+			perror("F_SETFL, NONBLOCK");
+			goto error;
+		}
 	}
 
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
-
 	return fd;
 
 error:
@@ -512,7 +513,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid %d\n",
 				pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd->name, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n", pmd->name);
 				return -1;
@@ -711,7 +712,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
 	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
+	fd = tun_alloc(tap_name, 0);
 	if (fd < 0) {
 		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
 		goto error_exit;
@@ -739,6 +740,8 @@ eth_dev_tap_create(const char *name, char *tap_name)
 error_exit:
 	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
 
+	if (fd > 0)
+		close(fd);
 	rte_free(data);
 	rte_free(pmd);
 
Signature · 1 line
2.8.0.GIT
#2 lore raw

Re: [PATCH 2/5] net/tap: fix multi-queue support

Quoted 147 lines · On Thu, 2 Feb 2017 16:33:27 -0600 Keith Wiles <[email protected]> wrote:
---
 drivers/net/tap/rte_eth_tap.c | 93

++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 45 deletions(-)

drivers/net/tap/rte_eth_tap.c +46 -45
index 3f179c3..9ed7a87 100644
@@ -115,10 +115,9 @@ struct pmd_internals {
  * supplied name.
  */
 static int
-tun_alloc(char *name)
+tun_alloc(char *name, uint16_t qid)
 {
 	struct ifreq ifr;
-	unsigned int features;
 	int fd;
 
 	memset(&ifr, 0, sizeof(struct ifreq));
@@ -133,55 +132,57 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
-	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
-		goto error;
-	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	/* This can only be done once per interface */
+	if (qid == 0) {
+		unsigned int features;
+
+		/* Grab the TUN features to verify we can work */
+		if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
+			RTE_LOG(ERR, PMD, "Unable to get TUN/TAP
 features\n");
+			goto error;
+		}
+		RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
 
 #ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
-			RTE_PMD_TAP_MAX_QUEUES);
-	}
+		if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES
 > 1)) {
+			RTE_LOG(DEBUG, PMD, "TUN/TAP device only one
 queue\n");
+			goto error;
+		} else if ((features & IFF_ONE_QUEUE) &&
+				(RTE_PMD_TAP_MAX_QUEUES == 1)) {
+			ifr.ifr_flags |= IFF_ONE_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		} else {
+			ifr.ifr_flags |= IFF_MULTI_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Multi-queue support for %d
 queues\n",
+				RTE_PMD_TAP_MAX_QUEUES);
+		}
 #else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	}
+		if (RTE_PMD_TAP_MAX_QUEUES > 1) {
+			RTE_LOG(DEBUG, PMD, "TUN/TAP device only one
 queue\n");
+			goto error;
+		} else {
+			ifr.ifr_flags |= IFF_ONE_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		}
 #endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
-	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
-			ifr.ifr_name);
-		perror("TUNSETIFF");
-		goto error;
-	}
+		/* Set the TUN/TAP configuration and get the name if needed
 */
+		if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
+			RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+				ifr.ifr_name);
+			perror("TUNSETIFF");
+			goto error;
+		}
 
-	/* Always set the file descriptor to non-blocking */
-	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set to nonblocking\n");
-		perror("F_SETFL, NONBLOCK");
-		goto error;
+		/* Always set the file descriptor to non-blocking */
+		if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+			RTE_LOG(WARNING, PMD, "Unable to set %s to
 nonblocking\n",
+				ifr.ifr_name);
+			perror("F_SETFL, NONBLOCK");
+			goto error;
+		}
 	}
 
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
-
 	return fd;
 
 error:
@@ -512,7 +513,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid
 %d\n", pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd->name, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
 pmd->name); return -1;
@@ -711,7 +712,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
 	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
+	fd = tun_alloc(tap_name, 0);
 	if (fd < 0) {
 		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
 		goto error_exit;

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name) · line 747

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -739,6 +740,8 @@ eth_dev_tap_create(const char *name, char *tap_name)
 error_exit:
 	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
 
+	if (fd > 0)
+		close(fd);
 	rte_free(data);
 	rte_free(pmd);
 

The patch looks good to me.

Can you maybe detail in the commit log that now queue 0 is created while probing, while other queues are handled through tap_setup_queue() only?

Pascal

#3 lore raw

Re: [PATCH 2/5] net/tap: fix multi-queue support

Quoted 164 lines · Pascal Mazon
Quoted 152 lines · On Thu, 2 Feb 2017 16:33:27 -0600 Keith Wiles <[email protected]> wrote:

---
drivers/net/tap/rte_eth_tap.c | 93 ++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 45 deletions(-)

drivers/net/tap/rte_eth_tap.c +0 -0
index 3f179c3..9ed7a87 100644
@@ -115,10 +115,9 @@ struct pmd_internals {
 * supplied name.
 */

static int

drivers/net/tap/rte_eth_tap.c +1 -1
-tun_alloc(char *name)
+tun_alloc(char *name, uint16_t qid)
{
	struct ifreq ifr;
drivers/net/tap/rte_eth_tap.c +0 -1
-	unsigned int features;
	int fd;

	memset(&ifr, 0, sizeof(struct ifreq));
drivers/net/tap/rte_eth_tap.c +43 -37
@@ -133,55 +132,57 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
-	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
-		goto error;
-	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	/* This can only be done once per interface */
+	if (qid == 0) {
+		unsigned int features;
+
+		/* Grab the TUN features to verify we can work */
+		if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
+			RTE_LOG(ERR, PMD, "Unable to get TUN/TAP
 features\n");
+			goto error;
+		}
+		RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
 
 #ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
-			RTE_PMD_TAP_MAX_QUEUES);
-	}
+		if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES
 > 1)) {
+			RTE_LOG(DEBUG, PMD, "TUN/TAP device only one
 queue\n");
+			goto error;
+		} else if ((features & IFF_ONE_QUEUE) &&
+				(RTE_PMD_TAP_MAX_QUEUES == 1)) {
+			ifr.ifr_flags |= IFF_ONE_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		} else {
+			ifr.ifr_flags |= IFF_MULTI_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Multi-queue support for %d
 queues\n",
+				RTE_PMD_TAP_MAX_QUEUES);
+		}
 #else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	}
+		if (RTE_PMD_TAP_MAX_QUEUES > 1) {
+			RTE_LOG(DEBUG, PMD, "TUN/TAP device only one
 queue\n");
+			goto error;
+		} else {
+			ifr.ifr_flags |= IFF_ONE_QUEUE;
+			RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		}
 #endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
-	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
-			ifr.ifr_name);
-		perror("TUNSETIFF");
-		goto error;
-	}
+		/* Set the TUN/TAP configuration and get the name if needed
 */
+		if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
+			RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+				ifr.ifr_name);
+			perror("TUNSETIFF");
+			goto error;
+		}
 
-	/* Always set the file descriptor to non-blocking */
-	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set to nonblocking\n");
-		perror("F_SETFL, NONBLOCK");
-		goto error;
+		/* Always set the file descriptor to non-blocking */
+		if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
+			RTE_LOG(WARNING, PMD, "Unable to set %s to
 nonblocking\n",
+				ifr.ifr_name);
+			perror("F_SETFL, NONBLOCK");
+			goto error;
+		}
	}
drivers/net/tap/rte_eth_tap.c +0 -4
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
-
	return fd;

error:

drivers/net/tap/rte_eth_tap.c +2 -2
@@ -512,7 +513,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid
 %d\n", pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd->name, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
 pmd->name); return -1;
@@ -711,7 +712,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
 	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
+	fd = tun_alloc(tap_name, 0);
 	if (fd < 0) {
 		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
 		goto error_exit;
@@ -739,6 +740,8 @@ eth_dev_tap_create(const char *name, char *tap_name)

error_exit:

	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
drivers/net/tap/rte_eth_tap.c +2 -0
+	if (fd > 0)
+		close(fd);
Quoted 3 lines
	rte_free(data);
	rte_free(pmd);

The patch looks good to me.

Quoted 2 lines

Can you maybe detail in the commit log that now queue 0 is created while probing, while other queues are handled through tap_setup_queue() only?

In my changes before your patch set I had removed creating queue 0 at probe and only created the interface/queue at queue setup time. It would have required a more changes compared to your patches and the original code. :-(

Quoted 2 lines

Pascal

Regards,
Keith

#4 lore raw

PATCH 3/5 net/tap: remove redundant fds array

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/tap/rte_eth_tap.c +4 -8
index 9ed7a87..6673182 100644
@@ -103,7 +103,6 @@ struct pmd_internals {
 	struct ether_addr eth_addr;	/* Mac address of the device port */
 
 	int if_index;			/* IF_INDEX for the port */
-	int fds[RTE_PMD_TAP_MAX_QUEUES]; /* List of all file descriptors */
 
 	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 */
@@ -350,8 +349,8 @@ tap_dev_stop(struct rte_eth_dev *dev)
 	struct pmd_internals *internals = dev->data->dev_private;
 
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 	tap_link_set_down(dev);
 }
 
@@ -583,7 +582,6 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	internals->fds[rx_queue_id] = fd;
 	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
 
@@ -720,7 +718,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 
 	/* Presetup the fds to -1 as being not working */
 	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->fds[i] = -1;
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
@@ -728,7 +725,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	/* Take the TUN/TAP fd and place in the first location */
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
-	pmd->fds[0] = fd;
 
 	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
@@ -851,8 +847,8 @@ rte_pmd_tap_remove(const char *name)
 
 	internals = eth_dev->data->dev_private;
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 
 	rte_free(eth_dev->data->dev_private);
 	rte_free(eth_dev->data);
Signature · 1 line
2.8.0.GIT
Acked-by on v1 3/5
#5 lore raw

Re: [PATCH 3/5] net/tap: remove redundant fds array

Quoted 53 lines · On Thu, 2 Feb 2017 16:33:28 -0600 Keith Wiles <[email protected]> wrote:
---
 drivers/net/tap/rte_eth_tap.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/tap/rte_eth_tap.c +0 -1
index 9ed7a87..6673182 100644
@@ -103,7 +103,6 @@ struct pmd_internals {
 	struct ether_addr eth_addr;	/* Mac address of the device port
 */ 
 	int if_index;			/* IF_INDEX for the port */
-	int fds[RTE_PMD_TAP_MAX_QUEUES]; /* List of all file descriptors */
 
 	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 */ @@ -350,8 +349,8 @@ tap_dev_stop(struct rte_eth_dev *dev)

drivers/net/tap/rte_eth_tap.c +2 -5
 	struct pmd_internals *internals = dev->data->dev_private;
 
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 	tap_link_set_down(dev);
 }
@@ -583,7 +582,6 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	internals->fds[rx_queue_id] = fd;
 	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id,
 internals->rxq[rx_queue_id].fd); 
@@ -720,7 +718,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 
 	/* Presetup the fds to -1 as being not working */
 	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->fds[i] = -1;
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
@@ -728,7 +725,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	/* Take the TUN/TAP fd and place in the first location */
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
-	pmd->fds[0] = fd;
 
 	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_remove(const char *name) · line 854

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +2 -2
@@ -851,8 +847,8 @@ rte_pmd_tap_remove(const char *name)
 
 	internals = eth_dev->data->dev_private;
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 
 	rte_free(eth_dev->data->dev_private);
 	rte_free(eth_dev->data);
#6 lore raw

PATCH 4/5 net/tap: fix up log message to correct channel

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/net/tap/rte_eth_tap.c +19 -20
index 6673182..4f7eacf 100644
@@ -167,7 +167,7 @@ tun_alloc(char *name, uint16_t qid)
 
 		/* Set the TUN/TAP configuration and get the name if needed */
 		if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-			RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+			RTE_LOG(WARNING, PMD, "Unable to set TUNSETIFF for %s\n",
 				ifr.ifr_name);
 			perror("TUNSETIFF");
 			goto error;
@@ -206,7 +206,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		/* allocate the next mbuf */
 		mbuf = rte_pktmbuf_alloc(rxq->mp);
 		if (unlikely(!mbuf)) {
-			RTE_LOG(WARNING, PMD, "Unable to allocate mbuf\n");
+			RTE_LOG(WARNING, PMD, "TAP unable to allocate mbuf\n");
 			break;
 		}
 
@@ -559,8 +559,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	int fd;
 
 	if ((rx_queue_id >= internals->nb_queues) || !mp) {
-		RTE_LOG(ERR, PMD, "nb_queues %d mp %p\n",
-			internals->nb_queues, mp);
+		RTE_LOG(WARNING, PMD, "nb_queues %d too small or mempool NULL\n",
+			internals->nb_queues);
 		return -1;
 	}
 
@@ -572,7 +572,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 				RTE_PKTMBUF_HEADROOM);
 
 	if (buf_size < ETH_FRAME_LEN) {
-		RTE_LOG(ERR, PMD,
+		RTE_LOG(WARNING, PMD,
 			"%s: %d bytes will not fit in mbuf (%d bytes)\n",
 			dev->data->name, ETH_FRAME_LEN, buf_size);
 		return -ENOMEM;
@@ -582,7 +582,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
 
 	return 0;
@@ -605,7 +605,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
 	if (ret == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "TX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  TX TAP device name %s, qid %d on fd %d\n",
 		internals->name, tx_queue_id, internals->txq[tx_queue_id].fd);
 
 	return 0;
@@ -643,7 +643,7 @@ pmd_mac_address(int fd, struct rte_eth_dev *dev, struct ether_addr *addr)
 	memset(&ifr, 0, sizeof(ifr));
 
 	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
-		RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
+		RTE_LOG(WARNING, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
 			ifr.ifr_name);
 		return -1;
 	}
@@ -662,26 +662,25 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	struct rte_eth_dev_data *data = NULL;
 	int i, fd = -1;
 
-	RTE_LOG(INFO, PMD,
-		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
-		 name, RTE_PMD_TAP_MAX_QUEUES, rte_socket_id());
+	RTE_LOG(DEBUG, PMD, "  TAP device with %d queues on numa %u\n",
+		 RTE_PMD_TAP_MAX_QUEUES, rte_socket_id());
 
 	data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
 	if (!data) {
-		RTE_LOG(ERR, PMD, "Failed to allocate data\n");
+		RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
 		goto error_exit;
 	}
 
 	pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node);
 	if (!pmd) {
-		RTE_LOG(ERR, PMD, "Unable to allocate internal struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate internal struct\n");
 		goto error_exit;
 	}
 
 	/* Use the name and not the tap_name */
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
-		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
 		goto error_exit;
 	}
 
@@ -712,7 +711,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	/* Create the first Tap device */
 	fd = tun_alloc(tap_name, 0);
 	if (fd < 0) {
-		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
+		RTE_LOG(ERR, PMD, "TAP tun_alloc() failed for %s\n", tap_name);
 		goto error_exit;
 	}
 
@@ -734,7 +733,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	return 0;
 
 error_exit:
-	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
+	RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name);
 
 	if (fd > 0)
 		close(fd);
@@ -787,7 +786,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 
 	if (params && (params[0] != '\0')) {
-		RTE_LOG(INFO, PMD, "paramaters (%s)\n", params);
+		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
 		kvlist = rte_kvargs_parse(params, valid_arguments);
 		if (kvlist) {
@@ -812,14 +811,14 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	}
 	pmd_link.link_speed = speed;
 
-	RTE_LOG(INFO, PMD, "Initializing pmd_tap for %s as %s\n",
+	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
 	ret = eth_dev_tap_create(name, tap_name);
 
 leave:
 	if (ret == -1) {
-		RTE_LOG(INFO, PMD, "Failed to create pmd for %s as %s\n",
+		RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n",
 			name, tap_name);
 		tap_unit--;		/* Restore the unit number */
 	}
@@ -837,7 +836,7 @@ rte_pmd_tap_remove(const char *name)
 	struct pmd_internals *internals;
 	int i;
 
-	RTE_LOG(INFO, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
+	RTE_LOG(DEBUG, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
 		rte_socket_id());
 
 	/* find the ethdev entry */
Signature · 1 line
2.8.0.GIT
Acked-by on v1 4/5
#7 lore raw

Re: [PATCH 4/5] net/tap: fix up log message to correct channel

Quoted 152 lines · On Thu, 2 Feb 2017 16:33:29 -0600 Keith Wiles <[email protected]> wrote:
---
 drivers/net/tap/rte_eth_tap.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/net/tap/rte_eth_tap.c +1 -1
index 6673182..4f7eacf 100644
@@ -167,7 +167,7 @@ tun_alloc(char *name, uint16_t qid)
 
 		/* Set the TUN/TAP configuration and get the name if needed
 */ if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-			RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+			RTE_LOG(WARNING, PMD, "Unable to set TUNSETIFF for
 %s\n", ifr.ifr_name);
 			perror("TUNSETIFF");
 			goto error;
@@ -206,7 +206,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs,

uint16_t nb_pkts) /* allocate the next mbuf */

drivers/net/tap/rte_eth_tap.c +1 -1
 		mbuf = rte_pktmbuf_alloc(rxq->mp);
 		if (unlikely(!mbuf)) {
-			RTE_LOG(WARNING, PMD, "Unable to allocate mbuf\n");
+			RTE_LOG(WARNING, PMD, "TAP unable to allocate

mbuf\n"); break;

drivers/net/tap/rte_eth_tap.c +16 -17
 		}
@@ -559,8 +559,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	int fd;
 
 	if ((rx_queue_id >= internals->nb_queues) || !mp) {
-		RTE_LOG(ERR, PMD, "nb_queues %d mp %p\n",
-			internals->nb_queues, mp);
+		RTE_LOG(WARNING, PMD, "nb_queues %d too small or mempool
 NULL\n",
+			internals->nb_queues);
 		return -1;
 	}
@@ -572,7 +572,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 				RTE_PKTMBUF_HEADROOM);
 
 	if (buf_size < ETH_FRAME_LEN) {
-		RTE_LOG(ERR, PMD,
+		RTE_LOG(WARNING, PMD,
 			"%s: %d bytes will not fit in mbuf (%d bytes)\n",
 			dev->data->name, ETH_FRAME_LEN, buf_size);
 		return -ENOMEM;
@@ -582,7 +582,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id,
 internals->rxq[rx_queue_id].fd); 
 	return 0;
@@ -605,7 +605,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
 	if (ret == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "TX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  TX TAP device name %s, qid %d on fd %d\n",
 		internals->name, tx_queue_id,
 internals->txq[tx_queue_id].fd); 
 	return 0;
@@ -643,7 +643,7 @@ pmd_mac_address(int fd, struct rte_eth_dev *dev, struct
 ether_addr *addr) memset(&ifr, 0, sizeof(ifr));
 
 	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
-		RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
+		RTE_LOG(WARNING, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
 			ifr.ifr_name);
 		return -1;
 	}
@@ -662,26 +662,25 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	struct rte_eth_dev_data *data = NULL;
 	int i, fd = -1;
 
-	RTE_LOG(INFO, PMD,
-		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
-		 name, RTE_PMD_TAP_MAX_QUEUES, rte_socket_id());
+	RTE_LOG(DEBUG, PMD, "  TAP device with %d queues on numa %u\n",
+		 RTE_PMD_TAP_MAX_QUEUES, rte_socket_id());
 
 	data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
 	if (!data) {
-		RTE_LOG(ERR, PMD, "Failed to allocate data\n");
+		RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
 		goto error_exit;
 	}
 
 	pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node);
 	if (!pmd) {
-		RTE_LOG(ERR, PMD, "Unable to allocate internal struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate internal
 struct\n"); goto error_exit;
 	}
 
 	/* Use the name and not the tap_name */
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
-		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
 		goto error_exit;
 	}
 
@@ -712,7 +711,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	/* Create the first Tap device */
 	fd = tun_alloc(tap_name, 0);
 	if (fd < 0) {
-		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
+		RTE_LOG(ERR, PMD, "TAP tun_alloc() failed for %s\n",
 tap_name); goto error_exit;
 	}
 
@@ -734,7 +733,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	return 0;
 
 error_exit:
-	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
+	RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name);
 
 	if (fd > 0)
 		close(fd);
@@ -787,7 +786,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 
 	if (params && (params[0] != '\0')) {
-		RTE_LOG(INFO, PMD, "paramaters (%s)\n", params);
+		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
 		kvlist = rte_kvargs_parse(params, valid_arguments);
 		if (kvlist) {
@@ -812,14 +811,14 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	}
 	pmd_link.link_speed = speed;
 
-	RTE_LOG(INFO, PMD, "Initializing pmd_tap for %s as %s\n",
+	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
 	ret = eth_dev_tap_create(name, tap_name);
 
 leave:
 	if (ret == -1) {
-		RTE_LOG(INFO, PMD, "Failed to create pmd for %s as %s\n",
+		RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n",
 			name, tap_name);
 		tap_unit--;		/* Restore the unit number */
 	}

drivers/net/tap/rte_eth_tap.c rte_pmd_tap_remove(const char *name) · line 842

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -837,7 +836,7 @@ rte_pmd_tap_remove(const char *name)
 	struct pmd_internals *internals;
 	int i;
 
-	RTE_LOG(INFO, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
+	RTE_LOG(DEBUG, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
 		rte_socket_id());
 
 	/* find the ethdev entry */
#8 lore raw

PATCH 5/5 net/tap: remove unused variable and minor cleanup

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/tap/rte_eth_tap.c +3 -7
index 4f7eacf..238824e 100644
@@ -390,9 +390,7 @@ tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
 		rx_total += tap_stats->q_ipackets[i];
 		rx_bytes_total += tap_stats->q_ibytes[i];
-	}
 
-	for (i = 0; i < imax; i++) {
 		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
 		tap_stats->q_errors[i] = pmd->txq[i].stats.errs;
 		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
@@ -417,9 +415,7 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->rxq[i].stats.ipackets = 0;
 		pmd->rxq[i].stats.ibytes = 0;
-	}
 
-	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->txq[i].stats.opackets = 0;
 		pmd->txq[i].stats.errs = 0;
 		pmd->txq[i].stats.obytes = 0;
@@ -633,11 +629,11 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct rte_eth_dev *dev, struct ether_addr *addr)
+pmd_mac_address(int fd, struct ether_addr *addr)
 {
 	struct ifreq ifr;
 
-	if ((fd <= 0) || !dev || !addr)
+	if ((fd <= 0) || !addr)
 		return -1;
 
 	memset(&ifr, 0, sizeof(ifr));
@@ -725,7 +721,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
 
-	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
+	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
 		goto error_exit;
 	}
Signature · 1 line
2.8.0.GIT
Acked-by on v1 5/5
#9 lore raw

Re: [PATCH 5/5] net/tap: remove unused variable and minor cleanup

Quoted 44 lines · On Thu, 2 Feb 2017 16:33:30 -0600 Keith Wiles <[email protected]> wrote:
---
 drivers/net/tap/rte_eth_tap.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/tap/rte_eth_tap.c +2 -6
index 4f7eacf..238824e 100644
@@ -390,9 +390,7 @@ tap_stats_get(struct rte_eth_dev *dev, struct
 rte_eth_stats *tap_stats) tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
 		rx_total += tap_stats->q_ipackets[i];
 		rx_bytes_total += tap_stats->q_ibytes[i];
-	}
 
-	for (i = 0; i < imax; i++) {
 		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
 		tap_stats->q_errors[i] = pmd->txq[i].stats.errs;
 		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
@@ -417,9 +415,7 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->rxq[i].stats.ipackets = 0;
 		pmd->rxq[i].stats.ibytes = 0;
-	}
 
-	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->txq[i].stats.opackets = 0;
 		pmd->txq[i].stats.errs = 0;
 		pmd->txq[i].stats.obytes = 0;
@@ -633,11 +629,11 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct rte_eth_dev *dev, struct ether_addr *addr)
+pmd_mac_address(int fd, struct ether_addr *addr)
 {
 	struct ifreq ifr;
 
-	if ((fd <= 0) || !dev || !addr)
+	if ((fd <= 0) || !addr)
 		return -1;
 
 	memset(&ifr, 0, sizeof(ifr));

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name) · line 727

Quoted 8 lines
drivers/net/tap/rte_eth_tap.c +1 -1
@@ -725,7 +721,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
 
-	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
+	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
 		goto error_exit;
 	}
#10 lore raw
In reply to Keith Wiles
Quoted 45 lines · On Thu, 2 Feb 2017 16:33:26 -0600 Keith Wiles <[email protected]> wrote:
---
 doc/guides/nics/tap.rst | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
doc/guides/nics/tap.rst +2 -2
index 622b9e7..2ab60ff 100644
@@ -45,18 +45,18 @@ device.
 These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
-``--vdev=net_tap`` option on the DPDK application command line. Each
-``--vdev=net_tap`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap0`` option on the DPDK application command line. Each
+``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
 and so on.
 
 The interfaced name can be changed by adding the ``iface=foo0``, for

example::

doc/guides/nics/tap.rst +3 -3
-   --vdev=net_tap,iface=foo0 --vdev=net_tap,iface=foo1, ...
+   --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
 Also the speed of the interface can be changed from 10G to whatever number
 needed, but the interface does not enforce that speed, for example::
 
-   --vdev=net_tap,iface=foo0,speed=25000
+   --vdev=net_tap0,iface=foo0,speed=25000
 
 After the DPDK application is started you can send and receive packets on the
 interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
@@ -97,7 +97,7 @@ following::
 
     sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -l 1-5 -n 4        \
      --proc-type auto --log-level 8 --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap --vdev=net_tap -b 05:00.0 -b 05:00.1                    \
+     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
      -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
      -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
      -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
@@ -131,6 +131,6 @@ time with ``start all``. The command ``str`` is an alias

for ``start all`` and
While running you should see the 64 byte counters increasing to verify the traffic is being looped back. You can use ``set all size XXX`` to change the

doc/guides/nics/tap.rst time with ``start all``. The command ``str`` is an alias for ``start all`` and · line 136

Quoted 5 lines
doc/guides/nics/tap.rst +2 -2
-size of the packets after you stop the traffic. Use the pktgen ``help``
+size of the packets after you stop the traffic. Use pktgen ``help``
 command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup.
+load commands at startup in command line or Lua script in pktgen.

To be consistent. commit title should be "net/tap"

The patch looks ok to me, but while in the doc, could you fix the "The interfaced name" into "The interface name"?

Regards,
Pascal

#11 lore raw
Quoted 5 lines · Pascal Mazon
Quoted 2 lines · On Thu, 2 Feb 2017 16:33:26 -0600 Keith Wiles <[email protected]> wrote:

---

<...>

Quoted 5 lines

To be consistent. commit title should be "net/tap"

The patch looks ok to me, but while in the doc, could you fix the "The interfaced name" into "The interface name"?

Also checkpatch gives a few long line warnings.

Apart from that, series LGTM too.

Quoted 4 lines

Regards,
Pascal

#12 lore raw

PATCH v2 1/6 net/tap: fix tap docs for device name

In reply to Keith Wiles
---
 doc/guides/nics/tap.rst | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
doc/guides/nics/tap.rst +8 -8
index 622b9e7..c4f207b 100644
@@ -45,18 +45,18 @@ device.
 These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
-``--vdev=net_tap`` option on the DPDK application command line. Each
-``--vdev=net_tap`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap0`` option on the DPDK application command line. Each
+``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
 and so on.
 
-The interfaced name can be changed by adding the ``iface=foo0``, for example::
+The interface name can be changed by adding the ``iface=foo0``, for example::
 
-   --vdev=net_tap,iface=foo0 --vdev=net_tap,iface=foo1, ...
+   --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
 Also the speed of the interface can be changed from 10G to whatever number
 needed, but the interface does not enforce that speed, for example::
 
-   --vdev=net_tap,iface=foo0,speed=25000
+   --vdev=net_tap0,iface=foo0,speed=25000
 
 After the DPDK application is started you can send and receive packets on the
 interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
@@ -97,7 +97,7 @@ following::
 
     sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -l 1-5 -n 4        \
      --proc-type auto --log-level 8 --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap --vdev=net_tap -b 05:00.0 -b 05:00.1                    \
+     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
      -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
      -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
      -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
@@ -131,6 +131,6 @@ time with ``start all``. The command ``str`` is an alias for ``start all`` and
 
 While running you should see the 64 byte counters increasing to verify the
 traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use the pktgen ``help``
+size of the packets after you stop the traffic. Use pktgen ``help``
 command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup.
+load commands at startup in command line or Lua script in pktgen.
Signature · 1 line
2.8.0.GIT
#13 lore raw

PATCH v2 2/6 net/tap: remove redundant fds array

---
 drivers/net/tap/rte_eth_tap.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/tap/rte_eth_tap.c +4 -8
index c7b04bb..6d93eb7 100644
@@ -103,7 +103,6 @@ struct pmd_internals {
 	struct ether_addr eth_addr;	/* Mac address of the device port */
 
 	int if_index;			/* IF_INDEX for the port */
-	int fds[RTE_PMD_TAP_MAX_QUEUES]; /* List of all file descriptors */
 
 	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 */
@@ -349,8 +348,8 @@ tap_dev_stop(struct rte_eth_dev *dev)
 	struct pmd_internals *internals = dev->data->dev_private;
 
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 	tap_link_set_down(dev);
 }
 
@@ -583,7 +582,6 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	internals->fds[rx_queue_id] = fd;
 	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
 
@@ -720,7 +718,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 
 	/* Presetup the fds to -1 as being not working */
 	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->fds[i] = -1;
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
@@ -728,7 +725,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	/* Take the TUN/TAP fd and place in the first location */
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
-	pmd->fds[0] = fd;
 
 	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
@@ -849,8 +845,8 @@ rte_pmd_tap_remove(const char *name)
 
 	internals = eth_dev->data->dev_private;
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 
 	rte_free(eth_dev->data->dev_private);
 	rte_free(eth_dev->data);
Signature · 1 line
2.8.0.GIT
#14 lore raw

PATCH v2 3/6 net/tap: remove unused variable and minor cleanup

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/tap/rte_eth_tap.c +3 -7
index 6d93eb7..61659bc 100644
@@ -389,9 +389,7 @@ tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
 		rx_total += tap_stats->q_ipackets[i];
 		rx_bytes_total += tap_stats->q_ibytes[i];
-	}
 
-	for (i = 0; i < imax; i++) {
 		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
 		tap_stats->q_errors[i] = pmd->txq[i].stats.errs;
 		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
@@ -416,9 +414,7 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->rxq[i].stats.ipackets = 0;
 		pmd->rxq[i].stats.ibytes = 0;
-	}
 
-	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->txq[i].stats.opackets = 0;
 		pmd->txq[i].stats.errs = 0;
 		pmd->txq[i].stats.obytes = 0;
@@ -633,11 +629,11 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct rte_eth_dev *dev, struct ether_addr *addr)
+pmd_mac_address(int fd, struct ether_addr *addr)
 {
 	struct ifreq ifr;
 
-	if ((fd <= 0) || !dev || !addr)
+	if ((fd <= 0) || !addr)
 		return -1;
 
 	memset(&ifr, 0, sizeof(ifr));
@@ -726,7 +722,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
 
-	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
+	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
 		goto error_exit;
 	}
Signature · 1 line
2.8.0.GIT
#15 lore raw

PATCH v2 4/6 net/tap: fix multi-queue support

In reply to Keith Wiles

At the same time remove the code which created the first device queue at probe time. Now all queues are created during queue setup calls.

---
 drivers/net/tap/rte_eth_tap.c | 104 ++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 70 deletions(-)
drivers/net/tap/rte_eth_tap.c +34 -70
index 61659bc..7c923a2 100644
@@ -57,7 +57,11 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 
+#ifdef IFF_MULTI_QUEUE
 #define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif
 
 static struct rte_vdev_driver pmd_tap_drv;
 
@@ -114,17 +118,20 @@ struct pmd_internals {
  * supplied name.
  */
 static int
-tun_alloc(char *name)
+tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 {
 	struct ifreq ifr;
+#ifdef IFF_MULTI_QUEUE
 	unsigned int features;
+#endif
 	int fd;
 
 	memset(&ifr, 0, sizeof(struct ifreq));
 
 	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-	if (name && name[0])
-		strncpy(ifr.ifr_name, name, IFNAMSIZ);
+	strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
+
+	RTE_LOG(DEBUG, PMD, "ifr_name '%s'\n", ifr.ifr_name);
 
 	fd = open(TUN_TAP_DEV_PATH, O_RDWR);
 	if (fd < 0) {
@@ -132,37 +139,26 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
+#ifdef IFF_MULTI_QUEUE
+	/* Grab the TUN features to verify we can work multi-queue */
 	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
+		RTE_LOG(ERR, PMD, "TAP unable to get TUN/TAP features\n");
 		goto error;
 	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	RTE_LOG(DEBUG, PMD, "  TAP Features %08x\n", features);
 
-#ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
+	if (features & IFF_MULTI_QUEUE) {
+		RTE_LOG(DEBUG, PMD, "  Multi-queue support for %d queues\n",
 			RTE_PMD_TAP_MAX_QUEUES);
-	}
-#else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
+		ifr.ifr_flags |= IFF_MULTI_QUEUE;
+	} else
+#endif
+	{
 		ifr.ifr_flags |= IFF_ONE_QUEUE;
 		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
 	}
-#endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
+	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
 			ifr.ifr_name);
@@ -177,9 +173,15 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
+	if (qid == 0) {
+		if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
+			RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
+				ifr.ifr_name);
+			goto error;
+		}
+
+		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+	}
 
 	return fd;
 
@@ -507,7 +509,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid %d\n",
 				pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
 					pmd->name);
@@ -629,34 +631,13 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct ether_addr *addr)
-{
-	struct ifreq ifr;
-
-	if ((fd <= 0) || !addr)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-
-	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
-		RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
-			ifr.ifr_name);
-		return -1;
-	}
-
-	rte_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	return 0;
-}
-
-static int
 eth_dev_tap_create(const char *name, char *tap_name)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev = NULL;
 	struct pmd_internals *pmd = NULL;
 	struct rte_eth_dev_data *data = NULL;
-	int i, fd = -1;
+	int i;
 
 	RTE_LOG(INFO, PMD,
 		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
@@ -674,7 +655,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 		goto error_exit;
 	}
 
-	/* Use the name and not the tap_name */
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
 		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
@@ -705,28 +685,12 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	dev->tx_pkt_burst = pmd_tx_burst;
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
-	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
-	if (fd < 0) {
-		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
-		goto error_exit;
-	}
-
-	/* Presetup the fds to -1 as being not working */
-	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
+	/* Presetup the fds to -1 as being not valid */
+	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
 
-	/* Take the TUN/TAP fd and place in the first location */
-	pmd->rxq[0].fd = fd;
-	pmd->txq[0].fd = fd;
-
-	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
-		goto error_exit;
-	}
-
 	return 0;
 
 error_exit:
Signature · 1 line
2.8.0.GIT
#16 lore raw

Re: [PATCH v2 4/6] net/tap: fix multi-queue support

Quoted 192 lines · On Sun, 5 Feb 2017 10:05:07 -0600 Keith Wiles <[email protected]> wrote:

At the same time remove the code which created the first device queue at probe time. Now all queues are created during queue setup calls.

---
 drivers/net/tap/rte_eth_tap.c | 104

++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 70 deletions(-)

drivers/net/tap/rte_eth_tap.c +34 -63
index 61659bc..7c923a2 100644
@@ -57,7 +57,11 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 
+#ifdef IFF_MULTI_QUEUE
 #define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif
 
 static struct rte_vdev_driver pmd_tap_drv;
 
@@ -114,17 +118,20 @@ struct pmd_internals {
  * supplied name.
  */
 static int
-tun_alloc(char *name)
+tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 {
 	struct ifreq ifr;
+#ifdef IFF_MULTI_QUEUE
 	unsigned int features;
+#endif
 	int fd;
 
 	memset(&ifr, 0, sizeof(struct ifreq));
 
 	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-	if (name && name[0])
-		strncpy(ifr.ifr_name, name, IFNAMSIZ);
+	strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
+
+	RTE_LOG(DEBUG, PMD, "ifr_name '%s'\n", ifr.ifr_name);
 
 	fd = open(TUN_TAP_DEV_PATH, O_RDWR);
 	if (fd < 0) {
@@ -132,37 +139,26 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
+#ifdef IFF_MULTI_QUEUE
+	/* Grab the TUN features to verify we can work multi-queue */
 	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
+		RTE_LOG(ERR, PMD, "TAP unable to get TUN/TAP features\n");
 		goto error;
 	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	RTE_LOG(DEBUG, PMD, "  TAP Features %08x\n", features);
 
-#ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
+	if (features & IFF_MULTI_QUEUE) {
+		RTE_LOG(DEBUG, PMD, "  Multi-queue support for %d queues\n",
 			RTE_PMD_TAP_MAX_QUEUES);
-	}
-#else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
+		ifr.ifr_flags |= IFF_MULTI_QUEUE;
+	} else
+#endif
+	{
 		ifr.ifr_flags |= IFF_ONE_QUEUE;
 		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
 	}
-#endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
+	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
 			ifr.ifr_name);
@@ -177,9 +173,15 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
+	if (qid == 0) {
+		if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
+			RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR)
 (%s)\n",
+				ifr.ifr_name);
+			goto error;
+		}
+
+		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+	}
 
 	return fd;
@@ -507,7 +509,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid
 %d\n", pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
 					pmd->name);
@@ -629,34 +631,13 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct ether_addr *addr)
-{
-	struct ifreq ifr;
-
-	if ((fd <= 0) || !addr)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-
-	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
-		RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
-			ifr.ifr_name);
-		return -1;
-	}
-
-	rte_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	return 0;
-}
-
-static int
 eth_dev_tap_create(const char *name, char *tap_name)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev = NULL;
 	struct pmd_internals *pmd = NULL;
 	struct rte_eth_dev_data *data = NULL;
-	int i, fd = -1;
+	int i;
 
 	RTE_LOG(INFO, PMD,
 		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
@@ -674,7 +655,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 		goto error_exit;
 	}
 
-	/* Use the name and not the tap_name */
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
 		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
@@ -705,28 +685,12 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	dev->tx_pkt_burst = pmd_tx_burst;
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
-	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
-	if (fd < 0) {
-		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
-		goto error_exit;
-	}
-
-	/* Presetup the fds to -1 as being not working */
-	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
+	/* Presetup the fds to -1 as being not valid */
+	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
 
-	/* Take the TUN/TAP fd and place in the first location */
-	pmd->rxq[0].fd = fd;

drivers/net/tap/rte_eth_tap.c eth_dev_tap_create(const char *name, char *tap_name) · line 696

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +0 -7
-	pmd->txq[0].fd = fd;
-
-	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
-		goto error_exit;
-	}
-
 	return 0;
 
 error_exit:

I like that you use #ifdef IFF_MULTI_QUEUE, it's a good thing.

Something bothers me, though.
I don't think you should close all fds in the dev_stop() function, but rather in the dev_close() function.
After a dev_close(), we don't expect the user to re-use the device, so we can safely remove the queues. However, after a dev_stop(), the user can definitely do a dev_start(), which in your case would fail because it will try to set the link up on an inexisting device.

dev_stop() should act as dev_start(), in symmetry, and dev_close() should close the fd/queues.

The rest of the code looks OK to me.

Best regards,
Pascal

#17 lore raw

Re: [PATCH v2 4/6] net/tap: fix multi-queue support

Quoted 219 lines · Pascal Mazon
Quoted 201 lines · On Sun, 5 Feb 2017 10:05:07 -0600 Keith Wiles <[email protected]> wrote:

At the same time remove the code which created the first device queue at probe time. Now all queues are created during queue setup calls.

---
drivers/net/tap/rte_eth_tap.c | 104 ++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 70 deletions(-)

drivers/net/tap/rte_eth_tap.c +4 -0
index 61659bc..7c923a2 100644
@@ -57,7 +57,11 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 
+#ifdef IFF_MULTI_QUEUE
 #define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif
 
 static struct rte_vdev_driver pmd_tap_drv;
 
@@ -114,17 +118,20 @@ struct pmd_internals {
 * supplied name.
 */

static int

drivers/net/tap/rte_eth_tap.c +1 -1
-tun_alloc(char *name)
+tun_alloc(struct pmd_internals *pmd, uint16_t qid)
{
	struct ifreq ifr;
+#ifdef IFF_MULTI_QUEUE
	unsigned int features;
+#endif
	int fd;

	memset(&ifr, 0, sizeof(struct ifreq));

	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
drivers/net/tap/rte_eth_tap.c +3 -2
-	if (name && name[0])
-		strncpy(ifr.ifr_name, name, IFNAMSIZ);
+	strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
+
+	RTE_LOG(DEBUG, PMD, "ifr_name '%s'\n", ifr.ifr_name);
	fd = open(TUN_TAP_DEV_PATH, O_RDWR);
	if (fd < 0) {
drivers/net/tap/rte_eth_tap.c +21 -26
@@ -132,37 +139,26 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
+#ifdef IFF_MULTI_QUEUE
+	/* Grab the TUN features to verify we can work multi-queue */
 	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
+		RTE_LOG(ERR, PMD, "TAP unable to get TUN/TAP features\n");
 		goto error;
 	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	RTE_LOG(DEBUG, PMD, "  TAP Features %08x\n", features);
 
-#ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
+	if (features & IFF_MULTI_QUEUE) {
+		RTE_LOG(DEBUG, PMD, "  Multi-queue support for %d queues\n",
 			RTE_PMD_TAP_MAX_QUEUES);
-	}
-#else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
+		ifr.ifr_flags |= IFF_MULTI_QUEUE;
+	} else
+#endif
+	{
 		ifr.ifr_flags |= IFF_ONE_QUEUE;
 		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
 	}
-#endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
+	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
 			ifr.ifr_name);
@@ -177,9 +173,15 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
+	if (qid == 0) {
+		if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
+			RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR)
 (%s)\n",
+				ifr.ifr_name);
+			goto error;
+		}
+
+		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+	}
 
 	return fd;
@@ -507,7 +509,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid
 %d\n", pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
 					pmd->name);
@@ -629,34 +631,13 @@ static const struct eth_dev_ops ops = {
 };
 

static int

drivers/net/tap/rte_eth_tap.c +0 -21
-pmd_mac_address(int fd, struct ether_addr *addr)
-{
-	struct ifreq ifr;
-
-	if ((fd <= 0) || !addr)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-
-	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
-		RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
-			ifr.ifr_name);
-		return -1;
-	}
-
-	rte_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	return 0;
-}
-
-static int

eth_dev_tap_create(const char *name, char *tap_name)

{
	int numa_node = rte_socket_id();
	struct rte_eth_dev *dev = NULL;
	struct pmd_internals *pmd = NULL;
	struct rte_eth_dev_data *data = NULL;
drivers/net/tap/rte_eth_tap.c +1 -1
-	int i, fd = -1;
+	int i;

RTE_LOG(INFO, PMD,
"%s: Create TAP Ethernet device with %d queues on numa %u\n",

drivers/net/tap/rte_eth_tap.c +2 -19
@@ -674,7 +655,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 		goto error_exit;
 	}
 
-	/* Use the name and not the tap_name */
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
 		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
@@ -705,28 +685,12 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	dev->tx_pkt_burst = pmd_tx_burst;
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
-	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
-	if (fd < 0) {
-		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
-		goto error_exit;
-	}
-
-	/* Presetup the fds to -1 as being not working */
-	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
+	/* Presetup the fds to -1 as being not valid */
+	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
 
-	/* Take the TUN/TAP fd and place in the first location */
-	pmd->rxq[0].fd = fd;
-	pmd->txq[0].fd = fd;
-
-	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
-		goto error_exit;
-	}
-
 	return 0;
 
Quoted 1 line

error_exit:

I like that you use #ifdef IFF_MULTI_QUEUE, it's a good thing.

Something bothers me, though.
I don't think you should close all fds in the dev_stop() function, but rather in the dev_close() function.
After a dev_close(), we don't expect the user to re-use the device, so we can safely remove the queues. However, after a dev_stop(), the user can definitely do a dev_start(), which in your case would fail because it will try to set the link up on an inexisting device.

Quoted 2 lines

dev_stop() should act as dev_start(), in symmetry, and dev_close() should close the fd/queues.

That is a good point should I create v3 or do a patch for that after this release?

Quoted 5 lines

The rest of the code looks OK to me.

Best regards,
Pascal

Regards,
Keith

#18 lore raw

PATCH v2 5/6 net/tap: cleanup log messages

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 54 ++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 26 deletions(-)
drivers/net/tap/rte_eth_tap.c +28 -26
index 7c923a2..65e4bab 100644
@@ -155,12 +155,13 @@ tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 #endif
 	{
 		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		RTE_LOG(DEBUG, PMD, "  Single queue only support\n");
 	}
 
 	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+		RTE_LOG(WARNING, PMD,
+			"Unable to set TUNSETIFF for %s\n",
 			ifr.ifr_name);
 		perror("TUNSETIFF");
 		goto error;
@@ -168,7 +169,9 @@ tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 
 	/* Always set the file descriptor to non-blocking */
 	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set to nonblocking\n");
+		RTE_LOG(WARNING, PMD,
+			"Unable to set %s to nonblocking\n",
+			ifr.ifr_name);
 		perror("F_SETFL, NONBLOCK");
 		goto error;
 	}
@@ -207,7 +210,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		/* allocate the next mbuf */
 		mbuf = rte_pktmbuf_alloc(rxq->mp);
 		if (unlikely(!mbuf)) {
-			RTE_LOG(WARNING, PMD, "Unable to allocate mbuf\n");
+			RTE_LOG(WARNING, PMD, "TAP unable to allocate mbuf\n");
 			break;
 		}
 
@@ -276,7 +279,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	return num_tx;
 }
 
-static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
+static int
+tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
 {
 	struct ifreq ifr;
 	int err, s;
@@ -296,8 +300,8 @@ static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
 	strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
 	err = ioctl(s, SIOCGIFFLAGS, &ifr);
 	if (err < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get tap netdevice flags: %s\n",
-			strerror(errno));
+		RTE_LOG(WARNING, PMD, "Unable to get %s device flags: %s\n",
+			pmd->name, strerror(errno));
 		close(s);
 		return -1;
 	}
@@ -307,7 +311,7 @@ static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
 		ifr.ifr_flags &= ~flags;
 	err = ioctl(s, SIOCSIFFLAGS, &ifr);
 	if (err < 0) {
-		RTE_LOG(ERR, PMD, "Unable to %s flags 0x%x: %s\n",
+		RTE_LOG(WARNING, PMD, "Unable to %s flags 0x%x: %s\n",
 			add ? "set" : "unset", flags, strerror(errno));
 		close(s);
 		return -1;
@@ -511,8 +515,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
 				pmd->name, qid);
 			fd = tun_alloc(pmd, qid);
 			if (fd < 0) {
-				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
-					pmd->name);
+				RTE_LOG(ERR, PMD, "tun_alloc(%s, %d) failed\n",
+					pmd->name, qid);
 				return -1;
 			}
 		}
@@ -557,8 +561,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	int fd;
 
 	if ((rx_queue_id >= internals->nb_queues) || !mp) {
-		RTE_LOG(ERR, PMD, "nb_queues %d mp %p\n",
-			internals->nb_queues, mp);
+		RTE_LOG(WARNING, PMD, "nb_queues %d too small or mempool NULL\n",
+			internals->nb_queues);
 		return -1;
 	}
 
@@ -570,7 +574,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 				RTE_PKTMBUF_HEADROOM);
 
 	if (buf_size < ETH_FRAME_LEN) {
-		RTE_LOG(ERR, PMD,
+		RTE_LOG(WARNING, PMD,
 			"%s: %d bytes will not fit in mbuf (%d bytes)\n",
 			dev->data->name, ETH_FRAME_LEN, buf_size);
 		return -ENOMEM;
@@ -580,7 +584,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
 
 	return 0;
@@ -603,7 +607,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
 	if (ret == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "TX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  TX TAP device name %s, qid %d on fd %d\n",
 		internals->name, tx_queue_id, internals->txq[tx_queue_id].fd);
 
 	return 0;
@@ -639,25 +643,23 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	struct rte_eth_dev_data *data = NULL;
 	int i;
 
-	RTE_LOG(INFO, PMD,
-		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
-		 name, RTE_PMD_TAP_MAX_QUEUES, rte_socket_id());
+	RTE_LOG(DEBUG, PMD, "  TAP device on numa %u\n", rte_socket_id());
 
 	data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
 	if (!data) {
-		RTE_LOG(ERR, PMD, "Failed to allocate data\n");
+		RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
 		goto error_exit;
 	}
 
 	pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node);
 	if (!pmd) {
-		RTE_LOG(ERR, PMD, "Unable to allocate internal struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate internal struct\n");
 		goto error_exit;
 	}
 
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
-		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
 		goto error_exit;
 	}
 
@@ -694,7 +696,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	return 0;
 
 error_exit:
-	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
+	RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name);
 
 	rte_free(data);
 	rte_free(pmd);
@@ -745,7 +747,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 
 	if (params && (params[0] != '\0')) {
-		RTE_LOG(INFO, PMD, "paramaters (%s)\n", params);
+		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
 		kvlist = rte_kvargs_parse(params, valid_arguments);
 		if (kvlist) {
@@ -770,14 +772,14 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	}
 	pmd_link.link_speed = speed;
 
-	RTE_LOG(INFO, PMD, "Initializing pmd_tap for %s as %s\n",
+	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
 	ret = eth_dev_tap_create(name, tap_name);
 
 leave:
 	if (ret == -1) {
-		RTE_LOG(INFO, PMD, "Failed to create pmd for %s as %s\n",
+		RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n",
 			name, tap_name);
 		tap_unit--;		/* Restore the unit number */
 	}
@@ -795,7 +797,7 @@ rte_pmd_tap_remove(const char *name)
 	struct pmd_internals *internals;
 	int i;
 
-	RTE_LOG(INFO, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
+	RTE_LOG(DEBUG, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
 		rte_socket_id());
 
 	/* find the ethdev entry */
Signature · 1 line
2.8.0.GIT
#19 lore raw

PATCH v2 6/6 net/tap: link set down must be before close

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap/rte_eth_tap.c +2 -1
index 65e4bab..966e91a 100644
@@ -353,10 +353,11 @@ tap_dev_stop(struct rte_eth_dev *dev)
 	int i;
 	struct pmd_internals *internals = dev->data->dev_private;
 
+	tap_link_set_down(dev);
+
 	for (i = 0; i < internals->nb_queues; i++)
 		if (internals->rxq[i].fd != -1)
 			close(internals->rxq[i].fd);
-	tap_link_set_down(dev);
 }
 
 static int
Signature · 1 line
2.8.0.GIT
#20 lore raw

Re: [PATCH v2 6/6] net/tap: link set down must be before close

Quoted 12 lines · On Sun, 5 Feb 2017 10:05:09 -0600 Keith Wiles <[email protected]> wrote:
---
 drivers/net/tap/rte_eth_tap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap/rte_eth_tap.c +0 -0
index 65e4bab..966e91a 100644
@@ -353,10 +353,11 @@ tap_dev_stop(struct rte_eth_dev *dev)
 	int i;
 	struct pmd_internals *internals = dev->data->dev_private;

drivers/net/tap/rte_eth_tap.c tap_dev_stop(struct rte_eth_dev *dev) · line 363

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +2 -1
 
+	tap_link_set_down(dev);
+
 	for (i = 0; i < internals->nb_queues; i++)
 		if (internals->rxq[i].fd != -1)
 			close(internals->rxq[i].fd);
-	tap_link_set_down(dev);
 }
 
 static int

There's a word missing in your commit title.
Otherwise the patch is absolutely necessary.

Could you add this line to your patch, please, for traceability?

Fixes ee418a25b0d3 ("net/tap: implement link up and down callbacks")

Thanks for fixing my bug.

Regards,
Pascal

#21 lore raw

Re: [PATCH v2 6/6] net/tap: link set down must be before close

Quoted 4 lines · Pascal Mazon
Fixes ee418a25b0d3 ("net/tap: implement link up and down callbacks”)

As I need to add these changes I will produce a v3 patch

Regards,
Keith

#22 lore raw

PATCH v3 1/7 net/tap: fix tap docs for device name

In reply to Keith Wiles
---
 doc/guides/nics/tap.rst | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
doc/guides/nics/tap.rst +8 -8
index 622b9e7..c4f207b 100644
@@ -45,18 +45,18 @@ device.
 These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK
 along with being able to be used as a network connection to the DPDK
 application. The method enable one or more interfaces is to use the
-``--vdev=net_tap`` option on the DPDK application command line. Each
-``--vdev=net_tap`` option give will create an interface named dtap0, dtap1,
+``--vdev=net_tap0`` option on the DPDK application command line. Each
+``--vdev=net_tap1`` option give will create an interface named dtap0, dtap1,
 and so on.
 
-The interfaced name can be changed by adding the ``iface=foo0``, for example::
+The interface name can be changed by adding the ``iface=foo0``, for example::
 
-   --vdev=net_tap,iface=foo0 --vdev=net_tap,iface=foo1, ...
+   --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ...
 
 Also the speed of the interface can be changed from 10G to whatever number
 needed, but the interface does not enforce that speed, for example::
 
-   --vdev=net_tap,iface=foo0,speed=25000
+   --vdev=net_tap0,iface=foo0,speed=25000
 
 After the DPDK application is started you can send and receive packets on the
 interface using the standard rx_burst/tx_burst APIs in DPDK. From the host
@@ -97,7 +97,7 @@ following::
 
     sudo ./app/app/x86_64-native-linuxapp-gcc/app/pktgen -l 1-5 -n 4        \
      --proc-type auto --log-level 8 --socket-mem 512,512 --file-prefix pg   \
-     --vdev=net_tap --vdev=net_tap -b 05:00.0 -b 05:00.1                    \
+     --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1                  \
      -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3                            \
      -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3                            \
      -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1                   \
@@ -131,6 +131,6 @@ time with ``start all``. The command ``str`` is an alias for ``start all`` and
 
 While running you should see the 64 byte counters increasing to verify the
 traffic is being looped back. You can use ``set all size XXX`` to change the
-size of the packets after you stop the traffic. Use the pktgen ``help``
+size of the packets after you stop the traffic. Use pktgen ``help``
 command to see a list of all commands. You can also use the ``-f`` option to
-load commands at startup.
+load commands at startup in command line or Lua script in pktgen.
Signature · 1 line
2.8.0.GIT
#23 lore raw

PATCH v3 2/7 net/tap: remove redundant fds array

---
 drivers/net/tap/rte_eth_tap.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/tap/rte_eth_tap.c +4 -8
index c7b04bb..6d93eb7 100644
@@ -103,7 +103,6 @@ struct pmd_internals {
 	struct ether_addr eth_addr;	/* Mac address of the device port */
 
 	int if_index;			/* IF_INDEX for the port */
-	int fds[RTE_PMD_TAP_MAX_QUEUES]; /* List of all file descriptors */
 
 	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 */
@@ -349,8 +348,8 @@ tap_dev_stop(struct rte_eth_dev *dev)
 	struct pmd_internals *internals = dev->data->dev_private;
 
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 	tap_link_set_down(dev);
 }
 
@@ -583,7 +582,6 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	internals->fds[rx_queue_id] = fd;
 	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
 
@@ -720,7 +718,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 
 	/* Presetup the fds to -1 as being not working */
 	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
-		pmd->fds[i] = -1;
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
@@ -728,7 +725,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	/* Take the TUN/TAP fd and place in the first location */
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
-	pmd->fds[0] = fd;
 
 	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
@@ -849,8 +845,8 @@ rte_pmd_tap_remove(const char *name)
 
 	internals = eth_dev->data->dev_private;
 	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->fds[i] != -1)
-			close(internals->fds[i]);
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
 
 	rte_free(eth_dev->data->dev_private);
 	rte_free(eth_dev->data);
Signature · 1 line
2.8.0.GIT
#24 lore raw

PATCH v3 3/7 net/tap: remove unused variable and minor cleanup

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/tap/rte_eth_tap.c +3 -7
index 6d93eb7..61659bc 100644
@@ -389,9 +389,7 @@ tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
 		tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
 		rx_total += tap_stats->q_ipackets[i];
 		rx_bytes_total += tap_stats->q_ibytes[i];
-	}
 
-	for (i = 0; i < imax; i++) {
 		tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
 		tap_stats->q_errors[i] = pmd->txq[i].stats.errs;
 		tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
@@ -416,9 +414,7 @@ tap_stats_reset(struct rte_eth_dev *dev)
 	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->rxq[i].stats.ipackets = 0;
 		pmd->rxq[i].stats.ibytes = 0;
-	}
 
-	for (i = 0; i < pmd->nb_queues; i++) {
 		pmd->txq[i].stats.opackets = 0;
 		pmd->txq[i].stats.errs = 0;
 		pmd->txq[i].stats.obytes = 0;
@@ -633,11 +629,11 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct rte_eth_dev *dev, struct ether_addr *addr)
+pmd_mac_address(int fd, struct ether_addr *addr)
 {
 	struct ifreq ifr;
 
-	if ((fd <= 0) || !dev || !addr)
+	if ((fd <= 0) || !addr)
 		return -1;
 
 	memset(&ifr, 0, sizeof(ifr));
@@ -726,7 +722,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	pmd->rxq[0].fd = fd;
 	pmd->txq[0].fd = fd;
 
-	if (pmd_mac_address(fd, dev, &pmd->eth_addr) < 0) {
+	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
 		goto error_exit;
 	}
Signature · 1 line
2.8.0.GIT
#25 lore raw

PATCH v3 4/7 net/tap: fix multi-queue support

In reply to Keith Wiles

At the same time remove the code which created the first device queue at probe time. Now all queues are created during queue setup calls.

---
 drivers/net/tap/rte_eth_tap.c | 104 ++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 70 deletions(-)
drivers/net/tap/rte_eth_tap.c +34 -70
index 61659bc..7c923a2 100644
@@ -57,7 +57,11 @@
 #define ETH_TAP_IFACE_ARG       "iface"
 #define ETH_TAP_SPEED_ARG       "speed"
 
+#ifdef IFF_MULTI_QUEUE
 #define RTE_PMD_TAP_MAX_QUEUES	16
+#else
+#define RTE_PMD_TAP_MAX_QUEUES	1
+#endif
 
 static struct rte_vdev_driver pmd_tap_drv;
 
@@ -114,17 +118,20 @@ struct pmd_internals {
  * supplied name.
  */
 static int
-tun_alloc(char *name)
+tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 {
 	struct ifreq ifr;
+#ifdef IFF_MULTI_QUEUE
 	unsigned int features;
+#endif
 	int fd;
 
 	memset(&ifr, 0, sizeof(struct ifreq));
 
 	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-	if (name && name[0])
-		strncpy(ifr.ifr_name, name, IFNAMSIZ);
+	strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
+
+	RTE_LOG(DEBUG, PMD, "ifr_name '%s'\n", ifr.ifr_name);
 
 	fd = open(TUN_TAP_DEV_PATH, O_RDWR);
 	if (fd < 0) {
@@ -132,37 +139,26 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* Grab the TUN features to verify we can work */
+#ifdef IFF_MULTI_QUEUE
+	/* Grab the TUN features to verify we can work multi-queue */
 	if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n");
+		RTE_LOG(ERR, PMD, "TAP unable to get TUN/TAP features\n");
 		goto error;
 	}
-	RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features);
+	RTE_LOG(DEBUG, PMD, "  TAP Features %08x\n", features);
 
-#ifdef IFF_MULTI_QUEUE
-	if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else if ((features & IFF_ONE_QUEUE) &&
-			(RTE_PMD_TAP_MAX_QUEUES == 1)) {
-		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
-	} else {
-		ifr.ifr_flags |= IFF_MULTI_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n",
+	if (features & IFF_MULTI_QUEUE) {
+		RTE_LOG(DEBUG, PMD, "  Multi-queue support for %d queues\n",
 			RTE_PMD_TAP_MAX_QUEUES);
-	}
-#else
-	if (RTE_PMD_TAP_MAX_QUEUES > 1) {
-		RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n");
-		goto error;
-	} else {
+		ifr.ifr_flags |= IFF_MULTI_QUEUE;
+	} else
+#endif
+	{
 		ifr.ifr_flags |= IFF_ONE_QUEUE;
 		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
 	}
-#endif
 
-	/* Set the TUN/TAP configuration and get the name if needed */
+	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
 		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
 			ifr.ifr_name);
@@ -177,9 +173,15 @@ tun_alloc(char *name)
 		goto error;
 	}
 
-	/* If the name is different that new name as default */
-	if (name && strcmp(name, ifr.ifr_name))
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name);
+	if (qid == 0) {
+		if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
+			RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
+				ifr.ifr_name);
+			goto error;
+		}
+
+		rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+	}
 
 	return fd;
 
@@ -507,7 +509,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 		if (fd < 0) {
 			RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid %d\n",
 				pmd->name, qid);
-			fd = tun_alloc(pmd->name);
+			fd = tun_alloc(pmd, qid);
 			if (fd < 0) {
 				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
 					pmd->name);
@@ -629,34 +631,13 @@ static const struct eth_dev_ops ops = {
 };
 
 static int
-pmd_mac_address(int fd, struct ether_addr *addr)
-{
-	struct ifreq ifr;
-
-	if ((fd <= 0) || !addr)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-
-	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) {
-		RTE_LOG(ERR, PMD, "ioctl failed (SIOCGIFHWADDR) (%s)\n",
-			ifr.ifr_name);
-		return -1;
-	}
-
-	rte_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	return 0;
-}
-
-static int
 eth_dev_tap_create(const char *name, char *tap_name)
 {
 	int numa_node = rte_socket_id();
 	struct rte_eth_dev *dev = NULL;
 	struct pmd_internals *pmd = NULL;
 	struct rte_eth_dev_data *data = NULL;
-	int i, fd = -1;
+	int i;
 
 	RTE_LOG(INFO, PMD,
 		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
@@ -674,7 +655,6 @@ eth_dev_tap_create(const char *name, char *tap_name)
 		goto error_exit;
 	}
 
-	/* Use the name and not the tap_name */
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
 		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
@@ -705,28 +685,12 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	dev->tx_pkt_burst = pmd_tx_burst;
 	snprintf(dev->data->name, sizeof(dev->data->name), "%s", name);
 
-	/* Create the first Tap device */
-	fd = tun_alloc(tap_name);
-	if (fd < 0) {
-		RTE_LOG(ERR, PMD, "tun_alloc() failed\n");
-		goto error_exit;
-	}
-
-	/* Presetup the fds to -1 as being not working */
-	for (i = 1; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
+	/* Presetup the fds to -1 as being not valid */
+	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		pmd->rxq[i].fd = -1;
 		pmd->txq[i].fd = -1;
 	}
 
-	/* Take the TUN/TAP fd and place in the first location */
-	pmd->rxq[0].fd = fd;
-	pmd->txq[0].fd = fd;
-
-	if (pmd_mac_address(fd, &pmd->eth_addr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get MAC address\n");
-		goto error_exit;
-	}
-
 	return 0;
 
 error_exit:
Signature · 1 line
2.8.0.GIT
#26 lore raw

PATCH v3 5/7 net/tap: cleanup log messages

In reply to Keith Wiles
---
 drivers/net/tap/rte_eth_tap.c | 54 ++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 26 deletions(-)
drivers/net/tap/rte_eth_tap.c +28 -26
index 7c923a2..65e4bab 100644
@@ -155,12 +155,13 @@ tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 #endif
 	{
 		ifr.ifr_flags |= IFF_ONE_QUEUE;
-		RTE_LOG(DEBUG, PMD, "Single queue only support\n");
+		RTE_LOG(DEBUG, PMD, "  Single queue only support\n");
 	}
 
 	/* Set the TUN/TAP configuration and set the name if needed */
 	if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n",
+		RTE_LOG(WARNING, PMD,
+			"Unable to set TUNSETIFF for %s\n",
 			ifr.ifr_name);
 		perror("TUNSETIFF");
 		goto error;
@@ -168,7 +169,9 @@ tun_alloc(struct pmd_internals *pmd, uint16_t qid)
 
 	/* Always set the file descriptor to non-blocking */
 	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
-		RTE_LOG(ERR, PMD, "Unable to set to nonblocking\n");
+		RTE_LOG(WARNING, PMD,
+			"Unable to set %s to nonblocking\n",
+			ifr.ifr_name);
 		perror("F_SETFL, NONBLOCK");
 		goto error;
 	}
@@ -207,7 +210,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		/* allocate the next mbuf */
 		mbuf = rte_pktmbuf_alloc(rxq->mp);
 		if (unlikely(!mbuf)) {
-			RTE_LOG(WARNING, PMD, "Unable to allocate mbuf\n");
+			RTE_LOG(WARNING, PMD, "TAP unable to allocate mbuf\n");
 			break;
 		}
 
@@ -276,7 +279,8 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	return num_tx;
 }
 
-static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
+static int
+tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
 {
 	struct ifreq ifr;
 	int err, s;
@@ -296,8 +300,8 @@ static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
 	strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
 	err = ioctl(s, SIOCGIFFLAGS, &ifr);
 	if (err < 0) {
-		RTE_LOG(ERR, PMD, "Unable to get tap netdevice flags: %s\n",
-			strerror(errno));
+		RTE_LOG(WARNING, PMD, "Unable to get %s device flags: %s\n",
+			pmd->name, strerror(errno));
 		close(s);
 		return -1;
 	}
@@ -307,7 +311,7 @@ static int tap_link_set_flags(struct pmd_internals *pmd, short flags, int add)
 		ifr.ifr_flags &= ~flags;
 	err = ioctl(s, SIOCSIFFLAGS, &ifr);
 	if (err < 0) {
-		RTE_LOG(ERR, PMD, "Unable to %s flags 0x%x: %s\n",
+		RTE_LOG(WARNING, PMD, "Unable to %s flags 0x%x: %s\n",
 			add ? "set" : "unset", flags, strerror(errno));
 		close(s);
 		return -1;
@@ -511,8 +515,8 @@ tap_setup_queue(struct rte_eth_dev *dev,
 				pmd->name, qid);
 			fd = tun_alloc(pmd, qid);
 			if (fd < 0) {
-				RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n",
-					pmd->name);
+				RTE_LOG(ERR, PMD, "tun_alloc(%s, %d) failed\n",
+					pmd->name, qid);
 				return -1;
 			}
 		}
@@ -557,8 +561,8 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	int fd;
 
 	if ((rx_queue_id >= internals->nb_queues) || !mp) {
-		RTE_LOG(ERR, PMD, "nb_queues %d mp %p\n",
-			internals->nb_queues, mp);
+		RTE_LOG(WARNING, PMD, "nb_queues %d too small or mempool NULL\n",
+			internals->nb_queues);
 		return -1;
 	}
 
@@ -570,7 +574,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 				RTE_PKTMBUF_HEADROOM);
 
 	if (buf_size < ETH_FRAME_LEN) {
-		RTE_LOG(ERR, PMD,
+		RTE_LOG(WARNING, PMD,
 			"%s: %d bytes will not fit in mbuf (%d bytes)\n",
 			dev->data->name, ETH_FRAME_LEN, buf_size);
 		return -ENOMEM;
@@ -580,7 +584,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,
 	if (fd == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "RX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  RX TAP device name %s, qid %d on fd %d\n",
 		internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
 
 	return 0;
@@ -603,7 +607,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,
 	if (ret == -1)
 		return -1;
 
-	RTE_LOG(INFO, PMD, "TX TAP device name %s, qid %d on fd %d\n",
+	RTE_LOG(DEBUG, PMD, "  TX TAP device name %s, qid %d on fd %d\n",
 		internals->name, tx_queue_id, internals->txq[tx_queue_id].fd);
 
 	return 0;
@@ -639,25 +643,23 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	struct rte_eth_dev_data *data = NULL;
 	int i;
 
-	RTE_LOG(INFO, PMD,
-		"%s: Create TAP Ethernet device with %d queues on numa %u\n",
-		 name, RTE_PMD_TAP_MAX_QUEUES, rte_socket_id());
+	RTE_LOG(DEBUG, PMD, "  TAP device on numa %u\n", rte_socket_id());
 
 	data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
 	if (!data) {
-		RTE_LOG(ERR, PMD, "Failed to allocate data\n");
+		RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
 		goto error_exit;
 	}
 
 	pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node);
 	if (!pmd) {
-		RTE_LOG(ERR, PMD, "Unable to allocate internal struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate internal struct\n");
 		goto error_exit;
 	}
 
 	dev = rte_eth_dev_allocate(tap_name);
 	if (!dev) {
-		RTE_LOG(ERR, PMD, "Unable to allocate device struct\n");
+		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
 		goto error_exit;
 	}
 
@@ -694,7 +696,7 @@ eth_dev_tap_create(const char *name, char *tap_name)
 	return 0;
 
 error_exit:
-	RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name);
+	RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name);
 
 	rte_free(data);
 	rte_free(pmd);
@@ -745,7 +747,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 		 DEFAULT_TAP_NAME, tap_unit++);
 
 	if (params && (params[0] != '\0')) {
-		RTE_LOG(INFO, PMD, "paramaters (%s)\n", params);
+		RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
 
 		kvlist = rte_kvargs_parse(params, valid_arguments);
 		if (kvlist) {
@@ -770,14 +772,14 @@ rte_pmd_tap_probe(const char *name, const char *params)
 	}
 	pmd_link.link_speed = speed;
 
-	RTE_LOG(INFO, PMD, "Initializing pmd_tap for %s as %s\n",
+	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
 	ret = eth_dev_tap_create(name, tap_name);
 
 leave:
 	if (ret == -1) {
-		RTE_LOG(INFO, PMD, "Failed to create pmd for %s as %s\n",
+		RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n",
 			name, tap_name);
 		tap_unit--;		/* Restore the unit number */
 	}
@@ -795,7 +797,7 @@ rte_pmd_tap_remove(const char *name)
 	struct pmd_internals *internals;
 	int i;
 
-	RTE_LOG(INFO, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
+	RTE_LOG(DEBUG, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
 		rte_socket_id());
 
 	/* find the ethdev entry */
Signature · 1 line
2.8.0.GIT
#27 lore raw

PATCH v3 6/7 net/tap: link set down must be done before close

In reply to Keith Wiles
Fixes ee418a25b0d3 ("net/tap: implement link up and down callbacks")
---
 drivers/net/tap/rte_eth_tap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap/rte_eth_tap.c +2 -1
index 65e4bab..966e91a 100644
@@ -353,10 +353,11 @@ tap_dev_stop(struct rte_eth_dev *dev)
 	int i;
 	struct pmd_internals *internals = dev->data->dev_private;
 
+	tap_link_set_down(dev);
+
 	for (i = 0; i < internals->nb_queues; i++)
 		if (internals->rxq[i].fd != -1)
 			close(internals->rxq[i].fd);
-	tap_link_set_down(dev);
 }
 
 static int
Signature · 1 line
2.8.0.GIT
#28 lore raw

PATCH v3 7/7 net/tap: move closing fds to pmd close from pmd stop

In reply to Keith Wiles

At the same time remove closing fds code from pmd stop routine.

---
 drivers/net/tap/rte_eth_tap.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/net/tap/rte_eth_tap.c +11 -7
index 966e91a..0a7f4af 100644
@@ -350,14 +350,7 @@ tap_dev_start(struct rte_eth_dev *dev)
 static void
 tap_dev_stop(struct rte_eth_dev *dev)
 {
-	int i;
-	struct pmd_internals *internals = dev->data->dev_private;
-
 	tap_link_set_down(dev);
-
-	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->rxq[i].fd != -1)
-			close(internals->rxq[i].fd);
 }
 
 static int
@@ -431,6 +424,17 @@ tap_stats_reset(struct rte_eth_dev *dev)
 static void
 tap_dev_close(struct rte_eth_dev *dev __rte_unused)
 {
+	int i;
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	tap_link_set_down(dev);
+
+	for (i = 0; i < internals->nb_queues; i++) {
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
+		internals->rxq[i].fd = -1;
+		internals->txq[i].fd = -1;
+	}
 }
 
 static void
Signature · 1 line
2.8.0.GIT
Acked-by on v3 7/7
#29 lore raw

Re: [PATCH v3 7/7] net/tap: move closing fds to pmd close from pmd stop

Quoted 34 lines · On Mon, 6 Feb 2017 13:40:38 -0600 Keith Wiles <[email protected]> wrote:

At the same time remove closing fds code from pmd stop routine.

---
 drivers/net/tap/rte_eth_tap.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/net/tap/rte_eth_tap.c +4 -7
index 966e91a..0a7f4af 100644
@@ -350,14 +350,7 @@ tap_dev_start(struct rte_eth_dev *dev)
 static void
 tap_dev_stop(struct rte_eth_dev *dev)
 {
-	int i;
-	struct pmd_internals *internals = dev->data->dev_private;
-
 	tap_link_set_down(dev);
-
-	for (i = 0; i < internals->nb_queues; i++)
-		if (internals->rxq[i].fd != -1)
-			close(internals->rxq[i].fd);
 }
 
 static int
@@ -431,6 +424,17 @@ tap_stats_reset(struct rte_eth_dev *dev)
 static void
 tap_dev_close(struct rte_eth_dev *dev __rte_unused)
 {
+	int i;
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	tap_link_set_down(dev);

drivers/net/tap/rte_eth_tap.c tap_stats_reset(struct rte_eth_dev *dev) · line 440

Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +7 -0
+
+	for (i = 0; i < internals->nb_queues; i++) {
+		if (internals->rxq[i].fd != -1)
+			close(internals->rxq[i].fd);
+		internals->rxq[i].fd = -1;
+		internals->txq[i].fd = -1;
+	}
 }
 
 static void

Ok, the series looks good to me.

#30 lore raw

Re: [PATCH v3 7/7] net/tap: move closing fds to pmd close from pmd stop

On 2/7/2017 8:51 AM, Pascal Mazon wrote:
<...>

Quoted 1 line
Quoted 1 line

<...>

Quoted 1 line

Series applied to dpdk-next-net/master, thanks.

(
patch 1/7: docs: fix tap PMD docs for device name
patch 4/7: Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD") patch 5/7: checkpatch warning fixed
patch 6/7: Fixes: 082fdb7361d7 ("net/tap: implement link up and down callbacks")
)