[DRBD-cvs] r1783 - in trunk: documentation user

www-data www-data at garcon.linbit.com
Thu Apr 21 12:18:54 CEST 2005


Author: phil
Date: 2005-04-21 12:18:53 +0200 (Thu, 21 Apr 2005)
New Revision: 1783

Added:
   trunk/documentation/drbdmeta.sgml
   trunk/user/drbdmeta_parser.h
   trunk/user/drbdmeta_scanner.fl
Modified:
   trunk/documentation/drbdadm.sgml
   trunk/user/Makefile
   trunk/user/drbdmeta.c
   trunk/user/drbdtool_common.c
Log:
- man page for drbdmeta
- restore-md in drbdmeta


Modified: trunk/documentation/drbdadm.sgml
===================================================================
--- trunk/documentation/drbdadm.sgml	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/documentation/drbdadm.sgml	2005-04-21 10:18:53 UTC (rev 1783)
@@ -18,6 +18,7 @@
       <arg>-d</arg>
       <arg>-c<arg choice="req"><replaceable>file</replaceable></arg></arg>
       <arg>-s<arg choice="req"><replaceable>cmd</replaceable></arg></arg>
+      <arg>-m<arg choice="req"><replaceable>cmd</replaceable></arg></arg>
       <arg choice="req"><replaceable>command</replaceable></arg>
       <group>
 	<arg choice="plain">all</arg>
@@ -30,8 +31,9 @@
     <title>Description</title>
     <para>
       Drbdadm is the high level tool of the DRBD program suite. Drbdadm is to 
-      drbdsetup what ifup/ifdown is to ifconfig. Drbdadm reads its configuration
-      file and performs the specified commands by calling the drbdsetup program.
+      drbdsetup and drbdmeta what ifup/ifdown is to ifconfig. Drbdadm reads its 
+      configuration file and performs the specified commands by calling the drbdsetup 
+      program.
     </para>    
   </refsect1>
   <refsect1>
@@ -61,6 +63,14 @@
 	  omitted, drbdadm will look for /sbin/drbdsetup and ./drbdsetup.
 	</para></listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>-m</option>, <option>--drbdmeta</option>
+          <replaceable>file</replaceable></term>
+        <listitem><para>
+          Specifies the full path to the drbdmeta program. If this option is
+	  omitted, drbdadm will look for /sbin/drbdmeta and ./drbdsetup.
+	</para></listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
@@ -154,6 +164,41 @@
         </para></listitem>
       </varlistentry>
       <varlistentry>
+        <term>create-md</term>
+        <listitem><para>
+          Create-md initializes the meta data storage. This needs to be
+	  done before a DRBD resource can be taken online for the first 
+	  time.
+        </para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>get-gi</term>
+        <listitem><para>
+          Get-gi shows a short textual repesentation of the data generation
+	  identifier.
+	</para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>show-gi</term>
+        <listitem><para>
+	  Show-gi prints a textual representation of the data generation
+	  identifiers including explanatory information.
+        </para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>dump-md</term>
+        <listitem><para>
+          Dumps the whole contents of the meta data storage including
+	  the stored bit-map and activity-log, in a textual representation.
+        </para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>outdate</term>
+        <listitem><para>
+          Sets the outdated flag in the meta data.
+        </para></listitem>
+      </varlistentry>
+      <varlistentry>
         <term>adjust</term>
         <listitem><para>
           Synchronizes the configuration of device with your configuration

Added: trunk/documentation/drbdmeta.sgml
===================================================================
--- trunk/documentation/drbdmeta.sgml	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/documentation/drbdmeta.sgml	2005-04-21 10:18:53 UTC (rev 1783)
@@ -0,0 +1,144 @@
+<!DOCTYPE RefEntry PUBLIC "-//Davenport//DTD DocBook V3.0//EN">
+<refentry>
+  <docinfo><date>19 Apr 2005</date></docinfo>
+  
+  <refmeta>
+    <refentrytitle>drbdmeta</refentrytitle>
+    <manvolnum>8</manvolnum>
+  </refmeta>
+  
+  <refnamediv>
+    <refname>drbdmeta</refname>
+    <refpurpose>DRBD's meta data management tool</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <cmdsynopsis>
+      <command>drbdmeta</command>
+      <arg choice="req"><replaceable>device</replaceable></arg>
+      <group>
+	<arg choice="plain">v06<replaceable>minor</replaceable></arg>
+	<arg choice="plain">v07<replaceable>meta_dev index</replaceable></arg>
+	<arg choice="plain">v08<replaceable>meta_dev index</replaceable></arg>
+      </group>
+      <arg choice="req"><replaceable>command</replaceable></arg>
+      <arg rep="repeat"><replaceable>cmd args</replaceable></arg>
+    </cmdsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Description</title>
+    <para>
+      Drbdmeta is used to create, display and modify the contents of
+      DRBD's meta data storage. Usually you do not want to use this
+      command directly but use it through the front end drbdadm.
+    </para>
+    <para>
+      This command only works if the DRBD resource is currently down, 
+      or at least detached from its backing stoage. The first parameter
+      is the device node assosiated to the resource. With the second
+      parameter you select which the version of the meta data. Currently
+      all major DRBD releases (0.6, 0.7 and 0.8) are supported.
+    </para>    
+  </refsect1>
+  <refsect1>
+    <title>Commands</title>
+    <variablelist>
+      <varlistentry>
+        <term>create-md</term>
+        <listitem><para>
+          Create-md initializes the meta data storage. This needs to be
+	  done before a DRBD resource can be taken online for the first 
+	  time. In case there is already a meta data signature of an
+	  older format in place, drbdmeta will ask you if it should
+	  convert the older format to the selected format.
+	</para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>get-gi</term>
+        <listitem><para>
+          Get-gi shows a short textual repesentation of the data generation
+	  identifier. In version 0.6 and 0.7 this are generation counters,
+	  while in version 0.8 this is a set of UUIDs.
+	</para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>show-gi</term>
+        <listitem><para>
+	  Show-gi prints a textual representation of the data generation
+	  identifiers including explanatory information.
+        </para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>dump-md</term>
+        <listitem><para>
+          Dumps the whole contents of the meta data storage including
+	  the stored bit-map and activity-log, in a textual representation.
+        </para></listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>outdate</term>
+        <listitem><para>
+          Sets the outdated flag in the meta data. This is used by the
+	  peer node when it wants to become primary, but can not reach
+	  communicate with the DRBD stack on this host.
+        </para></listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+  <refsect1>
+    <title>Expert's commands</title>
+    <para>
+      Drbdmeta allows you to modifiy the meta data as well. This is
+      intetionally omitted for the commad's usage output, since you
+      should only use this if you really know what you are doing.
+      By setting the generation identifiers to wrong values you
+      risk to overwrite your up-to-data data by an older version 
+      of your data.
+    </para>
+    <variablelist>
+      <varlistentry>
+        <term>set-gi <replaceable>gi</replaceable></term>
+        <listitem><para>
+          Set-gi allows you to set the generation identifier. 
+	  <replaceable>Gi</replaceable> needs to be a generation 
+	  counter for the 0.6 and 0.7 format, and a UUID set for 0.8.
+	  Specify it in the same way as get-gi shows it.
+	</para></listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1>
+    <title>Version</title>
+    <simpara>
+      This document is correct for version 0.8 of the DRBD distribution.
+    </simpara>
+  </refsect1>
+
+  <refsect1>
+    <title>Author</title>
+    <simpara>Written by Philipp Reisner <email>philipp.reisner at linbit.com</email>.
+    </simpara>
+  </refsect1>
+  <refsect1>
+    <title>Reporting Bugs</title>
+    <simpara>Report bugs to <email>drbd-user at lists.linbit.com</email>.
+    </simpara>
+  </refsect1>
+  <refsect1>
+    <title>Copyright</title>
+    <simpara>
+      Copyright (c) 2004 Philipp Reisner. This  is  free software; 
+      see the source for copying conditions.  There is NO warranty; 
+      not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+    </simpara>
+  </refsect1>
+  <refsect1>
+    <title>See Also</title>
+    <para>
+      <citerefentry><refentrytitle>drbdadm</refentrytitle>
+      <manvolnum>8</manvolnum></citerefentry>
+    </para>
+  </refsect1>
+</refentry>

Modified: trunk/user/Makefile
===================================================================
--- trunk/user/Makefile	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/user/Makefile	2005-04-21 10:18:53 UTC (rev 1783)
@@ -26,7 +26,7 @@
 drbdsetup-obj = drbdsetup.o drbdtool_common.o ../drbd/drbd_buildtag.o \
 	        ../drbd/drbd_strings.o
 
-drbdmeta-obj = drbdmeta.o drbdtool_common.o ../drbd/drbd_buildtag.o
+drbdmeta-obj = drbdmeta.o drbdmeta_scanner.o drbdtool_common.o ../drbd/drbd_buildtag.o
 
 all: drbdsetup drbdadm drbdmeta
 
@@ -36,6 +36,9 @@
 drbdadm_scanner.c: drbdadm_scanner.fl drbdadm_parser.h
 	flex -s -odrbdadm_scanner.c drbdadm_scanner.fl
 
+drbdmeta_scanner.c: drbdmeta_scanner.fl drbdmeta_parser.h
+	flex -odrbdmeta_scanner.c drbdmeta_scanner.fl
+
 # for debug:	flex -d -s -odrbdadm_scanner.c drbdadm_scanner.fl
 
 drbdadm_parser.h: drbdadm_parser.y

Modified: trunk/user/drbdmeta.c
===================================================================
--- trunk/user/drbdmeta.c	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/user/drbdmeta.c	2005-04-21 10:18:53 UTC (rev 1783)
@@ -46,6 +46,10 @@
 #include "drbdtool_common.h"
 #include "drbd_endian.h"
 
+#include "drbdmeta_parser.h"
+extern FILE* yyin;
+YYSTYPE yylval;
+
 /* FIXME? should use sector_t and off_t, not long/u64 ... */
 /* FIXME? rename open -> mmap, close -> munmap */
 
@@ -543,6 +547,7 @@
 int meta_get_gi(struct format *cfg, char **argv, int argc);
 int meta_show_gi(struct format *cfg, char **argv, int argc);
 int meta_dump_md(struct format *cfg, char **argv, int argc);
+int meta_restore_md(struct format *cfg, char **argv, int argc);
 int meta_create_md(struct format *cfg, char **argv, int argc);
 int meta_set_gi(struct format *cfg, char **argv, int argc);
 int meta_outdate(struct format *cfg, char **argv, int argc);
@@ -552,6 +557,7 @@
 	{"get-gi", 0, meta_get_gi, 1},
 	{"show-gi", 0, meta_show_gi, 1},
 	{"dump-md", 0, meta_dump_md, 1},
+	{"restore-md", "file", meta_restore_md, 1},
 	{"create-md", 0, meta_create_md, 1},
 	/* FIXME convert still missing.
 	 * implicit convert from v07 to v08 by create-md
@@ -613,12 +619,6 @@
 	return size64;
 }
 
-#if BITS_PER_LONG == 32
-# define FMT " 0x%016llX;"
-#else
-# define FMT " 0x%016lX;"
-#endif
-
 /* le_u64, because we want to be able to hexdump it reliably
  * regardless of sizeof(long) */
 void printf_bm(const le_u64 * bm, const unsigned int n)
@@ -632,28 +632,11 @@
 			else
 				printf("\n   ");
 		}
-		printf(FMT, le64_to_cpu(bm[i].le));
+		printf(" 0x"X64(016)";", le64_to_cpu(bm[i].le));
 	}
 	printf("\n}\n");
 }
 
-#undef FMT
-
-
-int get_real_random(void * p, int size)
-{
-	int fd,rv;
-
-	fd = open("/dev/random", O_RDONLY);
-	if(fd == -1) {
-		PERROR("open('/dev/random',O_RDONLY)");
-		exit(20);
-	}
-	rv = size == read(fd,p,size);
-	close(fd);
-	return rv;
-}
-
 u64 new_style_offset(struct format * cfg)
 {
 	u64 offset;
@@ -1314,10 +1297,7 @@
 	if (cfg->ops->open(cfg))
 		return -1;
 
-	/* FIXME invent some sceme to identify this dump,
-	 * so we can safely restore it later */
-	printf("DRBD meta data dump version <FIXME drbdmeta dump version>\n");
-	printf("meta data version %s\n\n", cfg->ops->name);
+	printf("version \"%s\";\n\n", cfg->ops->name);
 	if (cfg->ops < f_ops + Drbd_08) {
 		printf("gc {");
 		for (i = 0; i < GEN_CNT_SIZE; i++) {
@@ -1347,8 +1327,81 @@
 	return cfg->ops->close(cfg);
 }
 
+void md_parse_error(const char *etext)
+{
+	fprintf(stderr,"Parse error '%s' expected.",etext);
+	exit(10);
+}
+
+#define EXP(TOKEN) if(yylex() != TOKEN) md_parse_error( #TOKEN );
+
+int meta_restore_md(struct format *cfg, char **argv, int argc)
+{
+	int i;
+	le_u64 *bm;
+
+	if (argc > 0) {
+		yyin = fopen(argv[0],"r");
+		if(yyin == NULL) {
+			fprintf(stderr, "open of '%s' failed.\n",argv[0]);
+			exit(20);
+		}
+	}
+
+	if (!cfg->ops->open(cfg)) {
+		if (!confirmed("Valid meta-data in place, overwrite?"))
+			return -1;
+	}
+
+	EXP(TK_VERSION); EXP(TK_STRING);
+	if(strcmp(yylval.txt,cfg->ops->name)) {
+		fprintf(stderr,"dump is '%s' you requested '%s'.\n",
+			yylval.txt,cfg->ops->name);
+		exit(10);
+	}
+	EXP(';');
+	if (cfg->ops < f_ops + Drbd_08) {
+		EXP(TK_GC); EXP('{');
+		for (i = 0; i < GEN_CNT_SIZE; i++) {
+			EXP(TK_U64); EXP(';');
+			cfg->md.gc[i] = yylval.u64;
+		}
+		EXP('}');
+	} else { // >? 08
+		EXP(TK_UUID); EXP('{');
+		for ( i=Current ; i<UUID_SIZE ; i++ ) {
+			EXP(TK_U64); EXP(';');
+			cfg->md.uuid[i] = yylval.u64;
+		}
+		EXP('}');
+	}
+	EXP(TK_LA_SIZE); EXP(TK_NUM); EXP(';');
+	cfg->md.la_sect = yylval.u64;
+	EXP(TK_BM); EXP('{');
+	bm = (le_u64 *)cfg->on_disk.bm;
+	i = 0;
+	while(yylex() == TK_U64) {
+		bm[i].le = cpu_to_le64(yylval.u64);
+		i++;
+		EXP(';');
+	}
+
+	if (cfg->ops->md_cpu_to_disk(cfg)
+	    || cfg->ops->close(cfg)) {
+		fprintf(stderr, "Writing failed\n");
+		return -1;
+	}
+
+	printf("Successfully restored meta data\n");
+
+	return 0;
+}
+
+#undef EXP
+
 int md_convert_07_to_08(struct format *cfg)
 {
+	int i,j=1;
 	/* Note that al and bm are not touched!
 	 * (they are currently not even mmaped)
 	 *
@@ -1356,15 +1409,31 @@
 	 * We only need to adjust the magic here. */
 	printf("Converting meta data...\n");
 	cfg->md.magic = DRBD_MD_MAGIC_08;
-	// get_real_random(&cfg->md.uuid,sizeof(u64));
-	// cfg->md.peer_uuid = 0;
+
+	// The MDF Flags are the same in 07 and 08
+	cfg->md.flags = cfg->md.gc[Flags];
+	/* 
+	 */
+	cfg->md.uuid[Current] = 
+		(u64)(cfg->md.gc[HumanCnt] & 0xffff) << 48 |
+		(u64)(cfg->md.gc[TimeoutCnt] & 0xffff) << 32 |
+		(u64)((cfg->md.gc[ConnectedCnt]+cfg->md.gc[ArbitraryCnt])
+		       & 0xffff) << 16 |
+		(u64)0xbabe;
+	cfg->md.uuid[Bitmap] = (u64)0;
+	if (cfg->bits_set) i = Bitmap;
+	else i = History_start;
+	for ( ; i<=History_end ; i++ ) {
+		cfg->md.uuid[i] = cfg->md.uuid[Current] - j*0x10000;
+		j++;
+	}
+
 	if (cfg->ops->md_cpu_to_disk(cfg)
 	    || cfg->ops->close(cfg)) {
 		fprintf(stderr, "conversion failed\n");
 		return -1;
 	}
-	printf("Convertion Currently BROKEN!\n");
-	//printf("Successfully converted v07 meta data to v08 format.\n");
+	printf("Successfully converted v07 meta data to v08 format.\n");
 	return 0;
 }
 

Added: trunk/user/drbdmeta_parser.h
===================================================================
--- trunk/user/drbdmeta_parser.h	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/user/drbdmeta_parser.h	2005-04-21 10:18:53 UTC (rev 1783)
@@ -0,0 +1,21 @@
+typedef union YYSTYPE {
+  char* txt;
+  u64   u64;
+} YYSTYPE;
+
+#define YYSTYPE_IS_DECLARED 1
+#define YYSTYPE_IS_TRIVIAL 1
+
+extern YYSTYPE yylval;
+
+enum yytokentype {
+	TK_STRING = 258,
+	TK_U64,
+	TK_NUM,
+	TK_GC,
+	TK_BM,
+	TK_UUID,
+	TK_VERSION,
+	TK_LA_SIZE
+};
+

Added: trunk/user/drbdmeta_scanner.fl
===================================================================
--- trunk/user/drbdmeta_scanner.fl	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/user/drbdmeta_scanner.fl	2005-04-21 10:18:53 UTC (rev 1783)
@@ -0,0 +1,53 @@
+%{
+
+#include "drbd_endian.h"
+#include "drbdmeta_parser.h"
+
+static void unescape(void);
+
+//#define DP printf("%s ",yytext);
+#define DP
+
+%}
+
+%option noyywrap
+
+WS		[ \t\n]
+COMMENT		\#[^\n]*
+NUM		[0-9]{1,9}
+U64		0x[0-9A-Fa-f]{16}
+OP		[{};]
+STRING		\"[^\"]*\"
+
+%%
+
+{WS}
+{COMMENT}
+{OP}		DP; return yytext[0];
+{STRING}	unescape(); yylval.txt=yytext; DP; return TK_STRING; 
+{U64}		yylval.u64 = strto_u64(yytext, NULL, 16); DP; return TK_U64;
+{NUM}		yylval.u64 = strto_u64(yytext, NULL, 10); DP; return TK_NUM;
+gc		DP; return TK_GC;
+bm		DP; return TK_BM;
+uuid		DP; return TK_UUID;
+version		DP; return TK_VERSION;
+la-size-sect	DP; return TK_LA_SIZE;
+
+%%
+
+static void unescape(void)
+{
+  /* backslash escapes from string */
+  char *ue, *e;
+  e = ue = yytext;
+  for (;;) {
+    if (*ue == '"')
+      ue++;
+    if (*ue == '\\')
+      ue++;
+    if (!*ue)
+      break;
+    *e++ = *ue++;
+  }
+  *e = '\0';
+}

Modified: trunk/user/drbdtool_common.c
===================================================================
--- trunk/user/drbdtool_common.c	2005-04-21 10:16:23 UTC (rev 1782)
+++ trunk/user/drbdtool_common.c	2005-04-21 10:18:53 UTC (rev 1783)
@@ -225,7 +225,7 @@
 	
 	dev_major = 147; //LANANA_DRBD_MAJOR;
 
-	if( stat(device, &drbd_stat) ) {
+	if( !stat(device, &drbd_stat) ) {
 
 		if(!S_ISBLK(drbd_stat.st_mode)) {
 			fprintf(stderr, "%s is not a block device!\n", device);
@@ -353,6 +353,6 @@
 "                             -<  Data was/is currently up-to-date  >--+ | | |\n"
 "                                  -<  Node was/is currently primary  >--+ | |\n"
 "                                  -<  Node was/is currently connected  >--+ |\n"
-"          -<  Node was in to progress of setting all bits in the bitmap  >--+\n"
+"         -<  Node was in the progress of setting all bits in the bitmap  >--+\n"
 "\n");
 }



More information about the drbd-cvs mailing list