fellow_io_uring: make use of registered files dynamic

It seems some OSes fail the call despite having it in the header file.

Fixes #68
parent cbb48e03
......@@ -57,6 +57,7 @@ struct fellow_io_uring {
uintptr_t base;
size_t len;
int fd;
uint8_t sqe_flags;
struct io_uring ring;
struct fellow_io_ioctl *ioctl;
};
......@@ -325,11 +326,18 @@ fellow_io_init(int fd, unsigned entries, void *base, size_t len,
fellow_io_fini((fellow_ioctx_t **)(&ctx));
}
#ifdef IOSQE_FIXED_FILE
AZ(io_uring_register_files(&ctx->ring, &fd, 1));
#define FEIOURING_SQE_FLAGS IOSQE_FIXED_FILE
#define FEIOURING_FD(ctx) 0
if (io_uring_register_files(&ctx->ring, &fd, 1) == 0)
ctx->sqe_flags |= IOSQE_FIXED_FILE;
else {
fprintf(stderr, "io_uring register_files failed "
"despite IOSQE_FIXED_FILE defined\n");
}
#define FEIOURING_SQE_FLAGS(ctx) ((ctx)->sqe_flags)
#define FEIOURING_FD(ctx) (FEIOURING_SQE_FLAGS(ctx) & IOSQE_FIXED_FILE ? 0 : (ctx)->fd)
#else
#define FEIOURING_SQE_FLAGS 0
fprintf(stderr, "io_uring IOSQE_FIXED_FILE unavailable\n");
#define FEIOURING_SQE_FLAGS(ctx) 0
#define FEIOURING_FD(ctx) ((ctx)->fd)
#endif
......@@ -436,7 +444,7 @@ fellow_io_read_async_enq(fellow_ioctx_t *ctxp,
io_uring_prep_read(sqe, FEIOURING_FD(ctx),
buf, nbytes, offset);
sqe->flags = FEIOURING_SQE_FLAGS;
sqe->flags = FEIOURING_SQE_FLAGS(ctx);
sqe->user_data = info;
ctx->unsubmitted++;
return (1);
......@@ -471,7 +479,7 @@ fellow_io_write_async_enq(fellow_ioctx_t *ctxp,
io_uring_prep_write(sqe, FEIOURING_FD(ctx), buf,
nbytes, offset);
sqe->flags = FEIOURING_SQE_FLAGS;
sqe->flags = FEIOURING_SQE_FLAGS(ctx);
sqe->user_data = info;
ctx->unsubmitted++;
return (1);
......@@ -490,7 +498,7 @@ fellow_io_fallocate_enq(fellow_ioctx_t *ctxp, uint64_t info,
if (sqe == NULL)
return (0);
io_uring_prep_fallocate(sqe, FEIOURING_FD(ctx), mode, offset, len);
sqe->flags = FEIOURING_SQE_FLAGS;
sqe->flags = FEIOURING_SQE_FLAGS(ctx);
sqe->user_data = info;
ctx->unsubmitted++;
return (1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment