[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/20] qcow2: Simplify preallocation code
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 02/20] qcow2: Simplify preallocation code |
Date: |
Wed, 27 Feb 2019 18:22:38 +0100 |
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 <address@hidden>
---
block/qcow2.c | 28 +---------------------------
1 file changed, 1 insertion(+), 27 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 1de5e24613..e38041e817 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2940,19 +2940,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);
@@ -3034,7 +3021,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;
@@ -3066,19 +3053,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;
--
2.20.1
- [Qemu-devel] [PATCH 00/20] qcow2: External data files, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 01/20] qemu-iotests: Test qcow2 preallocation modes, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 03/20] qcow2: Extend spec for external data files, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 05/20] qcow2: Pass bs to qcow2_get_cluster_type(), Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 06/20] qcow2: Prepare qcow2_get_cluster_type() for external data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 18/20] qemu-iotests: Preallocation with external data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 14/20] qcow2: Add basic data-file infrastructure, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 09/20] qcow2: Return 0/-errno in qcow2_alloc_compressed_cluster_offset(), Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 02/20] qcow2: Simplify preallocation code,
Kevin Wolf <=
- [Qemu-devel] [PATCH 13/20] qcow2: Support external data file in qemu-img check, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 07/20] qcow2: Prepare count_contiguous_clusters() for external data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 10/20] qcow2: Prepare qcow2_co_block_status() for data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 08/20] qcow2: Don't assume 0 is an invalid cluster offset, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 20/20] qemu-iotests: amend with external data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 15/20] qcow2: Creating images with external data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 04/20] qcow2: Basic definitions for external data files, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 12/20] qcow2: Return error for snapshot operation with data file, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 16/20] qcow2: Store data file name in the image, Kevin Wolf, 2019/02/27
- [Qemu-devel] [PATCH 19/20] qemu-iotests: General tests for qcow2 with external data file, Kevin Wolf, 2019/02/27