public inbox for [email protected]
 help / color / mirror / Atom feed
From: Glauber Costa <[email protected]>
To: [email protected]
Cc: [email protected], Glauber Costa <[email protected]>,
	Avi Kivity <[email protected]>
Subject: [PATCH v2 liburing] add helper functions to verify io_uring functionality
Date: Thu, 30 Jan 2020 11:00:13 -0500	[thread overview]
Message-ID: <[email protected]> (raw)

It is common for an application using an ever-evolving interface to want
to inquire about the presence of certain functionality it plans to use.

Information about opcodes is stored in a io_uring_probe structure. There
is usually some boilerplate involved in initializing one, and then using
it to check if it is enabled.

This patch adds two new helper functions: one that returns a pointer to
a io_uring_probe (or null if it probe is not available), and another one
that given a probe checks if the opcode is supported.

Signed-off-by: Glauber Costa <[email protected]>
CC: Avi Kivity <[email protected]>
---
 src/include/liburing.h | 11 +++++++++++
 src/liburing.map       |  1 +
 src/setup.c            | 19 +++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index 83d11dd..da52ca6 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -72,6 +72,17 @@ struct io_uring {
 /*
  * Library interface
  */
+
+/*
+ * return an allocated io_uring_probe structure, or NULL if probe fails (for
+ * example, if it is not available). The caller is responsible for freeing it
+ */
+extern struct io_uring_probe *io_uring_get_probe(struct io_uring *ring);
+
+static inline int io_uring_opcode_supported(struct io_uring_probe *p, int op) {
+	return (p->last_op > op) && (p->ops[op].flags & IO_URING_OP_SUPPORTED);
+}
+
 extern int io_uring_queue_init_params(unsigned entries, struct io_uring *ring,
 	struct io_uring_params *p);
 extern int io_uring_queue_init(unsigned entries, struct io_uring *ring,
diff --git a/src/liburing.map b/src/liburing.map
index b45f373..ac8288a 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -72,4 +72,5 @@ LIBURING_0.4 {
 		io_uring_register_probe;
 		io_uring_register_personality;
 		io_uring_unregister_personality;
+		io_uring_get_probe;
 } LIBURING_0.3;
diff --git a/src/setup.c b/src/setup.c
index c53f234..c03274c 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include "liburing/compat.h"
 #include "liburing/io_uring.h"
@@ -167,3 +168,21 @@ void io_uring_queue_exit(struct io_uring *ring)
 	io_uring_unmap_rings(sq, cq);
 	close(ring->ring_fd);
 }
+
+struct io_uring_probe *io_uring_get_probe(struct io_uring *ring)
+{
+	struct io_uring_probe *probe;
+	int r;
+
+	size_t len = sizeof(*probe) + 256 * sizeof(struct io_uring_probe_op);
+	probe = malloc(len);
+	memset(probe, 0, len);
+	r = io_uring_register_probe(ring, probe, 256);
+	if (r < 0)
+		goto fail;
+
+	return probe;
+fail:
+	free(probe);
+	return NULL;
+}
-- 
2.20.1


             reply	other threads:[~2020-01-30 16:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 16:00 Glauber Costa [this message]
2020-01-30 16:13 ` [PATCH v2 liburing] add helper functions to verify io_uring functionality Jens Axboe
2020-01-30 16:29   ` Glauber Costa
2020-01-30 16:31     ` Jens Axboe
2020-01-31 13:52       ` Glauber Costa
2020-01-31 15:14         ` Jens Axboe
2020-01-31 15:27           ` Glauber Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox