diff mbox

[2/2] vmdk: fix cluster size check for flat extents

Message ID 1379502855-27759-3-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Sept. 18, 2013, 11:14 a.m. UTC
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

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/vmdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefan Hajnoczi Sept. 19, 2013, 11:31 a.m. UTC | #1
On Wed, Sep 18, 2013 at 07:14:15PM +0800, Fam Zheng wrote:
> 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
Paolo Bonzini Sept. 20, 2013, 3:04 p.m. UTC | #2
Il 19/09/2013 13:31, Stefan Hajnoczi ha scritto:
>> > 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

> The cleaner fix would be to stop passing it as cluster size :).
Fam Zheng Sept. 22, 2013, 12:53 a.m. UTC | #3
On Fri, 09/20 17:04, Paolo Bonzini wrote:
> Il 19/09/2013 13:31, Stefan Hajnoczi ha scritto:
> >> > 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
diff mbox

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index fb5b529..fdd4eaa 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -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;