From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 830314BE1 for ; Fri, 9 Jun 2017 20:36:15 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jun 2017 11:36:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,319,1493708400"; d="scan'208";a="1180496608" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by fmsmga002.fm.intel.com with ESMTP; 09 Jun 2017 11:36:13 -0700 From: Ferruh Yigit To: Thomas Monjalon Cc: dev@dpdk.org, Ferruh Yigit , Gaetan Rivet , Jan Blunck Date: Fri, 9 Jun 2017 19:36:06 +0100 Message-Id: <20170609183606.34596-3-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170609183606.34596-1-ferruh.yigit@intel.com> References: <20170526161141.4746-1-ferruh.yigit@intel.com> <20170609183606.34596-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v2 3/3] ethdev: use device name from device structure 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: Fri, 09 Jun 2017 18:36:16 -0000 Device name resides in two different locations, in rte_device->name and in ethernet device private data. For now, the copy in the ethernet device private data is required for multi process support, the name is the how secondary process finds about primary process device. But in the ethdev library some eth_dev->data->name usage can be converted to rte_device->name. This patch updates ethdev to use rte_device->name when possible. Signed-off-by: Ferruh Yigit --- Cc: Gaetan Rivet Cc: Jan Blunck --- lib/librte_ether/rte_ethdev.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index d257406..1cbe9b9 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -178,9 +178,11 @@ rte_eth_dev_allocated(const char *name) unsigned i; for (i = 0; i < RTE_MAX_ETHPORTS; i++) { - if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) && - strcmp(rte_eth_devices[i].data->name, name) == 0) - return &rte_eth_devices[i]; + if (rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED && + rte_eth_devices[i].device) { + if (!strcmp(rte_eth_devices[i].device->name, name)) + return &rte_eth_devices[i]; + } } return NULL; } @@ -310,7 +312,7 @@ rte_eth_dev_count(void) int rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) { - char *tmp; + const char *tmp; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); @@ -321,7 +323,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) /* shouldn't check 'rte_eth_devices[i].data', * because it might be overwritten by VDEV PMD */ - tmp = rte_eth_dev_data[port_id].name; + tmp = rte_eth_devices[port_id].device->name; strcpy(name, tmp); return 0; } @@ -329,6 +331,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) int rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) { + int ret; int i; if (name == NULL) { @@ -341,11 +344,14 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) *port_id = RTE_MAX_ETHPORTS; RTE_ETH_FOREACH_DEV(i) { - if (!strncmp(name, - rte_eth_dev_data[i].name, strlen(name))) { + if (!rte_eth_devices[i].device) + continue; - *port_id = i; + ret = strncmp(name, rte_eth_devices[i].device->name, + strlen(name)); + if (!ret) { + *port_id = i; return 0; } } @@ -438,8 +444,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name) if (rte_eth_dev_is_detachable(port_id)) goto err; - snprintf(name, sizeof(rte_eth_devices[port_id].data->name), - "%s", rte_eth_devices[port_id].data->name); + snprintf(name, sizeof(rte_eth_devices[port_id].device->name), + "%s", rte_eth_devices[port_id].device->name); ret = rte_eal_dev_detach(name); if (ret < 0) goto err; -- 2.9.4