[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 32/64] block: Flush all children in generic code
From: |
Kevin Wolf |
Subject: |
[PULL 32/64] block: Flush all children in generic code |
Date: |
Mon, 7 Sep 2020 13:09:04 +0200 |
From: Max Reitz <mreitz@redhat.com>
If the driver does not support .bdrv_co_flush() so bdrv_co_flush()
itself has to flush the children of the given node, it should not flush
just bs->file->bs, but in fact all children that might have been written
to (judging from the permissions taken on them).
This is a bug fix for qcow2 images with an external data file, as they
so far did not flush that data_file node.
In any case, the BLKDBG_EVENT() should be emitted on the primary child,
because that is where a blkdebug node would be if there is any.
Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
block/io.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/block/io.c b/block/io.c
index 6f9402117e..8d777cd0ec 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2771,6 +2771,8 @@ static int coroutine_fn bdrv_flush_co_entry(void *opaque)
int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
{
+ BdrvChild *primary_child = bdrv_primary_child(bs);
+ BdrvChild *child;
int current_gen;
int ret = 0;
@@ -2800,7 +2802,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
}
/* Write back cached data to the OS even with cache=unsafe */
- BLKDBG_EVENT(bs->file, BLKDBG_FLUSH_TO_OS);
+ BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_OS);
if (bs->drv->bdrv_co_flush_to_os) {
ret = bs->drv->bdrv_co_flush_to_os(bs);
if (ret < 0) {
@@ -2810,15 +2812,15 @@ 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_parent;
+ goto flush_children;
}
/* Check if we really need to flush anything */
if (bs->flushed_gen == current_gen) {
- goto flush_parent;
+ goto flush_children;
}
- BLKDBG_EVENT(bs->file, BLKDBG_FLUSH_TO_DISK);
+ BLKDBG_EVENT(primary_child, BLKDBG_FLUSH_TO_DISK);
if (!bs->drv) {
/* bs->drv->bdrv_co_flush() might have ejected the BDS
* (even in case of apparent success) */
@@ -2862,8 +2864,17 @@ 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_parent:
- ret = bs->file ? bdrv_co_flush(bs->file->bs) : 0;
+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;
+ }
+ }
+ }
+
out:
/* Notify any pending flushes that we have completed */
if (ret == 0) {
--
2.25.4
- [PULL 24/64] throttle: Support compressed writes, (continued)
- [PULL 24/64] throttle: Support compressed writes, Kevin Wolf, 2020/09/07
- [PULL 26/64] block: Use bdrv_filter_(bs|child) where obvious, Kevin Wolf, 2020/09/07
- [PULL 22/64] block: Drop bdrv_is_encrypted(), Kevin Wolf, 2020/09/07
- [PULL 27/64] block: Use CAFs in block status functions, Kevin Wolf, 2020/09/07
- [PULL 25/64] copy-on-read: Support compressed writes, Kevin Wolf, 2020/09/07
- [PULL 28/64] stream: Deal with filters, Kevin Wolf, 2020/09/07
- [PULL 30/64] block: Use bdrv_cow_child() in bdrv_co_truncate(), Kevin Wolf, 2020/09/07
- [PULL 31/64] block: Re-evaluate backing file handling in reopen, Kevin Wolf, 2020/09/07
- [PULL 29/64] block: Use CAFs when working with backing chains, Kevin Wolf, 2020/09/07
- [PULL 38/64] block: Use CAFs for debug breakpoints, Kevin Wolf, 2020/09/07
- [PULL 32/64] block: Flush all children in generic code,
Kevin Wolf <=
- [PULL 39/64] block: Improve get_allocated_file_size's default, Kevin Wolf, 2020/09/07
- [PULL 40/64] block/null: Implement bdrv_get_allocated_file_size, Kevin Wolf, 2020/09/07
- [PULL 34/64] block: Iterate over children in refresh_limits, Kevin Wolf, 2020/09/07
- [PULL 35/64] block: Use CAFs in bdrv_refresh_filename(), Kevin Wolf, 2020/09/07
- [PULL 41/64] blockdev: Use CAF in external_snapshot_prepare(), Kevin Wolf, 2020/09/07
- [PULL 36/64] block: Use CAF in bdrv_co_rw_vmstate(), Kevin Wolf, 2020/09/07
- [PULL 43/64] block: Use child access functions for QAPI queries, Kevin Wolf, 2020/09/07
- [PULL 33/64] vmdk: Drop vmdk_co_flush(), Kevin Wolf, 2020/09/07
- [PULL 45/64] mirror: Deal with filters, Kevin Wolf, 2020/09/07
- [PULL 48/64] nbd: Use CAF when looking for dirty bitmap, Kevin Wolf, 2020/09/07