patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] examples/l2fwd/main.c: free resources in case of error
@ 2020-05-11 11:28 Muhammad Bilal
  2020-05-12  4:49 ` Varghese, Vipin
  2020-05-12 13:56 ` [dpdk-stable] [PATCH v2] examples/l2fwd: " Muhammad Bilal
  0 siblings, 2 replies; 6+ messages in thread
From: Muhammad Bilal @ 2020-05-11 11:28 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, Muhammad Bilal, stable, vipin.varghese, jgrajcia

Bugzilla ID: 437
Cc: dev@dpdk.org
Cc: stable@dpdk.org
Cc: bruce.richardson@intel.com
Cc: vipin.varghese@intel.com
Cc: jgrajcia@cisco.com
Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
---
 examples/l2fwd/main.c | 72 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 57 insertions(+), 15 deletions(-)

diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 88ddfe589..dbaa457e2 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -517,6 +517,17 @@ signal_handler(int signum)
 	}
 }
 
+static void
+stop_and_close_eth_dev(uint16_t portid)
+{
+	RTE_ETH_FOREACH_DEV(portid) {
+		printf("Closing port %d...", portid);
+		rte_eth_dev_stop(portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+	}
+}
+
 int
 main(int argc, char **argv)
 {
@@ -543,8 +554,10 @@ main(int argc, char **argv)
 
 	/* parse application arguments (after the EAL ones) */
 	ret = l2fwd_parse_args(argc, argv);
-	if (ret < 0)
+	if (ret < 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n");
+	}
 
 	printf("MAC updating %s\n", mac_updating ? "enabled" : "disabled");
 
@@ -552,13 +565,17 @@ main(int argc, char **argv)
 	timer_period *= rte_get_timer_hz();
 
 	nb_ports = rte_eth_dev_count_avail();
-	if (nb_ports == 0)
+	if (nb_ports == 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
+	}
 
 	/* check port mask to possible port mask */
-	if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1))
+	if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1)) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Invalid portmask; possible (0x%x)\n",
 			(1 << nb_ports) - 1);
+	}
 
 	/* reset l2fwd_dst_ports */
 	for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
@@ -601,8 +618,10 @@ main(int argc, char **argv)
 		       lcore_queue_conf[rx_lcore_id].n_rx_port ==
 		       l2fwd_rx_queue_per_lcore) {
 			rx_lcore_id++;
-			if (rx_lcore_id >= RTE_MAX_LCORE)
+			if (rx_lcore_id >= RTE_MAX_LCORE) {
+				stop_and_close_eth_dev(portid);
 				rte_exit(EXIT_FAILURE, "Not enough cores\n");
+			}
 		}
 
 		if (qconf != &lcore_queue_conf[rx_lcore_id]) {
@@ -623,8 +642,10 @@ main(int argc, char **argv)
 	l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
 		MEMPOOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
 		rte_socket_id());
-	if (l2fwd_pktmbuf_pool == NULL)
+	if (l2fwd_pktmbuf_pool == NULL) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
+	}
 
 	/* Initialise each port */
 	RTE_ETH_FOREACH_DEV(portid) {
@@ -645,32 +666,40 @@ main(int argc, char **argv)
 		fflush(stdout);
 
 		ret = rte_eth_dev_info_get(portid, &dev_info);
-		if (ret != 0)
+		if (ret != 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				"Error during getting device (port %u) info: %s\n",
 				portid, strerror(-ret));
+		}
 
 		if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
 			local_port_conf.txmode.offloads |=
 				DEV_TX_OFFLOAD_MBUF_FAST_FREE;
 		ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
 				  ret, portid);
+		}
 
 		ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
 						       &nb_txd);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				 "Cannot adjust number of descriptors: err=%d, port=%u\n",
 				 ret, portid);
+		}
 
 		ret = rte_eth_macaddr_get(portid,
 					  &l2fwd_ports_eth_addr[portid]);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				 "Cannot get MAC address: err=%d, port=%u\n",
 				 ret, portid);
+		}
 
 		/* init one RX queue */
 		fflush(stdout);
@@ -680,9 +709,11 @@ main(int argc, char **argv)
 					     rte_eth_dev_socket_id(portid),
 					     &rxq_conf,
 					     l2fwd_pktmbuf_pool);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n",
 				  ret, portid);
+		}
 
 		/* init one TX queue on each port */
 		fflush(stdout);
@@ -691,27 +722,33 @@ main(int argc, char **argv)
 		ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
 				rte_eth_dev_socket_id(portid),
 				&txq_conf);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n",
 				ret, portid);
+		}
 
 		/* Initialize TX buffers */
 		tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
 				RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
 				rte_eth_dev_socket_id(portid));
-		if (tx_buffer[portid] == NULL)
+		if (tx_buffer[portid] == NULL) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n",
 					portid);
+		}
 
 		rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST);
 
 		ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid],
 				rte_eth_tx_buffer_count_callback,
 				&port_statistics[portid].dropped);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 			"Cannot set error callback for tx buffer on port %u\n",
 				 portid);
+		}
 
 		ret = rte_eth_dev_set_ptypes(portid, RTE_PTYPE_UNKNOWN, NULL,
 					     0);
@@ -720,17 +757,21 @@ main(int argc, char **argv)
 					portid);
 		/* Start device */
 		ret = rte_eth_dev_start(portid);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n",
 				  ret, portid);
+		}
 
 		printf("done: \n");
 
 		ret = rte_eth_promiscuous_enable(portid);
-		if (ret != 0)
+		if (ret != 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				 "rte_eth_promiscuous_enable:err=%s, port=%u\n",
 				 rte_strerror(-ret), portid);
+		}
 
 		printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
 				portid,
@@ -746,6 +787,7 @@ main(int argc, char **argv)
 	}
 
 	if (!nb_ports_available) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE,
 			"All available ports are disabled. Please set portmask.\n");
 	}
-- 
2.17.1


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

* Re: [dpdk-stable] [PATCH] examples/l2fwd/main.c: free resources in case of error
  2020-05-11 11:28 [dpdk-stable] [PATCH] examples/l2fwd/main.c: free resources in case of error Muhammad Bilal
@ 2020-05-12  4:49 ` Varghese, Vipin
  2020-05-12  5:44   ` [dpdk-stable] [dpdk-dev] " Jerin Jacob
  2020-05-12 13:56 ` [dpdk-stable] [PATCH v2] examples/l2fwd: " Muhammad Bilal
  1 sibling, 1 reply; 6+ messages in thread
From: Varghese, Vipin @ 2020-05-12  4:49 UTC (permalink / raw)
  To: Muhammad Bilal, Richardson, Bruce; +Cc: dev, stable, jgrajcia

snipped
> Subject: [PATCH] examples/l2fwd/main.c: free resources in case of error
> 
> Bugzilla ID: 437
> Cc: dev@dpdk.org
> Cc: stable@dpdk.org
> Cc: bruce.richardson@intel.com
> Cc: vipin.varghese@intel.com
> Cc: jgrajcia@cisco.com
> Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
> ---
>  examples/l2fwd/main.c | 72 ++++++++++++++++++++++++++++++++++---------
>  1 file changed, 57 insertions(+), 15 deletions(-)
> 
> diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index
> 88ddfe589..dbaa457e2 100644
> --- a/examples/l2fwd/main.c
> +++ b/examples/l2fwd/main.c
> @@ -517,6 +517,17 @@ signal_handler(int signum)
>  	}
>  }
> 
> +static void
> +stop_and_close_eth_dev(uint16_t portid) {
> +	RTE_ETH_FOREACH_DEV(portid) {
> +		printf("Closing port %d...", portid);
> +		rte_eth_dev_stop(portid);
> +		rte_eth_dev_close(portid);
> +		printf(" Done\n");
> +	}
> +}
> +
If the solution is to cleanup in application, then all application needs to do cleanup. Hence `+1` for updating this to all examples in DPDK. 


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

* Re: [dpdk-stable] [dpdk-dev] [PATCH] examples/l2fwd/main.c: free resources in case of error
  2020-05-12  4:49 ` Varghese, Vipin
@ 2020-05-12  5:44   ` Jerin Jacob
  0 siblings, 0 replies; 6+ messages in thread
From: Jerin Jacob @ 2020-05-12  5:44 UTC (permalink / raw)
  To: Varghese, Vipin; +Cc: Muhammad Bilal, Richardson, Bruce, dev, stable, jgrajcia

On Tue, May 12, 2020 at 10:20 AM Varghese, Vipin
<vipin.varghese@intel.com> wrote:
>
> snipped
> > Subject: [PATCH] examples/l2fwd/main.c: free resources in case of error
> >
> > Bugzilla ID: 437
> > Cc: dev@dpdk.org
> > Cc: stable@dpdk.org
> > Cc: bruce.richardson@intel.com
> > Cc: vipin.varghese@intel.com
> > Cc: jgrajcia@cisco.com
> > Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
> > ---
> >  examples/l2fwd/main.c | 72 ++++++++++++++++++++++++++++++++++---------
> >  1 file changed, 57 insertions(+), 15 deletions(-)
> >
> > diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index
> > 88ddfe589..dbaa457e2 100644
> > --- a/examples/l2fwd/main.c
> > +++ b/examples/l2fwd/main.c
> > @@ -517,6 +517,17 @@ signal_handler(int signum)
> >       }
> >  }
> >
> > +static void
> > +stop_and_close_eth_dev(uint16_t portid) {
> > +     RTE_ETH_FOREACH_DEV(portid) {
> > +             printf("Closing port %d...", portid);
> > +             rte_eth_dev_stop(portid);
> > +             rte_eth_dev_close(portid);
> > +             printf(" Done\n");
> > +     }
> > +}
> > +
> If the solution is to cleanup in application, then all application needs to do cleanup. Hence `+1` for updating this to all examples in DPDK.

When updating the examples, Add  the rte_eal_cleanup() as well(it is
the counterpart of rte_eal_init())


>

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

* [dpdk-stable] [PATCH v2] examples/l2fwd: free resources in case of error
  2020-05-11 11:28 [dpdk-stable] [PATCH] examples/l2fwd/main.c: free resources in case of error Muhammad Bilal
  2020-05-12  4:49 ` Varghese, Vipin
@ 2020-05-12 13:56 ` Muhammad Bilal
  2020-06-05 12:01   ` Muhammad Bilal
  2023-06-12 21:18   ` [dpdk-dev] " Stephen Hemminger
  1 sibling, 2 replies; 6+ messages in thread
From: Muhammad Bilal @ 2020-05-12 13:56 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, Muhammad Bilal, stable, vipin.varghese, jgrajcia

Bugzilla ID: 437
Cc: dev@dpdk.org
Cc: stable@dpdk.org
Cc: bruce.richardson@intel.com
Cc: vipin.varghese@intel.com
Cc: jgrajcia@cisco.com
Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
---
 examples/l2fwd/main.c | 76 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 60 insertions(+), 16 deletions(-)

diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 88ddfe589..efea2dce3 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -517,6 +517,18 @@ signal_handler(int signum)
 	}
 }
 
+static void
+stop_and_close_eth_dev(uint16_t portid)
+{
+	RTE_ETH_FOREACH_DEV(portid) {
+		printf("Closing port %d...", portid);
+		rte_eth_dev_stop(portid);
+		rte_eth_dev_close(portid);
+		printf(" Done\n");
+		rte_eal_cleanup();
+	}
+}
+
 int
 main(int argc, char **argv)
 {
@@ -524,7 +536,8 @@ main(int argc, char **argv)
 	int ret;
 	uint16_t nb_ports;
 	uint16_t nb_ports_available = 0;
-	uint16_t portid, last_port;
+	uint16_t portid = 0;
+	uint16_t last_port;
 	unsigned lcore_id, rx_lcore_id;
 	unsigned nb_ports_in_mask = 0;
 	unsigned int nb_lcores = 0;
@@ -543,8 +556,10 @@ main(int argc, char **argv)
 
 	/* parse application arguments (after the EAL ones) */
 	ret = l2fwd_parse_args(argc, argv);
-	if (ret < 0)
+	if (ret < 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n");
+	}
 
 	printf("MAC updating %s\n", mac_updating ? "enabled" : "disabled");
 
@@ -552,13 +567,17 @@ main(int argc, char **argv)
 	timer_period *= rte_get_timer_hz();
 
 	nb_ports = rte_eth_dev_count_avail();
-	if (nb_ports == 0)
+	if (nb_ports == 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
+	}
 
 	/* check port mask to possible port mask */
-	if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1))
+	if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1)) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Invalid portmask; possible (0x%x)\n",
 			(1 << nb_ports) - 1);
+	}
 
 	/* reset l2fwd_dst_ports */
 	for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
@@ -601,8 +620,10 @@ main(int argc, char **argv)
 		       lcore_queue_conf[rx_lcore_id].n_rx_port ==
 		       l2fwd_rx_queue_per_lcore) {
 			rx_lcore_id++;
-			if (rx_lcore_id >= RTE_MAX_LCORE)
+			if (rx_lcore_id >= RTE_MAX_LCORE) {
+				stop_and_close_eth_dev(portid);
 				rte_exit(EXIT_FAILURE, "Not enough cores\n");
+			}
 		}
 
 		if (qconf != &lcore_queue_conf[rx_lcore_id]) {
@@ -623,8 +644,10 @@ main(int argc, char **argv)
 	l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
 		MEMPOOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
 		rte_socket_id());
-	if (l2fwd_pktmbuf_pool == NULL)
+	if (l2fwd_pktmbuf_pool == NULL) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
+	}
 
 	/* Initialise each port */
 	RTE_ETH_FOREACH_DEV(portid) {
@@ -645,32 +668,40 @@ main(int argc, char **argv)
 		fflush(stdout);
 
 		ret = rte_eth_dev_info_get(portid, &dev_info);
-		if (ret != 0)
+		if (ret != 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				"Error during getting device (port %u) info: %s\n",
 				portid, strerror(-ret));
+		}
 
 		if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
 			local_port_conf.txmode.offloads |=
 				DEV_TX_OFFLOAD_MBUF_FAST_FREE;
 		ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
 				  ret, portid);
+		}
 
 		ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
 						       &nb_txd);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				 "Cannot adjust number of descriptors: err=%d, port=%u\n",
 				 ret, portid);
+		}
 
 		ret = rte_eth_macaddr_get(portid,
 					  &l2fwd_ports_eth_addr[portid]);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				 "Cannot get MAC address: err=%d, port=%u\n",
 				 ret, portid);
+		}
 
 		/* init one RX queue */
 		fflush(stdout);
@@ -680,9 +711,11 @@ main(int argc, char **argv)
 					     rte_eth_dev_socket_id(portid),
 					     &rxq_conf,
 					     l2fwd_pktmbuf_pool);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n",
 				  ret, portid);
+		}
 
 		/* init one TX queue on each port */
 		fflush(stdout);
@@ -691,27 +724,33 @@ main(int argc, char **argv)
 		ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
 				rte_eth_dev_socket_id(portid),
 				&txq_conf);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n",
 				ret, portid);
+		}
 
 		/* Initialize TX buffers */
 		tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
 				RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
 				rte_eth_dev_socket_id(portid));
-		if (tx_buffer[portid] == NULL)
+		if (tx_buffer[portid] == NULL) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n",
 					portid);
+		}
 
 		rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST);
 
 		ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid],
 				rte_eth_tx_buffer_count_callback,
 				&port_statistics[portid].dropped);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 			"Cannot set error callback for tx buffer on port %u\n",
 				 portid);
+		}
 
 		ret = rte_eth_dev_set_ptypes(portid, RTE_PTYPE_UNKNOWN, NULL,
 					     0);
@@ -720,17 +759,21 @@ main(int argc, char **argv)
 					portid);
 		/* Start device */
 		ret = rte_eth_dev_start(portid);
-		if (ret < 0)
+		if (ret < 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n",
 				  ret, portid);
+		}
 
 		printf("done: \n");
 
 		ret = rte_eth_promiscuous_enable(portid);
-		if (ret != 0)
+		if (ret != 0) {
+			stop_and_close_eth_dev(portid);
 			rte_exit(EXIT_FAILURE,
 				 "rte_eth_promiscuous_enable:err=%s, port=%u\n",
 				 rte_strerror(-ret), portid);
+		}
 
 		printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
 				portid,
@@ -746,6 +789,7 @@ main(int argc, char **argv)
 	}
 
 	if (!nb_ports_available) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE,
 			"All available ports are disabled. Please set portmask.\n");
 	}
-- 
2.17.1


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

* Re: [dpdk-stable] [PATCH v2] examples/l2fwd: free resources in case of error
  2020-05-12 13:56 ` [dpdk-stable] [PATCH v2] examples/l2fwd: " Muhammad Bilal
@ 2020-06-05 12:01   ` Muhammad Bilal
  2023-06-12 21:18   ` [dpdk-dev] " Stephen Hemminger
  1 sibling, 0 replies; 6+ messages in thread
From: Muhammad Bilal @ 2020-06-05 12:01 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, stable, vipin.varghese, jgrajcia

Is there anything else to be done for acceptance? So that this problem
can be removed from other examples.

On Tue, May 12, 2020 at 6:57 PM Muhammad Bilal <m.bilal@emumba.com> wrote:
>
> Bugzilla ID: 437
> Cc: dev@dpdk.org
> Cc: stable@dpdk.org
> Cc: bruce.richardson@intel.com
> Cc: vipin.varghese@intel.com
> Cc: jgrajcia@cisco.com
> Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
> ---
>  examples/l2fwd/main.c | 76 ++++++++++++++++++++++++++++++++++---------
>  1 file changed, 60 insertions(+), 16 deletions(-)
>
> diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
> index 88ddfe589..efea2dce3 100644
> --- a/examples/l2fwd/main.c
> +++ b/examples/l2fwd/main.c
> @@ -517,6 +517,18 @@ signal_handler(int signum)
>         }
>  }
>
> +static void
> +stop_and_close_eth_dev(uint16_t portid)
> +{
> +       RTE_ETH_FOREACH_DEV(portid) {
> +               printf("Closing port %d...", portid);
> +               rte_eth_dev_stop(portid);
> +               rte_eth_dev_close(portid);
> +               printf(" Done\n");
> +               rte_eal_cleanup();
> +       }
> +}
> +
>  int
>  main(int argc, char **argv)
>  {
> @@ -524,7 +536,8 @@ main(int argc, char **argv)
>         int ret;
>         uint16_t nb_ports;
>         uint16_t nb_ports_available = 0;
> -       uint16_t portid, last_port;
> +       uint16_t portid = 0;
> +       uint16_t last_port;
>         unsigned lcore_id, rx_lcore_id;
>         unsigned nb_ports_in_mask = 0;
>         unsigned int nb_lcores = 0;
> @@ -543,8 +556,10 @@ main(int argc, char **argv)
>
>         /* parse application arguments (after the EAL ones) */
>         ret = l2fwd_parse_args(argc, argv);
> -       if (ret < 0)
> +       if (ret < 0) {
> +               stop_and_close_eth_dev(portid);
>                 rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n");
> +       }
>
>         printf("MAC updating %s\n", mac_updating ? "enabled" : "disabled");
>
> @@ -552,13 +567,17 @@ main(int argc, char **argv)
>         timer_period *= rte_get_timer_hz();
>
>         nb_ports = rte_eth_dev_count_avail();
> -       if (nb_ports == 0)
> +       if (nb_ports == 0) {
> +               stop_and_close_eth_dev(portid);
>                 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
> +       }
>
>         /* check port mask to possible port mask */
> -       if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1))
> +       if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1)) {
> +               stop_and_close_eth_dev(portid);
>                 rte_exit(EXIT_FAILURE, "Invalid portmask; possible (0x%x)\n",
>                         (1 << nb_ports) - 1);
> +       }
>
>         /* reset l2fwd_dst_ports */
>         for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
> @@ -601,8 +620,10 @@ main(int argc, char **argv)
>                        lcore_queue_conf[rx_lcore_id].n_rx_port ==
>                        l2fwd_rx_queue_per_lcore) {
>                         rx_lcore_id++;
> -                       if (rx_lcore_id >= RTE_MAX_LCORE)
> +                       if (rx_lcore_id >= RTE_MAX_LCORE) {
> +                               stop_and_close_eth_dev(portid);
>                                 rte_exit(EXIT_FAILURE, "Not enough cores\n");
> +                       }
>                 }
>
>                 if (qconf != &lcore_queue_conf[rx_lcore_id]) {
> @@ -623,8 +644,10 @@ main(int argc, char **argv)
>         l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
>                 MEMPOOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
>                 rte_socket_id());
> -       if (l2fwd_pktmbuf_pool == NULL)
> +       if (l2fwd_pktmbuf_pool == NULL) {
> +               stop_and_close_eth_dev(portid);
>                 rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
> +       }
>
>         /* Initialise each port */
>         RTE_ETH_FOREACH_DEV(portid) {
> @@ -645,32 +668,40 @@ main(int argc, char **argv)
>                 fflush(stdout);
>
>                 ret = rte_eth_dev_info_get(portid, &dev_info);
> -               if (ret != 0)
> +               if (ret != 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE,
>                                 "Error during getting device (port %u) info: %s\n",
>                                 portid, strerror(-ret));
> +               }
>
>                 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
>                         local_port_conf.txmode.offloads |=
>                                 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
>                 ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
>                                   ret, portid);
> +               }
>
>                 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
>                                                        &nb_txd);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE,
>                                  "Cannot adjust number of descriptors: err=%d, port=%u\n",
>                                  ret, portid);
> +               }
>
>                 ret = rte_eth_macaddr_get(portid,
>                                           &l2fwd_ports_eth_addr[portid]);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE,
>                                  "Cannot get MAC address: err=%d, port=%u\n",
>                                  ret, portid);
> +               }
>
>                 /* init one RX queue */
>                 fflush(stdout);
> @@ -680,9 +711,11 @@ main(int argc, char **argv)
>                                              rte_eth_dev_socket_id(portid),
>                                              &rxq_conf,
>                                              l2fwd_pktmbuf_pool);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n",
>                                   ret, portid);
> +               }
>
>                 /* init one TX queue on each port */
>                 fflush(stdout);
> @@ -691,27 +724,33 @@ main(int argc, char **argv)
>                 ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
>                                 rte_eth_dev_socket_id(portid),
>                                 &txq_conf);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n",
>                                 ret, portid);
> +               }
>
>                 /* Initialize TX buffers */
>                 tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
>                                 RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
>                                 rte_eth_dev_socket_id(portid));
> -               if (tx_buffer[portid] == NULL)
> +               if (tx_buffer[portid] == NULL) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n",
>                                         portid);
> +               }
>
>                 rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST);
>
>                 ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid],
>                                 rte_eth_tx_buffer_count_callback,
>                                 &port_statistics[portid].dropped);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE,
>                         "Cannot set error callback for tx buffer on port %u\n",
>                                  portid);
> +               }
>
>                 ret = rte_eth_dev_set_ptypes(portid, RTE_PTYPE_UNKNOWN, NULL,
>                                              0);
> @@ -720,17 +759,21 @@ main(int argc, char **argv)
>                                         portid);
>                 /* Start device */
>                 ret = rte_eth_dev_start(portid);
> -               if (ret < 0)
> +               if (ret < 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n",
>                                   ret, portid);
> +               }
>
>                 printf("done: \n");
>
>                 ret = rte_eth_promiscuous_enable(portid);
> -               if (ret != 0)
> +               if (ret != 0) {
> +                       stop_and_close_eth_dev(portid);
>                         rte_exit(EXIT_FAILURE,
>                                  "rte_eth_promiscuous_enable:err=%s, port=%u\n",
>                                  rte_strerror(-ret), portid);
> +               }
>
>                 printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
>                                 portid,
> @@ -746,6 +789,7 @@ main(int argc, char **argv)
>         }
>
>         if (!nb_ports_available) {
> +               stop_and_close_eth_dev(portid);
>                 rte_exit(EXIT_FAILURE,
>                         "All available ports are disabled. Please set portmask.\n");
>         }
> --
> 2.17.1
>

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

* Re: [dpdk-dev] [PATCH v2] examples/l2fwd: free resources in case of error
  2020-05-12 13:56 ` [dpdk-stable] [PATCH v2] examples/l2fwd: " Muhammad Bilal
  2020-06-05 12:01   ` Muhammad Bilal
@ 2023-06-12 21:18   ` Stephen Hemminger
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2023-06-12 21:18 UTC (permalink / raw)
  To: Muhammad Bilal; +Cc: bruce.richardson, dev, stable, vipin.varghese, jgrajcia

On Tue, 12 May 2020 18:56:37 +0500
Muhammad Bilal <m.bilal@emumba.com> wrote:

> Bugzilla ID: 437
> Cc: dev@dpdk.org
> Cc: stable@dpdk.org
> Cc: bruce.richardson@intel.com
> Cc: vipin.varghese@intel.com
> Cc: jgrajcia@cisco.com
> Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>

This whole series was just trying to workaround a bug in memif driver.
Please fix that driver instead.

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

end of thread, other threads:[~2023-06-12 21:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 11:28 [dpdk-stable] [PATCH] examples/l2fwd/main.c: free resources in case of error Muhammad Bilal
2020-05-12  4:49 ` Varghese, Vipin
2020-05-12  5:44   ` [dpdk-stable] [dpdk-dev] " Jerin Jacob
2020-05-12 13:56 ` [dpdk-stable] [PATCH v2] examples/l2fwd: " Muhammad Bilal
2020-06-05 12:01   ` Muhammad Bilal
2023-06-12 21:18   ` [dpdk-dev] " Stephen Hemminger

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