splice engine: add unmapping for vmsplice-to-user
[fio.git] / engines / splice.c
index f54b4414ae1851318ae79fb5aa40d67ea8e5b9f3..d8080b42ff71460b8a340dd858da795f5a8511a6 100644 (file)
@@ -82,6 +82,7 @@ static int fio_splice_read(struct thread_data *td, struct io_u *io_u)
        offset = io_u->offset;
        buflen = io_u->xfer_buflen;
        p = io_u->xfer_buf;
+       io_u->xfer_buf = NULL;
        while (buflen) {
                int this_len = buflen;
 
@@ -108,15 +109,17 @@ static int fio_splice_read(struct thread_data *td, struct io_u *io_u)
                        else if (!ret)
                                return -ENODATA;
 
+                       if (!io_u->xfer_buf)
+                               io_u->xfer_buf = iov.iov_base;
                        iov.iov_len -= ret;
                        iov.iov_base += ret;
                }
        }
 
+       io_u->unmap = splice_unmap_io_u;
        return io_u->xfer_buflen;
 }
 
-
 /*
  * For splice writing, we can vmsplice our data buffer directly into a
  * pipe and then splice that to a file.
@@ -156,15 +159,34 @@ static int fio_splice_write(struct thread_data *td, struct io_u *io_u)
        return io_u->xfer_buflen;
 }
 
+static void splice_unmap_io_u(struct thread_data *td, struct io_u *io_u)
+{
+       struct spliceio_data *sd = td->io_ops->data;
+       struct iovec iov = {
+               .iov_base = io_u->xfer_buf,
+               .iov_len = io_u->xfer_buflen,
+       };
+
+       vmsplice(sd->pipe[0], &iov, 1, SPLICE_F_UNMAP);
+}
+
 static int fio_spliceio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct spliceio_data *sd = td->io_ops->data;
        int ret;
 
        if (io_u->ddir == DDIR_READ) {
-               if (sd->vmsplice_to_user)
+               if (sd->vmsplice_to_user) {
                        ret = fio_splice_read(td, io_u);
-               else
+                       /*
+                        * This kernel doesn't support vmsplice to user
+                        * space. Reset the vmsplice_to_user flag, so that
+                        * we retry below and don't hit this path again.
+                        */
+                       if (ret == -EBADF)
+                               sd->vmsplice_to_user = 0;
+               }
+               if (!sd->vmsplice_to_user)
                        ret = fio_splice_read_old(td, io_u);
        } else if (io_u->ddir == DDIR_WRITE)
                ret = fio_splice_write(td, io_u);
@@ -209,9 +231,9 @@ static int fio_spliceio_init(struct thread_data *td)
        }
 
        /*
-        * need some check for enabling this, for now just leave it disabled
+        * Assume this work, we'll reset this if it doesn't
         */
-       sd->vmsplice_to_user = 0;
+       sd->vmsplice_to_user = 1;
 
        td->io_ops->data = sd;
        return 0;