All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hu Tao <hutao@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
	Peter Lieven <pl@kamp.de>,
	hutao@cn.fujitsu.com
Subject: [Qemu-devel] [RFC PATCH v3 6/6] qcow2: Add full image preallocation option
Date: Thu, 19 Dec 2013 10:27:41 +0800	[thread overview]
Message-ID: <4f5c56d2ebd81d5ae3333b4894eb785ab98cf2db.1387419339.git.hutao@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1387419339.git.hutao@cn.fujitsu.com>

This adds a preallocation=full mode to qcow2 image creation, which
creates a non-sparse image file.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 block/qcow2.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 487a595..3c41d4a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1386,7 +1386,7 @@ static int qcow2_change_backing_file(BlockDriverState *bs,
     return qcow2_update_header(bs);
 }
 
-static int preallocate(BlockDriverState *bs)
+static int preallocate(BlockDriverState *bs, enum prealloc_mode mode)
 {
     uint64_t nb_sectors;
     uint64_t offset;
@@ -1395,9 +1395,19 @@ static int preallocate(BlockDriverState *bs)
     int ret;
     QCowL2Meta *meta;
 
+    assert(mode != PREALLOC_OFF);
+
     nb_sectors = bdrv_getlength(bs) >> 9;
     offset = 0;
 
+    if (mode == PREALLOC_FULL) {
+        ret = bdrv_preallocate(bs->file, 0, bdrv_getlength(bs));
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
+    /* allocate metadata */
     while (nb_sectors) {
         num = MIN(nb_sectors, INT_MAX >> 9);
         ret = qcow2_alloc_cluster_offset(bs, offset, 0, num, &num,
@@ -1577,11 +1587,11 @@ static int qcow2_create2(const char *filename, int64_t total_size,
         }
     }
 
-    /* And if we're supposed to preallocate metadata, do that now */
+    /* And if we're supposed to preallocate data, do that now */
     if (prealloc) {
         BDRVQcowState *s = bs->opaque;
         qemu_co_mutex_lock(&s->lock);
-        ret = preallocate(bs);
+        ret = preallocate(bs, prealloc);
         qemu_co_mutex_unlock(&s->lock);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Could not preallocate metadata");
@@ -1638,6 +1648,8 @@ static int qcow2_create(const char *filename, QEMUOptionParameter *options,
                 prealloc = PREALLOC_OFF;
             } else if (!strcmp(options->value.s, "metadata")) {
                 prealloc = PREALLOC_METADATA;
+            } else if (!strcmp(options->value.s, "full")) {
+                prealloc = PREALLOC_FULL;
             } else {
                 error_setg(errp, "Invalid preallocation mode: '%s'",
                            options->value.s);
@@ -2229,7 +2241,7 @@ static QEMUOptionParameter qcow2_create_options[] = {
     {
         .name = BLOCK_OPT_PREALLOC,
         .type = OPT_STRING,
-        .help = "Preallocation mode (allowed values: off, metadata)"
+        .help = "Preallocation mode (allowed values: off, metadata, full)"
     },
     {
         .name = BLOCK_OPT_LAZY_REFCOUNTS,
-- 
1.7.11.7

  parent reply	other threads:[~2013-12-19  2:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-19  2:27 [Qemu-devel] [RFC PATCH v3 0/6] qemu-img: add preallocation=full Hu Tao
2013-12-19  2:27 ` [Qemu-devel] [RFC PATCH v3 1/6] block: introduce prealloc_mode Hu Tao
2013-12-20 10:08   ` Stefan Hajnoczi
2013-12-20 12:36   ` Eric Blake
2013-12-19  2:27 ` [Qemu-devel] [RFC PATCH v3 2/6] block: add BlockDriver.bdrv_preallocate Hu Tao
2013-12-20 10:10   ` Stefan Hajnoczi
2013-12-24  8:31     ` Hu Tao
2013-12-19  2:27 ` [Qemu-devel] [RFC PATCH v3 3/6] block/raw-posix: implement bdrv_preallocate Hu Tao
2013-12-20 10:14   ` Stefan Hajnoczi
2013-12-23  1:45     ` Hu Tao
2013-12-19  2:27 ` [Qemu-devel] [RFC PATCH v3 4/6] raw-posix: Add full image preallocation option Hu Tao
2013-12-19  2:27 ` [Qemu-devel] [RFC PATCH v3 5/6] qcow2: implement bdrv_preallocate Hu Tao
2013-12-20 10:19   ` Stefan Hajnoczi
2013-12-19  2:27 ` Hu Tao [this message]
2013-12-20 10:21   ` [Qemu-devel] [RFC PATCH v3 6/6] qcow2: Add full image preallocation option Stefan Hajnoczi
2013-12-20 10:30 ` [Qemu-devel] [RFC PATCH v3 0/6] qemu-img: add preallocation=full Stefan Hajnoczi
2013-12-20 12:54   ` Eric Blake
2013-12-23  1:59   ` Hu Tao

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=4f5c56d2ebd81d5ae3333b4894eb785ab98cf2db.1387419339.git.hutao@cn.fujitsu.com \
    --to=hutao@cn.fujitsu.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.