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>
This commit is contained in:
parent
97f94cb4f8
commit
c5e86ebc11
@ -2952,19 +2952,6 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
|
|||||||
goto out;
|
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 */
|
/* Write the header */
|
||||||
QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
|
QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
|
||||||
header = g_malloc0(cluster_size);
|
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 */
|
/* 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) {
|
if (ret < 0) {
|
||||||
error_prepend(errp, "Could not resize image: ");
|
error_prepend(errp, "Could not resize image: ");
|
||||||
goto out;
|
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_unref(blk);
|
||||||
blk = NULL;
|
blk = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user