Patchwork [06/41] qemu-file: pass errno from qemu_fflush via f->last_error

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

Comments

Paolo Bonzini - Feb. 15, 2013, 5:46 p.m.
This is done by almost all callers of qemu_fflush, move the code
directly to qemu_fflush.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 savevm.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
Orit Wasserman - Feb. 18, 2013, 9:20 a.m.
On 02/15/2013 07:46 PM, Paolo Bonzini wrote:
> This is done by almost all callers of qemu_fflush, move the code
> directly to qemu_fflush.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  savevm.c |   25 ++++++++++++-------------
>  1 files changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/savevm.c b/savevm.c
> index 4302903..a681177 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -453,13 +453,13 @@ static void qemu_file_set_error(QEMUFile *f, int ret)
>  /** Flushes QEMUFile buffer
>   *
>   */
> -static int qemu_fflush(QEMUFile *f)
> +static void qemu_fflush(QEMUFile *f)
>  {
>      int ret = 0;
>  
> -    if (!f->ops->put_buffer)
> -        return 0;
> -
> +    if (!f->ops->put_buffer) {
> +        return;
> +    }
>      if (f->is_write && f->buf_index > 0) {
>          ret = f->ops->put_buffer(f->opaque, f->buf, f->buf_offset, f->buf_index);
>          if (ret >= 0) {
> @@ -467,7 +467,9 @@ static int qemu_fflush(QEMUFile *f)
>          }
>          f->buf_index = 0;
>      }
> -    return ret;
> +    if (ret < 0) {
> +        qemu_file_set_error(f, ret);
> +    }
>  }
>  
>  static void qemu_fill_buffer(QEMUFile *f)
> @@ -518,7 +520,8 @@ int qemu_get_fd(QEMUFile *f)
>  int qemu_fclose(QEMUFile *f)
>  {
>      int ret;
> -    ret = qemu_fflush(f);
> +    qemu_fflush(f);
> +    ret = qemu_file_get_error(f);
>  
>      if (f->ops->close) {
>          int ret2 = f->ops->close(f->opaque);
> @@ -560,9 +563,8 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size)
>          buf += l;
>          size -= l;
>          if (f->buf_index >= IO_BUF_SIZE) {
> -            int ret = qemu_fflush(f);
> -            if (ret < 0) {
> -                qemu_file_set_error(f, ret);
> +            qemu_fflush(f);
> +            if (qemu_file_get_error(f)) {
>                  break;
>              }
>          }
> @@ -584,10 +586,7 @@ void qemu_put_byte(QEMUFile *f, int v)
>      f->buf[f->buf_index++] = v;
>      f->is_write = 1;
>      if (f->buf_index >= IO_BUF_SIZE) {
> -        int ret = qemu_fflush(f);
> -        if (ret < 0) {
> -            qemu_file_set_error(f, ret);
> -        }
> +        qemu_fflush(f);
>      }
>  }
>  
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Juan Quintela - Feb. 22, 2013, 10:40 a.m.
Paolo Bonzini <pbonzini@redhat.com> wrote:
> This is done by almost all callers of qemu_fflush, move the code
> directly to qemu_fflush.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

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

Patch

diff --git a/savevm.c b/savevm.c
index 4302903..a681177 100644
--- a/savevm.c
+++ b/savevm.c
@@ -453,13 +453,13 @@  static void qemu_file_set_error(QEMUFile *f, int ret)
 /** Flushes QEMUFile buffer
  *
  */
-static int qemu_fflush(QEMUFile *f)
+static void qemu_fflush(QEMUFile *f)
 {
     int ret = 0;
 
-    if (!f->ops->put_buffer)
-        return 0;
-
+    if (!f->ops->put_buffer) {
+        return;
+    }
     if (f->is_write && f->buf_index > 0) {
         ret = f->ops->put_buffer(f->opaque, f->buf, f->buf_offset, f->buf_index);
         if (ret >= 0) {
@@ -467,7 +467,9 @@  static int qemu_fflush(QEMUFile *f)
         }
         f->buf_index = 0;
     }
-    return ret;
+    if (ret < 0) {
+        qemu_file_set_error(f, ret);
+    }
 }
 
 static void qemu_fill_buffer(QEMUFile *f)
@@ -518,7 +520,8 @@  int qemu_get_fd(QEMUFile *f)
 int qemu_fclose(QEMUFile *f)
 {
     int ret;
-    ret = qemu_fflush(f);
+    qemu_fflush(f);
+    ret = qemu_file_get_error(f);
 
     if (f->ops->close) {
         int ret2 = f->ops->close(f->opaque);
@@ -560,9 +563,8 @@  void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size)
         buf += l;
         size -= l;
         if (f->buf_index >= IO_BUF_SIZE) {
-            int ret = qemu_fflush(f);
-            if (ret < 0) {
-                qemu_file_set_error(f, ret);
+            qemu_fflush(f);
+            if (qemu_file_get_error(f)) {
                 break;
             }
         }
@@ -584,10 +586,7 @@  void qemu_put_byte(QEMUFile *f, int v)
     f->buf[f->buf_index++] = v;
     f->is_write = 1;
     if (f->buf_index >= IO_BUF_SIZE) {
-        int ret = qemu_fflush(f);
-        if (ret < 0) {
-            qemu_file_set_error(f, ret);
-        }
+        qemu_fflush(f);
     }
 }