From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: stefanha@redhat.com, fam@euphon.net, kwolf@redhat.com,
mreitz@redhat.com, jsnow@redhat.com, berto@igalia.com,
den@openvz.org, vsementsov@virtuozzo.com,
andrey.shinkevich@virtuozzo.com
Subject: [Qemu-devel] [PATCH v3 1/3] block: include base when checking image chain for block allocation
Date: Fri, 5 Apr 2019 19:56:17 +0300 [thread overview]
Message-ID: <1554483379-682051-2-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1554483379-682051-1-git-send-email-andrey.shinkevich@virtuozzo.com>
This patch is used in the 'block/stream: introduce a bottom node'
that is following. Instead of the base node, the caller may pass
the node that has the base as its backing image to the new function
bdrv_is_allocated_above_inclusive() and get rid of the dependency
on the base that may change during commit/stream parallel jobs.
Now, if the specified base is not found in the backing image chain,
the QEMU will crash.
Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/io.c | 33 ++++++++++++++++++++++++++++-----
include/block/block.h | 4 ++++
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index dfc153b..7e6019f 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2317,7 +2317,8 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,
* Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP]
*
* Return true if (a prefix of) the given range is allocated in any image
- * between BASE and TOP (inclusive). BASE can be NULL to check if the given
+ * between BASE and TOP (TOP included). To check the BASE image, set the
+ * 'base_included' to 'true'. The BASE can be NULL to check if the given
* offset is allocated in any image of the chain. Return false otherwise,
* or negative errno on failure.
*
@@ -2329,16 +2330,19 @@ 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,
- int64_t offset, int64_t bytes, int64_t *pnum)
+static int bdrv_do_is_allocated_above(BlockDriverState *top,
+ BlockDriverState *base,
+ bool base_included, int64_t offset,
+ int64_t bytes, int64_t *pnum)
{
BlockDriverState *intermediate;
int ret;
int64_t n = bytes;
+ assert(base || !base_included);
+
intermediate = top;
- while (intermediate && intermediate != base) {
+ while (base_included || intermediate != base) {
int64_t pnum_inter;
int64_t size_inter;
@@ -2360,6 +2364,10 @@ int bdrv_is_allocated_above(BlockDriverState *top,
n = pnum_inter;
}
+ if (intermediate == base) {
+ break;
+ }
+
intermediate = backing_bs(intermediate);
}
@@ -2367,6 +2375,21 @@ int bdrv_is_allocated_above(BlockDriverState *top,
return 0;
}
+int bdrv_is_allocated_above(BlockDriverState *top,
+ BlockDriverState *base,
+ int64_t offset, int64_t bytes, int64_t *pnum)
+{
+ return bdrv_do_is_allocated_above(top, base, false, offset, bytes, pnum);
+}
+
+int bdrv_is_allocated_above_inclusive(BlockDriverState *top,
+ BlockDriverState *base,
+ int64_t offset, int64_t bytes,
+ int64_t *pnum)
+{
+ return bdrv_do_is_allocated_above(top, base, true, offset, bytes, pnum);
+}
+
typedef struct BdrvVmstateCo {
BlockDriverState *bs;
QEMUIOVector *qiov;
diff --git a/include/block/block.h b/include/block/block.h
index c7a2619..be1e9a0 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -449,6 +449,10 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes,
int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
int64_t offset, int64_t bytes, int64_t *pnum);
+int bdrv_is_allocated_above_inclusive(BlockDriverState *top,
+ BlockDriverState *base,
+ int64_t offset, int64_t bytes,
+ int64_t *pnum);
bool bdrv_is_read_only(BlockDriverState *bs);
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
bool ignore_allow_rdw, Error **errp);
--
1.8.3.1
WARNING: multiple messages have this Message-ID (diff)
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com,
berto@igalia.com, mreitz@redhat.com, stefanha@redhat.com,
andrey.shinkevich@virtuozzo.com, den@openvz.org,
jsnow@redhat.com
Subject: [Qemu-devel] [PATCH v3 1/3] block: include base when checking image chain for block allocation
Date: Fri, 5 Apr 2019 19:56:17 +0300 [thread overview]
Message-ID: <1554483379-682051-2-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
Message-ID: <20190405165617._gFzWWFb2hjRDYTNRFK6tzw6gLWd7zZF2lxzOW0K72o@z> (raw)
In-Reply-To: <1554483379-682051-1-git-send-email-andrey.shinkevich@virtuozzo.com>
This patch is used in the 'block/stream: introduce a bottom node'
that is following. Instead of the base node, the caller may pass
the node that has the base as its backing image to the new function
bdrv_is_allocated_above_inclusive() and get rid of the dependency
on the base that may change during commit/stream parallel jobs.
Now, if the specified base is not found in the backing image chain,
the QEMU will crash.
Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/io.c | 33 ++++++++++++++++++++++++++++-----
include/block/block.h | 4 ++++
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index dfc153b..7e6019f 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2317,7 +2317,8 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset,
* Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP]
*
* Return true if (a prefix of) the given range is allocated in any image
- * between BASE and TOP (inclusive). BASE can be NULL to check if the given
+ * between BASE and TOP (TOP included). To check the BASE image, set the
+ * 'base_included' to 'true'. The BASE can be NULL to check if the given
* offset is allocated in any image of the chain. Return false otherwise,
* or negative errno on failure.
*
@@ -2329,16 +2330,19 @@ 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,
- int64_t offset, int64_t bytes, int64_t *pnum)
+static int bdrv_do_is_allocated_above(BlockDriverState *top,
+ BlockDriverState *base,
+ bool base_included, int64_t offset,
+ int64_t bytes, int64_t *pnum)
{
BlockDriverState *intermediate;
int ret;
int64_t n = bytes;
+ assert(base || !base_included);
+
intermediate = top;
- while (intermediate && intermediate != base) {
+ while (base_included || intermediate != base) {
int64_t pnum_inter;
int64_t size_inter;
@@ -2360,6 +2364,10 @@ int bdrv_is_allocated_above(BlockDriverState *top,
n = pnum_inter;
}
+ if (intermediate == base) {
+ break;
+ }
+
intermediate = backing_bs(intermediate);
}
@@ -2367,6 +2375,21 @@ int bdrv_is_allocated_above(BlockDriverState *top,
return 0;
}
+int bdrv_is_allocated_above(BlockDriverState *top,
+ BlockDriverState *base,
+ int64_t offset, int64_t bytes, int64_t *pnum)
+{
+ return bdrv_do_is_allocated_above(top, base, false, offset, bytes, pnum);
+}
+
+int bdrv_is_allocated_above_inclusive(BlockDriverState *top,
+ BlockDriverState *base,
+ int64_t offset, int64_t bytes,
+ int64_t *pnum)
+{
+ return bdrv_do_is_allocated_above(top, base, true, offset, bytes, pnum);
+}
+
typedef struct BdrvVmstateCo {
BlockDriverState *bs;
QEMUIOVector *qiov;
diff --git a/include/block/block.h b/include/block/block.h
index c7a2619..be1e9a0 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -449,6 +449,10 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes,
int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
int64_t offset, int64_t bytes, int64_t *pnum);
+int bdrv_is_allocated_above_inclusive(BlockDriverState *top,
+ BlockDriverState *base,
+ int64_t offset, int64_t bytes,
+ int64_t *pnum);
bool bdrv_is_read_only(BlockDriverState *bs);
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
bool ignore_allow_rdw, Error **errp);
--
1.8.3.1
next prev parent reply other threads:[~2019-04-05 17:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 16:56 [Qemu-devel] [PATCH v3 0/3] block/stream: get rid of the base Andrey Shinkevich
2019-04-05 16:56 ` Andrey Shinkevich
2019-04-05 16:56 ` Andrey Shinkevich [this message]
2019-04-05 16:56 ` [Qemu-devel] [PATCH v3 1/3] block: include base when checking image chain for block allocation Andrey Shinkevich
2019-04-08 15:03 ` Alberto Garcia
2019-04-08 15:03 ` Alberto Garcia
2019-04-08 15:14 ` Vladimir Sementsov-Ogievskiy
2019-04-08 15:14 ` Vladimir Sementsov-Ogievskiy
2019-04-08 15:16 ` Andrey Shinkevich
2019-04-08 15:16 ` Andrey Shinkevich
2019-04-08 15:22 ` Alberto Garcia
2019-04-08 15:22 ` Alberto Garcia
2019-04-08 15:29 ` Andrey Shinkevich
2019-04-08 15:29 ` Andrey Shinkevich
2019-04-05 16:56 ` [Qemu-devel] [PATCH v3 2/3] block/stream: refactor stream_run: drop goto Andrey Shinkevich
2019-04-05 16:56 ` Andrey Shinkevich
2019-04-05 16:56 ` [Qemu-devel] [PATCH v3 3/3] block/stream: introduce a bottom node Andrey Shinkevich
2019-04-05 16:56 ` Andrey Shinkevich
2019-04-08 14:08 ` Vladimir Sementsov-Ogievskiy
2019-04-08 14:08 ` Vladimir Sementsov-Ogievskiy
2019-04-08 15:39 ` Alberto Garcia
2019-04-08 15:39 ` Alberto Garcia
2019-04-08 15:43 ` Andrey Shinkevich
2019-04-08 15:43 ` Andrey Shinkevich
2019-04-08 18:17 ` Andrey Shinkevich
2019-04-08 18:17 ` Andrey Shinkevich
2019-04-09 13:06 ` Alberto Garcia
2019-04-09 13:06 ` Alberto Garcia
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=1554483379-682051-2-git-send-email-andrey.shinkevich@virtuozzo.com \
--to=andrey.shinkevich@virtuozzo.com \
--cc=berto@igalia.com \
--cc=den@openvz.org \
--cc=fam@euphon.net \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.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).