diff mbox

[2/4] block: Improve error report for wrong format

Message ID 1355580573-19323-3-git-send-email-sw@weilnetz.de
State Superseded
Headers show

Commit Message

Stefan Weil Dec. 15, 2012, 2:09 p.m. UTC
There is no good system error for this kind of error,
so it needs special handling instead of strerror.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 blockdev.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Luiz Capitulino Dec. 17, 2012, 3:08 p.m. UTC | #1
On Sat, 15 Dec 2012 15:09:31 +0100
Stefan Weil <sw@weilnetz.de> wrote:

> There is no good system error for this kind of error,
> so it needs special handling instead of strerror.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  blockdev.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/blockdev.c b/blockdev.c
> index 5a4cd56..3da44f6 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -624,8 +624,13 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
>  
>      ret = bdrv_open(dinfo->bdrv, file, bdrv_flags, drv);
>      if (ret < 0) {
> -        error_report("could not open disk image %s: %s",
> -                     file, strerror(-ret));
> +        if (ret == BDRV_WRONG_FORMAT) {
> +            error_report("could not open disk image %s: not in %s format",
> +                         file, drv->format_name);
> +        } else {
> +            error_report("could not open disk image %s: %s",
> +                         file, strerror(-ret));

IIRC, I have an rfc series propagating an Error object down to bdrv_open(),
and was planning to propagate it to block drivers. You could do it instead
of creating this new error code.

It's usually more work, but the end result is usually better.

> +        }
>          goto err;
>      }
>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 5a4cd56..3da44f6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -624,8 +624,13 @@  DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
 
     ret = bdrv_open(dinfo->bdrv, file, bdrv_flags, drv);
     if (ret < 0) {
-        error_report("could not open disk image %s: %s",
-                     file, strerror(-ret));
+        if (ret == BDRV_WRONG_FORMAT) {
+            error_report("could not open disk image %s: not in %s format",
+                         file, drv->format_name);
+        } else {
+            error_report("could not open disk image %s: %s",
+                         file, strerror(-ret));
+        }
         goto err;
     }