Skip to contentSkip to conversation

Accommodate VHDX images created by Disk2VHD

PATCH Applied Jeff Cody 3 participants 6 messages May 13, 2014 – May 14, 2014 Block layer

lore
Share & tools
lore

Jeff Cody

author
#0 lore raw

cover Accommodate VHDX images created by Disk2VHD

This series adds support for VHDX images created with Microsofts p2v tool Disk2VHD.

Jeff Cody (2):
block: vhdx - account for identical header sections
block: add test for vhdx image created by Disk2VHD

 block/vhdx.c                                            |   9 ++++++++-
 tests/qemu-iotests/070                                  |   7 +++++++
 tests/qemu-iotests/070.out                              |   7 +++++++
 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 | Bin 0 -> 1424 bytes
 4 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 block: vhdx - account for identical header sections

The VHDX spec v1.00 declares that "a header is current if it is the only valid header or if it is valid and its SequenceNumber field is greater than the other header’s SequenceNumber field. The parser must only use data from the current header. If there is no current header, then the VHDX file is corrupt."

However, the Disk2VHD tool from Microsoft creates a VHDX image file that has 2 identical headers, including matching checksums and matching sequence numbers. Likely, as a shortcut the tool is just writing the header twice, for the active and inactive headers, during the image creation. Technically, this should be considered a corrupt VHDX file (at least per the 1.00 spec, and that is how we currently treat it).

But in order to accomodate images created with Disk2VHD, we can safely create an exception for this case. If we find identical sequence numbers, then we check the VHDXHeader-sized chunks of each 64KB header sections (we won't rely just on the crc32c to indicate the headers are the same). If they are identical, then we go ahead and use the first one.

---
 block/vhdx.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
block/vhdx.c +8 -1
index 509baaf..353c74d 100644
@@ -473,7 +473,14 @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s,
         } else if (h2_seq > h1_seq) {
             s->curr_header = 1;
         } else {
-            goto fail;
+            /* The Microsoft Disk2VHD tool will create 2 identical
+             * headers, with identical sequence numbers.  If the headers are
+             * identical, don't consider the file corrupt */
+            if (!memcmp(header1, header2, sizeof(VHDXHeader))) {
+                s->curr_header = 0;
+            } else {
+                goto fail;
+            }
         }
     }
 
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/2 block: add test for vhdx image created by Disk2VHD

In reply to Jeff Cody

This adds a test for VHDX images created by Microsoft's tool, Disk2VHD.

VHDX images created by this tool have 2 identical header sections, with identical sequence numbers. This makes sure we detect VHDX images with identical headers, and do not flag them as corrupt.

---
 tests/qemu-iotests/070                                  |   7 +++++++
 tests/qemu-iotests/070.out                              |   7 +++++++
 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 | Bin 0 -> 1424 bytes
 3 files changed, 14 insertions(+)
 create mode 100644 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2
tests/qemu-iotests/070 +7 -0
index ce71fa4..ea0dae7 100755
@@ -72,6 +72,13 @@ echo "=== Verify open image read-only succeeds after log replay ==="
 $QEMU_IO -r -c "read -pP 0xa5 0 18M" "$TEST_IMG" 2>&1 | _filter_testdir \
                                                       | _filter_qemu_io
 
+_cleanup_test_img
+_use_sample_img test-disk2vhd.vhdx.bz2
+
+echo
+echo "=== Verify image created by Disk2VHD can be opened ==="
+$QEMU_IMG info "$TEST_IMG" 2>&1 | _filter_testdir | _filter_qemu
+
 # success, all done
 echo "*** done"
 rm -f $seq.full
tests/qemu-iotests/070.out +7 -0
index 922d62c..15f1fc1 100644
@@ -18,4 +18,11 @@ No errors were found on the image.
 === Verify open image read-only succeeds after log replay ===
 read 18874368/18874368 bytes at offset 0
 18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Verify image created by Disk2VHD can be opened ===
+image: TEST_DIR/test-disk2vhd.vhdx
+file format: vhdx
+virtual size: 256M (268435456 bytes)
+disk size: 260M
+cluster_size: 2097152
 *** done
tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2891c9a6d62908e0195d3791817284016249aaee
GIT binary patch
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: add test for vhdx image created by Disk2VHD

Quoted 1 line · Jeff Cody

This adds a test for VHDX images created by Microsoft's tool, Disk2VHD.

Out of curiosity, is this an official tool from Microsoft?

Quoted 18 lines

VHDX images created by this tool have 2 identical header sections, with identical sequence numbers. This makes sure we detect VHDX images with identical headers, and do not flag them as corrupt.

---
 tests/qemu-iotests/070                                  |   7 +++++++
 tests/qemu-iotests/070.out                              |   7 +++++++
 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 | Bin 0 -> 1424 bytes
 3 files changed, 14 insertions(+)
 create mode 100644 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2
tests/qemu-iotests/070 +0 -0
index ce71fa4..ea0dae7 100755

tests/qemu-iotests/070 echo "=== Verify open image read-only succeeds after log replay ===" · line 81

Quoted 10 lines
tests/qemu-iotests/070 +7 -0
@@ -72,6 +72,13 @@ echo "=== Verify open image read-only succeeds after log replay ==="
 $QEMU_IO -r -c "read -pP 0xa5 0 18M" "$TEST_IMG" 2>&1 | _filter_testdir \
                                                       | _filter_qemu_io
 
+_cleanup_test_img
+_use_sample_img test-disk2vhd.vhdx.bz2
+
+echo
+echo "=== Verify image created by Disk2VHD can be opened ==="
+$QEMU_IMG info "$TEST_IMG" 2>&1 | _filter_testdir | _filter_qemu
+

_filter_qemu shouldn't make a difference for $QEMU_IMG. Anyway,

Quoted 58 lines
tests/qemu-iotests/070 +0 -0
 # success, all done
 echo "*** done"
 rm -f $seq.full
tests/qemu-iotests/070.out +7 -0
index 922d62c..15f1fc1 100644
@@ -18,4 +18,11 @@ No errors were found on the image.
 === Verify open image read-only succeeds after log replay ===
 read 18874368/18874368 bytes at offset 0
 18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Verify image created by Disk2VHD can be opened ===
+image: TEST_DIR/test-disk2vhd.vhdx
+file format: vhdx
+virtual size: 256M (268435456 bytes)
+disk size: 260M
+cluster_size: 2097152
 *** done
tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2891c9a6d62908e0195d3791817284016249aaee
GIT binary patch
Signature · 2 lines
-- 
1.8.3.1
Applied
#5 lore raw
In reply to Jeff Cody

Am 13.05.2014 um 16:00 hat Jeff Cody geschrieben:

Quoted 6 lines

This series adds support for VHDX images created with Microsofts p2v tool Disk2VHD.

Jeff Cody (2):
block: vhdx - account for identical header sections
block: add test for vhdx image created by Disk2VHD

Quoted 6 lines
 block/vhdx.c                                            |   9 ++++++++-
 tests/qemu-iotests/070                                  |   7 +++++++
 tests/qemu-iotests/070.out                              |   7 +++++++
 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 | Bin 0 -> 1424 bytes
 4 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2

Thanks, applied to the block branch.

Unrelated bug I noticed while testing this: The old error message for opening the image was 'qemu-img: Could not open 'TEST_DIR/test-disk2vhd. vhdx': No valid VHDX header found: Unknown error -4096'.

This is because vhdx_parse_header() doesn't set ret before jumping to
fail: while trying to find the current header.

Kevin

author
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: add test for vhdx image created by Disk2VHD

In reply to Fam Zheng
Quoted 5 lines · Fam Zheng
Quoted 1 line · Jeff Cody

This adds a test for VHDX images created by Microsoft's tool, Disk2VHD.

Out of curiosity, is this an official tool from Microsoft?

Yes, it is a p2v tool from MS for Virtual PC / Hyper-V hosts:

http://technet.microsoft.com/en-us/sysinternals/ee656415.aspx

Quoted 91 lines
Quoted 18 lines

VHDX images created by this tool have 2 identical header sections, with identical sequence numbers. This makes sure we detect VHDX images with identical headers, and do not flag them as corrupt.

---
 tests/qemu-iotests/070                                  |   7 +++++++
 tests/qemu-iotests/070.out                              |   7 +++++++
 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 | Bin 0 -> 1424 bytes
 3 files changed, 14 insertions(+)
 create mode 100644 tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2
tests/qemu-iotests/070 +0 -0
index ce71fa4..ea0dae7 100755

tests/qemu-iotests/070 echo "=== Verify open image read-only succeeds after log replay ===" · line 81

Quoted 10 lines
tests/qemu-iotests/070 +7 -0
@@ -72,6 +72,13 @@ echo "=== Verify open image read-only succeeds after log replay ==="
 $QEMU_IO -r -c "read -pP 0xa5 0 18M" "$TEST_IMG" 2>&1 | _filter_testdir \
                                                       | _filter_qemu_io
 
+_cleanup_test_img
+_use_sample_img test-disk2vhd.vhdx.bz2
+
+echo
+echo "=== Verify image created by Disk2VHD can be opened ==="
+$QEMU_IMG info "$TEST_IMG" 2>&1 | _filter_testdir | _filter_qemu
+

_filter_qemu shouldn't make a difference for $QEMU_IMG. Anyway,

Quoted 58 lines
tests/qemu-iotests/070 +0 -0
 # success, all done
 echo "*** done"
 rm -f $seq.full
tests/qemu-iotests/070.out +7 -0
index 922d62c..15f1fc1 100644
@@ -18,4 +18,11 @@ No errors were found on the image.
 === Verify open image read-only succeeds after log replay ===
 read 18874368/18874368 bytes at offset 0
 18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Verify image created by Disk2VHD can be opened ===
+image: TEST_DIR/test-disk2vhd.vhdx
+file format: vhdx
+virtual size: 256M (268435456 bytes)
+disk size: 260M
+cluster_size: 2097152
 *** done
tests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2891c9a6d62908e0195d3791817284016249aaee
GIT binary patch
Signature · 2 lines
-- 
1.8.3.1