Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io_uring_try_setup_flags: New function to probe kernel flag support #1292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions man/io_uring_try_setup_flags.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.\" Copyright (C) 2024 Tavian Barnes <[email protected]>
.\"
.\" SPDX-License-Identifier: LGPL-2.0-or-later
.\"
.TH io_uring_try_setup_flags 3 "December 4, 2024" "liburing-2.9" "liburing Manual"
.SH NAME
io_uring_try_setup_flags \- check if the kernel supports some setup flags
.SH SYNOPSIS
.nf
.B #include <liburing.h>
.PP
.BI "int io_uring_try_setup_flags(struct io_uring_params *" params ","
.BI " unsigned " flags ");"
.fi
.SH DESCRIPTION
.PP
The
.BR io_uring_try_setup_flags (3)
function checks whether the running kernel supports a combination of
.B IORING_SETUP_*
flags. On success,
.BR io_uring_try_setup_flags (3)
performs
.PP
.nf
.RS
.I params\->flags |= flags;
.RE
.fi
.PP
and returns 0. On failure,
.I params
remains unchanged and
.B \-errno
is returned.
.SH RETURN VALUE
.BR io_uring_try_setup_flags (3)
returns 0 on success and
.BR -errno
on failure.
.SH ERRORS
.TP
.B EINVAL
The flag combination is invalid.
.SH SEE ALSO
.BR io_uring_setup (2),
.BR io_uring_queue_init (3)
2 changes: 2 additions & 0 deletions src/include/liburing.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ IOURINGINLINE int io_uring_opcode_supported(const struct io_uring_probe *p,
return (p->ops[op].flags & IO_URING_OP_SUPPORTED) != 0;
}

int io_uring_try_setup_flags(struct io_uring_params *p, unsigned flags);

int io_uring_queue_init_mem(unsigned entries, struct io_uring *ring,
struct io_uring_params *p,
void *buf, size_t buf_size);
Expand Down
1 change: 1 addition & 0 deletions src/liburing.map
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ LIBURING_2.9 {
io_uring_submit_and_wait_reg;
io_uring_clone_buffers_offset;
io_uring_register_region;
io_uring_try_setup_flags;
} LIBURING_2.8;
17 changes: 17 additions & 0 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,23 @@ __cold void io_uring_free_probe(struct io_uring_probe *probe)
free(probe);
}

int io_uring_try_setup_flags(struct io_uring_params *p, unsigned flags)
{
struct io_uring ring;
unsigned saved = p->flags;
int r;

p->flags |= flags;
r = io_uring_queue_init_params(2, &ring, p);
if (r == 0) {
io_uring_queue_exit(&ring);
} else {
p->flags = saved;
}

return r;
}

static size_t npages(size_t size, long page_size)
{
size--;
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ test_srcs := \
timeout.c \
timeout-new.c \
truncate.c \
try-setup-flags.c \
tty-write-dpoll.c \
unlink.c \
uring_cmd_ublk.c \
Expand Down
33 changes: 33 additions & 0 deletions test/try-setup-flags.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* SPDX-License-Identifier: MIT */
/*
* Description: test io_uring_try_setup_flags()
*
*/
#include <stdio.h>

#include "liburing.h"
#include "helpers.h"

int main(int argc, char *argv[])
{
struct io_uring_params params = {0};
int ret;

if (argc > 1)
return T_EXIT_SKIP;

ret = io_uring_try_setup_flags(&params, IORING_SETUP_CLAMP);
if (ret != 0) {
fprintf(stderr, "IORING_SETUP_CLAMP failed\n");
return T_EXIT_FAIL;
}

/* should fail without IORING_SETUP_SINGLE_ISSUER */
ret = io_uring_try_setup_flags(&params, IORING_SETUP_DEFER_TASKRUN);
if (ret != -EINVAL) {
fprintf(stderr, "IORING_SETUP_DEFER_TASKRUN failed\n");
return T_EXIT_FAIL;
}

return T_EXIT_PASS;
}