[sheepdog] [PATCH v2 1/3] 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
Mon Nov 12 09:58:17 CET 2012
sheepkeeper 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 a45b818..722fab0 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include "sheepdog_proto.h"
+#include "net.h"
#define SD_SHEEP_PROTO_VER 0x06
@@ -223,4 +224,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 2679c19..aa0ede6 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