From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
Eric Blake <eblake@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH v4 09/16] block/qcow2: Generalize preallocate()
Date: Tue, 13 Jun 2017 22:21:00 +0200 [thread overview]
Message-ID: <20170613202107.10125-10-mreitz@redhat.com> (raw)
In-Reply-To: <20170613202107.10125-1-mreitz@redhat.com>
This patch adds two new parameters to the preallocate() function so we
will be able to use it not just for preallocating a new image but also
for preallocated image growth.
The offset parameter allows the caller to specify a virtual offset from
which to start preallocating. For newly created images this is always 0,
but for preallocating growth this will be the old image length.
The new_length parameter specifies the supposed new length of the image
(basically the "end offset" for preallocation). During image truncation,
bdrv_getlength() will return the old image length so we cannot rely on
its return value then.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/qcow2.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 6371c32..7d201bb 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2035,17 +2035,24 @@ static int qcow2_change_backing_file(BlockDriverState *bs,
return qcow2_update_header(bs);
}
-static int preallocate(BlockDriverState *bs)
+/**
+ * Preallocates metadata structures for data clusters between @offset (in the
+ * guest disk) and @new_length (which is thus generally the new guest disk
+ * size).
+ *
+ * Returns: 0 on success, -errno on failure.
+ */
+static int preallocate(BlockDriverState *bs,
+ uint64_t offset, uint64_t new_length)
{
uint64_t bytes;
- uint64_t offset;
uint64_t host_offset = 0;
unsigned int cur_bytes;
int ret;
QCowL2Meta *meta;
- bytes = bdrv_getlength(bs);
- offset = 0;
+ assert(offset <= new_length);
+ bytes = new_length - offset;
while (bytes) {
cur_bytes = MIN(bytes, INT_MAX);
@@ -2384,7 +2391,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
if (prealloc != PREALLOC_MODE_OFF) {
BDRVQcow2State *s = blk_bs(blk)->opaque;
qemu_co_mutex_lock(&s->lock);
- ret = preallocate(blk_bs(blk));
+ ret = preallocate(blk_bs(blk), 0, total_size);
qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not preallocate metadata");
--
2.9.4
next prev parent reply other threads:[~2017-06-13 20:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-13 20:20 [Qemu-devel] [PATCH v4 00/16] block: Preallocated truncate Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 01/16] block: Add PreallocMode to BD.bdrv_truncate() Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 02/16] block: Add PreallocMode to bdrv_truncate() Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 03/16] block: Add PreallocMode to blk_truncate() Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 04/16] qemu-img: Expose PreallocMode for resizing Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 05/16] block/file-posix: Small fixes in raw_create() Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 06/16] block/file-posix: Extract raw_regular_truncate() Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 07/16] block/file-posix: Generalize raw_regular_truncate Max Reitz
2017-06-13 20:20 ` [Qemu-devel] [PATCH v4 08/16] block/file-posix: Preallocation for truncate Max Reitz
2017-06-13 20:21 ` Max Reitz [this message]
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 10/16] block/qcow2: Lock s->lock in preallocate() Max Reitz
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 11/16] block/qcow2: Metadata preallocation for truncate Max Reitz
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 12/16] block/qcow2: Add qcow2_refcount_area() Max Reitz
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 13/16] block/qcow2: Rename "fail_block" to just "fail" Max Reitz
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 14/16] block/qcow2: falloc/full preallocating growth Max Reitz
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 15/16] iotests: Add preallocated resize test for raw Max Reitz
2017-06-13 20:21 ` [Qemu-devel] [PATCH v4 16/16] iotests: Add preallocated growth test for qcow2 Max Reitz
2017-06-19 15:02 ` [Qemu-devel] [PATCH v4 00/16] block: Preallocated truncate Stefan Hajnoczi
2017-07-09 20:16 ` Max Reitz
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=20170613202107.10125-10-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@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).