[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 06/29] block: Add bdrv_drain_all_{begin,end}()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 06/29] block: Add bdrv_drain_all_{begin,end}() |
Date: |
Mon, 31 Oct 2016 18:25:35 +0100 |
From: Alberto Garcia <address@hidden>
bdrv_drain_all() doesn't allow the caller to do anything after all
pending requests have been completed but before block jobs are
resumed.
This patch splits bdrv_drain_all() into _begin() and _end() for that
purpose. It also adds aio_{disable,enable}_external() calls to disable
external clients in the meantime.
An important restriction of this split is that no new block jobs or
BlockDriverStates can be created between the bdrv_drain_all_begin()
and bdrv_drain_all_end() calls. This is not a concern now because
we'll only be using this in bdrv_reopen_multiple(), but it must be
dealt with if we ever have other uses cases in the future.
Signed-off-by: Alberto Garcia <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/io.c | 27 ++++++++++++++++++++++++---
include/block/block.h | 2 ++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/block/io.c b/block/io.c
index be0d862..37749b6 100644
--- a/block/io.c
+++ b/block/io.c
@@ -273,8 +273,14 @@ void bdrv_drain(BlockDriverState *bs)
*
* This function does not flush data to disk, use bdrv_flush_all() for that
* after calling this function.
+ *
+ * This pauses all block jobs and disables external clients. It must
+ * be paired with bdrv_drain_all_end().
+ *
+ * NOTE: no new block jobs or BlockDriverStates can be created between
+ * the bdrv_drain_all_begin() and bdrv_drain_all_end() calls.
*/
-void bdrv_drain_all(void)
+void bdrv_drain_all_begin(void)
{
/* Always run first iteration so any pending completion BHs run */
bool waited = true;
@@ -297,6 +303,7 @@ void bdrv_drain_all(void)
aio_context_acquire(aio_context);
bdrv_parent_drained_begin(bs);
bdrv_io_unplugged_begin(bs);
+ aio_disable_external(aio_context);
aio_context_release(aio_context);
if (!g_slist_find(aio_ctxs, aio_context)) {
@@ -326,17 +333,25 @@ void bdrv_drain_all(void)
}
}
+ g_slist_free(aio_ctxs);
+}
+
+void bdrv_drain_all_end(void)
+{
+ BlockDriverState *bs;
+ BdrvNextIterator it;
+ BlockJob *job = NULL;
+
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
AioContext *aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
+ aio_enable_external(aio_context);
bdrv_io_unplugged_end(bs);
bdrv_parent_drained_end(bs);
aio_context_release(aio_context);
}
- g_slist_free(aio_ctxs);
- job = NULL;
while ((job = block_job_next(job))) {
AioContext *aio_context = blk_get_aio_context(job->blk);
@@ -346,6 +361,12 @@ void bdrv_drain_all(void)
}
}
+void bdrv_drain_all(void)
+{
+ bdrv_drain_all_begin();
+ bdrv_drain_all_end();
+}
+
/**
* Remove an active request from the tracked requests list
*
diff --git a/include/block/block.h b/include/block/block.h
index b7dc7d5..b81a3e3 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -332,6 +332,8 @@ int bdrv_flush_all(void);
void bdrv_close_all(void);
void bdrv_drain(BlockDriverState *bs);
void coroutine_fn bdrv_co_drain(BlockDriverState *bs);
+void bdrv_drain_all_begin(void);
+void bdrv_drain_all_end(void);
void bdrv_drain_all(void);
#define BDRV_POLL_WHILE(bs, cond) ({ \
--
1.8.3.1
- [Qemu-block] [PULL 00/29] Block layer patches, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 04/29] block/ssh: Use InetSocketAddress options, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 01/29] block/ssh: Add ssh_has_filename_options_conflict(), Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 05/29] qapi: allow blockdev-add for ssh, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 06/29] block: Add bdrv_drain_all_{begin,end}(),
Kevin Wolf <=
- [Qemu-block] [PULL 03/29] block/ssh: Add InetSocketAddress and accept it, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 02/29] util/qemu-sockets: Make inet_connect_saddr() public, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 08/29] block: Add block_job_add_bdrv(), Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 07/29] block: Pause all jobs during bdrv_reopen_multiple(), Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 09/29] block: Use block_job_add_bdrv() in mirror_start_job(), Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 12/29] block: Block all nodes involved in the block-commit operation, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 10/29] block: Use block_job_add_bdrv() in backup_start(), Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 11/29] block: Check blockers in all nodes involved in a block-commit job, Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 13/29] block: Block all intermediate nodes in commit_active_start(), Kevin Wolf, 2016/10/31
- [Qemu-block] [PULL 14/29] block: Support streaming to an intermediate layer, Kevin Wolf, 2016/10/31