[Patch 2/3] chunkd: use "auto" keyword

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The current implementation of automatic listening ports was configured
implicitly by adding <PortFile> clause. This turned out to be a silly
idea. A special keyword for <Port> is more convenient. Also, we do not
need to use /dev/null in <PortFile> anymore.

The configuration is not strictly speaking compatible, but since
nobody should be using auto ports in production anyway, impact on
installations should be nil. But this must be built after the support
for "-p auto" is added to CLD.

Signed-off-by: Pete Zaitcev <zaitcev@xxxxxxxxxx>

diff -urp -X dontdiff chunkd-m/doc/setup.txt chunkd-tip/doc/setup.txt
--- chunkd-m/doc/setup.txt	2009-09-10 21:20:17.322717905 -0600
+++ chunkd-tip/doc/setup.txt	2009-09-29 11:46:44.683272442 -0600
@@ -39,6 +39,15 @@ _cld._udp.phx2.ex.com has SRV record 10 
    not a great idea to specify interfaces, since they often use IPv6 or
    acquire IP addresses from DHCP. So, just specify a port.
 
+   An option exists to let the server to listen on a random port with
+   the "auto" keyword:
+
+	<Listen>auto</Listen>
+
+   This works with CLD-aware clients that find the connection information
+   from records like /chunk-picbak/*. It's not commonly used in real clouds
+   but may be beneficial in chroots and other odd environments.
+
 *) choose pathname (dir + filename) where daemon should store its
    PID file. Default is /var/run/chunkd.pid, but it limits you to
    one Chunk daemon per node, which is usual in clouds.
diff -urp -X dontdiff chunkd-m/server/config.c chunkd-tip/server/config.c
--- chunkd-m/server/config.c	2009-09-10 21:20:17.328715747 -0600
+++ chunkd-tip/server/config.c	2009-09-29 11:24:18.169224959 -0600
@@ -131,13 +131,8 @@ static void cfg_elm_end_listen(struct co
 		return;
 	}
 
-	if (cc->tmp_listen.port && cc->tmp_listen.port_file) {
-		applog(LOG_ERR, "cfgfile: Listen with both Port and PortFile");
-		goto err;
-	}
-
-	if (!cc->tmp_listen.port && !cc->tmp_listen.port_file) {
-		applog(LOG_ERR, "cfgfile: Listen with no Port or PortFile");
+	if (!cc->tmp_listen.port) {
+		applog(LOG_ERR, "cfgfile: Listen with no Port");
 		goto err;
 	}
 
@@ -318,7 +313,8 @@ static void cfg_elm_end (GMarkupParseCon
 
 		if (cc->in_listen) {
 			n = strtol(cc->text, NULL, 10);
-			if (n > 0 && n < 65536) {
+			if ((n > 0 && n < 65536) ||
+			   !strcmp(cc->text, "auto")) {
 				free(cc->tmp_listen.port);
 				cc->tmp_listen.port = cc->text;
 			} else {
diff -urp -X dontdiff chunkd-m/server/server.c chunkd-tip/server/server.c
--- chunkd-m/server/server.c	2009-09-10 21:20:17.329715602 -0600
+++ chunkd-tip/server/server.c	2009-09-29 10:53:25.827153407 -0600
@@ -1018,6 +1018,23 @@ err_out:
 	cli_free(cli);
 }
 
+static int net_write_port(const char *port_file, const char *port_str)
+{
+	FILE *portf;
+	int rc;
+
+	portf = fopen(port_file, "w");
+	if (portf == NULL) {
+		rc = errno;
+		applog(LOG_INFO, "Cannot create port file %s: %s",
+		       port_file, strerror(rc));
+		return -rc;
+	}
+	fprintf(portf, "%s\n", port_str);
+	fclose(portf);
+	return 0;
+}
+
 static int net_open_socket(const struct listen_cfg *cfg,
 			   int addr_fam, int sock_type, int sock_prot,
 			   int addr_len, void *addr_ptr)
@@ -1089,10 +1106,8 @@ static int net_open_socket(const struct 
  */
 static int net_open_any(struct listen_cfg *cfg)
 {
-	char *portfile = cfg->port_file;
 	struct sockaddr_in addr4;
 	struct sockaddr_in6 addr6;
-	FILE *portf;
 	int fd4, fd6;
 	socklen_t addr_len;
 	unsigned short port;
@@ -1139,24 +1154,17 @@ static int net_open_any(struct listen_cf
 		port = ntohs(addr4.sin_port);
 	}
 
-	applog(LOG_INFO, "Listening on port %u file %s", port, portfile);
+	applog(LOG_INFO, "Listening on auto port %u", port);
 
+	free(cfg->port);
 	rc = asprintf(&cfg->port, "%u", port);
 	if (rc < 0) {
 		applog(LOG_ERR, "OOM");
 		return -ENOMEM;
 	}
 
-	portf = fopen(portfile, "w");
-	if (portf == NULL) {
-		rc = errno;
-		applog(LOG_INFO, "Cannot create port file %s: %s",
-		       portfile, strerror(rc));
-		return -rc;
-	}
-	fprintf(portf, "%u\n", port);
-	fclose(portf);
-
+	if (cfg->port_file)
+		return net_write_port(cfg->port_file, cfg->port);
 	return 0;
 }
 
@@ -1213,12 +1221,14 @@ static int net_open_known(const struct l
 			    listen_serv, sizeof(listen_serv),
 			    NI_NUMERICHOST | NI_NUMERICSERV);
 
-		applog(LOG_INFO, "Listening on %s port %s",
+		applog(LOG_INFO, "Listening on host %s port %s",
 		       listen_host, listen_serv);
 	}
 
 	freeaddrinfo(res0);
 
+	if (cfg->port_file)
+		net_write_port(cfg->port_file, cfg->port);
 	return 0;
 
 err_out:
@@ -1227,7 +1237,7 @@ err_out:
 
 static int net_open(struct listen_cfg *cfg)
 {
-	if (cfg->port_file)
+	if (!strcmp(cfg->port, "auto"))
 		return net_open_any(cfg);
 	else
 		return net_open_known(cfg);
diff -urp -X dontdiff chunkd-m/test/server-test.cfg chunkd-tip/test/server-test.cfg
--- chunkd-m/test/server-test.cfg	2009-09-10 21:20:17.336715752 -0600
+++ chunkd-tip/test/server-test.cfg	2009-09-29 11:44:05.962218307 -0600
@@ -5,10 +5,12 @@
 </SSL>
 
 <Listen>
+	<Port>auto</Port>
 	<PortFile>chunkd.port</PortFile>
 </Listen>
 
 <Listen>
+	<Port>auto</Port>
 	<PortFile>chunkd-ssl.port</PortFile>
 	<Encrypt>true</Encrypt>
 </Listen>
diff -urp -X dontdiff chunkd-m/test/start-daemon.real chunkd-tip/test/start-daemon.real
--- chunkd-m/test/start-daemon.real	2009-09-10 21:31:52.957718587 -0600
+++ chunkd-tip/test/start-daemon.real	2009-09-29 09:46:01.956156333 -0600
@@ -11,7 +11,7 @@ then
 	exit 1
 fi
 
-/usr/sbin/cld -d data/cld -P cld.pid --port-file=cld.port  -E
+/usr/sbin/cld -d data/cld -P cld.pid -p auto --port-file=cld.port -E
 
 ../server/chunkd -C $top_srcdir/test/server-test.cfg -E $*
 
diff -urp -X dontdiff chunkd-m/test/start-daemon.real.in chunkd-tip/test/start-daemon.real.in
--- chunkd-m/test/start-daemon.real.in	2009-09-10 21:20:17.337719649 -0600
+++ chunkd-tip/test/start-daemon.real.in	2009-09-29 09:44:01.765251512 -0600
@@ -11,7 +11,7 @@ then
 	exit 1
 fi
 
-@CLDC_CMD@ -d data/cld -P cld.pid --port-file=cld.port  -E
+@CLDC_CMD@ -d data/cld -P cld.pid -p auto --port-file=cld.port -E
 
 ../server/chunkd -C $top_srcdir/test/server-test.cfg -E $*
 
--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Fedora Clound]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux