From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 99E33A04C0;
	Tue, 29 Sep 2020 01:17:11 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 1DA6F1D90D;
	Tue, 29 Sep 2020 01:15:20 +0200 (CEST)
Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com
 [66.111.4.26]) by dpdk.org (Postfix) with ESMTP id 0BD511D8D1
 for <dev@dpdk.org>; Tue, 29 Sep 2020 01:15:05 +0200 (CEST)
Received: from compute7.internal (compute7.nyi.internal [10.202.2.47])
 by mailout.nyi.internal (Postfix) with ESMTP id A8DE25C01B0;
 Mon, 28 Sep 2020 19:15:04 -0400 (EDT)
Received: from mailfrontend2 ([10.202.2.163])
 by compute7.internal (MEProxy); Mon, 28 Sep 2020 19:15:04 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 from:to:cc:subject:date:message-id:in-reply-to:references
 :mime-version:content-transfer-encoding; s=fm2; bh=eNXQ7yZTlH3MT
 yqjxIWINnIQIuF9l8QoOQ4Jo3eLaCU=; b=jCFMp4M+MAsCRsZLnj5ZE8UF8crMH
 Dxa32bEKKMEx+J93XYHdu1TL+8yqPGfO6DER0gRoV22Mmea03+T7AtYeM2dl9sRM
 751seo9liKRJ8e7QfF1HcbGVV/P97ilW+iyvGhqQnIEGGGdAO2IC2LApBS5tMIbQ
 fMOHoIQmKKxKNhZpxmwtd02ObtX0QgelPERUF3P+7Wis0JsAGHpRMZSGd0h/YgYG
 ayUEEDKqICo/7BvedF5ZapPVzJafTmA4Z6x5159Sw//Uu3/0ZN8K1l9OvfoLUKKn
 Rz4Bbuf+QLgcRduCAjKUPpFgbq3JZz7+qagpxSltNkDAr9rnrzC630LwA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:date:from
 :in-reply-to:message-id:mime-version:references:subject:to
 :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
 fm3; bh=eNXQ7yZTlH3MTyqjxIWINnIQIuF9l8QoOQ4Jo3eLaCU=; b=uKg4eT1+
 h8q1Au6ZKpQoHYv8Q/7Ihor5QJxy1+sCf88XF8zCiOPj9+tKKEoQ1lpbPuIefqcP
 s7QijW4KSpetKZszKHzfopFVgeYOwEXg7VhFJv9pLGrmzQgQQlQmrfN9+yXbsNB3
 ZK3pZohLus1u31Tw/HDcSqjbYT2MNeZluvzbMrbCaDUUdOwCW39EuhbCTT1xajv4
 bpULI8XuLoEgVag97WIyVu5Kosuq8pL13w5zYtOTxTgceMTNZbGzYUtPiNt9s3Ig
 ZtMatcGhK3/yz5pXG5mz13HbtDZ7pH9Jv8HXnsvlNPEUfkRR4ljQEh0uvVxqSma3
 1DkB59XcTU/OuA==
X-ME-Sender: <xms:eG5yXytyKOXosEdT6mbFUEcmnkcBvpUxrUfzhG4A8yyxQa4vr-bWZw>
 <xme:eG5yX3daZbpJTyJYpGkd2tWBzmOtpu10jCF4YBB2DJ7vWQ5l9Idl1IoWIOqQ0qW6R
 aetRTsEx8TxTaCQrw>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdejgddulecutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
 uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc
 fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs
 ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucggtf
 frrghtthgvrhhnpedvhefgiedvjeegtdevheefhfetleefgfeivefgffevfeejgedtgfeu
 tdehtdegveenucfkphepjeejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrhfuih
 iivgepkeenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhho
 nhdrnhgvth
X-ME-Proxy: <xmx:eG5yX9zGgvsKfxt-79UVHfOUAUIok9CHDD2Tw2Fkd6yvdXLfXhUyBA>
 <xmx:eG5yX9O_C_UTRaJM8q03409lQaeoKQvc6P4uqzEGKu4OMwnHXyiTxg>
 <xmx:eG5yXy8DIPGU__qsHDe2gX2VpDmOAhpccp9yaGMDhiR4FkahK2bvXQ>
 <xmx:eG5yX5aMU8_EbOmhpJiyW5eicMIDLdhRM1aFlrXVKsSa-GO5wphCNw>
Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184])
 by mail.messagingengine.com (Postfix) with ESMTPA id A1A4C3064684;
 Mon, 28 Sep 2020 19:15:03 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, arybchenko@solarflare.com,
 Chas Williams <chas3@att.com>, "Wei Hu (Xavier)" <xavier.huwei@huawei.com>,
 Anatoly Burakov <anatoly.burakov@intel.com>
Date: Tue, 29 Sep 2020 01:14:15 +0200
Message-Id: <20200928231437.414489-8-thomas@monjalon.net>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20200928231437.414489-1-thomas@monjalon.net>
References: <20200913220711.3768597-1-thomas@monjalon.net>
 <20200928231437.414489-1-thomas@monjalon.net>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v3 07/29] net/bonding: release port upon close
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

The flag RTE_ETH_DEV_CLOSE_REMOVE is set so all port resources
can be freed by rte_eth_dev_close().

Freeing of private port resources is moved
from the ".remove(device)" to the ".dev_close(port)" operation.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 34 ++++++++++++--------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index dff835ef92..a9ed5d8e12 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2103,6 +2103,9 @@ bond_ethdev_close(struct rte_eth_dev *dev)
 	int skipped = 0;
 	struct rte_flow_error ferror;
 
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
 	RTE_BOND_LOG(INFO, "Closing bonded device %s", dev->device->name);
 	while (internals->slave_count != skipped) {
 		uint16_t port_id = internals->slaves[skipped].port_id;
@@ -2119,6 +2122,17 @@ bond_ethdev_close(struct rte_eth_dev *dev)
 	bond_flow_ops.flush(dev, &ferror);
 	bond_ethdev_free_queues(dev);
 	rte_bitmap_reset(internals->vlan_filter_bmp);
+	rte_bitmap_free(internals->vlan_filter_bmp);
+	rte_free(internals->vlan_filter_bmpmem);
+
+	/* Try to release mempool used in mode6. If the bond
+	 * device is not mode6, free the NULL is not problem.
+	 */
+	rte_mempool_free(internals->mode6.mempool);
+
+	dev->dev_ops = NULL;
+	dev->rx_pkt_burst = NULL;
+	dev->tx_pkt_burst = NULL;
 
 	return 0;
 }
@@ -3195,6 +3209,7 @@ bond_alloc(struct rte_vdev_device *dev, uint8_t mode)
 	}
 
 	internals = eth_dev->data->dev_private;
+	eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
 	eth_dev->data->nb_rx_queues = (uint16_t)1;
 	eth_dev->data->nb_tx_queues = (uint16_t)1;
 
@@ -3414,14 +3429,10 @@ bond_remove(struct rte_vdev_device *dev)
 	name = rte_vdev_device_name(dev);
 	RTE_BOND_LOG(INFO, "Uninitializing pmd_bond for %s", name);
 
-	/* now free all data allocation - for eth_dev structure,
-	 * dummy pci driver and internal (private) data
-	 */
-
 	/* find an ethdev entry */
 	eth_dev = rte_eth_dev_allocated(name);
 	if (eth_dev == NULL)
-		return -ENODEV;
+		return 0; /* port already released */
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return rte_eth_dev_release_port(eth_dev);
@@ -3436,19 +3447,6 @@ bond_remove(struct rte_vdev_device *dev)
 		bond_ethdev_stop(eth_dev);
 		bond_ethdev_close(eth_dev);
 	}
-
-	eth_dev->dev_ops = NULL;
-	eth_dev->rx_pkt_burst = NULL;
-	eth_dev->tx_pkt_burst = NULL;
-
-	internals = eth_dev->data->dev_private;
-	/* Try to release mempool used in mode6. If the bond
-	 * device is not mode6, free the NULL is not problem.
-	 */
-	rte_mempool_free(internals->mode6.mempool);
-	rte_bitmap_free(internals->vlan_filter_bmp);
-	rte_free(internals->vlan_filter_bmpmem);
-
 	rte_eth_dev_release_port(eth_dev);
 
 	return 0;
-- 
2.28.0