Skip to contentSkip to conversation

vmdk: Use bdrv_nb_sectors() where sectors, not bytes are wanted

PATCH Superseded Markus Armbruster 4 participants 8 messages Aug 20, 2014 – Aug 21, 2014 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +5 -6
index 01412a8..3b74e85 100644
@@ -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;
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Markus Armbruster

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Markus Armbruster
Quoted 24 lines · Markus Armbruster

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +1 -1
index 01412a8..3b74e85 100644
@@ -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 */

block/vmdk.c static int vmdk_add_extent(BlockDriverState *bs, · line 416

Quoted 7 lines
block/vmdk.c +1 -3
@@ -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

Quoted 19 lines
block/vmdk.c +3 -2
+    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;
Signature · 1 line
1.9.3
#3 lore raw
Quoted 28 lines · Fam Zheng
Quoted 27 lines · Markus Armbruster

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +1 -1
index 01412a8..3b74e85 100644
@@ -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;
     }
 
Quoted 6 lines

block/vmdk.c static int vmdk_add_extent(BlockDriverState *bs, · line 416

Quoted 4 lines
block/vmdk.c +1 -3
-    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!

[...]

#4 lore raw
Quoted 37 lines · Markus Armbruster
Quoted 28 lines · Fam Zheng
Quoted 27 lines · Markus Armbruster

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +1 -1
index 01412a8..3b74e85 100644
@@ -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;
     }
 
Quoted 6 lines

block/vmdk.c static int vmdk_add_extent(BlockDriverState *bs, · line 416

Quoted 4 lines
block/vmdk.c +1 -3
-    length = bdrv_getlength(file);
-    if (length < 0) {
-        return length;
+    nb_sectors = bdrv_getlength(file);

Should be bdrv_nb_sectors.

Quoted 5 lines

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

#5 lore raw
In reply to Markus Armbruster

Am 21.08.2014 um 08:43 hat Markus Armbruster geschrieben:

Quoted 30 lines
Quoted 28 lines · Fam Zheng
Quoted 27 lines · Markus Armbruster

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +1 -1
index 01412a8..3b74e85 100644
@@ -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;
     }
 
Quoted 8 lines
Quoted 6 lines

block/vmdk.c static int vmdk_add_extent(BlockDriverState *bs, · line 416

Quoted 4 lines
block/vmdk.c +1 -3
-    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. :-/

Quoted 2 lines

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

#6 lore raw
Quoted 38 lines · Kevin Wolf

Am 21.08.2014 um 08:43 hat Markus Armbruster geschrieben:

Quoted 37 lines
Quoted 34 lines · Fam Zheng
Quoted 24 lines · Markus Armbruster

Instead of bdrv_getlength().

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

---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +1 -1
index 01412a8..3b74e85 100644
@@ -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 */

block/vmdk.c static int vmdk_add_extent(BlockDriverState *bs, · line 416

Quoted 7 lines
block/vmdk.c +1 -3
@@ -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.

Quoted 4 lines
Quoted 1 line

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.

Quoted 5 lines
Quoted 2 lines

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.

#7 lore raw
Quoted 8 lines · Markus Armbruster
Quoted 2 lines · Kevin Wolf

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.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org