diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index 52659520d52..e700f4bf1e2 100644 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -53,9 +53,9 @@ bin/ctdb_test: $(OBJS) tests/ctdb_test.o tests/cmdline.o @echo Linking $@ @$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o tests/cmdline.o $(OBJS) $(LIB_FLAGS) -bin/ctdbd: $(OBJS) direct/ctdbd.o +bin/ctdbd: $(OBJS) direct/ctdbd.o tests/cmdline.o @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ direct/ctdbd.o $(OBJS) $(LIB_FLAGS) + @$(CC) $(CFLAGS) -o $@ direct/ctdbd.o tests/cmdline.o $(OBJS) $(LIB_FLAGS) bin/ctdbd_test: $(OBJS) direct/ctdbd_test.o @echo Linking $@ diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index 0ccbecd905e..2d3b6f79167 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -215,6 +215,9 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length) return; } + DEBUG(3,(__location__ " ctdb request of type %d length %d from node %d to %d\n", + hdr->operation, hdr->length, hdr->srcnode, hdr->destnode)); + switch (hdr->operation) { case CTDB_REQ_CALL: ctdb_request_call(ctdb, hdr); @@ -245,7 +248,8 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length) break; default: - printf("Packet with unknown operation %d\n", hdr->operation); + DEBUG(0,("%s: Packet with unknown operation %d\n", + __location__, hdr->operation)); break; } talloc_free(hdr); @@ -257,8 +261,8 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length) static void ctdb_node_dead(struct ctdb_node *node) { node->ctdb->num_connected--; - printf("%s: node %s is dead: %d connected\n", - node->ctdb->name, node->name, node->ctdb->num_connected); + DEBUG(1,("%s: node %s is dead: %d connected\n", + node->ctdb->name, node->name, node->ctdb->num_connected)); } /* @@ -267,8 +271,8 @@ static void ctdb_node_dead(struct ctdb_node *node) static void ctdb_node_connected(struct ctdb_node *node) { node->ctdb->num_connected++; - printf("%s: connected to %s - %d connected\n", - node->ctdb->name, node->name, node->ctdb->num_connected); + DEBUG(1,("%s: connected to %s - %d connected\n", + node->ctdb->name, node->name, node->ctdb->num_connected)); } /* diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c index f9bbd901aa5..65a1a5659c9 100644 --- a/ctdb/common/ctdb_call.c +++ b/ctdb/common/ctdb_call.c @@ -276,7 +276,7 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr return; } if (ret == -2) { - printf("deferring ctdb_request_dmaster\n"); + DEBUG(2,(__location__ " deferring ctdb_request_dmaster\n")); return; } @@ -357,7 +357,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) return; } if (ret == -2) { - printf("deferred ctdb_request_call\n"); + DEBUG(2,(__location__ " deferred ctdb_request_call\n")); return; } @@ -425,7 +425,7 @@ void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) if (state == NULL) return; if (!talloc_get_type(state, struct ctdb_call_state)) { - printf("ctdb idr type error at %s\n", __location__); + DEBUG(0,("ctdb idr type error at %s\n", __location__)); return; } @@ -465,7 +465,7 @@ void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) } if (!talloc_get_type(state, struct ctdb_call_state)) { - printf("ctdb idr type error at %s\n", __location__); + DEBUG(0,("ctdb idr type error at %s\n", __location__)); return; } @@ -507,7 +507,7 @@ void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) if (state == NULL) return; if (!talloc_get_type(state, struct ctdb_call_state)) { - printf("ctdb idr type error at %s\n", __location__); + DEBUG(0,("ctdb idr type error at %s\n", __location__)); return; } @@ -537,7 +537,7 @@ void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) if (state == NULL) return; if (!talloc_get_type(state, struct ctdb_call_state)) { - printf("ctdb idr type error at %s\n", __location__); + DEBUG(0,("ctdb idr type error at %s\n", __location__)); return; } diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index df2a01d86a9..c6071e7ba17 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -78,7 +78,7 @@ void ctdb_reply_fetch_lock(struct ctdb_context *ctdb, struct ctdb_req_header *hd if (state == NULL) return; if (!talloc_get_type(state, struct ctdb_fetch_lock_state)) { - printf("ctdb idr type error at %s\n", __location__); + DEBUG(0, ("ctdb idr type error at %s\n", __location__)); return; } @@ -139,7 +139,7 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args) break; default: - printf("bogus operation code:%d\n",hdr->operation); + DEBUG(0,("bogus operation code:%d\n",hdr->operation)); } } @@ -266,7 +266,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, state = talloc_zero(ctdb_db, struct ctdb_call_state); if (state == NULL) { - printf("failed to allocate state\n"); + DEBUG(0, (__location__ " failed to allocate state\n")); return NULL; } @@ -275,7 +275,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize; state->c = ctdbd_allocate_pkt(ctdb, len); if (state->c == NULL) { - printf("failed to allocate packet\n"); + DEBUG(0, (__location__ " failed to allocate packet\n")); return NULL; } talloc_set_name_const(state->c, "ctdbd req_call packet"); @@ -417,7 +417,7 @@ void ctdb_connect_wait(struct ctdb_context *ctdb) res = ctdb_queue_send(ctdb->daemon.queue, (uint8_t *)&r.hdr, r.hdr.length); if (res != 0) { - printf("Failed to queue a connect wait request\n"); + DEBUG(0,(__location__ " Failed to queue a connect wait request\n")); return; } @@ -449,7 +449,7 @@ static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_ state = talloc_zero(ctdb_db, struct ctdb_fetch_lock_state); if (state == NULL) { - printf("failed to allocate state\n"); + DEBUG(0, (__location__ " failed to allocate state\n")); return NULL; } state->state = CTDB_FETCH_LOCK_WAIT; @@ -457,7 +457,7 @@ static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_ len = offsetof(struct ctdb_req_fetch_lock, key) + key.dsize; state->req = req = ctdbd_allocate_pkt(ctdb, len); if (req == NULL) { - printf("failed to allocate packet\n"); + DEBUG(0, (__location__ " failed to allocate packet\n")); return NULL; } ZERO_STRUCT(*req); @@ -559,7 +559,7 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL /* step 1 - get the chain lock */ ret = ctdb_ltdb_lock(ctdb_db, key); if (ret != 0) { - printf("failed to lock ltdb record\n"); + DEBUG(0, (__location__ " failed to lock ltdb record\n")); talloc_free(h); return NULL; } @@ -590,7 +590,7 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL h->header.dmaster = ctdb_db->ctdb->vnn; ret = ctdb_ltdb_store(ctdb_db, key, &h->header, *data); if (ret != 0) { - printf("bugger - we're in real trouble now! can't update record to mark us as dmasterx\n"); + DEBUG(0, (__location__" can't update record to mark us as dmaster\n")); talloc_free(h); return NULL; } diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c index cf0c72a58b7..e824e098e56 100644 --- a/ctdb/common/ctdb_util.c +++ b/ctdb/common/ctdb_util.c @@ -25,6 +25,8 @@ #include "system/filesys.h" #include "../include/ctdb_private.h" +int LogLevel; + /* return error string for last error */ diff --git a/ctdb/direct/ctdbd.c b/ctdb/direct/ctdbd.c index 9e13c4c825a..bfd73d551b9 100644 --- a/ctdb/direct/ctdbd.c +++ b/ctdb/direct/ctdbd.c @@ -23,6 +23,7 @@ #include "system/filesys.h" #include "popt.h" #include "system/wait.h" +#include "tests/cmdline.h" static void block_signal(int signum) { @@ -43,21 +44,12 @@ static void block_signal(int signum) int main(int argc, const char *argv[]) { struct ctdb_context *ctdb; - const char *nlist = NULL; - const char *transport = "tcp"; - const char *myaddress = NULL; - int self_connect=0; - int daemon_mode=0; const char *db_list = "test.tdb"; char *s, *tok; struct poptOption popt_options[] = { POPT_AUTOHELP - { "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" }, - { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" }, - { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL }, - { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" }, - { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" }, + POPT_CTDB_CMDLINE { "dblist", 0, POPT_ARG_STRING, &db_list, 0, "list of databases", NULL }, POPT_TABLEEND }; @@ -86,45 +78,11 @@ int main(int argc, const char *argv[]) while (extra_argv[extra_argc]) extra_argc++; } - if (nlist == NULL || myaddress == NULL) { - printf("You must provide a node list with --nlist and an address with --listen\n"); - exit(1); - } - block_signal(SIGPIPE); ev = event_context_init(NULL); - /* initialise ctdb */ - ctdb = ctdb_init(ev); - if (ctdb == NULL) { - printf("Failed to init ctdb\n"); - exit(1); - } - - if (self_connect) { - ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT); - } - - ret = ctdb_set_transport(ctdb, transport); - if (ret == -1) { - printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } - - /* tell ctdb what address to listen on */ - ret = ctdb_set_address(ctdb, myaddress); - if (ret == -1) { - printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } - - /* tell ctdb what nodes are available */ - ret = ctdb_set_nlist(ctdb, nlist); - if (ret == -1) { - printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb)); - exit(1); - } + ctdb = ctdb_cmdline_init(ev); /* attach to the list of databases */ s = talloc_strdup(ctdb, db_list); diff --git a/ctdb/include/includes.h b/ctdb/include/includes.h index e55ddc2c6b8..5d3207820cb 100644 --- a/ctdb/include/includes.h +++ b/ctdb/include/includes.h @@ -12,7 +12,7 @@ typedef bool BOOL; #define True 1 #define False 0 -#define LogLevel 0 +extern int LogLevel; #define DEBUG(lvl, x) if ((lvl) <= LogLevel) (printf x) diff --git a/ctdb/tests/cmdline.c b/ctdb/tests/cmdline.c index 94d488a084a..4753d8286bc 100644 --- a/ctdb/tests/cmdline.c +++ b/ctdb/tests/cmdline.c @@ -44,6 +44,7 @@ struct poptOption popt_ctdb_cmdline[] = { { "listen", 0, POPT_ARG_STRING, &ctdb_cmdline.myaddress, 0, "address to listen on", "address" }, { "transport", 0, POPT_ARG_STRING, &ctdb_cmdline.transport, 0, "protocol transport", NULL }, { "self-connect", 0, POPT_ARG_NONE, &ctdb_cmdline.self_connect, 0, "enable self connect", "boolean" }, + { "debug", 'd', POPT_ARG_INT, &LogLevel, 0, "debug level"}, { NULL } };