[sheepdog] [PATCH v5 1/4] move node_to_str() and str_to_node() from sheep/cluster.h to include/internal_proto.h

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Wed Jan 9 08:09:03 CET 2013


shephered uses node_to_str() and str_to_node(), so they should be
moved to the header which can be included by other directories of
sheep/.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 include/internal_proto.h |   41 +++++++++++++++++++++++++++++++++++++++++
 sheep/cluster.h          |   40 ----------------------------------------
 2 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index 6e6e5f7..b4b74a3 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -18,6 +18,7 @@
  */
 
 #include <stdint.h>
+#include "net.h"
 
 #define SD_SHEEP_PROTO_VER 0x06
 
@@ -224,4 +225,44 @@ struct vdi_op_message {
 	uint8_t data[0];
 };
 
+static inline char *node_to_str(const struct sd_node *id)
+{
+	static char str[256];
+	char name[256];
+	int af = AF_INET6;
+	const uint8_t *addr = id->nid.addr;
+
+	/* Find address family type */
+	if (addr[12]) {
+		int  oct_no = 0;
+		while (!addr[oct_no] && oct_no++ < 12)
+			;
+		if (oct_no == 12)
+			af = AF_INET;
+	}
+
+	snprintf(str, sizeof(str), "%s ip:%s port:%d",
+		(af == AF_INET) ? "IPv4" : "IPv6",
+		addr_to_str(name, sizeof(name), id->nid.addr, 0), id->nid.port);
+
+	return str;
+}
+
+static inline struct sd_node *str_to_node(const char *str, struct sd_node *id)
+{
+	int port, af = AF_INET6;
+	char v[8], ip[256];
+
+	sscanf(str, "%s ip:%s port:%d", v, ip, &port);
+	id->nid.port = port;
+
+	if (strcmp(v, "IPv4") == 0)
+		af = AF_INET;
+
+	if (!str_to_addr(af, ip, id->nid.addr))
+		return NULL;
+
+	return id;
+}
+
 #endif /* __INTERNAL_PROTO_H__ */
diff --git a/sheep/cluster.h b/sheep/cluster.h
index d1e711d..a928bb1 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -153,46 +153,6 @@ static inline const char *get_cdrv_option(const struct cluster_driver *cdrv,
 		return NULL;
 }
 
-static inline char *node_to_str(const struct sd_node *id)
-{
-	static char str[256];
-	char name[256];
-	int af = AF_INET6;
-	const uint8_t *addr = id->nid.addr;
-
-	/* Find address family type */
-	if (addr[12]) {
-		int  oct_no = 0;
-		while (!addr[oct_no] && oct_no++ < 12)
-			;
-		if (oct_no == 12)
-			af = AF_INET;
-	}
-
-	snprintf(str, sizeof(str), "%s ip:%s port:%d",
-		(af == AF_INET) ? "IPv4" : "IPv6",
-		addr_to_str(name, sizeof(name), id->nid.addr, 0), id->nid.port);
-
-	return str;
-}
-
-static inline struct sd_node *str_to_node(const char *str, struct sd_node *id)
-{
-	int port, af = AF_INET6;
-	char v[8], ip[256];
-
-	sscanf(str, "%s ip:%s port:%d", v, ip, &port);
-	id->nid.port = port;
-
-	if (strcmp(v, "IPv4") == 0)
-		af = AF_INET;
-
-	if (!str_to_addr(af, ip, id->nid.addr))
-		return NULL;
-
-	return id;
-}
-
 /* callbacks back into sheepdog from the cluster drivers */
 void sd_join_handler(const struct sd_node *joined,
 		     const struct sd_node *members,
-- 
1.7.2.5




More information about the sheepdog mailing list