[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 for-2.10 09/16] block/qcow2: Generalize preal

From: Philippe Mathieu-Daudé
Subject: Re: [Qemu-devel] [PATCH v2 for-2.10 09/16] block/qcow2: Generalize preallocate()
Date: Mon, 3 Apr 2017 16:19:39 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Hi Max,

On 04/03/2017 01:09 PM, Max Reitz wrote:
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 <address@hidden>
 block/qcow2.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 9fd220ec34..163d51ec65 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2034,17 +2034,23 @@ static int qcow2_change_backing_file(BlockDriverState 
     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, int64_t offset, int64_t 
     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;

why use `int64_t`? is it ok to have a negative offset?
preallocate a negative length sound weird... even `bytes` is unsigned.

+    assert(offset <= new_length);
+    bytes = new_length - offset;

     while (bytes) {
         cur_bytes = MIN(bytes, INT_MAX);
@@ -2314,7 +2320,7 @@ static int qcow2_create2(const char *filename, int64_t 
     if (prealloc != PREALLOC_MODE_OFF) {
         BDRVQcow2State *s = blk_bs(blk)->opaque;
-        ret = preallocate(blk_bs(blk));
+        ret = preallocate(blk_bs(blk), 0, total_size);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not preallocate metadata");

reply via email to

[Prev in Thread] Current Thread [Next in Thread]