Received: from eggs.gnu.org ([2001:4830:134:3::10]:57083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPCb9-0002zR-CJ for qemu-devel@nongnu.org; Wed, 03 Sep 2014 11:35:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPCb4-0003TC-HZ for qemu-devel@nongnu.org; Wed, 03 Sep 2014 11:35:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPCb4-0003Sz-69 for qemu-devel@nongnu.org; Wed, 03 Sep 2014 11:35:46 -0400 Date: Wed, 3 Sep 2014 17:35:02 +0200 From: Kevin Wolf Message-ID: <20140903153502.GK7717@noname.str.redhat.com> References: <6c9b670c.6435.14839faf35e.Coremail.shhuiw@163.com> <20140903105943.GH28095@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7AUc2qLy4jB3hD7Z" Content-Disposition: inline In-Reply-To: <20140903105943.GH28095@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] Question about cow format with hexdump List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: shhuiw , "qemu-devel@nongnu.org" --7AUc2qLy4jB3hD7Z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 03.09.2014 um 12:59 hat Stefan Hajnoczi geschrieben: > On Wed, Sep 03, 2014 at 01:27:00PM +0800, shhuiw wrote: > > I'm reading the source code of cow.c: https://github.com/qemu/qemu/blob= /master/block/cow.c > > and try to understand the format better. >=20 > The 'cow' format is an old format that is rarely used. It's not a good > example. >=20 > qcow2 is actively developed and performs better. Unfortunately it is a > lot more complex. >=20 > > I created a cow format imagefile and can run 'qume-img info' to query t= he header info > > -----------------------------------------------------------------------= -------- > > -bash-4.1$ qemu-img create -f cow dummy 1M > > Formatting 'test/dummy', fmt=3Dcow size=3D1048576=20 > > -bash-4.1$ qemu-img info dummy=20 > > image: dummy > > file format: cow > > virtual size: 1.0M (1048576 bytes) > > disk size: 4.0K > >=20 > >=20 > > But when I used hexdump to dis the header part, I cannot find all info = recorded: > > (compared the define of struct cow_header_v2 and cow_create()) > > -----------------------------------------------------------------------= ------- > > 1) recognize the magic and version info: > > -bash-4.1$ hexdump -C dummy -n 8 > > 00000000 4f 4f 4f 4d 00 00 00 02 |OOOM....| > > 00000008 > >=20 > > 2) backing_file and mtime fields are 0s: = # I think the "dummy" should be recorded > > -bash-4.1$ hexdump -C dummy -n 1032 > > 00000000 4f 4f 4f 4d 00 00 00 02 00 00 00 00 00 00 00 00 |OOOM......= =2E.....| > > 00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |..........= =2E.....| > > * > > 00000400 00 00 00 00 00 00 00 00 |........| > > 00000408 > > -bash-4.1$ hexdump -C dummy -n 1036 > > 00000000 4f 4f 4f 4d 00 00 00 02 00 00 00 00 00 00 00 00 |OOOM......= =2E.....| > > 00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |..........= =2E.....| > > * > > 00000400 00 00 00 00 00 00 00 00 00 00 00 00 |..........= =2E.| > > 0000040c > >=20 > > 3) size field is 0s: > > -bash-4.1$ hexdump -C dummy -n 1044 = # size should be 1M > > 00000000 4f 4f 4f 4d 00 00 00 02 00 00 00 00 00 00 00 00 |OOOM......= =2E.....| > > 00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |..........= =2E.....| > > * > > 00000410 00 00 00 00 |....| > > 00000414 >=20 > $ sudo yum install dwarves > $ pahole block/cow.o > ... > struct cow_header_v2 { > uint32_t magic; /* 0 4 */ > uint32_t version; /* 4 4 */ > char backing_file[1024]; /* 8 1024 */ > /* --- cacheline 16 boundary (1024 bytes) was 8 bytes ago --- */ > int32_t mtime; /* 1032 4 */ >=20 > /* XXX 4 bytes hole, try to pack */ >=20 > uint64_t size; /* 1040 8 */ > uint32_t sectorsize; /* 1048 4 */ >=20 > /* size: 1056, cachelines: 17, members: 6 */ > /* sum members: 1048, holes: 1, sum holes: 4 */ > /* padding: 4 */ > /* last cacheline: 32 bytes */ > }; >=20 > Ooops, the compiler has inserted padding into the struct because the > size field was not aligned. >=20 > We can't change this because QEMU must stay backwards compatible. We can at least make it explicit like I did for qcow1 in ea54feff. Kevin --7AUc2qLy4jB3hD7Z Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJUBzUmAAoJEH8JsnLIjy/WFVcQAMPDWh6mGoiIwEpPlqbObwH9 TPVraEc9x6JoyyH8/T6NsoLmwcDed4ssJ9AIsirvGLxyQRTrpdT3Y3Rbkvugwkc0 USDj1OkxkDYi4TysZqiq4iaxS4xcosQPM6m/XFDHWZhPL0hE6vlnJmPOZXg0VWEe nw/ZzOfvi0YSacSn/J5gShqKffKjXg5IzQ1ZC0eelPqyQSDD10NGBqe+tmqaUkKF 7vdGeFnOQ4xUplIA5Q4KWgVYA/i9DIvtFD69aGnbXWEOjI+oMMNRiOCquBJif73W j3mzq5vaKK0G786ZuWioX0//11ADg7SuDrQox/bFH2p26t0hhreFVcs1pbN/cZkt /BQ9d9Mb791CET80yRYqXSAnTjFn5W/e+n800auRhVwMDXr44Fakr32bqWdkjeS7 mliA46Lf+etpnco7fVpr5AqM1xTALisbdBXBctDHCHMpQx7GPGv/WebWyqBl6OwI FLXQbiIe3+CH/bWre+jLPfgdfKeuCV2RIOtC+CodGkpG0xh3PHS5HZQyN9lg6J7D GpY2e1JOKuCxbU6o4AZrhuT/YewxX16beSaqOdmCTAaMFfy4badt/q4h0XrzHzKv Ci1BdpHW+L3jyhuqWo64mrj0RlfGQmQsIjmmMXhseUBsM+Dt1n/Elu8PaDEhfhT+ MzQU6ZIlzrMwfIJ1BSmh =LhiE -----END PGP SIGNATURE----- --7AUc2qLy4jB3hD7Z--