[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 14/23] qcow2: Leave s unchanged on qcow2_update_optio
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 14/23] qcow2: Leave s unchanged on qcow2_update_options() failure |
Date: |
Fri, 11 Sep 2015 21:40:54 +0200 |
On return, either all new options should be applied to BDRVQcowState (on
success), or all of the old settings should be preserved (on failure).
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/qcow2.c | 57 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 35 insertions(+), 22 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index cf6992e..c61d996 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -597,7 +597,10 @@ static int qcow2_update_options(BlockDriverState *bs,
QDict *options,
const char *opt_overlap_check, *opt_overlap_check_template;
int overlap_check_template = 0;
uint64_t l2_cache_size, refcount_cache_size;
+ Qcow2Cache *l2_table_cache;
+ Qcow2Cache *refcount_block_cache;
uint64_t cache_clean_interval;
+ bool use_lazy_refcounts;
int i;
Error *local_err = NULL;
int ret;
@@ -640,9 +643,9 @@ static int qcow2_update_options(BlockDriverState *bs, QDict
*options,
}
/* alloc L2 table/refcount block cache */
- s->l2_table_cache = qcow2_cache_create(bs, l2_cache_size);
- s->refcount_block_cache = qcow2_cache_create(bs, refcount_cache_size);
- if (s->l2_table_cache == NULL || s->refcount_block_cache == NULL) {
+ l2_table_cache = qcow2_cache_create(bs, l2_cache_size);
+ refcount_block_cache = qcow2_cache_create(bs, refcount_cache_size);
+ if (l2_table_cache == NULL || refcount_block_cache == NULL) {
error_setg(errp, "Could not allocate metadata caches");
ret = -ENOMEM;
goto fail;
@@ -656,23 +659,18 @@ static int qcow2_update_options(BlockDriverState *bs,
QDict *options,
ret = -EINVAL;
goto fail;
}
- s->cache_clean_interval = cache_clean_interval;
- cache_clean_timer_init(bs, bdrv_get_aio_context(bs));
/* Enable lazy_refcounts according to image and command line options */
- s->use_lazy_refcounts = qemu_opt_get_bool(opts, QCOW2_OPT_LAZY_REFCOUNTS,
+ use_lazy_refcounts = qemu_opt_get_bool(opts, QCOW2_OPT_LAZY_REFCOUNTS,
(s->compatible_features & QCOW2_COMPAT_LAZY_REFCOUNTS));
+ if (use_lazy_refcounts && s->qcow_version < 3) {
+ error_setg(errp, "Lazy refcounts require a qcow2 image with at least "
+ "qemu 1.1 compatibility level");
+ ret = -EINVAL;
+ goto fail;
+ }
- s->discard_passthrough[QCOW2_DISCARD_NEVER] = false;
- s->discard_passthrough[QCOW2_DISCARD_ALWAYS] = true;
- s->discard_passthrough[QCOW2_DISCARD_REQUEST] =
- qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_REQUEST,
- flags & BDRV_O_UNMAP);
- s->discard_passthrough[QCOW2_DISCARD_SNAPSHOT] =
- qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_SNAPSHOT, true);
- s->discard_passthrough[QCOW2_DISCARD_OTHER] =
- qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false);
-
+ /* Overlap check options */
opt_overlap_check = qemu_opt_get(opts, QCOW2_OPT_OVERLAP);
opt_overlap_check_template = qemu_opt_get(opts,
QCOW2_OPT_OVERLAP_TEMPLATE);
if (opt_overlap_check_template && opt_overlap_check &&
@@ -704,6 +702,10 @@ static int qcow2_update_options(BlockDriverState *bs,
QDict *options,
goto fail;
}
+ /*
+ * Start updating fields in BDRVQcow2State.
+ * After this point no failure is allowed any more.
+ */
s->overlap_check = 0;
for (i = 0; i < QCOW2_OL_MAX_BITNR; i++) {
/* overlap-check defines a template bitmask, but every flag may be
@@ -713,12 +715,23 @@ static int qcow2_update_options(BlockDriverState *bs,
QDict *options,
overlap_check_template & (1 << i)) << i;
}
- if (s->use_lazy_refcounts && s->qcow_version < 3) {
- error_setg(errp, "Lazy refcounts require a qcow2 image with at least "
- "qemu 1.1 compatibility level");
- ret = -EINVAL;
- goto fail;
- }
+ s->l2_table_cache = l2_table_cache;
+ s->refcount_block_cache = refcount_block_cache;
+
+ s->use_lazy_refcounts = use_lazy_refcounts;
+
+ s->discard_passthrough[QCOW2_DISCARD_NEVER] = false;
+ s->discard_passthrough[QCOW2_DISCARD_ALWAYS] = true;
+ s->discard_passthrough[QCOW2_DISCARD_REQUEST] =
+ qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_REQUEST,
+ flags & BDRV_O_UNMAP);
+ s->discard_passthrough[QCOW2_DISCARD_SNAPSHOT] =
+ qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_SNAPSHOT, true);
+ s->discard_passthrough[QCOW2_DISCARD_OTHER] =
+ qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false);
+
+ s->cache_clean_interval = cache_clean_interval;
+ cache_clean_timer_init(bs, bdrv_get_aio_context(bs));
ret = 0;
fail:
--
1.8.3.1
- [Qemu-block] [PULL 04/23] block: Drop drv parameter from bdrv_fill_options(), (continued)
- [Qemu-block] [PULL 04/23] block: Drop drv parameter from bdrv_fill_options(), Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 08/23] qemu-io: Remove duplicate 'open' error message, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 07/23] block: Allow specifying driver-specific options to reopen, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 09/23] qemu-io: Add command 'reopen', Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 10/23] qcow2: Improve error message, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 06/23] qcow2: Rename BDRVQcowState to BDRVQcow2State, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 11/23] qcow2: Factor out qcow2_update_options(), Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 12/23] qcow2: Move qcow2_update_options() call up, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 13/23] qcow2: Move rest of option handling to qcow2_update_options(), Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 15/23] qcow2: Fix memory leak in qcow2_update_options() error path, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 14/23] qcow2: Leave s unchanged on qcow2_update_options() failure,
Kevin Wolf <=
- [Qemu-block] [PULL 23/23] qcow2: Make qcow2_alloc_bytes() more explicit, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 21/23] iotests: Add test for checking large image files, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 22/23] vmdk: Fix next_cluster_sector for compressed write, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 16/23] qcow2: Make qcow2_update_options() suitable for transactions, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 18/23] qemu-iotests: Reopen qcow2 with lazy-refcounts change, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 17/23] qcow2: Support updating driver-specific options in reopen, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 20/23] qcow2: Make size_to_clusters() return uint64_t, Kevin Wolf, 2015/09/11
- [Qemu-block] [PULL 19/23] qemu-iotests: More qcow2 reopen tests, Kevin Wolf, 2015/09/11
- Re: [Qemu-block] [Qemu-devel] [PULL 00/23] Block layer patches, Peter Maydell, 2015/09/14