All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	sheepdog@lists.wpkg.org, Kevin Wolf <kwolf@redhat.com>,
	Jeff Cody <jcody@redhat.com>,
	Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>,
	Liu Yuan <namei.unix@gmail.com>
Subject: [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc()
Date: Tue, 13 Feb 2018 14:03:55 +0100	[thread overview]
Message-ID: <20180213130356.8885-7-mreitz@redhat.com> (raw)
In-Reply-To: <20180213130356.8885-1-mreitz@redhat.com>

sd_prealloc() will now preallocate the area [old_size, new_size).  As
before, it rounds to buf_size and may thus overshoot and preallocate
areas that were not requested to be preallocated.  For image creation,
this is no change in behavior.  For truncation, this is in accordance
with the documentation for preallocated truncation.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/sheepdog.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index cc1d37b3da..d300fb69c0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1826,14 +1826,14 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot,
     return 0;
 }
 
-static int sd_prealloc(BlockDriverState *bs, Error **errp)
+static int sd_prealloc(BlockDriverState *bs, int64_t old_size, int64_t new_size,
+                       Error **errp)
 {
     BlockBackend *blk = NULL;
     BDRVSheepdogState *base = bs->opaque;
     unsigned long buf_size;
     uint32_t idx, max_idx;
     uint32_t object_size;
-    int64_t vdi_size;
     void *buf = NULL;
     int ret;
 
@@ -1847,19 +1847,13 @@ static int sd_prealloc(BlockDriverState *bs, Error **errp)
 
     blk_set_allow_write_beyond_eof(blk, true);
 
-    vdi_size = blk_getlength(blk);
-    if (vdi_size < 0) {
-        ret = vdi_size;
-        goto out;
-    }
-
     object_size = (UINT32_C(1) << base->inode.block_size_shift);
     buf_size = MIN(object_size, SD_DATA_OBJ_SIZE);
     buf = g_malloc0(buf_size);
 
-    max_idx = DIV_ROUND_UP(vdi_size, buf_size);
+    max_idx = DIV_ROUND_UP(new_size, buf_size);
 
-    for (idx = 0; idx < max_idx; idx++) {
+    for (idx = old_size / buf_size; idx < max_idx; idx++) {
         /*
          * The created image can be a cloned image, so we need to read
          * a data from the source image.
@@ -2119,7 +2113,7 @@ static int sd_create(const char *filename, QemuOpts *opts,
             goto out;
         }
 
-        ret = sd_prealloc(bs, errp);
+        ret = sd_prealloc(bs, 0, s->inode.vdi_size, errp);
 
         bdrv_unref(bs);
     }
-- 
2.14.3

  parent reply	other threads:[~2018-02-13 13:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
2018-02-13 13:03 ` [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up Max Reitz
2018-02-13 14:54   ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create Max Reitz
2018-02-13 14:56   ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate() Max Reitz
2018-02-13 14:57   ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation Max Reitz
2018-02-13 14:58   ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS Max Reitz
2018-02-13 15:02   ` Eric Blake
2018-02-13 13:03 ` Max Reitz [this message]
2018-02-13 15:04   ` [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc() Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation Max Reitz
2018-02-13 15:05   ` Eric Blake
2018-02-13 15:19 ` [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Kevin Wolf

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=20180213130356.8885-7-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mitake.hitoshi@lab.ntt.co.jp \
    --cc=namei.unix@gmail.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sheepdog@lists.wpkg.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.