From patchwork Wed Jan 20 16:24:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 570766 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 C081B1402EC for ; Thu, 21 Jan 2016 03:29:29 +1100 (AEDT) Received: from localhost ([::1]:43911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLvdP-00039l-QC for incoming@patchwork.ozlabs.org; Wed, 20 Jan 2016 11:29:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLvZV-0003Zh-Su for qemu-devel@nongnu.org; Wed, 20 Jan 2016 11:25:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLvZU-0006xM-LF for qemu-devel@nongnu.org; Wed, 20 Jan 2016 11:25:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLvZQ-0006uB-Qv; Wed, 20 Jan 2016 11:25:20 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 800AF8E766; Wed, 20 Jan 2016 16:25:20 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0KGP8CU032534; Wed, 20 Jan 2016 11:25:19 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Jan 2016 17:24:56 +0100 Message-Id: <1453307106-28330-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1453307106-28330-1-git-send-email-kwolf@redhat.com> References: <1453307106-28330-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 07/17] qcow2: Write full header on image creation 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 When creating a qcow2 image, we didn't necessarily call qcow2_update_header(), but could end up with the basic header that qcow2_create2() created manually. One thing that this basic header lacks is the feature table. Let's make sure that it's always present. This requires a few updates to test cases as well. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/qcow2.c | 7 +++++++ tests/qemu-iotests/031.out | 5 +++++ tests/qemu-iotests/036 | 2 ++ tests/qemu-iotests/036.out | 5 +++++ tests/qemu-iotests/061.out | 20 ++++++++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 20e4057..037afbf 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2239,6 +2239,13 @@ static int qcow2_create2(const char *filename, int64_t total_size, abort(); } + /* Create a full header (including things like feature table) */ + ret = qcow2_update_header(bs); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not update qcow2 header"); + goto out; + } + /* Okay, now that we have a valid image, let's give it the right size */ ret = bdrv_truncate(bs, total_size); if (ret < 0) { diff --git a/tests/qemu-iotests/031.out b/tests/qemu-iotests/031.out index f065404..7f5050b 100644 --- a/tests/qemu-iotests/031.out +++ b/tests/qemu-iotests/031.out @@ -116,6 +116,11 @@ refcount_order 4 header_length 104 Header extension: +magic 0x6803f857 +length 144 +data + +Header extension: magic 0x12345678 length 31 data 'This is a test header extension' diff --git a/tests/qemu-iotests/036 b/tests/qemu-iotests/036 index 392f1ef..c4cc91b 100755 --- a/tests/qemu-iotests/036 +++ b/tests/qemu-iotests/036 @@ -57,6 +57,7 @@ _make_test_img 64M $PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 63 # Without feature table +$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857 $PYTHON qcow2.py "$TEST_IMG" dump-header _img_info @@ -73,6 +74,7 @@ $PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 62 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 63 # Without feature table +$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857 _img_info # With feature table containing bit 63 diff --git a/tests/qemu-iotests/036.out b/tests/qemu-iotests/036.out index 5616e37..f443635 100644 --- a/tests/qemu-iotests/036.out +++ b/tests/qemu-iotests/036.out @@ -56,6 +56,11 @@ autoclear_features 0x8000000000000000 refcount_order 4 header_length 104 +Header extension: +magic 0x6803f857 +length 144 +data + === Repair image === diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index d604682..a03732e 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -24,6 +24,11 @@ autoclear_features 0x0 refcount_order 4 header_length 104 +Header extension: +magic 0x6803f857 +length 144 +data + magic 0x514649fb version 2 backing_file_offset 0x0 @@ -76,6 +81,11 @@ autoclear_features 0x0 refcount_order 4 header_length 104 +Header extension: +magic 0x6803f857 +length 144 +data + ERROR cluster 5 refcount=0 reference=1 ERROR cluster 6 refcount=0 reference=1 Rebuilding refcount structure @@ -126,6 +136,11 @@ autoclear_features 0x40000000000 refcount_order 4 header_length 104 +Header extension: +magic 0x6803f857 +length 144 +data + magic 0x514649fb version 2 backing_file_offset 0x0 @@ -228,6 +243,11 @@ autoclear_features 0x0 refcount_order 4 header_length 104 +Header extension: +magic 0x6803f857 +length 144 +data + ERROR cluster 5 refcount=0 reference=1 ERROR cluster 6 refcount=0 reference=1 Rebuilding refcount structure