From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9B3FAA0093; Tue, 19 May 2020 10:55:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C19431D5D8; Tue, 19 May 2020 10:55:40 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 9DD0B1D5D7 for ; Tue, 19 May 2020 10:55:39 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id f13so2180497wmc.5 for ; Tue, 19 May 2020 01:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1bJ8C63K9QfAiP6OGLhqjOW2OeIWzB2peTJe2RgkVfw=; b=KXHnZbmEZia9Rj9USgCoxKs9XnOb8WNOJy88fYXy7BiEGr8D8LiD18W0gNx2DQZin8 FatKfWHFA1NBCgnetSRdU5ERh/Rh64DmPX59RzgPqT9G0oO4U/rcD+3DSAtGCr4mxrUa K6ayeRaP9m8XWF82Uz34GTYh95dmxQV4K67uM3CrU03YN4fI+ZfzSRYdFscdbIz+j7H8 LjaDVEmRTiU8eB+re45WpY58Ow4DPML5CWavXLDVMlep8mTpGIoE5XtksF6LkRGawdC2 ZT+Y9/87zkURX9KOB20X8LOlP3Mc2t0K653OB4zj5AL/pdGLf/ESrj0Uo3jKCqMnf774 85xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1bJ8C63K9QfAiP6OGLhqjOW2OeIWzB2peTJe2RgkVfw=; b=nmTT2XWoQ29uxmkBusQqY1EwdfJNgFaV2WfsPMNrYt7k8XaXbgqfpZKeeII/TVRg7w GScvihqEBGLqPvsd8qJ/VIPBH3AanMjjpq0EkYNdFRmRUk4cW5o32s1tcakjzc2LFbg4 1ddnrUkNdCsIPquqBMerVPHzw0+z5pKIxDz6xCCxCkSIjRVX4RbsmrKi8IN6enj1byGg 5KBi3VsQCALx5Wcdb9bYKS8+pBM9+asLD13yKAtsZlhH0bXFGCAZMfLIV/de6XQ7cKsF uAxcruhIZ/fnlvmOT+P2bXveYHmuBOoESdSMTHe8+R5yqIqpqwZuLr65PyZzlubsSpNE G50w== X-Gm-Message-State: AOAM531z/99wPrp5rI1fB0NDuUdh6fYabBNb12aBwajIeA3JJdhjykLV mL+zxTjSjX71sE+j0JO/DKgzEA== X-Google-Smtp-Source: ABdhPJzICpoRmDTxoFWylNcrwWuooj8Z6ozEIBnxptQA7WTqOdycFvhzrfu3pf5uvQyfixePFE7YAQ== X-Received: by 2002:a7b:cc06:: with SMTP id f6mr4129263wmh.119.1589878539333; Tue, 19 May 2020 01:55:39 -0700 (PDT) Received: from localhost.localdomain ([111.119.188.30]) by smtp.gmail.com with ESMTPSA id i4sm15528630wrv.23.2020.05.19.01.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 01:55:38 -0700 (PDT) From: Muhammad Bilal To: declan.doherty@intel.com, tomasz.kantecki@intel.com, pbhagavatula@marvell.com, skori@marvell.com Cc: dev@dpdk.org, Muhammad Bilal Date: Tue, 19 May 2020 13:54:44 +0500 Message-Id: <20200519085444.4562-5-m.bilal@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519085444.4562-1-m.bilal@emumba.com> References: <20200519085444.4562-1-m.bilal@emumba.com> Subject: [dpdk-dev] [PATCH 5/5] examples/l2fwd-crypto: free resources in case of error X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Freeing the resources and call rte_eal_cleanup in case of error exit. Signed-off-by: Muhammad Bilal --- 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