From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com,
qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com,
den@openvz.org
Subject: [PATCH 1/9] block/io: refactor bdrv_is_allocated_above to run only one coroutine
Date: Wed, 8 Apr 2020 12:30:43 +0300 [thread overview]
Message-ID: <20200408093051.9893-2-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20200408093051.9893-1-vsementsov@virtuozzo.com>
bdrv_is_allocated_above creates new coroutine on each iteration if
called from non-coroutine context. To simplify expansion of in_flight
inc/dec sections in further patch let's refactor it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/io.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 72 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index aba67f66b9..a9f1a3e93e 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2482,6 +2482,22 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
return ret;
}
+static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs,
+ int64_t offset, int64_t bytes,
+ int64_t *pnum)
+{
+ int ret;
+ int64_t dummy;
+
+ ret = bdrv_co_block_status_above(bs, backing_bs(bs), false, offset,
+ bytes, pnum ? pnum : &dummy, NULL,
+ NULL);
+ if (ret < 0) {
+ return ret;
+ }
+ return !!(ret & BDRV_BLOCK_ALLOCATED);
+}
+
/* Coroutine wrapper for bdrv_block_status_above() */
static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
{
@@ -2578,10 +2594,10 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,
* but 'pnum' will only be 0 when end of file is reached.
*
*/
-int bdrv_is_allocated_above(BlockDriverState *top,
- BlockDriverState *base,
- bool include_base, int64_t offset,
- int64_t bytes, int64_t *pnum)
+static int coroutine_fn
+bdrv_co_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
+ bool include_base, int64_t offset, int64_t bytes,
+ int64_t *pnum)
{
BlockDriverState *intermediate;
int ret;
@@ -2595,7 +2611,7 @@ int bdrv_is_allocated_above(BlockDriverState *top,
int64_t size_inter;
assert(intermediate);
- ret = bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter);
+ ret = bdrv_co_is_allocated(intermediate, offset, bytes, &pnum_inter);
if (ret < 0) {
return ret;
}
@@ -2624,6 +2640,57 @@ int bdrv_is_allocated_above(BlockDriverState *top,
return 0;
}
+typedef struct BdrvCoIsAllocatedAboveData {
+ BlockDriverState *top;
+ BlockDriverState *base;
+ bool include_base;
+ int64_t offset;
+ int64_t bytes;
+ int64_t *pnum;
+ int ret;
+ bool done;
+} BdrvCoIsAllocatedAboveData;
+
+static void coroutine_fn bdrv_is_allocated_above_co_entry(void *opaque)
+{
+ BdrvCoIsAllocatedAboveData *data = opaque;
+
+ data->ret = bdrv_co_is_allocated_above(data->top, data->base,
+ data->include_base,
+ data->offset, data->bytes,
+ data->pnum);
+ data->done = true;
+ aio_wait_kick();
+}
+
+int coroutine_fn
+bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
+ bool include_base, int64_t offset, int64_t bytes,
+ int64_t *pnum)
+{
+ Coroutine *co;
+ BdrvCoIsAllocatedAboveData data = {
+ .top = top,
+ .base = base,
+ .include_base = include_base,
+ .offset = offset,
+ .bytes = bytes,
+ .pnum = pnum,
+ .done = false,
+ };
+
+ if (qemu_in_coroutine()) {
+ /* Fast-path if already in coroutine context */
+ bdrv_is_allocated_above_co_entry(&data);
+ } else {
+ co = qemu_coroutine_create(bdrv_is_allocated_above_co_entry, &data);
+ bdrv_coroutine_enter(top, co);
+ BDRV_POLL_WHILE(top, !data.done);
+ }
+
+ return data.ret;
+}
+
typedef struct BdrvVmstateCo {
BlockDriverState *bs;
QEMUIOVector *qiov;
--
2.21.0
next prev parent reply other threads:[~2020-04-08 9:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-08 9:30 [PATCH for-5.0? 0/9] block/io: safer inc/dec in_flight sections Vladimir Sementsov-Ogievskiy
2020-04-08 9:30 ` Vladimir Sementsov-Ogievskiy [this message]
2020-04-20 15:56 ` [PATCH 1/9] block/io: refactor bdrv_is_allocated_above to run only one coroutine Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 2/9] block/io: refactor bdrv_co_ioctl: move aio stuff to corresponding block Vladimir Sementsov-Ogievskiy
2020-04-20 15:57 ` Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 3/9] block/io: move flush and pdiscard stuff down Vladimir Sementsov-Ogievskiy
2020-04-20 16:01 ` Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 4/9] block/io: move bdrv_rw_co_entry and friends down Vladimir Sementsov-Ogievskiy
2020-04-20 16:04 ` Stefan Hajnoczi
2020-04-27 14:11 ` Vladimir Sementsov-Ogievskiy
2020-04-08 9:30 ` [PATCH 5/9] block/io: expand in_flight inc/dec section: simple cases Vladimir Sementsov-Ogievskiy
2020-04-20 16:22 ` Stefan Hajnoczi
2020-04-22 13:47 ` Vladimir Sementsov-Ogievskiy
2020-04-22 16:06 ` Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 6/9] block/io: expand in_flight inc/dec section: block-status Vladimir Sementsov-Ogievskiy
2020-04-20 16:44 ` Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 7/9] block/io: add bdrv_do_pwrite_zeroes Vladimir Sementsov-Ogievskiy
2020-04-20 16:38 ` Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 8/9] block/io: move bdrv_make_zero under block-status Vladimir Sementsov-Ogievskiy
2020-04-20 16:40 ` Stefan Hajnoczi
2020-04-08 9:30 ` [PATCH 9/9] block/io: expand in_flight inc/dec section: bdrv_make_zero Vladimir Sementsov-Ogievskiy
2020-04-20 16:43 ` Stefan Hajnoczi
2020-04-08 10:15 ` [PATCH for-5.0? 0/9] block/io: safer inc/dec in_flight sections no-reply
2020-04-08 10:22 ` no-reply
2020-04-08 10:25 ` no-reply
2020-04-09 17:00 ` Stefan Hajnoczi
2020-04-09 18:49 ` Vladimir Sementsov-Ogievskiy
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=20200408093051.9893-2-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=den@openvz.org \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).