[sheepdog] [PATCH 2/2] misc: check 64-bit alignment of structs for message

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Mar 19 05:03:47 CET 2013


This patch adds check of alignment of structs defined in
internal_proto.h. check_alignment_of_structs() does that but this
function doesn't have to becalled. The checking is done in build time.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 include/internal_proto.h |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 6f1fdb3..ff61cec 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -20,6 +20,8 @@
 #include <stdint.h>
 #include <netinet/in.h>
 
+#include "util.h"
+
 #define SD_SHEEP_PROTO_VER 0x07
 
 #define SD_DEFAULT_COPIES 3
@@ -229,4 +231,25 @@ struct vdi_op_message {
 	uint8_t data[0];
 };
 
+static inline void check_alignment_of_structs(void)
+{
+	/*
+	 * This function doesn't have to be called.
+	 * It does only checking of size of the below structs with
+	 * BUILD_BUG_ON(). They must be aligned with 64bit.
+	 */
+	BUILD_BUG_ON(sizeof(struct sd_so_req) % 8);
+	BUILD_BUG_ON(sizeof(struct sd_so_rsp) % 8);
+	BUILD_BUG_ON(sizeof(struct sd_list_req) % 8);
+	BUILD_BUG_ON(sizeof(struct sd_list_rsp) % 8);
+	BUILD_BUG_ON(sizeof(struct sd_node_req) % 8);
+	BUILD_BUG_ON(sizeof(struct sd_node_rsp) % 8);
+
+	BUILD_BUG_ON(sizeof(struct node_id) % 8);
+	BUILD_BUG_ON(sizeof(struct sd_node) % 8);
+	BUILD_BUG_ON(sizeof(struct epoch_log) % 8);
+	BUILD_BUG_ON(sizeof(struct join_message) % 8);
+	BUILD_BUG_ON(sizeof(struct vdi_op_message) % 8);
+}
+
 #endif /* __INTERNAL_PROTO_H__ */
-- 
1.7.2.5




More information about the sheepdog mailing list