Patchwork [v3,5/9] Use writev ops if available

login
register
mail settings
Submitter Orit Wasserman
Date March 21, 2013, 4:05 p.m.
Message ID <1363881940-27505-6-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/229755/
State New
Headers show

Comments

Orit Wasserman - March 21, 2013, 4:05 p.m.
Update qemu_fflush and stdio_close to use writev ops if they are available
Use the buffers stored in the iovec.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 savevm.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
Juan Quintela - March 21, 2013, 5:17 p.m.
Orit Wasserman <owasserm@redhat.com> wrote:
> Update qemu_fflush and stdio_close to use writev ops if they are available
> Use the buffers stored in the iovec.
>
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

I think that qemu_fflush() should only be called for QEMUFiles opened in
write mode, but that is independent of this series.

Patch

diff --git a/savevm.c b/savevm.c
index ab81dd3..f69dce3 100644
--- a/savevm.c
+++ b/savevm.c
@@ -292,7 +292,7 @@  static int stdio_fclose(void *opaque)
     QEMUFileStdio *s = opaque;
     int ret = 0;
 
-    if (s->file->ops->put_buffer) {
+    if (s->file->ops->put_buffer || s->file->ops->writev_buffer) {
         int fd = fileno(s->stdio_file);
         struct stat st;
 
@@ -515,24 +515,40 @@  static void qemu_file_set_error(QEMUFile *f, int ret)
     }
 }
 
-/** Flushes QEMUFile buffer
+/**
+ * Flushes QEMUFile buffer
  *
+ * If there is writev_buffer QEMUFileOps it uses it otherwise uses
+ * put_buffer ops.
  */
 static void qemu_fflush(QEMUFile *f)
 {
     int ret = 0;
+    int i = 0;
 
-    if (!f->ops->put_buffer) {
+    if (!f->ops->writev_buffer && !f->ops->put_buffer) {
         return;
     }
-    if (f->is_write && f->buf_index > 0) {
-        ret = f->ops->put_buffer(f->opaque, f->buf, f->pos, f->buf_index);
-        if (ret >= 0) {
-            f->pos += f->buf_index;
+
+    if (f->is_write && f->iovcnt > 0) {
+        if (f->ops->writev_buffer) {
+            ret = f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt);
+            if (ret >= 0) {
+                f->pos += ret;
+            }
+        } else {
+            for (i = 0; i < f->iovcnt && ret >= 0; i++) {
+                ret = f->ops->put_buffer(f->opaque, f->iov[i].iov_base, f->pos,
+                                         f->iov[i].iov_len);
+                if (ret >= 0) {
+                    f->pos += ret;
+                }
+            }
         }
         f->buf_index = 0;
         f->iovcnt = 0;
     }
+
     if (ret < 0) {
         qemu_file_set_error(f, ret);
     }