aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2019-02-21 15:48:11 +0100
committerKevin Wolf <kwolf@redhat.com>2019-03-08 12:26:45 +0100
commitc5e86ebc113407dce87b813d68ff3abe9496f422 (patch)
treeb6c4656f7913c4be79f7b3a8259b92dbee635813 /block
parent97f94cb4f842ff43e21e990e59a3ca01708e76d0 (diff)
qcow2: Simplify preallocation code
Image creation already involves a bdrv_co_truncate() call, which allows to specify a preallocation mode. Just pass the right mode there and remove the code that is made redundant by this. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2.c28
1 files changed, 1 insertions, 27 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index 48d22f48d5..9489d795e5 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2952,19 +2952,6 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
goto out;
}
- if (qcow2_opts->preallocation == PREALLOC_MODE_FULL ||
- qcow2_opts->preallocation == PREALLOC_MODE_FALLOC)
- {
- int64_t prealloc_size =
- qcow2_calc_prealloc_size(qcow2_opts->size, cluster_size,
- refcount_order);
-
- ret = blk_truncate(blk, prealloc_size, qcow2_opts->preallocation, errp);
- if (ret < 0) {
- goto out;
- }
- }
-
/* Write the header */
QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
header = g_malloc0(cluster_size);
@@ -3046,7 +3033,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
/* Okay, now that we have a valid image, let's give it the right size */
- ret = blk_truncate(blk, qcow2_opts->size, PREALLOC_MODE_OFF, errp);
+ ret = blk_truncate(blk, qcow2_opts->size, qcow2_opts->preallocation, errp);
if (ret < 0) {
error_prepend(errp, "Could not resize image: ");
goto out;
@@ -3078,19 +3065,6 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
}
- /* And if we're supposed to preallocate metadata, do that now */
- if (qcow2_opts->preallocation != PREALLOC_MODE_OFF) {
- BDRVQcow2State *s = blk_bs(blk)->opaque;
- qemu_co_mutex_lock(&s->lock);
- ret = preallocate_co(blk_bs(blk), 0, qcow2_opts->size);
- qemu_co_mutex_unlock(&s->lock);
-
- if (ret < 0) {
- error_setg_errno(errp, -ret, "Could not preallocate metadata");
- goto out;
- }
- }
-
blk_unref(blk);
blk = NULL;