[dpdk-dev] [PATCH v5 3/3] ethdev: fix wrong error return refere to API definition

Ananyev, Konstantin konstantin.ananyev at intel.com
Fri Oct 24 13:04:44 CEST 2014



> -----Original Message-----
> From: y at ecsmtp.sh.intel.com [mailto:y at ecsmtp.sh.intel.com]
> Sent: Friday, October 24, 2014 6:55 AM
> To: dev at dpdk.org
> Cc: nhorman at tuxdriver.com; Richardson, Bruce; Ananyev, Konstantin; De Lara Guarch, Pablo; Liang, Cunming
> Subject: [PATCH v5 3/3] ethdev: fix wrong error return refere to API definition
> 
> From: Cunming Liang <cunming.liang at intel.com>
> 
> Per definition, rte_eth_rx_burst/rte_eth_tx_burst/rte_eth_rx_queue_count returns the packet number.
> When RTE_LIBRTE_ETHDEV_DEBUG turns on, retval of FUNC_PTR_OR_ERR_RTE was set to -ENOTSUP.
> It makes confusing.
> The patch always return 0 no matter no packet or there's error.
> Meanwhile set errno in such kind of checking.
> 
> Signed-off-by: Cunming Liang <cunming.liang at intel.com>
> ---
>  lib/librte_ether/rte_ethdev.c |   10 +++++++---
>  1 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 50f10d9..6675f28 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -81,12 +81,14 @@
>  /* Macros for checking for restricting functions to primary instance only */
>  #define PROC_PRIMARY_OR_ERR_RET(retval) do { \
>  	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
> +		rte_errno = -E_RTE_SECONDARY;				\
>  		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
>  		return (retval); \
>  	} \
>  } while(0)
>  #define PROC_PRIMARY_OR_RET() do { \
>  	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
> +		rte_errno = -E_RTE_SECONDARY;				\
>  		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
>  		return; \
>  	} \
> @@ -95,12 +97,14 @@
>  /* Macros to check for invlaid function pointers in dev_ops structure */
>  #define FUNC_PTR_OR_ERR_RET(func, retval) do { \
>  	if ((func) == NULL) { \
> +		rte_errno = -ENOTSUP; \
>  		PMD_DEBUG_TRACE("Function not supported\n"); \
>  		return (retval); \
>  	} \
>  } while(0)
>  #define FUNC_PTR_OR_RET(func) do { \
>  	if ((func) == NULL) { \
> +		rte_errno = -ENOTSUP; \
>  		PMD_DEBUG_TRACE("Function not supported\n"); \
>  		return; \
>  	} \
> @@ -2530,7 +2534,7 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
>  		return 0;
>  	}
>  	dev = &rte_eth_devices[port_id];
> -	FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
> +	FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
>  	if (queue_id >= dev->data->nb_rx_queues) {
>  		PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
>  		return 0;
> @@ -2551,7 +2555,7 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
>  	}
>  	dev = &rte_eth_devices[port_id];
> 
> -	FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, -ENOTSUP);
> +	FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
>  	if (queue_id >= dev->data->nb_tx_queues) {
>  		PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
>  		return 0;
> @@ -2570,7 +2574,7 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
>  		return 0;
>  	}
>  	dev = &rte_eth_devices[port_id];
> -	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP);
> +	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
>  	return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
>  }

There are few things that worry me with that approach:

1.  Different behaviour of rte_eth_rx_burst/rte_eth_tx_burst  for RTE_LIBRTE_ETHDEV_DEBUG switched on/off.
So application might need to differentiate its code depending on  RTE_LIBRTE_ETHDEV_DEBUG value.

2. Even for RTE_LIBRTE_ETHDEV_DEBUG is on the behaviour of rte_eth_rx_burst/ rte_eth_tx_burst will be inconsistent:
It sets rte_errno if dev->rx_pkt_burst == NULL, but doesn't do the same for other error conditions:
When port_id or queue_id is invalid.

3. Modifying FUNC_PTR_OR_ERR_RET() to set rte_errno, we make behaviour of other rte_ethdev functions inconsistent too:
Now for some error conditions they do set rte_errno, for others they don't.

So if it would be me, I'll just:
- leave FUNC_PTR_OR_*_RET unmodified.
- changes rte_eth_rx_burst/tx_burst for RTE_LIBRTE_ETHDEV_DEBUG something like:

- FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, -ENOTSUP);
+ FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);

I think, that just error logging is enough here.  

Konstantin

> 
> --
> 1.7.4.1



More information about the dev mailing list