[DRBD-cvs] svn commit by phil - r2388 - in trunk: . drbd user - Slowly shaking out the bugs of the new netlink/connecto

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Mon Aug 28 13:48:33 CEST 2006


Author: phil
Date: 2006-08-28 13:48:29 +0200 (Mon, 28 Aug 2006)
New Revision: 2388

Modified:
   trunk/Makefile
   trunk/drbd/drbd_main.c
   trunk/drbd/drbd_nl.c
   trunk/user/Makefile
   trunk/user/drbdadm.h
   trunk/user/drbdadm_adjust.c
   trunk/user/drbdadm_main.c
   trunk/user/drbdadm_parser.c
   trunk/user/drbdadm_scanner.fl
   trunk/user/drbdsetup.c
   trunk/user/drbdtool_common.c
Log:
Slowly shaking out the bugs of the new netlink/connector
based drbdsetup <-> kernel interface .


Modified: trunk/Makefile
===================================================================
--- trunk/Makefile	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/Makefile	2006-08-28 11:48:29 UTC (rev 2388)
@@ -13,7 +13,7 @@
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with drbd; see the file COPYING.  If not, write to
+# along with drbd
 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 #
 

Modified: trunk/drbd/drbd_main.c
===================================================================
--- trunk/drbd/drbd_main.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/drbd/drbd_main.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -2084,11 +2084,6 @@
 	/* no need to lock it, I'm the only thread alive */
 	if ( mdev->epoch_size !=  0)
 		ERR("epoch_size:%d\n",mdev->epoch_size);
-#define ZAP(x) memset(&x,0,sizeof(x))
-	ZAP(mdev->sync_conf);
-	// ZAP(mdev->data); Not yet!
-	// ZAP(mdev->meta); Not yet!
-#undef ZAP
 	mdev->al_writ_cnt  =
 	mdev->bm_writ_cnt  =
 	mdev->read_cnt     =
@@ -2361,7 +2356,6 @@
 	disk->first_minor = minor;
 	disk->fops = &drbd_ops;
 	sprintf(disk->disk_name, DEVICE_NAME "%d", minor);
-	sprintf(disk->devfs_name, "%s/%d", drbd_devfs_name, minor);
 	disk->private_data = mdev;
 	add_disk(disk);
 		

Modified: trunk/drbd/drbd_nl.c
===================================================================
--- trunk/drbd/drbd_nl.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/drbd/drbd_nl.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -690,12 +690,11 @@
 		goto fail;
 	}
 
-	if(inc_local(mdev)) {
+	if( !(nlp->flags & DRBD_NL_SET_DEFAULTS) && inc_local(mdev) ) {
 		memcpy(&nbc->dc,&mdev->bc->dc,sizeof(struct disk_conf));
 		dec_local(mdev);
-	} else memset(&nbc->dc,0,sizeof(struct disk_conf));
-
-	if(nlp->flags & DRBD_NL_SET_DEFAULTS) {
+	} else {
+		memset(&nbc->dc,0,sizeof(struct disk_conf));
 		nbc->dc.disk_size   = DRBD_DISK_SIZE_SECT_DEF;
 		nbc->dc.on_io_error = DRBD_ON_IO_ERROR_DEF;
 		nbc->dc.fencing     = DRBD_FENCING_DEF;
@@ -1019,12 +1018,11 @@
 		goto fail;
 	}
 
-	if(inc_net(mdev)) {
+	if( !(nlp->flags & DRBD_NL_SET_DEFAULTS) && inc_net(mdev)) {
 		memcpy(new_conf,mdev->net_conf,sizeof(struct net_conf));
 		dec_local(mdev);
-	} else memset(new_conf,0,sizeof(struct net_conf));
-
-	if(nlp->flags & DRBD_NL_SET_DEFAULTS) {
+	} else {
+		memset(new_conf,0,sizeof(struct net_conf));
 		new_conf->timeout         = DRBD_TIMEOUT_DEF;
 		new_conf->try_connect_int = DRBD_CONNECT_INT_DEF;
 		new_conf->ping_int        = DRBD_PING_INT_DEF;

Modified: trunk/user/Makefile
===================================================================
--- trunk/user/Makefile	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/Makefile	2006-08-28 11:48:29 UTC (rev 2388)
@@ -17,20 +17,28 @@
 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 #
 
+KDIR := /lib/modules/$(shell uname -r)/build
+
 CFLAGS = -g -O2 -c -W -Wall -I../drbd -I$(KDIR)/include
 CC = gcc
 
 drbdadm-obj = drbdadm_scanner.o drbdadm_parser.o drbdadm_main.o \
 	      drbdadm_adjust.o drbdtool_common.o drbdadm_usage_cnt.o \
-	      ../drbd/drbd_buildtag.o
+	      drbd_buildtag.o
 
-drbdsetup-obj = drbdsetup.o drbdtool_common.o ../drbd/drbd_buildtag.o \
-	        ../drbd/drbd_strings.o
+drbdsetup-obj = drbdsetup.o drbdtool_common.o drbd_buildtag.o \
+	        drbd_strings.o
 
-drbdmeta-obj = drbdmeta.o drbdmeta_scanner.o drbdtool_common.o ../drbd/drbd_buildtag.o
+drbdmeta-obj = drbdmeta.o drbdmeta_scanner.o drbdtool_common.o drbd_buildtag.o
 
 all: drbdadm drbdmeta drbdsetup
 
+drbd_buildtag.c: ../drbd/drbd_buildtag.c
+	cp $^ $@ 
+
+drbd_strings.c: ../drbd/drbd_strings.c
+	cp $^ $@ 
+
 drbdadm: $(drbdadm-obj)
 	$(CC) -o $@ $^ 
 
@@ -51,6 +59,7 @@
 clean:
 	rm -f drbdadm_scanner.c drbdmeta_scanner.c
 	rm -f drbdsetup drbdadm drbdmeta *.o
+	rm -f drbd_buildtag.c drbd_strings.c
 	rm -f *~
 
 distclean: clean
@@ -72,13 +81,14 @@
 	rm -f $(PREFIX)/sbin/drbdadm
 
 ###dependencies
-drbdsetup.o:       drbdtool_common.h           ../drbd/linux/drbd_limits.h
-drbdtool_common.o: drbdtool_common.h          
+drbdsetup.o:       drbdtool_common.h ../drbd/linux/drbd_limits.h
+drbdsetup.o:       ../drbd/linux/drbd_tag_magic.h ../drbd/linux/drbd.h
+drbdsetup.o:       ../drbd/linux/drbd_config.h ../drbd/linux/drbd_nl.h
+drbdtool_common.o: drbdtool_common.h    
 drbdadm_main.o:    drbdtool_common.h drbdadm.h
 drbdadm_adjust.o:  drbdtool_common.h drbdadm.h
 drbdadm_parser.o:  drbdtool_common.h drbdadm.h ../drbd/linux/drbd_limits.h
 drbdadm_scanner.o:                   drbdadm.h               drbdadm_parser.h 
 drbdsetup.o:       drbdtool_common.h           ../drbd/linux/drbd_limits.h
-drbdsetup.o: ../drbd/linux/drbd.h ../drbd/linux/drbd_config.h
 drbdmeta.o:        drbdtool_common.h drbd_endian.h 
 drbdadm_usage_cnt.o: drbdadm.h drbd_endian.h

Modified: trunk/user/drbdadm.h
===================================================================
--- trunk/user/drbdadm.h	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdadm.h	2006-08-28 11:48:29 UTC (rev 2388)
@@ -68,8 +68,6 @@
   char* name;
   char* device;
   char* disk;
-  int disk_major;
-  int disk_minor;
   char* address;
   char* port;
   char* meta_disk;

Modified: trunk/user/drbdadm_adjust.c
===================================================================
--- trunk/user/drbdadm_adjust.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdadm_adjust.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -139,15 +139,6 @@
 	return !strcmp(conf->protocol, running->protocol);
 }
 
-static int dev_eq(char* device_name, unsigned int g_major, unsigned int g_minor)
-{
-	struct stat sb;
-	
-	if(stat(device_name,&sb)) return 0;
-
-	return major(sb.st_rdev) == g_major && minor(sb.st_rdev) == g_minor;
-}
-
 /* Are both internal, or are both not internal. */
 static int int_eq(char* m_conf, char* m_running)
 {
@@ -158,10 +149,10 @@
 {
 	int eq = 1;
 
-	eq &= dev_eq(conf->disk,running->disk_major,running->disk_minor);
+	eq &= !strcmp(conf->disk,running->disk);
 	eq &= int_eq(conf->meta_disk,running->meta_disk);
 	if(!strcmp(conf->meta_disk,"internal")) return eq;
-	eq &= dev_eq(conf->meta_disk,running->meta_major,running->meta_minor);
+	eq &= !strcmp(conf->meta_disk,running->meta_disk);
 
 	return eq;
 }

Modified: trunk/user/drbdadm_main.c
===================================================================
--- trunk/user/drbdadm_main.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdadm_main.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -623,8 +623,14 @@
   argv[argc++]=res->me->device;
   argv[argc++]="disk";
   argv[argc++]=res->me->disk;
-  argv[argc++]=res->me->meta_disk;
+  if(!strcmp(res->me->meta_disk,"internal")) {
+    argv[argc++]=res->me->disk;
+  } else {
+    argv[argc++]=res->me->meta_disk;
+  }
   argv[argc++]=res->me->meta_index;
+  argv[argc++]="--set-defaults";
+  argv[argc++]="--create-device";
   opt=res->disk_options;
   make_options(opt);
   argv[argc++]=0;
@@ -790,6 +796,8 @@
   ssprintf(argv[argc++],"%s:%s",res->peer->address,res->peer->port);
   argv[argc++]=res->protocol;
 
+  argv[argc++]="--set-defaults";
+  argv[argc++]="--create-device";
   opt=res->net_options;
   make_options(opt);
 
@@ -829,6 +837,8 @@
   argv[argc++]=res->me->device;
   argv[argc++]="syncer";
 
+  argv[argc++]="--set-defaults";
+  argv[argc++]="--create-device";
   opt=res->sync_options;
   make_options(opt);
   argv[argc++]=0;

Modified: trunk/user/drbdadm_parser.c
===================================================================
--- trunk/user/drbdadm_parser.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdadm_parser.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -338,19 +338,7 @@
 			host->disk = yylval.txt;
 			check_uniq("disk", "%s:%s:%s", "disk",
 				   host->name, yylval.txt);
-			switch (yylex()) {
-			case TK__MAJOR:
-				EXP(TK_INTEGER);
-				host->disk_major = atoi(yylval.txt);
-				EXP(TK__MINOR);
-				EXP(TK_INTEGER);
-				host->disk_minor = atoi(yylval.txt);
-				EXP(';');
-			case ';':
-				break;
-			default:
-				pe_expected("_major | ;");
-			}
+			EXP(';');
 			break;
 		case TK_DEVICE:
 			check_uniq("device statement", "%s:%s:device",
@@ -383,19 +371,7 @@
 				EXP(TK_INTEGER);
 				host->meta_index = yylval.txt;
 				EXP(']');
-				switch (yylex()) {
-				case TK__MAJOR:
-					EXP(TK_INTEGER);
-					host->meta_major = atoi(yylval.txt);
-					EXP(TK__MINOR);
-					EXP(TK_INTEGER);
-					host->meta_minor = atoi(yylval.txt);
-					EXP(';');
-				case ';':
-					break;
-				default:
-					pe_expected("_major | ;");
-				}
+				EXP(';');
 			} else {
 				EXP(';');
 			}

Modified: trunk/user/drbdadm_scanner.fl
===================================================================
--- trunk/user/drbdadm_scanner.fl	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdadm_scanner.fl	2006-08-28 11:48:29 UTC (rev 2388)
@@ -63,8 +63,6 @@
 flexible-meta-disk	{ DP; return TK_FLEX_META_DISK;		}
 usage-count 		{ DP; return TK_USAGE_COUNT;		}
 _is_default 		{ DP; return TK__IS_DEFAULT;		}
-_major	 		{ DP; return TK__MAJOR;			}
-_minor	 		{ DP; return TK__MINOR;			}
 _this_host 		{ DP; return TK__THIS_HOST;		}
 _remote_host 		{ DP; return TK__REMOTE_HOST;		}
 size			{ DP; CP; RC(DISK_SIZE); return TK_DISK_OPTION;	}

Modified: trunk/user/drbdsetup.c
===================================================================
--- trunk/user/drbdsetup.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdsetup.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -87,9 +87,9 @@
 	void (*show_function)(struct drbd_option *,unsigned short*);
 	union {
 		struct {
-			const unsigned long long min;
-			const unsigned long long max;
-			const unsigned long long def;
+			const long long min;
+			const long long max;
+			const long long def;
 			const unsigned char default_unit;
 		} numeric_param;
 		struct {
@@ -118,9 +118,11 @@
 
 // other functions
 void print_command_usage(int i, const char *addinfo);
+
 // command functions
 int generic_config_cmd(struct drbd_cmd *cm, int minor, int argc, char **argv);
 int show_cmd(struct drbd_cmd *cm, int minor, int argc, char **argv);
+int down_cmd(struct drbd_cmd *cm, int minor, int argc, char **argv);
 // convert functions for arguments
 int conv_block_dev(struct drbd_argument *ad, struct drbd_tag_list *tl, char* arg);
 int conv_md_idx(struct drbd_argument *ad, struct drbd_tag_list *tl, char* arg);
@@ -171,10 +173,10 @@
 	[PanicPrimary]      = "panic"
 };
 
-#define EN(N) \
+#define EN(N,U) \
 	conv_numeric, show_numeric, \
 	{ .numeric_param = { DRBD_ ## N ## _MIN, DRBD_ ## N ## _MAX, \
-		DRBD_ ## N ## _DEF ,0  } }
+		DRBD_ ## N ## _DEF ,U  } }
 #define EH(N,D) \
 	conv_handler, show_handler, { .handler_param = { N, ARRY_SIZE(N), \
 	DRBD_ ## D ## _DEF } }
@@ -196,7 +198,7 @@
 		 { "meta_data_index",	T_meta_dev_idx,	conv_md_idx },
 		 { NULL,                0,           	NULL}, },
 	 (struct drbd_option[]) {
-		 { "size",'d',		T_disk_size,	EN(DISK_SIZE_SECT) },
+		 { "size",'d',		T_disk_size,	EN(DISK_SIZE_SECT,'s') },
 		 { "on-io-error",'e',	T_on_io_error,	EH(on_error,ON_IO_ERROR) },
 		 { "fencing",'f',	T_fencing,      EH(fencing_n,FENCING) },
 		 { NULL,0,0,NULL,NULL, { } }, }, },
@@ -210,14 +212,14 @@
 		 { "protocol",		T_wire_protocol,conv_protocol },
  		 { NULL,                0,           	NULL}, },
 	 (struct drbd_option[]) {
-		 { "timeout",'t',	T_timeout,	EN(TIMEOUT) },
-		 { "max-epoch-size",'e',T_max_epoch_size,EN(MAX_EPOCH_SIZE) },
-		 { "max-buffers",'b',	T_max_buffers,	EN(MAX_BUFFERS) },
-		 { "unplug-watermark",'u',T_unplug_watermark, EN(UNPLUG_WATERMARK) },
-		 { "connect-int",'c',	T_try_connect_int, EN(CONNECT_INT) },
-		 { "ping-int",'i',	T_ping_int,	   EN(PING_INT) },
-		 { "sndbuf-size",'S',	T_sndbuf_size,	   EN(SNDBUF_SIZE) },
-		 { "ko-count",'k',	T_ko_count,	   EN(KO_COUNT) },
+		 { "timeout",'t',	T_timeout,	EN(TIMEOUT,1) },
+		 { "max-epoch-size",'e',T_max_epoch_size,EN(MAX_EPOCH_SIZE,1) },
+		 { "max-buffers",'b',	T_max_buffers,	EN(MAX_BUFFERS,1) },
+		 { "unplug-watermark",'u',T_unplug_watermark, EN(UNPLUG_WATERMARK,1) },
+		 { "connect-int",'c',	T_try_connect_int, EN(CONNECT_INT,1) },
+		 { "ping-int",'i',	T_ping_int,	   EN(PING_INT,1) },
+		 { "sndbuf-size",'S',	T_sndbuf_size,	   EN(SNDBUF_SIZE,1) },
+		 { "ko-count",'k',	T_ko_count,	   EN(KO_COUNT,1) },
 		 { "allow-two-primaries",'m',T_two_primaries, EB },
 		 { "cram-hmac-alg",'a',	T_cram_hmac_alg,   ES },
 		 { "shared-secret",'x',	T_shared_secret,   ES },
@@ -231,14 +233,14 @@
 
 	{"resize", P_resize, generic_config_cmd, NULL,
 	 (struct drbd_option[]) {
-		 { "size",'s',T_resize_size,		EN(DISK_SIZE_SECT) },
+		 { "size",'s',T_resize_size,		EN(DISK_SIZE_SECT,'s') },
 		 { NULL,0,0,NULL,NULL, { } }, }, },
 
 	{"syncer", P_syncer_conf, generic_config_cmd, NULL,
 	 (struct drbd_option[]) {
-		 { "rate",'r',T_rate,			EN(RATE) },
-		 { "after",'a',T_after,			EN(AFTER) },
-		 { "al-extents",'e',T_al_extents,	EN(AL_EXTENTS) },
+		 { "rate",'r',T_rate,			EN(RATE,'k') },
+		 { "after",'a',T_after,			EN(AFTER,1) },
+		 { "al-extents",'e',T_al_extents,	EN(AL_EXTENTS,1) },
 		 { NULL,0,0,NULL,NULL, { } }, }, },
 
 	{"invalidate", P_invalidate, generic_config_cmd, NULL, NULL },
@@ -248,9 +250,8 @@
 	{"suspend-io", P_suspend_io, generic_config_cmd, NULL, NULL },
 	{"resume-io", P_resume_io, generic_config_cmd, NULL, NULL },
 	{"outdate", P_outdate, generic_config_cmd, NULL, NULL },
+	{"down", 0, down_cmd, NULL, NULL },
 
-	// {"down", 0 , down_cmd, NULL, NULL },
-
 	/*
 	{"state", cmd_state,               0, 0, },
 	{"cstate", cmd_cstate,             0, 0, },
@@ -298,13 +299,14 @@
 	EM(NoResizeDuringResync) = "Resize not allowed during resync.",
 	EM(APrimaryNodeNeeded) = "Need the a primary node to resize.",
 	EM(SyncAfterInvalid) = "The sync after minor number is invalid",
-	EM(SyncAfterCycle-) = "This would cause a sync-after dependency cycle",
+	EM(SyncAfterCycle) = "This would cause a sync-after dependency cycle",
 	EM(PauseFlagAlreadySet) = "PauseFlagAlreadySet",
 	EM(PauseFlagAlreadyClear) = "PauseFlagAlreadyClear",
 	EM(DiskLowerThanOutdated) = "DiskLowerThanOutdated",
 	EM(FailedToClaimMyself) = "FailedToClaimMyself",
 };
 
+const char empty_string[] = "";
 char* cmdname = 0;
 
 int dump_tag_list(unsigned short *tlc)
@@ -315,7 +317,7 @@
 	int integer;
 	char bit;
 	__u64 int64;
-	char* string;
+	const char* string;
 	int found_unknown=0;
 
 	while( (tag = *tlc++ ) != TT_END) {
@@ -425,7 +427,7 @@
 	int idx;
 
 	if(!strcmp(arg,"internal")) idx = DRBD_MD_INDEX_FLEX_INT;
-	else if(!strcmp(arg,"flex")) idx = DRBD_MD_INDEX_FLEX_EXT;
+	else if(!strcmp(arg,"flexible")) idx = DRBD_MD_INDEX_FLEX_EXT;
 	else idx = m_strtoll(arg,1);
 
 	add_tag(tl,ad->tag,&idx,sizeof(idx));
@@ -508,7 +510,7 @@
 	return 0;
 }
 
-int conv_bit(struct drbd_option *od, struct drbd_tag_list *tl, char* arg)
+int conv_bit(struct drbd_option *od, struct drbd_tag_list *tl, char* arg __attribute((unused)))
 {
 	char bit=1;
 
@@ -519,10 +521,10 @@
 
 int conv_numeric(struct drbd_option *od, struct drbd_tag_list *tl, char* arg)
 {
-	const unsigned long long min = od->numeric_param.min;
-	const unsigned long long max = od->numeric_param.max;
+	const long long min = od->numeric_param.min;
+	const long long max = od->numeric_param.max;
 	const unsigned char default_unit = od->numeric_param.default_unit;
-	unsigned long long l;
+	long long l;
 	int i;
 	char unit[] = {0,0};
 
@@ -731,7 +733,7 @@
 		val=0;
 	}
 
-	printf("\t%s\t\t%lld",od->name,val);
+	printf("\t%-16s\t%lld",od->name,val);
 	if(val == (long long) od->numeric_param.def) printf(" _is_default");
 	printf(";\n");
 }
@@ -744,7 +746,7 @@
 	ASSERT( tag_type(*tp++) == TT_INTEGER );
 	ASSERT( *tp++ == sizeof(int) );
 	i = *(int*)tp;
-	printf("\t%s\t\t%s",od->name,handler_names[i]);
+	printf("\t%-16s\t%s",od->name,handler_names[i]);
 	if( i == (long long)od->numeric_param.def) printf(" _is_default");
 	printf(";\n");
 }
@@ -753,13 +755,13 @@
 {
 	ASSERT( tag_type(*tp++) == TT_BIT );
 	ASSERT( *tp++ == sizeof(char) );
-	if(*(char*)tp) printf("\t%s;\n",od->name);
+	if(*(char*)tp) printf("\t%-16s;\n",od->name);
 }
 
 void show_string(struct drbd_option *od, unsigned short* tp)
 {
 	ASSERT( tag_type(*tp++) == TT_STRING );
-	if( *tp++ > 0) printf("\t%s\t\t\"%s\";\n",od->name,(char*)tp);
+	if( *tp++ > 0) printf("\t%-16s\t\"%s\";\n",od->name,(char*)tp);
 }
 
 unsigned short *look_for_tag(unsigned short *tlc, unsigned short tag)
@@ -798,7 +800,7 @@
 	}
 }
 
-char* consume_tag_string(enum drbd_tags tag, unsigned short *tlc)
+const char* consume_tag_string(enum drbd_tags tag, unsigned short *tlc)
 {
 	unsigned short *tp;
 	tp = look_for_tag(tlc,tag);
@@ -806,7 +808,7 @@
 		*tp++ = TT_REMOVED;
 		if( *tp++ > 0) return (char*)tp;
 	}
-	return "";
+	return empty_string;
 }
 
 int consume_tag_int(enum drbd_tags tag, unsigned short *tlc)
@@ -821,7 +823,7 @@
 	return 0;
 }
 
-int show_cmd(struct drbd_cmd *cm, int minor, int argc, char **argv)
+int show_cmd(struct drbd_cmd *cm, int minor, int argc, char **argv __attribute((unused)))
 {
 	char buffer[ 4096 ];
 	struct drbd_tag_list *tl;
@@ -831,13 +833,12 @@
 	unsigned short *rtl;
 
 	int idx;
-	char* str;
+	const char* str;
 
 	ASSERT(cm->packet_id == P_get_config);
 
 	if(argc > 1) {
 		fprintf(stderr,"Ignoring excess arguments\n");
-	
 	}
 
 	tl = create_tag_list(2);
@@ -865,15 +866,15 @@
 	idx = consume_tag_int(T_wire_protocol,rtl);
 	if(idx) printf("protocol %c;\n",'A'+idx-1);
 	str = consume_tag_string(T_backing_dev,rtl);
-	if(str) {
+	if(str != empty_string) {
 		printf("_this_host {\n");
-		printf("\tdevice\t\t\"/dev/drbd%d\";\n",minor);
-		printf("\tdisk\t\t\"%s\";\n",str);
+		printf("\tdevice\t\t\t\"/dev/drbd%d\";\n",minor);
+		printf("\tdisk\t\t\t\"%s\";\n",str);
 		idx=consume_tag_int(T_meta_dev_idx,rtl);
 		switch(idx) {
 		case DRBD_MD_INDEX_INTERNAL:
 		case DRBD_MD_INDEX_FLEX_INT:
-			printf("\tmeta-disk\tinternal;\n");
+			printf("\tmeta-disk\t\tinternal;\n");
 			consume_tag_string(T_meta_dev,rtl);
 			break;
 		case DRBD_MD_INDEX_FLEX_EXT:
@@ -881,13 +882,13 @@
 			       consume_tag_string(T_meta_dev,rtl));
 			break;
 		default:
-			printf("\tmeta-disk\t\"%s\" [ %d ];\n",
+			printf("\tmeta-disk\t\t\"%s\" [ %d ];\n",
 			       consume_tag_string(T_meta_dev,rtl),idx);
 		}
 		str = consume_tag_string(T_my_addr,rtl);
-		if(str) {
+		if(str != empty_string ) {
 			addr = (struct sockaddr_in *)str;
-			printf("\taddress\t\t%s:%d;\n",
+			printf("\taddress\t\t\t%s:%d;\n",
 			       inet_ntoa(addr->sin_addr),
 			       ntohs(addr->sin_port));
 		}
@@ -895,10 +896,10 @@
 	}
 
 	str = consume_tag_string(T_peer_addr,rtl);
-	if(str) {
+	if(str != empty_string) {
 		printf("_remote_host {\n");
 		addr = (struct sockaddr_in *)str;
-		printf("\taddress\t\t%s:%d;\n",
+		printf("\taddress\t\t\t%s:%d;\n",
 		       inet_ntoa(addr->sin_addr),
 		       ntohs(addr->sin_port));
 		printf("}\n");
@@ -912,6 +913,35 @@
 	return 0;
 }
 
+static struct drbd_cmd *find_cmd_by_name(const char* name)
+{
+	unsigned int i;
+
+	for(i=0;i<ARRY_SIZE(commands);i++) {
+		if(!strcmp(name,commands[i].cmd)) {
+			return commands+i;
+		}
+	}
+	return NULL;
+}
+
+int down_cmd(struct drbd_cmd *cm __attribute((unused)), int minor, int argc, char **argv)
+{
+	struct drbd_cmd *cmd;
+	int rv = 0;
+
+	if(argc > 1) {
+		fprintf(stderr,"Ignoring excess arguments\n");	
+	}
+
+	cmd = find_cmd_by_name("disconnect");
+	rv |= cmd->function(cmd,minor,argc,argv);
+	cmd = find_cmd_by_name("detach");
+	rv |= cmd->function(cmd,minor,argc,argv);
+
+	return rv;
+}
+
 void print_command_usage(int i, const char *addinfo)
     // CAUTION no range check for i
 {
@@ -1096,11 +1126,9 @@
 
 int main(int argc, char** argv)
 {
-	int help = 0;
-	unsigned int i;
-	int minor;
-	int drbd_fd,lock_fd;
+	int minor,drbd_fd,lock_fd;
 	struct drbd_cmd *cmd;
+	int help = 0, rv=0;
 
 	chdir("/");
 
@@ -1115,22 +1143,16 @@
 
 	if (argc < 3) print_usage(argc==1 ? 0 : " Insufficient arguments");
 
-	cmd=NULL;
-	for(i=0;i<ARRY_SIZE(commands);i++) {
-		if(strcmp(argv[2],commands[i].cmd)==0) {
-			cmd = commands+i;
-			break;
-		}
-	}
+	cmd=find_cmd_by_name(argv[2]);
 
 	if(cmd) {
 		drbd_fd = dt_lock_open_drbd(argv[1], &lock_fd, 1 );
 		minor=dt_minor_of_dev(argv[1]);
-		commands[i].function(commands+i,minor,argc-3,argv+3);
+		rv = cmd->function(cmd,minor,argc-3,argv+3);
 		dt_close_drbd_unlock(drbd_fd,lock_fd);
 	} else {
 		print_usage("invalid command");
 	}
 
-	return 0;
+	return rv;
 }

Modified: trunk/user/drbdtool_common.c
===================================================================
--- trunk/user/drbdtool_common.c	2006-08-25 09:01:54 UTC (rev 2387)
+++ trunk/user/drbdtool_common.c	2006-08-28 11:48:29 UTC (rev 2388)
@@ -80,6 +80,10 @@
       shift = -10;
       break;
 
+    case 's':
+      shift = -9;   // sectors 
+      break;
+
       /*
          case 'M':
          case 'm':



More information about the drbd-cvs mailing list