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 v2 2/5] block/io: bdrv_common_block_status_above: support include_base
Date: Tue, 19 May 2020 22:54:58 +0300 [thread overview]
Message-ID: <20200519195501.29071-3-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20200519195501.29071-1-vsementsov@virtuozzo.com>
In order to reuse bdrv_common_block_status_above in
bdrv_is_allocated_above, let's support include_base parameter.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
block/io.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index db990e812b..cdc0e6663e 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2223,6 +2223,7 @@ int bdrv_flush_all(void)
typedef struct BdrvCoBlockStatusData {
BlockDriverState *bs;
BlockDriverState *base;
+ bool include_base;
bool want_zero;
int64_t offset;
int64_t bytes;
@@ -2445,6 +2446,7 @@ early_out:
static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
BlockDriverState *base,
+ bool include_base,
bool want_zero,
int64_t offset,
int64_t bytes,
@@ -2456,8 +2458,8 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
int ret = 0;
bool first = true;
- assert(bs != base);
- for (p = bs; p != base; p = backing_bs(p)) {
+ assert(include_base || bs != base);
+ for (p = bs; include_base || p != base; p = backing_bs(p)) {
ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map,
file);
if (ret < 0) {
@@ -2495,6 +2497,11 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
/* [offset, pnum] unallocated on this layer, which could be only
* the first part of [offset, bytes]. */
+
+ if (p == base) {
+ break;
+ }
+
assert(*pnum <= bytes);
bytes = *pnum;
first = false;
@@ -2509,7 +2516,7 @@ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
BdrvCoBlockStatusData *data = opaque;
data->ret = bdrv_co_block_status_above(data->bs, data->base,
- data->want_zero,
+ data->include_base, data->want_zero,
data->offset, data->bytes,
data->pnum, data->map, data->file);
data->done = true;
@@ -2523,6 +2530,7 @@ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
*/
static int bdrv_common_block_status_above(BlockDriverState *bs,
BlockDriverState *base,
+ bool include_base,
bool want_zero, int64_t offset,
int64_t bytes, int64_t *pnum,
int64_t *map,
@@ -2532,6 +2540,7 @@ static int bdrv_common_block_status_above(BlockDriverState *bs,
BdrvCoBlockStatusData data = {
.bs = bs,
.base = base,
+ .include_base = include_base,
.want_zero = want_zero,
.offset = offset,
.bytes = bytes,
@@ -2556,7 +2565,7 @@ int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base,
int64_t offset, int64_t bytes, int64_t *pnum,
int64_t *map, BlockDriverState **file)
{
- return bdrv_common_block_status_above(bs, base, true, offset, bytes,
+ return bdrv_common_block_status_above(bs, base, false, true, offset, bytes,
pnum, map, file);
}
@@ -2573,7 +2582,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,
int ret;
int64_t dummy;
- ret = bdrv_common_block_status_above(bs, backing_bs(bs), false, offset,
+ ret = bdrv_common_block_status_above(bs, bs, true, false, offset,
bytes, pnum ? pnum : &dummy, NULL,
NULL);
if (ret < 0) {
--
2.21.0
next prev parent reply other threads:[~2020-05-19 19:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 19:54 [PATCH v2 0/5] fix & merge block_status_above and is_allocated_above Vladimir Sementsov-Ogievskiy
2020-05-19 19:54 ` [PATCH v2 1/5] block/io: fix bdrv_co_block_status_above Vladimir Sementsov-Ogievskiy
2020-05-19 20:41 ` Eric Blake
2020-05-19 21:13 ` Vladimir Sementsov-Ogievskiy
2020-05-19 21:48 ` Eric Blake
2020-05-20 6:16 ` Vladimir Sementsov-Ogievskiy
2020-05-19 19:54 ` Vladimir Sementsov-Ogievskiy [this message]
2020-05-19 19:54 ` [PATCH v2 3/5] block/io: bdrv_common_block_status_above: support bs == base Vladimir Sementsov-Ogievskiy
2020-05-19 19:55 ` [PATCH v2 4/5] block/io: fix bdrv_is_allocated_above Vladimir Sementsov-Ogievskiy
2020-05-19 20:45 ` Eric Blake
2020-05-19 19:55 ` [PATCH v2 5/5] iotests: add commit top->base cases to 274 Vladimir Sementsov-Ogievskiy
2020-05-19 21:13 ` Eric Blake
2020-05-19 21:25 ` Vladimir Sementsov-Ogievskiy
2020-05-19 21:49 ` Eric Blake
2020-05-19 20:21 ` [PATCH v2 0/5] fix & merge block_status_above and is_allocated_above Eric Blake
2020-05-19 20:28 ` 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=20200519195501.29071-3-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).