Test io_uring flags before using them

is there a better way?

https://github.com/axboe/liburing/issues/906
parent ecf6f24c
......@@ -226,6 +226,42 @@ test_task(struct worker *wrk, void *priv)
/* XXX very simplistic. Sufficient for fellow, but not otherwise */
static int shared_wq_fd = -1;
/* XXX BETTER WAY? https://github.com/axboe/liburing/issues/906 */
static unsigned flags_checked = 0;
static unsigned flags_supported = 0;
static unsigned
try_flag(unsigned flag)
{
struct io_uring_params params;
struct io_uring ring;
int ret;
memset(&params, 0, sizeof params);
params.flags = flag;
ret = io_uring_queue_init_params(2, &ring, &params);
if (ret == 0) {
io_uring_queue_exit(&ring);
return (flag);
}
assert(ret == -EINVAL);
return (0);
}
static void
try_flags(void)
{
if (flags_checked != 0)
return;
#ifdef IORING_SETUP_COOP_TASKRUN
flags_supported |= try_flag(IORING_SETUP_COOP_TASKRUN);
#endif
flags_checked = 1;
}
fellow_ioctx_t *
fellow_io_init(int fd, unsigned entries, void *base, size_t len,
fellow_task_run_t taskrun)
......@@ -236,6 +272,8 @@ fellow_io_init(int fd, unsigned entries, void *base, size_t len,
int ret, answer = 0;
fellow_task_privstate taskstate;
try_flags();
probe = io_uring_get_probe();
if (probe == NULL) {
fprintf(stderr, "io_uring_get_probe() failed\n");
......@@ -250,10 +288,7 @@ fellow_io_init(int fd, unsigned entries, void *base, size_t len,
AZ(taskrun(test_task, &answer, &taskstate));
memset(&params, 0, sizeof params);
#ifdef IORING_SETUP_COOP_TASKRUN
params.flags |= IORING_SETUP_COOP_TASKRUN;
#endif
params.flags = flags_supported;
#ifdef IORING_SETUP_ATTACH_WQ
if (shared_wq_fd >= 0) {
......
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