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 B19E05B2C for ; Mon, 22 Oct 2018 14:31:50 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5AEF021F01; Mon, 22 Oct 2018 08:31:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 22 Oct 2018 08:31:50 -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=UeTBHGtjwC boGKNN3DW86cznNE7qzb+6XybmJPwjZ+k=; b=LZzHXg2PNp6DIH8B7T0atYKOeD ukU1eK1KR5vclnjAcya5Kg9wpSkEFA6ZN4V4KwFKYd8tTZef9rtDPYGubPA4rFGE TC85VjfpPZ3moUjlyqOjZvdx5o+laQ3nYb6jrCP5aX5gZE2rLF8FI7QC9+/7Kzic bGb8gZzn7BsjKjsx8= 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=UeTBHGtjwCboGKNN3DW86cznNE7qzb+6XybmJPwjZ+k=; b=qA3achpn yafTPf6dmtjx64J1DYpvIcdJtOMaMUDTUVDN7KPjKMYd4cPcmy4SNo/URWJpr9Sj jiIudsqUXRp1r3Pu6RL9NWXEosNOewu8AFTPvbv+lp8M6jF0np2k0KNbIX2ETb0x I87JTm0e8+GrHts9MXaX1U85jxBWwrc7LGVo8t8+VeUQs4x9/dWRKHQYlFVcm6Fu E+LdBBePAFUMESAouRkjBLT5PcdDqGt/B3aR9cITMgdVCK+zZvHGIez5yZrjmUK4 gL10zKpnynDeQoNizXulWjD5t+kjaTZSp+Jm4gYdQl9M1KVsejNVLGyS+zj53v37 TdQPBj9Msb/oPg== 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 EA9F1E405D; Mon, 22 Oct 2018 08:31:45 -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: Mon, 22 Oct 2018 14:31:10 +0200 Message-Id: <20181022123110.5733-8-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181022123110.5733-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181022123110.5733-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 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: Mon, 22 Oct 2018 12:31:51 -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 | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 14647fa19..2a357affc 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,25 @@ 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 (%s) is closed\n", sibling, + rte_eth_devices[sibling].data->name); + } + } + 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