From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPSsb-0006QC-GW for qemu-devel@nongnu.org; Thu, 04 Sep 2014 04:59:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPSsV-0004KE-CT for qemu-devel@nongnu.org; Thu, 04 Sep 2014 04:58:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPSsV-0004K7-5Q for qemu-devel@nongnu.org; Thu, 04 Sep 2014 04:58:51 -0400 From: Stefan Hajnoczi Date: Thu, 4 Sep 2014 09:58:41 +0100 Message-Id: <1409821121-20645-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH] cow: make padding in the header explicit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , shhuiw@163.com, 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 --- 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