[v3,1/6] rte_ethdev: change rte_eth_dev_owner_get to return error if unowned
Checks
Commit Message
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
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
@@ -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,
@@ -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) {
@@ -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, ðdev->data->owner, sizeof(*owner));
}
@@ -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,