From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 48/53] block: add bdrv_drain()
Date: Mon, 3 Nov 2014 11:50:51 +0000 [thread overview]
Message-ID: <1415015456-25086-49-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1415015456-25086-1-git-send-email-stefanha@redhat.com>
Now that op blockers are in use, we can ensure that no other sources are
generating I/O on a BlockDriverState. Therefore it is possible to drain
requests for a single BDS.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1413889440-32577-7-git-send-email-stefanha@redhat.com
---
block.c | 36 +++++++++++++++++++++++++++++-------
include/block/block.h | 1 +
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/block.c b/block.c
index c5ff560..a909b9d 100644
--- a/block.c
+++ b/block.c
@@ -1904,6 +1904,34 @@ static bool bdrv_requests_pending(BlockDriverState *bs)
return false;
}
+static bool bdrv_drain_one(BlockDriverState *bs)
+{
+ bool bs_busy;
+
+ bdrv_flush_io_queue(bs);
+ bdrv_start_throttled_reqs(bs);
+ bs_busy = bdrv_requests_pending(bs);
+ bs_busy |= aio_poll(bdrv_get_aio_context(bs), bs_busy);
+ return bs_busy;
+}
+
+/*
+ * Wait for pending requests to complete on a single BlockDriverState subtree
+ *
+ * See the warning in bdrv_drain_all(). This function can only be called if
+ * you are sure nothing can generate I/O because you have op blockers
+ * installed.
+ *
+ * Note that unlike bdrv_drain_all(), the caller must hold the BlockDriverState
+ * AioContext.
+ */
+void bdrv_drain(BlockDriverState *bs)
+{
+ while (bdrv_drain_one(bs)) {
+ /* Keep iterating */
+ }
+}
+
/*
* Wait for pending requests to complete across all BlockDriverStates
*
@@ -1927,16 +1955,10 @@ void bdrv_drain_all(void)
QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
AioContext *aio_context = bdrv_get_aio_context(bs);
- bool bs_busy;
aio_context_acquire(aio_context);
- bdrv_flush_io_queue(bs);
- bdrv_start_throttled_reqs(bs);
- bs_busy = bdrv_requests_pending(bs);
- bs_busy |= aio_poll(aio_context, bs_busy);
+ busy |= bdrv_drain_one(bs);
aio_context_release(aio_context);
-
- busy |= bs_busy;
}
}
}
diff --git a/include/block/block.h b/include/block/block.h
index 5d13282..13e4537 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -334,6 +334,7 @@ int bdrv_flush(BlockDriverState *bs);
int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
int bdrv_flush_all(void);
void bdrv_close_all(void);
+void bdrv_drain(BlockDriverState *bs);
void bdrv_drain_all(void);
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
--
1.9.3
next prev parent reply other threads:[~2014-11-03 11:53 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-03 11:50 [Qemu-devel] [PULL 00/53] Block patches Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 01/53] util: introduce MIN_NON_ZERO Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 02/53] BlockLimits: introduce max_transfer_length Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 03/53] block/iscsi: set max_transfer_length Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 04/53] block: avoid creating oversized writes in multiwrite_merge Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 05/53] block/iscsi: use sector_limits_lun2qemu throughout iscsi_refresh_limits Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 06/53] block/iscsi: check for oversized requests Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 07/53] ahci: Correct PIO/D2H FIS responses Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 08/53] ahci: Update byte count after DMA completion Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 09/53] ahci: Fix SDB FIS Construction Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 10/53] snapshot: Reset err to NULL to avoid double free Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 11/53] iotests: replace fake parallels image with authentic one Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 12/53] iotests: add v2 parallels sample image and simple test for it Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 13/53] block/parallels: fix access to not initialized memory in catalog_bitmap Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 14/53] rbd: Add support for bdrv_invalidate_cache Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 15/53] block.c: Fix type of IoOperationType variable in send_qmp_error_event() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 16/53] snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid concurrency problem Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 17/53] block/curl: Improve type safety of s->timeout Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 18/53] raw-posix: Fix raw_co_get_block_status() after EOF Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 19/53] raw-posix: raw_co_get_block_status() return value Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 20/53] iotests: Add test for external image truncation Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 21/53] qcow2: Allow "full" discard Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 22/53] qcow2: Implement bdrv_make_empty() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 23/53] qcow2: Optimize bdrv_make_empty() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 24/53] blockjob: Introduce block_job_complete_sync() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 25/53] blockjob: Add "ready" field Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 26/53] iotests: Omit length/offset test in 040 and 041 Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 27/53] block/mirror: Improve progress report Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 28/53] qemu-img: Implement commit like QMP Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 29/53] qemu-img: Empty image after commit Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 30/53] qemu-img: Enable progress output for commit Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 31/53] qemu-img: Specify backing file " Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 32/53] iotests: Add _filter_qemu_img_map Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 33/53] iotests: Add test for backing-chain commits Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 34/53] iotests: Add test for qcow2's bdrv_make_empty Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 35/53] block: qemu-iotest 107 supports NFS Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 36/53] block: Add status callback to bdrv_amend_options() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 37/53] qemu-img: Add progress output for amend Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 38/53] qemu-img: Fix insignificant memleak Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 39/53] block/qcow2: Implement status CB for amend Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 40/53] block/qcow2: Make get_refcount() global Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 41/53] block/qcow2: Simplify shared L2 handling in amend Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 42/53] iotests: Expand test 061 Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 43/53] block: acquire AioContext in generic blockjob QMP commands Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 44/53] blockdev: acquire AioContext in do_qmp_query_block_jobs_one() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 45/53] blockdev: acquire AioContext in blockdev_mark_auto_del() Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 46/53] blockdev: add note that block_job_cb() must be thread-safe Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 47/53] blockjob: add block_job_defer_to_main_loop() Stefan Hajnoczi
2014-11-03 11:50 ` Stefan Hajnoczi [this message]
2014-11-03 11:50 ` [Qemu-devel] [PULL 49/53] block: let backup blockjob run in BDS AioContext Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 50/53] block: let stream " Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 51/53] block: let mirror " Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 52/53] block: let commit " Stefan Hajnoczi
2014-11-03 11:50 ` [Qemu-devel] [PULL 53/53] block: declare blockjobs and dataplane friends! Stefan Hajnoczi
2014-11-03 20:22 ` [Qemu-devel] [PULL 00/53] Block patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415015456-25086-49-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).