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

Christoph Hellwig hch at infradead.org
Thu Jun 7 10:40:37 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>

Index: sheepdog/sheep/group.c
===================================================================
--- sheepdog.orig/sheep/group.c	2012-06-07 04:27:31.000000000 -0400
+++ sheepdog/sheep/group.c	2012-06-07 04:29:08.428008818 -0400
@@ -1031,7 +1031,8 @@ void sd_leave_handler(struct sd_node *le
 	}
 }
 
-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 zon
 	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;
Index: sheepdog/sheep/sheep.c
===================================================================
--- sheepdog.orig/sheep/sheep.c	2012-06-07 04:27:28.000000000 -0400
+++ sheepdog/sheep/sheep.c	2012-06-07 04:28:41.403874812 -0400
@@ -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);
Index: sheepdog/sheep/sheep_priv.h
===================================================================
--- sheepdog.orig/sheep/sheep_priv.h	2012-06-07 04:27:28.000000000 -0400
+++ sheepdog/sheep/sheep_priv.h	2012-06-07 04:28:41.403874812 -0400
@@ -249,7 +249,8 @@ void resume_wait_obj_requests(uint64_t o
 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