Patchwork [1/4] savevm: teach qemu_fill_buffer to do partial refills

login
register
mail settings
Submitter Juan Quintela
Date Oct. 4, 2011, 2:38 p.m.
Message ID <b7364a48b984bf28cd7f64c01d60ddcbbc76a189.1317738629.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/117630/
State New
Headers show

Comments

Juan Quintela - Oct. 4, 2011, 2:38 p.m.
We will need on next patch to be able to lookahead on next patch

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 savevm.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
Anthony Liguori - Oct. 5, 2011, 7:41 p.m.
On 10/04/2011 09:38 AM, Juan Quintela wrote:
> We will need on next patch to be able to lookahead on next patch
>
> Signed-off-by: Juan Quintela<quintela@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   savevm.c |   14 +++++++++++---
>   1 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/savevm.c b/savevm.c
> index 46f2447..31131df 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -455,6 +455,7 @@ void qemu_fflush(QEMUFile *f)
>   static void qemu_fill_buffer(QEMUFile *f)
>   {
>       int len;
> +    int used;
>
>       if (!f->get_buffer)
>           return;
> @@ -462,10 +463,17 @@ static void qemu_fill_buffer(QEMUFile *f)
>       if (f->is_write)
>           abort();
>
> -    len = f->get_buffer(f->opaque, f->buf, f->buf_offset, IO_BUF_SIZE);
> +    used = f->buf_size - f->buf_index;
> +    if (used>  0) {
> +        memmove(f->buf, f->buf + f->buf_index, used);
> +    }
> +    f->buf_index = 0;
> +    f->buf_size = used;
> +
> +    len = f->get_buffer(f->opaque, f->buf + used, f->buf_offset,
> +                        IO_BUF_SIZE - used);
>       if (len>  0) {
> -        f->buf_index = 0;
> -        f->buf_size = len;
> +        f->buf_size += len;
>           f->buf_offset += len;
>       } else if (len != -EAGAIN)
>           f->has_error = 1;

Patch

diff --git a/savevm.c b/savevm.c
index 46f2447..31131df 100644
--- a/savevm.c
+++ b/savevm.c
@@ -455,6 +455,7 @@  void qemu_fflush(QEMUFile *f)
 static void qemu_fill_buffer(QEMUFile *f)
 {
     int len;
+    int used;

     if (!f->get_buffer)
         return;
@@ -462,10 +463,17 @@  static void qemu_fill_buffer(QEMUFile *f)
     if (f->is_write)
         abort();

-    len = f->get_buffer(f->opaque, f->buf, f->buf_offset, IO_BUF_SIZE);
+    used = f->buf_size - f->buf_index;
+    if (used > 0) {
+        memmove(f->buf, f->buf + f->buf_index, used);
+    }
+    f->buf_index = 0;
+    f->buf_size = used;
+
+    len = f->get_buffer(f->opaque, f->buf + used, f->buf_offset,
+                        IO_BUF_SIZE - used);
     if (len > 0) {
-        f->buf_index = 0;
-        f->buf_size = len;
+        f->buf_size += len;
         f->buf_offset += len;
     } else if (len != -EAGAIN)
         f->has_error = 1;