Skip to contentSkip to conversation

add helper functions to verify io_uring functionality

PATCH In review Glauber Costa 2 participants 7 messages Jan 30, 2020 – Jan 31, 2020 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 add helper functions to verify io_uring functionality

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.

---
 src/include/liburing.h | 11 +++++++++++
 src/liburing.map       |  1 +
 src/setup.c            | 19 +++++++++++++++++++
 3 files changed, 31 insertions(+)
src/include/liburing.h +11 -0
index 83d11dd..da52ca6 100644
@@ -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,
src/liburing.map +1 -0
index b45f373..ac8288a 100644
@@ -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;
src/setup.c +19 -0
index c53f234..c03274c 100644
@@ -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;
+}
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 10 lines · Glauber Costa

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.

This looks good, I committed it with minor changes.

On top of this, we should have a helper that doesn't need a ring. So basically one that just sets up a ring, calls io_uring_get_probe(), then tears down the ring.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 13 lines · Jens Axboe
Quoted 10 lines · Glauber Costa

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.

Quoted 6 lines

This looks good, I committed it with minor changes.

On top of this, we should have a helper that doesn't need a ring. So basically one that just sets up a ring, calls io_uring_get_probe(), then tears down the ring.

I'd be happy to follow up with that.

Just to be sure, the information returned by probe should be able to outlive the tear down of the ring, right ?

maintainer
#3 lore raw
Quoted 16 lines · Glauber Costa
Quoted 15 lines · Jens Axboe
Quoted 10 lines · Glauber Costa

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.

This looks good, I committed it with minor changes.

Quoted 8 lines
Quoted 4 lines

On top of this, we should have a helper that doesn't need a ring. So basically one that just sets up a ring, calls io_uring_get_probe(), then tears down the ring.

I'd be happy to follow up with that.

Just to be sure, the information returned by probe should be able to outlive the tear down of the ring, right ?

Yeah, same lifetime as the helper you have now, caller must free it once done.

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 22 lines · Jens Axboe
Quoted 20 lines · Glauber Costa
Quoted 19 lines · Jens Axboe
Quoted 10 lines · Glauber Costa

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.

This looks good, I committed it with minor changes.

On top of this, we should have a helper that doesn't need a ring. So basically one that just sets up a ring, calls io_uring_get_probe(), then tears down the ring.

Quoted 7 lines
Quoted 4 lines

I'd be happy to follow up with that.

Just to be sure, the information returned by probe should be able to outlive the tear down of the ring, right ?

Yeah, same lifetime as the helper you have now, caller must free it once done.

Well, in hindsight, I should have called that
io_uring_get_probe_ring() so io_uring_get_probe()
doesn't take a ring.

Alternatively, to keep things in a single function, I can change io_uring_get_probe() so that if it
ring is NULL, we do our own allocation.

I actually kind of like that. Would that work for you ?

Quoted 4 lines

--
Jens Axboe

maintainer
#5 lore raw
Quoted 28 lines · Glauber Costa
Quoted 27 lines · Jens Axboe
Quoted 24 lines · Glauber Costa
Quoted 13 lines · Jens Axboe
Quoted 10 lines · Glauber Costa

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.

Quoted 6 lines

This looks good, I committed it with minor changes.

On top of this, we should have a helper that doesn't need a ring. So basically one that just sets up a ring, calls io_uring_get_probe(), then tears down the ring.

I'd be happy to follow up with that.

Just to be sure, the information returned by probe should be able to outlive the tear down of the ring, right ?

Quoted 6 lines
Quoted 2 lines

Yeah, same lifetime as the helper you have now, caller must free it once done.

Well, in hindsight, I should have called that
io_uring_get_probe_ring() so io_uring_get_probe()
doesn't take a ring.

Just change it - we just added it yesterday, and it's not released yet. I don't break anything that's been in a release, and I maintain compatibility between releases, but we can change it now.

Quoted 5 lines

Alternatively, to keep things in a single function, I can change io_uring_get_probe() so that if it
ring is NULL, we do our own allocation.

I actually kind of like that. Would that work for you ?

Not a huge deal to me, we can go that route.

Signature · 1 line
Jens Axboe
#6 lore raw
Quoted 33 lines · Jens Axboe
Quoted 31 lines · Glauber Costa
Quoted 29 lines · Jens Axboe
Quoted 16 lines · Glauber Costa
Quoted 15 lines · Jens Axboe
Quoted 10 lines · Glauber Costa

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.

This looks good, I committed it with minor changes.

Quoted 8 lines
Quoted 4 lines

On top of this, we should have a helper that doesn't need a ring. So basically one that just sets up a ring, calls io_uring_get_probe(), then tears down the ring.

I'd be happy to follow up with that.

Just to be sure, the information returned by probe should be able to outlive the tear down of the ring, right ?

Yeah, same lifetime as the helper you have now, caller must free it once done.

Quoted 7 lines
Quoted 3 lines

Well, in hindsight, I should have called that
io_uring_get_probe_ring() so io_uring_get_probe()
doesn't take a ring.

Just change it - we just added it yesterday, and it's not released yet. I don't break anything that's been in a release, and I maintain compatibility between releases, but we can change it now.

Yeah, I figured as much and ended up changing it.

Quoted 12 lines
Quoted 6 lines

Alternatively, to keep things in a single function, I can change io_uring_get_probe() so that if it
ring is NULL, we do our own allocation.

I actually kind of like that. Would that work for you ?

Not a huge deal to me, we can go that route.

--
Jens Axboe