DPDK patches and discussions
 help / color / mirror / Atom feed
From: Muhammad Bilal <m.bilal@emumba.com>
To: declan.doherty@intel.com, tomasz.kantecki@intel.com,
	pbhagavatula@marvell.com, skori@marvell.com
Cc: dev@dpdk.org, Muhammad Bilal <m.bilal@emumba.com>
Subject: [dpdk-dev] [PATCH 5/5] examples/l2fwd-crypto: free resources in case of error
Date: Tue, 19 May 2020 13:54:44 +0500
Message-ID: <20200519085444.4562-5-m.bilal@emumba.com> (raw)
In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com>

Freeing the resources and call rte_eal_cleanup in case of error exit.
Signed-off-by: Muhammad Bilal <m.bilal@emumba.com>
---
 examples/l2fwd-crypto/main.c | 54 ++++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 11 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index fcb55c370..169f011f8 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -2660,6 +2660,18 @@ reserve_key_memory(struct l2fwd_crypto_options *options)
 	options->aad.phys_addr = rte_malloc_virt2iova(options->aad.data);
 }
 
+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)
 {
@@ -2667,7 +2679,7 @@ main(int argc, char **argv)
 	struct l2fwd_crypto_options options;
 
 	uint8_t nb_cryptodevs, cdev_id;
-	uint16_t portid;
+	uint16_t portid = 0;
 	unsigned lcore_id, rx_lcore_id = 0;
 	int ret, enabled_cdevcount, enabled_portcount;
 	uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = {0};
@@ -2684,8 +2696,10 @@ main(int argc, char **argv)
 
 	/* parse application arguments (after the EAL ones) */
 	ret = l2fwd_crypto_parse_args(&options, argc, argv);
-	if (ret < 0)
+	if (ret < 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Invalid L2FWD-CRYPTO arguments\n");
+	}
 
 	printf("MAC updating %s\n",
 			options.mac_updating ? "enabled" : "disabled");
@@ -2694,20 +2708,26 @@ main(int argc, char **argv)
 	l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 512,
 			sizeof(struct rte_crypto_op),
 			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 create mbuf pool\n");
+	}
 
 	/* create crypto op pool */
 	l2fwd_crypto_op_pool = rte_crypto_op_pool_create("crypto_op_pool",
 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MBUF, 128, MAXIMUM_IV_LENGTH,
 			rte_socket_id());
-	if (l2fwd_crypto_op_pool == NULL)
+	if (l2fwd_crypto_op_pool == NULL) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n");
+	}
 
 	/* Enable Ethernet ports */
 	enabled_portcount = initialize_ports(&options);
-	if (enabled_portcount < 1)
+	if (enabled_portcount < 1) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Failed to initial Ethernet ports\n");
+	}
 
 	/* Initialize the port/queue configuration of each logical core */
 	RTE_ETH_FOREACH_DEV(portid) {
@@ -2719,9 +2739,11 @@ main(int argc, char **argv)
 		if (options.single_lcore && qconf == NULL) {
 			while (rte_lcore_is_enabled(rx_lcore_id) == 0) {
 				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");
+				}
 			}
 		} else if (!options.single_lcore) {
 			/* get the lcore_id for this port */
@@ -2729,9 +2751,11 @@ main(int argc, char **argv)
 			       lcore_queue_conf[rx_lcore_id].nb_rx_ports ==
 			       options.nb_ports_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");
+				}
 			}
 		}
 
@@ -2748,13 +2772,17 @@ main(int argc, char **argv)
 	/* Enable Crypto devices */
 	enabled_cdevcount = initialize_cryptodevs(&options, enabled_portcount,
 			enabled_cdevs);
-	if (enabled_cdevcount < 0)
+	if (enabled_cdevcount < 0) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Failed to initialize crypto devices\n");
+	}
 
-	if (enabled_cdevcount < enabled_portcount)
+	if (enabled_cdevcount < enabled_portcount) {
+		stop_and_close_eth_dev(portid);
 		rte_exit(EXIT_FAILURE, "Number of capable crypto devices (%d) "
 				"has to be more or equal to number of ports (%d)\n",
 				enabled_cdevcount, enabled_portcount);
+	}
 
 	nb_cryptodevs = rte_cryptodev_count();
 
@@ -2769,9 +2797,11 @@ main(int argc, char **argv)
 		if (options.single_lcore && qconf == NULL) {
 			while (rte_lcore_is_enabled(rx_lcore_id) == 0) {
 				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");
+				}
 			}
 		} else if (!options.single_lcore) {
 			/* get the lcore_id for this port */
@@ -2779,9 +2809,11 @@ main(int argc, char **argv)
 			       lcore_queue_conf[rx_lcore_id].nb_crypto_devs ==
 			       options.nb_ports_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");
+				}
 			}
 		}
 
-- 
2.17.1


  parent reply	other threads:[~2020-05-19  8:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19  8:54 [dpdk-dev] [PATCH 1/5] examples/l2fwd-event: " Muhammad Bilal
2020-05-19  8:54 ` [dpdk-dev] [PATCH 2/5] examples/l2fwd-jobstats: " Muhammad Bilal
2020-05-19  8:54 ` [dpdk-dev] [PATCH 3/5] examples/l2fwd-keepalive: " Muhammad Bilal
2020-05-19  8:54 ` [dpdk-dev] [PATCH 4/5] examples/l2fwd-cat: " Muhammad Bilal
2020-05-19  8:54 ` Muhammad Bilal [this message]
2020-05-19  9:34 ` [dpdk-dev] [EXT] [PATCH 1/5] examples/l2fwd-event: " Sunil Kumar Kori
2020-06-02 12:27   ` Muhammad Bilal
2020-06-10 10:01     ` Sunil Kumar Kori
2020-06-15 12:00       ` Muhammad Bilal
2020-06-16  5:53         ` Sunil Kumar Kori
2020-06-16 10:14           ` Muhammad Bilal
2020-06-16 10:38             ` Sunil Kumar Kori
2020-06-16 11:47       ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200519085444.4562-5-m.bilal@emumba.com \
    --to=m.bilal@emumba.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=pbhagavatula@marvell.com \
    --cc=skori@marvell.com \
    --cc=tomasz.kantecki@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git