diff mbox

[v4,11/14] vmdk: Return extent's file in bdrv_get_block_status

Message ID 1450936225-4249-12-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Dec. 24, 2015, 5:50 a.m. UTC
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/vmdk.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Max Reitz Jan. 4, 2016, 8:48 p.m. UTC | #1
On 24.12.2015 06:50, Fam Zheng wrote:
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/vmdk.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index f5a56fd..b60a5af 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -1265,6 +1265,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
>                               0, 0);
>      qemu_co_mutex_unlock(&s->lock);
>  
> +    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
>      switch (ret) {
>      case VMDK_ERROR:
>          ret = -EIO;
> @@ -1276,15 +1277,13 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
>          ret = BDRV_BLOCK_ZERO;
>          break;
>      case VMDK_OK:
> -        ret = BDRV_BLOCK_DATA;
> -        if (extent->file == bs->file && !extent->compressed) {
> -            ret |= BDRV_BLOCK_OFFSET_VALID | offset;
> -        }
> -
> +        ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID;
> +        ret |= (offset + (index_in_cluster << BDRV_SECTOR_BITS))
> +                & BDRV_BLOCK_OFFSET_MASK;
> +        *file = extent->file->bs;

What if the extent is compressed?

Max

>          break;
>      }
>  
> -    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
>      n = extent->cluster_sectors - index_in_cluster;
>      if (n > nb_sectors) {
>          n = nb_sectors;
>
Fam Zheng Jan. 5, 2016, 4:23 a.m. UTC | #2
On Mon, 01/04 21:48, Max Reitz wrote:
> On 24.12.2015 06:50, Fam Zheng wrote:
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  block/vmdk.c | 11 +++++------
> >  1 file changed, 5 insertions(+), 6 deletions(-)
> > 
> > diff --git a/block/vmdk.c b/block/vmdk.c
> > index f5a56fd..b60a5af 100644
> > --- a/block/vmdk.c
> > +++ b/block/vmdk.c
> > @@ -1265,6 +1265,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
> >                               0, 0);
> >      qemu_co_mutex_unlock(&s->lock);
> >  
> > +    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
> >      switch (ret) {
> >      case VMDK_ERROR:
> >          ret = -EIO;
> > @@ -1276,15 +1277,13 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
> >          ret = BDRV_BLOCK_ZERO;
> >          break;
> >      case VMDK_OK:
> > -        ret = BDRV_BLOCK_DATA;
> > -        if (extent->file == bs->file && !extent->compressed) {
> > -            ret |= BDRV_BLOCK_OFFSET_VALID | offset;
> > -        }
> > -
> > +        ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID;
> > +        ret |= (offset + (index_in_cluster << BDRV_SECTOR_BITS))
> > +                & BDRV_BLOCK_OFFSET_MASK;
> > +        *file = extent->file->bs;
> 
> What if the extent is compressed?
> 

You're right, the offset shouldn't be set if compressed. Will fix.

Thanks!

Fam
diff mbox

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index f5a56fd..b60a5af 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1265,6 +1265,7 @@  static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
                              0, 0);
     qemu_co_mutex_unlock(&s->lock);
 
+    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
     switch (ret) {
     case VMDK_ERROR:
         ret = -EIO;
@@ -1276,15 +1277,13 @@  static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs,
         ret = BDRV_BLOCK_ZERO;
         break;
     case VMDK_OK:
-        ret = BDRV_BLOCK_DATA;
-        if (extent->file == bs->file && !extent->compressed) {
-            ret |= BDRV_BLOCK_OFFSET_VALID | offset;
-        }
-
+        ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID;
+        ret |= (offset + (index_in_cluster << BDRV_SECTOR_BITS))
+                & BDRV_BLOCK_OFFSET_MASK;
+        *file = extent->file->bs;
         break;
     }
 
-    index_in_cluster = vmdk_find_index_in_cluster(extent, sector_num);
     n = extent->cluster_sectors - index_in_cluster;
     if (n > nb_sectors) {
         n = nb_sectors;