Skip to contentSkip to conversation

block: two fixes for image opening

PATCH Applied Fam Zheng 3 participants 8 messages Sep 18, 2013 – Sep 22, 2013 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover block: two fixes for image opening

This fixes two bugs of image opening. The vmdk fix also applies to 1.6.

Fam Zheng (2):
block: don't lose data from last incomplete sector
vmdk: fix cluster size check for flat extents

 block.c      | 2 +-
 block/vmdk.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 block: don't lose data from last incomplete sector

To read the last sector that is not aligned to sector boundary, current code for growable backends, since commit 893a8f6 "block: Produce zeros when protocols reading beyond end of file", drops the data and directly returns zeroes. That is incorrect.

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index a325efc..9b28ef9 100644
@@ -2613,7 +2613,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
             goto out;
         }
 
-        total_sectors = len >> BDRV_SECTOR_BITS;
+        total_sectors = (len + BDRV_SECTOR_SIZE - 1) >> BDRV_SECTOR_BITS;
         max_nb_sectors = MAX(0, total_sectors - sector_num);
         if (max_nb_sectors > 0) {
             ret = drv->bdrv_co_readv(bs, sector_num,
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: don't lose data from last incomplete sector

Quoted 9 lines · Fam Zheng

To read the last sector that is not aligned to sector boundary, current code for growable backends, since commit 893a8f6 "block: Produce zeros when protocols reading beyond end of file", drops the data and directly returns zeroes. That is incorrect.

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I merged this patch because I hit the problem myself today. And my code includes a test case which will be posted soon.

So don't worry about writing a test case for this patch. I still don't fully understand the vmdk patch and would like a test case for it.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

author
#3 lore raw

PATCH 2/2 vmdk: fix cluster size check for flat extents

In reply to Fam Zheng

We use the extent size as cluster size for flat extents (where no L1/L2 table is allocated so it's safe).

So don't check the cluster size for flat case in opening.

Otherwise flat extent opening is broken:

    # qemu-img create -f vmdk -o subformat=monolithicFlat /tmp/a.vmdk 100G
    Formatting '/tmp/a.vmdk', fmt=vmdk size=107374182400 compat6=off subformat='monolithicFlat' zeroed_grain=off
    # qemu-img info /tmp/a.vmdk
    image: /tmp/a.vmdk
    file format: raw
    virtual size: 0 (0 bytes)
    disk size: 4.0K
---
 block/vmdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/vmdk.c +1 -1
index fb5b529..fdd4eaa 100644
@@ -396,7 +396,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
     VmdkExtent *extent;
     BDRVVmdkState *s = bs->opaque;
 
-    if (cluster_sectors > 0x200000) {
+    if (!flat && cluster_sectors > 0x200000) {
         /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
         error_report("invalid granularity, image may be corrupt");
         return -EINVAL;
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] vmdk: fix cluster size check for flat extents

Quoted 2 lines · Fam Zheng

We use the extent size as cluster size for flat extents (where no L1/L2 table is allocated so it's safe).

Why is the extent size passed as the cluster size parameter?

The cleaner fix would be to stop passing it as cluster size :).

Stefan

#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] vmdk: fix cluster size check for flat extents

Il 19/09/2013 13:31, Stefan Hajnoczi ha scritto:

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

We use the extent size as cluster size for flat extents (where no L1/L2 table is allocated so it's safe).

Why is the extent size passed as the cluster size parameter?

I think it's so that the flat extent doesn't take up too many cache entries.

Paolo

Quoted 1 line

The cleaner fix would be to stop passing it as cluster size :).

author
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] vmdk: fix cluster size check for flat extents

Quoted 8 lines · Paolo Bonzini

Il 19/09/2013 13:31, Stefan Hajnoczi ha scritto:

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

We use the extent size as cluster size for flat extents (where no L1/L2 table is allocated so it's safe).

Why is the extent size passed as the cluster size parameter?

I think it's so that the flat extent doesn't take up too many cache entries.

Paolo

Flat extent doesn't take cache entry at all. It's passed as this because so that more the code path for finding data offset can be the same with sparse:
flat is a special case of sparse with only 1 cluster. Otherwize flat needs to be treated specially.

Another fix would be pass zero to cluster size parameter but initialize it to extent size after parameter checking. But not quite different.

Fam

#7 lore raw
In reply to Fam Zheng
Quoted 9 lines · Fam Zheng

This fixes two bugs of image opening. The vmdk fix also applies to 1.6.

Fam Zheng (2):
block: don't lose data from last incomplete sector
vmdk: fix cluster size check for flat extents

 block.c      | 2 +-
 block/vmdk.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Please add qemu-iotests cases for these bugs. This way we get regression tests that ensure the same bug will not be reintroduced in the future.

Stefan