block/io.c: Flush parent for quorum in generic code
RFC PATCH 1/1 block/io.c: Flush parent for quorum in generic code
Fix the issue from this patch:
[PATCH] block: Flush all children in generic code
From 883833e29cb800b4d92b5d4736252f4004885191
Quorum driver do not have the primary child.
It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown.
--- block/io.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
block/io.c +22 -9
@@ -2849,6 +2849,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)BdrvChild *child;int current_gen;int ret =0 ; +bool no_primary_child = false; + +/* Quorum drivers do not have the primary child. */ +if (!primary_child) { + primary_child = bs->file; + no_primary_child = true; + }bdrv_inc_in_flight (bs);
@@ -2886,12 +2893,12 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)/* But don't actually force it to the disk with cache=unsafe */ if (bs->open_flags &BDRV_O_NO_FLUSH ) { - goto flush_children; + goto flush_data; }/* Check if we really need to flush anything */ if (bs->flushed_gen == current_gen) { - goto flush_children; + goto flush_data; }BLKDBG_EVENT (primary_child,BLKDBG_FLUSH_TO_DISK );
@@ -2938,13 +2945,19 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)/* Now flush the underlying protocol. It will also have BDRV_O_NO_FLUSH * in the case of cache=unsafe, so there are no useless flushes. */ -flush_children: - ret =0 ; - QLIST_FOREACH(child, &bs->children, next) { -if (child->perm & (BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED )) { -int this_child_ret =bdrv_co_flush (child->bs); -if (!ret) { - ret = this_child_ret; +flush_data: +if (no_primary_child) { +/* Flush parent */ + ret = bs->file ?bdrv_co_flush (bs->file->bs) :0 ; + }else { +/* Flush childrens */ + ret =0 ; + QLIST_FOREACH(child, &bs->children, next) { +if (child->perm & (BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED )) { +int this_child_ret =bdrv_co_flush (child->bs); +if (!ret) { + ret = this_child_ret; + } } } }
Signature · 1 line
2.25.1
Quoted 13 lines · Zhang Chen
Fix the issue from this patch:
[PATCH] block: Flush all children in generic code
From883833e29cb800b4d92b5d4736252f4004885191Quorum driver do not have the primary child.
It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown.Signed-off-by Zhang Chen <[email protected]>Reported-by Minghao Yuan <[email protected]>--- block/io.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
...
Quoted 5 lines
block/io.c +5
-0+flush_data: +if (no_primary_child) { +/* Flush parent */ + ret = bs->file ?bdrv_co_flush (bs->file->bs) :0 ; + }else {
block/io.c int coroutine_fn bdrv_co_flush(BlockDriverState *bs) · line 2962
Quoted 10 lines
block/io.c +8
-0+/* Flush childrens */ + ret =0 ; + QLIST_FOREACH(child, &bs->children, next) { +if (child->perm & (BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED )) { +int this_child_ret =bdrv_co_flush (child->bs); +if (!ret) { + ret = this_child_ret; + } } }
I'm missing something:
The quorum driver has a valid bs->children list even though it does not have a primary child. Why does QLIST_FOREACH() loop fail for you?
Does this patch effectively skip bdrv_co_flush() calls on all quorum children? That seems wrong since children need to be flushed so that data is persisted.
Stefan
Quoted 44 lines
-----Original Message-----
From: Stefan Hajnoczi <[email protected]>
Sent: Thursday, May 13, 2021 10:26 PM
To: Zhang, Chen <[email protected]>
Cc: Kevin Wolf <[email protected]>; Max Reitz <[email protected]>; Fam Zheng <[email protected]>; qemu-dev <[email protected]>; qemu- block <[email protected]>; Zhang Chen <[email protected]>; Minghao Yuan <[email protected]>
Subject: Re: [RFC PATCH]block/io.c: Flush parent for quorum in generic codeQuoted 13 lines · Zhang Chen
Fix the issue from this patch:
[PATCH] block: Flush all children in generic code From883833e29cb800b4d92b5d4736252f4004885191Quorum driver do not have the primary child.
It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown.Signed-off-by Zhang Chen <[email protected]>Reported-by Minghao Yuan <[email protected]>--- block/io.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)...
block/io.c int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
Quoted 9 lines
block/io.c +9
-0+flush_data: +if (no_primary_child) { +/* Flush parent */ + ret = bs->file ?bdrv_co_flush (bs->file->bs) :0 ; + }else { +/* Flush childrens */ + ret =0 ; + QLIST_FOREACH(child, &bs->children, next) { + if (child->perm & (BLK_PERM_WRITE |
BLK_PERM_WRITE_UNCHANGED)) {block/io.c int coroutine_fn bdrv_co_flush(BlockDriverState *bs) · line 2962
Quoted 6 lines
block/io.c +4
-0+int this_child_ret =bdrv_co_flush (child->bs); +if (!ret) { + ret = this_child_ret; + } } }
Quoted 5 lines
I'm missing something:
The quorum driver has a valid
bs->childrenlist even though it does not have a primary child. Why doesQLIST_FOREACH()loop fail for you?
Yes, in most cases QLIST_FOREACH() works for me.
But not work when one of the child disconnected, the original patch changed the default behavior of quorum driver when occurs issue.
For example:
VM quorum driver have two children, local disk1 and NBD disk2. When network down and NBD disk2 disconnected, current code will report "event": "QUORUM_REPORT_BAD" "type": "flush", "error": "Input/output error" And
"event": "BLOCK_IO_ERROR" "#block008", "reason": "Input/output error"
The guest even cannot read/write the normal local disk1. VM IO will crashed caused by NDB disk2 input/output error. I think we do need report the event about we lose a child(NBD disk2) at this time, but no need crash all IO system. Because we can fix it by x-blockdev-change and drive_add/drive_del for new children.
Before the original patch(883833e2), VM still can read/write the local disk1.
This patch just the RFC version, please give me more comments to fix this issue.
Thanks
Chen
Quoted 3 lines
Does this patch effectively skip
bdrv_co_flush()calls on all quorum children? That seems wrong since children need to be flushed so that data is persisted.
Yes,
Quoted 1 line
Stefan
Quoted 7 lines · On Wed, 12 May 2021 15:49:57 +0800 Zhang Chen <[email protected]> wrote:
Fix the issue from this patch:
[PATCH] block: Flush all children in generic code
From883833e29cb800b4d92b5d4736252f4004885191Quorum driver do not have the primary child.
It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown.
Hi,
I think the problem is rather that the quorum driver provides .bdrv_co_flush_to_disk (which predates .bdrv_co_flush) instead of .bdrv_co_flush. Can you try with the following patch instead?
block/quorum.c +1 -1
@@ -1279,7 +1279,7 @@ static BlockDriver bdrv_quorum = { .bdrv_dirname = quorum_dirname, .bdrv_co_block_status = quorum_co_block_status, - .bdrv_co_flush_to_disk = quorum_co_flush, + .bdrv_co_flush = quorum_co_flush, .bdrv_getlength = quorum_getlength,
Quoted 66 lines
Signed-off-by Zhang Chen <[email protected]>Reported-by Minghao Yuan <[email protected]>--- block/io.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)block/io.c +22
-9@@ -2849,6 +2849,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)BdrvChild *child;int current_gen;int ret =0 ; +bool no_primary_child = false; + +/* Quorum drivers do not have the primary child. */ +if (!primary_child) { + primary_child = bs->file; + no_primary_child = true; + }bdrv_inc_in_flight (bs);@@ -2886,12 +2893,12 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)/* But don't actually force it to the disk with cache=unsafe */ if (bs->open_flags &BDRV_O_NO_FLUSH ) { - goto flush_children; + goto flush_data; }/* Check if we really need to flush anything */ if (bs->flushed_gen == current_gen) { - goto flush_children; + goto flush_data; }BLKDBG_EVENT (primary_child,BLKDBG_FLUSH_TO_DISK );@@ -2938,13 +2945,19 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)/* Now flush the underlying protocol. It will also have BDRV_O_NO_FLUSH * in the case of cache=unsafe, so there are no useless flushes. */ -flush_children: - ret =0 ; - QLIST_FOREACH(child, &bs->children, next) { -if (child->perm & (BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED )) { -int this_child_ret =bdrv_co_flush (child->bs); -if (!ret) { - ret = this_child_ret; +flush_data: +if (no_primary_child) { +/* Flush parent */ + ret = bs->file ?bdrv_co_flush (bs->file->bs) :0 ; + }else { +/* Flush childrens */ + ret =0 ; + QLIST_FOREACH(child, &bs->children, next) { +if (child->perm & (BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED )) { +int this_child_ret =bdrv_co_flush (child->bs); +if (!ret) { + ret = this_child_ret; + } } } }
Am 18.05.2021 um 08:33 hat Lukas Straub geschrieben:
Quoted 21 lines
Quoted 7 lines · On Wed, 12 May 2021 15:49:57 +0800 Zhang Chen <[email protected]> wrote:
Fix the issue from this patch:
[PATCH] block: Flush all children in generic code
From883833e29cb800b4d92b5d4736252f4004885191Quorum driver do not have the primary child.
It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown.Hi,
I think the problem is rather that the quorum driver provides .bdrv_co_flush_to_disk (which predates .bdrv_co_flush) instead of .bdrv_co_flush. Can you try with the following patch instead?block/quorum.c +0
-0
block/quorum.c static BlockDriver bdrv_quorum = { · line 1284
Quoted 7 lines
block/quorum.c +1
-1@@ -1279,7 +1279,7 @@ static BlockDriver bdrv_quorum = { .bdrv_dirname = quorum_dirname, .bdrv_co_block_status = quorum_co_block_status, - .bdrv_co_flush_to_disk = quorum_co_flush, + .bdrv_co_flush = quorum_co_flush, .bdrv_getlength = quorum_getlength,
Thanks, Lukas. This is exactly what I was going to suggest after having a look at the code now.
The problem is not related to drivers not having a primary child in general (though quorum might be the only one in this category at the moment), but that quorum wants to override the default error handling semantics with its voting mechanism.
Kevin
Quoted 46 lines
-----Original Message-----
From: Kevin Wolf <[email protected]>
Sent: Tuesday, May 18, 2021 3:39 PM
To: Lukas Straub <[email protected]>
Cc: Zhang, Chen <[email protected]>; Max Reitz <[email protected]>; Stefan Hajnoczi <[email protected]>; Fam Zheng <[email protected]>; qemu-dev <[email protected]>; qemu-block <qemu- [email protected]>; Minghao Yuan <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [RFC PATCH]block/io.c: Flush parent for quorum in generic codeAm 18.05.2021 um 08:33 hat Lukas Straub geschrieben:
Quoted 21 lines
Quoted 7 lines · On Wed, 12 May 2021 15:49:57 +0800 Zhang Chen <[email protected]> wrote:
Fix the issue from this patch:
[PATCH] block: Flush all children in generic code From883833e29cb800b4d92b5d4736252f4004885191Quorum driver do not have the primary child.
It will caused guest block flush issue when use quorum and NBD. The vm guest flushes failed,and then guest filesystem is shutdown.Hi,
I think the problem is rather that the quorum driver provides .bdrv_co_flush_to_disk (which predates .bdrv_co_flush) instead of .bdrv_co_flush. Can you try with the following patch instead?block/quorum.c index renamed from block/quorum.c +0
-0
cfc1436abb..f2c0805000100644block/quorum.c static BlockDriver bdrv_quorum = { · line 1284
Quoted 7 lines
block/quorum.c +1
-1@@ -1279,7 +1279,7 @@ static BlockDriver bdrv_quorum = { .bdrv_dirname = quorum_dirname, .bdrv_co_block_status = quorum_co_block_status, - .bdrv_co_flush_to_disk = quorum_co_flush, + .bdrv_co_flush = quorum_co_flush, .bdrv_getlength = quorum_getlength,Thanks, Lukas. This is exactly what I was going to suggest after having a look at the code now.
Quoted 4 lines
The problem is not related to drivers not having a primary child in general (though quorum might be the only one in this category at the moment), but that quorum wants to override the default error handling semantics with its voting mechanism.
Yes, you are right. We can ignore this patch.
I tested Lukas's patch, it works for me.
Hi Lukas, Can you send this patch to upstream?
Thanks
Chen
Quoted 2 lines
Kevin