[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v8 05/10] qcow2: Split upgrade/downgrade paths for a
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v8 05/10] qcow2: Split upgrade/downgrade paths for amend |
Date: |
Wed, 3 Jun 2015 22:13:34 +0200 |
If the image version should be upgraded, that is the first we should do;
if it should be downgraded, that is the last we should do. So split the
version change block into an upgrade part at the start and a downgrade
part at the end.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
block/qcow2.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index c444960..a1fa348 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2752,20 +2752,13 @@ static int qcow2_amend_options(BlockDriverState *bs,
QemuOpts *opts,
desc++;
}
- if (new_version != old_version) {
- if (new_version > old_version) {
- /* Upgrade */
- s->qcow_version = new_version;
- ret = qcow2_update_header(bs);
- if (ret < 0) {
- s->qcow_version = old_version;
- return ret;
- }
- } else {
- ret = qcow2_downgrade(bs, new_version, status_cb, cb_opaque);
- if (ret < 0) {
- return ret;
- }
+ /* Upgrade first (some features may require compat=1.1) */
+ if (new_version > old_version) {
+ s->qcow_version = new_version;
+ ret = qcow2_update_header(bs);
+ if (ret < 0) {
+ s->qcow_version = old_version;
+ return ret;
}
}
@@ -2780,7 +2773,7 @@ static int qcow2_amend_options(BlockDriverState *bs,
QemuOpts *opts,
if (s->use_lazy_refcounts != lazy_refcounts) {
if (lazy_refcounts) {
- if (s->qcow_version < 3) {
+ if (new_version < 3) {
error_report("Lazy refcounts only supported with compatibility
"
"level 1.1 and above (use compat=1.1 or
greater)");
return -EINVAL;
@@ -2816,6 +2809,14 @@ static int qcow2_amend_options(BlockDriverState *bs,
QemuOpts *opts,
}
}
+ /* Downgrade last (so unsupported features can be removed before) */
+ if (new_version < old_version) {
+ ret = qcow2_downgrade(bs, new_version, status_cb, cb_opaque);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
return 0;
}
--
2.4.1
- [Qemu-devel] [PATCH v8 00/10] qcow2: Support refcount order amendment, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 01/10] progress: Allow regressing progress, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 04/10] qcow2: Use abort() instead of assert(false), Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 03/10] qcow2: Use error_report() in qcow2_amend_options(), Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 02/10] block: Add opaque value to the amend CB, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 05/10] qcow2: Split upgrade/downgrade paths for amend,
Max Reitz <=
- [Qemu-devel] [PATCH v8 06/10] qcow2: Use intermediate helper CB for amend, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 07/10] qcow2: Add function for refcount order amendment, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 08/10] qcow2: Invoke refcount order amendment function, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 09/10] qcow2: Point to amend function in check, Max Reitz, 2015/06/03
- [Qemu-devel] [PATCH v8 10/10] iotests: Extend test 112 for qemu-img amend, Max Reitz, 2015/06/03