[Sheepdog] [PATCH 1/3] sheep: make sys->stat operation bit-wise

Liu Yuan namei.unix at gmail.com
Thu Oct 20 08:49:55 CEST 2011


From: Liu Yuan <tailai.ly at taobao.com>

Add sys_stat_* helpers and higher level(sys_can_*) API based on them.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/group.c      |    5 ---
 sheep/sheep_priv.h |   71 ++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 4671e0a..401dfcb 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1459,11 +1459,6 @@ static void __sd_join_done(struct cpg_event *cevent)
 		send_join_request(&w->joined);
 }
 
-int sys_flag_nohalt()
-{
-	return sys->flags & SD_FLAG_NOHALT;
-}
-
 static void __sd_leave_done(struct cpg_event *cevent)
 {
 	struct work_leave *w = container_of(cevent, struct work_leave, cev);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 09da642..850dd0d 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -32,12 +32,12 @@
 #define SD_MSG_LEAVE            0x04
 #define SD_MSG_MASTER_TRANSFER  0x05
 
-#define SD_STATUS_OK                0x00
-#define SD_STATUS_WAIT_FOR_FORMAT   0x01
-#define SD_STATUS_WAIT_FOR_JOIN     0x02
-#define SD_STATUS_SHUTDOWN          0x03
-#define SD_STATUS_JOIN_FAILED       0x04
-#define SD_STATUS_HALT              0x05
+#define SD_STATUS_OK                0x00000001
+#define SD_STATUS_WAIT_FOR_FORMAT   0x00000002
+#define SD_STATUS_WAIT_FOR_JOIN     0x00000004
+#define SD_STATUS_SHUTDOWN          0x00000008
+#define SD_STATUS_JOIN_FAILED       0x00000010
+#define SD_STATUS_HALT              0x00000020
 
 #define SD_RES_NETWORK_ERROR    0x81 /* Network error between sheeps */
 
@@ -215,8 +215,6 @@ int get_global_nr_copies(uint32_t *copies);
 int set_cluster_flags(uint16_t flags);
 int get_cluster_flags(uint16_t *flags);
 
-int sys_flag_nohalt(void);
-
 #define NR_GW_WORKER_THREAD 4
 #define NR_IO_WORKER_THREAD 4
 
@@ -260,4 +258,61 @@ static inline int is_myself(uint8_t *addr, uint16_t port)
 		port == sys->this_node.port;
 }
 
+/* Cluster status/flag helper */
+
+static inline int sys_flag_nohalt(void)
+{
+	return sys->flags & SD_FLAG_NOHALT;
+}
+
+static inline int sys_stat_ok(void)
+{
+	return sys->status & SD_STATUS_OK;
+}
+
+static inline int sys_stat_wait_format(void)
+{
+	return sys->status & SD_STATUS_WAIT_FOR_FORMAT;
+}
+
+static inline int sys_stat_wait_join(void)
+{
+	return sys->status & SD_STATUS_WAIT_FOR_JOIN;
+}
+
+static inline int sys_stat_join_failed(void)
+{
+	return sys->status & SD_STATUS_JOIN_FAILED;
+}
+
+static inline int sys_stat_shutdown(void)
+{
+	return sys->status & SD_STATUS_SHUTDOWN;
+}
+
+static inline int sys_stat_halt(void)
+{
+	return sys->status & SD_STATUS_HALT;
+}
+
+static inline void sys_stat_set(uint32_t s)
+{
+	sys->status = s;
+}
+
+static inline uint32_t sys_stat_get(void)
+{
+	return sys->status;
+}
+
+static inline int sys_can_recover(void)
+{
+	return sys_stat_ok() || sys_stat_halt();
+}
+
+static inline int sys_can_halt(void)
+{
+	return sys_stat_ok() && !sys_flag_nohalt();
+}
+
 #endif
-- 
1.7.6.1




More information about the sheepdog mailing list