| 469 | } |
| 470 | |
| 471 | static int |
| 472 | eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, |
| 473 | const struct rte_eth_dev_owner *new_owner) |
| 474 | __rte_exclusive_locks_required(rte_mcfg_ethdev_get_lock()) |
| 475 | { |
| 476 | struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; |
| 477 | struct rte_eth_dev_owner *port_owner; |
| 478 | |
| 479 | if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) { |
| 480 | RTE_ETHDEV_LOG(ERR, "Port ID %"PRIu16" is not allocated\n", |
| 481 | port_id); |
| 482 | return -ENODEV; |
| 483 | } |
| 484 | |
| 485 | if (new_owner == NULL) { |
| 486 | RTE_ETHDEV_LOG(ERR, |
| 487 | "Cannot set ethdev port %u owner from NULL owner\n", |
| 488 | port_id); |
| 489 | return -EINVAL; |
| 490 | } |
| 491 | |
| 492 | if (!eth_is_valid_owner_id(new_owner->id) && |
| 493 | !eth_is_valid_owner_id(old_owner_id)) { |
| 494 | RTE_ETHDEV_LOG(ERR, |
| 495 | "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64"\n", |
| 496 | old_owner_id, new_owner->id); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
| 500 | port_owner = &rte_eth_devices[port_id].data->owner; |
| 501 | if (port_owner->id != old_owner_id) { |
| 502 | RTE_ETHDEV_LOG(ERR, |
| 503 | "Cannot set owner to port %u already owned by %s_%016"PRIX64"\n", |
| 504 | port_id, port_owner->name, port_owner->id); |
| 505 | return -EPERM; |
| 506 | } |
| 507 | |
| 508 | /* can not truncate (same structure) */ |
| 509 | strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN); |
| 510 | |
| 511 | port_owner->id = new_owner->id; |
| 512 | |
| 513 | RTE_ETHDEV_LOG(DEBUG, "Port %u owner is %s_%016"PRIx64"\n", |
| 514 | port_id, new_owner->name, new_owner->id); |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | int |
| 520 | rte_eth_dev_owner_set(const uint16_t port_id, |
no test coverage detected