[sheepdog] [PATCH 2/2] sheep: add an option to override the advertised address

Christoph Hellwig hch at infradead.org
Wed Jun 6 14:39:29 CEST 2012


Allow users to override the address advertised to other sheep.  This is
important for setups where the computers running sheep nodes have multiple
network interfaces and we need to use a specific one.

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

diff --git a/sheep/group.c b/sheep/group.c
index 71c64ca..4715651 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1031,7 +1031,8 @@ void sd_leave_handler(struct sd_node *left, struct sd_node *members,
 	}
 }
 
-int create_cluster(int port, int64_t zone, int nr_vnodes)
+int create_cluster(int port, int64_t zone, int nr_vnodes,
+		bool explicit_addr)
 {
 	int ret;
 
@@ -1050,12 +1051,14 @@ int create_cluster(int port, int64_t zone, int nr_vnodes)
 	if (ret < 0)
 		return -1;
 	
-	if (sys->cdrv->get_local_addr)
-		ret = sys->cdrv->get_local_addr(sys->this_node.addr);
-	else
-		ret = get_local_addr(sys->this_node.addr);
-	if (ret < 0)
-		return -1;
+	if (!explicit_addr) {
+		if (sys->cdrv->get_local_addr)
+			ret = sys->cdrv->get_local_addr(sys->this_node.addr);
+		else
+			ret = get_local_addr(sys->this_node.addr);
+		if (ret < 0)
+			return -1;
+	}
 
 	sys->this_node.port = port;
 	sys->this_node.nr_vnodes = nr_vnodes;
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 491f49f..323419f 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -44,6 +44,7 @@ static struct option const long_options[] = {
 	{"help", no_argument, NULL, 'h'},
 	{"nr_io_worker", required_argument, NULL, 'i'},
 	{"loglevel", required_argument, NULL, 'l'},
+	{"myaddr", required_argument, NULL, 'y'},
 	{"stdout", no_argument, NULL, 'o'},
 	{"port", required_argument, NULL, 'p'},
 	{"vnodes", required_argument, NULL, 'v'},
@@ -52,7 +53,7 @@ static struct option const long_options[] = {
 	{NULL, 0, NULL, 0},
 };
 
-static const char *short_options = "ac:dDfg:Ghi:l:op:v:Wz:";
+static const char *short_options = "ac:dDfg:Ghi:l:op:v:Wy:z:";
 
 static void usage(int status)
 {
@@ -78,6 +79,7 @@ Options:\n\
   -p, --port              specify the TCP port on which to listen\n\
   -v, --vnodes            specify the number of virtual nodes\n\
   -W, --disable-cache     disable writecache\n\
+  -y, --myaddr            specify the address advertised to other sheep\n\
   -z, --zone              specify the zone id\n\
 ", PACKAGE_VERSION, program_name);
 	exit(status);
@@ -112,6 +114,8 @@ int main(int argc, char **argv)
 	char path[PATH_MAX];
 	int64_t zone = -1;
 	int nr_vnodes = SD_DEFAULT_VNODES;
+	bool explicit_addr = false;
+	int af;
 	char *p;
 	struct cluster_driver *cdrv;
 	int enable_write_cache = 1; /* enabled by default */
@@ -142,6 +146,17 @@ int main(int argc, char **argv)
 				exit(1);
 			}
 			break;
+		case 'y':
+			af = strstr(optarg, ":") ? AF_INET6 : AF_INET;
+			if (!str_to_addr(af, optarg, sys->this_node.addr)) {
+				fprintf(stderr,
+					"Invalid address: '%s'\n",
+					optarg);
+				sdlog_help();
+				exit(1);
+			}
+			explicit_addr = true;
+			break;
 		case 'd':
 			/* removed soon. use loglevel instead */
 			log_level = SDOG_DEBUG;
@@ -254,7 +269,7 @@ int main(int argc, char **argv)
 	if (ret)
 		exit(1);
 
-	ret = create_cluster(port, zone, nr_vnodes);
+	ret = create_cluster(port, zone, nr_vnodes, explicit_addr);
 	if (ret) {
 		eprintf("failed to create sheepdog cluster\n");
 		exit(1);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 45d3852..f38259e 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -249,7 +249,8 @@ void resume_wait_obj_requests(uint64_t oid);
 void resume_wait_recovery_requests(void);
 void flush_wait_obj_requests(void);
 
-int create_cluster(int port, int64_t zone, int nr_vnodes);
+int create_cluster(int port, int64_t zone, int nr_vnodes,
+		bool explicit_addr);
 int leave_cluster(void);
 
 void queue_cluster_request(struct request *req);



More information about the sheepdog mailing list