[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 08/37] qcow2: Handle full/falloc preallocation in
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v4 08/37] qcow2: Handle full/falloc preallocation in qcow2_co_create() |
Date: |
Wed, 7 Mar 2018 19:59:17 +0100 |
Once qcow2_co_create() can be called directly on an already existing
node, we must provide the 'full' and 'falloc' preallocation modes
outside of creating the image on the protocol layer. Fortunately, we
have preallocated truncate now which can provide this functionality.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/qcow2.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index e1821eb3c8..933c612754 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2908,6 +2908,25 @@ qcow2_co_create(BlockdevCreateOptions *create_options,
Error **errp)
}
blk_set_allow_write_beyond_eof(blk, true);
+ /* Clear the protocol layer and preallocate it if necessary */
+ ret = blk_truncate(blk, 0, PREALLOC_MODE_OFF, errp);
+ if (ret < 0) {
+ 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);
@@ -3145,15 +3164,6 @@ static int coroutine_fn qcow2_co_create_opts(const char
*filename, QemuOpts *opt
/* Create and open the file (protocol layer) */
- if (prealloc == PREALLOC_MODE_FULL || prealloc == PREALLOC_MODE_FALLOC) {
- int refcount_order = ctz32(refcount_bits);
- int64_t prealloc_size =
- qcow2_calc_prealloc_size(size, cluster_size, refcount_order);
- qemu_opt_set_number(opts, BLOCK_OPT_SIZE, prealloc_size, &error_abort);
- qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_str(prealloc),
- &error_abort);
- }
-
ret = bdrv_create_file(filename, opts, errp);
if (ret < 0) {
goto finish;
--
2.13.6
- [Qemu-devel] [PATCH v4 00/37] x-blockdev-create for protocols and qcow2, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 04/37] qcow2: Let qcow2_create() handle protocol layer, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 07/37] qcow2: Use QCryptoBlockCreateOptions in qcow2_co_create(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 03/37] qcow2: Rename qcow2_co_create2() to qcow2_co_create(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 01/37] block/qapi: Introduce BlockdevCreateOptions, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 09/37] util: Add qemu_opts_to_qdict_filtered(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 05/37] qcow2: Pass BlockdevCreateOptions to qcow2_co_create(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 02/37] block/qapi: Add qcow2 create options to schema, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 08/37] qcow2: Handle full/falloc preallocation in qcow2_co_create(),
Kevin Wolf <=
- [Qemu-devel] [PATCH v4 06/37] qcow2: Use BlockdevRef in qcow2_co_create(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 11/37] test-qemu-opts: Test qemu_opts_to_qdict_filtered(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 12/37] qdict: Introduce qdict_rename_keys(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 10/37] test-qemu-opts: Test qemu_opts_append(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 14/37] block: Make bdrv_is_whitelisted() public, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 13/37] qcow2: Use visitor for options in qcow2_create(), Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 16/37] file-posix: Support .bdrv_co_create, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 15/37] block: x-blockdev-create QMP command, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 18/37] gluster: Support .bdrv_co_create, Kevin Wolf, 2018/03/07
- [Qemu-devel] [PATCH v4 17/37] file-win32: Support .bdrv_co_create, Kevin Wolf, 2018/03/07