From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0V7v-0002NU-MF for qemu-devel@nongnu.org; Mon, 15 Dec 2014 07:51:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0V7p-0007yU-9d for qemu-devel@nongnu.org; Mon, 15 Dec 2014 07:51:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47088) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0V7o-0007y4-VF for qemu-devel@nongnu.org; Mon, 15 Dec 2014 07:51:45 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBFCphiS015637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 15 Dec 2014 07:51:44 -0500 From: Max Reitz Date: Mon, 15 Dec 2014 13:50:52 +0100 Message-Id: <1418647857-3589-22-git-send-email-mreitz@redhat.com> In-Reply-To: <1418647857-3589-1-git-send-email-mreitz@redhat.com> References: <1418647857-3589-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v5 21/26] qcow2: Split upgrade/downgrade paths for amend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz 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 --- block/qcow2.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 258e0df..6f9e4c8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2737,20 +2737,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; } } @@ -2764,7 +2757,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; @@ -2800,6 +2793,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; } -- 1.9.3