Blame 1001-io-add-new-qio_channel_-readv-writev-read-write-_all.patch

Paolo Bonzini 0fb2b2
From 758d848ef10835108a75187d1a1a0418167f04b2 Mon Sep 17 00:00:00 2001
Paolo Bonzini 0fb2b2
From: "Daniel P. Berrange" <berrange@redhat.com>
Paolo Bonzini 0fb2b2
Date: Wed, 30 Aug 2017 14:53:59 +0100
Paolo Bonzini 0fb2b2
Subject: [PATCH 01/15] io: add new qio_channel_{readv, writev, read,
Paolo Bonzini 0fb2b2
 write}_all functions
Paolo Bonzini 0fb2b2
Paolo Bonzini 0fb2b2
These functions wait until they are able to read / write the full
Paolo Bonzini 0fb2b2
requested data buffer(s).
Paolo Bonzini 0fb2b2
Paolo Bonzini 0fb2b2
Reviewed-by: Eric Blake <eblake@redhat.com>
Paolo Bonzini 0fb2b2
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Paolo Bonzini 0fb2b2
---
Paolo Bonzini 0fb2b2
 include/io/channel.h       |  90 +++++++++++++++++++++++++++++++++++++++
Paolo Bonzini 0fb2b2
 io/channel.c               |  94 +++++++++++++++++++++++++++++++++++++++++
Paolo Bonzini 0fb2b2
 tests/io-channel-helpers.c | 102 ++++-----------------------------------------
Paolo Bonzini 0fb2b2
 3 files changed, 193 insertions(+), 93 deletions(-)
Paolo Bonzini 0fb2b2
Paolo Bonzini 0fb2b2
diff --git a/include/io/channel.h b/include/io/channel.h
Paolo Bonzini 0fb2b2
index db9bb022a1..e11a62ea50 100644
Paolo Bonzini 0fb2b2
--- a/include/io/channel.h
Paolo Bonzini 0fb2b2
+++ b/include/io/channel.h
Paolo Bonzini 0fb2b2
@@ -269,6 +269,58 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
                                 Error **errp);
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 /**
Paolo Bonzini 0fb2b2
+ * qio_channel_readv_all:
Paolo Bonzini 0fb2b2
+ * @ioc: the channel object
Paolo Bonzini 0fb2b2
+ * @iov: the array of memory regions to read data into
Paolo Bonzini 0fb2b2
+ * @niov: the length of the @iov array
Paolo Bonzini 0fb2b2
+ * @errp: pointer to a NULL-initialized error object
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Read data from the IO channel, storing it in the
Paolo Bonzini 0fb2b2
+ * memory regions referenced by @iov. Each element
Paolo Bonzini 0fb2b2
+ * in the @iov will be fully populated with data
Paolo Bonzini 0fb2b2
+ * before the next one is used. The @niov parameter
Paolo Bonzini 0fb2b2
+ * specifies the total number of elements in @iov.
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * The function will wait for all requested data
Paolo Bonzini 0fb2b2
+ * to be read, yielding from the current coroutine
Paolo Bonzini 0fb2b2
+ * if required.
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * If end-of-file occurs before all requested data
Paolo Bonzini 0fb2b2
+ * has been read, an error will be reported.
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Returns: 0 if all bytes were read, or -1 on error
Paolo Bonzini 0fb2b2
+ */
Paolo Bonzini 0fb2b2
+int qio_channel_readv_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                          const struct iovec *iov,
Paolo Bonzini 0fb2b2
+                          size_t niov,
Paolo Bonzini 0fb2b2
+                          Error **errp);
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+/**
Paolo Bonzini 0fb2b2
+ * qio_channel_writev_all:
Paolo Bonzini 0fb2b2
+ * @ioc: the channel object
Paolo Bonzini 0fb2b2
+ * @iov: the array of memory regions to write data from
Paolo Bonzini 0fb2b2
+ * @niov: the length of the @iov array
Paolo Bonzini 0fb2b2
+ * @errp: pointer to a NULL-initialized error object
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Write data to the IO channel, reading it from the
Paolo Bonzini 0fb2b2
+ * memory regions referenced by @iov. Each element
Paolo Bonzini 0fb2b2
+ * in the @iov will be fully sent, before the next
Paolo Bonzini 0fb2b2
+ * one is used. The @niov parameter specifies the
Paolo Bonzini 0fb2b2
+ * total number of elements in @iov.
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * The function will wait for all requested data
Paolo Bonzini 0fb2b2
+ * to be written, yielding from the current coroutine
Paolo Bonzini 0fb2b2
+ * if required.
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Returns: 0 if all bytes were written, or -1 on error
Paolo Bonzini 0fb2b2
+ */
Paolo Bonzini 0fb2b2
+int qio_channel_writev_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                           const struct iovec *iov,
Paolo Bonzini 0fb2b2
+                           size_t niov,
Paolo Bonzini 0fb2b2
+                           Error **erp);
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+/**
Paolo Bonzini 0fb2b2
  * qio_channel_readv:
Paolo Bonzini 0fb2b2
  * @ioc: the channel object
Paolo Bonzini 0fb2b2
  * @iov: the array of memory regions to read data into
Paolo Bonzini 0fb2b2
@@ -331,6 +383,44 @@ ssize_t qio_channel_write(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
                           Error **errp);
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 /**
Paolo Bonzini 0fb2b2
+ * qio_channel_read_all:
Paolo Bonzini 0fb2b2
+ * @ioc: the channel object
Paolo Bonzini 0fb2b2
+ * @buf: the memory region to read data into
Paolo Bonzini 0fb2b2
+ * @buflen: the number of bytes to @buf
Paolo Bonzini 0fb2b2
+ * @errp: pointer to a NULL-initialized error object
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Reads @buflen bytes into @buf, possibly blocking or (if the
Paolo Bonzini 0fb2b2
+ * channel is non-blocking) yielding from the current coroutine
Paolo Bonzini 0fb2b2
+ * multiple times until the entire content is read. If end-of-file
Paolo Bonzini 0fb2b2
+ * occurs it will return an error rather than a short-read. Otherwise
Paolo Bonzini 0fb2b2
+ * behaves as qio_channel_read().
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Returns: 0 if all bytes were read, or -1 on error
Paolo Bonzini 0fb2b2
+ */
Paolo Bonzini 0fb2b2
+int qio_channel_read_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                         char *buf,
Paolo Bonzini 0fb2b2
+                         size_t buflen,
Paolo Bonzini 0fb2b2
+                         Error **errp);
Paolo Bonzini 0fb2b2
+/**
Paolo Bonzini 0fb2b2
+ * qio_channel_write_all:
Paolo Bonzini 0fb2b2
+ * @ioc: the channel object
Paolo Bonzini 0fb2b2
+ * @buf: the memory region to write data into
Paolo Bonzini 0fb2b2
+ * @buflen: the number of bytes to @buf
Paolo Bonzini 0fb2b2
+ * @errp: pointer to a NULL-initialized error object
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Writes @buflen bytes from @buf, possibly blocking or (if the
Paolo Bonzini 0fb2b2
+ * channel is non-blocking) yielding from the current coroutine
Paolo Bonzini 0fb2b2
+ * multiple times until the entire content is written.  Otherwise
Paolo Bonzini 0fb2b2
+ * behaves as qio_channel_write().
Paolo Bonzini 0fb2b2
+ *
Paolo Bonzini 0fb2b2
+ * Returns: 0 if all bytes were written, or -1 on error
Paolo Bonzini 0fb2b2
+ */
Paolo Bonzini 0fb2b2
+int qio_channel_write_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                          const char *buf,
Paolo Bonzini 0fb2b2
+                          size_t buflen,
Paolo Bonzini 0fb2b2
+                          Error **errp);
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+/**
Paolo Bonzini 0fb2b2
  * qio_channel_set_blocking:
Paolo Bonzini 0fb2b2
  * @ioc: the channel object
Paolo Bonzini 0fb2b2
  * @enabled: the blocking flag state
Paolo Bonzini 0fb2b2
diff --git a/io/channel.c b/io/channel.c
Paolo Bonzini 0fb2b2
index 1cfb8b33a2..5e8c2f0a91 100644
Paolo Bonzini 0fb2b2
--- a/io/channel.c
Paolo Bonzini 0fb2b2
+++ b/io/channel.c
Paolo Bonzini 0fb2b2
@@ -22,6 +22,7 @@
Paolo Bonzini 0fb2b2
 #include "io/channel.h"
Paolo Bonzini 0fb2b2
 #include "qapi/error.h"
Paolo Bonzini 0fb2b2
 #include "qemu/main-loop.h"
Paolo Bonzini 0fb2b2
+#include "qemu/iov.h"
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 bool qio_channel_has_feature(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
                              QIOChannelFeature feature)
Paolo Bonzini 0fb2b2
@@ -85,6 +86,79 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
 }
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+int qio_channel_readv_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                          const struct iovec *iov,
Paolo Bonzini 0fb2b2
+                          size_t niov,
Paolo Bonzini 0fb2b2
+                          Error **errp)
Paolo Bonzini 0fb2b2
+{
Paolo Bonzini 0fb2b2
+    int ret = -1;
Paolo Bonzini 0fb2b2
+    struct iovec *local_iov = g_new(struct iovec, niov);
Paolo Bonzini 0fb2b2
+    struct iovec *local_iov_head = local_iov;
Paolo Bonzini 0fb2b2
+    unsigned int nlocal_iov = niov;
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+    nlocal_iov = iov_copy(local_iov, nlocal_iov,
Paolo Bonzini 0fb2b2
+                          iov, niov,
Paolo Bonzini 0fb2b2
+                          0, iov_size(iov, niov));
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+    while (nlocal_iov > 0) {
Paolo Bonzini 0fb2b2
+        ssize_t len;
Paolo Bonzini 0fb2b2
+        len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp);
Paolo Bonzini 0fb2b2
+        if (len == QIO_CHANNEL_ERR_BLOCK) {
Paolo Bonzini 0fb2b2
+            qio_channel_wait(ioc, G_IO_IN);
Paolo Bonzini 0fb2b2
+            continue;
Paolo Bonzini 0fb2b2
+        } else if (len < 0) {
Paolo Bonzini 0fb2b2
+            goto cleanup;
Paolo Bonzini 0fb2b2
+        } else if (len == 0) {
Paolo Bonzini 0fb2b2
+            error_setg(errp,
Paolo Bonzini 0fb2b2
+                       "Unexpected end-of-file before all bytes were read");
Paolo Bonzini 0fb2b2
+            goto cleanup;
Paolo Bonzini 0fb2b2
+        }
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+        iov_discard_front(&local_iov, &nlocal_iov, len);
Paolo Bonzini 0fb2b2
+    }
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+    ret = 0;
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+ cleanup:
Paolo Bonzini 0fb2b2
+    g_free(local_iov_head);
Paolo Bonzini 0fb2b2
+    return ret;
Paolo Bonzini 0fb2b2
+}
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+int qio_channel_writev_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                           const struct iovec *iov,
Paolo Bonzini 0fb2b2
+                           size_t niov,
Paolo Bonzini 0fb2b2
+                           Error **errp)
Paolo Bonzini 0fb2b2
+{
Paolo Bonzini 0fb2b2
+    int ret = -1;
Paolo Bonzini 0fb2b2
+    struct iovec *local_iov = g_new(struct iovec, niov);
Paolo Bonzini 0fb2b2
+    struct iovec *local_iov_head = local_iov;
Paolo Bonzini 0fb2b2
+    unsigned int nlocal_iov = niov;
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+    nlocal_iov = iov_copy(local_iov, nlocal_iov,
Paolo Bonzini 0fb2b2
+                          iov, niov,
Paolo Bonzini 0fb2b2
+                          0, iov_size(iov, niov));
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+    while (nlocal_iov > 0) {
Paolo Bonzini 0fb2b2
+        ssize_t len;
Paolo Bonzini 0fb2b2
+        len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp);
Paolo Bonzini 0fb2b2
+        if (len == QIO_CHANNEL_ERR_BLOCK) {
Paolo Bonzini 0fb2b2
+            qio_channel_wait(ioc, G_IO_OUT);
Paolo Bonzini 0fb2b2
+            continue;
Paolo Bonzini 0fb2b2
+        }
Paolo Bonzini 0fb2b2
+        if (len < 0) {
Paolo Bonzini 0fb2b2
+            goto cleanup;
Paolo Bonzini 0fb2b2
+        }
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+        iov_discard_front(&local_iov, &nlocal_iov, len);
Paolo Bonzini 0fb2b2
+    }
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+    ret = 0;
Paolo Bonzini 0fb2b2
+ cleanup:
Paolo Bonzini 0fb2b2
+    g_free(local_iov_head);
Paolo Bonzini 0fb2b2
+    return ret;
Paolo Bonzini 0fb2b2
+}
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
 ssize_t qio_channel_readv(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
                           const struct iovec *iov,
Paolo Bonzini 0fb2b2
                           size_t niov,
Paolo Bonzini 0fb2b2
@@ -123,6 +197,26 @@ ssize_t qio_channel_write(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
 }
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
+int qio_channel_read_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                         char *buf,
Paolo Bonzini 0fb2b2
+                         size_t buflen,
Paolo Bonzini 0fb2b2
+                         Error **errp)
Paolo Bonzini 0fb2b2
+{
Paolo Bonzini 0fb2b2
+    struct iovec iov = { .iov_base = buf, .iov_len = buflen };
Paolo Bonzini 0fb2b2
+    return qio_channel_readv_all(ioc, &iov, 1, errp);
Paolo Bonzini 0fb2b2
+}
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+int qio_channel_write_all(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
+                          const char *buf,
Paolo Bonzini 0fb2b2
+                          size_t buflen,
Paolo Bonzini 0fb2b2
+                          Error **errp)
Paolo Bonzini 0fb2b2
+{
Paolo Bonzini 0fb2b2
+    struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };
Paolo Bonzini 0fb2b2
+    return qio_channel_writev_all(ioc, &iov, 1, errp);
Paolo Bonzini 0fb2b2
+}
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
+
Paolo Bonzini 0fb2b2
 int qio_channel_set_blocking(QIOChannel *ioc,
Paolo Bonzini 0fb2b2
                               bool enabled,
Paolo Bonzini 0fb2b2
                               Error **errp)
Paolo Bonzini 0fb2b2
diff --git a/tests/io-channel-helpers.c b/tests/io-channel-helpers.c
Paolo Bonzini 0fb2b2
index 05e5579cf8..5430e1389d 100644
Paolo Bonzini 0fb2b2
--- a/tests/io-channel-helpers.c
Paolo Bonzini 0fb2b2
+++ b/tests/io-channel-helpers.c
Paolo Bonzini 0fb2b2
@@ -21,6 +21,7 @@
Paolo Bonzini 0fb2b2
 #include "qemu/osdep.h"
Paolo Bonzini 0fb2b2
 #include "io-channel-helpers.h"
Paolo Bonzini 0fb2b2
 #include "qapi/error.h"
Paolo Bonzini 0fb2b2
+#include "qemu/iov.h"
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 struct QIOChannelTest {
Paolo Bonzini 0fb2b2
     QIOChannel *src;
Paolo Bonzini 0fb2b2
@@ -37,77 +38,17 @@ struct QIOChannelTest {
Paolo Bonzini 0fb2b2
 };
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
-static void test_skip_iovec(struct iovec **iov,
Paolo Bonzini 0fb2b2
-                            size_t *niov,
Paolo Bonzini 0fb2b2
-                            size_t skip,
Paolo Bonzini 0fb2b2
-                            struct iovec *old)
Paolo Bonzini 0fb2b2
-{
Paolo Bonzini 0fb2b2
-    size_t offset = 0;
Paolo Bonzini 0fb2b2
-    size_t i;
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-    for (i = 0; i < *niov; i++) {
Paolo Bonzini 0fb2b2
-        if (skip < (*iov)[i].iov_len) {
Paolo Bonzini 0fb2b2
-            old->iov_len = (*iov)[i].iov_len;
Paolo Bonzini 0fb2b2
-            old->iov_base = (*iov)[i].iov_base;
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-            (*iov)[i].iov_len -= skip;
Paolo Bonzini 0fb2b2
-            (*iov)[i].iov_base += skip;
Paolo Bonzini 0fb2b2
-            break;
Paolo Bonzini 0fb2b2
-        } else {
Paolo Bonzini 0fb2b2
-            skip -= (*iov)[i].iov_len;
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-            if (i == 0 && old->iov_base) {
Paolo Bonzini 0fb2b2
-                (*iov)[i].iov_len = old->iov_len;
Paolo Bonzini 0fb2b2
-                (*iov)[i].iov_base = old->iov_base;
Paolo Bonzini 0fb2b2
-                old->iov_len = 0;
Paolo Bonzini 0fb2b2
-                old->iov_base = NULL;
Paolo Bonzini 0fb2b2
-            }
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-            offset++;
Paolo Bonzini 0fb2b2
-        }
Paolo Bonzini 0fb2b2
-    }
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-    *iov = *iov + offset;
Paolo Bonzini 0fb2b2
-    *niov -= offset;
Paolo Bonzini 0fb2b2
-}
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
 /* This thread sends all data using iovecs */
Paolo Bonzini 0fb2b2
 static gpointer test_io_thread_writer(gpointer opaque)
Paolo Bonzini 0fb2b2
 {
Paolo Bonzini 0fb2b2
     QIOChannelTest *data = opaque;
Paolo Bonzini 0fb2b2
-    struct iovec *iov = data->inputv;
Paolo Bonzini 0fb2b2
-    size_t niov = data->niov;
Paolo Bonzini 0fb2b2
-    struct iovec old = { 0 };
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
     qio_channel_set_blocking(data->src, data->blocking, NULL);
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
-    while (niov) {
Paolo Bonzini 0fb2b2
-        ssize_t ret;
Paolo Bonzini 0fb2b2
-        ret = qio_channel_writev(data->src,
Paolo Bonzini 0fb2b2
-                                 iov,
Paolo Bonzini 0fb2b2
-                                 niov,
Paolo Bonzini 0fb2b2
-                                 &data->writeerr);
Paolo Bonzini 0fb2b2
-        if (ret == QIO_CHANNEL_ERR_BLOCK) {
Paolo Bonzini 0fb2b2
-            if (data->blocking) {
Paolo Bonzini 0fb2b2
-                error_setg(&data->writeerr,
Paolo Bonzini 0fb2b2
-                           "Unexpected I/O blocking");
Paolo Bonzini 0fb2b2
-                break;
Paolo Bonzini 0fb2b2
-            } else {
Paolo Bonzini 0fb2b2
-                qio_channel_wait(data->src,
Paolo Bonzini 0fb2b2
-                                 G_IO_OUT);
Paolo Bonzini 0fb2b2
-                continue;
Paolo Bonzini 0fb2b2
-            }
Paolo Bonzini 0fb2b2
-        } else if (ret < 0) {
Paolo Bonzini 0fb2b2
-            break;
Paolo Bonzini 0fb2b2
-        } else if (ret == 0) {
Paolo Bonzini 0fb2b2
-            error_setg(&data->writeerr,
Paolo Bonzini 0fb2b2
-                       "Unexpected zero length write");
Paolo Bonzini 0fb2b2
-            break;
Paolo Bonzini 0fb2b2
-        }
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-        test_skip_iovec(&iov, &niov, ret, &old;;
Paolo Bonzini 0fb2b2
-    }
Paolo Bonzini 0fb2b2
+    qio_channel_writev_all(data->src,
Paolo Bonzini 0fb2b2
+                           data->inputv,
Paolo Bonzini 0fb2b2
+                           data->niov,
Paolo Bonzini 0fb2b2
+                           &data->writeerr);
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
     return NULL;
Paolo Bonzini 0fb2b2
 }
Paolo Bonzini 0fb2b2
@@ -117,38 +58,13 @@ static gpointer test_io_thread_writer(gpointer opaque)
Paolo Bonzini 0fb2b2
 static gpointer test_io_thread_reader(gpointer opaque)
Paolo Bonzini 0fb2b2
 {
Paolo Bonzini 0fb2b2
     QIOChannelTest *data = opaque;
Paolo Bonzini 0fb2b2
-    struct iovec *iov = data->outputv;
Paolo Bonzini 0fb2b2
-    size_t niov = data->niov;
Paolo Bonzini 0fb2b2
-    struct iovec old = { 0 };
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
     qio_channel_set_blocking(data->dst, data->blocking, NULL);
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
-    while (niov) {
Paolo Bonzini 0fb2b2
-        ssize_t ret;
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-        ret = qio_channel_readv(data->dst,
Paolo Bonzini 0fb2b2
-                                iov,
Paolo Bonzini 0fb2b2
-                                niov,
Paolo Bonzini 0fb2b2
-                                &data->readerr);
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-        if (ret == QIO_CHANNEL_ERR_BLOCK) {
Paolo Bonzini 0fb2b2
-            if (data->blocking) {
Paolo Bonzini 0fb2b2
-                error_setg(&data->readerr,
Paolo Bonzini 0fb2b2
-                           "Unexpected I/O blocking");
Paolo Bonzini 0fb2b2
-                break;
Paolo Bonzini 0fb2b2
-            } else {
Paolo Bonzini 0fb2b2
-                qio_channel_wait(data->dst,
Paolo Bonzini 0fb2b2
-                                 G_IO_IN);
Paolo Bonzini 0fb2b2
-                continue;
Paolo Bonzini 0fb2b2
-            }
Paolo Bonzini 0fb2b2
-        } else if (ret < 0) {
Paolo Bonzini 0fb2b2
-            break;
Paolo Bonzini 0fb2b2
-        } else if (ret == 0) {
Paolo Bonzini 0fb2b2
-            break;
Paolo Bonzini 0fb2b2
-        }
Paolo Bonzini 0fb2b2
-
Paolo Bonzini 0fb2b2
-        test_skip_iovec(&iov, &niov, ret, &old;;
Paolo Bonzini 0fb2b2
-    }
Paolo Bonzini 0fb2b2
+    qio_channel_readv_all(data->dst,
Paolo Bonzini 0fb2b2
+                          data->outputv,
Paolo Bonzini 0fb2b2
+                          data->niov,
Paolo Bonzini 0fb2b2
+                          &data->readerr);
Paolo Bonzini 0fb2b2
 
Paolo Bonzini 0fb2b2
     return NULL;
Paolo Bonzini 0fb2b2
 }
Paolo Bonzini 0fb2b2
-- 
Paolo Bonzini 0fb2b2
2.13.5
Paolo Bonzini 0fb2b2