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 e7b53b0..615fe49 100644 --- a/sheep/group.c +++ b/sheep/group.c @@ -1001,11 +1001,6 @@ static void __sd_join_done(struct cpg_event *cevent) } } -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 130515a..26e0a53 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -26,12 +26,12 @@ #define SD_OP_GET_OBJ_LIST 0xA1 #define SD_OP_GET_EPOCH 0XA2 -#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 */ @@ -203,8 +203,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 @@ -248,4 +246,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 |