From: Jeff Cody <jcody@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: kwolf@redhat.com, sw@weilnetz.de, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 6/7] block: add header update capability for VHDX images.
Date: Thu, 7 Mar 2013 10:33:49 -0500 [thread overview]
Message-ID: <20130307153349.GF22782@localhost.localdomain> (raw)
In-Reply-To: <20130307145056.GD27175@stefanha-thinkpad.redhat.com>
On Thu, Mar 07, 2013 at 03:50:56PM +0100, Stefan Hajnoczi wrote:
> On Wed, Mar 06, 2013 at 09:48:33AM -0500, Jeff Cody wrote:
> > This adds the ability to update the headers in a VHDX image, including
> > generating a new MS-compatible GUID, and checksum.
> >
> > Signed-off-by: Jeff Cody <jcody@redhat.com>
> > ---
> > block/vhdx.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> > 1 file changed, 163 insertions(+), 2 deletions(-)
> >
> > diff --git a/block/vhdx.c b/block/vhdx.c
> > index 97775d2..13d1e7f 100644
> > --- a/block/vhdx.c
> > +++ b/block/vhdx.c
> > @@ -27,6 +27,11 @@
> > le16_to_cpus(&(guid)->data2); \
> > le16_to_cpus(&(guid)->data3); } while (0)
> >
> > +#define cpu_to_leguids(guid) do { \
> > + cpu_to_le32s(&(guid)->data1); \
> > + cpu_to_le16s(&(guid)->data2); \
> > + cpu_to_le16s(&(guid)->data3); } while (0)
> > +
>
> Please use a function instead of a macro.
>
OK.
> > +/* Calculates new checksum.
> > + *
> > + * Zero is substituted during crc calculation for the original crc field
> > + * crc_offset: byte offset in buf of the buffer crc
> > + * buf: buffer pointer
> > + * size: size of buffer (must be > crc_offset+4)
> > + */
> > +static uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset)
> > +{
> > + uint32_t crc;
> > +
> > + assert(buf != NULL);
> > + assert(size > (crc_offset+4));
> > +
> > + memset(buf+crc_offset, 0, sizeof(crc));
> > + crc = crc32c(0xffffffff, buf, size);
> > + memcpy(buf+crc_offset, &crc, sizeof(crc));
>
> Worth a comment that the checksum is in CPU endianness. Must use
> vhdx_header_le_export() before writing to file. That implies the buffer
> must also be in CPU endianness otherwise vhdx_header_le_export() will
> byteswap unwanted fields.
>
OK.
> > +
> > + return crc;
> > +}
> > +
> > /* Validates the checksum of the buffer, with an in-place CRC.
> > *
> > * Zero is substituted during crc calculation for the original crc field,
> > @@ -198,6 +227,33 @@ static bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset)
> > }
> >
> > /*
> > + * This generates a UUID that is compliant with the MS GUIDs used
> > + * in the VHDX spec (and elsewhere).
> > + *
> > + * We can do this with uuid_generate if uuid.h is present,
> > + * however not all systems have uuid and the generation is
>
> Do you mean libuuid is not available on all host platforms supported by
> QEMU, or just that you wanted to avoid the dependency?
>
The former, I am assuming by the configure check for uuid and
CONFIG_UUID.
> Since other parts of QEMU already use libuuid I'd rather see it used
> than reimplemented in VHDX.
There are two other users of uuid.h - block/vpc.c and block/vdi.c.
Both uses are wrapped in an #ifdef for CONFIG_UUID, and if
uuid_generate is not present they just leave the uuid field with
zeroes.
At least for the VHDX spec, there are several places where a GUID /
UUID of zero has a special meaning. So if CONFIG_UUID is not present,
something needs to be generated - and generating a valid GUID that is
compatible with the spec is pretty trivial, which is why I just went
ahead and did that.
I also thought about adding this into util/ or the like, so that if
uuid.h is not available, vdi and vpc could use it. However, I wasn't
certain of the requirements for vdi and vpc itself, so I didn't do
that yet.
Jeff
next prev parent reply other threads:[~2013-03-07 15:34 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-06 14:46 [Qemu-devel] [PATCH 0/7] Initial VHDX support (and a bug fix for QCOW) Jeff Cody
2013-03-06 14:47 ` [Qemu-devel] [PATCH 1/7] block: only force IO completion in .bdrv_truncate if we are shrinking Jeff Cody
2013-03-06 17:50 ` Peter Lieven
2013-03-06 18:06 ` Paolo Bonzini
2013-03-06 18:14 ` Jeff Cody
2013-03-06 18:31 ` Paolo Bonzini
2013-03-06 18:48 ` Jeff Cody
2013-03-06 19:03 ` Peter Lieven
2013-03-06 20:39 ` Paolo Bonzini
2013-03-07 8:50 ` Kevin Wolf
2013-03-07 8:56 ` Peter Lieven
2013-03-07 9:03 ` Kevin Wolf
2013-03-07 9:16 ` Peter Lieven
2013-03-07 9:22 ` Kevin Wolf
2013-03-07 9:25 ` Peter Lieven
2013-03-07 10:00 ` Kevin Wolf
2013-03-07 10:22 ` Peter Lieven
2013-03-07 16:45 ` Paolo Bonzini
2013-03-07 8:53 ` Peter Lieven
2013-03-07 8:59 ` Kevin Wolf
2013-03-07 16:09 ` Paolo Bonzini
2013-03-08 7:53 ` Peter Lieven
2013-03-08 9:23 ` Paolo Bonzini
2013-03-08 9:35 ` Kevin Wolf
2013-03-08 11:46 ` Peter Lieven
2013-03-08 11:56 ` Kevin Wolf
2013-03-09 9:36 ` Peter Lieven
[not found] ` <51378A23.5090301@dlhnet.de>
[not found] ` <20130306184217.GC3743@localhost.localdomain>
2013-03-06 18:46 ` Peter Lieven
2013-03-06 18:27 ` Peter Lieven
2013-03-07 8:57 ` Kevin Wolf
2013-03-06 18:32 ` Jeff Cody
2013-03-06 20:22 ` Paolo Bonzini
2013-03-06 14:47 ` [Qemu-devel] [PATCH 2/7] qemu: add castagnoli crc32c checksum algorithm Jeff Cody
2013-03-06 14:47 ` [Qemu-devel] [PATCH 3/7] block: vhdx header for the QEMU support of VHDX images Jeff Cody
2013-03-07 13:15 ` Stefan Hajnoczi
2013-03-07 13:43 ` Jeff Cody
2013-03-06 14:48 ` [Qemu-devel] [PATCH 4/7] block: initial VHDX driver support framework - supports open and probe Jeff Cody
2013-03-07 14:30 ` Stefan Hajnoczi
2013-03-07 15:23 ` Jeff Cody
2013-03-07 16:12 ` Stefan Hajnoczi
2013-03-08 8:35 ` Kevin Wolf
2013-03-06 14:48 ` [Qemu-devel] [PATCH 5/7] block: add read-only support to VHDX image format Jeff Cody
2013-03-06 14:48 ` [Qemu-devel] [PATCH 6/7] block: add header update capability for VHDX images Jeff Cody
2013-03-07 14:50 ` Stefan Hajnoczi
2013-03-07 15:33 ` Jeff Cody [this message]
2013-03-07 16:15 ` Stefan Hajnoczi
2013-03-06 14:48 ` [Qemu-devel] [PATCH 7/7] block: add write support " Jeff Cody
2013-03-07 15:59 ` Stefan Hajnoczi
2013-03-07 16:05 ` Jeff Cody
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130307153349.GF22782@localhost.localdomain \
--to=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).