Patchwork [31/41] savevm: unfold qemu_fclose_internal()

login
register
mail settings
Submitter Juan Quintela
Date Sept. 21, 2012, 8:47 a.m.
Message ID <1348217255-22441-32-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/185642/
State New
Headers show

Comments

Juan Quintela - Sept. 21, 2012, 8:47 a.m.
It was used only one, and was only one if.  It makes error handling
saner.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 savevm.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
Paolo Bonzini - Sept. 21, 2012, 12:48 p.m.
Il 21/09/2012 10:47, Juan Quintela ha scritto:
> It was used only one, and was only one if.  It makes error handling
> saner.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  savevm.c | 26 ++++++--------------------
>  1 file changed, 6 insertions(+), 20 deletions(-)
> 
> diff --git a/savevm.c b/savevm.c
> index 0953695..8efa7cc 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -506,22 +506,6 @@ static void qemu_fill_buffer(QEMUFile *f)
>          qemu_file_set_error(f, len);
>  }
> 
> -/** Calls close function and set last_error if needed
> - *
> - * Internal function. qemu_fflush() must be called before this.
> - *
> - * Returns f->close() return value, or 0 if close function is not set.
> - */
> -static int qemu_fclose_internal(QEMUFile *f)
> -{
> -    int ret = 0;
> -    if (f->close) {
> -        ret = f->close(f->opaque);
> -        qemu_file_set_if_error(f, ret);
> -    }
> -    return ret;
> -}
> -
>  /** Closes the file
>   *
>   * Returns negative error value if any error happened on previous operations or
> @@ -532,12 +516,14 @@ static int qemu_fclose_internal(QEMUFile *f)
>   */
>  int qemu_fclose(QEMUFile *f)
>  {
> -    int ret, ret2;
> +    int ret;
>      ret = qemu_fflush(f);
> -    ret2 = qemu_fclose_internal(f);
> 
> -    if (ret >= 0) {
> -        ret = ret2;
> +    if (f->close) {
> +        int ret2 = f->close(f->opaque);
> +        if (ret >= 0) {
> +            ret = ret2;
> +        }
>      }
>      /* If any error was spotted before closing, we should report it
>       * instead of the close() return value.
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Patch

diff --git a/savevm.c b/savevm.c
index 0953695..8efa7cc 100644
--- a/savevm.c
+++ b/savevm.c
@@ -506,22 +506,6 @@  static void qemu_fill_buffer(QEMUFile *f)
         qemu_file_set_error(f, len);
 }

-/** Calls close function and set last_error if needed
- *
- * Internal function. qemu_fflush() must be called before this.
- *
- * Returns f->close() return value, or 0 if close function is not set.
- */
-static int qemu_fclose_internal(QEMUFile *f)
-{
-    int ret = 0;
-    if (f->close) {
-        ret = f->close(f->opaque);
-        qemu_file_set_if_error(f, ret);
-    }
-    return ret;
-}
-
 /** Closes the file
  *
  * Returns negative error value if any error happened on previous operations or
@@ -532,12 +516,14 @@  static int qemu_fclose_internal(QEMUFile *f)
  */
 int qemu_fclose(QEMUFile *f)
 {
-    int ret, ret2;
+    int ret;
     ret = qemu_fflush(f);
-    ret2 = qemu_fclose_internal(f);

-    if (ret >= 0) {
-        ret = ret2;
+    if (f->close) {
+        int ret2 = f->close(f->opaque);
+        if (ret >= 0) {
+            ret = ret2;
+        }
     }
     /* If any error was spotted before closing, we should report it
      * instead of the close() return value.