Make the code in update_cluster_info a bit more readable by exiting early
if the cluster status isn't ok or halt and thus consolidate all the checks
for it, including the subtile change from checking msg->cluster_status
to sys->status once we did the sys_stat_set, as well as not using the
sys_can_recover shortcut.

Signed-off-by: Christoph Hellwig <[email protected]>

diff --git a/sheep/group.c b/sheep/group.c
index d597c8c..4e83b1e 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -704,23 +704,25 @@ static void update_cluster_info(struct join_message *msg,
        old_vnode_info = current_vnode_info;
        current_vnode_info = alloc_vnode_info(nodes, nr_nodes);
 
-       if (msg->cluster_status == SD_STATUS_OK ||
-           msg->cluster_status == SD_STATUS_HALT) {
-               if (msg->inc_epoch) {
-                       uatomic_inc(&sys->epoch);
-                       log_current_epoch();
-               }
-               /* Fresh node */
-               if (!sys_stat_ok() && !sys_stat_halt()) {
-                       set_cluster_copies(sys->nr_copies);
-                       set_cluster_flags(sys->flags);
-                       set_cluster_ctime(msg->ctime);
-               }
+       if (msg->cluster_status != SD_STATUS_OK &&
+           msg->cluster_status != SD_STATUS_HALT) {
+               sys_stat_set(msg->cluster_status);
+               goto out_put_vnode_info;
+       }
+
+       if (msg->inc_epoch) {
+               uatomic_inc(&sys->epoch);
+               log_current_epoch();
        }
 
-       if (!sys_stat_ok() &&
-           (msg->cluster_status == SD_STATUS_OK ||
-            msg->cluster_status == SD_STATUS_HALT)) {
+       /* Fresh node */
+       if (!sys_stat_ok() && !sys_stat_halt()) {
+               set_cluster_copies(sys->nr_copies);
+               set_cluster_flags(sys->flags);
+               set_cluster_ctime(msg->ctime);
+       }
+
+       if (!sys_stat_ok()) {
                int array_len = nr_nodes * sizeof(struct sd_node);
                struct vdi_bitmap_work *w;
 
@@ -735,18 +737,19 @@ static void update_cluster_info(struct join_message *msg,
 
        sys_stat_set(msg->cluster_status);
 
-       if (sys_can_recover() && msg->inc_epoch) {
+       if (msg->inc_epoch) {
                list_for_each_entry_safe(n, t, &sys->leave_list, list)
                        list_del(&n->list);
                start_recovery(current_vnode_info, old_vnode_info);
        }
 
-       put_vnode_info(old_vnode_info);
-
        if (sys_stat_halt()) {
                if (current_vnode_info->nr_zones >= sys->nr_copies)
                        sys_stat_set(SD_STATUS_OK);
        }
+
+out_put_vnode_info:
+       put_vnode_info(old_vnode_info);
 }
 
 /*

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to