[v3,1/6] rte_ethdev: change rte_eth_dev_owner_get to return error if unowned
diff mbox series

Message ID 20200402171953.13356-2-stephen@networkplumber.org
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers show
Series
  • checking for owned ports in portmask
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger April 2, 2020, 5:19 p.m. UTC
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(-)

Comments

Ferruh Yigit April 10, 2020, 3:45 p.m. UTC | #1
On 4/2/2020 6:19 PM, Stephen Hemminger wrote:
> 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>

<...>

> @@ -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.

Not sure if port not having an owner is error, I understand the motivation but
what about send a special value, like 1, instead of error:
0: get owner success, port owned
1: get owner success, port not owned
-ENODEV: get owner failed, port_id is not valid

Patch
diff mbox series

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,