From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfWfe-00028V-Jk for qemu-devel@nongnu.org; Fri, 15 Jun 2012 09:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SfWfZ-0004uF-9V for qemu-devel@nongnu.org; Fri, 15 Jun 2012 09:34:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SfWfZ-0004ti-1I for qemu-devel@nongnu.org; Fri, 15 Jun 2012 09:34:33 -0400 From: Kevin Wolf Date: Fri, 15 Jun 2012 15:33:35 +0200 Message-Id: <1339767219-24297-36-git-send-email-kwolf@redhat.com> In-Reply-To: <1339767219-24297-1-git-send-email-kwolf@redhat.com> References: <1339767219-24297-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 35/39] qcow2: fix autoclear image header update List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Stefan Hajnoczi The autoclear feature bits can be used for qcow2 file format features that are safe to "drop" by old programs that do not understand the feature. Upon opening the image file unknown autoclear feature bits are cleared and the image file header is rewritten, but this was happening too early in the code when critical header fields were not yet loaded. Process autoclear feature bits after all necessary header information has been loaded. Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/qcow2.c | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 57fd43d..2c1cd0a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -297,14 +297,6 @@ static int qcow2_open(BlockDriverState *bs, int flags) goto fail; } - if (!bs->read_only && s->autoclear_features != 0) { - s->autoclear_features = 0; - ret = qcow2_update_header(bs); - if (ret < 0) { - goto fail; - } - } - /* Check support for various header values */ if (header.refcount_order != 4) { report_unsupported(bs, "%d bit reference counts", @@ -408,6 +400,15 @@ static int qcow2_open(BlockDriverState *bs, int flags) goto fail; } + /* Clear unknown autoclear feature bits */ + if (!bs->read_only && s->autoclear_features != 0) { + s->autoclear_features = 0; + ret = qcow2_update_header(bs); + if (ret < 0) { + goto fail; + } + } + /* Initialise locks */ qemu_co_mutex_init(&s->lock); -- 1.7.6.5