Skip to contentSkip to conversation

block: bdrv_invalidate_cache: invalidate children first

PATCH Applied Vladimir Sementsov-Ogievskiy 3 participants 5 messages Jan 31, 2017 – Feb 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: bdrv_invalidate_cache: invalidate children first

Current implementation invalidates firstly parent bds and then its children. This leads to the following bug:

after incoming migration, in bdrv_invalidate_cache_all:
1. invalidate parent bds - reopen it with BDRV_O_INACTIVE cleared
2. child is not yet invalidated
3. parent check that its BDRV_O_INACTIVE is cleared
4. parent writes to child
5. assert in bdrv_co_pwritev, as BDRV_O_INACTIVE is set for child

This patch fixes it by just changing invalidate sequence: invalidate children first.

---

v2: I've missed that bdrv_invalidate_cache is already recursive, so we can change sequence here. Also v1 doesn't cover the case when bdrv_invalidate_cache is called not from bdrv_invalidate_cache_all.

 block.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
block.c +5 -6
index a0346c80c6..dce1dc02af 100644
@@ -3235,19 +3235,18 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
     if (!(bs->open_flags & BDRV_O_INACTIVE)) {
         return;
     }
-    bs->open_flags &= ~BDRV_O_INACTIVE;
 
-    if (bs->drv->bdrv_invalidate_cache) {
-        bs->drv->bdrv_invalidate_cache(bs, &local_err);
+    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;
         }
     }
 
-    QLIST_FOREACH(child, &bs->children, next) {
-        bdrv_invalidate_cache(child->bs, &local_err);
+    bs->open_flags &= ~BDRV_O_INACTIVE;
+    if (bs->drv->bdrv_invalidate_cache) {
+        bs->drv->bdrv_invalidate_cache(bs, &local_err);
         if (local_err) {
             bs->open_flags |= BDRV_O_INACTIVE;
             error_propagate(errp, local_err);
Signature · 1 line
2.11.0
#1 lore raw

v2 missed in topic, sorry for that.

First version was "[PATCH] block: bdrv_invalidate_cache_all: invalidate children first"

Signature · 2 lines
Best regards,
Vladimir
Reviewed-by on v1 1/1
#2 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 14 lines · Vladimir Sementsov-Ogievskiy

Current implementation invalidates firstly parent bds and then its children. This leads to the following bug:

after incoming migration, in bdrv_invalidate_cache_all:
1. invalidate parent bds - reopen it with BDRV_O_INACTIVE cleared
2. child is not yet invalidated
3. parent check that its BDRV_O_INACTIVE is cleared
4. parent writes to child
5. assert in bdrv_co_pwritev, as BDRV_O_INACTIVE is set for child

This patch fixes it by just changing invalidate sequence: invalidate children first.

Quoted 8 lines

---

v2: I've missed that bdrv_invalidate_cache is already recursive, so we can change sequence here. Also v1 doesn't cover the case when bdrv_invalidate_cache is called not from bdrv_invalidate_cache_all.

 block.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

I'll wait a bit until I apply this patch (please remind me next week if I forget it...), though, because migration-related things are not exactly my forte, so maybe someone else has something to say.

Max

Reviewed-by on v1 1/1
#3 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 14 lines · Vladimir Sementsov-Ogievskiy

Current implementation invalidates firstly parent bds and then its children. This leads to the following bug:

after incoming migration, in bdrv_invalidate_cache_all:
1. invalidate parent bds - reopen it with BDRV_O_INACTIVE cleared
2. child is not yet invalidated
3. parent check that its BDRV_O_INACTIVE is cleared
4. parent writes to child
5. assert in bdrv_co_pwritev, as BDRV_O_INACTIVE is set for child

This patch fixes it by just changing invalidate sequence: invalidate children first.

Quoted 8 lines

---

v2: I've missed that bdrv_invalidate_cache is already recursive, so we can change sequence here. Also v1 doesn't cover the case when bdrv_invalidate_cache is called not from bdrv_invalidate_cache_all.

 block.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Applied
#4 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 13 lines · Vladimir Sementsov-Ogievskiy

Current implementation invalidates firstly parent bds and then its children. This leads to the following bug:

after incoming migration, in bdrv_invalidate_cache_all:
1. invalidate parent bds - reopen it with BDRV_O_INACTIVE cleared
2. child is not yet invalidated
3. parent check that its BDRV_O_INACTIVE is cleared
4. parent writes to child
5. assert in bdrv_co_pwritev, as BDRV_O_INACTIVE is set for child

This patch fixes it by just changing invalidate sequence: invalidate children first.

Quoted 6 lines

---

v2: I've missed that bdrv_invalidate_cache is already recursive, so we can change sequence here. Also v1 doesn't cover the case when bdrv_invalidate_cache is called not from bdrv_invalidate_cache_all.

Thanks, applied to my block tree:

https://github.com/XanClic/qemu/commits/block

Max