diff mbox

[1/1] vmdk: Use bdrv_nb_sectors() where sectors, not bytes are wanted

Message ID 1408554429-22341-1-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Aug. 20, 2014, 5:07 p.m. UTC
Instead of bdrv_getlength().

Commit 57322b7 did this all over block, but one more bdrv_getlength()
has crept in since.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Eric Blake Aug. 20, 2014, 6:55 p.m. UTC | #1
On 08/20/2014 11:07 AM, Markus Armbruster wrote:
> Instead of bdrv_getlength().
> 
> Commit 57322b7 did this all over block, but one more bdrv_getlength()
> has crept in since.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block/vmdk.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Fam Zheng Aug. 21, 2014, 1:15 a.m. UTC | #2
On Wed, 08/20 19:07, Markus Armbruster wrote:
> Instead of bdrv_getlength().
> 
> Commit 57322b7 did this all over block, but one more bdrv_getlength()
> has crept in since.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block/vmdk.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 01412a8..3b74e85 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -397,7 +397,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
>  {
>      VmdkExtent *extent;
>      BDRVVmdkState *s = bs->opaque;
> -    int64_t length;
> +    int64_t nb_sectors;
>  
>      if (cluster_sectors > 0x200000) {
>          /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
> @@ -413,9 +413,9 @@ static int vmdk_add_extent(BlockDriverState *bs,
>          return -EFBIG;
>      }
>  
> -    length = bdrv_getlength(file);
> -    if (length < 0) {
> -        return length;
> +    nb_sectors = bdrv_getlength(file);

Should be bdrv_nb_sectors.

Fam

> +    if (nb_sectors < 0) {
> +        return nb_sectors;
>      }
>  
>      s->extents = g_realloc(s->extents,
> @@ -433,8 +433,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
>      extent->l1_entry_sectors = l2_size * cluster_sectors;
>      extent->l2_size = l2_size;
>      extent->cluster_sectors = flat ? sectors : cluster_sectors;
> -    extent->next_cluster_sector =
> -        ROUND_UP(DIV_ROUND_UP(length, BDRV_SECTOR_SIZE), cluster_sectors);
> +    extent->next_cluster_sector = ROUND_UP(nb_sectors, cluster_sectors);
>  
>      if (s->num_extents > 1) {
>          extent->end_sector = (*(extent - 1)).end_sector + extent->sectors;
> -- 
> 1.9.3
> 
>
Markus Armbruster Aug. 21, 2014, 6:43 a.m. UTC | #3
Fam Zheng <famz@redhat.com> writes:

> On Wed, 08/20 19:07, Markus Armbruster wrote:
>> Instead of bdrv_getlength().
>> 
>> Commit 57322b7 did this all over block, but one more bdrv_getlength()
>> has crept in since.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  block/vmdk.c | 11 +++++------
>>  1 file changed, 5 insertions(+), 6 deletions(-)
>> 
>> diff --git a/block/vmdk.c b/block/vmdk.c
>> index 01412a8..3b74e85 100644
>> --- a/block/vmdk.c
>> +++ b/block/vmdk.c
>> @@ -397,7 +397,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
>>  {
>>      VmdkExtent *extent;
>>      BDRVVmdkState *s = bs->opaque;
>> -    int64_t length;
>> +    int64_t nb_sectors;
>>  
>>      if (cluster_sectors > 0x200000) {
>>          /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
>> @@ -413,9 +413,9 @@ static int vmdk_add_extent(BlockDriverState *bs,
>>          return -EFBIG;
>>      }
>>  
>> -    length = bdrv_getlength(file);
>> -    if (length < 0) {
>> -        return length;
>> +    nb_sectors = bdrv_getlength(file);
>
> Should be bdrv_nb_sectors.

Brown paperbag...  I shouldn't do "trivial" patches when tired.

I wish "make check-block" covered a bit more, or there was something
that does while being trivial enough for me to run it unthinkingly.

Thanks!

[...]
Fam Zheng Aug. 21, 2014, 7:09 a.m. UTC | #4
On Thu, 08/21 08:43, Markus Armbruster wrote:
> Fam Zheng <famz@redhat.com> writes:
> 
> > On Wed, 08/20 19:07, Markus Armbruster wrote:
> >> Instead of bdrv_getlength().
> >> 
> >> Commit 57322b7 did this all over block, but one more bdrv_getlength()
> >> has crept in since.
> >> 
> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> >> ---
> >>  block/vmdk.c | 11 +++++------
> >>  1 file changed, 5 insertions(+), 6 deletions(-)
> >> 
> >> diff --git a/block/vmdk.c b/block/vmdk.c
> >> index 01412a8..3b74e85 100644
> >> --- a/block/vmdk.c
> >> +++ b/block/vmdk.c
> >> @@ -397,7 +397,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
> >>  {
> >>      VmdkExtent *extent;
> >>      BDRVVmdkState *s = bs->opaque;
> >> -    int64_t length;
> >> +    int64_t nb_sectors;
> >>  
> >>      if (cluster_sectors > 0x200000) {
> >>          /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
> >> @@ -413,9 +413,9 @@ static int vmdk_add_extent(BlockDriverState *bs,
> >>          return -EFBIG;
> >>      }
> >>  
> >> -    length = bdrv_getlength(file);
> >> -    if (length < 0) {
> >> -        return length;
> >> +    nb_sectors = bdrv_getlength(file);
> >
> > Should be bdrv_nb_sectors.
> 
> Brown paperbag...  I shouldn't do "trivial" patches when tired.
> 
> I wish "make check-block" covered a bit more, or there was something
> that does while being trivial enough for me to run it unthinkingly.
> 

The test case here would be "write a little more data to the image, assert that
the file size (EOF offset) doesn't explode". :)

Fam
Kevin Wolf Aug. 21, 2014, 8:35 a.m. UTC | #5
Am 21.08.2014 um 08:43 hat Markus Armbruster geschrieben:
> Fam Zheng <famz@redhat.com> writes:
> 
> > On Wed, 08/20 19:07, Markus Armbruster wrote:
> >> Instead of bdrv_getlength().
> >> 
> >> Commit 57322b7 did this all over block, but one more bdrv_getlength()
> >> has crept in since.
> >> 
> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> >> ---
> >>  block/vmdk.c | 11 +++++------
> >>  1 file changed, 5 insertions(+), 6 deletions(-)
> >> 
> >> diff --git a/block/vmdk.c b/block/vmdk.c
> >> index 01412a8..3b74e85 100644
> >> --- a/block/vmdk.c
> >> +++ b/block/vmdk.c
> >> @@ -397,7 +397,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
> >>  {
> >>      VmdkExtent *extent;
> >>      BDRVVmdkState *s = bs->opaque;
> >> -    int64_t length;
> >> +    int64_t nb_sectors;
> >>  
> >>      if (cluster_sectors > 0x200000) {
> >>          /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
> >> @@ -413,9 +413,9 @@ static int vmdk_add_extent(BlockDriverState *bs,
> >>          return -EFBIG;
> >>      }
> >>  
> >> -    length = bdrv_getlength(file);
> >> -    if (length < 0) {
> >> -        return length;
> >> +    nb_sectors = bdrv_getlength(file);
> >
> > Should be bdrv_nb_sectors.
> 
> Brown paperbag...  I shouldn't do "trivial" patches when tired.

The worst part is that it got a Reviewed-by which might just have fooled
me if Fam hadn't reviewed it as well. :-/

> I wish "make check-block" covered a bit more, or there was something
> that does while being trivial enough for me to run it unthinkingly.

Well, you know what you have to do for v2, right? qemu-iotests is
in-tree for a reason.

Kevin
Markus Armbruster Aug. 21, 2014, 12:22 p.m. UTC | #6
Kevin Wolf <kwolf@redhat.com> writes:

> Am 21.08.2014 um 08:43 hat Markus Armbruster geschrieben:
>> Fam Zheng <famz@redhat.com> writes:
>> 
>> > On Wed, 08/20 19:07, Markus Armbruster wrote:
>> >> Instead of bdrv_getlength().
>> >> 
>> >> Commit 57322b7 did this all over block, but one more bdrv_getlength()
>> >> has crept in since.
>> >> 
>> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> >> ---
>> >>  block/vmdk.c | 11 +++++------
>> >>  1 file changed, 5 insertions(+), 6 deletions(-)
>> >> 
>> >> diff --git a/block/vmdk.c b/block/vmdk.c
>> >> index 01412a8..3b74e85 100644
>> >> --- a/block/vmdk.c
>> >> +++ b/block/vmdk.c
>> >> @@ -397,7 +397,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
>> >>  {
>> >>      VmdkExtent *extent;
>> >>      BDRVVmdkState *s = bs->opaque;
>> >> -    int64_t length;
>> >> +    int64_t nb_sectors;
>> >>  
>> >>      if (cluster_sectors > 0x200000) {
>> >>          /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
>> >> @@ -413,9 +413,9 @@ static int vmdk_add_extent(BlockDriverState *bs,
>> >>          return -EFBIG;
>> >>      }
>> >>  
>> >> -    length = bdrv_getlength(file);
>> >> -    if (length < 0) {
>> >> -        return length;
>> >> +    nb_sectors = bdrv_getlength(file);
>> >
>> > Should be bdrv_nb_sectors.
>> 
>> Brown paperbag...  I shouldn't do "trivial" patches when tired.
>
> The worst part is that it got a Reviewed-by which might just have fooled
> me if Fam hadn't reviewed it as well. :-/

This kind of idiotic error is hard to spot in review for the same reason
it's easy to make when tired.

>> I wish "make check-block" covered a bit more, or there was something
>> that does while being trivial enough for me to run it unthinkingly.
>
> Well, you know what you have to do for v2, right? qemu-iotests is
> in-tree for a reason.

All right, "./check -T -vmdk -g quick" would've caught this.

I tried it with -nocache first, because that's how tests/check-block.sh
runs it, but that fails due to a bug we traced back to raw-posix in
#qemu.  Stefan is taking care of it.

Looks like check-block.sh hasn't been used much lately.  I didn't know
it existed until it showed up in a grep.

I'll respin this patch.  I'll discuss improving "make check-block" in a
new thread.
Eric Blake Aug. 21, 2014, 12:33 p.m. UTC | #7
On 08/21/2014 06:22 AM, Markus Armbruster wrote:
> Kevin Wolf <kwolf@redhat.com> writes:
> 

>> The worst part is that it got a Reviewed-by which might just have fooled
>> me if Fam hadn't reviewed it as well. :-/
> 
> This kind of idiotic error is hard to spot in review for the same reason
> it's easy to make when tired.

Indeed; I had merely reviewed that the patch looked sane, and not
actually tested against a testsuite, so I'm glad Fam caught it.  There's
a reason I've been sticking with Reviewed-by and not Tested-by, although
I agree that enhancing the testsuite to make sure dumb things like this
get caught is worthwhile.
diff mbox

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 01412a8..3b74e85 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -397,7 +397,7 @@  static int vmdk_add_extent(BlockDriverState *bs,
 {
     VmdkExtent *extent;
     BDRVVmdkState *s = bs->opaque;
-    int64_t length;
+    int64_t nb_sectors;
 
     if (cluster_sectors > 0x200000) {
         /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
@@ -413,9 +413,9 @@  static int vmdk_add_extent(BlockDriverState *bs,
         return -EFBIG;
     }
 
-    length = bdrv_getlength(file);
-    if (length < 0) {
-        return length;
+    nb_sectors = bdrv_getlength(file);
+    if (nb_sectors < 0) {
+        return nb_sectors;
     }
 
     s->extents = g_realloc(s->extents,
@@ -433,8 +433,7 @@  static int vmdk_add_extent(BlockDriverState *bs,
     extent->l1_entry_sectors = l2_size * cluster_sectors;
     extent->l2_size = l2_size;
     extent->cluster_sectors = flat ? sectors : cluster_sectors;
-    extent->next_cluster_sector =
-        ROUND_UP(DIV_ROUND_UP(length, BDRV_SECTOR_SIZE), cluster_sectors);
+    extent->next_cluster_sector = ROUND_UP(nb_sectors, cluster_sectors);
 
     if (s->num_extents > 1) {
         extent->end_sector = (*(extent - 1)).end_sector + extent->sectors;