* [dpdk-dev] [PATCH v2] net/af_packet: add string error for system errors
@ 2019-07-10 14:46 kkanas
2019-07-10 16:04 ` Stephen Hemminger
0 siblings, 1 reply; 6+ messages in thread
From: kkanas @ 2019-07-10 14:46 UTC (permalink / raw)
To: dev, Ferruh Yigit, John W. Linville; +Cc: Krzysztof Kanas
From: Krzysztof Kanas <kkanas@marvell.com>
Print system error to make easier diagnosis of errors with af_packet.
Signed-off-by: Krzysztof Kanas <kkanas@marvell.com>
---
drivers/net/af_packet/rte_eth_af_packet.c | 53 ++++++++++-------------
1 file changed, 24 insertions(+), 29 deletions(-)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index db1a751cef5b..d4c899526b3c 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -13,7 +13,9 @@
#include <rte_malloc.h>
#include <rte_kvargs.h>
#include <rte_bus_vdev.h>
+#include <rte_errno.h>
+#include <errno.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <arpa/inet.h>
@@ -103,6 +105,10 @@ static int af_packet_logtype;
rte_log(RTE_LOG_ ## level, af_packet_logtype, \
"%s(): " fmt "\n", __func__, ##args)
+#define PMD_LOG_ERRNO(level, fmt, args...) \
+ rte_log(RTE_LOG_ ## level, af_packet_logtype, \
+ "%s(): " fmt ":%s\n", __func__, ##args, rte_strerror(errno))
+
static uint16_t
eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
@@ -603,9 +609,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
return -1;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
- PMD_LOG(ERR,
- "%s: ioctl failed (SIOCGIFINDEX)",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
return -1;
}
(*internals)->if_name = strdup(pair->value);
@@ -614,9 +618,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
(*internals)->if_index = ifr.ifr_ifindex;
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
- PMD_LOG(ERR,
- "%s: ioctl failed (SIOCGIFHWADDR)",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFHWADDR)", name);
return -1;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
@@ -638,9 +640,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
/* Open an AF_PACKET socket for this queue... */
qsockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (qsockfd == -1) {
- PMD_LOG(ERR,
- "%s: could not open AF_PACKET socket",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: could not open AF_PACKET socket",
+ name);
return -1;
}
@@ -648,9 +649,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_VERSION,
&tpver, sizeof(tpver));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_VERSION on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_VERSION on AF_PACKET socket for %s:",
+ name, pair->value);
goto error;
}
@@ -658,9 +658,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_LOSS,
&discard, sizeof(discard));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
+ name, pair->value);
goto error;
}
@@ -668,9 +667,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
&qdisc_bypass, sizeof(qdisc_bypass));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
+ name, pair->value);
goto error;
}
#else
@@ -679,15 +677,14 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_RX_RING on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_RX_RING on AF_PACKE socket for %s",
+ name, pair->value);
goto error;
}
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_TX_RING on AF_PACKET "
"socket for %s", name, pair->value);
goto error;
@@ -700,7 +697,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
qsockfd, 0);
if (rx_queue->map == MAP_FAILED) {
- PMD_LOG(ERR,
+ PMD_LOG_ERRNO(ERR,
"%s: call to mmap failed on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@ -737,9 +734,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = bind(qsockfd, (const struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not bind AF_PACKET socket to %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not bind AF_PACKET socket to %s",
+ name, pair->value);
goto error;
}
@@ -747,9 +743,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_FANOUT,
&fanout_arg, sizeof(fanout_arg));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_FANOUT on AF_PACKET socket "
- "for %s", name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_FANOUT on AF_PACKET socket for %s",
+ name, pair->value);
goto error;
}
#endif
--
2.21.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] net/af_packet: add string error for system errors
2019-07-10 14:46 [dpdk-dev] [PATCH v2] net/af_packet: add string error for system errors kkanas
@ 2019-07-10 16:04 ` Stephen Hemminger
2019-07-11 9:56 ` [dpdk-dev] [EXT] " Krzysztof Kanas
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2019-07-10 16:04 UTC (permalink / raw)
To: kkanas
Cc: 27ee549a-d01b-21a5-4a0b-a7e5594b38c0, dev, Ferruh Yigit,
John W. Linville
On Wed, 10 Jul 2019 16:46:30 +0200
<kkanas@marvell.com> wrote:
>
> +#define PMD_LOG_ERRNO(level, fmt, args...) \
> + rte_log(RTE_LOG_ ## level, af_packet_logtype, \
> + "%s(): " fmt ":%s\n", __func__, ##args, rte_strerror(errno))
> +
> static uint16_t
> eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> {
> @@ -603,9 +609,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
> return -1;
> }
> if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
> - PMD_LOG(ERR,
> - "%s: ioctl failed (SIOCGIFINDEX)",
> - name);
> + PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
> return -1;
This is wrong.
The ioctl sets errno not rte_errno.
Why not?
PMD_LOG(ERR, "%s: ioctl failed (SIOCGIFINDEX): %s",
name, strerror(errno));
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [EXT] Re: [PATCH v2] net/af_packet: add string error for system errors
2019-07-10 16:04 ` Stephen Hemminger
@ 2019-07-11 9:56 ` Krzysztof Kanas
2019-07-11 16:10 ` Stephen Hemminger
0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kanas @ 2019-07-11 9:56 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Krzysztof Kanas, 27ee549a-d01b-21a5-4a0b-a7e5594b38c0, dev,
Ferruh Yigit, John W. Linville
On 19-07-10 09:04, Stephen Hemminger wrote:
> External Email
>
> ----------------------------------------------------------------------
> On Wed, 10 Jul 2019 16:46:30 +0200
> <kkanas@marvell.com> wrote:
>
> >
> > +#define PMD_LOG_ERRNO(level, fmt, args...) \
> > + rte_log(RTE_LOG_ ## level, af_packet_logtype, \
> > + "%s(): " fmt ":%s\n", __func__, ##args, rte_strerror(errno))
> > +
> > static uint16_t
> > eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> > {
> > @@ -603,9 +609,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
> > return -1;
> > }
> > if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
> > - PMD_LOG(ERR,
> > - "%s: ioctl failed (SIOCGIFINDEX)",
> > - name);
> > + PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
> > return -1;
>
> This is wrong.
> The ioctl sets errno not rte_errno.
I was following the documentation on rte_strerror, which states:
For non-RTE-specific error codes, this function returns the value from
the libc strerror function.
>
>
> Why not?
> PMD_LOG(ERR, "%s: ioctl failed (SIOCGIFINDEX): %s",
> name, strerror(errno));
Ok, but rte_strerror uses strerror_r, although I am unsure this is
required here.
--
-
Regards,
Krzysztof(Chris) Kanas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [EXT] Re: [PATCH v2] net/af_packet: add string error for system errors
2019-07-11 9:56 ` [dpdk-dev] [EXT] " Krzysztof Kanas
@ 2019-07-11 16:10 ` Stephen Hemminger
2019-07-12 10:01 ` [dpdk-dev] [PATCH v3] " kkanas
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2019-07-11 16:10 UTC (permalink / raw)
To: Krzysztof Kanas
Cc: 27ee549a-d01b-21a5-4a0b-a7e5594b38c0, dev, Ferruh Yigit,
John W. Linville
On Thu, 11 Jul 2019 09:56:32 +0000
Krzysztof Kanas <kkanas@marvell.com> wrote:
> On 19-07-10 09:04, Stephen Hemminger wrote:
> > External Email
> >
> > ----------------------------------------------------------------------
> > On Wed, 10 Jul 2019 16:46:30 +0200
> > <kkanas@marvell.com> wrote:
> >
> > >
> > > +#define PMD_LOG_ERRNO(level, fmt, args...) \
> > > + rte_log(RTE_LOG_ ## level, af_packet_logtype, \
> > > + "%s(): " fmt ":%s\n", __func__, ##args, rte_strerror(errno))
> > > +
> > > static uint16_t
> > > eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
> > > {
> > > @@ -603,9 +609,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
> > > return -1;
> > > }
> > > if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
> > > - PMD_LOG(ERR,
> > > - "%s: ioctl failed (SIOCGIFINDEX)",
> > > - name);
> > > + PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
> > > return -1;
> >
> > This is wrong.
> > The ioctl sets errno not rte_errno.
> I was following the documentation on rte_strerror, which states:
>
> For non-RTE-specific error codes, this function returns the value from
> the libc strerror function
That document is correct, but the intended usage is to do rte_strerror(rte_errno)
and since rte_errno values correspond to errno values for system errors it would work.
In conclusion, your code will work but is a little confusing.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH v3] net/af_packet: add string error for system errors
2019-07-11 16:10 ` Stephen Hemminger
@ 2019-07-12 10:01 ` kkanas
2019-07-15 14:06 ` Ferruh Yigit
0 siblings, 1 reply; 6+ messages in thread
From: kkanas @ 2019-07-12 10:01 UTC (permalink / raw)
To: dev, Stephen Hemminger, Ferruh Yigit, John W. Linville; +Cc: Krzysztof Kanas
From: Krzysztof Kanas <kkanas@marvell.com>
Print system error to make easier diagnosis of errors with af_packet.
Signed-off-by: Krzysztof Kanas <kkanas@marvell.com>
---
drivers/net/af_packet/rte_eth_af_packet.c | 53 ++++++++++-------------
1 file changed, 24 insertions(+), 29 deletions(-)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index db1a751cef5b..fdbf7d3be4e7 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -14,6 +14,7 @@
#include <rte_kvargs.h>
#include <rte_bus_vdev.h>
+#include <errno.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <arpa/inet.h>
@@ -21,6 +22,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <poll.h>
@@ -103,6 +105,10 @@ static int af_packet_logtype;
rte_log(RTE_LOG_ ## level, af_packet_logtype, \
"%s(): " fmt "\n", __func__, ##args)
+#define PMD_LOG_ERRNO(level, fmt, args...) \
+ rte_log(RTE_LOG_ ## level, af_packet_logtype, \
+ "%s(): " fmt ":%s\n", __func__, ##args, strerror(errno))
+
static uint16_t
eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
@@ -603,9 +609,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
return -1;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
- PMD_LOG(ERR,
- "%s: ioctl failed (SIOCGIFINDEX)",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name);
return -1;
}
(*internals)->if_name = strdup(pair->value);
@@ -614,9 +618,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
(*internals)->if_index = ifr.ifr_ifindex;
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
- PMD_LOG(ERR,
- "%s: ioctl failed (SIOCGIFHWADDR)",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: ioctl failed (SIOCGIFHWADDR)", name);
return -1;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
@@ -638,9 +640,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
/* Open an AF_PACKET socket for this queue... */
qsockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (qsockfd == -1) {
- PMD_LOG(ERR,
- "%s: could not open AF_PACKET socket",
- name);
+ PMD_LOG_ERRNO(ERR, "%s: could not open AF_PACKET socket",
+ name);
return -1;
}
@@ -648,9 +649,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_VERSION,
&tpver, sizeof(tpver));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_VERSION on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_VERSION on AF_PACKET socket for %s:",
+ name, pair->value);
goto error;
}
@@ -658,9 +658,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_LOSS,
&discard, sizeof(discard));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_LOSS on AF_PACKET socket for %s",
+ name, pair->value);
goto error;
}
@@ -668,9 +667,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
&qdisc_bypass, sizeof(qdisc_bypass));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s",
+ name, pair->value);
goto error;
}
#else
@@ -679,15 +677,14 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_RX_RING on AF_PACKET socket for %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_RX_RING on AF_PACKE socket for %s",
+ name, pair->value);
goto error;
}
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req));
if (rc == -1) {
- PMD_LOG(ERR,
+ PMD_LOG_ERRNO(ERR,
"%s: could not set PACKET_TX_RING on AF_PACKET "
"socket for %s", name, pair->value);
goto error;
@@ -700,7 +697,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
qsockfd, 0);
if (rx_queue->map == MAP_FAILED) {
- PMD_LOG(ERR,
+ PMD_LOG_ERRNO(ERR,
"%s: call to mmap failed on AF_PACKET socket for %s",
name, pair->value);
goto error;
@@ -737,9 +734,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = bind(qsockfd, (const struct sockaddr*)&sockaddr, sizeof(sockaddr));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not bind AF_PACKET socket to %s",
- name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not bind AF_PACKET socket to %s",
+ name, pair->value);
goto error;
}
@@ -747,9 +743,8 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_FANOUT,
&fanout_arg, sizeof(fanout_arg));
if (rc == -1) {
- PMD_LOG(ERR,
- "%s: could not set PACKET_FANOUT on AF_PACKET socket "
- "for %s", name, pair->value);
+ PMD_LOG_ERRNO(ERR, "%s: could not set PACKET_FANOUT on AF_PACKET socket for %s",
+ name, pair->value);
goto error;
}
#endif
--
2.21.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v3] net/af_packet: add string error for system errors
2019-07-12 10:01 ` [dpdk-dev] [PATCH v3] " kkanas
@ 2019-07-15 14:06 ` Ferruh Yigit
0 siblings, 0 replies; 6+ messages in thread
From: Ferruh Yigit @ 2019-07-15 14:06 UTC (permalink / raw)
To: kkanas, dev, Stephen Hemminger, John W. Linville
On 7/12/2019 11:01 AM, kkanas@marvell.com wrote:
> From: Krzysztof Kanas <kkanas@marvell.com>
>
> Print system error to make easier diagnosis of errors with af_packet.
>
> Signed-off-by: Krzysztof Kanas <kkanas@marvell.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Applied to dpdk-next-net/master, thanks.
(Whitespace updated, to use a tab instead of align to parentheses, while merging.)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-07-15 14:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10 14:46 [dpdk-dev] [PATCH v2] net/af_packet: add string error for system errors kkanas
2019-07-10 16:04 ` Stephen Hemminger
2019-07-11 9:56 ` [dpdk-dev] [EXT] " Krzysztof Kanas
2019-07-11 16:10 ` Stephen Hemminger
2019-07-12 10:01 ` [dpdk-dev] [PATCH v3] " kkanas
2019-07-15 14:06 ` Ferruh Yigit
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).