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

Sunil Mushran sunil.mushran at oracle.com
Thu Dec 16 13:35:16 PST 2010


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

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

diff --git a/include/o2cb/o2cb.h b/include/o2cb/o2cb.h
index 688817a..b1452aa 100644
--- a/include/o2cb/o2cb.h
+++ b/include/o2cb/o2cb.h
@@ -114,6 +114,16 @@ 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);
+errcode_t o2cb_get_node_local(const char *cluster_name,
+			      const char *node_name,
+			      uint32_t *local);
+
 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 41f6344..e2f2f3f 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <limits.h>
+#include <ctype.h>
 
 #include <linux/types.h>
 
@@ -107,6 +108,20 @@ static int control_device_fd = -1;
 
 static char *configfs_path;
 
+static char *do_strchomp(char *str)
+{
+	int len = strlen(str);
+	char *p;
+
+	if (!len)
+		return str;
+
+	p = str + len - 1;
+	while (isspace(*p) && len--)
+		*p-- = '\0';
+
+	return str;
+}
 
 static ssize_t read_single_line_file(const char *file, char *line,
 				     size_t count)
@@ -2045,6 +2060,60 @@ 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)
+{
+	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 */
+	do_strchomp(ip_address);
+
+	return 0;
+}
+
+errcode_t o2cb_get_node_local(const char *cluster_name, const char *node_name,
+			      uint32_t *local)
+{
+	char val[30];
+	char *p;
+	errcode_t ret;
+
+	ret = o2cb_get_node_attribute(cluster_name, node_name, "local",
+				      val, sizeof(val));
+	if (ret)
+		return ret;
+
+	*local = strtoul(val, &p, 0);
+	if (!p || (*p && *p != '\n'))
+		return O2CB_ET_INTERNAL_FAILURE;
+
+	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.1




More information about the Ocfs2-tools-devel mailing list