Sorry if formatting is wrong. Replying from a phone.

On Jan 21, 2015 6:14 PM, "Mario Torrecillas Rodriguez" <
mario.torrecillasrodrig...@arm.com> 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 <
mario.torrecillasrodrig...@arm.com>
> ---
> (This code contribution is provided under the terms of agreement
LES-LTM-21309)
>
> Changes from previous version:
> * Changed doxygen comment
> * Removed <errno.h> from API file
>
>  platform/linux-generic/Makefile.am             |  2 +
>  platform/linux-generic/include/api/odp_errno.h | 60
++++++++++++++++++++++++++
>  platform/linux-generic/include/odp_internal.h  |  1 +
>  platform/linux-generic/odp_errno.c             | 35 +++++++++++++++
>  platform/linux-generic/odp_packet_io.c         |  2 +-
>  platform/linux-generic/odp_packet_socket.c     | 17 ++++++++
>  platform/linux-generic/odp_timer.c             |  5 ++-
>  7 files changed, 119 insertions(+), 3 deletions(-)
>  create mode 100644 platform/linux-generic/include/api/odp_errno.h
>  create mode 100644 platform/linux-generic/odp_errno.c
>
> diff --git a/platform/linux-generic/Makefile.am
b/platform/linux-generic/Makefile.am
> index a699ea6..1b71b71 100644
> --- a/platform/linux-generic/Makefile.am
> +++ b/platform/linux-generic/Makefile.am
> @@ -19,6 +19,7 @@ include_HEADERS = \
>
$(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \
>
$(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \
>
$(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \
> +
 $(top_srcdir)/platform/linux-generic/include/api/odp_errno.h \
>
$(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \
>
$(top_srcdir)/platform/linux-generic/include/api/odp_init.h \
>
$(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \
> @@ -80,6 +81,7 @@ __LIB__libodp_la_SOURCES = \
>                            odp_classification.c \
>                            odp_cpumask.c \
>                            odp_crypto.c \
> +                          odp_errno.c \
>                            odp_init.c \
>                            odp_impl.c \
>                            odp_linux.c \
> diff --git a/platform/linux-generic/include/api/odp_errno.h
b/platform/linux-generic/include/api/odp_errno.h
> new file mode 100644
> index 0000000..0157720
> --- /dev/null
> +++ b/platform/linux-generic/include/api/odp_errno.h
> @@ -0,0 +1,60 @@
> +/* 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
> +
> +/**
> +* 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 549d406..b953163 100644
> --- a/platform/linux-generic/include/odp_internal.h
> +++ b/platform/linux-generic/include/odp_internal.h
> @@ -18,6 +18,7 @@
>  extern "C" {
>  #endif
>
> +extern __thread int __odp_errno;
>
>  int odp_system_info_init(void);
>
> diff --git a/platform/linux-generic/odp_errno.c
b/platform/linux-generic/odp_errno.c
> new file mode 100644
> index 0000000..ba080e7
> --- /dev/null
> +++ b/platform/linux-generic/odp_errno.c
> @@ -0,0 +1,35 @@
> +/* Copyright (c) 2015, Linaro Limited
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier:    BSD-3-Clause
> + */
> +
> +#include <odp_errno.h>
> +#include <odp_internal.h>
> +#include <string.h>
> +#include <stdio.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);
> +
> +       printf("%s\n", strerror(__odp_errno));

ODP_PRINT should be used instead of printf.

> +}
> +
> +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 c03f47c..18475b8 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -264,7 +264,7 @@ odp_pktio_t odp_pktio_open(const char *dev,
odp_buffer_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 da7fb2c..ed65edb 100644
> --- a/platform/linux-generic/odp_packet_socket.c
> +++ b/platform/linux-generic/odp_packet_socket.c
> @@ -40,6 +40,8 @@
>  #include <odp_align_internal.h>
>  #include <odp_debug_internal.h>
>  #include <odp_hints.h>
> +#include <odp_errno.h>
> +#include <odp_internal.h>
>
>  #include <odph_eth.h>
>  #include <odph_ip.h>
> @@ -112,6 +114,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 +188,8 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const
char *netdev,
>         return sockfd;
>
>  error:
> +       __odp_errno = errno;
> +
>         return -1;
>  }
>
> @@ -195,6 +200,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 +436,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 +576,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 +606,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 +633,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 +641,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 +666,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 +714,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 +733,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, &ethreq);
>         if (ret != 0) {
> +               __odp_errno = errno;
>                 ODP_ERR("ioctl(SIOCGIFHWADDR): %s\n", strerror(errno));
>                 return -1;
>         }
> @@ -775,6 +790,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 +812,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 3ba32a1..a8e00f8 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -50,6 +50,7 @@
>  #include <odp_time.h>
>  #include <odp_timer.h>
>  #include <odp_timer_internal.h>
> +#include <odp_errno.h>
>
>  #define TMO_UNUSED   ((uint64_t)0xFFFFFFFFFFFFFFFF)
>  /* TMO_INACTIVE is or-ed with the expiration tick to indicate an expired
timer.
> @@ -210,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),
> @@ -295,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
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to