[Sheepdog] [PATCH v2 2/5] sheep: add support for cluster driver-specific option

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed Nov 2 10:59:23 CET 2011


You can specify cluster driver-specific options as follows:

 $ sheep /store -c [name]:[options]

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/cluster.h          |   29 ++++++++++++++++++++++++++++-
 sheep/cluster/corosync.c |    3 ++-
 sheep/group.c            |   12 +++---------
 sheep/sheep.c            |   10 +++-------
 sheep/sheep_priv.h       |    1 +
 5 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/sheep/cluster.h b/sheep/cluster.h
index 11e2922..352a844 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -53,7 +53,8 @@ struct cluster_driver {
 	 * may be used with the poll(2) to monitor cluster events.  On
 	 * error, returns -1.
 	 */
-	int (*init)(struct cdrv_handlers *handlers, uint8_t *myaddr);
+	int (*init)(struct cdrv_handlers *handlers, const char *option,
+		    uint8_t *myaddr);
 
 	/*
 	 * Join the cluster
@@ -129,6 +130,32 @@ 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;
+	int len;
+
+	FOR_EACH_CLUSTER_DRIVER(cdrv) {
+		len = strlen(cdrv->name);
+
+		if (strncmp(cdrv->name, name, len) == 0 &&
+		    (name[len] == ':' || name[len] == '\0'))
+			return cdrv;
+	}
+
+	return NULL;
+}
+
+static inline const char *get_cdrv_option(struct cluster_driver *cdrv,
+					  const char *arg)
+{
+	int len = strlen(cdrv->name);
+
+	if (arg[len] == ':')
+		return strdup(arg + len + 1);
+	else
+		return NULL;
+}
 
 static inline char *node_to_str(struct sheepdog_node_list_entry *id)
 {
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index 05bc458..e4c5668 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -571,7 +571,8 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 	__corosync_dispatch();
 }
 
-static int corosync_init(struct cdrv_handlers *handlers, uint8_t *myaddr)
+static int corosync_init(struct cdrv_handlers *handlers, const char *option,
+			 uint8_t *myaddr)
 {
 	int ret, fd;
 	uint32_t nodeid;
diff --git a/sheep/group.c b/sheep/group.c
index bfdadbf..daf3db5 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1324,7 +1324,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,
@@ -1332,16 +1331,11 @@ 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");
+		dprintf("use corosync cluster driver as default\n");
 	}
 
-	fd = sys->cdrv->init(&handlers, sys->this_node.addr);
+	fd = sys->cdrv->init(&handlers, sys->cdrv_option, sys->this_node.addr);
 	if (fd < 0)
 		return -1;
 
diff --git a/sheep/sheep.c b/sheep/sheep.c
index ad2e515..00fbe7b 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -142,13 +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);
 				printf("Supported drivers:");
@@ -158,6 +152,8 @@ int main(int argc, char **argv)
 				printf("\n");
 				exit(1);
 			}
+
+			sys->cdrv_option = get_cdrv_option(sys->cdrv, optarg);
 			break;
 		case 'h':
 			usage(0);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 8a945ea..f57eba7 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -106,6 +106,7 @@ struct data_object_bmap {
 
 struct cluster_info {
 	struct cluster_driver *cdrv;
+	const char *cdrv_option;
 
 	/* set after finishing the JOIN procedure */
 	int join_finished;
-- 
1.7.2.5




More information about the sheepdog mailing list