[DRBD-cvs] svn commit by phil - r2076 - in trunk: . user - Fixed the way we determin our own revision number

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Wed Feb 22 18:26:02 CET 2006


Author: phil
Date: 2006-02-22 18:26:01 +0100 (Wed, 22 Feb 2006)
New Revision: 2076

Modified:
   trunk/ROADMAP
   trunk/user/drbdadm_usage_cnt.c
   trunk/user/drbdtool_common.c
   trunk/user/drbdtool_common.h
Log:
Fixed the way we determin our own revision number


Modified: trunk/ROADMAP
===================================================================
--- trunk/ROADMAP	2006-02-14 09:53:49 UTC (rev 2075)
+++ trunk/ROADMAP	2006-02-22 17:26:01 UTC (rev 2076)
@@ -684,7 +684,14 @@
 31 Resizing several GB results in ko-count timeouts, maybe since the
    secondary node does the enlargement of the bitmap in the receiver (?)
 
+32 drbdmeta: with internal meta-data v07 and v08 meta-data super blocks
+   are in different places. -> It is possible to have v07 AND v08 meta
+   data on one device. 
+   => drbdmeta should make sure that it overwrites the other location
+      in case it create a meta-data block.
 
+33? Online verification.
+
 plus-banches:
 ----------------------
 

Modified: trunk/user/drbdadm_usage_cnt.c
===================================================================
--- trunk/user/drbdadm_usage_cnt.c	2006-02-14 09:53:49 UTC (rev 2075)
+++ trunk/user/drbdadm_usage_cnt.c	2006-02-22 17:26:01 UTC (rev 2076)
@@ -41,6 +41,7 @@
 #include <netdb.h>
 
 #include "drbdadm.h"
+#include "drbdtool_common.h"
 #include "drbd_endian.h"
 #include "linux/drbd.h"		/* only use DRBD_MAGIC from here! */
 
@@ -60,31 +61,73 @@
 	struct node_info ni;
 } __attribute((packed));
 
-/* FIX: mark plus versions, mark production vs beta releases.
-        read the version string from the /proc file, so we
-	look at the version of the module and not at the version
-	of the drbdadm executable.
+/* For our purpose (finding the revision) SLURP_SIZE is always enough.
  */
-static unsigned int numeric_version_code(char* text)
+static char* slurp_proc_drbd()
 {
-	unsigned int nc;
-	char buffer[5], *c, *b;
-	unsigned m = 1000000;
+	const int SLURP_SIZE = 4096;
+	char* buffer;
+	int rr, fd;
 
-	nc = 0;
-	c = text;
+	fd = open("/proc/drbd",O_RDONLY);
+	if( fd == -1) return 0;
+	
+	buffer = malloc(SLURP_SIZE);
+	if(!buffer) return 0;
 
-	while(*c) {
-		while(!isdigit(*c)) c++;
-		b = buffer;
-		while(isdigit(*c)) *b++=*c++;
-		*b=0;
+	rr = read(fd, buffer, SLURP_SIZE-1);
+	if( rr == -1) {
+		free(buffer);
+		return 0;
+	}
+	
+	buffer[rr]=0;
+	close(fd);
 
-		nc = nc + atoi( buffer ) * m;
-		m=m/1000;
+	return buffer;
+}
+
+static unsigned int extract_svn_revision(char* text)
+{
+	char token[40];
+	unsigned int svn_rev = 0;
+	int plus=0;
+	enum { begin,f_svn,f_rev } ex=begin;
+
+	while(sget_token(token,40,&text) != EOF) {
+		switch(ex) {
+		case begin: 
+			if(!strcmp(token,"plus")) plus = 1;
+			if(!strcmp(token,"SVN"))  ex = f_svn;
+			break;
+		case f_svn:
+			if(!strcmp(token,"Revision:"))  ex = f_rev;
+			break;
+		case f_rev:
+			svn_rev = atol(token); 
+			goto out;
+		}
 	}
+ out:
+	svn_rev = svn_rev * 10;
+	if( svn_rev && plus ) svn_rev += 1;
+	return svn_rev;
+}
 
-	return nc;
+static unsigned int current_svn_revision()
+{
+	char* version_txt;
+	unsigned int svn_rev;
+
+	version_txt = slurp_proc_drbd();
+	if(version_txt) {
+		svn_rev = extract_svn_revision(version_txt);
+		free(version_txt);
+	} else {
+		svn_rev = extract_svn_revision(drbd_buildtag());
+	}
+
+	return svn_rev;
 }
 
 static void get_random_bytes(void* buffer, int len)
@@ -254,7 +297,7 @@
 
 	if( type == UC_NO ) return;
 
-	current = numeric_version_code(REL_VERSION);
+	current = current_svn_revision();
 
 	if( ! read_node_id(&ni) ) {
 		get_random_bytes(&ni.node_uuid,sizeof(ni.node_uuid));
@@ -319,3 +362,4 @@
 		fgets(answer,9,stdin);
 	}
 }
+

Modified: trunk/user/drbdtool_common.c
===================================================================
--- trunk/user/drbdtool_common.c	2006-02-14 09:53:49 UTC (rev 2075)
+++ trunk/user/drbdtool_common.c	2006-02-22 17:26:01 UTC (rev 2076)
@@ -373,3 +373,23 @@
 	*sp=0;
 	return 1;
 }
+
+int sget_token(char *s, int size, char** text)
+{
+	int c;
+	char* sp = s;
+
+	do { // eat white spaces in front.
+		c = *(*text)++;
+		if( c == 0) return EOF;
+	} while (!isgraph(c));
+
+	do { // read the first word into s
+		*sp++ = c;
+		c = *(*text)++;
+		if ( c == 0) break;
+	} while (isgraph(c) && --size);
+
+	*sp=0;
+	return 1;
+}

Modified: trunk/user/drbdtool_common.h
===================================================================
--- trunk/user/drbdtool_common.h	2006-02-14 09:53:49 UTC (rev 2075)
+++ trunk/user/drbdtool_common.h	2006-02-22 17:26:01 UTC (rev 2076)
@@ -36,5 +36,6 @@
 extern void dt_print_uuids(const __u64* uuid, unsigned int flags);
 extern void dt_pretty_print_uuids(const __u64* uuid, unsigned int flags);
 extern int fget_token(char *s, int size, FILE* stream);
+extern int sget_token(char *s, int size, char** text);
 
 #endif



More information about the drbd-cvs mailing list