From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8I6-0004uW-57 for qemu-devel@nongnu.org; Wed, 03 Sep 2014 06:59:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XP8Hz-000704-Q7 for qemu-devel@nongnu.org; Wed, 03 Sep 2014 06:59:54 -0400 Received: from mail-wg0-x22b.google.com ([2a00:1450:400c:c00::22b]:61149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XP8Hz-0006xQ-FP for qemu-devel@nongnu.org; Wed, 03 Sep 2014 06:59:47 -0400 Received: by mail-wg0-f43.google.com with SMTP id a1so8179897wgh.2 for ; Wed, 03 Sep 2014 03:59:46 -0700 (PDT) Date: Wed, 3 Sep 2014 11:59:43 +0100 From: Stefan Hajnoczi Message-ID: <20140903105943.GH28095@stefanha-thinkpad.redhat.com> References: <6c9b670c.6435.14839faf35e.Coremail.shhuiw@163.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="aF3LVLvitz/VQU3c" Content-Disposition: inline In-Reply-To: <6c9b670c.6435.14839faf35e.Coremail.shhuiw@163.com> Subject: Re: [Qemu-devel] Question about cow format with hexdump List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: shhuiw Cc: "qemu-devel@nongnu.org" --aF3LVLvitz/VQU3c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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/m= aster/block/cow.c > and try to understand the format better. The 'cow' format is an old format that is rarely used. It's not a good example. qcow2 is actively developed and performs better. Unfortunately it is a lot more complex. > I created a cow format imagefile and can run 'qume-img info' to query the= 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 re= corded: > (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 |............| > 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 $ sudo yum install dwarves $ pahole block/cow.o =2E.. 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 */ /* XXX 4 bytes hole, try to pack */ uint64_t size; /* 1040 8 */ uint32_t sectorsize; /* 1048 4 */ /* size: 1056, cachelines: 17, members: 6 */ /* sum members: 1048, holes: 1, sum holes: 4 */ /* padding: 4 */ /* last cacheline: 32 bytes */ }; Ooops, the compiler has inserted padding into the struct because the size field was not aligned. We can't change this because QEMU must stay backwards compatible. Stefan --aF3LVLvitz/VQU3c Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUBvSfAAoJEJykq7OBq3PIcGoH/22axLECMFtUGg2kfgdypoc9 FMvtBdvqtFz01xYTTbeyd18kpTtDyeE/SLCt+ZmrhdVbncifax//KBIGbg+J5yuS 8NDxMc/Km7RJRkBWTbwA3TQgyVWmUboNg4XS8F6fpOPP1jIbq+3a2CiudPGSAVWL 2EEOzF5jASCQvJ5m/6szzfTSvoI2whsn+u327EMtrfhd9QUBtQMyf21nfHnEIKxH UrCaUu1TfRgeJmI0ITRAli17H0v3vv0DAK1CXw8SxhtAPSMtcljaZ+/+aD6l4dIX Q07eMXV8dORyPsYDP3evJTeflXd+uTyVFUqfpHAs4EnwXPm1hon0nBFnsfwBayo= =K3Q+ -----END PGP SIGNATURE----- --aF3LVLvitz/VQU3c--