[DRBD-cvs] r1770 - in trunk: . scripts user

www-data www-data at garcon.linbit.com
Mon Mar 21 21:02:54 CET 2005


Author: phil
Date: 2005-03-21 21:02:52 +0100 (Mon, 21 Mar 2005)
New Revision: 1770

Modified:
   trunk/ROADMAP
   trunk/scripts/drbd.conf
   trunk/user/drbdadm.h
   trunk/user/drbdadm_main.c
   trunk/user/drbdadm_parser.y
   trunk/user/drbdadm_scanner.fl
Log:
Implemented the common section for drbd.conf. 
This finishes item 12 of the ROADMAP.



Modified: trunk/ROADMAP
===================================================================
--- trunk/ROADMAP	2005-03-17 13:05:16 UTC (rev 1769)
+++ trunk/ROADMAP	2005-03-21 20:02:52 UTC (rev 1770)
@@ -360,7 +360,7 @@
   section (like handlers, startup, disk, net and syncer)
   are inherited from the common section, if they are not
   defined in a resource section.
-  0% DONE
+  99% DONE
 
 13 Introduce an UUID (universally unique identifier) in the
   meta data. One purpose is to tag the bitmap with this UUID. 

Modified: trunk/scripts/drbd.conf
===================================================================
--- trunk/scripts/drbd.conf	2005-03-17 13:05:16 UTC (rev 1769)
+++ trunk/scripts/drbd.conf	2005-03-21 20:02:52 UTC (rev 1770)
@@ -90,7 +90,21 @@
     # disable-io-hints;
 # }
 
+
 #
+# The common section can have all the sections a resource can have but
+# not the host section (started with the "on" keyword).
+# The common section must precede all resources.
+# All resources inherit the settings from the common section.
+# Whereas settings in the resources have precedence over the common
+# setting.
+#
+
+common {
+  syncer { rate 10M; }
+}
+
+#
 # this need not be r#, you may use phony resource names,
 # like "resource web" or "resource mail", too
 #
@@ -297,7 +311,6 @@
     # max-epoch-size  2048;
   }
   syncer {
-    rate   4M;
     group   1; # sync concurrently with r0
   }
 
@@ -340,7 +353,6 @@
   startup { wfc-timeout	0; degr-wfc-timeout	120; }
   disk { on-io-error detach; }
   syncer {
-    rate	4M;
     group	3;   # sync when r2 is finished syncing.
   }
   on amd {

Modified: trunk/user/drbdadm.h
===================================================================
--- trunk/user/drbdadm.h	2005-03-17 13:05:16 UTC (rev 1769)
+++ trunk/user/drbdadm.h	2005-03-21 20:02:52 UTC (rev 1770)
@@ -88,6 +88,7 @@
 extern char* config_file;
 extern int config_valid;
 extern struct d_resource* config;
+extern struct d_resource* common;
 extern struct d_globals global_options;
 extern int line, fline, c_resource_start;
 

Modified: trunk/user/drbdadm_main.c
===================================================================
--- trunk/user/drbdadm_main.c	2005-03-17 13:05:16 UTC (rev 1769)
+++ trunk/user/drbdadm_main.c	2005-03-21 20:02:52 UTC (rev 1770)
@@ -105,6 +105,7 @@
 struct d_globals global_options = { 0, 0, 1 };
 char *config_file = NULL;
 struct d_resource* config = NULL;
+struct d_resource* common = NULL;
 int nr_resources;
 int highest_minor;
 int config_valid=1;
@@ -263,6 +264,17 @@
     }
 }
 
+static void dump_common_info()
+{
+  printI("common {\n"); ++indent;
+  dump_options("net",common->net_options);
+  dump_options("disk",common->disk_options);
+  dump_options("syncer",common->sync_options);
+  dump_options("startup",common->startup_options);
+  dump_options("handlers",common->handlers);
+  --indent; printf("}\n\n");  
+}
+
 static void dump_host_info(struct d_host_info* hi)
 {
   if(!hi) {
@@ -391,8 +403,55 @@
     free_options(f->handlers);
     free(f);
   }
+  free_options(common->net_options);
+  free_options(common->disk_options);
+  free_options(common->sync_options);
+  free_options(common->startup_options);
+  free_options(common->handlers);
 }
 
+static struct d_option* new_opt(char* name,char* value)
+{
+  struct d_option* cn = malloc(sizeof(struct d_option));
+
+  /* fprintf(stderr,"%s:%d: %s = %s\n",config_file,line,name,value); */
+  cn->name=name;
+  cn->value=value;
+  cn->mentioned=0;
+
+  return cn;
+}
+
+static void expand_opts(struct d_option* co, struct d_option** opts)
+{
+  struct d_option* no;
+
+  while(co) {
+    if(!find_opt(*opts,co->name)) {
+      // prepend new item to opts
+      no = malloc(sizeof(struct d_option));
+      no->name=strdup(co->name);
+      no->value=strdup(co->value);
+      no->next = *opts;
+      *opts = no;
+    }
+    co=co->next;
+  }
+}
+
+static void expand_common(void)
+{
+  struct d_resource *res,*tmp;
+
+  for_each_resource(res,tmp,config) {
+    expand_opts(common->net_options,     &res->net_options);
+    expand_opts(common->disk_options,    &res->disk_options);
+    expand_opts(common->sync_options,    &res->sync_options);
+    expand_opts(common->startup_options, &res->startup_options);
+    expand_opts(common->handlers,        &res->handlers);
+  }
+}
+
 static void find_drbdcmd(char** cmd, char** pathes)
 {
   char **path;
@@ -1324,7 +1383,12 @@
         print_usage (argv[0]);	// arguments missing.
 
       if(optind==argc || !strcmp(argv[optind],"all")) {
-        if (cmd->function == adm_dump) dump_global_info();
+        if (cmd->function == adm_dump) {
+	  dump_global_info();
+	  dump_common_info();
+	} else {
+	  expand_common(); // Propagate common options to resources.
+	}
         for_each_resource(res,tmp,config) {
 	  if( (rv |= cmd->function(res,cmd->name)) >= 10 ) {
 	    fprintf(stderr,"drbdsetup exited with code %d\n",rv);

Modified: trunk/user/drbdadm_parser.y
===================================================================
--- trunk/user/drbdadm_parser.y	2005-03-17 13:05:16 UTC (rev 1769)
+++ trunk/user/drbdadm_parser.y	2005-03-21 20:02:52 UTC (rev 1770)
@@ -238,8 +238,8 @@
 %token TK_GLOBAL TK_RESOURCE
 %token TK_ON TK_NET TK_DISK_S TK_SYNCER TK_STARTUP
 %token TK_DISABLE_IO_HINTS
-%token TK_PROTOCOL TK_HANDLERS
-%token TK_ADDRESS TK_DISK TK_DEVICE TK_META_DISK
+%token TK_PROTOCOL TK_HANDLERS TK_COMMON
+%token TK_ADDRESS TK_DISK TK_DEVICE TK_META_DISK 
 %token <txt> TK_MINOR_COUNT TK_INTEGER TK_STRING
 %token <txt> TK_ON_IO_ERROR TK_SIZE TK_SPLIT_BRAIN_FIX
 %token <txt> TK_TIMEOUT TK_CONNECT_INT TK_PING_INT TK_MAX_BUFFERS TK_IPADDR
@@ -260,7 +260,7 @@
 %type <d_resource> resources resource
 
 %%
-config:		  global_sec resources	 { config=$2; }
+config:		  global_sec common resources	 { config=$3; }
 		;
 
 global_sec:	  /* empty */
@@ -285,7 +285,12 @@
 		}
 		;
 
-resources:	  /* empty */	     { $$ = 0; }
+common:		  /* empty */	      { common = NULL;  }
+		| TK_COMMON { c_res = new_resource("common"); } 
+			res_stmts { common = c_res; }
+		;
+
+resources:	  /* empty */	     { $$ = NULL; }
 		| resources resource { $$=APPEND($1,$2); }
 		;
 
@@ -344,17 +349,17 @@
 		}
 		;
 
-disk_stmts:	  /* empty */	           { $$ = 0; }
+disk_stmts:	  /* empty */	           { $$ = NULL; }
 		| disk_stmts disk_stmt	   { $$=APPEND($1,$2); }
 		;
 
 disk_stmt:	  TK_ON_IO_ERROR TK_STRING { $$=new_opt($1,$2); }
 		| TK_SIZE TK_INTEGER
 		{ $$=new_opt($1,$2); range_check(R_DISK_SIZE,$1,$2); }
-		| TK_SPLIT_BRAIN_FIX       { $$=new_opt($1,0);  }
+		| TK_SPLIT_BRAIN_FIX       { $$=new_opt($1,NULL);  }
 		;
 
-net_stmts:	  /* empty */	           { $$ = 0; }
+net_stmts:	  /* empty */	           { $$ = NULL; }
 		| net_stmts net_stmt       { $$=APPEND($1,$2); }
 		;
 
@@ -373,17 +378,17 @@
 		| TK_KO_COUNT       TK_INTEGER
 		{ range_check(R_KO_COUNT,$1,$2);	$$=new_opt($1,$2); }
 		| TK_ON_DISCONNECT  TK_STRING	{	$$=new_opt($1,$2); }
-		| TK_ALLOW_TWO_PRIMARIES	{	$$=new_opt($1,0);  }
+		| TK_ALLOW_TWO_PRIMARIES	{	$$=new_opt($1,NULL); }
 		| TK_CRAM_HMAC_ALG  TK_STRING	{	$$=new_opt($1,$2); }
 		| TK_SHARED_SECRET  TK_STRING	{	$$=new_opt($1,$2); }
 		;
 
-sync_stmts:	  /* empty */	           { $$ = 0; }
+sync_stmts:	  /* empty */	           { $$ = NULL; }
 		| sync_stmts sync_stmt	   { $$=APPEND($1,$2); }
 		;
 
-sync_stmt:	  TK_SKIP_SYNC		   { $$=new_opt($1,0);  }
-		| TK_USE_CSUMS		   { $$=new_opt($1,0);  }
+sync_stmt:	  TK_SKIP_SYNC		   { $$=new_opt($1,NULL);  }
+		| TK_USE_CSUMS		   { $$=new_opt($1,NULL);  }
 		| TK_RATE	TK_INTEGER
 		{ range_check(R_RATE,$1,$2); $$=new_opt($1,$2); }
 		| TK_SYNC_GROUP TK_INTEGER { $$=new_opt($1,$2); }
@@ -417,7 +422,7 @@
 		| TK_STRING { c_host->meta_disk = $1; }
 		;
 
-startup_stmts:	  /* empty */  { $$ = 0; }
+startup_stmts:	  /* empty */  { $$ = NULL; }
 		| startup_stmts startup_stmt   { $$=APPEND($1,$2); }
 		;
 
@@ -427,7 +432,7 @@
 		{ range_check(R_DEGR_WFC_TIMEOUT,$1,$2);$$=new_opt($1,$2); }
 		;
 
-handler_stmts:	  /* empty */	           { $$ = 0; }
+handler_stmts:	  /* empty */	           { $$ = NULL; }
 		| handler_stmts handler_stmt	   { $$=APPEND($1,$2); }
 		;
 

Modified: trunk/user/drbdadm_scanner.fl
===================================================================
--- trunk/user/drbdadm_scanner.fl	2005-03-17 13:05:16 UTC (rev 1769)
+++ trunk/user/drbdadm_scanner.fl	2005-03-21 20:02:52 UTC (rev 1770)
@@ -47,7 +47,7 @@
 %option stack
 
 %x RESOURCE GLOBAL
-%x STARTUP DISK NET SYNCER HOST HANDLERS
+%x STARTUP DISK NET SYNCER HOST HANDLERS COMMON
 %x SEMICOLON ASSIGN NUM NUM_U NAME STRING PROTO IO_ERROR ON_DISCONNECT
 %x IP_AND_PORT PORT META_DISK META_IDX
 %x LS LBRACE IGNORE_SECTION
@@ -74,6 +74,7 @@
 _0_255			  0|[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-5]
 IPV4ADDR		  {_1_254}\.{_0_255}\.{_0_255}\.{_1_254}
 PORT			  {WSC}port{ASSIGN}{NUM}
+COMMON			  common
 
 %%
 
@@ -87,10 +88,11 @@
   global		section(GLOBAL); return TK_GLOBAL;
   resource		named_section(RESOURCE); return TK_RESOURCE;
   \}			syntax_error("unmached closing brace.");
+  common		section(COMMON); return TK_COMMON;
   {NDELIM}		expect_error("one of 'global|resource'");
 }
 
-<RESOURCE,GLOBAL,IGNORE_SECTION,STARTUP,DISK,NET,SYNCER,HOST,HANDLERS>{
+<RESOURCE,GLOBAL,IGNORE_SECTION,STARTUP,DISK,NET,SYNCER,HOST,HANDLERS,COMMON>{
   {IGNORE}		update_lcnt();
   \}			yy_pop_state();
 }
@@ -214,7 +216,7 @@
   protocol		do_assign(PROTO);  CP; return TK_PROTOCOL;
   {NDELIM}		{
 			  expect_error(
-				"one of 'protocol|incon-degr-cmd|"
+				"one of 'protocol"
 				"startup|disk|net|syncer|on <HOSTNAME>'|"
 				"handlers");
 			}
@@ -289,6 +291,19 @@
 			}
 }
 
+<COMMON>{
+  startup		section(STARTUP);    return TK_STARTUP;
+  syncer		section(SYNCER);     return TK_SYNCER;
+  disk			section(DISK);	     return TK_DISK_S;
+  net			section(NET);	     return TK_NET;
+  handlers		section(HANDLERS);   return TK_HANDLERS;
+
+  {NDELIM}		{
+			  expect_error(
+				"one of 'startup|disk|net|syncer|handlers");
+			}
+}
+
 <*>{
   \{			syntax_error("unexpected opening brace.");
   \n			syntax_error("unexpected end of line, maybe missing ';' ? ");



More information about the drbd-cvs mailing list