[dpdk-dev] eventdev: set rte errno in port link/unlink functions

Message ID 1510699450-29204-1-git-send-email-gage.eads@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Eads, Gage Nov. 14, 2017, 10:44 p.m. UTC
  The return value for rte_event_port_{link, unlink}() is defined as the
"number of {links, unlinks} actually established." However, the eventdev
layer's error checking returns negative error values. This commit aligns
the eventdev code with the API definition by having it set rte_errno and
return 0 if it detects an error.

Fixes: 4f0804bbdfb9 ("eventdev: implement the northbound APIs")

Signed-off-by: Gage Eads <gage.eads@intel.com>
---
 lib/librte_eventdev/rte_eventdev.c     | 36 ++++++++++++++++++++++++----------
 lib/librte_eventdev/rte_eventdev_pmd.h |  8 ++++++++
 2 files changed, 34 insertions(+), 10 deletions(-)
  

Comments

Jerin Jacob Dec. 4, 2017, 3:06 a.m. UTC | #1
-----Original Message-----
> Date: Tue, 14 Nov 2017 16:44:10 -0600
> From: Gage Eads <gage.eads@intel.com>
> To: dev@dpdk.org
> CC: jerin.jacob@caviumnetworks.com, harry.van.haaren@intel.com,
>  bruce.richardson@intel.com, hemant.agrawal@nxp.com, nipun.gupta@nxp.com,
>  santosh.shukla@caviumnetworks.com, pbhagavatula@caviumnetworks.com
> Subject: [PATCH] eventdev: set rte errno in port link/unlink functions
> X-Mailer: git-send-email 2.7.4
> 
> The return value for rte_event_port_{link, unlink}() is defined as the
> "number of {links, unlinks} actually established." However, the eventdev
> layer's error checking returns negative error values. This commit aligns
> the eventdev code with the API definition by having it set rte_errno and
> return 0 if it detects an error.
> 
> Fixes: 4f0804bbdfb9 ("eventdev: implement the northbound APIs")
> 
> Signed-off-by: Gage Eads <gage.eads@intel.com>

Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
  
Jerin Jacob Dec. 4, 2017, 5:12 a.m. UTC | #2
-----Original Message-----
> Date: Mon, 4 Dec 2017 08:36:20 +0530
> From: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> To: Gage Eads <gage.eads@intel.com>
> CC: dev@dpdk.org, harry.van.haaren@intel.com, bruce.richardson@intel.com,
>  hemant.agrawal@nxp.com, nipun.gupta@nxp.com,
>  santosh.shukla@caviumnetworks.com, pbhagavatula@caviumnetworks.com
> Subject: Re: [dpdk-dev] [PATCH] eventdev: set rte errno in port link/unlink
>  functions
> User-Agent: Mutt/1.9.1 (2017-09-22)
> 
> -----Original Message-----
> > Date: Tue, 14 Nov 2017 16:44:10 -0600
> > From: Gage Eads <gage.eads@intel.com>
> > To: dev@dpdk.org
> > CC: jerin.jacob@caviumnetworks.com, harry.van.haaren@intel.com,
> >  bruce.richardson@intel.com, hemant.agrawal@nxp.com, nipun.gupta@nxp.com,
> >  santosh.shukla@caviumnetworks.com, pbhagavatula@caviumnetworks.com
> > Subject: [PATCH] eventdev: set rte errno in port link/unlink functions
> > X-Mailer: git-send-email 2.7.4
> > 
> > The return value for rte_event_port_{link, unlink}() is defined as the
> > "number of {links, unlinks} actually established." However, the eventdev
> > layer's error checking returns negative error values. This commit aligns
> > the eventdev code with the API definition by having it set rte_errno and
> > return 0 if it detects an error.
> > 
> > Fixes: 4f0804bbdfb9 ("eventdev: implement the northbound APIs")
> > 
> > Signed-off-by: Gage Eads <gage.eads@intel.com>
> 
> Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

Applied to dpdk-next-eventdev/master. Thanks.

>
  

Patch

diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c
index 378ccb5..f000b80 100644
--- a/lib/librte_eventdev/rte_eventdev.c
+++ b/lib/librte_eventdev/rte_eventdev.c
@@ -830,13 +830,19 @@  rte_event_port_link(uint8_t dev_id, uint8_t port_id,
 	uint16_t *links_map;
 	int i, diag;
 
-	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+	RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, -EINVAL, 0);
 	dev = &rte_eventdevs[dev_id];
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_link, -ENOTSUP);
+
+	if (*dev->dev_ops->port_link == NULL) {
+		RTE_PMD_DEBUG_TRACE("Function not supported\n");
+		rte_errno = -ENOTSUP;
+		return 0;
+	}
 
 	if (!is_valid_port(dev, port_id)) {
 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
-		return -EINVAL;
+		rte_errno = -EINVAL;
+		return 0;
 	}
 
 	if (queues == NULL) {
@@ -855,8 +861,10 @@  rte_event_port_link(uint8_t dev_id, uint8_t port_id,
 	}
 
 	for (i = 0; i < nb_links; i++)
-		if (queues[i] >= dev->data->nb_queues)
-			return -EINVAL;
+		if (queues[i] >= dev->data->nb_queues) {
+			rte_errno = -EINVAL;
+			return 0;
+		}
 
 	diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
 						queues, priorities, nb_links);
@@ -881,13 +889,19 @@  rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
 	int i, diag;
 	uint16_t *links_map;
 
-	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+	RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, -EINVAL, 0);
 	dev = &rte_eventdevs[dev_id];
-	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_unlink, -ENOTSUP);
+
+	if (*dev->dev_ops->port_unlink == NULL) {
+		RTE_PMD_DEBUG_TRACE("Function not supported\n");
+		rte_errno = -ENOTSUP;
+		return 0;
+	}
 
 	if (!is_valid_port(dev, port_id)) {
 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
-		return -EINVAL;
+		rte_errno = -EINVAL;
+		return 0;
 	}
 
 	if (queues == NULL) {
@@ -898,8 +912,10 @@  rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
 	}
 
 	for (i = 0; i < nb_unlinks; i++)
-		if (queues[i] >= dev->data->nb_queues)
-			return -EINVAL;
+		if (queues[i] >= dev->data->nb_queues) {
+			rte_errno = -EINVAL;
+			return 0;
+		}
 
 	diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
 					queues, nb_unlinks);
diff --git a/lib/librte_eventdev/rte_eventdev_pmd.h b/lib/librte_eventdev/rte_eventdev_pmd.h
index 4369d9b..4016fef 100644
--- a/lib/librte_eventdev/rte_eventdev_pmd.h
+++ b/lib/librte_eventdev/rte_eventdev_pmd.h
@@ -76,6 +76,14 @@  extern "C" {
 	} \
 } while (0)
 
+#define RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, errno, retval) do { \
+	if (!rte_event_pmd_is_valid_dev((dev_id))) { \
+		RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
+		rte_errno = errno; \
+		return retval; \
+	} \
+} while (0)
+
 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
 	if (!rte_event_pmd_is_valid_dev((dev_id))) { \
 		RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \