Patchwork [1/3] qemu-nbd: Fix return value handling of bdrv_open

login
register
mail settings
Submitter Ryota OZAKI
Date March 20, 2010, 6:23 a.m.
Message ID <1269066204-4376-1-git-send-email-ozaki.ryota@gmail.com>
Download mbox | patch
Permalink /patch/48200/
State New
Headers show

Comments

Ryota OZAKI - March 20, 2010, 6:23 a.m.
bdrv_open may return -errno so we have to check
if the return value is '< 0', not '== -1'.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
---
 qemu-nbd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Markus Armbruster - March 20, 2010, 7:01 a.m.
Ryota Ozaki <ozaki.ryota@gmail.com> writes:

> bdrv_open may return -errno so we have to check
> if the return value is '< 0', not '== -1'.
>
> Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
> ---
>  qemu-nbd.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index a393583..b89c361 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -333,7 +333,7 @@ int main(int argc, char **argv)
>      if (bs == NULL)
>          return 1;
>  
> -    if (bdrv_open(bs, argv[optind], flags) == -1)
> +    if (bdrv_open(bs, argv[optind], flags) < 0)
>          return 1;
>  
>      fd_size = bs->total_sectors * 512;

Same bug in qemu-io.c.  Could you fix that as well?
Ryota OZAKI - March 20, 2010, 7:05 a.m.
On Sat, Mar 20, 2010 at 4:01 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Ryota Ozaki <ozaki.ryota@gmail.com> writes:
>
>> bdrv_open may return -errno so we have to check
>> if the return value is '< 0', not '== -1'.
>>
>> Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
>> ---
>>  qemu-nbd.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/qemu-nbd.c b/qemu-nbd.c
>> index a393583..b89c361 100644
>> --- a/qemu-nbd.c
>> +++ b/qemu-nbd.c
>> @@ -333,7 +333,7 @@ int main(int argc, char **argv)
>>      if (bs == NULL)
>>          return 1;
>>
>> -    if (bdrv_open(bs, argv[optind], flags) == -1)
>> +    if (bdrv_open(bs, argv[optind], flags) < 0)
>>          return 1;
>>
>>      fd_size = bs->total_sectors * 512;
>
> Same bug in qemu-io.c.  Could you fix that as well?
>

OK. I will.

Thanks,
  ozaki-r
Aurelien Jarno - March 27, 2010, 1:03 p.m.
On Sat, Mar 20, 2010 at 03:23:22PM +0900, Ryota Ozaki wrote:
> bdrv_open may return -errno so we have to check
> if the return value is '< 0', not '== -1'.

Thanks, applied.

> Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
> ---
>  qemu-nbd.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index a393583..b89c361 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -333,7 +333,7 @@ int main(int argc, char **argv)
>      if (bs == NULL)
>          return 1;
>  
> -    if (bdrv_open(bs, argv[optind], flags) == -1)
> +    if (bdrv_open(bs, argv[optind], flags) < 0)
>          return 1;
>  
>      fd_size = bs->total_sectors * 512;
> -- 
> 1.6.5.2
> 
> 
> 
>

Patch

diff --git a/qemu-nbd.c b/qemu-nbd.c
index a393583..b89c361 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -333,7 +333,7 @@  int main(int argc, char **argv)
     if (bs == NULL)
         return 1;
 
-    if (bdrv_open(bs, argv[optind], flags) == -1)
+    if (bdrv_open(bs, argv[optind], flags) < 0)
         return 1;
 
     fd_size = bs->total_sectors * 512;