[SCM] CTDB repository - branch master updated - ctdb-1.12-98-g57fb074

Ronnie Sahlberg sahlberg at samba.org
Mon Dec 5 21:15:03 MST 2011


The branch, master has been updated
       via  57fb074a65dc56168fc3813b79a5bab4b3727cf3 (commit)
       via  bf1174ef699b06485b36ee8ae70412be0759e142 (commit)
       via  f93ffeee7b9e9ca5dd116655bdc7f89fc987ed8a (commit)
       via  c4b72683eb046007fbc2e60b4a54bc91faf4cf7e (commit)
       via  8527396b7290cfc8378779631e91d2ae09e2a106 (commit)
      from  0f15a2c65db8f8b4ac0d5ad2755b9aa3c2a8b279 (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 57fb074a65dc56168fc3813b79a5bab4b3727cf3
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 29 15:18:45 2011 +1100

    ctdb tool - move parsing of nodestring to where it is needed
    
    This puts the parsing and checking logic close together.  This makes
    it easy to change the parsing code.  Changed parsing code can now
    easily use both old client code and libctdb since both are guaranteed
    to be setup.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit bf1174ef699b06485b36ee8ae70412be0759e142
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 29 15:17:09 2011 +1100

    ctdb tool - replace fprintf with DEBUG
    
    It's the only one in the file.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit f93ffeee7b9e9ca5dd116655bdc7f89fc987ed8a
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 29 14:38:39 2011 +1100

    ctdb tool - short circuit most of the logic in main for non-daemon commands
    
    This allows all that logic to be hacked a little more easily.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit c4b72683eb046007fbc2e60b4a54bc91faf4cf7e
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 29 14:25:31 2011 +1100

    ctdb tool - commands that don't use the daemon can't take -n/--node
    
    It just doesn't make sense!
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 8527396b7290cfc8378779631e91d2ae09e2a106
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Nov 29 14:20:26 2011 +1100

    ctdb tool - simplify main() by taking most code out of a loop
    
    Most of the action in main() happens inside a for loop and an if
    statement.  This causes 2 levels of extra indent for the code and
    makes it harder to read.
    
    Instead, the current body of the loop is put below the loop and its
    corresponding failure check.
    
    To see how small this change really is, view with "diff -w".  ;-)
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 tools/ctdb.c |  126 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 64 insertions(+), 62 deletions(-)


Changeset truncated at 500 lines:

diff --git a/tools/ctdb.c b/tools/ctdb.c
index a356c28..793e98f 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -5265,6 +5265,7 @@ int main(int argc, const char *argv[])
 	poptContext pc;
 	struct event_context *ev;
 	const char *control;
+	const char *socket_name;
 
 	setlinebuf(stdout);
 	
@@ -5309,15 +5310,6 @@ int main(int argc, const char *argv[])
 	signal(SIGALRM, ctdb_alarm);
 	alarm(options.maxruntime);
 
-	/* setup the node number to contact */
-	if (nodestring != NULL) {
-		if (strcmp(nodestring, "all") == 0) {
-			options.pnn = CTDB_BROADCAST_ALL;
-		} else {
-			options.pnn = strtoul(nodestring, NULL, 0);
-		}
-	}
-
 	control = extra_argv[0];
 
 	ev = event_context_init(NULL);
@@ -5329,69 +5321,79 @@ int main(int argc, const char *argv[])
 
 	for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {
 		if (strcmp(control, ctdb_commands[i].name) == 0) {
-			int j;
+			break;
+		}
+	}
 
-			if (ctdb_commands[i].without_daemon == true) {
-				close(2);
-			}
+	if (i == ARRAY_SIZE(ctdb_commands)) {
+		DEBUG(DEBUG_ERR, ("Unknown control '%s'\n", control));
+		exit(1);
+	}
 
-			/* initialise ctdb */
-			ctdb = ctdb_cmdline_client(ev, TIMELIMIT());
+	if (ctdb_commands[i].without_daemon == true) {
+		if (nodestring != NULL) {
+			DEBUG(DEBUG_ERR, ("Can't specify node(s) with \"ctdb %s\"\n", control));
+			exit(1);
+		}
+		close(2);
+		return ctdb_commands[i].fn(NULL, extra_argc-1, extra_argv+1);
+	}
 
-			if (ctdb_commands[i].without_daemon == false) {
-				const char *socket_name;
+	/* initialise ctdb */
+	ctdb = ctdb_cmdline_client(ev, TIMELIMIT());
 
-				if (ctdb == NULL) {
-					DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
-					exit(1);
-				}
+	if (ctdb == NULL) {
+		DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
+		exit(1);
+	}
 
-				/* initialize a libctdb connection as well */
-				socket_name = ctdb_get_socketname(ctdb);
-				ctdb_connection = ctdb_connect(socket_name,
-						       ctdb_log_file, stderr);
-				if (ctdb_connection == NULL) {
-					fprintf(stderr, "Failed to connect to daemon from libctdb\n");
-					exit(1);
-				}				
-			
-				/* verify the node exists */
-				verify_node(ctdb);
-
-				if (options.pnn == CTDB_CURRENT_NODE) {
-					int pnn;
-					pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);		
-					if (pnn == -1) {
-						return -1;
-					}
-					options.pnn = pnn;
-				}
-			}
+	/* initialize a libctdb connection as well */
+	socket_name = ctdb_get_socketname(ctdb);
+	ctdb_connection = ctdb_connect(socket_name,
+				       ctdb_log_file, stderr);
+	if (ctdb_connection == NULL) {
+		DEBUG(DEBUG_ERR, ("Failed to connect to daemon from libctdb\n"));
+		exit(1);
+	}				
 
-			if (ctdb_commands[i].auto_all && 
-			    options.pnn == CTDB_BROADCAST_ALL) {
-				uint32_t *nodes;
-				uint32_t num_nodes;
-				ret = 0;
+	/* setup the node number to contact */
+	if (nodestring != NULL) {
+		if (strcmp(nodestring, "all") == 0) {
+			options.pnn = CTDB_BROADCAST_ALL;
+		} else {
+			options.pnn = strtoul(nodestring, NULL, 0);
+		}
+	}
 
-				nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes);
-				CTDB_NO_MEMORY(ctdb, nodes);
-	
-				for (j=0;j<num_nodes;j++) {
-					options.pnn = nodes[j];
-					ret |= ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);
-				}
-				talloc_free(nodes);
-			} else {
-				ret = ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);
-			}
-			break;
+	/* verify the node exists */
+	verify_node(ctdb);
+
+	if (options.pnn == CTDB_CURRENT_NODE) {
+		int pnn;
+		pnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);		
+		if (pnn == -1) {
+			return -1;
 		}
+		options.pnn = pnn;
 	}
 
-	if (i == ARRAY_SIZE(ctdb_commands)) {
-		DEBUG(DEBUG_ERR, ("Unknown control '%s'\n", control));
-		exit(1);
+	if (ctdb_commands[i].auto_all && 
+	    options.pnn == CTDB_BROADCAST_ALL) {
+		uint32_t *nodes;
+		uint32_t num_nodes;
+		int j;
+		ret = 0;
+
+		nodes = ctdb_get_connected_nodes(ctdb, TIMELIMIT(), ctdb, &num_nodes);
+		CTDB_NO_MEMORY(ctdb, nodes);
+	
+		for (j=0;j<num_nodes;j++) {
+			options.pnn = nodes[j];
+			ret |= ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);
+		}
+		talloc_free(nodes);
+	} else {
+		ret = ctdb_commands[i].fn(ctdb, extra_argc-1, extra_argv+1);
 	}
 
 	return ret;


-- 
CTDB repository


More information about the samba-cvs mailing list