[pve-devel] r6394 - in pve-cluster/trunk/data: . PVE src

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Aug 2 13:24:13 CEST 2011


Author: dietmar
Date: 2011-08-02 13:24:13 +0200 (Tue, 02 Aug 2011)
New Revision: 6394

Modified:
   pve-cluster/trunk/data/ChangeLog
   pve-cluster/trunk/data/PVE/Cluster.pm
   pve-cluster/trunk/data/PVE/Makefile
   pve-cluster/trunk/data/PVE/test.pl
   pve-cluster/trunk/data/src/cfs-utils.h
   pve-cluster/trunk/data/src/dfsm.c
   pve-cluster/trunk/data/src/dfsm.h
   pve-cluster/trunk/data/src/pmxcfs.c
   pve-cluster/trunk/data/src/status.c
Log:
	* src/dfsm.c (dfsm_set_mode): call new callback dfsm_synced_fn()

	* src/status.c: add 'iphash' to store ip adresses of all
	nodes.
	(nodeip_hash_set): helper to update iphash
	(dfsm_synced): send ip address when we are in sync

	* src/pmxcfs.c (main): set cfs.ip to local ip address.

2


Modified: pve-cluster/trunk/data/ChangeLog
===================================================================
--- pve-cluster/trunk/data/ChangeLog	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/ChangeLog	2011-08-02 11:24:13 UTC (rev 6394)
@@ -1,3 +1,14 @@
+2011-08-02  Proxmox Support Team  <support at proxmox.com>
+
+	* src/dfsm.c (dfsm_set_mode): call new callback dfsm_synced_fn()
+
+	* src/status.c: add 'iphash' to store ip adresses of all
+	nodes.
+	(nodeip_hash_set): helper to update iphash
+	(dfsm_synced): send ip address when we are in sync
+
+	* src/pmxcfs.c (main): set cfs.ip to local ip address.
+
 2011-08-01  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/Cluster.pm (check_cfs_quorum): helper to check quorum

Modified: pve-cluster/trunk/data/PVE/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/PVE/Cluster.pm	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/PVE/Cluster.pm	2011-08-02 11:24:13 UTC (rev 6394)
@@ -867,13 +867,17 @@
    syslog("err", "writing cluster log failed: $@") if $@;
 }
 
-# this is also use to get the IP of the local node
+# this is also used to get the IP of the local node
 sub remote_node_ip {
     my ($nodename, $noerr) = @_;
 
-    # fixme: get IP from pmxcfs for remote nodes
+    my $nodelist = $clinfo->{nodelist};
+    if ($nodelist && $nodelist->{$nodename}) {
+	if (my $ip = $nodelist->{$nodename}->{ip}) {
+	    return $ip;
+	}
+    }
 
-
     # fallback: try to get IP by other means
     my $packed_ip = gethostbyname($nodename);
     if (defined $packed_ip) {

Modified: pve-cluster/trunk/data/PVE/Makefile
===================================================================
--- pve-cluster/trunk/data/PVE/Makefile	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/PVE/Makefile	2011-08-02 11:24:13 UTC (rev 6394)
@@ -1,5 +1,5 @@
 # Makefile.in generated by automake 1.11.1 from Makefile.am.
-# perl/Makefile.  Generated from Makefile.in by configure.
+# PVE/Makefile.  Generated from Makefile.in by configure.
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
 # 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
@@ -35,7 +35,7 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
 perlbin_PROGRAMS = IPCC.so$(EXEEXT)
-subdir = perl
+subdir = PVE
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.in
@@ -144,7 +144,7 @@
 PKG_CONFIG_LIBDIR = 
 PKG_CONFIG_PATH = 
 QB_CFLAGS =  
-QB_LIBS = -lqb -lrt  
+QB_LIBS = -lqb -lrt -ldl  
 RANLIB = ranlib
 SET_MAKE = 
 SHELL = /bin/bash
@@ -152,8 +152,8 @@
 SQLITE3_LIBS = -lsqlite3  
 STRIP = 
 VERSION = 1.0
-abs_builddir = /home/dietmar/pve2-devel/pve-cluster/data/perl
-abs_srcdir = /home/dietmar/pve2-devel/pve-cluster/data/perl
+abs_builddir = /home/dietmar/pve2-devel/pve-cluster/data/PVE
+abs_srcdir = /home/dietmar/pve2-devel/pve-cluster/data/PVE
 abs_top_builddir = /home/dietmar/pve2-devel/pve-cluster/data
 abs_top_srcdir = /home/dietmar/pve2-devel/pve-cluster/data
 ac_ct_CC = gcc
@@ -214,9 +214,9 @@
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign perl/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign PVE/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --foreign perl/Makefile
+	  $(AUTOMAKE) --foreign PVE/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
@@ -561,7 +561,7 @@
 	mv IPCC.xsc IPCC.c
 
 install-exec-hook:
-	perl -I. ./pvecm verifyapi
+	perl -I.. ./pvecm verifyapi
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.

Modified: pve-cluster/trunk/data/PVE/test.pl
===================================================================
--- pve-cluster/trunk/data/PVE/test.pl	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/PVE/test.pl	2011-08-02 11:24:13 UTC (rev 6394)
@@ -4,7 +4,7 @@
 
 use PVE::IPCC;
 
-if (defined(my $res = PVE::IPCC::ipcc_send_rec(1))) {
+if (defined(my $res = PVE::IPCC::ipcc_send_rec(2))) {
     print "GOT: $res\n";
 } else {
     die "ipcc_send_rec failed: $!\n";

Modified: pve-cluster/trunk/data/src/cfs-utils.h
===================================================================
--- pve-cluster/trunk/data/src/cfs-utils.h	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/src/cfs-utils.h	2011-08-02 11:24:13 UTC (rev 6394)
@@ -39,6 +39,7 @@
 
 typedef struct {
 	char *nodename;
+	char *ip;
 	gid_t gid;
 	int debug;
 	int print_to_console;

Modified: pve-cluster/trunk/data/src/dfsm.c
===================================================================
--- pve-cluster/trunk/data/src/dfsm.c	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/src/dfsm.c	2011-08-02 11:24:13 UTC (rev 6394)
@@ -543,6 +543,8 @@
 		cfs_dom_message(dfsm->log_domain, "starting data syncronisation");
 	} else if (new_mode == DFSM_MODE_SYNCED) {
 		cfs_dom_message(dfsm->log_domain, "all data is up to date");
+		if (dfsm->dfsm_callbacks->dfsm_synced_fn)
+			dfsm->dfsm_callbacks->dfsm_synced_fn(dfsm);
 	} else if (new_mode == DFSM_MODE_UPDATE) {
 		cfs_dom_message(dfsm->log_domain, "waiting for updates from leader");	
 	} else if (new_mode == DFSM_MODE_LEAVE) {

Modified: pve-cluster/trunk/data/src/dfsm.h
===================================================================
--- pve-cluster/trunk/data/src/dfsm.h	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/src/dfsm.h	2011-08-02 11:24:13 UTC (rev 6394)
@@ -84,6 +84,8 @@
 	gpointer data,
 	dfsm_sync_info_t *syncinfo);
 
+typedef void (*dfsm_synced_fn_t)(dfsm_t *dfsm);
+
 /* return values:
  * res < 0    ... serious error, leave group
  * res >=  0  ... OK
@@ -106,6 +108,7 @@
 	dfsm_process_state_update_fn_t dfsm_cleanup_fn;
 	dfsm_process_update_fn_t dfsm_process_update_fn;
 	dfsm_checksum_fn_t dfsm_checksum_fn;
+	dfsm_synced_fn_t dfsm_synced_fn;
 } dfsm_callbacks_t;
 
 typedef struct {

Modified: pve-cluster/trunk/data/src/pmxcfs.c
===================================================================
--- pve-cluster/trunk/data/src/pmxcfs.c	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/src/pmxcfs.c	2011-08-02 11:24:13 UTC (rev 6394)
@@ -38,7 +38,11 @@
 #include <dirent.h>
 #include <sys/utsname.h>
 #include <grp.h>
-
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+ 
 #include <qb/qbdefs.h>
 #include <qb/qbutil.h>
 
@@ -514,6 +518,29 @@
 	cfs_plug_base_insert(bplug, (cfs_plug_t*)lnk);
 }
 
+static char *
+lookup_node_ip(const char *nodename) 
+{
+	struct addrinfo *ainfo;
+	struct addrinfo ahints;
+	memset(&ahints, 0, sizeof(ahints));
+
+	if (getaddrinfo(nodename, NULL, &ahints, &ainfo))
+		return NULL;
+
+	if (ainfo->ai_family == AF_INET) {
+		char buf[INET6_ADDRSTRLEN];
+		struct sockaddr_in *sa = (struct sockaddr_in *)ainfo->ai_addr;
+		inet_ntop(ainfo->ai_family, &sa->sin_addr, buf, sizeof(buf));
+		if (strncmp(buf, "127.", 4) != 0) {
+			return g_strdup(buf);
+		}
+	}
+
+	// ipv6 support ?
+
+	return NULL;
+}
 int main(int argc, char *argv[])
 {
 	int ret = -1;
@@ -576,6 +603,11 @@
 
 	cfs.nodename = g_strdup(utsname.nodename);
 
+	if (!(cfs.ip = lookup_node_ip(cfs.nodename))) { 
+		cfs_critical("Unable to get local IP address");
+		exit(-1);
+	}
+
 	struct group *www_data = getgrnam("www-data");
 	if (!www_data) {
 		cfs_critical("Unable to get www-data group ID");

Modified: pve-cluster/trunk/data/src/status.c
===================================================================
--- pve-cluster/trunk/data/src/status.c	2011-08-02 05:51:35 UTC (rev 6393)
+++ pve-cluster/trunk/data/src/status.c	2011-08-02 11:24:13 UTC (rev 6394)
@@ -98,6 +98,7 @@
 	dfsm_t *kvstore;
 	GHashTable *kvhash;
 	GHashTable *rrdhash;
+	GHashTable *iphash;
 
 	GHashTable *memdb_changes;
 
@@ -285,6 +286,11 @@
 					       node->name, node->nodeid, node->online);
 
 
+			char *ip = (char *)g_hash_table_lookup(cfs_status.iphash, node->name);
+			if (ip) {
+				g_string_append_printf(str, ", \"ip\": \"%s\"", ip);
+			}
+
 			g_string_append_printf(str, "}");
 
 		}
@@ -369,6 +375,8 @@
 
 	cfs_status.rrdhash = rrdentry_hash_new();
 
+	cfs_status.iphash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
 	cfs_status.memdb_changes = g_hash_table_new(g_str_hash, g_str_equal);
 
 	for (int i = 0; i < G_N_ELEMENTS(memdb_change_array); i++) {
@@ -412,6 +420,11 @@
 		cfs_status.rrdhash = NULL;
 	}
 
+	if (cfs_status.iphash) {
+		g_hash_table_destroy(cfs_status.iphash);
+		cfs_status.iphash = NULL;
+	}
+
 	if (cfs_status.clusterlog)
 		clusterlog_destroy(cfs_status.clusterlog);
 
@@ -1068,6 +1081,30 @@
 }
 
 static gboolean
+nodeip_hash_set(
+	GHashTable *iphash,
+	const char *nodename,
+	const char *ip,
+	size_t len)
+{
+	g_return_val_if_fail(iphash != NULL, FALSE);
+	g_return_val_if_fail(nodename != NULL, FALSE);
+	g_return_val_if_fail(ip != NULL, FALSE);
+	g_return_val_if_fail(len > 0, FALSE);
+	g_return_val_if_fail(len < 256, FALSE);
+	g_return_val_if_fail(ip[len-1] == 0, FALSE);
+
+	char *oldip = (char *)g_hash_table_lookup(iphash, nodename);
+
+	if (!oldip || (strcmp(oldip, ip) != 0)) {
+		cfs_status.clinfo_version++;
+		g_hash_table_replace(iphash, g_strdup(nodename), g_strdup(ip));
+	}
+
+	return TRUE;
+}
+
+static gboolean
 rrdentry_hash_set(
 	GHashTable *rrdhash,
 	const char *key,
@@ -1266,6 +1303,8 @@
 
 	if (strncmp(key, "rrd/", 4) == 0) {
 		res = rrdentry_hash_set(cfs_status.rrdhash, key + 4, data, len);
+	} else if (!strcmp(key, "nodeip")) {
+		res = nodeip_hash_set(cfs_status.iphash, cfs.nodename, data, len);
 	} else {
 		res = kventry_hash_set(cfs_status.kvhash, key, data, len);
 	}
@@ -1300,9 +1339,9 @@
 	cfs_debug("got node %d status update %s", nodeid, key);
 
 	if (strncmp(key, "rrd/", 4) == 0) {
-
 		rrdentry_hash_set(cfs_status.rrdhash, key + 4, data, len);
-
+	} else if (!strcmp(key, "nodeip")) {
+		nodeip_hash_set(cfs_status.iphash, clnode->name, data, len);
 	} else {
 		if (!clnode->kvhash) {
 			if (!(clnode->kvhash = kventry_hash_new())) {
@@ -1515,6 +1554,20 @@
 	return 1;
 }
 
+static void
+dfsm_synced(dfsm_t *dfsm)
+{
+	g_return_val_if_fail(dfsm != NULL, -1);
+
+	cfs_critical("TEST commit");
+
+	char *ip = (char *)g_hash_table_lookup(cfs_status.iphash, cfs.nodename);
+	if (!ip) 
+		ip = cfs.ip;
+
+	cfs_status_set("nodeip", ip, strlen(ip) + 1);
+}
+
 static int
 dfsm_cleanup(
 	dfsm_t *dfsm,
@@ -1533,6 +1586,7 @@
 	.dfsm_process_update_fn = dfsm_process_update,
 	.dfsm_commit_fn = dfsm_commit,
 	.dfsm_cleanup_fn = dfsm_cleanup,
+	.dfsm_synced_fn = dfsm_synced,
 };
 
 dfsm_t *



More information about the pve-devel mailing list