[DRBD-cvs] svn commit by phil - r3086 - branches/drbd-8.2/user - Making the proxy support sane #1 * The host sections wi

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Wed Oct 3 10:07:02 CEST 2007


Author: phil
Date: 2007-10-03 10:07:00 +0200 (Wed, 03 Oct 2007)
New Revision: 3086

Modified:
   branches/drbd-8.2/user/drbdadm.h
   branches/drbd-8.2/user/drbdadm_main.c
   branches/drbd-8.2/user/drbdadm_parser.c
Log:
Making the proxy support sane #1
 * The host sections with the "proxy on" subsections
   may now be in arbitrary order.
 * In case there are no proxy options drbdadm should not
   call drbd-proxy-ctl a second time.


Modified: branches/drbd-8.2/user/drbdadm.h
===================================================================
--- branches/drbd-8.2/user/drbdadm.h	2007-10-02 15:14:34 UTC (rev 3085)
+++ branches/drbd-8.2/user/drbdadm.h	2007-10-03 08:07:00 UTC (rev 3086)
@@ -84,6 +84,7 @@
   int meta_minor;
   char* meta_index;
   struct d_proxy_info *proxy;
+  struct d_host_info* next;
 };
 
 struct d_option
@@ -101,6 +102,7 @@
   char* protocol;
   struct d_host_info* me;
   struct d_host_info* peer;
+  struct d_host_info* all_hosts;
   struct d_option* net_options;
   struct d_option* disk_options;
   struct d_option* sync_options;

Modified: branches/drbd-8.2/user/drbdadm_main.c
===================================================================
--- branches/drbd-8.2/user/drbdadm_main.c	2007-10-02 15:14:34 UTC (rev 3085)
+++ branches/drbd-8.2/user/drbdadm_main.c	2007-10-03 08:07:00 UTC (rev 3086)
@@ -1063,8 +1063,8 @@
     opt=opt->next; 
   }
   argv[NA(argc)]=0;
-
-  return m_system(argv,SLEEPS_SHORT);  
+  if(argc > 2) return m_system(argv,SLEEPS_SHORT);  
+  return rv;
 }
 
 

Modified: branches/drbd-8.2/user/drbdadm_parser.c
===================================================================
--- branches/drbd-8.2/user/drbdadm_parser.c	2007-10-02 15:14:34 UTC (rev 3085)
+++ branches/drbd-8.2/user/drbdadm_parser.c	2007-10-03 08:07:00 UTC (rev 3086)
@@ -325,10 +325,9 @@
 	}
 }
 
-static void parse_proxy_section(struct d_resource* res, struct d_host_info *host)
+static void parse_proxy_section(struct d_host_info *host)
 {
 	struct d_proxy_info *proxy;
-	struct d_host_info *tmp;
 
 	proxy=calloc(1,sizeof(struct d_proxy_info));
 	host->proxy = proxy;
@@ -337,14 +336,6 @@
 	EXP(TK_STRING);
 	proxy->name = yylval.txt;
 
-	/* TODO: This needs to get improved! This works now only for trivial two
-	   node cases! */
-	if(strcmp(proxy->name, nodeinfo.nodename) == 0 && host == res->peer) {
-		tmp = res->me;
-		res->me = res->peer;
-		res->peer = tmp;
-	}
-
 	EXP('{');
 	while (1) {
 		switch (yylex()) {
@@ -377,9 +368,19 @@
 }
 
 
-static void parse_host_body(struct d_host_info *host,
-			    struct d_resource *res, int require_all)
+static void parse_host_section(struct d_resource *res, 
+			       char *host_name, int require_all)
 {
+	struct d_host_info *host;
+
+	c_section_start = line;
+	fline = line;
+
+	host=calloc(1,sizeof(struct d_host_info));
+	host->name = host_name;
+	check_uniq("host section", "%s: on %s", res->name, host->name);
+	res->all_hosts = APPEND(res->all_hosts, host);
+
 	EXP('{');
 	while (1) {
 		switch (yylex()) {
@@ -451,7 +452,7 @@
 			}
 			break;
 		case TK_PROXY:
-			parse_proxy_section(res,host);
+			parse_proxy_section(host);
 			break;
 		case '}':
 			goto break_loop;
@@ -509,59 +510,10 @@
 	while (level) ;
 }
 
-
-static void parse_host_section(struct d_resource* res)
-{
-	struct d_host_info *host;
-
-	c_section_start = line;
-	fline = line;
-
-	host=calloc(1,sizeof(struct d_host_info));
-	EXP(TK_STRING);
-	host->name = yylval.txt;
-
-	check_uniq("host section", "%s: on %s", res->name, host->name);
-	if(strcmp(host->name, nodeinfo.nodename) == 0) {
-		// if (res->me) die duplicate entry ... done by check_uniq above
-		res->me = host;
-	} else {
-		if (res->peer) {
-			config_valid = 0;
-			fprintf(stderr,
-		"%s:%d: in resource %s, on %s { ... } ... on %s { ... }:\n"
-		"\tThere are multiple host sections for the peer.\n"
-		"\tMaybe misspelled local host name '%s'?\n",
-				config_file, c_section_start, res->name,
-				res->peer->name, host->name, nodeinfo.nodename);
-		}
-		res->peer = host;
-	}
-	parse_host_body(host,res,1);
-}
-
-static void parse_drbdsetup_host_dump(struct d_resource* res, int local)
-{
-	struct d_host_info *host;
-
-	c_section_start = line;
-
-	host=calloc(1,sizeof(struct d_host_info));
-
-	if(local) {
-		res->me = host;
-		host->name = strdup("_this_host");
-	} else {
-		res->peer = host;
-		host->name = strdup("_remote_host");
-	}
-
-	parse_host_body(host,res,0);
-}
-
 struct d_resource* parse_resource(char* res_name, enum pr_flags flags)
 {
 	struct d_resource* res;
+	struct d_host_info *host;
 	int token;
 
 	fline = line;
@@ -579,13 +531,14 @@
 			EXP(';');
 			break;
 		case TK_ON:
-			parse_host_section(res);
+			EXP(TK_STRING);
+			parse_host_section(res, yylval.txt, 1);
 			break;
 		case TK__THIS_HOST:
-			parse_drbdsetup_host_dump(res, 1);
+			parse_host_section(res, strdup("_this_host"), 0);
 			break;
 		case TK__REMOTE_HOST:
-			parse_drbdsetup_host_dump(res, 0);
+			parse_host_section(res, strdup("_remote_host"), 0);
 			break;
 		case TK_DISK:
 			check_uniq("disk section", "%s:disk", res->name);
@@ -626,6 +579,32 @@
 	}
 
  exit_loop:
+
+	/* Determin the local host section and the peer host section. */
+	host = res->all_hosts;
+	while(host) {
+		if(!strcmp(host->name, nodeinfo.nodename) ||
+		   !strcmp(host->name, "_this_host") ||
+		   ( host->proxy && 
+		     !strcmp(host->proxy->name, nodeinfo.nodename))) {
+			res->me = host;
+		} else {
+			/* This needs to be refined as soon as we support 
+			   multiple peers in the resource section */
+			if(res->peer) {
+				config_valid = 0;
+				fprintf(stderr,
+					"%s:%d: in resource %s, on %s { ... } ... on %s { ... }:\n"
+					"\tThere are multiple host sections for the peer.\n"
+					"\tMaybe misspelled local host name '%s'?\n",
+					config_file, c_section_start, res->name,
+						res->peer->name, host->name, nodeinfo.nodename);
+			}
+			res->peer = host;
+		}
+		host=host->next;
+	}
+
 	if(flags & ThisHRequired && !res->me) {
 		config_valid = 0;
 



More information about the drbd-cvs mailing list