Signed-off-by: MORITA Kazutaka <[email protected]>
---
 sheep/cluster.h |   11 +++++++++++
 sheep/group.c   |   14 +++++++-------
 sheep/sheep.c   |    7 +------
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/sheep/cluster.h b/sheep/cluster.h
index 11e2922..e10e897 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -129,6 +129,17 @@ static void __attribute__((constructor)) regist_ ## 
driver(void) { \
 #define FOR_EACH_CLUSTER_DRIVER(driver) \
        list_for_each_entry(driver, &cluster_drivers, list)
 
+static inline struct cluster_driver *find_cdrv(const char *name)
+{
+       struct cluster_driver *cdrv;
+
+       FOR_EACH_CLUSTER_DRIVER(cdrv) {
+               if (strcmp(cdrv->name, name) == 0)
+                       return cdrv;
+       }
+
+       return NULL;
+}
 
 static inline char *node_to_str(struct sheepdog_node_list_entry *id)
 {
diff --git a/sheep/group.c b/sheep/group.c
index d9bf201..b629654 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1260,7 +1260,6 @@ oom:
 int create_cluster(int port, int64_t zone)
 {
        int fd, ret;
-       struct cluster_driver *cdrv;
        struct cdrv_handlers handlers = {
                .join_handler = sd_join_handler,
                .leave_handler = sd_leave_handler,
@@ -1268,12 +1267,13 @@ int create_cluster(int port, int64_t zone)
        };
 
        if (!sys->cdrv) {
-               FOR_EACH_CLUSTER_DRIVER(cdrv) {
-                       if (strcmp(cdrv->name, "corosync") == 0) {
-                               dprintf("use corosync driver as default\n");
-                               sys->cdrv = cdrv;
-                               break;
-                       }
+               sys->cdrv = find_cdrv("corosync");
+               if (sys->cdrv)
+                       dprintf("use corosync cluster driver as default\n");
+               else {
+                       /* corosync cluster driver is not compiled */
+                       sys->cdrv = find_cdrv("local");
+                       dprintf("use local cluster driver as default\n");
                }
        }
 
diff --git a/sheep/sheep.c b/sheep/sheep.c
index ad2e515..f7f9035 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -142,12 +142,7 @@ int main(int argc, char **argv)
                        sys->this_node.zone = zone;
                        break;
                case 'c':
-                       FOR_EACH_CLUSTER_DRIVER(cdrv) {
-                               if (strcmp(cdrv->name, optarg) == 0) {
-                                       sys->cdrv = cdrv;
-                                       break;
-                               }
-                       }
+                       sys->cdrv = find_cdrv(optarg);
 
                        if (!sys->cdrv) {
                                printf("No such cluster driver, %s\n", optarg);
-- 
1.7.2.5

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

Reply via email to