]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_io_uring: implement POSIX append-IO
authorRalph Boehme <slow@samba.org>
Sun, 24 Nov 2024 08:27:36 +0000 (09:27 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 7 Jan 2025 22:04:33 +0000 (22:04 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_io_uring.c
source3/wscript

index b33c09a6ef84aa0a5211c0c79c1cd4e3e4e4c8ed..20eb80477db715e94f3dfb15d2aed729ba4e4235 100644 (file)
@@ -416,6 +416,22 @@ static void vfs_io_uring_fd_handler(struct tevent_context *ev,
        vfs_io_uring_queue_run(config);
 }
 
+static int vfs_io_uring_openat(struct vfs_handle_struct *handle,
+                              const struct files_struct *dirfsp,
+                              const struct smb_filename *smb_fname,
+                              struct files_struct *fsp,
+                              const struct vfs_open_how *how)
+{
+#ifndef HAVE_IO_URING_PREP_WRITEV2
+       if (fsp->fsp_flags.posix_append) {
+               DBG_ERR("POSIX append-IO not supported without writev2 support");
+               errno = EINVAL;
+               return -1;
+       }
+#endif
+       return SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, how);
+}
+
 struct vfs_io_uring_pread_state {
        struct files_struct *fsp;
        off_t offset;
@@ -606,6 +622,7 @@ static struct tevent_req *vfs_io_uring_pwrite_send(struct vfs_handle_struct *han
        SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->ur.profile_bytes);
 
        ok = sys_valid_io_range(offset, n);
+       ok |= offset == VFS_PWRITE_APPEND_OFFSET;
        if (!ok) {
                tevent_req_error(req, EINVAL);
                return tevent_req_post(req, ev);
@@ -627,10 +644,24 @@ static struct tevent_req *vfs_io_uring_pwrite_send(struct vfs_handle_struct *han
 
 static void vfs_io_uring_pwrite_submit(struct vfs_io_uring_pwrite_state *state)
 {
-       io_uring_prep_writev(&state->ur.sqe,
-                            fsp_get_io_fd(state->fsp),
-                            &state->iov, 1,
-                            state->offset);
+       if (!state->fsp->fsp_flags.posix_append) {
+               io_uring_prep_writev(&state->ur.sqe,
+                                    fsp_get_io_fd(state->fsp),
+                                    &state->iov, 1,
+                                    state->offset);
+       }
+       else {
+#ifdef HAVE_IO_URING_PREP_WRITEV2
+               io_uring_prep_writev2(&state->ur.sqe,
+                                     fsp_get_io_fd(state->fsp),
+                                     &state->iov, 1,
+                                     -1,
+                                     RWF_APPEND);
+#else
+               /* This should have been caught by vfs_io_uring_openat() */
+               smb_panic("Unexpected POSIX append-IO");
+#endif
+       }
        vfs_io_uring_request_submit(&state->ur);
 }
 
@@ -806,6 +837,7 @@ static int vfs_io_uring_fsync_recv(struct tevent_req *req,
 
 static struct vfs_fn_pointers vfs_io_uring_fns = {
        .connect_fn = vfs_io_uring_connect,
+       .openat_fn = vfs_io_uring_openat,
        .pread_send_fn = vfs_io_uring_pread_send,
        .pread_recv_fn = vfs_io_uring_pread_recv,
        .pwrite_send_fn = vfs_io_uring_pwrite_send,
index f746a67b800833b7d2b5e298f04418173a5ca662..26327cba32fb32fb475aa705f6eb0e51dc54e7bc 100644 (file)
@@ -1680,7 +1680,7 @@ int main(void) {
                       msg='Checking for liburing package', uselib_store="URING"):
         if (conf.CHECK_HEADERS('liburing.h', lib='uring')
                                       and conf.CHECK_LIB('uring', shlib=True)):
-            conf.CHECK_FUNCS_IN('io_uring_ring_dontfork', 'uring',
+            conf.CHECK_FUNCS_IN('io_uring_ring_dontfork io_uring_prep_writev2', 'uring',
                                 headers='liburing.h')
             # There are a few distributions, which
             # don't seem to have linux/openat2.h available