aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2019-11-14 10:47:25 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-08-07 20:49:18 +0000
commitffa14d74beb6d732ab243117084d6deaa11abe3b (patch)
tree2bade6bf8d2298c258fd1e27337213116d952f0b
parentbe50f64a751e86f06277dcfadd302c5311cf7634 (diff)
libmemif: memif_control_fd_update always pass context from libmemif_main
Event polling instance is always identified by libmemif main private context. Fixes event polling handled by libmemif. Type: fix Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: I51dcdb279b18f8ce97bad3b2695848e0b25a232d (cherry picked from commit 6f090fa1fa44bb2de0565bbedb2756e37ea35040)
-rw-r--r--extras/libmemif/src/libmemif.h5
-rw-r--r--extras/libmemif/src/main.c27
-rw-r--r--extras/libmemif/src/socket.c8
3 files changed, 23 insertions, 17 deletions
diff --git a/extras/libmemif/src/libmemif.h b/extras/libmemif/src/libmemif.h
index 609b98a7ba4..244c3fe2b72 100644
--- a/extras/libmemif/src/libmemif.h
+++ b/extras/libmemif/src/libmemif.h
@@ -145,9 +145,14 @@ typedef void (memif_free_t) (void *ptr);
/** \brief Memif control file descriptor update (callback function)
@param fd - new file descriptor to watch
@param events - event type(s) to watch for
+ @param private_ctx - libmemif main private context. Is NULL for
+ libmemif main created by memif_init()
+
This callback is called when there is new fd to watch for events on
or if fd is about to be closed (user mey want to stop watching for events on this fd).
+ Private context is taken from libmemif_main, 'private_ctx' passed to memif_per_thread_init()
+ or NULL in case of memif_init()
*/
typedef int (memif_control_fd_update_t) (int fd, uint8_t events,
void *private_ctx);
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index dde5aff8030..0c4adc256a2 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -309,10 +309,7 @@ memif_control_fd_update (int fd, uint8_t events, void *private_ctx)
{
libmemif_main_t *lm;
- if (private_ctx == NULL)
- return MEMIF_ERR_INVAL_ARG;
-
- lm = (libmemif_main_t *) private_ctx;
+ lm = (private_ctx == NULL) ? &libmemif_main : (libmemif_main_t *) private_ctx;
if (events & MEMIF_FD_EVENT_DEL)
return memif_del_epoll_fd (lm, fd);
@@ -559,7 +556,7 @@ memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name,
DBG ("eventfd: %s", strerror (err));
return memif_syscall_error_handler (err);
}
- lm->control_fd_update (lm->poll_cancel_fd, MEMIF_FD_EVENT_READ, NULL);
+ lm->control_fd_update (lm->poll_cancel_fd, MEMIF_FD_EVENT_READ, lm->private_ctx);
DBG ("libmemif event polling initialized");
}
@@ -633,7 +630,7 @@ memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name,
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, NULL) < 0)
+ 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;
@@ -718,6 +715,10 @@ memif_per_thread_init (memif_per_thread_main_handle_t * pt_main,
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)
@@ -911,7 +912,8 @@ memif_socket_start_listening (memif_socket_t * ms)
elt.key = ms->fd;
elt.data_struct = ms;
add_list_elt (lm, &elt, &lm->socket_list, &lm->socket_list_len);
- lm->control_fd_update (ms->fd, MEMIF_FD_EVENT_READ, ms->private_ctx);
+ /* if lm->private_ctx == lm event polling is done by libmemif */
+ lm->control_fd_update (ms->fd, MEMIF_FD_EVENT_READ, lm->private_ctx);
ms->type = MEMIF_SOCKET_TYPE_LISTENER;
@@ -1269,10 +1271,9 @@ memif_request_connection (memif_conn_handle_t c)
conn->error_fn = memif_conn_fd_error;
lm->control_list[conn->index].key = conn->fd;
-
lm->control_fd_update (sockfd,
MEMIF_FD_EVENT_READ |
- MEMIF_FD_EVENT_WRITE, conn->private_ctx);
+ MEMIF_FD_EVENT_WRITE, lm->private_ctx);
lm->disconn_slaves--;
if (lm->disconn_slaves == 0)
@@ -1681,7 +1682,7 @@ memif_disconnect_internal (memif_connection_t * c)
if (c->fd > 0)
{
memif_msg_send_disconnect (c->fd, (uint8_t *) "interface deleted", 0);
- lm->control_fd_update (c->fd, MEMIF_FD_EVENT_DEL, c->private_ctx);
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_DEL, lm->private_ctx);
close (c->fd);
}
get_list_elt (&e, lm->control_list, lm->control_list_len, c->fd);
@@ -1722,7 +1723,7 @@ memif_disconnect_internal (memif_connection_t * c)
{
if (c->on_interrupt != NULL)
lm->control_fd_update (mq->int_fd, MEMIF_FD_EVENT_DEL,
- c->private_ctx);
+ lm->private_ctx);
close (mq->int_fd);
}
free_list_elt (lm->interrupt_list, lm->interrupt_list_len,
@@ -1846,7 +1847,7 @@ memif_delete (memif_conn_handle_t * conn)
/* stop listening on this socket */
if (ms->type == MEMIF_SOCKET_TYPE_LISTENER)
{
- lm->control_fd_update (ms->fd, MEMIF_FD_EVENT_DEL, ms->private_ctx);
+ lm->control_fd_update (ms->fd, MEMIF_FD_EVENT_DEL, lm->private_ctx);
free_list_elt (lm->socket_list, lm->socket_list_len, ms->fd);
close (ms->fd);
ms->fd = -1;
@@ -1952,7 +1953,7 @@ memif_connect1 (memif_connection_t * c)
}
lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD,
- c->private_ctx);
+ lm->private_ctx);
return 0;
}
diff --git a/extras/libmemif/src/socket.c b/extras/libmemif/src/socket.c
index 2ea6fabc58b..41bb22b570d 100644
--- a/extras/libmemif/src/socket.c
+++ b/extras/libmemif/src/socket.c
@@ -471,7 +471,7 @@ memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
error:
memif_msg_send_disconnect (fd, err_string, 0);
- lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL, c->private_ctx);
+ lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL, lm->private_ctx);
free_list_elt (lm->pending_list, lm->pending_list_len, fd);
close (fd);
fd = -1;
@@ -602,7 +602,7 @@ memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
&lm->interrupt_list_len);
lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ,
- c->private_ctx);
+ lm->private_ctx);
}
}
@@ -633,7 +633,7 @@ memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
for (i = 0; i < c->run_args.num_s2m_rings; i++)
{
lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ,
- c->private_ctx);
+ lm->private_ctx);
}
}
@@ -892,7 +892,7 @@ memif_conn_fd_accept_ready (memif_socket_t * ms)
add_list_elt (lm, &elt, &lm->pending_list, &lm->pending_list_len);
lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE,
- ms->private_ctx);
+ lm->private_ctx);
return memif_msg_send_hello (lm, conn_fd);
}