[sheepdog] [PATCH 5/5] sheep: check store format at compile time

MORITA Kazutaka morita.kazutaka at gmail.com
Fri May 31 19:15:50 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This tries to detect unintentional break of the backend format.  Of
course, this check is not enough, but much better than doing nothing.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/internal_proto.h |    8 ++++++++
 sheep/config.c           |    7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 91450a0..bddb5dc 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -120,6 +120,8 @@ struct node_id {
 	uint8_t pad[4];
 };
 
+#define SD_NODE_SIZE 56
+
 struct sd_node {
 	struct node_id  nid;
 	uint16_t	nr_vnodes;
@@ -201,4 +203,10 @@ enum cluster_join_result {
 	CJ_RES_MASTER_TRANSFER,
 };
 
+static inline __attribute__((used)) void __sd_epoch_format_build_bug_ons(void)
+{
+	/* never called, only for checking BUILD_BUG_ON()s */
+	BUILD_BUG_ON(sizeof(struct sd_node) != SD_NODE_SIZE);
+}
+
 #endif /* __INTERNAL_PROTO_H__ */
diff --git a/sheep/config.c b/sheep/config.c
index bc7c98a..26840e9 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -18,6 +18,7 @@
 #include "sheep_priv.h"
 
 #define SD_FORMAT_VERSION 0x0002
+#define SD_CONFIG_SIZE 40
 
 static struct sheepdog_config {
 	uint64_t ctime;
@@ -198,3 +199,9 @@ int get_node_space(uint64_t *space)
 
 	return SD_RES_SUCCESS;
 }
+
+static inline __attribute__((used)) void __sd_config_format_build_bug_ons(void)
+{
+	/* never called, only for checking BUILD_BUG_ON()s */
+	BUILD_BUG_ON(sizeof(struct sheepdog_config) != SD_CONFIG_SIZE);
+}
-- 
1.7.9.5




More information about the sheepdog mailing list