diff mbox

[10/10] block: print errno on error

Message ID 92764ba73c7a75e8747b7a5a58a4a1ccb3d51489.1267617582.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela March 3, 2010, 12:07 p.m. UTC
Now that we changed all create calls to return errno, just print it.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 qemu-img.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Comments

Kevin Wolf March 3, 2010, 2:01 p.m. UTC | #1
Am 03.03.2010 13:07, schrieb Juan Quintela:
> Now that we changed all create calls to return errno, just print it.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  qemu-img.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 0c9f2d4..f6c40fb 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -374,7 +374,7 @@ static int img_create(int argc, char **argv)
>          } else if (ret == -EFBIG) {
>              error("The image size is too large for file format '%s'", fmt);
>          } else {
> -            error("Error while formatting");
> +            error("Error (%s) while formatting for file format '%s'", strerror(ret), fmt);
>          }
>      }
>      return 0;
> @@ -687,7 +687,7 @@ static int img_convert(int argc, char **argv)
>          } else if (ret == -EFBIG) {
>              error("The image size is too large for file format '%s'", out_fmt);
>          } else {
> -            error("Error while formatting '%s'", out_filename);
> +            error("Error (%s) while formatting file '%s'", strerror(ret), out_filename);
>          }
>      }
> 

I think it should be strerror(-ret) in both cases.

Kevin
Paolo Bonzini March 3, 2010, 2:36 p.m. UTC | #2
>> diff --git a/qemu-img.c b/qemu-img.c
>> index 0c9f2d4..f6c40fb 100644
>> --- a/qemu-img.c
>> +++ b/qemu-img.c
>> @@ -374,7 +374,7 @@ static int img_create(int argc, char **argv)
>>           } else if (ret == -EFBIG) {
>>               error("The image size is too large for file format '%s'", fmt);
>>           } else {
>> -            error("Error while formatting");
>> +            error("Error (%s) while formatting for file format '%s'", strerror(ret), fmt);
>>           }
>>       }
>>       return 0;
>> @@ -687,7 +687,7 @@ static int img_convert(int argc, char **argv)
>>           } else if (ret == -EFBIG) {
>>               error("The image size is too large for file format '%s'", out_fmt);
>>           } else {
>> -            error("Error while formatting '%s'", out_filename);
>> +            error("Error (%s) while formatting file '%s'", strerror(ret), out_filename);
>>           }
>>       }
>>
>
> I think it should be strerror(-ret) in both cases.

Yes; also, since you are at it, I think that respectively

error("%s: error while creating %s image: %s", filename, fmt,
       strerror(-ret);

error(%s: error while converting to %s: %s", out_filename, fmt,
       strerror(-ret);

would be more consistent with usual error messages:

$ cat fdsfds
cat: fdsfds: No such file or directory

Paolo
Juan Quintela March 3, 2010, 4:21 p.m. UTC | #3
Paolo Bonzini <pbonzini@redhat.com> wrote:
>>> diff --git a/qemu-img.c b/qemu-img.c
>>> index 0c9f2d4..f6c40fb 100644
>>> --- a/qemu-img.c
>>> +++ b/qemu-img.c
>>> @@ -374,7 +374,7 @@ static int img_create(int argc, char **argv)
>>>           } else if (ret == -EFBIG) {
>>>               error("The image size is too large for file format '%s'", fmt);
>>>           } else {
>>> -            error("Error while formatting");
>>> +            error("Error (%s) while formatting for file format '%s'", strerror(ret), fmt);
>>>           }
>>>       }
>>>       return 0;
>>> @@ -687,7 +687,7 @@ static int img_convert(int argc, char **argv)
>>>           } else if (ret == -EFBIG) {
>>>               error("The image size is too large for file format '%s'", out_fmt);
>>>           } else {
>>> -            error("Error while formatting '%s'", out_filename);
>>> +            error("Error (%s) while formatting file '%s'", strerror(ret), out_filename);
>>>           }
>>>       }
>>>
>>
>> I think it should be strerror(-ret) in both cases.

oops, yes.

> Yes; also, since you are at it, I think that respectively
>
> error("%s: error while creating %s image: %s", filename, fmt,
>       strerror(-ret);
>
> error(%s: error while converting to %s: %s", out_filename, fmt,
>       strerror(-ret);
>
> would be more consistent with usual error messages:
>
> $ cat fdsfds
> cat: fdsfds: No such file or directory

I agree.  I just didn't want to change it too much.

> Paolo
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 0c9f2d4..f6c40fb 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -374,7 +374,7 @@  static int img_create(int argc, char **argv)
         } else if (ret == -EFBIG) {
             error("The image size is too large for file format '%s'", fmt);
         } else {
-            error("Error while formatting");
+            error("Error (%s) while formatting for file format '%s'", strerror(ret), fmt);
         }
     }
     return 0;
@@ -687,7 +687,7 @@  static int img_convert(int argc, char **argv)
         } else if (ret == -EFBIG) {
             error("The image size is too large for file format '%s'", out_fmt);
         } else {
-            error("Error while formatting '%s'", out_filename);
+            error("Error (%s) while formatting file '%s'", strerror(ret), out_filename);
         }
     }