[sheepdog] [PATCH v2 1/4] sheep: add option for dual nic support
Liu Yuan
namei.unix at gmail.com
Tue Jan 15 10:12:05 CET 2013
From: Liu Yuan <tailai.ly at taobao.com>
This is a prepare patch, add one option to add another nic for IO requests.
Usage:
sheep -i ip{,port} ...
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
include/internal_proto.h | 6 +++-
include/net.h | 1 +
lib/net.c | 13 ++++++++
sheep/sheep.c | 83 ++++++++++++++++++++++++++++------------------
4 files changed, 70 insertions(+), 33 deletions(-)
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 6e6e5f7..364a478 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -18,8 +18,9 @@
*/
#include <stdint.h>
+#include <netinet/in.h>
-#define SD_SHEEP_PROTO_VER 0x06
+#define SD_SHEEP_PROTO_VER 0x07
#define SD_DEFAULT_COPIES 3
#define SD_MAX_COPIES 8
@@ -175,6 +176,9 @@ struct sd_node_rsp {
struct node_id {
uint8_t addr[16];
uint16_t port;
+ uint8_t io_addr[16];
+ uint16_t io_port;
+ uint8_t pad[4];
};
struct sd_node {
diff --git a/include/net.h b/include/net.h
index 3665f5e..e0bbabd 100644
--- a/include/net.h
+++ b/include/net.h
@@ -56,5 +56,6 @@ int set_keepalive(int fd);
int set_snd_timeout(int fd);
int set_timeout(int fd);
int get_local_addr(uint8_t *bytes);
+bool inetaddr_is_valid(char *addr);
#endif
diff --git a/lib/net.c b/lib/net.c
index 343de0f..77da430 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -574,3 +574,16 @@ err:
return -1;
}
+
+bool inetaddr_is_valid(char *addr)
+{
+ unsigned char buf[INET6_ADDRSTRLEN];
+ int af;
+
+ af = strstr(addr, ":") ? AF_INET6 : AF_INET;
+ if (!inet_pton(af, addr, buf)) {
+ eprintf("Bad address '%s'\n", addr);
+ return false;
+ }
+ return true;
+}
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 9f3965d..be78098 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -47,6 +47,7 @@ static struct sd_option sheep_options[] = {
{'f', "foreground", false, "make the program run in the foreground"},
{'g', "gateway", false, "make the progam run as a gateway mode"},
{'h', "help", false, "display this help and exit"},
+ {'i', "ioaddr", true, "use separate network card to handle IO requests"},
{'j', "journal", true, "use jouranl file to log all the write operations"},
{'l', "loglevel", true, "specify the level of logging detail"},
{'o', "stdout", false, "log to stdout instead of shared logger"},
@@ -341,6 +342,26 @@ static void init_journal_arg(char *arg)
}
}
+static char *io_addr, *io_pt;
+static void init_io_arg(char *arg)
+{
+ const char *host = "host=", *port = "port=";
+ int hl = strlen(host), pl = strlen(port);
+
+ if (!strncmp(host, arg, hl)) {
+ arg += hl;
+ io_addr = arg;
+ } else if (!strncmp(port, arg, pl)) {
+ arg += hl;
+ io_pt = arg;
+ } else {
+ fprintf(stderr, "invalid paramters %s. "
+ "Use '-i host=a.b.c.d,port=xxx'\n",
+ arg);
+ exit(1);
+ }
+}
+
static int init_work_queues(void)
{
if (init_wqueue_eventfd())
@@ -365,28 +386,14 @@ static int init_work_queues(void)
int main(int argc, char **argv)
{
- int ch, longindex;
- int ret, port = SD_LISTEN_PORT;
- const char *dirp = DEFAULT_OBJECT_DIR;
- char *dir;
- bool is_daemon = true;
- bool to_stdout = false;
- int log_level = SDOG_INFO;
- char path[PATH_MAX];
- int64_t zone = -1;
- int64_t free_space = 0;
- int nr_vnodes = SD_DEFAULT_VNODES;
- bool explicit_addr = false;
- int af;
- char *p;
+ int ch, longindex, ret, port = SD_LISTEN_PORT, io_port = SD_LISTEN_PORT;
+ int log_level = SDOG_INFO, af, nr_vnodes = SD_DEFAULT_VNODES;
+ const char *dirp = DEFAULT_OBJECT_DIR, *short_options;
+ char *dir, *p, *pid_file = NULL, *bindaddr = NULL, path[PATH_MAX];
+ bool is_daemon = true, to_stdout = false, explicit_addr = false;
+ int64_t zone = -1, free_space = 0;
struct cluster_driver *cdrv;
- char *pid_file = NULL;
- char *bindaddr = NULL;
- unsigned char buf[sizeof(struct in6_addr)];
- int ipv4 = 0;
- int ipv6 = 0;
struct option *long_options;
- const char *short_options;
signal(SIGPIPE, SIG_IGN);
@@ -422,10 +429,8 @@ int main(int argc, char **argv)
case 'y':
af = strstr(optarg, ":") ? AF_INET6 : AF_INET;
if (!str_to_addr(af, optarg, sys->this_node.nid.addr)) {
- fprintf(stderr,
- "Invalid address: '%s'\n",
+ fprintf(stderr, "Invalid address: '%s'\n",
optarg);
- sdlog_help();
exit(1);
}
explicit_addr = true;
@@ -485,6 +490,24 @@ int main(int argc, char **argv)
case 'w':
init_cache_type(optarg);
break;
+ case 'i':
+ parse_arg(optarg, ",", init_io_arg);
+ af = strstr(io_addr, ":") ? AF_INET6 : AF_INET;
+ if (!str_to_addr(af, io_addr,
+ sys->this_node.nid.io_addr)) {
+ fprintf(stderr, "Bad addr: '%s'\n",
+ io_addr);
+ exit(1);
+ }
+
+ if (io_pt)
+ if (sscanf(io_pt, "%u", &io_port) != 1) {
+ fprintf(stderr, "Bad port '%s'\n",
+ io_pt);
+ exit(1);
+ }
+ sys->this_node.nid.io_port = io_port;
+ break;
case 'j':
uatomic_set_true(&sys->use_journal);
parse_arg(optarg, ",", init_journal_arg);
@@ -495,16 +518,9 @@ int main(int argc, char **argv)
}
break;
case 'b':
- /* validate provided address using inet_pton */
- ipv4 = inet_pton(AF_INET, optarg, buf);
- ipv6 = inet_pton(AF_INET6, optarg, buf);
- if (ipv4 || ipv6) {
- bindaddr = optarg;
- } else {
- fprintf(stderr,
- "Invalid bind address '%s'\n", optarg);
+ if (!inetaddr_is_valid(optarg))
exit(1);
- }
+ bindaddr = optarg;
break;
case 'h':
usage(0);
@@ -560,6 +576,9 @@ int main(int argc, char **argv)
if (ret)
exit(1);
+ if (io_addr && create_listen_port(io_addr, io_port))
+ exit(1);
+
ret = init_unix_domain_socket(dir);
if (ret)
exit(1);
--
1.7.9.5
More information about the sheepdog
mailing list