From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJlNs-0003Uh-Bi for qemu-devel@nongnu.org; Mon, 27 Jul 2015 12:36:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJlNn-0004N9-Nw for qemu-devel@nongnu.org; Mon, 27 Jul 2015 12:36:11 -0400 From: Max Reitz Date: Mon, 27 Jul 2015 17:51:35 +0200 Message-Id: <1438012300-25164-6-git-send-email-mreitz@redhat.com> In-Reply-To: <1438012300-25164-1-git-send-email-mreitz@redhat.com> References: <1438012300-25164-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v9 05/10] qcow2: Split upgrade/downgrade paths for amend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz , Stefan Hajnoczi 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 Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia --- block/qcow2.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index a7f50db..fe91974 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2759,20 +2759,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; } } @@ -2787,7 +2780,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; @@ -2823,6 +2816,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.6