aboutsummaryrefslogtreecommitdiffstats
path: root/extras/libmemif/src
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2021-01-04 10:39:30 +0100
committerDamjan Marion <dmarion@me.com>2021-09-27 14:35:45 +0000
commit45cf1fc3f58ee465d2e7e4689158e79fd706658e (patch)
tree78449dda3a1e6e62344dc1e51e80b50650a89e23 /extras/libmemif/src
parent9f99e9a60e31f558f9eb5f8e3762d7a97bde67a8 (diff)
libmemif: remove per_thread_ namespace
Type: refactor Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: Ib5a88132ad28860553fc82f5aaaf84e0a1b8e8bf
Diffstat (limited to 'extras/libmemif/src')
-rw-r--r--extras/libmemif/src/libmemif.h95
-rw-r--r--extras/libmemif/src/main.c468
2 files changed, 1 insertions, 562 deletions
diff --git a/extras/libmemif/src/libmemif.h b/extras/libmemif/src/libmemif.h
index 12d2f1e3af4..f9e3dcd09b3 100644
--- a/extras/libmemif/src/libmemif.h
+++ b/extras/libmemif/src/libmemif.h
@@ -23,7 +23,7 @@
#define _LIBMEMIF_H_
/** Libmemif version. */
-#define LIBMEMIF_VERSION "3.1"
+#define LIBMEMIF_VERSION "4.0"
/** Default name of application using libmemif. */
#define MEMIF_DEFAULT_APP_NAME "libmemif-app"
@@ -98,12 +98,6 @@ typedef enum
#define MEMIF_FD_EVENT_MOD (1 << 4)
/** @} */
-/** \brief Memif per thread main handle
- Pointer of type void, pointing to internal structure.
- Used to identify internal per thread database.
-*/
-typedef void *memif_per_thread_main_handle_t;
-
/** \brief Memif connection handle
pointer of type void, pointing to internal structure
*/
@@ -498,28 +492,6 @@ int memif_init (memif_control_fd_update_t * on_control_fd_update,
char *app_name, memif_alloc_t * memif_alloc,
memif_realloc_t * memif_realloc, memif_free_t * memif_free);
-/** \brief Memif per thread initialization
- @param pt_main - per thread main handle
- @param private_ctx - private context
- @param on_control_fd_update - if control fd updates inform user to watch new fd
- @param app_name - application name (will be truncated to 32 chars)
- @param memif_alloc - custom memory allocator, NULL = default
- @param memif_realloc - custom memory reallocation, NULL = default
- @param memif_free - custom memory free, NULL = default
-
- Per thread version of memif_init ().
- Instead of using global database, creates and initializes unique database,
- identified by 'memif_per_thread_main_handle_t'.
-
- \return memif_err_t
-*/
-int memif_per_thread_init (memif_per_thread_main_handle_t * pt_main,
- void *private_ctx,
- memif_control_fd_update_t * on_control_fd_update,
- char *app_name, memif_alloc_t * memif_alloc,
- memif_realloc_t * memif_realloc,
- memif_free_t * memif_free);
-
/** \brief Memif cleanup
Free libmemif internal allocations.
@@ -528,15 +500,6 @@ int memif_per_thread_init (memif_per_thread_main_handle_t * pt_main,
*/
int memif_cleanup ();
-/** \brief Memif per thread cleanup
- @param pt_main - per thread main handle
-
- Free libmemif internal allocations and sets the handle to NULL.
-
- \return memif_err_t
-*/
-int memif_per_thread_cleanup (memif_per_thread_main_handle_t * pt_main);
-
/** \brief Memory interface create function
@param conn - connection handle for client app
@param args - memory interface connection arguments
@@ -585,19 +548,6 @@ int memif_create (memif_conn_handle_t * conn, memif_conn_args_t * args,
*/
int memif_control_fd_handler (int fd, uint8_t events);
-/** \brief Memif per thread control file descriptor handler
- @param pt_main - per thread main handle
- @param fd - file descriptor on which the event occurred
- @param events - event type(s) that occurred
-
- Per thread version of memif_control_fd_handler.
-
- \return memif_err_t
-
-*/
-int memif_per_thread_control_fd_handler (memif_per_thread_main_handle_t
- pt_main, int fd, uint8_t events);
-
/** \brief Memif delete
@param conn - pointer to memif connection handle
@@ -714,13 +664,6 @@ int memif_poll_event (int timeout);
@param pt_main - per thread main handle
@param timeout - timeout in seconds
- Per thread version of memif_poll_event.
-
- \return memif_err_t
-*/
-int memif_per_thread_poll_event (memif_per_thread_main_handle_t pt_main,
- int timeout);
-
/** \brief Send signal to stop concurrently running memif_poll_event().
The function, however, does not wait for memif_poll_event() to stop.
@@ -735,15 +678,6 @@ int memif_per_thread_poll_event (memif_per_thread_main_handle_t pt_main,
*/
#define MEMIF_HAVE_CANCEL_POLL_EVENT 1
int memif_cancel_poll_event ();
-/** \brief Send signal to stop concurrently running memif_poll_event().
- @param pt_main - per thread main handle
-
- Per thread version of memif_cancel_poll_event.
-
- \return memif_err_t
-*/
-int memif_per_thread_cancel_poll_event (memif_per_thread_main_handle_t
- pt_main);
/** \brief Set connection request timer value
@param timer - new timer value
@@ -755,19 +689,6 @@ int memif_per_thread_cancel_poll_event (memif_per_thread_main_handle_t
*/
int memif_set_connection_request_timer (struct itimerspec timer);
-/** \brief Set connection request timer value
- @param pt_main - per thread main handle
- @param timer - new timer value
-
- Per thread version of memif_set_connection_request_timer
-
- \return memif_err_t
-*/
-int
-memif_per_thread_set_connection_request_timer (memif_per_thread_main_handle_t
- pt_main,
- struct itimerspec timer);
-
/** \brief Send connection request
@param conn - memif connection handle
@@ -794,20 +715,6 @@ int memif_request_connection (memif_conn_handle_t conn);
int memif_create_socket (memif_socket_handle_t * sock, const char *filename,
void *private_ctx);
-/** \brief Create memif socket
- @param pt_main - per thread main handle
- @param sock - socket handle for client app
- @param filename - path to socket file
- @param private_ctx - private context
-
- Per thread version of memif_create_socket.
-
- \return memif_err_t
-*/
-int memif_per_thread_create_socket (memif_per_thread_main_handle_t pt_main,
- memif_socket_handle_t * sock,
- const char *filename, void *private_ctx);
-
/** \brief Delete memif socket
@param sock - socket handle for client app
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index e70334ae40f..967e033cda3 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -478,27 +478,6 @@ memif_set_connection_request_timer (struct itimerspec timer)
}
int
-memif_per_thread_set_connection_request_timer (memif_per_thread_main_handle_t
- pt_main,
- struct itimerspec timer)
-{
- libmemif_main_t *lm = (libmemif_main_t *) pt_main;
- int err = MEMIF_ERR_SUCCESS;
-
- lm->arm = timer;
-
- /* overwrite timer, if already armed */
- if (lm->disconn_slaves != 0)
- {
- if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0)
- {
- err = memif_syscall_error_handler (errno);
- }
- }
- return err;
-}
-
-int
memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name,
memif_alloc_t * memif_alloc, memif_realloc_t * memif_realloc,
memif_free_t * memif_free)
@@ -646,174 +625,6 @@ error:
return err;
}
-int
-memif_per_thread_init (memif_per_thread_main_handle_t * pt_main,
- void *private_ctx,
- memif_control_fd_update_t * on_control_fd_update,
- char *app_name, memif_alloc_t * memif_alloc,
- memif_realloc_t * memif_realloc,
- memif_free_t * memif_free)
-{
- memif_err_t err = MEMIF_ERR_SUCCESS;
- int i;
- libmemif_main_t *lm;
-
- /* Allocate unique libmemif main */
- if (memif_alloc != NULL)
- lm = memif_alloc (sizeof (libmemif_main_t));
- else
- lm = malloc (sizeof (libmemif_main_t));
-
- if (lm == NULL)
- return MEMIF_ERR_NOMEM;
-
- memset (lm, 0, sizeof (libmemif_main_t));
-
- /* register custom memory management */
- if (memif_alloc != NULL)
- {
- memif_alloc_register (lm, memif_alloc);
- }
- else
- memif_alloc_register (lm, malloc);
-
- if (memif_realloc != NULL)
- {
- memif_realloc_register (lm, memif_realloc);
- }
- else
- memif_realloc_register (lm, realloc);
-
- if (memif_free != NULL)
- memif_free_register (lm, memif_free);
- else
- memif_free_register (lm, free);
-
- lm->private_ctx = private_ctx;
-
- /* set app name */
- if (app_name != NULL)
- {
- strlcpy ((char *) lm->app_name, app_name, MEMIF_NAME_LEN);
- }
- else
- {
- strlcpy ((char *) lm->app_name, MEMIF_DEFAULT_APP_NAME,
- sizeof (lm->app_name));
- }
-
- lm->poll_cancel_fd = -1;
- /* register control fd update callback */
- if (on_control_fd_update != NULL)
- memif_control_fd_update_register (lm, on_control_fd_update);
- else
- {
- /* private_ctx only used internally by memif_control_fd_update
- * pointer to this libmemif main
- */
- lm->private_ctx = lm;
- lm->epfd = epoll_create (1);
- memif_control_fd_update_register (lm, memif_control_fd_update);
- if ((lm->poll_cancel_fd = eventfd (0, EFD_NONBLOCK)) < 0)
- {
- err = errno;
- DBG ("eventfd: %s", strerror (err));
- return memif_syscall_error_handler (err);
- }
- lm->control_fd_update (lm->poll_cancel_fd, MEMIF_FD_EVENT_READ,
- lm->private_ctx);
- DBG ("libmemif event polling initialized");
- }
-
- /* Initialize lists */
- lm->control_list_len = 2;
- lm->interrupt_list_len = 2;
- lm->socket_list_len = 1;
- lm->pending_list_len = 1;
-
- lm->control_list =
- lm->alloc (sizeof (memif_list_elt_t) * lm->control_list_len);
- if (lm->control_list == NULL)
- {
- err = MEMIF_ERR_NOMEM;
- goto error;
- }
- lm->interrupt_list =
- lm->alloc (sizeof (memif_list_elt_t) * lm->interrupt_list_len);
- if (lm->interrupt_list == NULL)
- {
- err = MEMIF_ERR_NOMEM;
- goto error;
- }
- lm->socket_list =
- lm->alloc (sizeof (memif_list_elt_t) * lm->socket_list_len);
- if (lm->socket_list == NULL)
- {
- err = MEMIF_ERR_NOMEM;
- goto error;
- }
- lm->pending_list =
- lm->alloc (sizeof (memif_list_elt_t) * lm->pending_list_len);
- if (lm->pending_list == NULL)
- {
- err = MEMIF_ERR_NOMEM;
- goto error;
- }
-
- for (i = 0; i < lm->control_list_len; i++)
- {
- lm->control_list[i].key = -1;
- lm->control_list[i].data_struct = NULL;
- }
- for (i = 0; i < lm->interrupt_list_len; i++)
- {
- lm->interrupt_list[i].key = -1;
- lm->interrupt_list[i].data_struct = NULL;
- }
- for (i = 0; i < lm->socket_list_len; i++)
- {
- lm->socket_list[i].key = -1;
- lm->socket_list[i].data_struct = NULL;
- }
- for (i = 0; i < lm->pending_list_len; i++)
- {
- lm->pending_list[i].key = -1;
- lm->pending_list[i].data_struct = NULL;
- }
-
- /* Initialize autoconnect */
- lm->disconn_slaves = 0;
-
- lm->timerfd = timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK);
- if (lm->timerfd < 0)
- {
- err = memif_syscall_error_handler (errno);
- goto error;
- }
-
- lm->arm.it_value.tv_sec = MEMIF_DEFAULT_RECONNECT_PERIOD_SEC;
- lm->arm.it_value.tv_nsec = MEMIF_DEFAULT_RECONNECT_PERIOD_NSEC;
- lm->arm.it_interval.tv_sec = MEMIF_DEFAULT_RECONNECT_PERIOD_SEC;
- lm->arm.it_interval.tv_nsec = MEMIF_DEFAULT_RECONNECT_PERIOD_NSEC;
-
- if (lm->control_fd_update (lm->timerfd, MEMIF_FD_EVENT_READ,
- lm->private_ctx) < 0)
- {
- DBG ("callback type memif_control_fd_update_t error!");
- err = MEMIF_ERR_CB_FDUPDATE;
- goto error;
- }
-
- *pt_main = lm;
-
- return err;
-
-error:
- *pt_main = lm;
- memif_per_thread_cleanup (pt_main);
- return err;
-}
-
static inline memif_ring_t *
memif_get_ring (memif_connection_t * conn, memif_ring_type_t type,
uint16_t ring_num)
@@ -988,78 +799,6 @@ error:
return err;
}
-int
-memif_per_thread_create_socket (memif_per_thread_main_handle_t pt_main,
- memif_socket_handle_t * sock,
- const char *filename, void *private_ctx)
-{
- libmemif_main_t *lm = (libmemif_main_t *) pt_main;
- memif_socket_t *ms = (memif_socket_t *) * sock;
- int i, err = MEMIF_ERR_SUCCESS;
-
- if (lm == NULL)
- return MEMIF_ERR_INVAL_ARG;
-
- for (i = 0; i < lm->socket_list_len; i++)
- {
- if ((ms = (memif_socket_t *) lm->socket_list[i].data_struct) != NULL)
- {
- if (strncmp ((char *) ms->filename, filename,
- strlen ((char *) ms->filename)) == 0)
- return MEMIF_ERR_INVAL_ARG;
- }
- }
-
- /* allocate memif_socket_t */
- ms = NULL;
- ms = lm->alloc (sizeof (memif_socket_t));
- if (ms == NULL)
- {
- err = MEMIF_ERR_NOMEM;
- goto error;
- }
- memset (ms, 0, sizeof (memif_socket_t));
- ms->lm = lm;
- /* set filename */
- memset (ms->filename, 0, sizeof (ms->filename));
- strlcpy ((char *) ms->filename, filename, sizeof (ms->filename));
-
- ms->type = MEMIF_SOCKET_TYPE_NONE;
-
- ms->interface_list_len = 1;
- ms->interface_list =
- lm->alloc (sizeof (memif_list_elt_t) * ms->interface_list_len);
- if (ms->interface_list == NULL)
- {
- err = MEMIF_ERR_NOMEM;
- goto error;
- }
- ms->interface_list[0].key = -1;
- ms->interface_list[0].data_struct = NULL;
-
- *sock = ms;
-
- return err;
-
-error:
- if (ms != NULL)
- {
- if (ms->fd > 0)
- {
- close (ms->fd);
- ms->fd = -1;
- }
- if (ms->interface_list != NULL)
- {
- lm->free (ms->interface_list);
- ms->interface_list = NULL;
- ms->interface_list_len = 0;
- }
- lm->free (ms);
- *sock = ms = NULL;
- }
- return err;
-}
int
memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
@@ -1385,119 +1124,6 @@ error:
return err;
}
-int
-memif_per_thread_control_fd_handler (memif_per_thread_main_handle_t pt_main,
- int fd, uint8_t events)
-{
- int i, err = MEMIF_ERR_SUCCESS; /* 0 */
- uint16_t num;
- memif_list_elt_t *e = NULL;
- memif_connection_t *conn;
- libmemif_main_t *lm = (libmemif_main_t *) pt_main;
-
- if (fd == lm->timerfd)
- {
- uint64_t b;
- ssize_t size;
- size = read (fd, &b, sizeof (b));
-
- if (size == -1)
- goto error;
-
- for (i = 0; i < lm->control_list_len; i++)
- {
- if ((lm->control_list[i].key < 0)
- && (lm->control_list[i].data_struct != NULL))
- {
- conn = lm->control_list[i].data_struct;
- if (conn->args.is_master)
- continue;
- err = memif_request_connection (conn);
- if (err != MEMIF_ERR_SUCCESS)
- DBG ("memif_request_connection: %s", memif_strerror (err));
- }
- }
- }
- else
- {
- get_list_elt (&e, lm->interrupt_list, lm->interrupt_list_len, fd);
- if (e != NULL)
- {
- if (((memif_connection_t *) e->data_struct)->on_interrupt != NULL)
- {
- num =
- (((memif_connection_t *) e->data_struct)->
- args.is_master) ? ((memif_connection_t *) e->
- data_struct)->run_args.
- num_s2m_rings : ((memif_connection_t *) e->data_struct)->
- run_args.num_m2s_rings;
- for (i = 0; i < num; i++)
- {
- if (((memif_connection_t *) e->data_struct)->
- rx_queues[i].int_fd == fd)
- {
- ((memif_connection_t *) e->data_struct)->
- on_interrupt ((void *) e->data_struct,
- ((memif_connection_t *) e->
- data_struct)->private_ctx, i);
- return MEMIF_ERR_SUCCESS;
- }
- }
- }
- return MEMIF_ERR_SUCCESS;
- }
- get_list_elt (&e, lm->socket_list, lm->socket_list_len, fd);
- if (e != NULL
- && ((memif_socket_t *) e->data_struct)->type ==
- MEMIF_SOCKET_TYPE_LISTENER)
- {
- err =
- memif_conn_fd_accept_ready ((memif_socket_t *) e->data_struct);
- return err;
- }
-
- get_list_elt (&e, lm->pending_list, lm->pending_list_len, fd);
- if (e != NULL)
- {
- err = memif_read_ready (lm, fd);
- return err;
- }
-
- get_list_elt (&e, lm->control_list, lm->control_list_len, fd);
- if (e != NULL)
- {
- if (events & MEMIF_FD_EVENT_READ)
- {
- err =
- ((memif_connection_t *) e->data_struct)->
- read_fn (e->data_struct);
- if (err != MEMIF_ERR_SUCCESS)
- return err;
- }
- if (events & MEMIF_FD_EVENT_WRITE)
- {
- err =
- ((memif_connection_t *) e->data_struct)->
- write_fn (e->data_struct);
- if (err != MEMIF_ERR_SUCCESS)
- return err;
- }
- if (events & MEMIF_FD_EVENT_ERROR)
- {
- err =
- ((memif_connection_t *) e->data_struct)->
- error_fn (e->data_struct);
- if (err != MEMIF_ERR_SUCCESS)
- return err;
- }
- }
- }
-
- return MEMIF_ERR_SUCCESS; /* 0 */
-
-error:
- return err;
-}
int
memif_poll_event (int timeout)
@@ -1542,49 +1168,6 @@ memif_poll_event (int timeout)
}
int
-memif_per_thread_poll_event (memif_per_thread_main_handle_t pt_main,
- int timeout)
-{
- libmemif_main_t *lm = (libmemif_main_t *) pt_main;
- struct epoll_event evt;
- int en = 0, err = MEMIF_ERR_SUCCESS; /* 0 */
- uint32_t events = 0;
- uint64_t counter = 0;
- ssize_t r = 0;
- memset (&evt, 0, sizeof (evt));
- evt.events = EPOLLIN | EPOLLOUT;
- sigset_t sigset;
- sigemptyset (&sigset);
- en = epoll_pwait (lm->epfd, &evt, 1, timeout, &sigset);
- if (en < 0)
- {
- err = errno;
- DBG ("epoll_pwait: %s", strerror (err));
- return memif_syscall_error_handler (err);
- }
- if (en > 0)
- {
- if (evt.data.fd == lm->poll_cancel_fd)
- {
- r = read (evt.data.fd, &counter, sizeof (counter));
- if (r == -1)
- return MEMIF_ERR_DISCONNECTED;
-
- return MEMIF_ERR_POLL_CANCEL;
- }
- if (evt.events & EPOLLIN)
- events |= MEMIF_FD_EVENT_READ;
- if (evt.events & EPOLLOUT)
- events |= MEMIF_FD_EVENT_WRITE;
- if (evt.events & EPOLLERR)
- events |= MEMIF_FD_EVENT_ERROR;
- err = memif_control_fd_handler (evt.data.fd, events);
- return err;
- }
- return 0;
-}
-
-int
memif_cancel_poll_event ()
{
libmemif_main_t *lm = &libmemif_main;
@@ -1600,25 +1183,6 @@ memif_cancel_poll_event ()
return 0;
}
-int
-memif_per_thread_cancel_poll_event (memif_per_thread_main_handle_t pt_main)
-{
- libmemif_main_t *lm = (libmemif_main_t *) pt_main;
- uint64_t counter = 1;
- ssize_t w = 0;
-
- if (lm == NULL)
- return MEMIF_ERR_INVAL_ARG;
-
- if (lm->poll_cancel_fd == -1)
- return 0;
- w = write (lm->poll_cancel_fd, &counter, sizeof (counter));
- if (w < sizeof (counter))
- return MEMIF_ERR_INT_WRITE;
-
- return 0;
-}
-
static void
memif_msg_queue_free (libmemif_main_t * lm, memif_msg_queue_elt_t ** e)
{
@@ -2844,35 +2408,3 @@ memif_cleanup ()
return MEMIF_ERR_SUCCESS; /* 0 */
}
-
-int
-memif_per_thread_cleanup (memif_per_thread_main_handle_t * pt_main)
-{
- libmemif_main_t *lm = (libmemif_main_t *) * pt_main;
-
- if (lm == NULL)
- return MEMIF_ERR_INVAL_ARG;
-
- /* No default socket in case of per thread */
-
- if (lm->control_list)
- lm->free (lm->control_list);
- lm->control_list = NULL;
- if (lm->interrupt_list)
- lm->free (lm->interrupt_list);
- lm->interrupt_list = NULL;
- if (lm->socket_list)
- lm->free (lm->socket_list);
- lm->socket_list = NULL;
- if (lm->pending_list)
- lm->free (lm->pending_list);
- lm->pending_list = NULL;
- if (lm->poll_cancel_fd != -1)
- close (lm->poll_cancel_fd);
-
- lm->free (lm);
-
- *pt_main = NULL;
-
- return MEMIF_ERR_SUCCESS; /* 0 */
-}