Skip to contentSkip to conversation

block: More complete inactivate/invalidate of on graph

PATCH Superseded Fam Zheng 3 participants 13 messages Apr 19, 2016 – May 11, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover block: More complete inactivate/invalidate of on graph

If qcow2 is a quorum child, we currently don't properly invalidate or inactivate it during migration. Recurse into the whole subtree (subgraph) in both bdrv_invalidate_cache and bdrv_inactivate.

Fam Zheng (2):
block: Invalidate all children
block: Inactivate all children

 block.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
Signature · 1 line
2.8.0
author
#1 lore raw

PATCH 1/2 block: Invalidate all children

Currently we only recurse to bs->file, which will miss the children in quorum and VMDK.

Recurse into the whole subtree to avoid that.

---
 block.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
block.c +14 -6
index d4939b4..fa8b38f 100644
@@ -3201,6 +3201,7 @@ void bdrv_init_with_whitelist(void)
 
 void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 {
+    BdrvChild *child;
     Error *local_err = NULL;
     int ret;
 
@@ -3215,13 +3216,20 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 
     if (bs->drv->bdrv_invalidate_cache) {
         bs->drv->bdrv_invalidate_cache(bs, &local_err);
-    } else if (bs->file) {
-        bdrv_invalidate_cache(bs->file->bs, &local_err);
+        if (local_err) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_propagate(errp, local_err);
+            return;
+        }
     }
-    if (local_err) {
-        bs->open_flags |= BDRV_O_INACTIVE;
-        error_propagate(errp, local_err);
-        return;
+
+    QLIST_FOREACH(child, &bs->children, next) {
+        bdrv_invalidate_cache(child->bs, &local_err);
+        if (local_err) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_propagate(errp, local_err);
+            return;
+        }
     }
 
     ret = refresh_total_sectors(bs, bs->total_sectors);
Signature · 1 line
2.8.0
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: Invalidate all children

Quoted 23 lines · Fam Zheng

Currently we only recurse to bs->file, which will miss the children in quorum and VMDK.

Recurse into the whole subtree to avoid that.

---
  block.c | 20 ++++++++++++++------
  1 file changed, 14 insertions(+), 6 deletions(-)
block.c +1 -0
index d4939b4..fa8b38f 100644
@@ -3201,6 +3201,7 @@ void bdrv_init_with_whitelist(void)
 
  void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
  {
+    BdrvChild *child;
      Error *local_err = NULL;
      int ret;
 

block.c void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) · line 3218

Quoted 3 lines
block.c +0 -0
@@ -3215,13 +3216,20 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 
      if (bs->drv->bdrv_invalidate_cache) {
          bs->drv->bdrv_invalidate_cache(bs, &local_err);

Kevin's commit 3456a8d1 introduced unexpected two spaces in this function, would you like remove it?

- if (bs->drv && bs->drv->bdrv_invalidate_cache) {
+ if (!bs->drv) {
+ return;
+ }

Quoted 9 lines
block.c +5 -3
-    } else if (bs->file) {
-        bdrv_invalidate_cache(bs->file->bs, &local_err);
+        if (local_err) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_propagate(errp, local_err);
+            return;
+        }
      }
-    if (local_err) {

block.c void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) · line 3231

Quoted 10 lines
block.c +7 -3
-        bs->open_flags |= BDRV_O_INACTIVE;
-        error_propagate(errp, local_err);
-        return;
+
+    QLIST_FOREACH(child, &bs->children, next) {
+        bdrv_invalidate_cache(child->bs, &local_err);
+        if (local_err) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_propagate(errp, local_err);
+            return;

If we really need return here? I just mean for example, Quorum A has 3 children(children.0, children.1, children.2), if we invalidate children.1 failed, then we are not going to invalidate children.2

Quoted 5 lines
block.c +1 -0
+        }
      }
 
      ret = refresh_total_sectors(bs, bs->total_sectors);
author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: Invalidate all children

Quoted 23 lines · Changlong Xie
Quoted 22 lines · Fam Zheng

Currently we only recurse to bs->file, which will miss the children in quorum and VMDK.

Recurse into the whole subtree to avoid that.

---
 block.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
block.c +1 -0
index d4939b4..fa8b38f 100644
@@ -3201,6 +3201,7 @@ void bdrv_init_with_whitelist(void)
 
 void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 {
+    BdrvChild *child;
     Error *local_err = NULL;
     int ret;
 
Quoted 7 lines

block.c void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) · line 3218

Quoted 4 lines
block.c +0 -0
@@ -3215,13 +3216,20 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 
     if (bs->drv->bdrv_invalidate_cache) {
         bs->drv->bdrv_invalidate_cache(bs, &local_err);

Kevin's commit 3456a8d1 introduced unexpected two spaces in this function, would you like remove it?

No, that's what to do in this patch. I'd just leave it.

Quoted 26 lines
block.c +3 -1
-    if (bs->drv && bs->drv->bdrv_invalidate_cache) {
+    if (!bs->drv)  {
+        return;
+    }
Quoted 10 lines
block.c +5 -3
-    } else if (bs->file) {
-        bdrv_invalidate_cache(bs->file->bs, &local_err);
+        if (local_err) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_propagate(errp, local_err);
+            return;
+        }
     }
-    if (local_err) {

block.c void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) · line 3231

Quoted 10 lines
block.c +7 -3
-        bs->open_flags |= BDRV_O_INACTIVE;
-        error_propagate(errp, local_err);
-        return;
+
+    QLIST_FOREACH(child, &bs->children, next) {
+        bdrv_invalidate_cache(child->bs, &local_err);
+        if (local_err) {
+            bs->open_flags |= BDRV_O_INACTIVE;
+            error_propagate(errp, local_err);
+            return;
Quoted 3 lines

If we really need return here? I just mean for example, Quorum A has 3 children(children.0, children.1, children.2), if we invalidate children.1 failed, then we are not going to invalidate children.2

We report error anyway and the caller will abort the operation, it's not very useful to continue.

Fam

Quoted 9 lines
Quoted 6 lines
block.c +1 -0
+        }
     }
 
     ret = refresh_total_sectors(bs, bs->total_sectors);
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: Invalidate all children

In reply to Fam Zheng

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 23 lines

Currently we only recurse to bs->file, which will miss the children in quorum and VMDK.

Recurse into the whole subtree to avoid that.

---
 block.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
block.c +1 -0
index d4939b4..fa8b38f 100644
@@ -3201,6 +3201,7 @@ void bdrv_init_with_whitelist(void)
 
 void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 {
+    BdrvChild *child;
     Error *local_err = NULL;
     int ret;
 

block.c void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) · line 3219

Quoted 5 lines
block.c +0 -2
@@ -3215,13 +3216,20 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 
     if (bs->drv->bdrv_invalidate_cache) {
         bs->drv->bdrv_invalidate_cache(bs, &local_err);
-    } else if (bs->file) {
-        bdrv_invalidate_cache(bs->file->bs, &local_err);

The old behaviour was that we only recurse for bs->file if the block driver doesn't have its own implementation.

This means that in qcow2, for example, we call bdrv_invalidate_cache() explicitly for bs->file. If we can already invalidate it here, the call inside qcow2 and probably other drivers could go away.

Kevin

author
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] block: Invalidate all children

Quoted 33 lines · Kevin Wolf

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 23 lines

Currently we only recurse to bs->file, which will miss the children in quorum and VMDK.

Recurse into the whole subtree to avoid that.

---
 block.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
block.c +1 -0
index d4939b4..fa8b38f 100644
@@ -3201,6 +3201,7 @@ void bdrv_init_with_whitelist(void)
 
 void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 {
+    BdrvChild *child;
     Error *local_err = NULL;
     int ret;
 

block.c void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) · line 3219

Quoted 5 lines
block.c +0 -2
@@ -3215,13 +3216,20 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 
     if (bs->drv->bdrv_invalidate_cache) {
         bs->drv->bdrv_invalidate_cache(bs, &local_err);
-    } else if (bs->file) {
-        bdrv_invalidate_cache(bs->file->bs, &local_err);

The old behaviour was that we only recurse for bs->file if the block driver doesn't have its own implementation.

Quoted 3 lines

This means that in qcow2, for example, we call bdrv_invalidate_cache() explicitly for bs->file. If we can already invalidate it here, the call inside qcow2 and probably other drivers could go away.

Yes, will update. Thanks.

Fam

author
#6 lore raw

PATCH 2/2 block: Inactivate all children

In reply to Fam Zheng

Currently we only inactivate the top BDS. Actually bdrv_inactivate should be the opposite of bdrv_invalidate_cache.

Recurse into the whole subtree instead.

---
 block.c | 8 ++++++++
 1 file changed, 8 insertions(+)
block.c +8 -0
index fa8b38f..9a84ed1 100644
@@ -3260,8 +3260,16 @@ void bdrv_invalidate_cache_all(Error **errp)
 
 static int bdrv_inactivate(BlockDriverState *bs)
 {
+    BdrvChild *child;
     int ret;
 
+    QLIST_FOREACH(child, &bs->children, next) {
+        ret = bdrv_inactivate(child->bs);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
     if (bs->drv->bdrv_inactivate) {
         ret = bs->drv->bdrv_inactivate(bs);
         if (ret < 0) {
Signature · 1 line
2.8.0
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Inactivate all children

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 6 lines

Currently we only inactivate the top BDS. Actually bdrv_inactivate should be the opposite of bdrv_invalidate_cache.

Recurse into the whole subtree instead.

Did you actually test this?

I would expect that bs->drv->bdrv_inactivate() fails now (as in assertion failure) if it has anything to flush to the image because bs->file has already be inactivated before. I think children need to be inactived after their parents.

Nodes with multiple parents could actually become even more interesting...

Kevin

Quoted 27 lines
 block.c | 8 ++++++++
 1 file changed, 8 insertions(+)
block.c +8 -0
index fa8b38f..9a84ed1 100644
@@ -3260,8 +3260,16 @@ void bdrv_invalidate_cache_all(Error **errp)
 
 static int bdrv_inactivate(BlockDriverState *bs)
 {
+    BdrvChild *child;
     int ret;
 
+    QLIST_FOREACH(child, &bs->children, next) {
+        ret = bdrv_inactivate(child->bs);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
     if (bs->drv->bdrv_inactivate) {
         ret = bs->drv->bdrv_inactivate(bs);
         if (ret < 0) {
Signature · 1 line
2.8.0
author
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Inactivate all children

Quoted 6 lines · Kevin Wolf

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 5 lines

Currently we only inactivate the top BDS. Actually bdrv_inactivate should be the opposite of bdrv_invalidate_cache.

Recurse into the whole subtree instead.

Quoted 8 lines
Quoted 1 line

Did you actually test this?

I would expect that bs->drv->bdrv_inactivate() fails now (as in assertion failure) if it has anything to flush to the image because bs->file has already be inactivated before. I think children need to be inactived after their parents.

OK, my test apparently failed to trigger that bdrv_pwritv() path. Good catch!

Quoted 3 lines

Nodes with multiple parents could actually become even more interesting...

I'll make it two passes recursion: one for calling drv->bdrv_inactivate and the other for setting BDRV_O_INACTIVATE.

Fam

#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Inactivate all children

Am 05.05.2016 um 02:32 hat Fam Zheng geschrieben:

Quoted 16 lines · Kevin Wolf
Quoted 6 lines

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 5 lines

Currently we only inactivate the top BDS. Actually bdrv_inactivate should be the opposite of bdrv_invalidate_cache.

Recurse into the whole subtree instead.

Quoted 8 lines
Quoted 1 line

Did you actually test this?

I would expect that bs->drv->bdrv_inactivate() fails now (as in assertion failure) if it has anything to flush to the image because bs->file has already be inactivated before. I think children need to be inactived after their parents.

Quoted 8 lines

OK, my test apparently failed to trigger that bdrv_pwritv() path. Good catch!

Quoted 3 lines

Nodes with multiple parents could actually become even more interesting...

I'll make it two passes recursion: one for calling drv->bdrv_inactivate and the other for setting BDRV_O_INACTIVATE.

Though that would assume that the .bdrv_inactivate() implementation of drivers doesn't already bring the BDS into a state where further writes aren't possible. I'm not sure if that's a good assumption to make, even though it's currently true for qcow2.

For example, imagine we went forward with format-based image locking. The first .bdrv_inactivate() would then already release the lock, we can't continue writing after that.

Maybe we need something like an "active reference counter", and we decrement that for all children and only call their .bdrv_inactivate() when it arrives at 0.

Kevin

author
#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Inactivate all children

Quoted 26 lines · Kevin Wolf

Am 05.05.2016 um 02:32 hat Fam Zheng geschrieben:

Quoted 16 lines · Kevin Wolf
Quoted 6 lines

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 5 lines

Currently we only inactivate the top BDS. Actually bdrv_inactivate should be the opposite of bdrv_invalidate_cache.

Recurse into the whole subtree instead.

Quoted 8 lines
Quoted 1 line

Did you actually test this?

I would expect that bs->drv->bdrv_inactivate() fails now (as in assertion failure) if it has anything to flush to the image because bs->file has already be inactivated before. I think children need to be inactived after their parents.

Quoted 8 lines

OK, my test apparently failed to trigger that bdrv_pwritv() path. Good catch!

Quoted 3 lines

Nodes with multiple parents could actually become even more interesting...

I'll make it two passes recursion: one for calling drv->bdrv_inactivate and the other for setting BDRV_O_INACTIVATE.

Quoted 8 lines

Though that would assume that the .bdrv_inactivate() implementation of drivers doesn't already bring the BDS into a state where further writes aren't possible. I'm not sure if that's a good assumption to make, even though it's currently true for qcow2.

For example, imagine we went forward with format-based image locking. The first .bdrv_inactivate() would then already release the lock, we can't continue writing after that.

we only need to make sure all cache of all images is flushed when bdrv_inactivate_all() returns, and similarly, that the cache of one image is flushed when .bdrv_inactivate() returns. The releasing of the lock is an explicit callback and should be place in bdrv_inactivate() right above setting of BDRV_O_INACTIVATE. This is the case in my image locking series.

Quoted 4 lines

Maybe we need something like an "active reference counter", and we decrement that for all children and only call their .bdrv_inactivate() when it arrives at 0.

That should work, but the effect of the counters are local to one invocation of bdrv_inactivate_all(), and is not really necessary if we do as above.

Fam

#11 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Inactivate all children

Am 10.05.2016 um 05:23 hat Fam Zheng geschrieben:

Quoted 36 lines · Kevin Wolf
Quoted 26 lines

Am 05.05.2016 um 02:32 hat Fam Zheng geschrieben:

Quoted 16 lines · Kevin Wolf
Quoted 6 lines

Am 19.04.2016 um 03:42 hat Fam Zheng geschrieben:

Quoted 5 lines

Currently we only inactivate the top BDS. Actually bdrv_inactivate should be the opposite of bdrv_invalidate_cache.

Recurse into the whole subtree instead.

Quoted 8 lines
Quoted 1 line

Did you actually test this?

I would expect that bs->drv->bdrv_inactivate() fails now (as in assertion failure) if it has anything to flush to the image because bs->file has already be inactivated before. I think children need to be inactived after their parents.

Quoted 8 lines

OK, my test apparently failed to trigger that bdrv_pwritv() path. Good catch!

Quoted 3 lines

Nodes with multiple parents could actually become even more interesting...

I'll make it two passes recursion: one for calling drv->bdrv_inactivate and the other for setting BDRV_O_INACTIVATE.

Quoted 8 lines

Though that would assume that the .bdrv_inactivate() implementation of drivers doesn't already bring the BDS into a state where further writes aren't possible. I'm not sure if that's a good assumption to make, even though it's currently true for qcow2.

For example, imagine we went forward with format-based image locking. The first .bdrv_inactivate() would then already release the lock, we can't continue writing after that.

Quoted 5 lines

we only need to make sure all cache of all images is flushed when bdrv_inactivate_all() returns, and similarly, that the cache of one image is flushed when .bdrv_inactivate() returns. The releasing of the lock is an explicit callback and should be place in bdrv_inactivate() right above setting of BDRV_O_INACTIVATE. This is the case in my image locking series.

Fair enough. My series didn't have a separate callback, but with yours that should be working.

So is the semantics of .bdrv_inactivate() basically "bdrv_flush, and I really mean it"?

Quoted 6 lines
Quoted 3 lines

Maybe we need something like an "active reference counter", and we decrement that for all children and only call their .bdrv_inactivate() when it arrives at 0.

That should work, but the effect of the counters are local to one invocation of bdrv_inactivate_all(), and is not really necessary if we do as above.

Agreed.

Kevin

author
#12 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: Inactivate all children

Quoted 6 lines · Kevin Wolf

Fair enough. My series didn't have a separate callback, but with yours that should be working.

So is the semantics of .bdrv_inactivate() basically "bdrv_flush, and I really mean it"?

Yes.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

Maybe we need something like an "active reference counter", and we decrement that for all children and only call their .bdrv_inactivate() when it arrives at 0.

That should work, but the effect of the counters are local to one invocation of bdrv_inactivate_all(), and is not really necessary if we do as above.

Agreed.

Working on another version now.

Fam