[sheepdog] [PATCH v7 1/6] move node_to_str() and str_to_node() from sheep/cluster.h to include/sheep.h
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Mon Mar 11 04:48:53 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/sheep.h | 38 ++++++++++++++++++++++++++++++++++++++
sheep/cluster.h | 37 -------------------------------------
2 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/include/sheep.h b/include/sheep.h
index a3bba2d..26b9639 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -300,4 +300,42 @@ static inline int nodes_to_vnodes(struct sd_node *nodes, int nr,
return nr_vnodes;
}
+#define MAX_NODE_STR_LEN 256
+
+static inline char *node_to_str(const struct sd_node *id)
+{
+ static char str[MAX_NODE_STR_LEN];
+ char name[MAX_NODE_STR_LEN];
+ 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;
+ char v[8], ip[MAX_NODE_STR_LEN];
+
+ sscanf(str, "%s ip:%s port:%d", v, ip, &port);
+ id->nid.port = port;
+ if (!str_to_addr(ip, id->nid.addr))
+ return NULL;
+
+ return id;
+}
+
#endif
diff --git a/sheep/cluster.h b/sheep/cluster.h
index df73d06..5e0bfc0 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -25,7 +25,6 @@
/* maximum payload size sent in ->notify and ->unblock */
#define SD_MAX_EVENT_BUF_SIZE (128 * 1024) /* 128k */
-#define MAX_NODE_STR_LEN 256
enum cluster_join_result {
CJ_RES_SUCCESS, /* Success */
@@ -155,42 +154,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[MAX_NODE_STR_LEN];
- char name[MAX_NODE_STR_LEN];
- 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;
- char v[8], ip[MAX_NODE_STR_LEN];
-
- sscanf(str, "%s ip:%s port:%d", v, ip, &port);
- id->nid.port = port;
- if (!str_to_addr(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