DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH v3 1/6] rte_ethdev: change rte_eth_dev_owner_get to return error if unowned
Date: Thu,  2 Apr 2020 10:19:48 -0700	[thread overview]
Message-ID: <20200402171953.13356-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20200402171953.13356-1-stephen@networkplumber.org>

For applications that want to check if device is owned,
change the return value of rte_eth_dev_owner_get to return -ENOENT
if there is no owner for the device.

Change the two drivers (failsafe and netvsc) that are using
this experimental API to handle the new return value.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/failsafe/failsafe_eal.c |  4 ++--
 drivers/net/netvsc/hn_vf.c          | 11 +++++------
 lib/librte_ethdev/rte_ethdev.c      |  4 +++-
 lib/librte_ethdev/rte_ethdev.h      |  6 ++++--
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index b9fc508673f2..8a1b5e068840 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -63,8 +63,8 @@ fs_bus_init(struct rte_eth_dev *dev)
 			 * The NEW callback tried to take ownership, check
 			 * whether it succeed or didn't.
 			 */
-			rte_eth_dev_owner_get(pid, &pid_owner);
-			if (pid_owner.id != PRIV(dev)->my_owner.id) {
+			if (rte_eth_dev_owner_get(pid, &pid_owner) == 0 &&
+			    pid_owner.id != PRIV(dev)->my_owner.id) {
 				INFO("sub_device %d owner(%s_%016"PRIX64") is not my,"
 				     " owner(%s_%016"PRIX64"), will try again later",
 				     i, pid_owner.name, pid_owner.id,
diff --git a/drivers/net/netvsc/hn_vf.c b/drivers/net/netvsc/hn_vf.c
index 7a3734cadfa4..b56f60b28a62 100644
--- a/drivers/net/netvsc/hn_vf.c
+++ b/drivers/net/netvsc/hn_vf.c
@@ -63,16 +63,15 @@ static int hn_vf_attach(struct hn_data *hv, uint16_t port_id)
 	}
 
 	ret = rte_eth_dev_owner_get(port_id, &owner);
-	if (ret < 0) {
-		PMD_DRV_LOG(ERR, "Can not find owner for port %d", port_id);
-		return ret;
-	}
-
-	if (owner.id != RTE_ETH_DEV_NO_OWNER) {
+	if (ret == 0) {
 		PMD_DRV_LOG(ERR, "Port %u already owned by other device %s",
 			    port_id, owner.name);
 		return -EBUSY;
 	}
+	if (ret != -ENOENT) {
+		PMD_DRV_LOG(ERR, "Can not find owner for port %d", port_id);
+		return ret;
+	}
 
 	ret = rte_eth_dev_owner_set(port_id, &hv->owner);
 	if (ret < 0) {
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 0854ef883270..0c4645cf9832 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -729,7 +729,9 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
 		RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n",
 			port_id);
 		ret = -ENODEV;
-	} else {
+	} else if (ethdev->data->owner.id == RTE_ETH_DEV_NO_OWNER) {
+		ret = -ENOENT;
+	} else if (owner != NULL) {
 		rte_memcpy(owner, &ethdev->data->owner, sizeof(*owner));
 	}
 
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index d1a593ad112a..0e59d39de54c 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -1685,9 +1685,11 @@ int rte_eth_dev_owner_delete(const uint64_t owner_id);
  * @param	port_id
  *  The port identifier.
  * @param	owner
- *  The owner structure pointer to fill.
+ *  The owner structure pointer to fill (optional can be NULL)
  * @return
- *  0 on success, negative errno value on error..
+ *  0 on success,
+ *  -ENODEV if port_id is not valid
+ *  -ENOENT if the device is ownerless.
  */
 __rte_experimental
 int rte_eth_dev_owner_get(const uint16_t port_id,
-- 
2.20.1


  reply	other threads:[~2020-04-02 17:20 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 17:20 [dpdk-dev] [PATCH 0/7] checking for owned ports in portmask Stephen Hemminger
2020-03-12 17:20 ` [dpdk-dev] [PATCH 1/7] ethdev: add function to test port ownership Stephen Hemminger
2020-03-15  7:45   ` Matan Azrad
2020-03-12 17:20 ` [dpdk-dev] [PATCH 2/7] examples/l2fwd-cat: block attempts to use owned ports Stephen Hemminger
2020-03-15  7:51   ` Matan Azrad
2020-03-12 17:20 ` [dpdk-dev] [PATCH 3/7] examples/l3fwd: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-dev] [PATCH 4/7] examples/l3fwd-acl: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-dev] [PATCH 5/7] examples/l3fwd-power: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-dev] [PATCH 6/7] examples/tep_termination: " Stephen Hemminger
2020-03-12 17:20 ` [dpdk-dev] [PATCH 7/7] examples/vhost: " Stephen Hemminger
2020-03-16 16:09 ` [dpdk-dev] [PATCH v2 0/6] check for owned ports in portmask Stephen Hemminger
2020-03-16 16:09   ` [dpdk-dev] [PATCH v2 1/6] rte_ethdev: add function to check if device is owned Stephen Hemminger
2020-04-01 21:42     ` Thomas Monjalon
2020-04-01 22:24       ` Stephen Hemminger
2020-04-02  8:04         ` Thomas Monjalon
2020-03-16 16:09   ` [dpdk-dev] [PATCH v2 2/6] examples/l2fwd-cat: block attempts to use owned ports Stephen Hemminger
2020-03-16 16:09   ` [dpdk-dev] [PATCH v2 3/6] examples/l3fwd: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-dev] [PATCH v2 4/6] examples/l3fwd-acl: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-dev] [PATCH v2 5/6] examples/l3fwd-power: " Stephen Hemminger
2020-03-16 16:09   ` [dpdk-dev] [PATCH v2 6/6] examples/tep_termination: " Stephen Hemminger
2020-03-17  8:18   ` [dpdk-dev] [PATCH v2 0/6] check for owned ports in portmask Matan Azrad
2020-04-02 17:19 ` [dpdk-dev] [PATCH v3 0/6] checking " Stephen Hemminger
2020-04-02 17:19   ` Stephen Hemminger [this message]
2020-04-10 15:45     ` [dpdk-dev] [PATCH v3 1/6] rte_ethdev: change rte_eth_dev_owner_get to return error if unowned Ferruh Yigit
2020-04-02 17:19   ` [dpdk-dev] [PATCH v3 2/6] examples/l2fwd-cat: make applicaton aware of port ownership Stephen Hemminger
2020-04-10 15:47     ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2020-04-02 17:19   ` [dpdk-dev] [PATCH v3 3/6] examples/l3fwd: " Stephen Hemminger
2020-04-02 17:19   ` [dpdk-dev] [PATCH v3 4/6] examples/l3fwd-acl: " Stephen Hemminger
2020-04-02 17:19   ` [dpdk-dev] [PATCH v3 5/6] examples/l3fwd-power: " Stephen Hemminger
2020-04-02 17:19   ` [dpdk-dev] [PATCH v3 6/6] examples/tep_termination: rework the port setup logic Stephen Hemminger
2020-04-10 16:16     ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200402171953.13356-2-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).