[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/29] block: Pause all jobs during bdrv_reopen_multi
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 07/29] block: Pause all jobs during bdrv_reopen_multiple() |
Date: |
Mon, 31 Oct 2016 18:25:36 +0100 |
From: Alberto Garcia <address@hidden>
When a BlockDriverState is about to be reopened it can trigger certain
operations that need to write to disk. During this process a different
block job can be woken up. If that block job completes and also needs
to call bdrv_reopen() it can happen that it needs to do it on the same
BlockDriverState that is still in the process of being reopened.
This can have fatal consequences, like in this example:
1) Block job A starts and sleeps after a while.
2) Block job B starts and tries to reopen node1 (a qcow2 file).
3) Reopening node1 means flushing and replacing its qcow2 cache.
4) While the qcow2 cache is being flushed, job A wakes up.
5) Job A completes and reopens node1, replacing its cache.
6) Job B resumes, but the cache that was being flushed no longer
exists.
This patch splits the bdrv_drain_all() call to keep all block jobs
paused during bdrv_reopen_multiple(), so that step 4 can never happen
and the operation is safe.
Note that this scenario can only happen if both bdrv_reopen() calls
are made by block jobs on the same backing chain. Otherwise there's no
chance that the same BlockDriverState appears in both reopen queues.
Signed-off-by: Alberto Garcia <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index a17baab..2c87186 100644
--- a/block.c
+++ b/block.c
@@ -2091,7 +2091,7 @@ int bdrv_reopen_multiple(AioContext *ctx,
BlockReopenQueue *bs_queue, Error **er
assert(bs_queue != NULL);
aio_context_release(ctx);
- bdrv_drain_all();
+ bdrv_drain_all_begin();
aio_context_acquire(ctx);
QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
@@ -2122,6 +2122,9 @@ cleanup:
g_free(bs_entry);
}
g_free(bs_queue);
+
+ bdrv_drain_all_end();
+
return ret;
}
--
1.8.3.1
- [Qemu-devel] [PULL 00/29] Block layer patches, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 04/29] block/ssh: Use InetSocketAddress options, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 05/29] qapi: allow blockdev-add for ssh, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 06/29] block: Add bdrv_drain_all_{begin,end}(), Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 02/29] util/qemu-sockets: Make inet_connect_saddr() public, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 01/29] block/ssh: Add ssh_has_filename_options_conflict(), Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 07/29] block: Pause all jobs during bdrv_reopen_multiple(),
Kevin Wolf <=
- [Qemu-devel] [PULL 08/29] block: Add block_job_add_bdrv(), Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 09/29] block: Use block_job_add_bdrv() in mirror_start_job(), Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 10/29] block: Use block_job_add_bdrv() in backup_start(), Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 03/29] block/ssh: Add InetSocketAddress and accept it, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 11/29] block: Check blockers in all nodes involved in a block-commit job, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 14/29] block: Support streaming to an intermediate layer, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 13/29] block: Block all intermediate nodes in commit_active_start(), Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 15/29] block: Add QMP support for streaming to an intermediate layer, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 12/29] block: Block all nodes involved in the block-commit operation, Kevin Wolf, 2016/10/31
- [Qemu-devel] [PULL 16/29] docs: Document how to stream to an intermediate layer, Kevin Wolf, 2016/10/31