Skip to contentSkip to conversation

Question about cow format with hexdump

Qemu-devel shhuiw 3 participants 4 messages Sep 3, 2014 – Sep 4, 2014

lore
Share & tools
lore

shhuiw

author
#0 lore raw

Hi,

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.

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=cow size=1048576
-bash-4.1$ qemu-img info dummy
image: dummy
file format: cow
virtual size: 1.0M (1048576 bytes)
disk size: 4.0K

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

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000400 00 00 00 00 00 00 00 00 00 00 00 00 |............|
0000040c

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000410 00 00 00 00 |....|
00000414

4) sectorsize is 512:
-bash-4.1$ hexdump -C dummy -n 1048

00000000  4f 4f 4f 4d 00 00 00 02  00 00 00 00 00 00 00 00  |OOOM............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000410 00 00 00 00 00 10 00 00 |........|
00000418

Can anyone help to explain this? Or how to debug further?

--

Regards,
shhuiw

#1 lore raw
Quoted 2 lines · shhuiw

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.

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.

Quoted 33 lines

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=cow size=1048576
-bash-4.1$ qemu-img info dummy
image: dummy
file format: cow
virtual size: 1.0M (1048576 bytes)
disk size: 4.0K

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

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000400 00 00 00 00 00 00 00 00 00 00 00 00 |............|
0000040c

Quoted 7 lines

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000410 00 00 00 00 |....|
00000414

$ 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 */
	/* 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

#2 lore raw

Am 03.09.2014 um 12:59 hat Stefan Hajnoczi geschrieben:

Quoted 72 lines · shhuiw
Quoted 2 lines

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.

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.

Quoted 33 lines

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=cow size=1048576
-bash-4.1$ qemu-img info dummy
image: dummy
file format: cow
virtual size: 1.0M (1048576 bytes)
disk size: 4.0K

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

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000400 00 00 00 00 00 00 00 00 00 00 00 00 |............|
0000040c

Quoted 7 lines

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000410 00 00 00 00 |....|
00000414

$ 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 */
	/* 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 */
};
Quoted 4 lines

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.

We can at least make it explicit like I did for qcow1 in ea54feff.

Kevin

author
#3 lore raw
In reply to shhuiw

Sorry to trouble you all.

I found the right way: I should use the -o option when I create cow image files. Then hexdump can give full info.

~> touch testcow # maked up backing_file ahead to get non-0s .mtime

~> qemu-img create -f cow -o backing_file=testcow,size=1M dummy Formatting 'dummy', fmt=cow size=1048576 backing_file='testcow'

~> hexdump -C dummy

00000000  4f 4f 4f 4d 00 00 00 02  74 65 73 74 63 6f 77 00  |OOOM....testcow.|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400  00 00 00 00 00 00 00 00  54 08 66 e8 00 00 00 00  |........T.f.....|
00000410  00 10 00 00 00 00 02 00  00 00 00 00 00 00 00 00  |................|
00000420  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000510 00 00 00 00 00 00 00 00 |........|
00000518

--

Regards,
shhuiw

Quoted 62 lines · shhuiw

Hi,

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.

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=cow size=1048576
-bash-4.1$ qemu-img info dummy
image: dummy
file format: cow
virtual size: 1.0M (1048576 bytes)
disk size: 4.0K

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

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000400 00 00 00 00 00 00 00 00 00 00 00 00 |............|
0000040c

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............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000410 00 00 00 00 |....|
00000414

4) sectorsize is 512:
-bash-4.1$ hexdump -C dummy -n 1048

00000000  4f 4f 4f 4d 00 00 00 02  00 00 00 00 00 00 00 00  |OOOM............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*
00000410 00 00 00 00 00 10 00 00 |........|
00000418

Can anyone help to explain this? Or how to debug further?

--

Regards,
shhuiw