[sheepdog] [PATCH 6/5] sheep: always access sys->status directly

Christoph Hellwig hch at infradead.org
Thu Jul 19 18:47:19 CEST 2012


A lot of access already need to be direct, e.g. for using switch statements.
Change the remaining instances to also directly access it and remove the wrappers
for it (and sys_flag_nohalt).

sd_leave_handler also got another additional cleanup by using a switch statement
and running the nr_zones check (uselessly but cleaner) for the halt state as well
so that it matches the join side.

Signed-off-by: Christoph Hellwig <hch at lst.de>

---
 sheep/group.c      |   37 ++++++++++++++++++++-----------------
 sheep/ops.c        |   17 ++++++++---------
 sheep/sdnet.c      |    2 +-
 sheep/sheep.c      |    3 ++-
 sheep/sheep_priv.h |   52 ----------------------------------------------------
 5 files changed, 31 insertions(+), 80 deletions(-)

Index: sheepdog/sheep/group.c
===================================================================
--- sheepdog.orig/sheep/group.c	2012-07-19 18:14:11.000000000 +0200
+++ sheepdog/sheep/group.c	2012-07-19 18:22:38.636682134 +0200
@@ -79,7 +79,7 @@ static int get_zones_nr_from(struct sd_n
 
 bool have_enough_zones(void)
 {
-	if (sys_flag_nohalt())
+	if (sys->flags & SD_FLAG_NOHALT)
 		return true;
 
 	if (!current_vnode_info)
@@ -689,7 +689,7 @@ static void do_get_vdi_bitmap(struct wor
 		 * If a new comer try to join the running cluster, it only
 		 * need read one copy of bitmap from one of other members.
 		 */
-		if (sys_stat_wait_format())
+		if (sys->status == SD_STATUS_WAIT_FOR_FORMAT)
 			break;
 	}
 }
@@ -802,7 +802,7 @@ static void update_cluster_info(struct j
 			break;
 		}
 
-		sys_stat_set(msg->cluster_status);
+		sys->status = msg->cluster_status;
 
 		if (msg->inc_epoch) {
 			uatomic_inc(&sys->epoch);
@@ -818,10 +818,10 @@ static void update_cluster_info(struct j
 		}
 
 		if (current_vnode_info->nr_zones >= sys->nr_copies)
-			sys_stat_set(SD_STATUS_OK);
+			sys->status = SD_STATUS_OK;
 		break;
 	default:
-		sys_stat_set(msg->cluster_status);
+		sys->status = msg->cluster_status;
 		break;
 	}
 
@@ -1014,7 +1014,7 @@ void sd_join_handler(struct sd_node *joi
 		for (i = 0; i < nr_members; i++)
 			dprintf("[%x] %s\n", i, node_to_str(members + i));
 
-		if (sys_stat_shutdown())
+		if (sys->status == SD_STATUS_SHUTDOWN)
 			break;
 
 		update_cluster_info(jm, joined, members, nr_members);
@@ -1024,7 +1024,7 @@ void sd_join_handler(struct sd_node *joi
 			vprintf(SDOG_DEBUG, "join Sheepdog cluster\n");
 		break;
 	case CJ_RES_FAIL:
-		if (!sys_stat_wait_join())
+		if (sys->status != SD_STATUS_WAIT_FOR_JOIN)
 			break;
 
 		if (!add_failed_node(le, joined))
@@ -1037,7 +1037,7 @@ void sd_join_handler(struct sd_node *joi
 
 		dprintf("%d == %d + %d\n", nr_local, nr, nr_failed);
 		if (nr_local == nr + nr_failed - nr_delayed_nodes) {
-			sys_stat_set(SD_STATUS_OK);
+			sys->status = SD_STATUS_OK;
 			log_current_epoch();
 		}
 		break;
@@ -1062,7 +1062,7 @@ void sd_join_handler(struct sd_node *joi
 
 		dprintf("%d == %d + %d\n", nr_local, nr, nr_failed);
 		if (nr_local == nr + nr_failed - nr_delayed_nodes) {
-			sys_stat_set(SD_STATUS_OK);
+			sys->status = SD_STATUS_OK;
 			log_current_epoch();
 		}
 
@@ -1083,24 +1083,27 @@ void sd_leave_handler(struct sd_node *le
 	for (i = 0; i < nr_members; i++)
 		dprintf("[%x] %s\n", i, node_to_str(members + i));
 
-	if (sys_stat_shutdown())
+	if (sys->status == SD_STATUS_SHUTDOWN)
 		return;
 
 	old_vnode_info = current_vnode_info;
 	current_vnode_info = alloc_vnode_info(members, nr_members);
 
-	if (sys_can_recover()) {
+	switch (sys->status) {
+	case SD_STATUS_HALT:
+	case SD_STATUS_OK:
 		uatomic_inc(&sys->epoch);
 		log_current_epoch();
 		start_recovery(current_vnode_info, old_vnode_info);
-	}
-	put_vnode_info(old_vnode_info);
 
-	if (sys_can_halt()) {
 		if (current_vnode_info->nr_zones < sys->nr_copies)
-			sys_stat_set(SD_STATUS_HALT);
+			sys->status = SD_STATUS_HALT;
+		break;
+	default:
+		break;
 	}
 
+	put_vnode_info(old_vnode_info);
 	sockfd_cache_del(&left->nid);
 }
 
@@ -1144,14 +1147,14 @@ int create_cluster(int port, int64_t zon
 	dprintf("zone id = %u\n", sys->this_node.zone);
 
 	if (get_latest_epoch() > 0) {
-		sys_stat_set(SD_STATUS_WAIT_FOR_JOIN);
+		sys->status = SD_STATUS_WAIT_FOR_JOIN;
 
 		get_cluster_copies(&sys->nr_copies);
 		get_cluster_flags(&sys->flags);
 
 		sys->epoch = get_latest_epoch();
 	} else {
-		sys_stat_set(SD_STATUS_WAIT_FOR_FORMAT);
+		sys->status = SD_STATUS_WAIT_FOR_FORMAT;
 	}
 
 	INIT_LIST_HEAD(&sys->pending_list);
Index: sheepdog/sheep/ops.c
===================================================================
--- sheepdog.orig/sheep/ops.c	2012-07-18 12:24:32.820168331 +0200
+++ sheepdog/sheep/ops.c	2012-07-19 18:21:41.960014604 +0200
@@ -246,9 +246,9 @@ static int cluster_make_fs(const struct
 	set_cluster_copies(sys->nr_copies);
 	set_cluster_flags(sys->flags);
 	if (have_enough_zones())
-		sys_stat_set(SD_STATUS_OK);
+		sys->status = SD_STATUS_OK;
 	else
-		sys_stat_set(SD_STATUS_HALT);
+		sys->status = SD_STATUS_HALT;
 
 	return SD_RES_SUCCESS;
 }
@@ -256,8 +256,7 @@ static int cluster_make_fs(const struct
 static int cluster_shutdown(const struct sd_req *req, struct sd_rsp *rsp,
 			    void *data)
 {
-	sys_stat_set(SD_STATUS_SHUTDOWN);
-
+	sys->status = SD_STATUS_SHUTDOWN;
 	return SD_RES_SUCCESS;
 }
 
@@ -337,7 +336,7 @@ static int local_stat_cluster(struct req
 	struct sd_rsp *rsp = &req->rp;
 	struct epoch_log *log;
 	int i, max_logs;
-	uint32_t sys_stat = sys_stat_get(), epoch;
+	uint32_t epoch;
 
 	max_logs = rsp->data_length / sizeof(*log);
 	epoch = get_latest_epoch();
@@ -363,7 +362,7 @@ static int local_stat_cluster(struct req
 		epoch--;
 	}
 
-	switch (sys_stat) {
+	switch (sys->status) {
 	case SD_STATUS_OK:
 		return SD_RES_SUCCESS;
 	case SD_STATUS_WAIT_FOR_FORMAT:
@@ -415,7 +414,7 @@ static int cluster_manual_recover(const
 	 * 2) some nodes are physically down (same epoch condition).
 	 * In both case, the nodes(s) stat is WAIT_FOR_JOIN.
 	 */
-	if (!sys_stat_wait_join())
+	if (sys->status != SD_STATUS_WAIT_FOR_JOIN)
 		return SD_RES_MANUAL_RECOVER;
 
 	ret = get_cluster_copies(&c);
@@ -443,9 +442,9 @@ static int cluster_manual_recover(const
 	}
 
 	if (have_enough_zones())
-		sys_stat_set(SD_STATUS_OK);
+		sys->status = SD_STATUS_OK;
 	else
-		sys_stat_set(SD_STATUS_HALT);
+		sys->status = SD_STATUS_HALT;
 
 	vnode_info = get_vnode_info();
 	start_recovery(vnode_info, old_vnode_info);
Index: sheepdog/sheep/sdnet.c
===================================================================
--- sheepdog.orig/sheep/sdnet.c	2012-07-16 11:32:44.100174613 +0200
+++ sheepdog/sheep/sdnet.c	2012-07-19 18:16:45.643343407 +0200
@@ -779,7 +779,7 @@ static void listen_handler(int listen_fd
 	int fd, ret;
 	struct client_info *ci;
 
-	if (sys_stat_shutdown()) {
+	if (sys->status == SD_STATUS_SHUTDOWN) {
 		dprintf("unregistering connection %d\n", listen_fd);
 		unregister_event(listen_fd);
 		return;
Index: sheepdog/sheep/sheep.c
===================================================================
--- sheepdog.orig/sheep/sheep.c	2012-07-18 11:52:40.576805788 +0200
+++ sheepdog/sheep/sheep.c	2012-07-19 18:17:28.206677394 +0200
@@ -315,7 +315,8 @@ int main(int argc, char **argv)
 
 	vprintf(SDOG_NOTICE, "sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
 
-	while (!sys_stat_shutdown() || sys->nr_outstanding_reqs != 0)
+	while (sys->status != SD_STATUS_SHUTDOWN ||
+	       sys->nr_outstanding_reqs != 0)
 		event_loop(-1);
 
 	vprintf(SDOG_INFO, "shutdown\n");
Index: sheepdog/sheep/sheep_priv.h
===================================================================
--- sheepdog.orig/sheep/sheep_priv.h	2012-07-19 18:14:10.000000000 +0200
+++ sheepdog/sheep/sheep_priv.h	2012-07-19 18:22:45.253348903 +0200
@@ -316,58 +316,6 @@ static inline int vnode_is_local(struct
 	return is_myself(v->nid.addr, v->nid.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_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();
-}
-
 /* gateway operations */
 int gateway_read_obj(struct request *req);
 int gateway_write_obj(struct request *req);



More information about the sheepdog mailing list