diff mbox

[09/20] cow: correctly propagate errors

Message ID 1391939335-31580-10-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Feb. 9, 2014, 9:48 a.m. UTC
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/cow.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Fam Zheng Feb. 10, 2014, 8:04 a.m. UTC | #1
On Sun, 02/09 10:48, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block/cow.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/block/cow.c b/block/cow.c
> index 7fc0b12..43a2150 100644
> --- a/block/cow.c
> +++ b/block/cow.c
> @@ -82,7 +82,7 @@ static int cow_open(BlockDriverState *bs, QDict *options, int flags,
>          char version[64];
>          snprintf(version, sizeof(version),
>                 "COW version %d", cow_header.version);
> -        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
> +        error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
>              bs->device_name, "cow", version);
>          ret = -ENOTSUP;
>          goto fail;
> @@ -330,7 +330,6 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
>      struct stat st;
>      int64_t image_sectors = 0;
>      const char *image_filename = NULL;
> -    Error *local_err = NULL;
>      int ret;
>      BlockDriverState *cow_bs;
>  
> @@ -344,18 +343,13 @@ static int cow_create(const char *filename, QEMUOptionParameter *options,
>          options++;
>      }
>  
> -    ret = bdrv_create_file(filename, options, &local_err);
> +    ret = bdrv_create_file(filename, options, errp);
>      if (ret < 0) {
> -        qerror_report_err(local_err);
> -        error_free(local_err);
>          return ret;
>      }
>  
> -    ret = bdrv_file_open(&cow_bs, filename, NULL, NULL, BDRV_O_RDWR,
> -                         &local_err);
> +    ret = bdrv_file_open(&cow_bs, filename, NULL, NULL, BDRV_O_RDWR, errp);
>      if (ret < 0) {
> -        qerror_report_err(local_err);
> -        error_free(local_err);
>          return ret;
>      }
>  
> -- 
> 1.8.5.3
> 

I'm never sure about choice of using local_err with error_propagate, or
straightly pass errp, but the logic still looks right to me, so,

Reviewed-by: Fam Zheng <famz@redhat.com>
Paolo Bonzini Feb. 10, 2014, 8:28 a.m. UTC | #2
Il 10/02/2014 09:04, Fam Zheng ha scritto:
> I'm never sure about choice of using local_err with error_propagate, or
> straightly pass errp, but the logic still looks right to me, so,

Basically, never use error_is_set.  If you do, you probably should have 
used instead &local_err and error_propagate.  If you are not using 
error_is_set, it's fine to use errp directly with no error_propagate.

Paolo

> Reviewed-by: Fam Zheng <famz@redhat.com>
diff mbox

Patch

diff --git a/block/cow.c b/block/cow.c
index 7fc0b12..43a2150 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -82,7 +82,7 @@  static int cow_open(BlockDriverState *bs, QDict *options, int flags,
         char version[64];
         snprintf(version, sizeof(version),
                "COW version %d", cow_header.version);
-        qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
+        error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
             bs->device_name, "cow", version);
         ret = -ENOTSUP;
         goto fail;
@@ -330,7 +330,6 @@  static int cow_create(const char *filename, QEMUOptionParameter *options,
     struct stat st;
     int64_t image_sectors = 0;
     const char *image_filename = NULL;
-    Error *local_err = NULL;
     int ret;
     BlockDriverState *cow_bs;
 
@@ -344,18 +343,13 @@  static int cow_create(const char *filename, QEMUOptionParameter *options,
         options++;
     }
 
-    ret = bdrv_create_file(filename, options, &local_err);
+    ret = bdrv_create_file(filename, options, errp);
     if (ret < 0) {
-        qerror_report_err(local_err);
-        error_free(local_err);
         return ret;
     }
 
-    ret = bdrv_file_open(&cow_bs, filename, NULL, NULL, BDRV_O_RDWR,
-                         &local_err);
+    ret = bdrv_file_open(&cow_bs, filename, NULL, NULL, BDRV_O_RDWR, errp);
     if (ret < 0) {
-        qerror_report_err(local_err);
-        error_free(local_err);
         return ret;
     }