Patchwork [RFC,04/12] Add stdio_writev_buffer function

login
register
mail settings
Submitter Orit Wasserman
Date March 21, 2013, 9:09 a.m.
Message ID <1363856971-4601-5-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/229594/
State New
Headers show

Comments

Orit Wasserman - March 21, 2013, 9:09 a.m.
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 savevm.c | 6 ++++++
 1 file changed, 6 insertions(+)
Paolo Bonzini - March 21, 2013, 9:28 a.m.
Il 21/03/2013 10:09, Orit Wasserman ha scritto:
> Signed-off-by: Orit Wasserman <owasserm@redhat.com>
> ---
>  savevm.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/savevm.c b/savevm.c
> index 41dc87f..fa07a86 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -241,6 +241,11 @@ static int stdio_get_fd(void *opaque)
>      return fileno(s->stdio_file);
>  }
>  
> +static int stdio_writev_buffer(void *opaque, struct iovec *iov, int iovcnt)
> +{
> +    return iov_writev(stdio_get_fd(opaque), iov, iovcnt);
> +}
> +
>  static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
>  {
>      QEMUFileStdio *s = opaque;
> @@ -321,6 +326,7 @@ static const QEMUFileOps stdio_pipe_read_ops = {
>  static const QEMUFileOps stdio_pipe_write_ops = {
>      .get_fd =     stdio_get_fd,
>      .put_buffer = stdio_put_buffer,
> +    .writev_buffer = stdio_writev_buffer,
>      .close =      stdio_pclose
>  };
>  
> 

This may cause subtle bugs if the FILE* is written before opening the
QEMUFile, but not flushed.  It doesn't happen in QEMU, but it is not too
clean.  If you let qemu_fflush pick one of stdio_put_buffer or
stdio_writev_buffer, the problem disappears.

Paolo

Patch

diff --git a/savevm.c b/savevm.c
index 41dc87f..fa07a86 100644
--- a/savevm.c
+++ b/savevm.c
@@ -241,6 +241,11 @@  static int stdio_get_fd(void *opaque)
     return fileno(s->stdio_file);
 }
 
+static int stdio_writev_buffer(void *opaque, struct iovec *iov, int iovcnt)
+{
+    return iov_writev(stdio_get_fd(opaque), iov, iovcnt);
+}
+
 static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
 {
     QEMUFileStdio *s = opaque;
@@ -321,6 +326,7 @@  static const QEMUFileOps stdio_pipe_read_ops = {
 static const QEMUFileOps stdio_pipe_write_ops = {
     .get_fd =     stdio_get_fd,
     .put_buffer = stdio_put_buffer,
+    .writev_buffer = stdio_writev_buffer,
     .close =      stdio_pclose
 };