qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] cow: make padding in the header explicit
@ 2014-09-04  8:58 Stefan Hajnoczi
  2014-09-04  9:26 ` Kevin Wolf
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2014-09-04  8:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, shhuiw, Stefan Hajnoczi

On-disk structures should be marked packed so the compiler does not
insert padding for field alignment.  Padding should be explicit so
on-disk layout is obvious and we don't rely on the architecture-specific
ABI for alignment rules.

The pahole(1) diff shows that the padding is now explicit and offsets
are unchanged:

 	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 */
-
+	uint32_t                   padding;              /*  1036     4 */
 	uint64_t                   size;                 /*  1040     8 */

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/cow.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/cow.c b/block/cow.c
index 6ee4833..5ee9363 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -37,9 +37,10 @@ struct cow_header_v2 {
     uint32_t version;
     char backing_file[1024];
     int32_t mtime;
+    uint32_t padding;
     uint64_t size;
     uint32_t sectorsize;
-};
+} QEMU_PACKED;
 
 typedef struct BDRVCowState {
     CoMutex lock;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-09-05 11:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-04  8:58 [Qemu-devel] [PATCH] cow: make padding in the header explicit Stefan Hajnoczi
2014-09-04  9:26 ` Kevin Wolf
2014-09-04  9:47 ` Benoît Canet
2014-09-04 12:07 ` Eric Blake
2014-09-04 12:57   ` shhuiw
2014-09-04 13:51   ` Stefan Hajnoczi
2014-09-04 14:10     ` Kevin Wolf
2014-09-04 15:43       ` Stefan Hajnoczi
2014-09-05  9:13         ` Kevin Wolf
2014-09-05 11:01         ` Markus Armbruster

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).