From patchwork Thu Oct 18 01:35:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47021 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0CEEE1B17C; Thu, 18 Oct 2018 03:35:48 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id E10581B101 for ; Thu, 18 Oct 2018 03:35:29 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B2CBA21DB2; Wed, 17 Oct 2018 21:35:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:28 -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=mesmtp; bh=D9Ihj3EnPt ovhk89ZPPtoi+Cda+qhiSumBUHE1u8nHo=; b=OKEhWNcsYTGjMa74kUydNcLPP6 vPjVFLeZS/lk7zyXXyQ/lYWcI8+DGUuOaFxamxVLffi+OlbJRr2NRS58s+PsbVRz qNJYOLSYKfB3tHl5fL8DOdQCjWLZpWswlzZMDWLhvPBJfeZ20rSVd1Cky0wrkH/p ED9ZfWrscByx8uQ24= 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= fm1; bh=D9Ihj3EnPtovhk89ZPPtoi+Cda+qhiSumBUHE1u8nHo=; b=dWRhBx4o jARjLk3vXEF7RJ/BpO1EDRthk5Yz+bIcJdF9I2WzpbRBT3iEWcXZ5nYrq7rUR1Lx LlUutfIf82nK9Y3ObrzAUQPhu+v6R6H0MHf+3nEIjYB+Vd1EdgKSy/A4zVCGG5UY 2n0to6xlIp8sDSsERlO+I7lYDNaaB3P6ZEfAVC41qUdKA5x0vNwrGR9xOt7Qbqdn scNSAuedg5IKlApW915HgBu+D1Fli+Kgk5Ew+Ft7turn3LqSIAyBI19YaF9xqeHR giWZhnKRPDz+a2Mvuxc572hYJxxHjaoQU8m9qtep66tqaY8Is2pTlUS5sB3bd/bY BTZA8iFr+QzrWg== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id AE1EAE4240; Wed, 17 Oct 2018 21:35:27 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:22 +0200 Message-Id: <20181018013522.11253-8-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 7/7] app/testpmd: check not detaching device twice 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" The command "port detach" is removing the EAL rte_device of the ethdev port specified as parameter. After detaching, the pointer, which maps a port to its device, is resetted. This way, it is possible to check whether a port is still associated to a (not removed) device. Signed-off-by: Thomas Monjalon --- app/test-pmd/testpmd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index f241ce363..3093d3306 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2340,8 +2340,17 @@ setup_attached_port(portid_t pi) void detach_port(portid_t port_id) { + struct rte_device *dev; + portid_t sibling; + printf("Detaching a port...\n"); + dev = rte_eth_devices[port_id].device; + if (dev == NULL) { + printf("Device already removed\n"); + return; + } + if (ports[port_id].port_status != RTE_PORT_CLOSED) { if (ports[port_id].port_status != RTE_PORT_STOPPED) { printf("Port not stopped\n"); @@ -2352,10 +2361,14 @@ detach_port(portid_t port_id) port_flow_flush(port_id); } - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) { + if (rte_dev_remove(dev) != 0) { TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id); return; } + /* reset mapping between old ports and removed device */ + for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) + if (rte_eth_devices[sibling].device == dev) + rte_eth_devices[sibling].device = NULL; remove_unused_fwd_ports();