[ovs-dev] [RFC dpdk-latest 2/2] netdev-dpdk: Replace rte_eth_dev_attach/detach.

Kevin Traynor ktraynor at redhat.com
Fri Nov 9 20:07:32 UTC 2018


On 11/09/2018 11:57 AM, Ilya Maximets wrote:
> On 08.11.2018 21:36, Kevin Traynor wrote:
>> rte_eth_dev_attach/detach have been removed from
>> DPDK 18.11. Replace them with rte_dev_probe/remove.
>>
>> Signed-off-by: Kevin Traynor <ktraynor at redhat.com>
>> ---
>>  lib/netdev-dpdk.c | 29 +++++++++++++++++------------
>>  1 file changed, 17 insertions(+), 12 deletions(-)
>>
>> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
>> index 10c4879a1..190d50007 100644
>> --- a/lib/netdev-dpdk.c
>> +++ b/lib/netdev-dpdk.c
>> @@ -1351,5 +1351,5 @@ netdev_dpdk_destruct(struct netdev *netdev)
>>  {
>>      struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
>> -    char devname[RTE_ETH_NAME_MAX_LEN];
>> +    struct rte_eth_dev_info dev_info;
>>  
>>      ovs_mutex_lock(&dpdk_mutex);
>> @@ -1360,8 +1360,9 @@ netdev_dpdk_destruct(struct netdev *netdev)
>>      if (dev->attached) {
>>          rte_eth_dev_close(dev->port_id);
>> -        if (rte_eth_dev_detach(dev->port_id, devname) < 0) {
>> +        rte_eth_dev_info_get(dev->port_id, &dev_info);
>> +        if (dev_info.device && !rte_dev_remove(dev_info.device)) {
>> +            VLOG_INFO("Device '%s' has been detached", dev->devargs);
>> +        } else {
>>              VLOG_ERR("Device '%s' can not be detached", dev->devargs);
>> -        } else {
>> -            VLOG_INFO("Device '%s' has been detached", devname);
>>          }
>>      }
>> @@ -1645,5 +1646,5 @@ netdev_dpdk_process_devargs(struct netdev_dpdk *dev,
>>      char *name;
>>      dpdk_port_t new_port_id = DPDK_ETH_PORT_ID_INVALID;
>> -
>> +    struct rte_dev_iterator iterator;
>>      if (strncmp(devargs, "class=eth,mac=", 14) == 0) {
>>          new_port_id = netdev_dpdk_get_port_by_mac(&devargs[14]);
>> @@ -1653,8 +1654,12 @@ netdev_dpdk_process_devargs(struct netdev_dpdk *dev,
>>                  || !rte_eth_dev_is_valid_port(new_port_id)) {
>>              /* Device not found in DPDK, attempt to attach it */
>> -            if (!rte_eth_dev_attach(devargs, &new_port_id)) {
>> +            if (!rte_dev_probe(devargs)) {
>>                  /* Attach successful */
>>                  dev->attached = true;
>>                  VLOG_INFO("Device '%s' attached to DPDK", devargs);
>> +                RTE_ETH_FOREACH_MATCHING_DEV(new_port_id, devargs, &iterator) {
>> +                    rte_eth_iterator_cleanup(&iterator);
>> +                    break;
>> +                }
> 
> This is a recommended way to find the device after probe, but it looks very
> unclear. Can we just call 'rte_eth_dev_get_port_by_name(name, &new_port_id)'
> here instead ? It should have same effect.

Yeah, looks like we can use it in this case. Changed to that in v2 and
checked the return before setting attached.

> If not, it'll be nice to have some comments.
> 
>>              } else {
>>                  /* Attach unsuccessful */
>> @@ -3206,6 +3211,6 @@ netdev_dpdk_detach(struct unixctl_conn *conn, int argc OVS_UNUSED,
>>      char *response;
>>      dpdk_port_t port_id;
>> -    char devname[RTE_ETH_NAME_MAX_LEN];
>>      struct netdev_dpdk *dev;
>> +    struct rte_eth_dev_info dev_info;
>>  
>>      ovs_mutex_lock(&dpdk_mutex);
>> @@ -3226,9 +3231,9 @@ netdev_dpdk_detach(struct unixctl_conn *conn, int argc OVS_UNUSED,
>>      rte_eth_dev_close(port_id);
>>  
>> -    ret = rte_eth_dev_detach(port_id, devname);
>> -    if (ret < 0) {
>> -        response = xasprintf("Device '%s' can not be detached", argv[1]);
>> -        goto error;
>> -    }
>> +    rte_eth_dev_info_get(port_id, &dev_info);
>> +    if (!dev_info.device || rte_dev_remove(dev_info.device)) {
>> +            response = xasprintf("Device '%s' can not be detached", argv[1]);
>> +            goto error;
>> +        }
> 
> Indents are a bit off.
> 

fixed, thanks.

>>  
>>      response = xasprintf("Device '%s' has been detached", argv[1]);
>>



More information about the dev mailing list