Patchwork [10/41] migration: use qemu_file_set_error

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 15, 2013, 5:46 p.m.
Message ID <1360950433-17106-11-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/220810/
State New
Headers show

Comments

Paolo Bonzini - Feb. 15, 2013, 5:46 p.m.
Remove the return value of buffered_flush, pass it via the error code
of s->file.  Once this is done, the error can be retrieved simply
via migrate_fd_close's call to qemu_fclose.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration.c |   22 ++++++----------------
 1 files changed, 6 insertions(+), 16 deletions(-)
Orit Wasserman - Feb. 18, 2013, 9:30 a.m.
On 02/15/2013 07:46 PM, Paolo Bonzini wrote:
> Remove the return value of buffered_flush, pass it via the error code
> of s->file.  Once this is done, the error can be retrieved simply
> via migrate_fd_close's call to qemu_fclose.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration.c |   22 ++++++----------------
>  1 files changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/migration.c b/migration.c
> index 609bd7c..6834d61 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -518,7 +518,7 @@ int64_t migrate_xbzrle_cache_size(void)
>  /* migration thread support */
>  
>  
> -static ssize_t buffered_flush(MigrationState *s)
> +static void buffered_flush(MigrationState *s)
>  {
>      size_t offset = 0;
>      ssize_t ret = 0;
> @@ -545,9 +545,8 @@ static ssize_t buffered_flush(MigrationState *s)
>      s->buffer_size -= offset;
>  
>      if (ret < 0) {
> -        return ret;
> +        qemu_file_set_error(s->file, ret);
>      }
> -    return offset;
>  }
>  
>  static int buffered_put_buffer(void *opaque, const uint8_t *buf,
> @@ -586,25 +585,15 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf,
>  static int buffered_close(void *opaque)
>  {
>      MigrationState *s = opaque;
> -    ssize_t ret = 0;
> -    int ret2;
>  
>      DPRINTF("closing\n");
>  
>      s->xfer_limit = INT_MAX;
>      while (!qemu_file_get_error(s->file) && s->buffer_size) {
> -        ret = buffered_flush(s);
> -        if (ret < 0) {
> -            break;
> -        }
> -    }
> -
> -    ret2 = migrate_fd_close(s);
> -    if (ret >= 0) {
> -        ret = ret2;
> +        buffered_flush(s);
>      }
>      s->complete = true;
> -    return ret;
> +    return migrate_fd_close(s);
>  }
>  
>  static int buffered_get_fd(void *opaque)
> @@ -741,7 +730,8 @@ static void *buffered_file_thread(void *opaque)
>              /* usleep expects microseconds */
>              g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
>          }
> -        ret = buffered_flush(s);
> +        buffered_flush(s);
> +        ret = qemu_file_get_error(s->file);
>      }
>  
>      if (ret < 0) {
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Juan Quintela - Feb. 22, 2013, 10:42 a.m.
Paolo Bonzini <pbonzini@redhat.com> wrote:
> Remove the return value of buffered_flush, pass it via the error code
> of s->file.  Once this is done, the error can be retrieved simply
> via migrate_fd_close's call to qemu_fclose.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

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

Patch

diff --git a/migration.c b/migration.c
index 609bd7c..6834d61 100644
--- a/migration.c
+++ b/migration.c
@@ -518,7 +518,7 @@  int64_t migrate_xbzrle_cache_size(void)
 /* migration thread support */
 
 
-static ssize_t buffered_flush(MigrationState *s)
+static void buffered_flush(MigrationState *s)
 {
     size_t offset = 0;
     ssize_t ret = 0;
@@ -545,9 +545,8 @@  static ssize_t buffered_flush(MigrationState *s)
     s->buffer_size -= offset;
 
     if (ret < 0) {
-        return ret;
+        qemu_file_set_error(s->file, ret);
     }
-    return offset;
 }
 
 static int buffered_put_buffer(void *opaque, const uint8_t *buf,
@@ -586,25 +585,15 @@  static int buffered_put_buffer(void *opaque, const uint8_t *buf,
 static int buffered_close(void *opaque)
 {
     MigrationState *s = opaque;
-    ssize_t ret = 0;
-    int ret2;
 
     DPRINTF("closing\n");
 
     s->xfer_limit = INT_MAX;
     while (!qemu_file_get_error(s->file) && s->buffer_size) {
-        ret = buffered_flush(s);
-        if (ret < 0) {
-            break;
-        }
-    }
-
-    ret2 = migrate_fd_close(s);
-    if (ret >= 0) {
-        ret = ret2;
+        buffered_flush(s);
     }
     s->complete = true;
-    return ret;
+    return migrate_fd_close(s);
 }
 
 static int buffered_get_fd(void *opaque)
@@ -741,7 +730,8 @@  static void *buffered_file_thread(void *opaque)
             /* usleep expects microseconds */
             g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
         }
-        ret = buffered_flush(s);
+        buffered_flush(s);
+        ret = qemu_file_get_error(s->file);
     }
 
     if (ret < 0) {