From patchwork Tue Feb 10 20:29:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 438565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6196A14012E for ; Wed, 11 Feb 2015 07:40:13 +1100 (AEDT) Received: from localhost ([::1]:41796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLHbP-0004Bh-0D for incoming@patchwork.ozlabs.org; Tue, 10 Feb 2015 15:40:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLHR9-00034b-RR for qemu-devel@nongnu.org; Tue, 10 Feb 2015 15:29:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLHR3-00071a-NX for qemu-devel@nongnu.org; Tue, 10 Feb 2015 15:29:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLHR3-00071K-FR for qemu-devel@nongnu.org; Tue, 10 Feb 2015 15:29:29 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1AKTSYx009433 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 10 Feb 2015 15:29:29 -0500 Received: from localhost ([10.18.17.71]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1AKTSZX002283 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Tue, 10 Feb 2015 15:29:28 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Tue, 10 Feb 2015 15:29:01 -0500 Message-Id: <1423600146-7642-20-git-send-email-mreitz@redhat.com> In-Reply-To: <1423600146-7642-1-git-send-email-mreitz@redhat.com> References: <1423600146-7642-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v6 19/24] qcow2: Split upgrade/downgrade paths for amend X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 c610c6c..9a730dc 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2738,20 +2738,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; } } @@ -2765,7 +2758,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; @@ -2801,6 +2794,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; }