[pve-devel] r5650 - in pve-cluster/trunk/data: . perl src

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Mar 7 14:30:56 CET 2011


Author: dietmar
Date: 2011-03-07 14:30:56 +0100 (Mon, 07 Mar 2011)
New Revision: 5650

Modified:
   pve-cluster/trunk/data/ChangeLog
   pve-cluster/trunk/data/perl/Cluster.pm
   pve-cluster/trunk/data/perl/IPCC.xs
   pve-cluster/trunk/data/perl/test1.pl
   pve-cluster/trunk/data/src/server.c
   pve-cluster/trunk/data/src/status.c
   pve-cluster/trunk/data/src/status.h
Log:
impl. rrd dump



Modified: pve-cluster/trunk/data/ChangeLog
===================================================================
--- pve-cluster/trunk/data/ChangeLog	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/ChangeLog	2011-03-07 13:30:56 UTC (rev 5650)
@@ -1,5 +1,7 @@
 2011-03-07  Proxmox Support Team  <support at proxmox.com>
 
+	* src/status.c (cfs_rrd_dump): impl. rrd dump
+
 	* perl/Cluster.pm (broadcast_rrd): start rrd integration
 
 2011-02-25  Proxmox Support Team  <support at proxmox.com>

Modified: pve-cluster/trunk/data/perl/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/perl/Cluster.pm	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/perl/Cluster.pm	2011-03-07 13:30:56 UTC (rev 5650)
@@ -408,6 +408,18 @@
     warn $err if $err;
 }
 
+sub rrd_dump {
+    my $res;
+    eval {
+	$res = &$ipcc_send_rec(10);
+    };
+    my $err = $@;
+
+    warn $err if $err;
+
+    return $res;
+}
+
 # a fast way to read files (avoid fuse overhead)
 sub get_config {
     my ($path) = @_;

Modified: pve-cluster/trunk/data/perl/IPCC.xs
===================================================================
--- pve-cluster/trunk/data/perl/IPCC.xs	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/perl/IPCC.xs	2011-03-07 13:30:56 UTC (rev 5650)
@@ -84,7 +84,12 @@
 		errno = -res_header->error;
 		XSRETURN_UNDEF;
 	} else {
-		RETVAL = newSVpv(ipcbuffer + sizeof(struct qb_ipc_response_header), dsize);
+		if (dsize > 0) {
+			RETVAL = newSVpv(ipcbuffer + sizeof(struct qb_ipc_response_header), dsize);
+		} else {
+			errno = 0;
+			XSRETURN_UNDEF;
+		}
 	}
 }
 OUTPUT: RETVAL

Modified: pve-cluster/trunk/data/perl/test1.pl
===================================================================
--- pve-cluster/trunk/data/perl/test1.pl	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/perl/test1.pl	2011-03-07 13:30:56 UTC (rev 5650)
@@ -15,7 +15,7 @@
 
 #print PVE::Cluster::get_system_log(undef, 0);
 
-PVE::Cluster::cfs_update();
+#PVE::Cluster::cfs_update();
 
 #my $res = PVE::Cluster::get_vmlist();
 #print "TEST1: " . Dumper($res->{ids});
@@ -24,11 +24,16 @@
 
 while (1) {
 
+    
+    print "update start\n";
     PVE::Cluster::cfs_update();
+    print "update end\n";
 
-    my $res = PVE::Cluster::cfs_file_version('user.cfg');
+    my $res = PVE::Cluster::rrd_dump();
+    print "RRDDATA:$res\n";
 
-    print "VER $res\n";
+    #my $res = PVE::Cluster::cfs_file_version('user.cfg');
+    #print "VER $res\n";
 
     sleep(1);
 }

Modified: pve-cluster/trunk/data/src/server.c
===================================================================
--- pve-cluster/trunk/data/src/server.c	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/src/server.c	2011-03-07 13:30:56 UTC (rev 5650)
@@ -302,6 +302,14 @@
 
 			result = 0;
 		}
+	} else if (req_pt->id == 10) {	
+	
+		if (req_pt->size != sizeof(struct qb_ipc_request_header)) {
+			result = -EINVAL;
+		} else {
+			cfs_rrd_dump(outbuf);
+			result = 0;
+		}
 	}
 
 	cfs_debug("process result %d", result);

Modified: pve-cluster/trunk/data/src/status.c
===================================================================
--- pve-cluster/trunk/data/src/status.c	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/src/status.c	2011-03-07 13:30:56 UTC (rev 5650)
@@ -825,11 +825,6 @@
 
 	// fixme: when do we remove old entries ?
 
-	/* make sure we are 0 terminated */
-	char databuf[4096];
-	memcpy(databuf, data, len);
-	databuf[len] = 0;
-
 	if (strncmp(key, "pve-nodes/", 10) == 0) {
 		const char *node = key + 10;
 		g_return_if_fail(strchr(node, '/') == NULL);
@@ -862,7 +857,7 @@
 		}
 
 		char *update_args[] = {
-			"update", filename, databuf, 
+			"update", filename, data, 
 			NULL,
 		};
 
@@ -874,17 +869,43 @@
 	}
 }
 
+void
+cfs_rrd_dump(GString *str)
+{
+	// fixme: cache result 
+	// fixme: remove old data
+
+	g_string_set_size(str, 0);
+
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_hash_table_iter_init (&iter, cfs_status.rrdhash);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		rrdentry_t *entry = (rrdentry_t *)value;
+		g_string_append(str, key);
+		g_string_append(str, ":");
+		g_string_append(str, entry->data);
+		g_string_append(str, "\n");
+	}
+
+	g_string_append_c(str, 0); // never return undef
+}
+
 static gboolean 
 rrdentry_hash_set(
 	GHashTable *rrdhash,
 	const char *key,
-	gconstpointer data,
+	const char *data,
 	size_t len)
 {
 	g_return_val_if_fail(rrdhash != NULL, FALSE);
 	g_return_val_if_fail(key != NULL, FALSE);
 	g_return_val_if_fail(data != NULL, FALSE);
 	g_return_val_if_fail(len > 0, FALSE);
+	g_return_val_if_fail(len < 4096, FALSE);
+	g_return_val_if_fail(data[len] == 0, FALSE);
 
 	rrdentry_t *entry;
 	if ((entry = (rrdentry_t *)g_hash_table_lookup(rrdhash, key))) {

Modified: pve-cluster/trunk/data/src/status.h
===================================================================
--- pve-cluster/trunk/data/src/status.h	2011-03-07 11:53:22 UTC (rev 5649)
+++ pve-cluster/trunk/data/src/status.h	2011-03-07 13:30:56 UTC (rev 5650)
@@ -52,6 +52,9 @@
 	const char *user, 
 	guint max_entries);
 
+void
+cfs_rrd_dump(GString *str); 
+
 int
 cfs_status_set(
 	const char *key,




More information about the pve-devel mailing list