qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 6/6] experimental native preadv/pwritev support for


From: Christoph Hellwig
Subject: [Qemu-devel] [PATCH 6/6] experimental native preadv/pwritev support for Linux
Date: Sat, 14 Mar 2009 20:31:27 +0100
User-agent: Mutt/1.3.28i


This ties up Gerd Hoffmann's unmegred preadv/pwritev syscalls to qemu.  Use with
care as the syscall numbers aren't finalized yet.

If someone of the BSD folks is interested it should be trivial to tie this up
for the preadv/pwritev syscalls that have been around there for a while.

Probably wants some optimization to not try preadv/pwritev again once we got
the first ENOSYS.


Signed-off-by: Christoph Hellwig <address@hidden>

Index: qemu/posix-aio-compat.c
===================================================================
--- qemu.orig/posix-aio-compat.c        2009-03-14 18:30:35.000000000 +0100
+++ qemu/posix-aio-compat.c     2009-03-14 18:30:36.000000000 +0100
@@ -76,6 +76,45 @@ static void thread_create(pthread_t *thr
     if (ret) die2(ret, "pthread_create");
 }
 
+#if defined (__linux__) && defined(__i386__)
+
+#define __NR_preadv             333
+#define __NR_pwritev            334
+
+static ssize_t
+qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
+{
+    uint32_t pos_high = offset >> 32;
+    uint32_t pos_low = offset;
+
+    return syscall(__NR_preadv, fd, iov, (unsigned long)nr_iov, pos_high, 
pos_low);
+}
+
+static ssize_t
+qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
+{
+    uint32_t pos_high = offset >> 32;
+    uint32_t pos_low = offset;
+
+    return syscall(__NR_pwritev, fd, iov, (unsigned long)nr_iov, pos_high, 
pos_low);
+}
+
+#else
+
+static ssize_t
+qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
+{
+    return -ENOSYS;
+}
+
+static ssize_t
+qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
+{
+    return -ENOSYS;
+}
+
+#endif
+
 /*
  * Check if we need to copy the data in the aiocb into a new
  * properly aligned buffer.
@@ -93,6 +132,29 @@ static int aiocb_needs_copy(struct qemu_
     return 0;
 }
 
+static size_t handle_aiocb_vector(struct qemu_paiocb *aiocb)
+{
+    size_t offset = 0;
+    ssize_t len;
+
+    do {
+        if (aiocb->is_write)
+            len = qemu_pwritev(aiocb->aio_fildes,
+                               aiocb->aio_iov,
+                               aiocb->aio_niov,
+                               aiocb->aio_offset + offset);
+         else
+            len = qemu_preadv(aiocb->aio_fildes,
+                              aiocb->aio_iov,
+                              aiocb->aio_niov,
+                              aiocb->aio_offset + offset);
+    } while (len == -1 && errno == EINTR);
+
+    if (len == -1)
+        return -errno;
+    return len;
+}
+
 static size_t handle_aiocb_linear(struct qemu_paiocb *aiocb, char *buf)
 {
     size_t offset = 0;
@@ -129,12 +191,31 @@ static size_t handle_aiocb(struct qemu_p
     size_t nbytes;
     char *buf;
 
-    if (!aiocb_needs_copy(aiocb) && aiocb->aio_niov == 1) {
+    if (!aiocb_needs_copy(aiocb)) {
         /*
          * If there is just a single buffer, and it is properly aligned
          * we can just use plain pread/pwrite without any problems.
          */
-        return handle_aiocb_linear(aiocb, aiocb->aio_iov->iov_base);
+        if (aiocb->aio_niov == 1)
+             return handle_aiocb_linear(aiocb, aiocb->aio_iov->iov_base);
+
+        /*
+         * We have more than one iovec, and all are properly aligned.
+         *
+         * Try preadv/pwritev first and fall back to linearizing the
+         * buffer if it's not supported.
+         */
+         nbytes = handle_aiocb_vector(aiocb);
+        if (nbytes == aiocb->aio_nbytes)
+            return nbytes;
+         if (nbytes < 0 && nbytes != -ENOSYS)
+             return nbytes;
+
+         /*
+          * XXX(hch): short read/write.  no easy way to handle the reminder
+          * using these interfaces.  For now retry using plain
+          * pread/pwrite?
+          */
     }
 
     /*




reply via email to

[Prev in Thread] Current Thread [Next in Thread]