X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fldp.c;h=a61acb9a6abdf6b7c9c9960960cb48ac488db32b;hb=30e79c2e388a98160a3660f4f03103890c9b1b7c;hp=453ddeb33409234b563c101c866372c53eee0687;hpb=940f78fcf4e276cadef3f163d0493b74fc49755c;p=vpp.git diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c index 453ddeb3340..a61acb9a6ab 100644 --- a/src/vcl/ldp.c +++ b/src/vcl/ldp.c @@ -51,11 +51,17 @@ #define LDP_MAX_NWORKERS 32 +#define LDP_F_SHUT_RD (1 << 0) +#define LDP_F_SHUT_WR (1 << 1) + typedef struct ldp_fd_entry_ { u32 session_index; + u32 worker_index; u32 fd; u32 fd_index; + u32 flags; + clib_spinlock_t lock; } ldp_fd_entry_t; typedef struct ldp_worker_ctx_ @@ -97,7 +103,7 @@ typedef struct ldp_worker_ctx_t *workers; int init; char app_name[LDP_APP_NAME_MAX]; - u32 sid_bit_val; + u32 sh_bit_val; u32 sid_bit_mask; u32 debug; ldp_fd_entry_t *fd_pool; @@ -112,10 +118,10 @@ typedef struct #define LDBG(_lvl, _fmt, _args...) \ if (ldp->debug > _lvl) \ - clib_warning (_fmt, ##_args) + clib_warning ("ldp<%d>: " _fmt, getpid(), ##_args) static ldp_main_t ldp_main = { - .sid_bit_val = (1 << LDP_SID_BIT_MIN), + .sh_bit_val = (1 << LDP_SID_BIT_MIN), .sid_bit_mask = (1 << LDP_SID_BIT_MIN) - 1, .debug = LDP_DEBUG_INIT, }; @@ -150,44 +156,73 @@ ldp_get_app_name () return ldp->app_name; } +static inline vcl_session_handle_t +ldp_fd_entry_sh (ldp_fd_entry_t * fde) +{ + return vppcom_session_handle (fde->session_index); +} + static int -ldp_fd_alloc (u32 sid) +ldp_fd_alloc (vcl_session_handle_t sh) { ldp_fd_entry_t *fde; clib_rwlock_writer_lock (&ldp->fd_table_lock); - if (pool_elts (ldp->fd_pool) >= (1ULL << 32) - ldp->sid_bit_val) + if (pool_elts (ldp->fd_pool) >= (1ULL << 32) - ldp->sh_bit_val) { clib_rwlock_writer_unlock (&ldp->fd_table_lock); return -1; } pool_get (ldp->fd_pool, fde); - fde->session_index = vppcom_session_index (sid); + fde->session_index = vppcom_session_index (sh); + fde->worker_index = vppcom_session_worker (sh); fde->fd_index = fde - ldp->fd_pool; - fde->fd = fde->fd_index + ldp->sid_bit_val; + fde->fd = fde->fd_index + ldp->sh_bit_val; hash_set (ldp->session_index_to_fd_table, fde->session_index, fde->fd); + clib_spinlock_init (&fde->lock); clib_rwlock_writer_unlock (&ldp->fd_table_lock); return fde->fd; } static ldp_fd_entry_t * -ldp_fd_entry_get_w_lock (u32 fd_index) +ldp_fd_entry_get (u32 fd_index) { - clib_rwlock_reader_lock (&ldp->fd_table_lock); if (pool_is_free_index (ldp->fd_pool, fd_index)) return 0; - return pool_elt_at_index (ldp->fd_pool, fd_index); } +static ldp_fd_entry_t * +ldp_fd_entry_lock (u32 fd_index) +{ + ldp_fd_entry_t *fe; + clib_rwlock_reader_lock (&ldp->fd_table_lock); + if (pool_is_free_index (ldp->fd_pool, fd_index)) + { + clib_rwlock_reader_unlock (&ldp->fd_table_lock); + return 0; + } + + fe = pool_elt_at_index (ldp->fd_pool, fd_index); + clib_spinlock_lock (&fe->lock); + return fe; +} + +static void +ldp_fd_entry_unlock (ldp_fd_entry_t * fde) +{ + clib_spinlock_unlock (&fde->lock); + clib_rwlock_reader_unlock (&ldp->fd_table_lock); +} + static inline int -ldp_fd_from_sid (u32 sid) +ldp_fd_from_sh (vcl_session_handle_t sh) { uword *fdp; int fd; clib_rwlock_reader_lock (&ldp->fd_table_lock); - fdp = hash_get (ldp->session_index_to_fd_table, vppcom_session_index (sid)); + fdp = hash_get (ldp->session_index_to_fd_table, vppcom_session_index (sh)); fd = fdp ? *fdp : -EMFILE; clib_rwlock_reader_unlock (&ldp->fd_table_lock); @@ -195,52 +230,63 @@ ldp_fd_from_sid (u32 sid) } static inline int -ldp_fd_is_sid (int fd) +ldp_fd_is_sh (int fd) { - return fd >= ldp->sid_bit_val; + return fd >= ldp->sh_bit_val; } static inline u32 -ldp_sid_from_fd (int fd) +ldp_sh_from_fd (int fd) { u32 fd_index, session_index; ldp_fd_entry_t *fde; - if (!ldp_fd_is_sid (fd)) + if (!ldp_fd_is_sh (fd)) return INVALID_SESSION_ID; - fd_index = fd - ldp->sid_bit_val; - fde = ldp_fd_entry_get_w_lock (fd_index); + fd_index = fd - ldp->sh_bit_val; + fde = ldp_fd_entry_lock (fd_index); if (!fde) { LDBG (0, "unknown fd %d", fd); - clib_rwlock_reader_unlock (&ldp->fd_table_lock); return INVALID_SESSION_ID; } session_index = fde->session_index; - clib_rwlock_reader_unlock (&ldp->fd_table_lock); + ldp_fd_entry_unlock (fde); return vppcom_session_handle (session_index); } +static ldp_fd_entry_t * +ldp_fd_entry_lock_w_fd (int fd) +{ + u32 fd_index; + + if (!ldp_fd_is_sh (fd)) + return 0; + + fd_index = fd - ldp->sh_bit_val; + return ldp_fd_entry_lock (fd_index); +} + static void -ldp_fd_free_w_sid (u32 sid) +ldp_fd_free_w_sh (vcl_session_handle_t sh) { ldp_fd_entry_t *fde; u32 fd_index; int fd; - fd = ldp_fd_from_sid (sid); + fd = ldp_fd_from_sh (sh); if (!fd) return; - fd_index = fd - ldp->sid_bit_val; - fde = ldp_fd_entry_get_w_lock (fd_index); - if (fde) - { - hash_unset (ldp->session_index_to_fd_table, fde->session_index); - pool_put (ldp->fd_pool, fde); - } + fd_index = fd - ldp->sh_bit_val; + clib_rwlock_writer_lock (&ldp->fd_table_lock); + fde = ldp_fd_entry_get (fd_index); + ASSERT (fde != 0); + hash_unset (ldp->session_index_to_fd_table, fde->session_index); + clib_spinlock_free (&fde->lock); + pool_put (ldp->fd_pool, fde); clib_rwlock_writer_unlock (&ldp->fd_table_lock); } @@ -258,9 +304,11 @@ ldp_init (void) rv = vppcom_app_create (ldp_get_app_name ()); if (rv != VPPCOM_OK) { - fprintf (stderr, "\nLDP<%d>: ERROR: ldp_init: vppcom_app_create()" - " failed! rv = %d (%s)\n", - getpid (), rv, vppcom_retval_str (rv)); + ldp->vcl_needs_real_epoll = 0; + if (rv == VPPCOM_EEXIST) + return 0; + LDBG (2, "\nERROR: ldp_init: vppcom_app_create()" + " failed! rv = %d (%s)\n", rv, vppcom_retval_str (rv)); ldp->init = 0; return rv; } @@ -279,8 +327,8 @@ ldp_init (void) else { ldp->debug = tmp; - LDBG (0, "LDP<%d>: configured LDP debug level (%u) from env var " - LDP_ENV_DEBUG "!", getpid (), ldp->debug); + LDBG (0, "configured LDP debug level (%u) from env var " + LDP_ENV_DEBUG "!", ldp->debug); } } @@ -288,8 +336,8 @@ ldp_init (void) if (env_var_str) { ldp_set_app_name (env_var_str); - LDBG (0, "LDP<%d>: configured LDP app name (%s) from the env var " - LDP_ENV_APP_NAME "!", getpid (), ldp->app_name); + LDBG (0, "configured LDP app name (%s) from the env var " + LDP_ENV_APP_NAME "!", ldp->app_name); } env_var_str = getenv (LDP_ENV_SID_BIT); @@ -301,44 +349,44 @@ ldp_init (void) clib_warning ("LDP<%d>: WARNING: Invalid LDP sid bit specified in" " the env var " LDP_ENV_SID_BIT " (%s)! sid bit " "value %d (0x%x)", getpid (), env_var_str, - ldp->sid_bit_val, ldp->sid_bit_val); + ldp->sh_bit_val, ldp->sh_bit_val); } else if (sb < LDP_SID_BIT_MIN) { - ldp->sid_bit_val = (1 << LDP_SID_BIT_MIN); - ldp->sid_bit_mask = ldp->sid_bit_val - 1; + ldp->sh_bit_val = (1 << LDP_SID_BIT_MIN); + ldp->sid_bit_mask = ldp->sh_bit_val - 1; clib_warning ("LDP<%d>: WARNING: LDP sid bit (%u) specified in the" " env var " LDP_ENV_SID_BIT " (%s) is too small. " "Using LDP_SID_BIT_MIN (%d)! sid bit value %d (0x%x)", getpid (), sb, env_var_str, LDP_SID_BIT_MIN, - ldp->sid_bit_val, ldp->sid_bit_val); + ldp->sh_bit_val, ldp->sh_bit_val); } else if (sb > LDP_SID_BIT_MAX) { - ldp->sid_bit_val = (1 << LDP_SID_BIT_MAX); - ldp->sid_bit_mask = ldp->sid_bit_val - 1; + ldp->sh_bit_val = (1 << LDP_SID_BIT_MAX); + ldp->sid_bit_mask = ldp->sh_bit_val - 1; clib_warning ("LDP<%d>: WARNING: LDP sid bit (%u) specified in the" " env var " LDP_ENV_SID_BIT " (%s) is too big. Using" " LDP_SID_BIT_MAX (%d)! sid bit value %d (0x%x)", getpid (), sb, env_var_str, LDP_SID_BIT_MAX, - ldp->sid_bit_val, ldp->sid_bit_val); + ldp->sh_bit_val, ldp->sh_bit_val); } else { - ldp->sid_bit_val = (1 << sb); - ldp->sid_bit_mask = ldp->sid_bit_val - 1; + ldp->sh_bit_val = (1 << sb); + ldp->sid_bit_mask = ldp->sh_bit_val - 1; - LDBG (0, "LDP<%d>: configured LDP sid bit (%u) from " - LDP_ENV_SID_BIT "! sid bit value %d (0x%x)", getpid (), sb, - ldp->sid_bit_val, ldp->sid_bit_val); + LDBG (0, "configured LDP sid bit (%u) from " + LDP_ENV_SID_BIT "! sid bit value %d (0x%x)", sb, + ldp->sh_bit_val, ldp->sh_bit_val); } } clib_time_init (&ldpw->clib_time); clib_rwlock_init (&ldp->fd_table_lock); - LDBG (0, "LDP<%d>: LDP initialization: done!", getpid ()); + LDBG (0, "LDP initialization: done!"); return 0; } @@ -346,25 +394,22 @@ ldp_init (void) int close (int fd) { - int rv, refcnt; - const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + int rv, refcnt, epfd; + ldp_fd_entry_t *fde; + u32 sh; if ((errno = -ldp_init ())) return -1; - if (sid != INVALID_SESSION_ID) + fde = ldp_fd_entry_lock_w_fd (fd); + if (fde) { - int epfd; - - func_str = "vppcom_session_attr[GET_LIBC_EPFD]"; - epfd = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0); + sh = ldp_fd_entry_sh (fde); + epfd = vppcom_session_attr (sh, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0); if (epfd > 0) { - func_str = "libc_close"; - - LDBG (0, "LDP<%d>: fd %d (0x%x): calling %s(): epfd %u (0x%x)", - getpid (), fd, fd, func_str, epfd, epfd); + LDBG (0, "fd %d (0x%x): calling libc_close: epfd %u (0x%x)", + fd, fd, epfd, epfd); rv = libc_close (epfd); if (rv < 0) @@ -372,7 +417,7 @@ close (int fd) u32 size = sizeof (epfd); epfd = 0; - (void) vppcom_session_attr (sid, VPPCOM_ATTR_SET_LIBC_EPFD, + (void) vppcom_session_attr (sh, VPPCOM_ATTR_SET_LIBC_EPFD, &epfd, &size); } } @@ -380,115 +425,79 @@ close (int fd) { errno = -epfd; rv = -1; + ldp_fd_entry_unlock (fde); goto done; } - func_str = "vppcom_session_close"; + LDBG (0, "fd %d (0x%x): calling vppcom_session_close: sid %u (0x%x)", + fd, fd, sh, sh); - LDBG (0, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x)", - getpid (), fd, fd, func_str, sid, sid); - - refcnt = vppcom_session_attr (sid, VPPCOM_ATTR_GET_REFCNT, 0, 0); - rv = vppcom_session_close (sid); + refcnt = vppcom_session_attr (sh, VPPCOM_ATTR_GET_REFCNT, 0, 0); + rv = vppcom_session_close (sh); if (rv != VPPCOM_OK) { errno = -rv; rv = -1; } - if (refcnt == 1) - ldp_fd_free_w_sid (sid); + + ldp_fd_entry_unlock (fde); + if (refcnt <= 1) + ldp_fd_free_w_sh (sh); } else { - func_str = "libc_close"; - - LDBG (0, "LDP<%d>: fd %d (0x%x): calling %s()", getpid (), fd, fd, - func_str); - + LDBG (0, "fd %d (0x%x): calling libc_close", fd, fd); rv = libc_close (fd); } done: - if (LDP_DEBUG > 0) - { - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, rv, rv); - } + + LDBG (1, "fd %d (0x%x): returning %d (0x%x)", fd, fd, rv, rv); return rv; } ssize_t read (int fd, void *buf, size_t nbytes) { + vcl_session_handle_t sh; + ldp_fd_entry_t *fde; ssize_t size; - const char *func_str; - u32 sid = ldp_sid_from_fd (fd); if ((errno = -ldp_init ())) return -1; - if (sid != INVALID_SESSION_ID) + fde = ldp_fd_entry_lock_w_fd (fd); + if (fde) { - func_str = "vppcom_session_read"; + sh = ldp_fd_entry_sh (fde); + LDBG (2, "fd %d (0x%x): calling vppcom_session_read(): sid %u (0x%x)," + " buf %p, nbytes %u", fd, fd, sh, sh, buf, nbytes); - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "sid %u (0x%x), buf %p, nbytes %u", getpid (), - fd, fd, func_str, sid, sid, buf, nbytes); - - size = vppcom_session_read (sid, buf, nbytes); + size = vppcom_session_read (sh, buf, nbytes); if (size < 0) { errno = -size; size = -1; } + ldp_fd_entry_unlock (fde); } else { - func_str = "libc_read"; - - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "buf %p, nbytes %u", getpid (), - fd, fd, func_str, buf, nbytes); + LDBG (2, "fd %d (0x%x): calling libc_read(): buf %p, nbytes %u", + fd, fd, buf, nbytes); size = libc_read (fd, buf, nbytes); } - if (LDP_DEBUG > 2) - { - if (size < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, size, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, size, size); - } + LDBG (2, "fd %d (0x%x): returning %d (0x%x)", fd, fd, size, size); return size; } ssize_t readv (int fd, const struct iovec * iov, int iovcnt) { - const char *func_str; ssize_t size = 0; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); int rv = 0, i, total = 0; if ((errno = -ldp_init ())) @@ -496,16 +505,13 @@ readv (int fd, const struct iovec * iov, int iovcnt) if (sid != INVALID_SESSION_ID) { - func_str = "vppcom_session_read"; do { for (i = 0; i < iovcnt; ++i) { - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s() [%d]: " - "sid %u (0x%x), iov %p, iovcnt %d, total %d", - getpid (), fd, fd, func_str, i, sid, sid, - iov, iovcnt, total); + LDBG (2, "fd %d (0x%x): calling vppcom_session_read() [%d]:" + " sid %u (0x%x), iov %p, iovcnt %d, total %d", fd, fd, i, + sid, sid, iov, iovcnt, total); rv = vppcom_session_read (sid, iov[i].iov_base, iov[i].iov_len); if (rv < 0) @@ -515,11 +521,8 @@ readv (int fd, const struct iovec * iov, int iovcnt) total += rv; if (rv < iov[i].iov_len) { - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): " - "rv (%d) < iov[%d].iov_len (%d)", - getpid (), fd, fd, rv, i, - iov[i].iov_len); + LDBG (2, "fd %d (0x%x): rv (%d) < iov[%d].iov_len (%d)", + fd, fd, rv, i, iov[i].iov_len); break; } } @@ -537,95 +540,59 @@ readv (int fd, const struct iovec * iov, int iovcnt) } else { - func_str = "libc_readv"; - - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "iov %p, iovcnt %d", getpid (), fd, fd, iov, iovcnt); + LDBG (2, "fd %d (0x%x): calling libc_readv(): iov %p, iovcnt %d", fd, + fd, iov, iovcnt); size = libc_readv (fd, iov, iovcnt); } - if (LDP_DEBUG > 2) - { - if (size < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, size, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, size, size); - } + + LDBG (2, "fd %d (0x%x): returning %d (0x%x)", fd, fd, size, size); return size; } ssize_t write (int fd, const void *buf, size_t nbytes) { - const char *func_str; + vcl_session_handle_t sh; + ldp_fd_entry_t *fde; ssize_t size = 0; - u32 sid = ldp_sid_from_fd (fd); if ((errno = -ldp_init ())) return -1; - if (sid != INVALID_SESSION_ID) + fde = ldp_fd_entry_lock_w_fd (fd); + if (fde) { - func_str = "vppcom_session_write"; - - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "sid %u (0x%x), buf %p, nbytes %u", getpid (), - fd, fd, func_str, sid, sid, buf, nbytes); + sh = ldp_fd_entry_sh (fde); + LDBG (2, "fd %d (0x%x): calling vppcom_session_write(): sid %u (0x%x), " + "buf %p, nbytes %u", fd, fd, sh, sh, buf, nbytes); - size = vppcom_session_write (sid, (void *) buf, nbytes); + size = vppcom_session_write_msg (sh, (void *) buf, nbytes); if (size < 0) { errno = -size; size = -1; } + ldp_fd_entry_unlock (fde); } else { - func_str = "libc_write"; - - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "buf %p, nbytes %u", getpid (), - fd, fd, func_str, buf, nbytes); + LDBG (2, "fd %d (0x%x): calling libc_write(): buf %p, nbytes %u", + fd, fd, buf, nbytes); size = libc_write (fd, buf, nbytes); } - if (LDP_DEBUG > 2) - { - if (size < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, size, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, size, size); - } + LDBG (2, "fd %d (0x%x): returning %d (0x%x)", fd, fd, size, size); return size; } ssize_t writev (int fd, const struct iovec * iov, int iovcnt) { - const char *func_str; ssize_t size = 0, total = 0; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); int i, rv = 0; /* @@ -637,33 +604,19 @@ writev (int fd, const struct iovec * iov, int iovcnt) if (sid != INVALID_SESSION_ID) { - func_str = "vppcom_session_write"; do { for (i = 0; i < iovcnt; ++i) { - if (LDP_DEBUG > 4) - printf ("%s:%d: LDP<%d>: fd %d (0x%x): calling %s() [%d]: " - "sid %u (0x%x), buf %p, nbytes %ld, total %ld", - __func__, __LINE__, getpid (), fd, fd, func_str, - i, sid, sid, iov[i].iov_base, iov[i].iov_len, total); - - rv = vppcom_session_write (sid, iov[i].iov_base, - iov[i].iov_len); + rv = vppcom_session_write_msg (sid, iov[i].iov_base, + iov[i].iov_len); if (rv < 0) break; else { total += rv; if (rv < iov[i].iov_len) - { - if (LDP_DEBUG > 4) - printf ("%s:%d: LDP<%d>: fd %d (0x%x): " - "rv (%d) < iov[%d].iov_len (%ld)", - __func__, __LINE__, getpid (), fd, fd, - rv, i, iov[i].iov_len); - break; - } + break; } } } @@ -679,32 +632,9 @@ writev (int fd, const struct iovec * iov, int iovcnt) } else { - func_str = "libc_writev"; - - if (LDP_DEBUG > 4) - printf ("%s:%d: LDP<%d>: fd %d (0x%x): calling %s(): " - "iov %p, iovcnt %d\n", __func__, __LINE__, getpid (), - fd, fd, func_str, iov, iovcnt); - size = libc_writev (fd, iov, iovcnt); } - if (LDP_DEBUG > 4) - { - if (size < 0) - { - int errno_val = errno; - perror (func_str); - fprintf (stderr, - "%s:%d: LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %ld, errno = %d\n", __func__, __LINE__, getpid (), fd, - fd, func_str, size, errno_val); - errno = errno_val; - } - else - printf ("%s:%d: LDP<%d>: fd %d (0x%x): returning %ld\n", - __func__, __LINE__, getpid (), fd, fd, size); - } return size; } @@ -714,7 +644,7 @@ fcntl (int fd, int cmd, ...) const char *func_str = __func__; int rv = 0; va_list ap; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -731,8 +661,8 @@ fcntl (int fd, int cmd, ...) { case F_SETFL: func_str = "vppcom_session_attr[SET_FLAGS]"; - LDBG (2, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x) " - "flags %d (0x%x), size %d", getpid (), fd, fd, func_str, sid, + LDBG (2, "fd %d (0x%x): calling %s(): sid %u (0x%x) " + "flags %d (0x%x), size %d", fd, fd, func_str, sid, sid, flags, flags, size); rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_FLAGS, &flags, @@ -741,16 +671,16 @@ fcntl (int fd, int cmd, ...) case F_GETFL: func_str = "vppcom_session_attr[GET_FLAGS]"; - LDBG (2, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), " - "flags %d (0x%x), size %d", getpid (), fd, fd, func_str, sid, + LDBG (2, "fd %d (0x%x): calling %s(): sid %u (0x%x), " + "flags %d (0x%x), size %d", fd, fd, func_str, sid, sid, flags, flags, size); rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_FLAGS, &flags, &size); if (rv == VPPCOM_OK) { - LDBG (2, "LDP<%d>: fd %d (0x%x), cmd %d (F_GETFL): %s() " - "returned flags %d (0x%x)", getpid (), fd, fd, cmd, + LDBG (2, "fd %d (0x%x), cmd %d (F_GETFL): %s() " + "returned flags %d (0x%x)", fd, fd, cmd, func_str, flags, flags); rv = flags; } @@ -774,9 +704,7 @@ fcntl (int fd, int cmd, ...) { func_str = "libc_vfcntl"; - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): cmd %d", - getpid (), fd, fd, func_str, cmd); + LDBG (2, "fd %d (0x%x): calling %s(): cmd %d", fd, fd, func_str, cmd); rv = libc_vfcntl (fd, cmd, ap); } @@ -807,7 +735,7 @@ ioctl (int fd, unsigned long int cmd, ...) const char *func_str; int rv; va_list ap; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -917,8 +845,7 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, /* select as fine grained sleep */ if (!nfds) { - LDBG (3, "LDP<%d>: sleeping for %.02f seconds", getpid (), - time_out); + LDBG (3, "sleeping for %.02f seconds", time_out); time_out += clib_time_now (&ldpw->clib_time); while (clib_time_now (&ldpw->clib_time) < time_out) @@ -935,12 +862,12 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, time_out = -1; - if (nfds <= ldp->sid_bit_val) + if (nfds <= ldp->sh_bit_val) { func_str = "libc_pselect"; - LDBG (3, "LDP<%d>: calling %s(): nfds %d, readfds %p, writefds %p, " - "exceptfds %p, timeout %p, sigmask %p", getpid (), func_str, nfds, + LDBG (3, "calling %s(): nfds %d, readfds %p, writefds %p, " + "exceptfds %p, timeout %p, sigmask %p", func_str, nfds, readfds, writefds, exceptfds, timeout, sigmask); rv = libc_pselect (nfds, readfds, writefds, exceptfds, @@ -948,11 +875,11 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, goto done; } - if (PREDICT_FALSE (ldp->sid_bit_val > FD_SETSIZE / 2)) + if (PREDICT_FALSE (ldp->sh_bit_val > FD_SETSIZE / 2)) { clib_warning ("LDP<%d>: ERROR: LDP sid bit value %d (0x%x) > " "FD_SETSIZE/2 %d (0x%x)!", getpid (), - ldp->sid_bit_val, ldp->sid_bit_val, + ldp->sh_bit_val, ldp->sh_bit_val, FD_SETSIZE / 2, FD_SETSIZE / 2); errno = EOVERFLOW; return -1; @@ -972,9 +899,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, clib_bitmap_foreach (fd, ldpw->rd_bitmap, ({ if (fd > nfds) break; - sid = ldp_sid_from_fd (fd); - LDBG (3, "LDP<%d>: readfds: fd %d (0x%x), sid %u (0x%x)", - getpid (), fd, fd, sid, sid); + sid = ldp_sh_from_fd (fd); + LDBG (3, "readfds: fd %d (0x%x), sid %u (0x%x)", fd, fd, sid, sid); if (sid == INVALID_SESSION_ID) clib_bitmap_set_no_check (ldpw->libc_rd_bitmap, fd, 1); else @@ -989,8 +915,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, libc_bits_set = clib_bitmap_last_set (ldpw->libc_rd_bitmap) + 1; libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits; - LDBG (3, "LDP<%d>: readfds: sid_bits_set %d, sid_bits %d, " - "libc_bits_set %d, libc_bits %d", getpid (), sid_bits_set, + LDBG (3, "readfds: sid_bits_set %d, sid_bits %d, " + "libc_bits_set %d, libc_bits %d", sid_bits_set, sid_bits, libc_bits_set, libc_bits); } if (writefds) @@ -1005,9 +931,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, clib_bitmap_foreach (fd, ldpw->wr_bitmap, ({ if (fd > nfds) break; - sid = ldp_sid_from_fd (fd); - LDBG (3, "LDP<%d>: writefds: fd %d (0x%x), sid %u (0x%x)", - getpid (), fd, fd, sid, sid); + sid = ldp_sh_from_fd (fd); + LDBG (3, "writefds: fd %d (0x%x), sid %u (0x%x)", fd, fd, sid, sid); if (sid == INVALID_SESSION_ID) clib_bitmap_set_no_check (ldpw->libc_wr_bitmap, fd, 1); else @@ -1022,8 +947,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, libc_bits_set = clib_bitmap_last_set (ldpw->libc_wr_bitmap) + 1; libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits; - LDBG (3, "LDP<%d>: writefds: sid_bits_set %d, sid_bits %d, " - "libc_bits_set %d, libc_bits %d", getpid (), + LDBG (3, "writefds: sid_bits_set %d, sid_bits %d, " + "libc_bits_set %d, libc_bits %d", sid_bits_set, sid_bits, libc_bits_set, libc_bits); } if (exceptfds) @@ -1038,9 +963,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, clib_bitmap_foreach (fd, ldpw->ex_bitmap, ({ if (fd > nfds) break; - sid = ldp_sid_from_fd (fd); - LDBG (3, "LDP<%d>: exceptfds: fd %d (0x%x), sid %u (0x%x)", - getpid (), fd, fd, sid, sid); + sid = ldp_sh_from_fd (fd); + LDBG (3, "exceptfds: fd %d (0x%x), sid %u (0x%x)", fd, fd, sid, sid); if (sid == INVALID_SESSION_ID) clib_bitmap_set_no_check (ldpw->libc_ex_bitmap, fd, 1); else @@ -1055,8 +979,8 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, libc_bits_set = clib_bitmap_last_set (ldpw->libc_ex_bitmap) + 1; libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits; - LDBG (3, "LDP<%d>: exceptfds: sid_bits_set %d, sid_bits %d, " - "libc_bits_set %d, libc_bits %d", getpid (), + LDBG (3, "exceptfds: sid_bits_set %d, sid_bits %d, " + "libc_bits_set %d, libc_bits %d", sid_bits_set, sid_bits, libc_bits_set, libc_bits); } @@ -1089,9 +1013,12 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, sizeof (clib_bitmap_t)); rv = vppcom_select (sid_bits, - readfds ? ldpw->rd_bitmap : NULL, - writefds ? ldpw->wr_bitmap : NULL, - exceptfds ? ldpw->ex_bitmap : NULL, 0); + readfds ? (unsigned long *) ldpw->rd_bitmap + : NULL, + writefds ? (unsigned long *) ldpw->wr_bitmap + : NULL, + exceptfds ? (unsigned long *) + ldpw->ex_bitmap : NULL, 0); if (rv < 0) { errno = -rv; @@ -1104,7 +1031,7 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, /* *INDENT-OFF* */ clib_bitmap_foreach (sid, ldpw->rd_bitmap, ({ - fd = ldp_fd_from_sid (vppcom_session_handle (sid)); + fd = ldp_fd_from_sh (vppcom_session_handle (sid)); if (PREDICT_FALSE (fd < 0)) { errno = EBADFD; @@ -1120,7 +1047,7 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, /* *INDENT-OFF* */ clib_bitmap_foreach (sid, ldpw->wr_bitmap, ({ - fd = ldp_fd_from_sid (vppcom_session_handle (sid)); + fd = ldp_fd_from_sh (vppcom_session_handle (sid)); if (PREDICT_FALSE (fd < 0)) { errno = EBADFD; @@ -1136,7 +1063,7 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, /* *INDENT-OFF* */ clib_bitmap_foreach (sid, ldpw->ex_bitmap, ({ - fd = ldp_fd_from_sid (vppcom_session_handle (sid)); + fd = ldp_fd_from_sh (vppcom_session_handle (sid)); if (PREDICT_FALSE (fd < 0)) { errno = EBADFD; @@ -1261,9 +1188,8 @@ socket (int domain, int type, int protocol) func_str = "vppcom_session_create"; - LDBG (0, "LDP<%d>: : calling %s(): proto %u (%s), is_nonblocking %u", - getpid (), func_str, proto, vppcom_proto_str (proto), - is_nonblocking); + LDBG (0, "calling %s(): proto %u (%s), is_nonblocking %u", + func_str, proto, vppcom_proto_str (proto), is_nonblocking); sid = vppcom_session_create (proto, is_nonblocking); if (sid < 0) @@ -1287,7 +1213,7 @@ socket (int domain, int type, int protocol) { func_str = "libc_socket"; - LDBG (0, "LDP<%d>: : calling %s()", getpid (), func_str); + LDBG (0, "calling %s()", func_str); rv = libc_socket (domain, type, protocol); } @@ -1304,7 +1230,7 @@ socket (int domain, int type, int protocol) errno = errno_val; } else - clib_warning ("LDP<%d>: : returning fd %d (0x%x)", getpid (), rv, rv); + clib_warning ("returning fd %d (0x%x)", getpid (), rv, rv); } return rv; } @@ -1339,7 +1265,7 @@ socketpair (int domain, int type, int protocol, int fds[2]) { func_str = "libc_socket"; - LDBG (1, "LDP<%d>: : calling %s()", getpid (), func_str); + LDBG (1, "calling %s()", func_str); rv = libc_socketpair (domain, type, protocol, fds); } @@ -1365,8 +1291,7 @@ int bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) { int rv; - const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -1375,8 +1300,6 @@ bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) { vppcom_endpt_t ep; - func_str = "vppcom_session_bind"; - switch (addr->sa_family) { case AF_INET: @@ -1417,10 +1340,8 @@ bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) rv = -1; goto done; } - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), " - "addr %p, len %u", - getpid (), fd, fd, func_str, sid, sid, addr, len); + LDBG (0, "fd %d (0x%x): calling vppcom_session_bind(): " + "sid %u (0x%x), addr %p, len %u", fd, fd, sid, sid, addr, len); rv = vppcom_session_bind (sid, &ep); if (rv != VPPCOM_OK) @@ -1431,32 +1352,15 @@ bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) } else { - func_str = "libc_bind"; - - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "addr %p, len %u", - getpid (), fd, fd, func_str, addr, len); + LDBG (0, "fd %d (0x%x): calling libc_bind(): addr %p, len %u", + fd, fd, addr, len); rv = libc_bind (fd, addr, len); } done: - if (LDP_DEBUG > 0) - { - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, rv, rv); - } + LDBG (1, "fd %d (0x%x): returning %d", fd, fd, rv); + return rv; } @@ -1511,7 +1415,7 @@ getsockname (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict len) { int rv; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -1580,8 +1484,7 @@ int connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) { int rv; - const char *func_str = __func__; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -1599,8 +1502,6 @@ connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) { vppcom_endpt_t ep; - func_str = "vppcom_session_connect"; - switch (addr->sa_family) { case AF_INET: @@ -1641,10 +1542,8 @@ connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) rv = -1; goto done; } - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x) " - "addr %p len %u", - getpid (), fd, fd, func_str, sid, sid, addr, len); + LDBG (0, "fd %d (0x%x): calling vppcom_session_connect(): sid %u (0x%x)" + " addr %p len %u", fd, fd, sid, sid, addr, len); rv = vppcom_session_connect (sid, &ep); if (rv != VPPCOM_OK) @@ -1655,32 +1554,14 @@ connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len) } else { - func_str = "libc_connect"; - - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "addr %p, len %u", - getpid (), fd, fd, func_str, addr, len); + LDBG (0, "fd %d (0x%x): calling libc_connect(): addr %p, len %u", + fd, fd, addr, len); rv = libc_connect (fd, addr, len); } done: - if (LDP_DEBUG > 0) - { - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, rv, rv); - } + LDBG (1, "fd %d (0x%x): returning %d (0x%x)", fd, fd, rv, rv); return rv; } @@ -1689,7 +1570,7 @@ getpeername (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict len) { int rv; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -1759,7 +1640,7 @@ send (int fd, const void *buf, size_t n, int flags) { ssize_t size; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -1817,7 +1698,7 @@ sendfile (int out_fd, int in_fd, off_t * offset, size_t len) ldp_worker_ctx_t *ldpw = ldp_worker_get_current (); ssize_t size = 0; const char *func_str; - u32 sid = ldp_sid_from_fd (out_fd); + u32 sid = ldp_sh_from_fd (out_fd); if ((errno = -ldp_init ())) return -1; @@ -2056,55 +1937,29 @@ ssize_t recv (int fd, void *buf, size_t n, int flags) { ssize_t size; - const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid; if ((errno = -ldp_init ())) return -1; + sid = ldp_sh_from_fd (fd); if (sid != INVALID_SESSION_ID) { - func_str = "vppcom_session_recvfrom"; - - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "sid %u (0x%x), buf %p, n %u, flags 0x%x", getpid (), - fd, fd, func_str, sid, sid, buf, n, flags); + LDBG (2, "fd %d (0x%x): calling vcl recvfrom: sid %u (0x%x), buf %p," + " n %u, flags 0x%x", fd, fd, sid, sid, buf, n, flags); size = vppcom_session_recvfrom (sid, buf, n, flags, NULL); if (size < 0) - { - errno = -size; - size = -1; - } + errno = -size; } else { - func_str = "libc_recv"; - - if (LDP_DEBUG > 2) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): " - "buf %p, n %u, flags 0x%x", getpid (), - fd, fd, func_str, buf, n, flags); + LDBG (2, "fd %d (0x%x): calling libc_recvfrom(): buf %p, n %u, " + "flags 0x%x", fd, fd, buf, n, flags); size = libc_recv (fd, buf, n, flags); } - if (LDP_DEBUG > 2) - { - if (size < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, size, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, size, size); - } return size; } @@ -2114,7 +1969,7 @@ sendto (int fd, const void *buf, size_t n, int flags, { ssize_t size; const char *func_str = __func__; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2205,7 +2060,7 @@ recvfrom (int fd, void *__restrict buf, size_t n, int flags, { ssize_t size; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2275,7 +2130,7 @@ sendmsg (int fd, const struct msghdr * message, int flags) { ssize_t size; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2324,7 +2179,7 @@ sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags) { ssize_t size; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2371,7 +2226,7 @@ recvmsg (int fd, struct msghdr * message, int flags) { ssize_t size; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2421,7 +2276,7 @@ recvmmsg (int fd, struct mmsghdr *vmessages, { ssize_t size; const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2470,7 +2325,7 @@ getsockopt (int fd, int level, int optname, { int rv; const char *func_str = __func__; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); u32 buflen = optlen ? (u32) * optlen : 0; if ((errno = -ldp_init ())) @@ -2698,7 +2553,7 @@ setsockopt (int fd, int level, int optname, { int rv; const char *func_str = __func__; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; @@ -2862,18 +2717,15 @@ int listen (int fd, int n) { int rv; - const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + u32 sid = ldp_sh_from_fd (fd); if ((errno = -ldp_init ())) return -1; if (sid != INVALID_SESSION_ID) { - func_str = "vppcom_session_listen"; - - LDBG (0, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), n %d", - getpid (), fd, fd, func_str, sid, sid, n); + LDBG (0, "fd %d (0x%x): calling vppcom_session_listen():" + " sid %u (0x%x), n %d", fd, fd, sid, sid, n); rv = vppcom_session_listen (sid, n); if (rv != VPPCOM_OK) @@ -2884,29 +2736,12 @@ listen (int fd, int n) } else { - func_str = "libc_listen"; - - LDBG (0, "LDP<%d>: fd %d (0x%x): calling %s(): n %d", getpid (), fd, - fd, func_str, n); + LDBG (0, "fd %d (0x%x): calling libc_listen(): n %d", fd, fd, n); rv = libc_listen (fd, n); } - if (LDP_DEBUG > 0) - { - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, rv, rv); - } + LDBG (1, "fd %d (0x%x): returning %d (0x%x)", fd, fd, rv, rv); return rv; } @@ -2915,32 +2750,28 @@ ldp_accept4 (int listen_fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len, int flags) { int rv; - const char *func_str; - u32 listen_sid = ldp_sid_from_fd (listen_fd); - int accept_sid; + u32 listen_sh; + int accept_sh; if ((errno = -ldp_init ())) return -1; - if (listen_sid != INVALID_SESSION_ID) + listen_sh = ldp_sh_from_fd (listen_fd); + if (listen_sh != INVALID_SESSION_ID) { vppcom_endpt_t ep; u8 src_addr[sizeof (struct sockaddr_in6)]; memset (&ep, 0, sizeof (ep)); ep.ip = src_addr; - func_str = "vppcom_session_accept"; + LDBG (0, "listen fd %d (0x%x): calling vppcom_session_accept:" + " listen sid %u (0x%x), ep %p, flags 0x%x", listen_fd, + listen_fd, listen_sh, listen_sh, ep, flags); - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): " - "listen sid %u (0x%x), ep %p, flags 0x%x", - getpid (), listen_fd, listen_fd, func_str, - listen_sid, listen_sid, ep, flags); - - accept_sid = vppcom_session_accept (listen_sid, &ep, flags); - if (accept_sid < 0) + accept_sh = vppcom_session_accept (listen_sh, &ep, flags); + if (accept_sh < 0) { - errno = -accept_sid; + errno = -accept_sh; rv = -1; } else @@ -2948,22 +2779,16 @@ ldp_accept4 (int listen_fd, __SOCKADDR_ARG addr, rv = ldp_copy_ep_to_sockaddr (addr, addr_len, &ep); if (rv != VPPCOM_OK) { - (void) vppcom_session_close ((u32) accept_sid); + (void) vppcom_session_close ((u32) accept_sh); errno = -rv; rv = -1; } else { - func_str = "ldp_fd_from_sid"; - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): " - "accept sid %u (0x%x), ep %p, flags 0x%x", - getpid (), listen_fd, listen_fd, - func_str, accept_sid, accept_sid, ep, flags); - rv = ldp_fd_alloc ((u32) accept_sid); + rv = ldp_fd_alloc ((u32) accept_sh); if (rv < 0) { - (void) vppcom_session_close ((u32) accept_sid); + (void) vppcom_session_close ((u32) accept_sh); errno = -rv; rv = -1; } @@ -2972,32 +2797,16 @@ ldp_accept4 (int listen_fd, __SOCKADDR_ARG addr, } else { - func_str = "libc_accept4"; - - if (LDP_DEBUG > 0) - clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): " - "addr %p, addr_len %p, flags 0x%x", - getpid (), listen_fd, listen_fd, func_str, - addr, addr_len, flags); + LDBG (0, "listen fd %d (0x%x): calling libc_accept4(): " + "addr %p, addr_len %p, flags 0x%x", listen_fd, + listen_fd, addr, addr_len, flags); rv = libc_accept4 (listen_fd, addr, addr_len, flags); } - if (LDP_DEBUG > 0) - { - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: listen fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), listen_fd, - listen_fd, func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: listen fd %d (0x%x): returning %d (0x%x)", - getpid (), listen_fd, listen_fd, rv, rv); - } + LDBG (1, "listen fd %d (0x%x): returning %d (0x%x)", listen_fd, listen_fd, + rv, rv); + return rv; } @@ -3017,44 +2826,42 @@ accept (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len) int shutdown (int fd, int how) { - int rv; - const char *func_str; - u32 sid = ldp_sid_from_fd (fd); + int rv = 0; if ((errno = -ldp_init ())) return -1; - if (sid != INVALID_SESSION_ID) + if (ldp_fd_is_sh (fd)) { - func_str = "vppcom_session_close[TODO]"; - rv = close (fd); + u32 fd_index = fd - ldp->sh_bit_val; + ldp_fd_entry_t *fde; + + fde = ldp_fd_entry_lock (fd_index); + if (!fde) + { + errno = ENOTCONN; + return -1; + } + + if (how == SHUT_RD) + fde->flags |= LDP_F_SHUT_RD; + else if (how == SHUT_WR) + fde->flags |= LDP_F_SHUT_WR; + else if (how == SHUT_RDWR) + fde->flags |= (LDP_F_SHUT_RD | LDP_F_SHUT_WR); + + if ((fde->flags & LDP_F_SHUT_RD) && (fde->flags & LDP_F_SHUT_WR)) + rv = close (fd); + + ldp_fd_entry_unlock (fde); + LDBG (0, "fd %d (0x%x): calling vcl shutdown: how %d", fd, fd, how); } else { - func_str = "libc_shutdown"; - - if (LDP_DEBUG > 1) - clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): how %d", - getpid (), fd, fd, func_str, how); - + LDBG (1, "fd %d (0x%x): calling libc_shutdown: how %d", fd, fd, how); rv = libc_shutdown (fd, how); } - if (LDP_DEBUG > 1) - { - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), fd, fd, - func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)", - getpid (), fd, fd, rv, rv); - } return rv; } @@ -3073,12 +2880,12 @@ epoll_create1 (int flags) rv = libc_epoll_create1 (flags); ldp->vcl_needs_real_epoll = 0; ldpw->vcl_mq_epfd = rv; - LDBG (0, "LDP<%d>: created vcl epfd %u", getpid (), rv); + LDBG (0, "created vcl epfd %u", rv); return rv; } func_str = "vppcom_epoll_create"; - LDBG (1, "LDP<%d>: calling %s()", getpid (), func_str); + LDBG (1, "calling %s()", func_str); rv = vppcom_epoll_create (); @@ -3116,7 +2923,7 @@ epoll_create (int size) int epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) { - u32 vep_idx = ldp_sid_from_fd (epfd), sid; + u32 vep_idx = ldp_sh_from_fd (epfd), sid; const char *func_str; int rv; @@ -3132,24 +2939,24 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) */ func_str = "libc_epoll_ctl"; - LDBG (1, "LDP<%d>: epfd %d (0x%x): calling %s(): op %d, fd %d (0x%x)," - " event %p", getpid (), epfd, epfd, func_str, op, fd, fd, event); + LDBG (1, "epfd %d (0x%x): calling %s(): op %d, fd %d (0x%x)," + " event %p", epfd, epfd, func_str, op, fd, fd, event); rv = libc_epoll_ctl (epfd, op, fd, event); goto done; } - sid = ldp_sid_from_fd (fd); + sid = ldp_sh_from_fd (fd); - LDBG (0, "LDP<%d>: epfd %d (0x%x), vep_idx %d (0x%x), sid %d (0x%x)", - getpid (), epfd, epfd, vep_idx, vep_idx, sid, sid); + LDBG (0, "epfd %d (0x%x), vep_idx %d (0x%x), sid %d (0x%x)", + epfd, epfd, vep_idx, vep_idx, sid, sid); if (sid != INVALID_SESSION_ID) { func_str = "vppcom_epoll_ctl"; - LDBG (1, "LDP<%d>: epfd %d (0x%x): calling %s(): vep_idx %d (0x%x)," - " op %d, sid %u (0x%x), event %p", getpid (), epfd, epfd, + LDBG (1, "epfd %d (0x%x): calling %s(): vep_idx %d (0x%x)," + " op %d, sid %u (0x%x), event %p", epfd, epfd, func_str, vep_idx, vep_idx, sid, sid, event); rv = vppcom_epoll_ctl (vep_idx, op, sid, event); @@ -3167,16 +2974,16 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) func_str = "vppcom_session_attr[GET_LIBC_EPFD]"; libc_epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0); - LDBG (1, "LDP<%d>: epfd %d (0x%x), vep_idx %d (0x%x): %s() " - "returned libc_epfd %d (0x%x)", getpid (), epfd, epfd, + LDBG (1, "epfd %d (0x%x), vep_idx %d (0x%x): %s() " + "returned libc_epfd %d (0x%x)", epfd, epfd, vep_idx, vep_idx, func_str, libc_epfd, libc_epfd); if (!libc_epfd) { func_str = "libc_epoll_create1"; - LDBG (1, "LDP<%d>: epfd %d (0x%x), vep_idx %d (0x%x): " - "calling %s(): EPOLL_CLOEXEC", getpid (), epfd, epfd, + LDBG (1, "epfd %d (0x%x), vep_idx %d (0x%x): " + "calling %s(): EPOLL_CLOEXEC", epfd, epfd, vep_idx, vep_idx, func_str); libc_epfd = libc_epoll_create1 (EPOLL_CLOEXEC); @@ -3187,9 +2994,9 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) } func_str = "vppcom_session_attr[SET_LIBC_EPFD]"; - LDBG (1, "LDP<%d>: epfd %d (0x%x): calling %s(): vep_idx %d (0x%x)," + LDBG (1, "epfd %d (0x%x): calling %s(): vep_idx %d (0x%x)," " VPPCOM_ATTR_SET_LIBC_EPFD, libc_epfd %d (0x%x), size %d", - getpid (), epfd, epfd, func_str, vep_idx, vep_idx, libc_epfd, + epfd, epfd, func_str, vep_idx, vep_idx, libc_epfd, libc_epfd, size); rv = vppcom_session_attr (vep_idx, VPPCOM_ATTR_SET_LIBC_EPFD, @@ -3210,8 +3017,8 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) func_str = "libc_epoll_ctl"; - LDBG (1, "LDP<%d>: epfd %d (0x%x): calling %s(): libc_epfd %d (0x%x), " - "op %d, fd %d (0x%x), event %p", getpid (), epfd, epfd, func_str, + LDBG (1, "epfd %d (0x%x): calling %s(): libc_epfd %d (0x%x), " + "op %d, fd %d (0x%x), event %p", epfd, epfd, func_str, libc_epfd, libc_epfd, op, fd, fd, event); rv = libc_epoll_ctl (libc_epfd, op, fd, event); @@ -3242,9 +3049,8 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, { ldp_worker_ctx_t *ldpw = ldp_worker_get_current (); double time_to_wait = (double) 0, time_out, now = 0; - u32 vep_idx = ldp_sid_from_fd (epfd); + u32 vep_idx = ldp_sh_from_fd (epfd); int libc_epfd, rv = 0; - const char *func_str; if ((errno = -ldp_init ())) return -1; @@ -3260,16 +3066,15 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, if (PREDICT_FALSE (vep_idx == INVALID_SESSION_ID)) { - clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): bad vep_idx %d (0x%x)!", - getpid (), epfd, epfd, vep_idx, vep_idx); + LDBG (0, "epfd %d (0x%x): bad vep_idx %d (0x%x)!", epfd, epfd, vep_idx, + vep_idx); errno = EBADFD; return -1; } - time_to_wait = ((timeout >= 0) ? (double) timeout : 0); + time_to_wait = ((timeout >= 0) ? (double) timeout / 1000 : 0); time_out = clib_time_now (&ldpw->clib_time) + time_to_wait; - func_str = "vppcom_session_attr[GET_LIBC_EPFD]"; libc_epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0); if (PREDICT_FALSE (libc_epfd < 0)) { @@ -3278,19 +3083,17 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, goto done; } - LDBG (2, "LDP<%d>: epfd %d (0x%x): vep_idx %d (0x%x), libc_epfd %d (0x%x), " + LDBG (2, "epfd %d (0x%x): vep_idx %d (0x%x), libc_epfd %d (0x%x), " "events %p, maxevents %d, timeout %d, sigmask %p: time_to_wait %.02f", - getpid (), epfd, epfd, vep_idx, vep_idx, libc_epfd, libc_epfd, events, + epfd, epfd, vep_idx, vep_idx, libc_epfd, libc_epfd, events, maxevents, timeout, sigmask, time_to_wait, time_out); do { if (!ldpw->epoll_wait_vcl) { - func_str = "vppcom_epoll_wait"; - - LDBG (3, "LDP<%d>: epfd %d (0x%x): calling %s(): vep_idx %d (0x%x)," - " events %p, maxevents %d", getpid (), epfd, epfd, func_str, - vep_idx, vep_idx, events, maxevents); + LDBG (3, "epfd %d (0x%x): calling vcl_epoll_wait: vep_idx %d (0x%x)" + " events %p, maxevents %d", epfd, epfd, vep_idx, vep_idx, + events, maxevents); rv = vppcom_epoll_wait (vep_idx, events, maxevents, 0); if (rv > 0) @@ -3310,14 +3113,11 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, if (libc_epfd > 0) { - func_str = "libc_epoll_pwait"; + LDBG (3, "epfd %d (0x%x): calling libc_epoll_wait: libc_epfd %d " + "(0x%x), events %p, maxevents %d, sigmask %p", epfd, epfd, + libc_epfd, libc_epfd, events, maxevents, sigmask); - LDBG (3, "LDP<%d>: epfd %d (0x%x): calling %s(): libc_epfd %d " - "(0x%x), events %p, maxevents %d, sigmask %p", getpid (), - epfd, epfd, func_str, libc_epfd, libc_epfd, events, - maxevents, sigmask); - - rv = libc_epoll_pwait (libc_epfd, events, maxevents, 1, sigmask); + rv = libc_epoll_pwait (libc_epfd, events, maxevents, 0, sigmask); if (rv != 0) goto done; } @@ -3328,23 +3128,6 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents, while (now < time_out); done: - if (LDP_DEBUG > 3) - { - if (libc_epfd > 0) - epfd = libc_epfd; - if (rv < 0) - { - int errno_val = errno; - perror (func_str); - clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): %s() failed! " - "rv %d, errno = %d", getpid (), epfd, epfd, - func_str, rv, errno_val); - errno = errno_val; - } - else - clib_warning ("LDP<%d>: epfd %d (0x%x): returning %d (0x%x)", - getpid (), epfd, epfd, rv, rv); - } return rv; } @@ -3371,8 +3154,7 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) vcl_poll_t *vp; double wait_for_time; - LDBG (3, "LDP<%d>: fds %p, nfds %d, timeout %d", getpid (), fds, nfds, - timeout); + LDBG (3, "fds %p, nfds %d, timeout %d", fds, nfds, timeout); if (timeout >= 0) wait_for_time = (f64) timeout / 1000; @@ -3384,11 +3166,10 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) if (fds[i].fd < 0) continue; - LDBG (3, "LDP<%d>: fds[%d] fd %d (0x%0x) events = 0x%x revents = 0x%x", - getpid (), i, fds[i].fd, fds[i].fd, fds[i].events, - fds[i].revents); + LDBG (3, "fds[%d] fd %d (0x%0x) events = 0x%x revents = 0x%x", + i, fds[i].fd, fds[i].fd, fds[i].events, fds[i].revents); - sid = ldp_sid_from_fd (fds[i].fd); + sid = ldp_sh_from_fd (fds[i].fd); if (sid != INVALID_SESSION_ID) { fds[i].fd = -fds[i].fd; @@ -3417,8 +3198,8 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) { func_str = "vppcom_poll"; - LDBG (3, "LDP<%d>: calling %s(): vcl_poll %p, n_sids %u (0x%x): " - "n_libc_fds %u", getpid (), func_str, ldpw->vcl_poll, + LDBG (3, "calling %s(): vcl_poll %p, n_sids %u (0x%x): " + "n_libc_fds %u", func_str, ldpw->vcl_poll, vec_len (ldpw->vcl_poll), vec_len (ldpw->vcl_poll), vec_len (ldpw->libc_poll)); @@ -3437,8 +3218,8 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) { func_str = "libc_poll"; - LDBG (3, "LDP<%d>: calling %s(): fds %p, nfds %u: n_sids %u", - getpid (), fds, nfds, vec_len (ldpw->vcl_poll)); + LDBG (3, "calling %s(): fds %p, nfds %u: n_sids %u", + fds, nfds, vec_len (ldpw->vcl_poll)); rv = libc_poll (ldpw->libc_poll, vec_len (ldpw->libc_poll), 0); if (rv < 0)