From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 95EFA1B3B1 for ; Tue, 23 Oct 2018 10:28:58 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 3367E22000; Tue, 23 Oct 2018 04:28:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 23 Oct 2018 04:28:58 -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=LZJzd0xPnR VaA00mGlsJfdHlcSjxu2rwBrag/QHHYVw=; b=iumgPkIEzk3jN4qWWGKiyExW+6 Uk5+KRT7TVrn/j9ozd/ICK8igOdMKeuwDQk4QvfuJv1cNINtKQb6RX6B+SGgr7CP sVzmHY5o3y4sGDDv6QcFr3pZSJF5znEczojpu0DOWdGbxBg8MmATvL/31lN3k9df G2luRSqrZEZ93XYUM= 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=LZJzd0xPnRVaA00mGlsJfdHlcSjxu2rwBrag/QHHYVw=; b=dWIMC7TQ YRU1/MRKCNVF1jTnj+yQUdy95lTKjMhELuuosS79JwjHeP7j5aVS81Xkb8Z8+d7x x+ZEa9MJTQ6q2qorUb35zzmL0yP33Iv7eeZ4pO8sein8nAO99A6yug5FRVDjm0fv L2vQo0ErykAzToSNdg5MPMhY+Ac5te+nnG3LAk3Gw+xMxaii8mLTNADafrEPo0Zl rQztfiB6jCBBqRAsroVIh1S2Mx1agEsg1g5WuW7WNS2f2vbr+6YRqAng2dK/RKha pNcwPEfHQa2iiy3gz65WKO8cD6xlZtwwBoK1FMGPzqWZcp58gTUlQb1eMvTieqw3 ih9oLo6ybdBYQQ== 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 0899CE4A3F; Tue, 23 Oct 2018 04:28:56 -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, bernard.iremonger@intel.com Date: Tue, 23 Oct 2018 10:28:42 +0200 Message-Id: <20181023082842.7963-8-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181023082842.7963-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181023082842.7963-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v7 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: , X-List-Received-Date: Tue, 23 Oct 2018 08:28:59 -0000 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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 14647fa19..d5998fddc 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void detach_port(portid_t port_id) { + struct rte_device *dev; + portid_t sibling; + printf("Removing a device...\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"); @@ -2365,15 +2374,24 @@ 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; + if (ports[sibling].port_status != RTE_PORT_CLOSED) { + ports[sibling].port_status = RTE_PORT_CLOSED; + printf("Port %u is closed\n", sibling); + } + } + remove_unused_fwd_ports(); - printf("Port %u is detached. Now total ports is %d\n", - port_id, nb_ports); + printf("Now total ports is %d\n", nb_ports); printf("Done\n"); return; } -- 2.19.0