[sheepdog] [PATCH 1/4] sheep: add option for dual nic support
Liu Yuan
namei.unix at gmail.com
Sun Jan 13 16:16:58 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 | 7 +++--
include/net.h | 1 +
lib/net.c | 13 +++++++++
sheep/sheep.c | 69 +++++++++++++++++++++++++---------------------
4 files changed, 56 insertions(+), 34 deletions(-)
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 6e6e5f7..4a6cefb 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
@@ -173,8 +174,10 @@ struct sd_node_rsp {
};
struct node_id {
- uint8_t addr[16];
+ uint8_t addr[INET6_ADDRSTRLEN];
uint16_t port;
+ uint8_t io_addr[INET6_ADDRSTRLEN];
+ uint16_t io_port;
};
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..bd33968 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"},
@@ -365,28 +366,15 @@ 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];
+ char *io_addr = NULL, *io_pt;
+ 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 +410,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 +471,29 @@ int main(int argc, char **argv)
case 'w':
init_cache_type(optarg);
break;
+ case 'i':
+ io_addr = strtok(optarg, ",");
+ if (!io_addr) {
+ fprintf(stderr, "Bad addr '%s'\n", optarg);
+ exit(1);
+ }
+ 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);
+ }
+
+ io_pt = strtok(NULL, ",");
+ 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 +504,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 +562,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