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 DCD134F9B for ; Wed, 24 Oct 2018 15:41:21 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4101622098; Wed, 24 Oct 2018 09:41:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 24 Oct 2018 09:41:21 -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=thdhTkqKrT j5EmbPiC+bFmfk8ejMfF3sJgWytHufI9o=; b=oogakdTVaVDhmKLUlFlIw+5cFj W3U2UHDcxzboyycO1wRElpTsF3MxxqvGxSKZ8G1zZ54AkedxVFDCdxT/ne1evuGX OEprApzQwDuePYIrjMoK16XTW90CLZuhNgWCIb1+RgCXCYyN4xiviWx12ydxN7mI 5iQg8hsthcROziK6U= 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=thdhTkqKrTj5EmbPiC+bFmfk8ejMfF3sJgWytHufI9o=; b=gcAWw7D0 8dmtZ2tb5FNuIO48gvVan4IW71m7DJZFHPVLF/jd8wnC1GkPmH6nUjrimiXnS9FL lSf+TdGiV3G+CkT1zstopmHBlCpGyQX1UerIHEVwTh8gFxR95pmhSTsd2tYvXZGR IvXCMccPianOkifo25jewkMaPIY9q7XP5XBk0V9TQjLKisz8EPk2+d7YwQ22WTVm rTDvK0Yjc53D5VAqhfz2mpvEaGkEHKCtv3YvpsBhWiVVyBbk/5SizQnNGaLOU2xO O8qDaA+JFuwYPVVEaqzb+k2irww7nTmG4cS9qi6wjog5sPWATxYPEZkyjd8wJzNE pTJKDoPBeMKrJg== 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 C677FE4122; Wed, 24 Oct 2018 09:41:19 -0400 (EDT) From: Thomas Monjalon To: bernard.iremonger@intel.com, jingjing.wu@intel.com, wenzhuo.lu@intel.com Cc: dev@dpdk.org, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Wed, 24 Oct 2018 15:41:07 +0200 Message-Id: <20181024134111.26771-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181024134111.26771-1-thomas@monjalon.net> References: <20181024134111.26771-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/5] 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: Wed, 24 Oct 2018 13:41:22 -0000 The command "port detach" is removing the EAL rte_device of the ethdev port specified as parameter. The function name and some comments are updated to make clear that we are detaching the whole device. After detaching, the pointer, which maps a port to its device, is reset. 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/cmdline.c | 2 +- app/test-pmd/testpmd.c | 35 ++++++++++++++++++++++++++++------- app/test-pmd/testpmd.h | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 3b469ac64..f041a01aa 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -1305,7 +1305,7 @@ static void cmd_operate_detach_port_parsed(void *parsed_result, struct cmd_operate_detach_port_result *res = parsed_result; if (!strcmp(res->keyword, "detach")) - detach_port(res->port_id); + detach_port_device(res->port_id); else printf("Unknown parameter\n"); } diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 14647fa19..56e408cdf 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2351,10 +2351,19 @@ setup_attached_port(portid_t pi) } void -detach_port(portid_t port_id) +detach_port_device(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,27 @@ detach_port(portid_t port_id) port_flow_flush(port_id); } - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) { - TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id); + if (rte_dev_remove(dev) != 0) { + TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name); return; } + for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) { + if (rte_eth_devices[sibling].device != dev) + continue; + /* reset mapping between old ports and removed device */ + rte_eth_devices[sibling].device = NULL; + if (ports[sibling].port_status != RTE_PORT_CLOSED) { + /* sibling ports are forced to be 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("Device of port %u is detached\n", port_id); + printf("Now total ports is %d\n", nb_ports); printf("Done\n"); return; } @@ -2406,7 +2427,7 @@ pmd_test_exit(void) */ device = rte_eth_devices[pt_id].device; if (device && !strcmp(device->driver->name, "net_virtio_user")) - detach_port(pt_id); + detach_port_device(pt_id); } } @@ -2518,7 +2539,7 @@ rmv_event_callback(void *arg) stop_port(port_id); no_link_check = org_no_link_check; close_port(port_id); - detach_port(port_id); + detach_port_device(port_id); if (need_to_start) start_packet_forwarding(0); } diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 3da728cad..646e44940 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -712,7 +712,7 @@ void stop_port(portid_t pid); void close_port(portid_t pid); void reset_port(portid_t pid); void attach_port(char *identifier); -void detach_port(portid_t port_id); +void detach_port_device(portid_t port_id); int all_ports_stopped(void); int port_is_stopped(portid_t port_id); int port_is_started(portid_t port_id); -- 2.19.0