Received: from eggs.gnu.org ([2001:4830:134:3::10]:34671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQdPs-0008ME-FM for qemu-devel@nongnu.org; Wed, 25 Feb 2015 09:58:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQdPo-0000F3-Ak for qemu-devel@nongnu.org; Wed, 25 Feb 2015 09:58:24 -0500 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:34729) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQdPn-0000Ex-Vu for qemu-devel@nongnu.org; Wed, 25 Feb 2015 09:58:20 -0500 Received: by mail-wi0-f181.google.com with SMTP id r20so5689708wiv.2 for ; Wed, 25 Feb 2015 06:58:19 -0800 (PST) Date: Wed, 25 Feb 2015 14:58:14 +0000 From: Stefan Hajnoczi Message-ID: <20150225145814.GB2922@stefanha-thinkpad.redhat.com> References: <1424007349-3365-1-git-send-email-gongxiaodong1@huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WhfpMioaduB5tiZL" Content-Disposition: inline In-Reply-To: <1424007349-3365-1-git-send-email-gongxiaodong1@huawei.com> Subject: Re: [Qemu-devel] [PATCH v9] Support vhd type VHD_DIFFERENCING List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xiaodong Gong Cc: kwolf@redhat.com, petrutlucian94@gmail.com, hahn@univention.de, jcody@redhat.com, cyliu@suse.com, qemu-devel@nongnu.org, ssdxiao@163.com, arei.gonglei@huawei.com, Xiaodong Gong , rudy.zhangmin@huawei.com --WhfpMioaduB5tiZL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 15, 2015 at 09:35:49PM +0800, Xiaodong Gong wrote: > Now qemu only supports vhd type VHD_FIXED and VHD_DYNAMIC, so qemu > can't read snapshot volume of vhd, and can't support other storage > features of vhd file. >=20 > This patch add read parent information in function "vpc_open", read > bitmap in "vpc_read", and change bitmap in "vpc_write". >=20 > Signed-off-by: Xiaodong Gong > Reviewed-by: Ding xiao > --- > Changes since v8 > - use backing_format to avoid being probed to format of raw >=20 > Changes since v7: > - use iconv to decode UTF-16LE(w2u) and UTF-8(macx) to ASCII > (Stefan Hajnoczi) I suggested glib's character set conversion functions, not iconv. glib abstracts the dependency character set conversion so it will work across platforms. That way we don't have to add iconv library detection to ./configure. Please use glib since QEMU already depends on it. https://developer.gnome.org/glib/stable/glib-Character-Set-Conversion.html > #define HEADER_SIZE 512 > +#define DYNAMIC_HEADER_SIZE 1024 > +#define PARENT_LOCATOR_NUM 8 > +#define TBBATMAP_HEAD_SIZE 28 > + > +#define MACX_PREFIX_LEN 7 /* file:// */ > + > +#define PLATFORM_MACX 0x5863614d /* big endian */ This comment doesn't make sense. The constant is just a C integer literal, it doesn't have endianness. > +static int vpc_decode_parent_loc(uint32_t platform, > + BlockDriverState *bs, > + int data_length) > +{ > + int ret; > + > + switch (platform) { > + case PLATFORM_MACX: > + ret =3D vpc_decode_maxc_loc(bs, data_length); > + if (ret < 0) { > + return ret; > + } > + break; > + > + case PLATFORM_W2RU: > + /* fall through! */ > + case PLATFORM_W2KU: > + ret =3D vpc_decode_w2u_loc(bs, data_length); > + if (ret < 0) { > + return ret; > + } > + break; > + > + default: > + return 0; This should fail. There are unimplemented platform codes. We should not attempt to open the file any further. In the PLATFORM_NONE (0x0) case it may be cleanest to vpc_read_backing_loc()'s for loop to skip empty platform locators instead of trying to read 0 bytes and then calling vpc_decode_parent_loc() with no data. > + } > + > + return 0; > +} > + > +static int vpc_read_backing_loc(VHDDynDiskHeader *dyndisk_header, > + BlockDriverState *bs, > + Error **errp) > +{ > + BDRVVPCState *s =3D bs->opaque; > + int64_t data_offset =3D 0; > + int data_length =3D 0; > + uint32_t platform; > + bool done =3D false; > + int parent_locator_offset =3D 0; > + int i; > + int ret =3D 0; > + > + for (i =3D 0; i < PARENT_LOCATOR_NUM; i++) { > + /* The PLATFORM_* is big ending, and the dyndisk_header > + * is always big ending. So whatever this platform in cpu > + * is, it works. */ This comment is incorrect. dyndisk_header is big endian but PLATFORM_* is not big endian. Please drop the comment. > + platform =3D > + dyndisk_header->parent_locator[i].platform; Missing be32_to_cpu(). > + data_offset =3D > + be64_to_cpu(dyndisk_header->parent_locator[i].data_offset); > + data_length =3D > + be32_to_cpu(dyndisk_header->parent_locator[i].data_length); > + > + /* Extend the location offset */ > + if (parent_locator_offset < data_offset) { > + parent_locator_offset =3D data_offset; Why is parent_locator_offset and this function's return value int? data_offset is uint64_t and it seems like values could get truncated if int is used. > @@ -278,7 +523,7 @@ static int vpc_open(BlockDriverState *bs, QDict *opti= ons, int flags, > s->bat_offset =3D be64_to_cpu(dyndisk_header->table_offset); > =20 > ret =3D bdrv_pread(bs->file, s->bat_offset, s->pagetable, > - s->max_table_entries * 4); > + s->max_table_entries * 4); > if (ret < 0) { > goto fail; > } Unnecessary whitespace change? > @@ -286,6 +531,48 @@ static int vpc_open(BlockDriverState *bs, QDict *opt= ions, int flags, > s->free_data_block_offset =3D > (s->bat_offset + (s->max_table_entries * 4) + 511) & ~511; > =20 > + /* Read tdbatmap header by offset */ > + if (be32_to_cpu(footer->version) >=3D VHD_VERSION(1, 2)) { > + ret =3D bdrv_pread(bs->file, s->free_data_block_offset, > + tdbatmap_header_buf, TBBATMAP_HEAD_SIZE); > + if (ret < 0) { > + goto fail; > + } > + > + tdbatmap_header =3D (VHDTdBatmapHeader *) tdbatmap_header_bu= f; > + if (!strncmp(tdbatmap_header->magic, "tdbatmap", 8)) { > + s->free_data_block_offset =3D > + be32_to_cpu(tdbatmap_header->batmap_size) * 512 > + + be64_to_cpu(tdbatmap_header->batmap_offset); > + } > + } > + > + if (dyndisk_header->parent_name[0] || dyndisk_header->parent_nam= e[1]) { > + int len; > + > + /* Read parent location from dyn header table */ > + ret =3D parent_locator_offset =3D vpc_read_backing_loc(dyndi= sk_header, > + bs, errp); > + if (ret < 0) { > + goto fail; > + } > + > + /* Fix me : Set parent format to avoid probing to raw in > + * format probe framework */ > + len =3D strlen("vpc"); > + if (sizeof(bs->backing_format) - 1 < len) { > + goto fail; > + } > + pstrcpy(bs->backing_format, sizeof(bs->backing_format), "vpc= "); > + bs->backing_format[len] =3D '\0'; pstrcpy() always NUL-terminates so this is not necessary. > @@ -376,7 +704,7 @@ static inline int64_t get_sector_offset(BlockDriverSt= ate *bs, > bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size= ); > } > =20 > -// printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx= 64 ", bloff: %" PRIx64 "\n", > +// printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx64= ", bloff: %" PRIx64 "\n", > // sector_num, pagetable_index, pageentry_index, > // bitmap_offset, block_offset); > =20 Unnecessary whitespace change? --WhfpMioaduB5tiZL Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJU7eMGAAoJEJykq7OBq3PIhVsIAMNA28eqALsSZVMW2uZ8Ti8w I1APeLDr75GW3ugw1llwoq+h02sM6bH/RpfEkOIXTdlpPrmzMfTkLOHM5dBnKPse fmHr5FRGm+e+6w1s4rUyDOPy8OCqdc0YjjWaafytCkIOqTmY3TXyjm+cWW6yyP10 2nmyMmMc6X4OBU2Wpo4TZ5AWw7lR0nK9jFaqaN0VFsOcf3Hro/yIf1Zbl13MA4qP iVdi+9Y1ClOC9ig+D9zPNblY93J0XL2vPa1I2tF6JtBeqc+wIuKbQ6J+37Tog+BA ap/lU9syUTSwF23BwOw0DGXIkMUP/lWfg55tcmiGoIBw9ovWcxzgNV7FNLhTVYI= =WIqL -----END PGP SIGNATURE----- --WhfpMioaduB5tiZL--