From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id E6F36558D for ; Fri, 22 Jul 2016 15:44:08 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 22 Jul 2016 06:44:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,405,1464678000"; d="scan'208";a="1027116314" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 22 Jul 2016 06:44:07 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u6MDi6MU001796; Fri, 22 Jul 2016 14:44:06 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id u6MDi6s3019056; Fri, 22 Jul 2016 14:44:06 +0100 Received: (from reshmapa@localhost) by sivswdev02.ir.intel.com with id u6MDi6lf019052; Fri, 22 Jul 2016 14:44:06 +0100 From: Reshma Pattan To: dev@dpdk.org Cc: Reshma Pattan Date: Fri, 22 Jul 2016 14:44:04 +0100 Message-Id: <1469195044-19018-1-git-send-email-reshma.pattan@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] app/pdump: cleanup rte rings upon failures X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2016 13:44:09 -0000 Function create_mp_ring_vdev() for failure cases exits without freeing the created rte rings, because of this pdump tool cannot be rerun successfully. Added rte ring cleanup logic upon failures. Fixes: caa7028276b8 ("app/pdump: add tool for packet capturing") Signed-off-by: Reshma Pattan --- app/pdump/main.c | 67 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/app/pdump/main.c b/app/pdump/main.c index e0ff8be..b76cfd0 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -525,6 +525,26 @@ free_ring_data(struct rte_ring *ring, uint8_t vdev_id, } static void +cleanup_rings(void) +{ + int i; + struct pdump_tuples *pt; + + for (i = 0; i < num_tuples; i++) { + pt = &pdump_t[i]; + + if (pt->device_id) + free(pt->device_id); + + /* free the rings */ + if (pt->rx_ring) + rte_ring_free(pt->rx_ring); + if (pt->tx_ring) + rte_ring_free(pt->tx_ring); + } +} + +static void cleanup_pdump_resources(void) { int i; @@ -545,16 +565,8 @@ cleanup_pdump_resources(void) free_ring_data(pt->rx_ring, pt->rx_vdev_id, &pt->stats); if (pt->dir & RTE_PDUMP_FLAG_TX) free_ring_data(pt->tx_ring, pt->tx_vdev_id, &pt->stats); - - if (pt->device_id) - free(pt->device_id); - - /* free the rings */ - if (pt->rx_ring) - rte_ring_free(pt->rx_ring); - if (pt->tx_ring) - rte_ring_free(pt->tx_ring); } + cleanup_rings(); } static void @@ -630,10 +642,12 @@ create_mp_ring_vdev(void) MBUF_POOL_CACHE_SIZE, 0, pt->mbuf_data_size, rte_socket_id()); - if (mbuf_pool == NULL) + if (mbuf_pool == NULL) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "Mempool creation failed: %s\n", rte_strerror(rte_errno)); + } } pt->mp = mbuf_pool; @@ -643,19 +657,23 @@ create_mp_ring_vdev(void) snprintf(ring_name, SIZE, RX_RING, i); pt->rx_ring = rte_ring_create(ring_name, pt->ring_size, rte_socket_id(), 0); - if (pt->rx_ring == NULL) + if (pt->rx_ring == NULL) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "%s:%s:%d\n", rte_strerror(rte_errno), __func__, __LINE__); + } /* create tx_ring */ snprintf(ring_name, SIZE, TX_RING, i); pt->tx_ring = rte_ring_create(ring_name, pt->ring_size, rte_socket_id(), 0); - if (pt->tx_ring == NULL) + if (pt->tx_ring == NULL) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "%s:%s:%d\n", rte_strerror(rte_errno), __func__, __LINE__); + } /* create vdevs */ (pt->rx_vdev_stream_type == IFACE) ? @@ -663,10 +681,12 @@ create_mp_ring_vdev(void) pt->rx_dev) : snprintf(vdev_args, SIZE, VDEV_PCAP, RX_STR, i, pt->rx_dev); - if (rte_eth_dev_attach(vdev_args, &portid) < 0) + if (rte_eth_dev_attach(vdev_args, &portid) < 0) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "vdev creation failed:%s:%d\n", __func__, __LINE__); + } pt->rx_vdev_id = portid; /* configure vdev */ @@ -680,10 +700,13 @@ create_mp_ring_vdev(void) pt->tx_dev) : snprintf(vdev_args, SIZE, VDEV_PCAP, TX_STR, i, pt->tx_dev); - if (rte_eth_dev_attach(vdev_args, &portid) < 0) + if (rte_eth_dev_attach(vdev_args, + &portid) < 0) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "vdev creation failed:" "%s:%d\n", __func__, __LINE__); + } pt->tx_vdev_id = portid; /* configure vdev */ @@ -695,19 +718,23 @@ create_mp_ring_vdev(void) snprintf(ring_name, SIZE, RX_RING, i); pt->rx_ring = rte_ring_create(ring_name, pt->ring_size, rte_socket_id(), 0); - if (pt->rx_ring == NULL) + if (pt->rx_ring == NULL) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } (pt->rx_vdev_stream_type == IFACE) ? snprintf(vdev_args, SIZE, VDEV_IFACE, RX_STR, i, pt->rx_dev) : snprintf(vdev_args, SIZE, VDEV_PCAP, RX_STR, i, pt->rx_dev); - if (rte_eth_dev_attach(vdev_args, &portid) < 0) + if (rte_eth_dev_attach(vdev_args, &portid) < 0) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "vdev creation failed:%s:%d\n", __func__, __LINE__); + } pt->rx_vdev_id = portid; /* configure vdev */ configure_vdev(pt->rx_vdev_id); @@ -717,18 +744,22 @@ create_mp_ring_vdev(void) snprintf(ring_name, SIZE, TX_RING, i); pt->tx_ring = rte_ring_create(ring_name, pt->ring_size, rte_socket_id(), 0); - if (pt->tx_ring == NULL) + if (pt->tx_ring == NULL) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno)); + } (pt->tx_vdev_stream_type == IFACE) ? snprintf(vdev_args, SIZE, VDEV_IFACE, TX_STR, i, pt->tx_dev) : snprintf(vdev_args, SIZE, VDEV_PCAP, TX_STR, i, pt->tx_dev); - if (rte_eth_dev_attach(vdev_args, &portid) < 0) + if (rte_eth_dev_attach(vdev_args, &portid) < 0) { + cleanup_rings(); rte_exit(EXIT_FAILURE, "vdev creation failed\n"); + } pt->tx_vdev_id = portid; /* configure vdev */ -- 2.5.0