summaryrefslogtreecommitdiff
path: root/uring.c
diff options
context:
space:
mode:
Diffstat (limited to 'uring.c')
-rw-r--r--uring.c115
1 files changed, 85 insertions, 30 deletions
diff --git a/uring.c b/uring.c
index 37b65eb..dc095c8 100644
--- a/uring.c
+++ b/uring.c
@@ -88,11 +88,11 @@ uring_task_refdump(struct uring_task *task)
void
uring_task_destroy(struct cfg *cfg, struct uring_task *task)
{
- fprintf(stderr, "%s: called (task: %s (%p), fd: %i, refcount: %u)\n",
- __func__, task->name, task, task->fd, task->refcount);
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
if (!task) {
- error("%s: called with no task\n", __func__);
+ error("called with no task\n");
return;
}
@@ -156,6 +156,9 @@ uring_task_get(struct cfg *cfg, struct uring_task *task)
void
uring_task_set_buf(struct uring_task *task, struct uring_task_buf *tbuf)
{
+ debug(DBG_UR, "task %s (%p), buf %p, refcount %u\n",
+ task->name, task, tbuf, task->refcount);
+
if (tbuf) {
/* iov_len and msg_namelen are set at send/receive time */
tbuf->iov.iov_base = tbuf->buf;
@@ -172,16 +175,17 @@ uring_task_set_buf(struct uring_task *task, struct uring_task_buf *tbuf)
void
uring_task_set_fd(struct uring_task *task, int fd)
{
- fprintf(stderr, "%s: task %s (%p) now uses fd %i\n",
- __func__, task->name, task, fd);
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, fd, task->refcount);
+
task->fd = fd;
}
void
uring_task_close_fd(struct cfg *cfg, struct uring_task *task)
{
- fprintf(stderr, "%s: called with task %s (0x%p)\n",
- __func__, task->name, task);
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
if (task->fd < 0)
return;
@@ -225,8 +229,10 @@ uring_task_init(struct uring_task *task, const char *name,
task->tbuf = NULL;
if (task->parent) {
- fprintf(stderr, "%s: task %s (%p) getting parent %s (%p)\n",
- __func__, task->name, task, task->parent->name, task->parent);
+ debug(DBG_REF, "task %s (%p), refcount %u, "
+ "getting parent %s (%p), refcount %u\n",
+ task->name, task, task->refcount,
+ task->parent->name, task->parent, task->parent->refcount);
uring_task_get(NULL, task->parent);
}
}
@@ -236,10 +242,11 @@ uring_close(struct cfg *cfg, struct uring_task *task, int fd)
{
struct io_uring_sqe *sqe;
- fprintf(stderr, "%s: called (task: %p (%s), fd: %i)\n", __func__, task, task->name, fd);
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
if (!task || fd < 0) {
- error("%s: invalid parameters (task: %p (%s), fd: %i)\n", __func__, task, task->name, fd);
+ error("invalid parameters (task: %p (%s), fd: %i)\n", task, task->name, fd);
return;
}
@@ -256,6 +263,9 @@ uring_tbuf_write_cb(struct cfg *cfg, struct uring_task *task, int res)
if (!task || !task->tbuf || !task->final_callback)
die("missing parameters");
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
if (res < 0) {
r = res;
goto finished;
@@ -282,10 +292,13 @@ void
uring_tbuf_write(struct cfg *cfg, struct uring_task *task, callback_t callback)
{
if (!task || task->fd < 0 || !task->tbuf || task->tbuf->len < 0) {
- error("%s invalid parameters\n", __func__);
+ error("invalid parameters\n");
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
task->tbuf->done = 0;
task->final_callback = callback;
uring_write(cfg, task, &task->tbuf->buf, task->tbuf->len, uring_tbuf_write_cb);
@@ -297,10 +310,13 @@ uring_write(struct cfg *cfg, struct uring_task *task, void *buf, size_t len, cal
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("uring_write called with no fd set\n");
+ error("no fd set\n");
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->callback = callback;
io_uring_prep_write(sqe, task->fd, buf, len, 0);
@@ -313,10 +329,13 @@ uring_tbuf_read_until_cb(struct cfg *cfg, struct uring_task *task, int res)
int r;
if (!task || !task->tbuf || !task->final_callback || !task->complete_callback) {
- error("%s: invalid parameters\n", __func__);
+ error("invalid parameters\n");
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
if (res < 0) {
r = res;
goto finished;
@@ -357,6 +376,9 @@ uring_tbuf_read_until(struct cfg *cfg, struct uring_task *task,
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
task->tbuf->len = 0;
task->complete_callback = complete;
task->final_callback = callback;
@@ -408,6 +430,9 @@ uring_read_offset(struct cfg *cfg, struct uring_task *task, void *buf, size_t le
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->callback = callback;
io_uring_prep_read(sqe, task->fd, buf, len, offset);
@@ -419,6 +444,9 @@ uring_openat(struct cfg *cfg, struct uring_task *task, const char *path, callbac
{
struct io_uring_sqe *sqe;
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->callback = callback;
io_uring_prep_openat(sqe, AT_FDCWD, path, O_RDONLY | O_CLOEXEC, 0);
@@ -431,10 +459,13 @@ uring_tbuf_recvmsg(struct cfg *cfg, struct uring_task *task, callback_t callback
struct io_uring_sqe *sqe;
if (!task->tbuf) {
- error("%s: called with no tbuf set\n", __func__);
+ error("called with no tbuf set\n");
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->tbuf->done = 0;
task->tbuf->len = 0;
@@ -455,6 +486,9 @@ uring_tbuf_sendmsg(struct cfg *cfg, struct uring_task *task, callback_t callback
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->tbuf->done = 0;
task->tbuf->iov.iov_len = task->tbuf->len;
@@ -470,10 +504,13 @@ uring_connect(struct cfg *cfg, struct uring_task *task, struct sockaddr_in46 *ad
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("uring_connect called with no fd set\n");
+ error("fd set\n");
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->callback = callback;
io_uring_prep_connect(sqe, task->fd, (struct sockaddr *)&addr->storage, addr->addrlen);
@@ -486,10 +523,13 @@ uring_accept(struct cfg *cfg, struct uring_task *task, struct sockaddr_in46 *add
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("uring_accept called with no fd set\n");
+ error("no fd set\n");
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
addr->addrlen = sizeof(addr->storage);
task->callback = callback;
@@ -507,6 +547,9 @@ uring_poll(struct cfg *cfg, struct uring_task *task, short poll_mask, callback_t
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->callback = callback;
io_uring_prep_poll_add(sqe, task->fd, poll_mask);
@@ -523,6 +566,9 @@ uring_poll_cancel(struct cfg *cfg, struct uring_task *task)
return;
}
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
sqe = get_sqe(cfg, task);
task->dead = true;
io_uring_prep_poll_remove(sqe, task);
@@ -534,7 +580,8 @@ uring_free(struct uring_task *task)
{
struct uring_ev *uev = container_of(task, struct uring_ev, task);
- fprintf(stderr, "%s: called\n", __func__);
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
io_uring_queue_exit(&uev->uring);
uev->cfg->uev = NULL;
@@ -550,7 +597,12 @@ uring_refdump(struct uring_ev *uev)
void
uring_delete(struct cfg *cfg)
{
- uring_task_put(cfg, &cfg->uev->task);
+ struct uring_task *task = &cfg->uev->task;
+
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ task->name, task, task->fd, task->refcount);
+
+ uring_task_put(cfg, task);
}
void
@@ -565,7 +617,7 @@ uring_init(struct cfg *cfg)
if (io_uring_queue_init_params(4096, &uev->uring, &uev->uring_params) < 0)
perrordie("io_uring_queue_init_params");
- fprintf(stderr, "uring initialized, features: 0x%08x\n", uev->uring_params.features);
+ verbose("uring initialized, features: 0x%08x\n", uev->uring_params.features);
uring_task_init(&uev->task, "uev", &cfg->task, uring_free);
cfg->uev = uev;
@@ -576,15 +628,18 @@ static inline void
uring_print_cqe(struct cfg *cfg, const char *type, struct uring_task *task,
struct io_uring_cqe *cqe)
{
- fprintf(stderr, "uring_event_loop: got %s CQE "
- "(res: %i (%s), task: %s (%p), fd: %i, cb: %p)\n",
- type,
- cqe->res,
- cqe->res < 0 ? strerror(-cqe->res) : "ok",
- task->name ? task->name : "<none>",
- task,
- task->fd,
- task->callback);
+ if (!debug_enabled(DBG_UR))
+ return;
+
+ error("got CQE "
+ "(type: %s, res: %i (%s), task: %s (%p), fd: %i, cb: %p)\n",
+ type,
+ cqe->res,
+ cqe->res < 0 ? strerror(-cqe->res) : "ok",
+ task->name ? task->name : "<none>",
+ task,
+ task->fd,
+ task->callback);
}
void
@@ -616,7 +671,7 @@ uring_event_loop(struct cfg *cfg)
task = (void *)((uintptr_t)task & ~CQE_TYPE_PTR_MASK);
if (!task)
- die("%s: null task\n", __func__);
+ die("null task");
switch (cqe_type) {
case CQE_TYPE_CANCEL: