[Qemu-devel] [RFC 04/12] Add stdio_writev_buffer function

2013-03-21 Thread Orit Wasserman
Signed-off-by: Orit Wasserman owass...@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
 };
 
-- 
1.7.11.7




Re: [Qemu-devel] [RFC 04/12] Add stdio_writev_buffer function

2013-03-21 Thread Paolo Bonzini
Il 21/03/2013 10:09, Orit Wasserman ha scritto:
 Signed-off-by: Orit Wasserman owass...@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