engines/io_uring: Fully clear out previous SQE contents.
[fio.git] / engines / io_uring.c
index 10cfe9f23e2476ffed8500ce13e46d2ad2e8ed90..e5edfcd25c60cd59062290e751fc7f5e877c064d 100644 (file)
@@ -152,15 +152,16 @@ static int fio_ioring_prep(struct thread_data *td, struct io_u *io_u)
        struct io_uring_sqe *sqe;
 
        sqe = &ld->sqes[io_u->index];
+
+       /* zero out fields not used in this submission */
+       memset(sqe, 0, sizeof(*sqe));
+
        if (o->registerfiles) {
                sqe->fd = f->engine_pos;
                sqe->flags = IOSQE_FIXED_FILE;
        } else {
                sqe->fd = f->fd;
-               sqe->flags = 0;
        }
-       sqe->ioprio = 0;
-       sqe->buf_index = 0;
 
        if (io_u->ddir == DDIR_READ || io_u->ddir == DDIR_WRITE) {
                if (o->fixedbufs) {
@@ -181,10 +182,16 @@ static int fio_ioring_prep(struct thread_data *td, struct io_u *io_u)
                }
                sqe->off = io_u->offset;
        } else if (ddir_sync(io_u->ddir)) {
-               sqe->fsync_flags = 0;
-               if (io_u->ddir == DDIR_DATASYNC)
-                       sqe->fsync_flags |= IORING_FSYNC_DATASYNC;
-               sqe->opcode = IORING_OP_FSYNC;
+               if (io_u->ddir == DDIR_SYNC_FILE_RANGE) {
+                       sqe->off = f->first_write;
+                       sqe->len = f->last_write - f->first_write;
+                       sqe->sync_range_flags = td->o.sync_file_range;
+                       sqe->opcode = IORING_OP_SYNC_FILE_RANGE;
+               } else {
+                       if (io_u->ddir == DDIR_DATASYNC)
+                               sqe->fsync_flags |= IORING_FSYNC_DATASYNC;
+                       sqe->opcode = IORING_OP_FSYNC;
+               }
        }
 
        sqe->user_data = (unsigned long) io_u;
@@ -259,7 +266,7 @@ static int fio_ioring_getevents(struct thread_data *td, unsigned int min,
                        r = io_uring_enter(ld, 0, actual_min,
                                                IORING_ENTER_GETEVENTS);
                        if (r < 0) {
-                               if (errno == EAGAIN)
+                               if (errno == EAGAIN || errno == EINTR)
                                        continue;
                                td_verror(td, errno, "io_uring_enter");
                                break;
@@ -370,7 +377,7 @@ static int fio_ioring_commit(struct thread_data *td)
                        io_u_mark_submit(td, ret);
                        continue;
                } else {
-                       if (errno == EAGAIN) {
+                       if (errno == EAGAIN || errno == EINTR) {
                                ret = fio_ioring_cqring_reap(td, 0, ld->queued);
                                if (ret)
                                        continue;
@@ -555,6 +562,7 @@ static int fio_ioring_post_init(struct thread_data *td)
                return 1;
        }
 
+       printf("files=%d\n", o->registerfiles);
        if (o->registerfiles) {
                err = fio_ioring_register_files(td);
                if (err) {
@@ -613,7 +621,7 @@ static int fio_ioring_open_file(struct thread_data *td, struct fio_file *f)
        struct ioring_data *ld = td->io_ops_data;
        struct ioring_options *o = td->eo;
 
-       if (!o->registerfiles)
+       if (!ld || !o->registerfiles)
                return generic_open_file(td, f);
 
        f->fd = ld->fds[f->engine_pos];
@@ -622,9 +630,10 @@ static int fio_ioring_open_file(struct thread_data *td, struct fio_file *f)
 
 static int fio_ioring_close_file(struct thread_data *td, struct fio_file *f)
 {
+       struct ioring_data *ld = td->io_ops_data;
        struct ioring_options *o = td->eo;
 
-       if (!o->registerfiles)
+       if (!ld || !o->registerfiles)
                return generic_close_file(td, f);
 
        f->fd = -1;