This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
master - ccs: libccs split ccs_lookup_nodename into extras.c
- From: "Fabio M. Di Nitto" <fabbione at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Tue, 28 Oct 2008 19:29:41 +0000 (UTC)
- Subject: master - ccs: libccs split ccs_lookup_nodename into extras.c
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=97374c0634c39554a5237e481ab16a51912f7f10
Commit: 97374c0634c39554a5237e481ab16a51912f7f10
Parent: 3c0707faabb70db57a54b517b50741124dd38cee
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate: Tue Oct 28 16:42:31 2008 +0100
Committer: Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Tue Oct 28 20:29:03 2008 +0100
ccs: libccs split ccs_lookup_nodename into extras.c
extras.c will collect wrappers for libccs that do not provide
libccs core functionalities.
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
config/libs/libccsconfdb/Makefile | 3 +
config/libs/libccsconfdb/extras.c | 191 +++++++++++++++++++++++++++++++++++++
config/libs/libccsconfdb/libccs.c | 186 ------------------------------------
3 files changed, 194 insertions(+), 186 deletions(-)
diff --git a/config/libs/libccsconfdb/Makefile b/config/libs/libccsconfdb/Makefile
index a0d6056..919f7a6 100644
--- a/config/libs/libccsconfdb/Makefile
+++ b/config/libs/libccsconfdb/Makefile
@@ -2,6 +2,9 @@ TARGET= libccs
INCDIRT=ccs.h
+OBJS= $(TARGET).o \
+ extras.o
+
include ../../../make/defines.mk
include $(OBJDIR)/make/libs.mk
include $(OBJDIR)/make/cobj.mk
diff --git a/config/libs/libccsconfdb/extras.c b/config/libs/libccsconfdb/extras.c
new file mode 100644
index 0000000..457d755
--- /dev/null
+++ b/config/libs/libccsconfdb/extras.c
@@ -0,0 +1,191 @@
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "ccs.h"
+
+/**
+ * ccs_lookup_nodename
+ * @cd: ccs descriptor
+ * @nodename: node name string
+ * @retval: pointer to location to assign the result, if found
+ *
+ * This function takes any valid representation (FQDN, non-qualified
+ * hostname, IP address, IPv6 address) of a node's name and finds its
+ * canonical name (per cluster.conf). This function will find the primary
+ * node name if passed a node's "altname" or any valid representation
+ * of it.
+ *
+ * Returns: 0 on success, < 0 on failure
+ */
+int ccs_lookup_nodename(int cd, const char *nodename, char **retval) {
+ char path[256];
+ char host_only[128];
+ char *str;
+ char *p;
+ int error;
+ int ret;
+ unsigned int i;
+ size_t nodename_len;
+ struct addrinfo hints;
+
+ if (nodename == NULL)
+ return (-1);
+
+ nodename_len = strlen(nodename);
+ ret = snprintf(path, sizeof(path),
+ "/cluster/clusternodes/clusternode[@name=\"%s\"]/@name", nodename);
+ if (ret < 0 || (size_t) ret >= sizeof(path)) {
+ errno = E2BIG;
+ return (-E2BIG);
+ }
+
+ str = NULL;
+ error = ccs_get(cd, path, &str);
+ if (!error) {
+ *retval = str;
+ return (0);
+ }
+
+ if (nodename_len >= sizeof(host_only)) {
+ errno = E2BIG;
+ return (-E2BIG);
+ }
+
+ /* Try just the hostname */
+ strcpy(host_only, nodename);
+ p = strchr(host_only, '.');
+ if (p != NULL) {
+ *p = '\0';
+
+ ret = snprintf(path, sizeof(path),
+ "/cluster/clusternodes/clusternode[@name=\"%s\"]/@name",
+ host_only);
+ if (ret < 0 || (size_t) ret >= sizeof(path))
+ return (-E2BIG);
+
+ str = NULL;
+ error = ccs_get(cd, path, &str);
+ if (!error) {
+ *retval = str;
+ return (0);
+ }
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ if (strchr(nodename, ':') != NULL)
+ hints.ai_family = AF_INET6;
+ else if (isdigit(nodename[nodename_len - 1]))
+ hints.ai_family = AF_INET;
+ else
+ hints.ai_family = AF_UNSPEC;
+
+ /*
+ ** Try to match against each clusternode in cluster.conf.
+ */
+ for (i = 1 ; ; i++) {
+ char canonical_name[128];
+ unsigned int altcnt;
+
+ ret = snprintf(path, sizeof(path),
+ "/cluster/clusternodes/clusternode[%u]/@name", i);
+ if (ret < 0 || (size_t) ret >= sizeof(path))
+ continue;
+
+ for (altcnt = 0 ; ; altcnt++) {
+ size_t len;
+ struct addrinfo *ai = NULL;
+ char cur_node[128];
+
+ if (altcnt != 0) {
+ ret = snprintf(path, sizeof(path),
+ "/cluster/clusternodes/clusternode[%u]/altname[%u]/@name",
+ i, altcnt);
+ if (ret < 0 || (size_t) ret >= sizeof(path))
+ continue;
+ }
+
+ str = NULL;
+ error = ccs_get(cd, path, &str);
+ if (error || !str) {
+ if (altcnt == 0)
+ goto out_fail;
+ break;
+ }
+
+ if (altcnt == 0) {
+ if (strlen(str) >= sizeof(canonical_name)) {
+ free(str);
+ errno = E2BIG;
+ return (-E2BIG);
+ }
+ strcpy(canonical_name, str);
+ }
+
+ if (strlen(str) >= sizeof(cur_node)) {
+ free(str);
+ errno = E2BIG;
+ return (-E2BIG);
+ }
+
+ strcpy(cur_node, str);
+
+ p = strchr(cur_node, '.');
+ if (p != NULL)
+ len = p - cur_node;
+ else
+ len = strlen(cur_node);
+
+ if (strlen(host_only) == len &&
+ !strncasecmp(host_only, cur_node, len))
+ {
+ free(str);
+ *retval = strdup(canonical_name);
+ if (*retval == NULL) {
+ errno = ENOMEM;
+ return (-ENOMEM);
+ }
+ return (0);
+ }
+
+ if (getaddrinfo(str, NULL, &hints, &ai) == 0) {
+ struct addrinfo *cur;
+
+ for (cur = ai ; cur != NULL ; cur = cur->ai_next) {
+ char hostbuf[512];
+ if (getnameinfo(cur->ai_addr, cur->ai_addrlen,
+ hostbuf, sizeof(hostbuf),
+ NULL, 0,
+ hints.ai_family != AF_UNSPEC ? NI_NUMERICHOST : 0))
+ {
+ continue;
+ }
+
+ if (!strcasecmp(hostbuf, nodename)) {
+ freeaddrinfo(ai);
+ free(str);
+ *retval = strdup(canonical_name);
+ if (*retval == NULL) {
+ errno = ENOMEM;
+ return (-ENOMEM);
+ }
+ return (0);
+ }
+ }
+ freeaddrinfo(ai);
+ }
+
+ free(str);
+
+ /* Now try any altnames */
+ }
+ }
+
+out_fail:
+ errno = EINVAL;
+ *retval = NULL;
+ return (-1);
+}
diff --git a/config/libs/libccsconfdb/libccs.c b/config/libs/libccsconfdb/libccs.c
index 071c840..3567d56 100644
--- a/config/libs/libccsconfdb/libccs.c
+++ b/config/libs/libccsconfdb/libccs.c
@@ -2,8 +2,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <netdb.h>
-#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <corosync/saAis.h>
@@ -254,7 +252,6 @@ static int add_to_buffer(char *data, char **buffer, int *bufsize)
memcpy(newbuf, *buffer, bufferlen);
free(*buffer);
*buffer = newbuf;
- sleep(1);
}
strncpy(*buffer + bufferlen, data, datalen);
}
@@ -1179,186 +1176,3 @@ int ccs_set(int desc, const char *path, char *val){
errno = ENOSYS;
return -1;
}
-
-/**
- * ccs_lookup_nodename
- * @cd: ccs descriptor
- * @nodename: node name string
- * @retval: pointer to location to assign the result, if found
- *
- * This function takes any valid representation (FQDN, non-qualified
- * hostname, IP address, IPv6 address) of a node's name and finds its
- * canonical name (per cluster.conf). This function will find the primary
- * node name if passed a node's "altname" or any valid representation
- * of it.
- *
- * Returns: 0 on success, < 0 on failure
- */
-int ccs_lookup_nodename(int cd, const char *nodename, char **retval) {
- char path[256];
- char host_only[128];
- char *str;
- char *p;
- int error;
- int ret;
- unsigned int i;
- size_t nodename_len;
- struct addrinfo hints;
-
- if (nodename == NULL)
- return (-1);
-
- nodename_len = strlen(nodename);
- ret = snprintf(path, sizeof(path),
- "/cluster/clusternodes/clusternode[@name=\"%s\"]/@name", nodename);
- if (ret < 0 || (size_t) ret >= sizeof(path)) {
- errno = E2BIG;
- return (-E2BIG);
- }
-
- str = NULL;
- error = ccs_get(cd, path, &str);
- if (!error) {
- *retval = str;
- return (0);
- }
-
- if (nodename_len >= sizeof(host_only)) {
- errno = E2BIG;
- return (-E2BIG);
- }
-
- /* Try just the hostname */
- strcpy(host_only, nodename);
- p = strchr(host_only, '.');
- if (p != NULL) {
- *p = '\0';
-
- ret = snprintf(path, sizeof(path),
- "/cluster/clusternodes/clusternode[@name=\"%s\"]/@name",
- host_only);
- if (ret < 0 || (size_t) ret >= sizeof(path))
- return (-E2BIG);
-
- str = NULL;
- error = ccs_get(cd, path, &str);
- if (!error) {
- *retval = str;
- return (0);
- }
- }
-
- memset(&hints, 0, sizeof(hints));
- if (strchr(nodename, ':') != NULL)
- hints.ai_family = AF_INET6;
- else if (isdigit(nodename[nodename_len - 1]))
- hints.ai_family = AF_INET;
- else
- hints.ai_family = AF_UNSPEC;
-
- /*
- ** Try to match against each clusternode in cluster.conf.
- */
- for (i = 1 ; ; i++) {
- char canonical_name[128];
- unsigned int altcnt;
-
- ret = snprintf(path, sizeof(path),
- "/cluster/clusternodes/clusternode[%u]/@name", i);
- if (ret < 0 || (size_t) ret >= sizeof(path))
- continue;
-
- for (altcnt = 0 ; ; altcnt++) {
- size_t len;
- struct addrinfo *ai = NULL;
- char cur_node[128];
-
- if (altcnt != 0) {
- ret = snprintf(path, sizeof(path),
- "/cluster/clusternodes/clusternode[%u]/altname[%u]/@name",
- i, altcnt);
- if (ret < 0 || (size_t) ret >= sizeof(path))
- continue;
- }
-
- str = NULL;
- error = ccs_get(cd, path, &str);
- if (error || !str) {
- if (altcnt == 0)
- goto out_fail;
- break;
- }
-
- if (altcnt == 0) {
- if (strlen(str) >= sizeof(canonical_name)) {
- free(str);
- errno = E2BIG;
- return (-E2BIG);
- }
- strcpy(canonical_name, str);
- }
-
- if (strlen(str) >= sizeof(cur_node)) {
- free(str);
- errno = E2BIG;
- return (-E2BIG);
- }
-
- strcpy(cur_node, str);
-
- p = strchr(cur_node, '.');
- if (p != NULL)
- len = p - cur_node;
- else
- len = strlen(cur_node);
-
- if (strlen(host_only) == len &&
- !strncasecmp(host_only, cur_node, len))
- {
- free(str);
- *retval = strdup(canonical_name);
- if (*retval == NULL) {
- errno = ENOMEM;
- return (-ENOMEM);
- }
- return (0);
- }
-
- if (getaddrinfo(str, NULL, &hints, &ai) == 0) {
- struct addrinfo *cur;
-
- for (cur = ai ; cur != NULL ; cur = cur->ai_next) {
- char hostbuf[512];
- if (getnameinfo(cur->ai_addr, cur->ai_addrlen,
- hostbuf, sizeof(hostbuf),
- NULL, 0,
- hints.ai_family != AF_UNSPEC ? NI_NUMERICHOST : 0))
- {
- continue;
- }
-
- if (!strcasecmp(hostbuf, nodename)) {
- freeaddrinfo(ai);
- free(str);
- *retval = strdup(canonical_name);
- if (*retval == NULL) {
- errno = ENOMEM;
- return (-ENOMEM);
- }
- return (0);
- }
- }
- freeaddrinfo(ai);
- }
-
- free(str);
-
- /* Now try any altnames */
- }
- }
-
-out_fail:
- errno = EINVAL;
- *retval = NULL;
- return (-1);
-}