[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 12/33] qcow2: Simplify preallocation code
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 12/33] qcow2: Simplify preallocation code |
Date: |
Fri, 8 Mar 2019 13:58:02 +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 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;
--
2.20.1
- [Qemu-block] [PULL 02/33] qcow2: Default to 4KB for the qcow2 cache entry size, (continued)
- [Qemu-block] [PULL 02/33] qcow2: Default to 4KB for the qcow2 cache entry size, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 03/33] iotests: open notrun files in text mode, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 05/33] iotests: ask QEMU for supported formats, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 04/33] block: iterate_format with account of whitelisting, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 07/33] tests/multiboot: Improve portability by searching bash in the $PATH, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 06/33] iotests: check whitelisted formats, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 13/33] qcow2: Extend spec for external data files, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 08/33] tests/bios-tables: Improve portability by searching bash in the $PATH, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 11/33] qemu-iotests: Test qcow2 preallocation modes, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 10/33] qemu-iotests: Ensure GNU sed is used, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 12/33] qcow2: Simplify preallocation code,
Kevin Wolf <=
- [Qemu-block] [PULL 09/33] qemu-iotests: Improve portability by searching bash in the $PATH, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 14/33] qcow2: Basic definitions for external data files, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 18/33] qcow2: Don't assume 0 is an invalid cluster offset, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 17/33] qcow2: Prepare count_contiguous_clusters() for external data file, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 19/33] qcow2: Return 0/-errno in qcow2_alloc_compressed_cluster_offset(), Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 20/33] qcow2: Prepare qcow2_co_block_status() for data file, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 21/33] qcow2: External file I/O, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 15/33] qcow2: Pass bs to qcow2_get_cluster_type(), Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 16/33] qcow2: Prepare qcow2_get_cluster_type() for external data file, Kevin Wolf, 2019/03/08
- [Qemu-block] [PULL 24/33] qcow2: Add basic data-file infrastructure, Kevin Wolf, 2019/03/08