Accommodate VHDX images created by Disk2VHD
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
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
@@ -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
PATCH 2/2 block: add test for vhdx image created by Disk2VHD
In reply to Jeff CodyThis 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
@@ -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
@@ -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
Signature · 1 line
1.8.3.1
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.
Signed-off-by Jeff Cody <[email protected]>--- 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.bz2tests/qemu-iotests/070 +0
-0
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.fulltests/qemu-iotests/070.out +7
-0@@ -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 *** donetests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 new file binary +0
-0Signature · 2 lines
-- 1.8.3.1
Kevin Wolf
AppliedAm 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
Re: [Qemu-devel] [PATCH 2/2] block: add test for vhdx image created by Disk2VHD
In reply to Fam ZhengQuoted 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.
Signed-off-by Jeff Cody <[email protected]>--- 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.bz2tests/qemu-iotests/070 +0
-0tests/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_qemushouldn't make a difference for $QEMU_IMG. Anyway,Reviewed-by Fam Zheng <[email protected]>Quoted 58 lines
tests/qemu-iotests/070 +0
-0# success, all done echo "*** done" rm -f $seq.fulltests/qemu-iotests/070.out +7
-0@@ -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 *** donetests/qemu-iotests/sample_images/test-disk2vhd.vhdx.bz2 new file binary +0
-0Signature · 2 lines
-- 1.8.3.1