Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anodos325 committed Oct 21, 2023
1 parent 6ae1ee3 commit db9e0f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lib/tevent/tevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ static void tevent_backend_init(void)
tevent_poll_init();
tevent_poll_mt_init();
#if defined(HAVE_EPOLL)
tevent_epoll_init();
//tevent_epoll_init();
tevent_libaio_init();
#elif defined(HAVE_SOLARIS_PORTS)
tevent_port_init();
#elif defined(HAVE_KQUEUE)
Expand Down
4 changes: 2 additions & 2 deletions lib/tevent/tevent_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ bool tevent_poll_event_add_fd_internal(struct tevent_context *ev,
struct tevent_fd *fde);
bool tevent_poll_mt_init(void);
#ifdef HAVE_EPOLL
bool tevent_epoll_init(void);
void tevent_epoll_set_panic_fallback(struct tevent_context *ev,
bool tevent_libaio_init(void);
void tevent_libaio_set_panic_fallback(struct tevent_context *ev,
bool (*panic_fallback)(struct tevent_context *ev,
bool replay));
#endif
Expand Down
39 changes: 24 additions & 15 deletions lib/tevent/tevent_libaio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ typedef struct libaio_event_context {
struct tevent_context *ev;
io_context_t *ctx;
pid_t pid;

bool panic_force_replay;
bool *panic_state;
bool (*panic_fallback)(struct tevent_context *ev, bool replay);
Expand Down Expand Up @@ -92,6 +91,22 @@ static void libaio_panic(libaio_ev_ctx_t *libaio_ev,
}
}

static int libaio_poll(io_context_t *ctx,
struct iocb *iocb,
struct tevent_fd *fde,
int events)
{
*iocb = (struct iocb) {
.aio_fildes = fde->fd,
.aio_lio_opcode = IO_CMD_POLL,
.aio_reqprio = 0,
.u.poll.events = events
.data = (void*)fde
};

return io_submit(ctx, 1, &iocb);
}

/*
map from TEVENT_FD_* to poll flags
*/
Expand All @@ -111,12 +126,14 @@ static int libaio_ctx_destructor(libaio_ev_ctx_t *libaio_ev)
{
int error;

// io_queue_release() states that it _may_ cancel pending
// iocbs.
error = io_queue_release(libaio_ev->ctx);
if (error) {
errno = -error;
}
libaio_ev->ctx = NULL;

libaio_ev->ctx = NULL;
return 0;
}

Expand Down Expand Up @@ -240,7 +257,7 @@ static int libaio_add_multiplex_fd(nlibaio_ev_ctx_t *libaio_ev,
/* Modify the mpx_fde to add in the new flags. */
pollflags = libaio_map_flags(mpx_fde->flags | add_fde->flags);

ret = io_poll(libaio_ev->ctx, &aiocb, NULL, mpx_fde->fd, pollflags);
ret = libaio_poll(libaio_ev->ctx, &aiocb, mpx_fde, pollflags);
if (ret != 0 && errno == EBADF) {
tevent_debug(libaio_ev->ev, TEVENT_DEBUG_ERROR,
"io_poll() failed with EBADF for "
Expand Down Expand Up @@ -300,7 +317,7 @@ static void libaio_add_event(libaio_ev_ctx_t *libaio_ev, struct tevent_fd *fde)

pollflags = libaio_map_flags(mpx_fde->flags | add_fde->flags);

ret = io_poll(libaio_ev->ctx, &aiocb, NULL, fde->fd, pollflags);
ret = libaio_poll(libaio_ev->ctx, &aiocb, fde, pollflags);
if (ret != 0 && errno == EBADF) {
tevent_debug(libaio_ev->ev, TEVENT_DEBUG_ERROR,
"io_poll() EBADF for "
Expand Down Expand Up @@ -396,7 +413,7 @@ static void libaio_mod_event(libaio_ev_ctx_t *libaio_ev, struct tevent_fd *fde)
pollflags |= libaio_map_flags(mpx_fde->flags);
}

ret = io_poll(libaio_ev->ctx, &aiocb, NULL, fde->fd, pollflags);
ret = libaio_poll(libaio_ev->ctx, &aiocb, fde, pollflags);
if (ret != 0 && errno == EBADF) {
tevent_debug(libaio_ev->ev, TEVENT_DEBUG_ERROR,
"io_poll() EBADF for "
Expand Down Expand Up @@ -503,17 +520,9 @@ static bool libaio_handle_hup_or_err(libaio_ev_ctx_t *libaio_ev,
static int process_poll_event(libaio_ev_ctx_t *libaio_ev, struct iocb *aiocb)
{
struct tevent_fd *fde = NULL, *mpx_fde = NULL;
uint16_t pollret = aiocb->u.poll;

for (fde = ev->fd_events; fde; fde = next) {
if (fde->fd == aiocb->aio_fildes) {
break;
}
}
int pollret = aiocb->u.poll.events;

if (fde == NULL) {
abort();
}
fde = talloc_get_type_abort(aiocb->data, struct tevent_fd);

if (fde->additional_flags & LIBAIO_ADDITIONAL_FD_FLAG_HAS_MPX) {
/*
Expand Down
2 changes: 1 addition & 1 deletion lib/tevent/tevent_standard.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int std_event_context_init(struct tevent_context *ev)
goto fallback;
}
#ifdef HAVE_EPOLL
tevent_epoll_set_panic_fallback(ev, std_fallback_to_poll);
tevent_libaio_set_panic_fallback(ev, std_fallback_to_poll);
#endif
#ifdef HAVE_KQUEUE
tevent_kqueue_set_panic_fallback(ev, std_fallback_to_poll);
Expand Down

0 comments on commit db9e0f7

Please sign in to comment.