[dpdk-dev,2/2] ethdev: move code to common place in hotplug

Message ID 1453377431-25850-3-git-send-email-david.marchand@6wind.com (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

David Marchand Jan. 21, 2016, 11:57 a.m. UTC
  Move these error logs and checks on detach capabilities in a common place.

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_ether/rte_ethdev.c | 69 +++++++++++++++++++++++++------------------
 1 file changed, 40 insertions(+), 29 deletions(-)
  

Comments

Jan Viktorin Jan. 21, 2016, 3:38 p.m. UTC | #1
On Thu, 21 Jan 2016 12:57:11 +0100
David Marchand <david.marchand@6wind.com> wrote:

> Move these error logs and checks on detach capabilities in a common place.
> 
> Signed-off-by: David Marchand <david.marchand@6wind.com>
> 
> ---
> lib/librte_ether/rte_ethdev.c | 69 +++++++++++++++++++++++++------------------
>  1 file changed, 40 insertions(+), 29 deletions(-)
> 
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 951fb1c..9083783 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -514,7 +514,6 @@ rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
>  
>  	return 0;
> [snip]
>  
> @@ -612,14 +599,25 @@ int
>  rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
>  {
>  	struct rte_pci_addr addr;
> +	int ret = -1;
>  
>  	if ((devargs == NULL) || (port_id == NULL))
> -		return -EINVAL;
> +		goto err;

This change modifies the return value from -EINVAL to -1. I don't know
whether is this an issue but it looks suspicious.

>  
> -	if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
> -		return rte_eth_dev_attach_pdev(&addr, port_id);
> -	else
> -		return rte_eth_dev_attach_vdev(devargs, port_id);
> +	if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
> +		ret = rte_eth_dev_attach_pdev(&addr, port_id);
> +		if (ret < 0)
> +			goto err;
> +	} else {
> +		ret = rte_eth_dev_attach_vdev(devargs, port_id);
> +		if (ret < 0)
> +			goto err;
> +	}
> +
> +	return 0;
> +err:
> +	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
> +	return ret;
>  }
>  
>  /* detach the device, then store the name of the device */
> @@ -627,26 +625,39 @@ int
>  rte_eth_dev_detach(uint8_t port_id, char *name)
>  {
>  	struct rte_pci_addr addr;
> -	int ret;
> +	int ret = -1;
>  
>  	if (name == NULL)
> -		return -EINVAL;
> +		goto err;

Same here...

> +
> +	/* check whether the driver supports detach feature, or not */
> +	if (rte_eth_dev_is_detachable(port_id))
> +		goto err;
>  
> [snip]
  
David Marchand Jan. 21, 2016, 6:06 p.m. UTC | #2
On Thu, Jan 21, 2016 at 4:38 PM, Jan Viktorin <viktorin@rehivetech.com> wrote:
> On Thu, 21 Jan 2016 12:57:11 +0100
> David Marchand <david.marchand@6wind.com> wrote:
>
[snip]
>> @@ -612,14 +599,25 @@ int
>>  rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
>>  {
>>       struct rte_pci_addr addr;
>> +     int ret = -1;
>>
>>       if ((devargs == NULL) || (port_id == NULL))
>> -             return -EINVAL;
>> +             goto err;
>
> This change modifies the return value from -EINVAL to -1. I don't know
> whether is this an issue but it looks suspicious.

Should not be an issue, as the api does not give details on expected
negative return values.
Just noticed, this also introduces a new log message that was not
displayed before.

To be safe, I suppose I should restore this.

Thomas, opinion ?


Thanks.
  
Thomas Monjalon Jan. 21, 2016, 6:42 p.m. UTC | #3
2016-01-21 19:06, David Marchand:
> On Thu, Jan 21, 2016 at 4:38 PM, Jan Viktorin <viktorin@rehivetech.com> wrote:
> > On Thu, 21 Jan 2016 12:57:11 +0100
> > David Marchand <david.marchand@6wind.com> wrote:
> >
> [snip]
> >> @@ -612,14 +599,25 @@ int
> >>  rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
> >>  {
> >>       struct rte_pci_addr addr;
> >> +     int ret = -1;
> >>
> >>       if ((devargs == NULL) || (port_id == NULL))
> >> -             return -EINVAL;
> >> +             goto err;
> >
> > This change modifies the return value from -EINVAL to -1. I don't know
> > whether is this an issue but it looks suspicious.
> 
> Should not be an issue, as the api does not give details on expected
> negative return values.
> Just noticed, this also introduces a new log message that was not
> displayed before.
> 
> To be safe, I suppose I should restore this.
> 
> Thomas, opinion ?

I'm OK with the log message added for this error case.
I would just keep the -EINVAL return value.

Other nit: you are allowed to fix the (moved) log message.
  
David Marchand Jan. 22, 2016, 7:15 a.m. UTC | #4
Hello,

On Thu, Jan 21, 2016 at 7:42 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2016-01-21 19:06, David Marchand:
>> On Thu, Jan 21, 2016 at 4:38 PM, Jan Viktorin <viktorin@rehivetech.com> wrote:
>> > This change modifies the return value from -EINVAL to -1. I don't know
>> > whether is this an issue but it looks suspicious.
>>
>> Should not be an issue, as the api does not give details on expected
>> negative return values.
>> Just noticed, this also introduces a new log message that was not
>> displayed before.
>>
>> To be safe, I suppose I should restore this.
>>
>> Thomas, opinion ?
>
> I'm OK with the log message added for this error case.
> I would just keep the -EINVAL return value.

Ok will do.
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 951fb1c..9083783 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -514,7 +514,6 @@  rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id)
 
 	return 0;
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
 	return -1;
 }
 
@@ -525,10 +524,6 @@  rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
 	struct rte_pci_addr freed_addr;
 	struct rte_pci_addr vp;
 
-	/* check whether the driver supports detach feature, or not */
-	if (rte_eth_dev_is_detachable(port_id))
-		goto err;
-
 	/* get pci address by port id */
 	if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr))
 		goto err;
@@ -546,7 +541,6 @@  rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
 	*addr = freed_addr;
 	return 0;
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
 	return -1;
 }
 
@@ -577,8 +571,6 @@  end:
 	free(name);
 	free(args);
 
-	if (ret < 0)
-		RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
 	return ret;
 }
 
@@ -588,10 +580,6 @@  rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
 {
 	char name[RTE_ETH_NAME_MAX_LEN];
 
-	/* check whether the driver supports detach feature, or not */
-	if (rte_eth_dev_is_detachable(port_id))
-		goto err;
-
 	/* get device name by port id */
 	if (rte_eth_dev_get_name_by_port(port_id, name))
 		goto err;
@@ -603,7 +591,6 @@  rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname)
 	strncpy(vdevname, name, sizeof(name));
 	return 0;
 err:
-	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
 	return -1;
 }
 
@@ -612,14 +599,25 @@  int
 rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
 	struct rte_pci_addr addr;
+	int ret = -1;
 
 	if ((devargs == NULL) || (port_id == NULL))
-		return -EINVAL;
+		goto err;
 
-	if (eal_parse_pci_DomBDF(devargs, &addr) == 0)
-		return rte_eth_dev_attach_pdev(&addr, port_id);
-	else
-		return rte_eth_dev_attach_vdev(devargs, port_id);
+	if (eal_parse_pci_DomBDF(devargs, &addr) == 0) {
+		ret = rte_eth_dev_attach_pdev(&addr, port_id);
+		if (ret < 0)
+			goto err;
+	} else {
+		ret = rte_eth_dev_attach_vdev(devargs, port_id);
+		if (ret < 0)
+			goto err;
+	}
+
+	return 0;
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
+	return ret;
 }
 
 /* detach the device, then store the name of the device */
@@ -627,26 +625,39 @@  int
 rte_eth_dev_detach(uint8_t port_id, char *name)
 {
 	struct rte_pci_addr addr;
-	int ret;
+	int ret = -1;
 
 	if (name == NULL)
-		return -EINVAL;
+		goto err;
+
+	/* check whether the driver supports detach feature, or not */
+	if (rte_eth_dev_is_detachable(port_id))
+		goto err;
 
 	if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
 		ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
 		if (ret < 0)
-			return ret;
+			goto err;
 
 		ret = rte_eth_dev_detach_pdev(port_id, &addr);
-		if (ret == 0)
-			snprintf(name, RTE_ETH_NAME_MAX_LEN,
-				"%04x:%02x:%02x.%d",
-				addr.domain, addr.bus,
-				addr.devid, addr.function);
+		if (ret < 0)
+			goto err;
 
-		return ret;
-	} else
-		return rte_eth_dev_detach_vdev(port_id, name);
+		snprintf(name, RTE_ETH_NAME_MAX_LEN,
+			"%04x:%02x:%02x.%d",
+			addr.domain, addr.bus,
+			addr.devid, addr.function);
+	} else {
+		ret = rte_eth_dev_detach_vdev(port_id, name);
+		if (ret < 0)
+			goto err;
+	}
+
+	return 0;
+
+err:
+	RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n");
+	return ret;
 }
 
 static int