On 4 February 2015 at 08:58, Mario Torrecillas Rodriguez < [email protected]> wrote:
> Added odp_errno.c and odp_errno.h > Changed odp_packet_io and odp_timer to use it. > > Signed-off-by: Mario Torrecillas Rodriguez < > [email protected]> > Tested-by: Mike Holmes <[email protected]> errono now appears in the doxygen module "ODP LOGGING / ABORT / VERSION / DEBUG / ERRNO" > --- > (This code contribution is provided under the terms of agreement > LES-LTM-21309) > > Changes from previous version: > * Added doxygen group > * Adapted to new file structure > > include/odp/api/version.h | 2 +- > platform/linux-generic/Makefile.am | 2 + > platform/linux-generic/include/odp/odp_errno.h | 68 > ++++++++++++++++++++++++++ > platform/linux-generic/include/odp_internal.h | 2 + > platform/linux-generic/odp_errno.c | 36 ++++++++++++++ > platform/linux-generic/odp_packet_io.c | 2 +- > platform/linux-generic/odp_packet_socket.c | 15 ++++++ > platform/linux-generic/odp_timer.c | 4 +- > 8 files changed, 127 insertions(+), 4 deletions(-) > create mode 100644 platform/linux-generic/include/odp/odp_errno.h > create mode 100644 platform/linux-generic/odp_errno.c > > diff --git a/include/odp/api/version.h b/include/odp/api/version.h > index 0889d9c..c0f96b9 100644 > --- a/include/odp/api/version.h > +++ b/include/odp/api/version.h > @@ -18,7 +18,7 @@ > extern "C" { > #endif > > -/** @defgroup odp_ver_abt_log_dbg ODP LOGGING / ABORT / VERSION / DEBUG > +/** @defgroup odp_ver_abt_log_dbg ODP LOGGING / ABORT / VERSION / DEBUG / > ERRNO > * @{ > */ > > diff --git a/platform/linux-generic/Makefile.am > b/platform/linux-generic/Makefile.am > index 81245b1..a0b704e 100644 > --- a/platform/linux-generic/Makefile.am > +++ b/platform/linux-generic/Makefile.am > @@ -21,6 +21,7 @@ odpinclude_HEADERS = \ > > $(top_srcdir)/platform/linux-generic/include/odp/cpumask.h \ > > $(top_srcdir)/platform/linux-generic/include/odp/crypto.h \ > $(top_srcdir)/platform/linux-generic/include/odp/debug.h > \ > + > $(top_srcdir)/platform/linux-generic/include/odp/odp_errno.h \ > $(top_srcdir)/platform/linux-generic/include/odp/event.h > \ > $(top_srcdir)/platform/linux-generic/include/odp/hints.h > \ > $(top_srcdir)/platform/linux-generic/include/odp/init.h \ > @@ -135,6 +136,7 @@ __LIB__libodp_la_SOURCES = \ > odp_classification.c \ > odp_cpumask.c \ > odp_crypto.c \ > + odp_errno.c \ > odp_event.c \ > odp_init.c \ > odp_impl.c \ > diff --git a/platform/linux-generic/include/odp/odp_errno.h > b/platform/linux-generic/include/odp/odp_errno.h > new file mode 100644 > index 0000000..527214e > --- /dev/null > +++ b/platform/linux-generic/include/odp/odp_errno.h > @@ -0,0 +1,68 @@ > +/* Copyright (c) 2015, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +/** > + * @file > + * > + * ODP errno API > + */ > + > +#ifndef ODP_ERRNO_H_ > +#define ODP_ERRNO_H_ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +/** @addtogroup odp_ver_abt_log_dbg > + * @{ > + */ > + > +/** > +* Return latest ODP errno > +* > +* @return ODP errno > +* @retval 0 No error > +*/ > +int odp_errno(void); > + > +/** > +* Set ODP errno to zero > +*/ > +void odp_errno_zero(void); > + > +/** > +* Print ODP errno > +* > +* Interprets the value of ODP errno as an error message, and prints it, > +* optionally preceding it with the custom message specified in str. > +* > +* @param str NULL, or pointer to the string to be appended > +*/ > +void odp_errno_print(const char *str); > + > +/** > +* Error message string > +* > +* Interprets the value of ODP errno, generating a string with a > +* message that describes the error. > +* It uses the system definition of errno. > +* > +* @param errnum Error code > +* > +* @retval Pointer to the string > +*/ > +const char *odp_errno_str(int errnum); > + > +/** > + * @} > + */ > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif > diff --git a/platform/linux-generic/include/odp_internal.h > b/platform/linux-generic/include/odp_internal.h > index 9a6e29d..f57f288 100644 > --- a/platform/linux-generic/include/odp_internal.h > +++ b/platform/linux-generic/include/odp_internal.h > @@ -20,6 +20,8 @@ extern "C" { > > #include <odp/init.h> > > +extern __thread int __odp_errno; > + > struct odp_global_data { > odp_log_func_t log_fn; > odp_abort_func_t abort_fn; > diff --git a/platform/linux-generic/odp_errno.c > b/platform/linux-generic/odp_errno.c > new file mode 100644 > index 0000000..c4fc0f4 > --- /dev/null > +++ b/platform/linux-generic/odp_errno.c > @@ -0,0 +1,36 @@ > +/* Copyright (c) 2015, Linaro Limited > + * All rights reserved. > + * > + * SPDX-License-Identifier: BSD-3-Clause > + */ > + > +#include <odp/odp_errno.h> > +#include <odp_internal.h> > +#include <string.h> > +#include <stdio.h> > +#include <odp_debug_internal.h> > + > +__thread int __odp_errno; > + > +int odp_errno(void) > +{ > + return __odp_errno; > +} > + > +void odp_errno_zero(void) > +{ > + __odp_errno = 0; > +} > + > +void odp_errno_print(const char *str) > +{ > + if (str != NULL) > + printf("%s ", str); > + > + ODP_PRINT("%s\n", strerror(__odp_errno)); > +} > + > +const char *odp_errno_str(int errnum) > +{ > + return strerror(errnum); > +} > diff --git a/platform/linux-generic/odp_packet_io.c > b/platform/linux-generic/odp_packet_io.c > index c3336cf..f54a625 100644 > --- a/platform/linux-generic/odp_packet_io.c > +++ b/platform/linux-generic/odp_packet_io.c > @@ -265,7 +265,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_pool_t > pool) > id = odp_pktio_lookup(dev); > if (id != ODP_PKTIO_INVALID) { > /* interface is already open */ > - errno = -EEXIST; > + __odp_errno = EEXIST; > return ODP_PKTIO_INVALID; > } > > diff --git a/platform/linux-generic/odp_packet_socket.c > b/platform/linux-generic/odp_packet_socket.c > index 3f114fa..41e57c1 100644 > --- a/platform/linux-generic/odp_packet_socket.c > +++ b/platform/linux-generic/odp_packet_socket.c > @@ -112,6 +112,7 @@ static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t > *const pkt_sock, > > err = setsockopt(sockfd, SOL_PACKET, PACKET_FANOUT, &val, > sizeof(val)); > if (err != 0) { > + __odp_errno = errno; > ODP_ERR("setsockopt(PACKET_FANOUT): %s\n", > strerror(errno)); > return -1; > } > @@ -185,6 +186,8 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const > char *netdev, > return sockfd; > > error: > + __odp_errno = errno; > + > return -1; > } > > @@ -195,6 +198,7 @@ error: > int close_pkt_sock(pkt_sock_t *const pkt_sock) > { > if (pkt_sock->sockfd != -1 && close(pkt_sock->sockfd) != 0) { > + __odp_errno = errno; > ODP_ERR("close(sockfd): %s\n", strerror(errno)); > return -1; > } > @@ -430,12 +434,14 @@ static int mmap_pkt_socket(void) > > int ret, sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); > if (sock == -1) { > + __odp_errno = errno; > ODP_ERR("socket(SOCK_RAW): %s\n", strerror(errno)); > return -1; > } > > ret = setsockopt(sock, SOL_PACKET, PACKET_VERSION, &ver, > sizeof(ver)); > if (ret == -1) { > + __odp_errno = errno; > ODP_ERR("setsockopt(PACKET_VERSION): %s\n", > strerror(errno)); > close(sock); > return -1; > @@ -568,6 +574,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct > ring *ring, > ret = sendto(sock, NULL, 0, MSG_DONTWAIT, NULL, 0); > if (ret == -1) { > if (errno != EAGAIN) { > + __odp_errno = errno; > ODP_ERR("sendto(pkt mmap): %s\n", strerror(errno)); > return -1; > } > @@ -597,6 +604,7 @@ static int mmap_set_packet_loss_discard(int sock) > ret = setsockopt(sock, SOL_PACKET, PACKET_LOSS, (void *)&discard, > sizeof(discard)); > if (ret == -1) { > + __odp_errno = errno; > ODP_ERR("setsockopt(PACKET_LOSS): %s\n", strerror(errno)); > return -1; > } > @@ -623,6 +631,7 @@ static int mmap_setup_ring(int sock, struct ring > *ring, int type) > > ret = setsockopt(sock, SOL_PACKET, type, &ring->req, > sizeof(ring->req)); > if (ret == -1) { > + __odp_errno = errno; > ODP_ERR("setsockopt(pkt mmap): %s\n", strerror(errno)); > return -1; > } > @@ -630,6 +639,7 @@ static int mmap_setup_ring(int sock, struct ring > *ring, int type) > ring->rd_len = ring->rd_num * sizeof(*ring->rd); > ring->rd = malloc(ring->rd_len); > if (ring->rd == NULL) { > + __odp_errno = errno; > ODP_ERR("malloc(): %s\n", strerror(errno)); > return -1; > } > @@ -654,6 +664,7 @@ static int mmap_sock(pkt_sock_mmap_t *pkt_sock) > MAP_SHARED | MAP_LOCKED | MAP_POPULATE, sock, 0); > > if (pkt_sock->mmap_base == MAP_FAILED) { > + __odp_errno = errno; > ODP_ERR("mmap rx&tx buffer failed: %s\n", strerror(errno)); > return -1; > } > @@ -701,6 +712,7 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, > const char *netdev) > ret = bind(pkt_sock->sockfd, (struct sockaddr *)&pkt_sock->ll, > sizeof(pkt_sock->ll)); > if (ret == -1) { > + __odp_errno = errno; > ODP_ERR("bind(to IF): %s\n", strerror(errno)); > return -1; > } > @@ -719,6 +731,7 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t *const > pkt_sock, > snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", netdev); > ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, ðreq); > if (ret != 0) { > + __odp_errno = errno; > ODP_ERR("ioctl(SIOCGIFHWADDR): %s\n", strerror(errno)); > return -1; > } > @@ -775,6 +788,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t *const > pkt_sock, const char *netdev, > > if_idx = if_nametoindex(netdev); > if (if_idx == 0) { > + __odp_errno = errno; > ODP_ERR("if_nametoindex(): %s\n", strerror(errno)); > return -1; > } > @@ -796,6 +810,7 @@ int close_pkt_sock_mmap(pkt_sock_mmap_t *const > pkt_sock) > { > mmap_unmap_sock(pkt_sock); > if (pkt_sock->sockfd != -1 && close(pkt_sock->sockfd) != 0) { > + __odp_errno = errno; > ODP_ERR("close(sockfd): %s\n", strerror(errno)); > return -1; > } > diff --git a/platform/linux-generic/odp_timer.c > b/platform/linux-generic/odp_timer.c > index 727f3a1..47af87d 100644 > --- a/platform/linux-generic/odp_timer.c > +++ b/platform/linux-generic/odp_timer.c > @@ -211,7 +211,7 @@ static odp_timer_pool *odp_timer_pool_new( > if (odp_unlikely(tp_idx >= MAX_TIMER_POOLS)) { > /* Restore the previous value */ > odp_atomic_sub_u32(&num_timer_pools, 1); > - errno = ENFILE; /* Table overflow */ > + __odp_errno = ENFILE; /* Table overflow */ > return NULL; > } > size_t sz0 = ODP_ALIGN_ROUNDUP(sizeof(odp_timer_pool), > @@ -296,7 +296,7 @@ static inline odp_timer_t timer_alloc(odp_timer_pool > *tp, > _ODP_MEMMODEL_RLS); > hdl = tp_idx_to_handle(tp, idx); > } else { > - errno = ENFILE; /* Reusing file table overflow */ > + __odp_errno = ENFILE; /* Reusing file table overflow */ > hdl = ODP_TIMER_INVALID; > } > odp_spinlock_unlock(&tp->lock); > -- > 1.9.1 > > > > _______________________________________________ > lng-odp mailing list > [email protected] > http://lists.linaro.org/mailman/listinfo/lng-odp > -- *Mike Holmes* Linaro Sr Technical Manager LNG - ODP
_______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
