From patchwork Mon Apr 16 15:02:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 152887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 559F2B7014 for ; Tue, 17 Apr 2012 01:03:31 +1000 (EST) Received: from localhost ([::1]:58674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SJnPL-0004p7-69 for incoming@patchwork.ozlabs.org; Mon, 16 Apr 2012 10:59:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SJnOb-0003Qg-QP for qemu-devel@nongnu.org; Mon, 16 Apr 2012 10:59:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SJnOW-0007rx-F9 for qemu-devel@nongnu.org; Mon, 16 Apr 2012 10:59:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8409) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SJnOW-0007rh-6E for qemu-devel@nongnu.org; Mon, 16 Apr 2012 10:59:08 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3GEx5vs000727 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Apr 2012 10:59:05 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-5-41.ams2.redhat.com [10.36.5.41]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3GEwVV0010388; Mon, 16 Apr 2012 10:59:04 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 16 Apr 2012 17:02:16 +0200 Message-Id: <1334588536-16313-19-git-send-email-kwolf@redhat.com> In-Reply-To: <1334588536-16313-1-git-send-email-kwolf@redhat.com> References: <1334588536-16313-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@gmail.com, freddy77@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 18/18] qemu-iotests: Fix test 031 for qcow2 v3 support 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 qcow2.py must be updated to work with version 3 images at all, the output has changed since the feature table extension has been added, and version 2 and version 3 images can't possibly have the same test output. Change the test case to completely ignore IMGOPTS and run the test for both compat=1.1 and compat=0.10 regardless of the ./check command line. Signed-off-by: Kevin Wolf --- tests/qemu-iotests/031 | 44 +++++++++------ tests/qemu-iotests/031.out | 130 ++++++++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/qcow2.py | 24 ++++++-- 3 files changed, 172 insertions(+), 26 deletions(-) diff --git a/tests/qemu-iotests/031 b/tests/qemu-iotests/031 index 6365f28..2d5e3b1 100755 --- a/tests/qemu-iotests/031 +++ b/tests/qemu-iotests/031 @@ -45,26 +45,34 @@ _supported_proto generic _supported_os Linux CLUSTER_SIZE=65536 -echo -echo === Create image with unknown header extension === -echo -_make_test_img 64M -./qcow2.py $TEST_IMG add-header-ext 0x12345678 "This is a test header extension" -./qcow2.py $TEST_IMG dump-header -_check_test_img -echo -echo === Rewrite header with no backing file === -echo -$QEMU_IMG rebase -u -b "" $TEST_IMG -./qcow2.py $TEST_IMG dump-header -_check_test_img +# qcow2.py output depends on the exact options used, so override the command +# line here as an exception +for IMGOPTS in "compat=0.10" "compat=1.1"; do -echo -echo === Add a backing file and format === -echo -$QEMU_IMG rebase -u -b "/some/backing/file/path" -F host_device $TEST_IMG -./qcow2.py $TEST_IMG dump-header + echo + echo ===== Testing with -o $IMGOPTS ===== + echo + echo === Create image with unknown header extension === + echo + _make_test_img 64M + ./qcow2.py $TEST_IMG add-header-ext 0x12345678 "This is a test header extension" + ./qcow2.py $TEST_IMG dump-header + _check_test_img + + echo + echo === Rewrite header with no backing file === + echo + $QEMU_IMG rebase -u -b "" $TEST_IMG + ./qcow2.py $TEST_IMG dump-header + _check_test_img + + echo + echo === Add a backing file and format === + echo + $QEMU_IMG rebase -u -b "/some/backing/file/path" -F host_device $TEST_IMG + ./qcow2.py $TEST_IMG dump-header +done # success, all done echo "*** done" diff --git a/tests/qemu-iotests/031.out b/tests/qemu-iotests/031.out index e1a536e..d3cab30 100644 --- a/tests/qemu-iotests/031.out +++ b/tests/qemu-iotests/031.out @@ -1,5 +1,7 @@ QA output created by 031 +===== Testing with -o compat=0.10 ===== + === Create image with unknown header extension === Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 @@ -16,6 +18,11 @@ refcount_table_offset 0x10000 refcount_table_clusters 1 nb_snapshots 0 snapshot_offset 0x0 +incompatible_features 0x0 +compatible_features 0x0 +autoclear_features 0x0 +refcount_order 4 +header_length 72 Header extension: magic 0x12345678 @@ -39,6 +46,16 @@ refcount_table_offset 0x10000 refcount_table_clusters 1 nb_snapshots 0 snapshot_offset 0x0 +incompatible_features 0x0 +compatible_features 0x0 +autoclear_features 0x0 +refcount_order 4 +header_length 72 + +Header extension: +magic 0x6803f857 +length 0 +data '' Header extension: magic 0x12345678 @@ -51,7 +68,108 @@ No errors were found on the image. magic 0x514649fb version 2 -backing_file_offset 0x90 +backing_file_offset 0x98 +backing_file_size 0x17 +cluster_bits 16 +size 67108864 +crypt_method 0 +l1_size 1 +l1_table_offset 0x30000 +refcount_table_offset 0x10000 +refcount_table_clusters 1 +nb_snapshots 0 +snapshot_offset 0x0 +incompatible_features 0x0 +compatible_features 0x0 +autoclear_features 0x0 +refcount_order 4 +header_length 72 + +Header extension: +magic 0xe2792aca +length 11 +data 'host_device' + +Header extension: +magic 0x6803f857 +length 0 +data '' + +Header extension: +magic 0x12345678 +length 31 +data 'This is a test header extension' + + +===== Testing with -o compat=1.1 ===== + +=== Create image with unknown header extension === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +magic 0x514649fb +version 3 +backing_file_offset 0x0 +backing_file_size 0x0 +cluster_bits 16 +size 67108864 +crypt_method 0 +l1_size 1 +l1_table_offset 0x30000 +refcount_table_offset 0x10000 +refcount_table_clusters 1 +nb_snapshots 0 +snapshot_offset 0x0 +incompatible_features 0x0 +compatible_features 0x0 +autoclear_features 0x0 +refcount_order 4 +header_length 104 + +Header extension: +magic 0x12345678 +length 31 +data 'This is a test header extension' + +No errors were found on the image. + +=== Rewrite header with no backing file === + +magic 0x514649fb +version 3 +backing_file_offset 0x0 +backing_file_size 0x0 +cluster_bits 16 +size 67108864 +crypt_method 0 +l1_size 1 +l1_table_offset 0x30000 +refcount_table_offset 0x10000 +refcount_table_clusters 1 +nb_snapshots 0 +snapshot_offset 0x0 +incompatible_features 0x0 +compatible_features 0x0 +autoclear_features 0x0 +refcount_order 4 +header_length 104 + +Header extension: +magic 0x6803f857 +length 0 +data '' + +Header extension: +magic 0x12345678 +length 31 +data 'This is a test header extension' + +No errors were found on the image. + +=== Add a backing file and format === + +magic 0x514649fb +version 3 +backing_file_offset 0xb8 backing_file_size 0x17 cluster_bits 16 size 67108864 @@ -62,6 +180,11 @@ refcount_table_offset 0x10000 refcount_table_clusters 1 nb_snapshots 0 snapshot_offset 0x0 +incompatible_features 0x0 +compatible_features 0x0 +autoclear_features 0x0 +refcount_order 4 +header_length 104 Header extension: magic 0xe2792aca @@ -69,6 +192,11 @@ length 11 data 'host_device' Header extension: +magic 0x6803f857 +length 0 +data '' + +Header extension: magic 0x12345678 length 31 data 'This is a test header extension' diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py index bfb47e8..e27196a 100755 --- a/tests/qemu-iotests/qcow2.py +++ b/tests/qemu-iotests/qcow2.py @@ -35,6 +35,13 @@ class QcowHeader: [ uint32_t, '%d', 'refcount_table_clusters' ], [ uint32_t, '%d', 'nb_snapshots' ], [ uint64_t, '%#x', 'snapshot_offset' ], + + # Version 3 header fields + [ uint64_t, '%#x', 'incompatible_features' ], + [ uint64_t, '%#x', 'compatible_features' ], + [ uint64_t, '%#x', 'autoclear_features' ], + [ uint32_t, '%d', 'refcount_order' ], + [ uint32_t, '%d', 'header_length' ], ]; fmt = '>' + ''.join(field[0] for field in fields) @@ -50,9 +57,10 @@ class QcowHeader: self.__dict__ = dict((field[2], header[i]) for i, field in enumerate(QcowHeader.fields)) + self.set_defaults() self.cluster_size = 1 << self.cluster_bits - fd.seek(self.get_header_length()) + fd.seek(self.header_length) self.load_extensions(fd) if self.backing_file_offset: @@ -61,11 +69,13 @@ class QcowHeader: else: self.backing_file = None - def get_header_length(self): + def set_defaults(self): if self.version == 2: - return 72 - else: - raise Exception("version != 2 not supported") + self.incompatible_features = 0 + self.compatible_features = 0 + self.autoclear_features = 0 + self.refcount_order = 4 + self.header_length = 72 def load_extensions(self, fd): self.extensions = [] @@ -86,7 +96,7 @@ class QcowHeader: def update_extensions(self, fd): - fd.seek(self.get_header_length()) + fd.seek(self.header_length) extensions = self.extensions extensions.append(QcowHeaderExtension(0, 0, "")) for ex in extensions: @@ -103,7 +113,7 @@ class QcowHeader: def update(self, fd): - header_bytes = self.get_header_length() + header_bytes = self.header_length self.update_extensions(fd)