[Ocfs2-tools-devel] [PATCH 06/25] libo2cb: Extend libo2cb api to learn ip address/port of a registered node

Sunil Mushran sunil.mushran at oracle.com
Wed Jun 23 11:44:16 PDT 2010


Adds two function calls, o2cb_get_node_ip_string() and o2cb_get_node_port(),
to learn the ip address and port of the registered node.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 include/o2cb/o2cb.h |    7 +++++++
 libo2cb/o2cb_abi.c  |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/include/o2cb/o2cb.h b/include/o2cb/o2cb.h
index 4fa59b6..4ac35cb 100644
--- a/include/o2cb/o2cb.h
+++ b/include/o2cb/o2cb.h
@@ -126,6 +126,13 @@ errcode_t o2cb_num_region_refs(const char *region_name,
 errcode_t o2cb_get_node_num(const char *cluster_name,
 			    const char *node_name,
 			    uint16_t *node_num);
+errcode_t o2cb_get_node_port(const char *cluster_name,
+			     const char *node_name,
+			     uint32_t *ip_port);
+errcode_t o2cb_get_node_ip_string(const char *cluster_name,
+				  const char *node_name,
+				  char *ip_address, int count);
+
 void o2cb_free_cluster_desc(struct o2cb_cluster_desc *cluster);
 errcode_t o2cb_running_cluster_desc(struct o2cb_cluster_desc *cluster);
 
diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c
index 130b6a2..18888fc 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -2173,6 +2173,47 @@ errcode_t o2cb_get_node_num(const char *cluster_name, const char *node_name,
 	return 0;
 }
 
+errcode_t o2cb_get_node_port(const char *cluster_name, const char *node_name,
+			     uint32_t *ip_port)
+{
+	char val[30];
+	char *p;
+	errcode_t ret;
+
+	ret = o2cb_get_node_attribute(cluster_name, node_name, "ipv4_port",
+				      val, sizeof(val));
+	if (ret)
+		return ret;
+
+	*ip_port = strtoul(val, &p, 0);
+	if (!p || (*p && *p != '\n'))
+		return O2CB_ET_INTERNAL_FAILURE;
+
+	return 0;
+}
+
+errcode_t o2cb_get_node_ip_string(const char *cluster_name,
+				  const char *node_name,
+				  char *ip_address, int count)
+{
+	char *p;
+	errcode_t ret;
+
+	ret = o2cb_get_node_attribute(cluster_name, node_name, "ipv4_address",
+				      ip_address, count - 1);
+	if (ret)
+		return ret;
+
+	/* wipeout the last newline character */
+	if (strlen(ip_address)) {
+		p = ip_address + strlen(ip_address) - 1;
+		if (*p == '\n')
+			*p = '\0';
+	}
+
+	return 0;
+}
+
 /*
  * The handshake is pretty simple.  We need to read all supported control
  * device protocols from the kernel.  Once we've read them, we can write
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list