Skip to contentSkip to conversation

block/quorum: implement .bdrv_co_get_block_status

PATCH In review Liu Yuan 5 participants 7 messages Jul 17, 2014 – Jul 21, 2014 Block layer

lore
Share & tools
lore

Liu Yuan

author
#0 lore raw

PATCH 1/1 block/quorum: implement .bdrv_co_get_block_status

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Cc Benoit Canet <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/quorum.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/quorum.c +16 -0
index ebf5c71..f0d0a98 100644
@@ -780,6 +780,21 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
     return result;
 }
 
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];
+
+    if (child_bs->drv->bdrv_co_get_block_status)
+        return child_bs->drv->bdrv_co_get_block_status(child_bs, sector_num,
+                                                       nb_sectors, pnum);
+
+    return bdrv_get_block_status(child_bs, sector_num, nb_sectors, pnum);
+}
+
 static bool quorum_recurse_is_first_non_filter(BlockDriverState *bs,
                                                BlockDriverState *candidate)
 {
@@ -1038,6 +1053,7 @@ static BlockDriver bdrv_quorum = {
     .bdrv_close                         = quorum_close,
 
     .bdrv_co_flush_to_disk              = quorum_co_flush,
+    .bdrv_co_get_block_status           = quorum_co_get_block_status,
 
     .bdrv_getlength                     = quorum_getlength,
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 16 lines · Liu Yuan

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Cc Benoit Canet <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/quorum.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/quorum.c +0 -0
index ebf5c71..f0d0a98 100644

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 789

Quoted 10 lines
block/quorum.c +7 -0
@@ -780,6 +780,21 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
     return result;
 }
 
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];

Should we consider other children?

Fam

Quoted 8 lines
block/quorum.c +8 -0
+
+    if (child_bs->drv->bdrv_co_get_block_status)
+        return child_bs->drv->bdrv_co_get_block_status(child_bs, sector_num,
+                                                       nb_sectors, pnum);
+
+    return bdrv_get_block_status(child_bs, sector_num, nb_sectors, pnum);
+}
+
author
#2 lore raw
Quoted 20 lines · Fam Zheng
Quoted 19 lines · Liu Yuan

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Cc Benoit Canet <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/quorum.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/quorum.c +0 -0
index ebf5c71..f0d0a98 100644
@@ -780,6 +780,21 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
     return result;
 }
 
Quoted 10 lines

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 789

Quoted 7 lines
block/quorum.c +7 -0
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];

Should we consider other children?

No, other children are identical because we always do multiple sync writes and at boot time we check the length.

Thanks
Yuan

#3 lore raw

Am 18.07.2014 um 07:52 hat Liu Yuan geschrieben:

Quoted 32 lines · Fam Zheng
Quoted 20 lines · Liu Yuan
Quoted 19 lines

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Cc Benoit Canet <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/quorum.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/quorum.c +0 -0
index ebf5c71..f0d0a98 100644
@@ -780,6 +780,21 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
     return result;
 }
 
Quoted 10 lines

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 789

Quoted 7 lines
block/quorum.c +7 -0
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];

Should we consider other children?

Quoted 2 lines

No, other children are identical because we always do multiple sync writes and at boot time we check the length.

But the basic assumption in quorum is that a single child isn't reliable and can fail. Otherwise, you wouldn't have to read from all of them and compare the results.

Kevin

#4 lore raw
In reply to Fam Zheng
Quoted 6 lines · Fam Zheng
Quoted 5 lines · Liu Yuan

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Quoted 9 lines

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 789

Quoted 7 lines
block/quorum.c +7 -0
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];

Should we consider other children?

Yes. Just because the children are written identically from the guest point of view does not mean they start identically mapped, only that they start with identical guest-visible contents. In particular, a quorum is allowed to be composed of disparate children (I could have a quorum between a raw, a qcow2 v0.10, and a qcow2 v1.1 - and those three formats have DIFFERENT notions of whether block_status can report sparse, even for the same guest contents), or even where one child is a chain of images while the other is flat.

For this function, I'm not sure you need a full quorum to declare a block sparse, but you definitely need to consider that the first child might not report sparse while later children do. In other words, you need to come up with some sane pattern that collapses information from all children into a reliable answer for the quorum as a whole (probably okay if any one child declares a sector as sparse to say the quorum is sparse). Likewise, you cannot assume that all the children have the same number of consecutive sectors in the same allocated condition; even though you can still come up with a reliable number for the quorum (probably the minimum of the numbers reported by each child).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
In reply to Liu Yuan

Il 17/07/2014 13:50, Liu Yuan ha scritto:

Quoted 20 lines

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Cc Benoit Canet <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/quorum.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/quorum.c +1 -0
index ebf5c71..f0d0a98 100644
@@ -780,6 +780,21 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
     return result;
 }
 
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 793

Quoted 10 lines
block/quorum.c +10 -0
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];
+
+    if (child_bs->drv->bdrv_co_get_block_status)
+        return child_bs->drv->bdrv_co_get_block_status(child_bs, sector_num,
+                                                       nb_sectors, pnum);

Is this "if" necessary?

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 795

Quoted 1 line
block/quorum.c +1 -0
+    return bdrv_get_block_status(child_bs, sector_num, nb_sectors, pnum);

Also, the definition of BDRV_BLOCK_OFFSET_VALID explicitly refers to bs->file, so you probably have to exclude it from the result as well as BDRV_BLOCK_RAW.

Paolo

Quoted 13 lines
block/quorum.c +2 -0
+
 static bool quorum_recurse_is_first_non_filter(BlockDriverState *bs,
                                                BlockDriverState *candidate)
 {
@@ -1038,6 +1053,7 @@ static BlockDriver bdrv_quorum = {
     .bdrv_close                         = quorum_close,
 
     .bdrv_co_flush_to_disk              = quorum_co_flush,
+    .bdrv_co_get_block_status           = quorum_co_get_block_status,
 
     .bdrv_getlength                     = quorum_getlength,
 
author
#6 lore raw
Quoted 20 lines · Paolo Bonzini

Il 17/07/2014 13:50, Liu Yuan ha scritto:

Quoted 19 lines

- allow drive-mirror to create sprase mirror on images like qcow2
- allow qemu-img map to work as expected on quorum driver

Cc Benoit Canet <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/quorum.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/quorum.c +0 -0
index ebf5c71..f0d0a98 100644
@@ -780,6 +780,21 @@ static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
     return result;
 }
 
Quoted 13 lines

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 793

Quoted 11 lines
block/quorum.c +11 -0
+static int64_t coroutine_fn quorum_co_get_block_status(BlockDriverState *bs,
+                                                       int64_t sector_num,
+                                                       int nb_sectors,
+                                                       int *pnum)
+{
+    BDRVQuorumState *s = bs->opaque;
+    BlockDriverState *child_bs = s->bs[0];
+
+    if (child_bs->drv->bdrv_co_get_block_status)
+        return child_bs->drv->bdrv_co_get_block_status(child_bs, sector_num,
+                                                       nb_sectors, pnum);

Is this "if" necessary?

Yes, otherwise bdrv_get_block_status() will be called multiple times and the result for qcow2 won't return desired value im my test. Or we can simply call bdrv_get_block_status() plus some tricks?

Quoted 7 lines

block/quorum.c static coroutine_fn int quorum_co_flush(BlockDriverState *bs) · line 795

Quoted 2 lines
block/quorum.c +1 -0
+    return bdrv_get_block_status(child_bs, sector_num, nb_sectors, pnum);

Also, the definition of BDRV_BLOCK_OFFSET_VALID explicitly refers to bs->file, so you probably have to exclude it from the result as well as BDRV_BLOCK_RAW.

Thanks for reminding.

Yuan