diff mbox series

[liburing,2/4] liburing: add zc send and notif helpers

Message ID 7f705b208e5f7baa6ee94904e39d3d0da2e28150.1658743360.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series zerocopy send headers and tests | expand

Commit Message

Pavel Begunkov July 25, 2022, 10:03 a.m. UTC
Add helpers for notification registration and preparing zerocopy send
requests.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 src/include/liburing.h | 41 +++++++++++++++++++++++++++++++++++++++++
 src/liburing.map       |  2 ++
 src/register.c         | 20 ++++++++++++++++++++
 3 files changed, 63 insertions(+)

Comments

Ammar Faizi July 25, 2022, 10:20 a.m. UTC | #1
Hi Pavel,

On 7/25/22 5:03 PM, Pavel Begunkov wrote:
> +static inline void io_uring_prep_notif_update(struct io_uring_sqe *sqe,
> +					      __u64 new_tag, /* 0 to ignore */
> +					      unsigned offset, unsigned nr)
> +{
> +	io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
> +			 (__u64)offset);
> +	sqe->ioprio = IORING_RSRC_UPDATE_NOTIF;
> +}
> +

This part breaks 32-bit architecture.

   include/liburing.h: In function ‘io_uring_prep_notif_update’:
   In file included from syscall.h:14,
                    from setup.c:5:
   include/liburing.h: In function ‘io_uring_prep_notif_update’:
   include/liburing.h:716:59: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     716 |         io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
         |                                                           ^
   include/liburing.h:716:59: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     716 |         io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
         |
Pavel Begunkov July 25, 2022, 11:18 a.m. UTC | #2
On 7/25/22 11:20, Ammar Faizi wrote:
> Hi Pavel,
> 
> On 7/25/22 5:03 PM, Pavel Begunkov wrote:
>> +static inline void io_uring_prep_notif_update(struct io_uring_sqe *sqe,
>> +                          __u64 new_tag, /* 0 to ignore */
>> +                          unsigned offset, unsigned nr)
>> +{
>> +    io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
>> +             (__u64)offset);
>> +    sqe->ioprio = IORING_RSRC_UPDATE_NOTIF;
>> +}
>> +
> 
> This part breaks 32-bit architecture.
> 
>    include/liburing.h: In function ‘io_uring_prep_notif_update’:
>    In file included from syscall.h:14,
>                     from setup.c:5:
>    include/liburing.h: In function ‘io_uring_prep_notif_update’:
>    include/liburing.h:716:59: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>      716 |         io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
>          |                                                           ^
>    include/liburing.h:716:59: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>      716 |         io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
>          |

Got it, thanks
diff mbox series

Patch

diff --git a/src/include/liburing.h b/src/include/liburing.h
index fc7613d..f3c5887 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -189,6 +189,10 @@  int io_uring_register_sync_cancel(struct io_uring *ring,
 int io_uring_register_file_alloc_range(struct io_uring *ring,
 					unsigned off, unsigned len);
 
+int io_uring_register_notifications(struct io_uring *ring, unsigned nr,
+				    struct io_uring_notification_slot *slots);
+int io_uring_unregister_notifications(struct io_uring *ring);
+
 /*
  * Helper for the peek/wait single cqe functions. Exported because of that,
  * but probably shouldn't be used directly in an application.
@@ -677,6 +681,43 @@  static inline void io_uring_prep_send(struct io_uring_sqe *sqe, int sockfd,
 	sqe->msg_flags = (__u32) flags;
 }
 
+static inline void io_uring_prep_sendzc(struct io_uring_sqe *sqe, int sockfd,
+				        const void *buf, size_t len, int flags,
+				        unsigned slot_idx, unsigned zc_flags)
+{
+	io_uring_prep_rw(IORING_OP_SENDZC_NOTIF, sqe, sockfd, buf, (__u32) len, 0);
+	sqe->msg_flags = (__u32) flags;
+	sqe->notification_idx = slot_idx;
+	sqe->ioprio = zc_flags;
+}
+
+static inline void io_uring_prep_sendzc_fixed(struct io_uring_sqe *sqe, int sockfd,
+					      const void *buf, size_t len,
+					      int flags, unsigned slot_idx,
+					      unsigned zc_flags, unsigned buf_idx)
+{
+	io_uring_prep_sendzc(sqe, sockfd, buf, len, flags, slot_idx, zc_flags);
+	sqe->ioprio |= IORING_RECVSEND_FIXED_BUF;
+	sqe->buf_index = buf_idx;
+}
+
+static inline void io_uring_prep_sendzc_set_addr(struct io_uring_sqe *sqe,
+						 const struct sockaddr *dest_addr,
+						 __u16 addr_len)
+{
+	sqe->addr2 = (unsigned long)(void *)dest_addr;
+	sqe->addr_len = addr_len;
+}
+
+static inline void io_uring_prep_notif_update(struct io_uring_sqe *sqe,
+					      __u64 new_tag, /* 0 to ignore */
+					      unsigned offset, unsigned nr)
+{
+	io_uring_prep_rw(IORING_OP_FILES_UPDATE, sqe, -1, (void *)new_tag, nr,
+			 (__u64)offset);
+	sqe->ioprio = IORING_RSRC_UPDATE_NOTIF;
+}
+
 static inline void io_uring_prep_recv(struct io_uring_sqe *sqe, int sockfd,
 				      void *buf, size_t len, int flags)
 {
diff --git a/src/liburing.map b/src/liburing.map
index 318d3d7..7d8f143 100644
--- a/src/liburing.map
+++ b/src/liburing.map
@@ -60,4 +60,6 @@  LIBURING_2.3 {
 	global:
 		io_uring_register_sync_cancel;
 		io_uring_register_file_alloc_range;
+		io_uring_register_notifications;
+		io_uring_unregister_notifications;
 } LIBURING_2.2;
diff --git a/src/register.c b/src/register.c
index 2b37e5f..7482112 100644
--- a/src/register.c
+++ b/src/register.c
@@ -364,3 +364,23 @@  int io_uring_register_file_alloc_range(struct io_uring *ring,
 				       IORING_REGISTER_FILE_ALLOC_RANGE, &range,
 				       0);
 }
+
+int io_uring_register_notifications(struct io_uring *ring, unsigned nr,
+				    struct io_uring_notification_slot *slots)
+{
+	struct io_uring_notification_register r = {
+		.nr_slots = nr,
+		.data = (unsigned long)slots,
+	};
+
+	return __sys_io_uring_register(ring->ring_fd,
+				       IORING_REGISTER_NOTIFIERS,
+				       &r, sizeof(r));
+}
+
+int io_uring_unregister_notifications(struct io_uring *ring)
+{
+	return __sys_io_uring_register(ring->ring_fd,
+				       IORING_UNREGISTER_NOTIFIERS,
+				       NULL, 0);
+}