qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors
@ 2012-11-30 12:52 Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 1/6] block: bdrv_img_create(): add Error ** argument Luiz Capitulino
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

By adding error propagation to bdrv_img_create() we improve error reporting
in QMP and simplify qemu-img.c:img_create() a bit.

o v3

 - Update qmp_drive_mirror()

o Patches changed:

 - 1/6 (changed)
 - 5/6 (new patch)

Luiz Capitulino (6):
  block: bdrv_img_create(): add Error ** argument
  qemu-img: img_create(): pass Error object to bdrv_img_create()
  qemu-img: img_create(): drop unneeded goto and ret variable
  qmp: qmp_transaction(): pass Error object to bdrv_img_create()
  qmp: qmp_drive_mirror(): pass Error object to bdrv_img_create()
  block: bdrv_img_create(): drop unused error handling code

 block.c    | 60 +++++++++++++++++++++++++-----------------------------------
 block.h    |  6 +++---
 blockdev.c | 29 +++++++++++++++--------------
 qemu-img.c | 19 ++++++++++---------
 4 files changed, 53 insertions(+), 61 deletions(-)

-- 
1.8.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/6] block: bdrv_img_create(): add Error ** argument
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
@ 2012-11-30 12:52 ` Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 2/6] qemu-img: img_create(): pass Error object to bdrv_img_create() Luiz Capitulino
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

This commit adds an Error ** argument to bdrv_img_create() and set it
appropriately on error.

Callers of bdrv_img_create() pass NULL for the new argument and still
rely on bdrv_img_create()'s return value. Next commits will change
callers to use the Error object instead.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block.c    | 22 +++++++++++++++++++++-
 block.h    |  2 +-
 blockdev.c |  6 +++---
 qemu-img.c |  2 +-
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index c05875f..9ee0036 100644
--- a/block.c
+++ b/block.c
@@ -4410,7 +4410,7 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
 
 int bdrv_img_create(const char *filename, const char *fmt,
                     const char *base_filename, const char *base_fmt,
-                    char *options, uint64_t img_size, int flags)
+                    char *options, uint64_t img_size, int flags, Error **errp)
 {
     QEMUOptionParameter *param = NULL, *create_options = NULL;
     QEMUOptionParameter *backing_fmt, *backing_file, *size;
@@ -4423,6 +4423,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
     drv = bdrv_find_format(fmt);
     if (!drv) {
         error_report("Unknown file format '%s'", fmt);
+        error_setg(errp, "Unknown file format '%s'", fmt);
         ret = -EINVAL;
         goto out;
     }
@@ -4430,6 +4431,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
     proto_drv = bdrv_find_protocol(filename);
     if (!proto_drv) {
         error_report("Unknown protocol '%s'", filename);
+        error_setg(errp, "Unknown protocol '%s'", filename);
         ret = -EINVAL;
         goto out;
     }
@@ -4449,6 +4451,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
         param = parse_option_parameters(options, create_options, param);
         if (param == NULL) {
             error_report("Invalid options for file format '%s'.", fmt);
+            error_setg(errp, "Invalid options for file format '%s'.", fmt);
             ret = -EINVAL;
             goto out;
         }
@@ -4459,6 +4462,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
                                  base_filename)) {
             error_report("Backing file not supported for file format '%s'",
                          fmt);
+            error_setg(errp, "Backing file not supported for file format '%s'",
+                       fmt);
             ret = -EINVAL;
             goto out;
         }
@@ -4468,6 +4473,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
         if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
             error_report("Backing file format not supported for file "
                          "format '%s'", fmt);
+            error_setg(errp, "Backing file format not supported for file "
+                             "format '%s'", fmt);
             ret = -EINVAL;
             goto out;
         }
@@ -4478,6 +4485,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
         if (!strcmp(filename, backing_file->value.s)) {
             error_report("Error: Trying to create an image with the "
                          "same filename as the backing file");
+            error_setg(errp, "Error: Trying to create an image with the "
+                             "same filename as the backing file");
             ret = -EINVAL;
             goto out;
         }
@@ -4489,6 +4498,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
         if (!backing_drv) {
             error_report("Unknown backing file format '%s'",
                          backing_fmt->value.s);
+            error_setg(errp, "Unknown backing file format '%s'",
+                       backing_fmt->value.s);
             ret = -EINVAL;
             goto out;
         }
@@ -4512,6 +4523,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
             ret = bdrv_open(bs, backing_file->value.s, back_flags, backing_drv);
             if (ret < 0) {
                 error_report("Could not open '%s'", backing_file->value.s);
+                error_setg_errno(errp, -ret, "Could not open '%s'",
+                                 backing_file->value.s);
                 goto out;
             }
             bdrv_get_geometry(bs, &size);
@@ -4521,6 +4534,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
             set_option_parameter(param, BLOCK_OPT_SIZE, buf);
         } else {
             error_report("Image creation needs a size parameter");
+            error_setg(errp, "Image creation needs a size parameter");
             ret = -EINVAL;
             goto out;
         }
@@ -4536,12 +4550,18 @@ int bdrv_img_create(const char *filename, const char *fmt,
         if (ret == -ENOTSUP) {
             error_report("Formatting or formatting option not supported for "
                          "file format '%s'", fmt);
+            error_setg(errp,"Formatting or formatting option not supported for "
+                            "file format '%s'", fmt);
         } else if (ret == -EFBIG) {
             error_report("The image size is too large for file format '%s'",
                          fmt);
+            error_setg(errp, "The image size is too large for file format '%s'",
+                       fmt);
         } else {
             error_report("%s: error while creating %s: %s", filename, fmt,
                          strerror(-ret));
+            error_setg(errp, "%s: error while creating %s: %s", filename, fmt,
+                       strerror(-ret));
         }
     }
 
diff --git a/block.h b/block.h
index 722c620..ff54d15 100644
--- a/block.h
+++ b/block.h
@@ -345,7 +345,7 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
 
 int bdrv_img_create(const char *filename, const char *fmt,
                     const char *base_filename, const char *base_fmt,
-                    char *options, uint64_t img_size, int flags);
+                    char *options, uint64_t img_size, int flags, Error **errp);
 
 void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
diff --git a/blockdev.c b/blockdev.c
index e73fd6e..2ec02ac 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -789,7 +789,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
             ret = bdrv_img_create(new_image_file, format,
                                   states->old_bs->filename,
                                   states->old_bs->drv->format_name,
-                                  NULL, -1, flags);
+                                  NULL, -1, flags, NULL);
             if (ret) {
                 error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
                 goto delete_and_fail;
@@ -1264,7 +1264,7 @@ void qmp_drive_mirror(const char *device, const char *target,
         bdrv_get_geometry(bs, &size);
         size *= 512;
         ret = bdrv_img_create(target, format,
-                              NULL, NULL, NULL, size, flags);
+                              NULL, NULL, NULL, size, flags, NULL);
     } else {
         switch (mode) {
         case NEW_IMAGE_MODE_EXISTING:
@@ -1275,7 +1275,7 @@ void qmp_drive_mirror(const char *device, const char *target,
             ret = bdrv_img_create(target, format,
                                   source->filename,
                                   source->drv->format_name,
-                                  NULL, -1, flags);
+                                  NULL, -1, flags, NULL);
             break;
         default:
             abort();
diff --git a/qemu-img.c b/qemu-img.c
index e29e01b..3896689 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -362,7 +362,7 @@ static int img_create(int argc, char **argv)
     }
 
     ret = bdrv_img_create(filename, fmt, base_filename, base_fmt,
-                          options, img_size, BDRV_O_FLAGS);
+                          options, img_size, BDRV_O_FLAGS, NULL);
 out:
     if (ret) {
         return 1;
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/6] qemu-img: img_create(): pass Error object to bdrv_img_create()
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 1/6] block: bdrv_img_create(): add Error ** argument Luiz Capitulino
@ 2012-11-30 12:52 ` Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 3/6] qemu-img: img_create(): drop unneeded goto and ret variable Luiz Capitulino
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qemu-img.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 3896689..595b6f5 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -301,6 +301,7 @@ static int img_create(int argc, char **argv)
     const char *filename;
     const char *base_filename = NULL;
     char *options = NULL;
+    Error *local_err = NULL;
 
     for(;;) {
         c = getopt(argc, argv, "F:b:f:he6o:");
@@ -361,8 +362,14 @@ static int img_create(int argc, char **argv)
         goto out;
     }
 
-    ret = bdrv_img_create(filename, fmt, base_filename, base_fmt,
-                          options, img_size, BDRV_O_FLAGS, NULL);
+    bdrv_img_create(filename, fmt, base_filename, base_fmt,
+                    options, img_size, BDRV_O_FLAGS, &local_err);
+    if (error_is_set(&local_err)) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
+        ret = -1;
+    }
+
 out:
     if (ret) {
         return 1;
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/6] qemu-img: img_create(): drop unneeded goto and ret variable
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 1/6] block: bdrv_img_create(): add Error ** argument Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 2/6] qemu-img: img_create(): pass Error object to bdrv_img_create() Luiz Capitulino
@ 2012-11-30 12:52 ` Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 4/6] qmp: qmp_transaction(): pass Error object to bdrv_img_create() Luiz Capitulino
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qemu-img.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 595b6f5..c4dae88 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -294,7 +294,7 @@ static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
 
 static int img_create(int argc, char **argv)
 {
-    int c, ret = 0;
+    int c;
     uint64_t img_size = -1;
     const char *fmt = "raw";
     const char *base_fmt = NULL;
@@ -351,15 +351,13 @@ static int img_create(int argc, char **argv)
             error_report("Invalid image size specified! You may use k, M, G or "
                   "T suffixes for ");
             error_report("kilobytes, megabytes, gigabytes and terabytes.");
-            ret = -1;
-            goto out;
+            return 1;
         }
         img_size = (uint64_t)sval;
     }
 
     if (options && is_help_option(options)) {
-        ret = print_block_option_help(filename, fmt);
-        goto out;
+        return print_block_option_help(filename, fmt);
     }
 
     bdrv_img_create(filename, fmt, base_filename, base_fmt,
@@ -367,13 +365,9 @@ static int img_create(int argc, char **argv)
     if (error_is_set(&local_err)) {
         error_report("%s", error_get_pretty(local_err));
         error_free(local_err);
-        ret = -1;
-    }
-
-out:
-    if (ret) {
         return 1;
     }
+
     return 0;
 }
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 4/6] qmp: qmp_transaction(): pass Error object to bdrv_img_create()
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
                   ` (2 preceding siblings ...)
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 3/6] qemu-img: img_create(): drop unneeded goto and ret variable Luiz Capitulino
@ 2012-11-30 12:52 ` Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 5/6] qmp: qmp_drive_mirror(): " Luiz Capitulino
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 blockdev.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 2ec02ac..cc9692d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -707,6 +707,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
     int ret = 0;
     BlockdevActionList *dev_entry = dev_list;
     BlkTransactionStates *states, *next;
+    Error *local_err = NULL;
 
     QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionStates) snap_bdrv_states;
     QSIMPLEQ_INIT(&snap_bdrv_states);
@@ -786,12 +787,12 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
 
         /* create new image w/backing file */
         if (mode != NEW_IMAGE_MODE_EXISTING) {
-            ret = bdrv_img_create(new_image_file, format,
-                                  states->old_bs->filename,
-                                  states->old_bs->drv->format_name,
-                                  NULL, -1, flags, NULL);
-            if (ret) {
-                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+            bdrv_img_create(new_image_file, format,
+                            states->old_bs->filename,
+                            states->old_bs->drv->format_name,
+                            NULL, -1, flags, &local_err);
+            if (error_is_set(&local_err)) {
+                error_propagate(errp, local_err);
                 goto delete_and_fail;
             }
         }
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 5/6] qmp: qmp_drive_mirror(): pass Error object to bdrv_img_create()
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
                   ` (3 preceding siblings ...)
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 4/6] qmp: qmp_transaction(): pass Error object to bdrv_img_create() Luiz Capitulino
@ 2012-11-30 12:52 ` Luiz Capitulino
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 6/6] block: bdrv_img_create(): drop unused error handling code Luiz Capitulino
  2012-11-30 13:19 ` [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Kevin Wolf
  6 siblings, 0 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 blockdev.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index cc9692d..6b293fe 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1264,8 +1264,8 @@ void qmp_drive_mirror(const char *device, const char *target,
         assert(format && drv);
         bdrv_get_geometry(bs, &size);
         size *= 512;
-        ret = bdrv_img_create(target, format,
-                              NULL, NULL, NULL, size, flags, NULL);
+        bdrv_img_create(target, format,
+                        NULL, NULL, NULL, size, flags, &local_err);
     } else {
         switch (mode) {
         case NEW_IMAGE_MODE_EXISTING:
@@ -1273,18 +1273,18 @@ void qmp_drive_mirror(const char *device, const char *target,
             break;
         case NEW_IMAGE_MODE_ABSOLUTE_PATHS:
             /* create new image with backing file */
-            ret = bdrv_img_create(target, format,
-                                  source->filename,
-                                  source->drv->format_name,
-                                  NULL, -1, flags, NULL);
+            bdrv_img_create(target, format,
+                            source->filename,
+                            source->drv->format_name,
+                            NULL, -1, flags, &local_err);
             break;
         default:
             abort();
         }
     }
 
-    if (ret) {
-        error_set(errp, QERR_OPEN_FILE_FAILED, target);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
         return;
     }
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 6/6] block: bdrv_img_create(): drop unused error handling code
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
                   ` (4 preceding siblings ...)
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 5/6] qmp: qmp_drive_mirror(): " Luiz Capitulino
@ 2012-11-30 12:52 ` Luiz Capitulino
  2012-11-30 13:19 ` [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Kevin Wolf
  6 siblings, 0 replies; 8+ messages in thread
From: Luiz Capitulino @ 2012-11-30 12:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pbonzini, armbru

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block.c | 40 +++++-----------------------------------
 block.h |  6 +++---
 2 files changed, 8 insertions(+), 38 deletions(-)

diff --git a/block.c b/block.c
index 9ee0036..3ca6126 100644
--- a/block.c
+++ b/block.c
@@ -4408,9 +4408,9 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
     bs->total_time_ns[cookie->type] += get_clock() - cookie->start_time_ns;
 }
 
-int bdrv_img_create(const char *filename, const char *fmt,
-                    const char *base_filename, const char *base_fmt,
-                    char *options, uint64_t img_size, int flags, Error **errp)
+void bdrv_img_create(const char *filename, const char *fmt,
+                     const char *base_filename, const char *base_fmt,
+                     char *options, uint64_t img_size, int flags, Error **errp)
 {
     QEMUOptionParameter *param = NULL, *create_options = NULL;
     QEMUOptionParameter *backing_fmt, *backing_file, *size;
@@ -4422,18 +4422,14 @@ int bdrv_img_create(const char *filename, const char *fmt,
     /* Find driver and parse its options */
     drv = bdrv_find_format(fmt);
     if (!drv) {
-        error_report("Unknown file format '%s'", fmt);
         error_setg(errp, "Unknown file format '%s'", fmt);
-        ret = -EINVAL;
-        goto out;
+        return;
     }
 
     proto_drv = bdrv_find_protocol(filename);
     if (!proto_drv) {
-        error_report("Unknown protocol '%s'", filename);
         error_setg(errp, "Unknown protocol '%s'", filename);
-        ret = -EINVAL;
-        goto out;
+        return;
     }
 
     create_options = append_option_parameters(create_options,
@@ -4450,9 +4446,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
     if (options) {
         param = parse_option_parameters(options, create_options, param);
         if (param == NULL) {
-            error_report("Invalid options for file format '%s'.", fmt);
             error_setg(errp, "Invalid options for file format '%s'.", fmt);
-            ret = -EINVAL;
             goto out;
         }
     }
@@ -4460,22 +4454,16 @@ int bdrv_img_create(const char *filename, const char *fmt,
     if (base_filename) {
         if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE,
                                  base_filename)) {
-            error_report("Backing file not supported for file format '%s'",
-                         fmt);
             error_setg(errp, "Backing file not supported for file format '%s'",
                        fmt);
-            ret = -EINVAL;
             goto out;
         }
     }
 
     if (base_fmt) {
         if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) {
-            error_report("Backing file format not supported for file "
-                         "format '%s'", fmt);
             error_setg(errp, "Backing file format not supported for file "
                              "format '%s'", fmt);
-            ret = -EINVAL;
             goto out;
         }
     }
@@ -4483,11 +4471,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
     backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
     if (backing_file && backing_file->value.s) {
         if (!strcmp(filename, backing_file->value.s)) {
-            error_report("Error: Trying to create an image with the "
-                         "same filename as the backing file");
             error_setg(errp, "Error: Trying to create an image with the "
                              "same filename as the backing file");
-            ret = -EINVAL;
             goto out;
         }
     }
@@ -4496,11 +4481,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
     if (backing_fmt && backing_fmt->value.s) {
         backing_drv = bdrv_find_format(backing_fmt->value.s);
         if (!backing_drv) {
-            error_report("Unknown backing file format '%s'",
-                         backing_fmt->value.s);
             error_setg(errp, "Unknown backing file format '%s'",
                        backing_fmt->value.s);
-            ret = -EINVAL;
             goto out;
         }
     }
@@ -4522,7 +4504,6 @@ int bdrv_img_create(const char *filename, const char *fmt,
 
             ret = bdrv_open(bs, backing_file->value.s, back_flags, backing_drv);
             if (ret < 0) {
-                error_report("Could not open '%s'", backing_file->value.s);
                 error_setg_errno(errp, -ret, "Could not open '%s'",
                                  backing_file->value.s);
                 goto out;
@@ -4533,9 +4514,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
             snprintf(buf, sizeof(buf), "%" PRId64, size);
             set_option_parameter(param, BLOCK_OPT_SIZE, buf);
         } else {
-            error_report("Image creation needs a size parameter");
             error_setg(errp, "Image creation needs a size parameter");
-            ret = -EINVAL;
             goto out;
         }
     }
@@ -4545,21 +4524,14 @@ int bdrv_img_create(const char *filename, const char *fmt,
     puts("");
 
     ret = bdrv_create(drv, filename, param);
-
     if (ret < 0) {
         if (ret == -ENOTSUP) {
-            error_report("Formatting or formatting option not supported for "
-                         "file format '%s'", fmt);
             error_setg(errp,"Formatting or formatting option not supported for "
                             "file format '%s'", fmt);
         } else if (ret == -EFBIG) {
-            error_report("The image size is too large for file format '%s'",
-                         fmt);
             error_setg(errp, "The image size is too large for file format '%s'",
                        fmt);
         } else {
-            error_report("%s: error while creating %s: %s", filename, fmt,
-                         strerror(-ret));
             error_setg(errp, "%s: error while creating %s: %s", filename, fmt,
                        strerror(-ret));
         }
@@ -4572,6 +4544,4 @@ out:
     if (bs) {
         bdrv_delete(bs);
     }
-
-    return ret;
 }
diff --git a/block.h b/block.h
index ff54d15..24bea09 100644
--- a/block.h
+++ b/block.h
@@ -343,9 +343,9 @@ int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
 int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
                       int64_t pos, int size);
 
-int bdrv_img_create(const char *filename, const char *fmt,
-                    const char *base_filename, const char *base_fmt,
-                    char *options, uint64_t img_size, int flags, Error **errp);
+void bdrv_img_create(const char *filename, const char *fmt,
+                     const char *base_filename, const char *base_fmt,
+                     char *options, uint64_t img_size, int flags, Error **errp);
 
 void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors
  2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
                   ` (5 preceding siblings ...)
  2012-11-30 12:52 ` [Qemu-devel] [PATCH 6/6] block: bdrv_img_create(): drop unused error handling code Luiz Capitulino
@ 2012-11-30 13:19 ` Kevin Wolf
  6 siblings, 0 replies; 8+ messages in thread
From: Kevin Wolf @ 2012-11-30 13:19 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: pbonzini, qemu-devel, armbru

Am 30.11.2012 13:52, schrieb Luiz Capitulino:
> By adding error propagation to bdrv_img_create() we improve error reporting
> in QMP and simplify qemu-img.c:img_create() a bit.
> 
> o v3
> 
>  - Update qmp_drive_mirror()
> 
> o Patches changed:
> 
>  - 1/6 (changed)
>  - 5/6 (new patch)
> 
> Luiz Capitulino (6):
>   block: bdrv_img_create(): add Error ** argument
>   qemu-img: img_create(): pass Error object to bdrv_img_create()
>   qemu-img: img_create(): drop unneeded goto and ret variable
>   qmp: qmp_transaction(): pass Error object to bdrv_img_create()
>   qmp: qmp_drive_mirror(): pass Error object to bdrv_img_create()
>   block: bdrv_img_create(): drop unused error handling code
> 
>  block.c    | 60 +++++++++++++++++++++++++-----------------------------------
>  block.h    |  6 +++---
>  blockdev.c | 29 +++++++++++++++--------------
>  qemu-img.c | 19 ++++++++++---------
>  4 files changed, 53 insertions(+), 61 deletions(-)

Thanks, applied all to the block-next branch for 1.4.

Kevin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-11-30 13:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-30 12:52 [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Luiz Capitulino
2012-11-30 12:52 ` [Qemu-devel] [PATCH 1/6] block: bdrv_img_create(): add Error ** argument Luiz Capitulino
2012-11-30 12:52 ` [Qemu-devel] [PATCH 2/6] qemu-img: img_create(): pass Error object to bdrv_img_create() Luiz Capitulino
2012-11-30 12:52 ` [Qemu-devel] [PATCH 3/6] qemu-img: img_create(): drop unneeded goto and ret variable Luiz Capitulino
2012-11-30 12:52 ` [Qemu-devel] [PATCH 4/6] qmp: qmp_transaction(): pass Error object to bdrv_img_create() Luiz Capitulino
2012-11-30 12:52 ` [Qemu-devel] [PATCH 5/6] qmp: qmp_drive_mirror(): " Luiz Capitulino
2012-11-30 12:52 ` [Qemu-devel] [PATCH 6/6] block: bdrv_img_create(): drop unused error handling code Luiz Capitulino
2012-11-30 13:19 ` [Qemu-devel] [PATCH v3 0/6] block: bdrv_img_create(): propagate errors Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).