summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie sahlberg <ronniesahlberg@gmail.com>2007-04-18 09:28:40 +1000
committerRonnie sahlberg <ronniesahlberg@gmail.com>2007-04-18 09:28:40 +1000
commit818abe7085a81b07d143d64b72d15bcb58148cfc (patch)
treeba4f47417cca14373d43347134151300a767f19a
parentefd5c4bf83fefcc608dd88be17b70ad4bf031db0 (diff)
parent98bb60e9d6fd68a5614f15517bd591e433956fe7 (diff)
downloadsamba-818abe7085a81b07d143d64b72d15bcb58148cfc.tar.gz
samba-818abe7085a81b07d143d64b72d15bcb58148cfc.tar.xz
samba-818abe7085a81b07d143d64b72d15bcb58148cfc.zip
merge from tridge
(This used to be ctdb commit d1262efebfc6e51e676720d42443017563aaffe3)
-rw-r--r--ctdb/Makefile.in28
-rw-r--r--ctdb/common/cmdline.c (renamed from ctdb/tests/cmdline.c)1
-rw-r--r--ctdb/common/ctdb.c17
-rw-r--r--ctdb/common/ctdb_call.c25
-rw-r--r--ctdb/common/ctdb_client.c50
-rw-r--r--ctdb/common/ctdb_daemon.c37
-rw-r--r--ctdb/common/ctdb_ltdb.c2
-rw-r--r--ctdb/common/ctdb_message.c5
-rw-r--r--ctdb/common/ctdb_util.c2
-rw-r--r--ctdb/direct/ctdbd.c48
-rw-r--r--ctdb/include/cmdline.h (renamed from ctdb/tests/cmdline.h)0
-rw-r--r--ctdb/include/includes.h2
-rw-r--r--ctdb/tcp/tcp_connect.c4
-rw-r--r--ctdb/tests/ctdb_bench.c2
-rw-r--r--ctdb/tests/ctdb_fetch.c2
-rw-r--r--ctdb/tests/ctdb_fetch1.c2
-rw-r--r--ctdb/tests/ctdb_messaging.c4
-rw-r--r--ctdb/tests/ctdb_test.c2
-rw-r--r--ctdb/tests/lockwait.c2
19 files changed, 132 insertions, 103 deletions
diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in
index 52659520d5..14e4487e6d 100644
--- a/ctdb/Makefile.in
+++ b/ctdb/Makefile.in
@@ -22,7 +22,7 @@ EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
CTDB_COMMON_OBJ = common/ctdb.o common/ctdb_daemon.o common/ctdb_client.o common/ctdb_io.o common/util.o common/ctdb_util.o \
common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_lockwait.o common/ctdb_message.o \
- lib/util/idtree.o lib/util/db_wrap.o
+ common/cmdline.o lib/util/idtree.o lib/util/db_wrap.o
CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
@@ -49,11 +49,11 @@ showflags:
dirs:
@mkdir -p $(DIRS)
-bin/ctdb_test: $(OBJS) tests/ctdb_test.o tests/cmdline.o
+bin/ctdb_test: $(OBJS) tests/ctdb_test.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o $(OBJS) $(LIB_FLAGS)
-bin/ctdbd: $(OBJS) direct/ctdbd.o
+bin/ctdbd: $(OBJS) direct/ctdbd.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ direct/ctdbd.o $(OBJS) $(LIB_FLAGS)
@@ -61,29 +61,29 @@ bin/ctdbd_test: $(OBJS) direct/ctdbd_test.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ direct/ctdbd_test.o
-bin/ctdb_bench: $(OBJS) tests/ctdb_bench.o tests/cmdline.o
+bin/ctdb_bench: $(OBJS) tests/ctdb_bench.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/ctdb_bench.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/ctdb_bench.o $(OBJS) $(LIB_FLAGS)
-bin/ctdb_fetch: $(OBJS) tests/ctdb_fetch.o tests/cmdline.o
+bin/ctdb_fetch: $(OBJS) tests/ctdb_fetch.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch.o $(OBJS) $(LIB_FLAGS)
-bin/ctdb_fetch1: $(OBJS) tests/ctdb_fetch1.o tests/cmdline.o
+bin/ctdb_fetch1: $(OBJS) tests/ctdb_fetch1.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch1.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/ctdb_fetch1.o $(OBJS) $(LIB_FLAGS)
-bin/ctdb_messaging: $(OBJS) tests/ctdb_messaging.o tests/cmdline.o
+bin/ctdb_messaging: $(OBJS) tests/ctdb_messaging.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/ctdb_messaging.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/ctdb_messaging.o $(OBJS) $(LIB_FLAGS)
bin/ibwrapper_test: $(OBJS) ib/ibwrapper_test.o
@echo Linking $@
@$(CC) $(CFLAGS) -o $@ ib/ibwrapper_test.o $(OBJS) $(LIB_FLAGS)
-bin/lockwait: $(OBJS) tests/lockwait.o tests/cmdline.o
+bin/lockwait: $(OBJS) tests/lockwait.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ tests/lockwait.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ tests/lockwait.o $(OBJS) $(LIB_FLAGS)
clean:
rm -f *.o */*.o */*/*.o
diff --git a/ctdb/tests/cmdline.c b/ctdb/common/cmdline.c
index 94d488a084..4753d8286b 100644
--- a/ctdb/tests/cmdline.c
+++ b/ctdb/common/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 }
};
diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c
index 0ccbecd905..a69cbdbee7 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));
}
/*
@@ -281,8 +285,11 @@ void ctdb_daemon_connect_wait(struct ctdb_context *ctdb)
expected++;
}
while (ctdb->num_connected != expected) {
+ DEBUG(3,("ctdb_connect_wait: waiting for %d nodes (have %d)\n",
+ expected, ctdb->num_connected));
event_loop_once(ctdb->ev);
}
+ DEBUG(3,("ctdb_connect_wait: got all %d nodes\n", expected));
}
/*
diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c
index 3c682d6bd6..65a1a5659c 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;
}
@@ -424,6 +424,11 @@ void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
state = idr_find(ctdb->idr, hdr->reqid);
if (state == NULL) return;
+ if (!talloc_get_type(state, struct ctdb_call_state)) {
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
+ return;
+ }
+
state->call.reply_data.dptr = c->data;
state->call.reply_data.dsize = c->datalen;
state->call.status = c->status;
@@ -458,6 +463,12 @@ void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
if (state == NULL) {
return;
}
+
+ if (!talloc_get_type(state, struct ctdb_call_state)) {
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
+ return;
+ }
+
ctdb_db = state->ctdb_db;
data.dptr = c->data;
@@ -495,6 +506,11 @@ void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
state = idr_find(ctdb->idr, hdr->reqid);
if (state == NULL) return;
+ if (!talloc_get_type(state, struct ctdb_call_state)) {
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
+ return;
+ }
+
talloc_steal(state, c);
state->state = CTDB_CALL_ERROR;
@@ -520,6 +536,11 @@ void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
state = idr_find(ctdb->idr, hdr->reqid);
if (state == NULL) return;
+ if (!talloc_get_type(state, struct ctdb_call_state)) {
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
+ return;
+ }
+
talloc_steal(state, c);
/* don't allow for too many redirects */
diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c
index 7ce36e7133..1b5c80c6f4 100644
--- a/ctdb/common/ctdb_client.c
+++ b/ctdb/common/ctdb_client.c
@@ -57,6 +57,7 @@ struct ctdb_fetch_lock_state {
enum fetch_lock_state state;
struct ctdb_db_context *ctdb_db;
struct ctdb_reply_fetch_lock *r;
+ struct ctdb_req_fetch_lock *req;
struct ctdb_ltdb_header header;
};
@@ -76,6 +77,11 @@ void ctdb_reply_fetch_lock(struct ctdb_context *ctdb, struct ctdb_req_header *hd
state = idr_find(ctdb->idr, hdr->reqid);
if (state == NULL) return;
+ if (!talloc_get_type(state, struct ctdb_fetch_lock_state)) {
+ DEBUG(0, ("ctdb idr type error at %s\n", __location__));
+ return;
+ }
+
state->r = talloc_steal(state, r);
/* get an extra reference here - this prevents the free in ctdb_recv_pkt()
@@ -133,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));
}
}
@@ -260,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;
}
@@ -269,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");
@@ -408,18 +414,28 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
r.hdr.ctdb_magic = CTDB_MAGIC;
r.hdr.ctdb_version = CTDB_VERSION;
r.hdr.operation = CTDB_REQ_CONNECT_WAIT;
+
+ DEBUG(3,("ctdb_connect_wait: sending to ctdbd\n"));
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;
}
+ DEBUG(3,("ctdb_connect_wait: waiting\n"));
+
/* now we can go into the normal wait routine, as the reply packet
will update the ctdb->num_connected variable */
ctdb_daemon_connect_wait(ctdb);
}
+static int ctdb_fetch_lock_destructor(struct ctdb_fetch_lock_state *state)
+{
+ idr_remove(state->ctdb_db->ctdb->idr, state->req->hdr.reqid);
+ return 0;
+}
+
static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_context *ctdb_db,
TALLOC_CTX *mem_ctx,
TDB_DATA key,
@@ -437,15 +453,15 @@ 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;
state->ctdb_db = ctdb_db;
len = offsetof(struct ctdb_req_fetch_lock, key) + key.dsize;
- req = ctdbd_allocate_pkt(ctdb, len);
+ 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);
@@ -461,6 +477,8 @@ static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_
req->keylen = key.dsize;
req->header = *header;
memcpy(&req->key[0], key.dptr, key.dsize);
+
+ talloc_set_destructor(state, ctdb_fetch_lock_destructor);
res = ctdb_client_queue_pkt(ctdb, &req->hdr);
if (res != 0) {
@@ -542,14 +560,19 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
}
h->data = data;
+ DEBUG(3,("ctdb_fetch_lock: key=%*.*s\n", key.dsize, key.dsize,
+ (const char *)key.dptr));
+
/* 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;
}
+ DEBUG(4,("ctdb_fetch_lock: got chain lock\n"));
+
talloc_set_destructor(h, fetch_lock_destructor);
ret = ctdb_ltdb_fetch(ctdb_db, key, &h->header, ctdb_db, data);
@@ -558,29 +581,38 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
return NULL;
}
+ DEBUG(4,("ctdb_fetch_lock: done local fetch\n"));
+
/* step 2 - check if we are the dmaster */
if (h->header.dmaster == ctdb_db->ctdb->vnn) {
+ DEBUG(4,("ctdb_fetch_lock: we are dmaster - done\n"));
return h;
}
/* we're not the dmaster - ask the ctdb daemon to make us dmaster */
state = ctdb_client_fetch_lock_send(ctdb_db, mem_ctx, key, &h->header);
+ DEBUG(4,("ctdb_fetch_lock: done fetch_lock_send\n"));
ret = ctdb_client_fetch_lock_recv(state, mem_ctx, key, &h->header, data);
if (ret != 0) {
+ DEBUG(4,("ctdb_fetch_lock: fetch_lock_recv failed\n"));
talloc_free(h);
return NULL;
}
+ DEBUG(4,("ctdb_fetch_lock: record is now local\n"));
+
/* the record is now local, and locked. update the record on disk
to mark us as the dmaster*/
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;
}
+ DEBUG(4,("ctdb_fetch_lock: done\n"));
+
/* give the caller a handle to be used for ctdb_record_store() or a cancel via
a talloc_free() */
return h;
diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c
index 320a9e9b19..94aba21ffb 100644
--- a/ctdb/common/ctdb_daemon.c
+++ b/ctdb/common/ctdb_daemon.c
@@ -36,7 +36,7 @@ static void ctdb_main_loop(struct ctdb_context *ctdb)
/* go into a wait loop to allow other nodes to complete */
event_loop_wait(ctdb->ev);
- printf("event_loop_wait() returned. this should not happen\n");
+ DEBUG(0,("event_loop_wait() returned. this should not happen\n"));
exit(1);
}
@@ -118,7 +118,8 @@ static void daemon_request_register_message_handler(struct ctdb_client *client,
c->srvid, daemon_message_handler,
client);
if (res != 0) {
- printf("Failed to register handler %u in daemon\n", c->srvid);
+ DEBUG(0,(__location__ " Failed to register handler %u in daemon\n",
+ c->srvid));
}
}
@@ -168,7 +169,7 @@ static void daemon_fetch_lock_complete(struct ctdb_call_state *state)
length = offsetof(struct ctdb_reply_fetch_lock, data) + state->call.reply_data.dsize;
r = ctdbd_allocate_pkt(client->ctdb, length);
if (r == NULL) {
- printf("Failed to allocate reply_call in ctdb daemon\n");
+ DEBUG(0,(__location__ " Failed to allocate reply_call in ctdb daemon\n"));
return;
}
memset(r, 0, offsetof(struct ctdb_reply_fetch_lock, data));
@@ -183,7 +184,7 @@ static void daemon_fetch_lock_complete(struct ctdb_call_state *state)
res = ctdb_queue_send(client->queue, (uint8_t *)&r->hdr, r->hdr.length);
if (res != 0) {
- printf("Failed to queue packet from daemon to client\n");
+ DEBUG(0,(__location__ " Failed to queue packet from daemon to client\n"));
}
talloc_free(r);
}
@@ -260,7 +261,7 @@ static void daemon_request_connect_wait(struct ctdb_client *client,
res = ctdb_queue_send(client->queue, (uint8_t *)&r.hdr, r.hdr.length);
if (res != 0) {
- printf("Failed to queue a connect wait response\n");
+ DEBUG(0,(__location__ " Failed to queue a connect wait response\n"));
return;
}
}
@@ -298,8 +299,8 @@ static void daemon_request_message_from_client(struct ctdb_client *client,
res = ctdb_daemon_send_message(client->ctdb, c->hdr.destnode,
c->srvid, data);
if (res != 0) {
- printf("Failed to send message to remote node %u\n",
- c->hdr.destnode);
+ DEBUG(0,(__location__ " Failed to send message to remote node %u\n",
+ c->hdr.destnode));
}
}
@@ -319,7 +320,8 @@ static void daemon_request_call_from_client(struct ctdb_client *client,
ctdb_db = find_ctdb_db(client->ctdb, c->db_id);
if (!ctdb_db) {
- printf("Unknown database in request. db_id==0x%08x",c->db_id);
+ DEBUG(0, (__location__ " Unknown database in request. db_id==0x%08x",
+ c->db_id));
return;
}
@@ -337,14 +339,14 @@ static void daemon_request_call_from_client(struct ctdb_client *client,
/* XXX this must be converted to fully async */
res = ctdb_daemon_call_recv(state, &call);
if (res != 0) {
- printf("ctdbd_call_recv() returned error\n");
+ DEBUG(0, (__location__ " ctdbd_call_recv() returned error\n"));
exit(1);
}
length = offsetof(struct ctdb_reply_call, data) + call.reply_data.dsize;
r = ctdbd_allocate_pkt(client->ctdb, length);
if (r == NULL) {
- printf("Failed to allocate reply_call in ctdb daemon\n");
+ DEBUG(0, (__location__ " Failed to allocate reply_call in ctdb daemon\n"));
return;
}
memset(r, 0, offsetof(struct ctdb_reply_call, data));
@@ -358,7 +360,7 @@ static void daemon_request_call_from_client(struct ctdb_client *client,
res = ctdb_queue_send(client->queue, (uint8_t *)&r->hdr, r->hdr.length);
if (res != 0) {
- printf("Failed to queue packet from daemon to client\n");
+ DEBUG(0, (__location__ "Failed to queue packet from daemon to client\n"));
}
talloc_free(r);
}
@@ -399,7 +401,8 @@ static void daemon_incoming_packet(struct ctdb_client *client, void *data, size_
daemon_request_fetch_lock(client, (struct ctdb_req_fetch_lock *)hdr);
break;
default:
- printf("daemon: unrecognized operation:%d\n",hdr->operation);
+ DEBUG(0,(__location__ " daemon: unrecognized operation %d\n",
+ hdr->operation));
}
done:
@@ -481,10 +484,10 @@ static void ctdb_read_from_parent(struct event_context *ev, struct fd_event *fde
/* XXX this is a good place to try doing some cleaning up before exiting */
cnt = read(*fd, &buf, 1);
if (cnt==0) {
- printf("parent process exited. filedescriptor dissappeared\n");
+ DEBUG(0,(__location__ " parent process exited. filedescriptor dissappeared\n"));
exit(1);
} else {
- printf("ctdb: did not expect data from parent process\n");
+ DEBUG(0,(__location__ " ctdb: did not expect data from parent process\n"));
exit(1);
}
}
@@ -549,18 +552,18 @@ int ctdb_start(struct ctdb_context *ctdb)
/* create a unix domain stream socket to listen to */
res = ux_socket_bind(ctdb);
if (res!=0) {
- printf("Failed to open CTDB unix domain socket\n");
+ DEBUG(0,(__location__ " Failed to open CTDB unix domain socket\n"));
exit(10);
}
res = pipe(&fd[0]);
if (res) {
- printf("Failed to open pipe for CTDB\n");
+ DEBUG(0,(__location__ " Failed to open pipe for CTDB\n"));
exit(1);
}
pid = fork();
if (pid==-1) {
- printf("Failed to fork CTDB daemon\n");
+ DEBUG(0,(__location__ " Failed to fork CTDB daemon\n"));
exit(1);
}
diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c
index a1e45efb02..724271da3b 100644
--- a/ctdb/common/ctdb_ltdb.c
+++ b/ctdb/common/ctdb_ltdb.c
@@ -227,7 +227,7 @@ static void lock_fetch_callback(void *p)
struct ctdb_req_header *hdr = p;
struct ctdb_context *ctdb = talloc_find_parent_bytype(p, struct ctdb_context);
ctdb_recv_pkt(ctdb, (uint8_t *)hdr, hdr->length);
- printf("PACKET REQUEUED\n");
+ DEBUG(0,(__location__ " PACKET REQUEUED\n"));
}
/*
diff --git a/ctdb/common/ctdb_message.c b/ctdb/common/ctdb_message.c
index 88fe04df50..9de12f6bcb 100644
--- a/ctdb/common/ctdb_message.c
+++ b/ctdb/common/ctdb_message.c
@@ -42,7 +42,8 @@ static int ctdb_dispatch_message(struct ctdb_context *ctdb, uint32_t srvid, TDB_
if (ml->srvid == srvid || ml->srvid == CTDB_SRVID_ALL) break;
}
if (ml == NULL) {
- printf("daemon vnn:%d no msg handler for srvid=%u\n", ctdb_get_vnn(ctdb), srvid);
+ DEBUG(0,(__location__ " daemon vnn:%d no msg handler for srvid=%u\n",
+ ctdb_get_vnn(ctdb), srvid));
/* no registered message handler */
return -1;
}
@@ -86,7 +87,7 @@ static void ctdb_local_message_trigger(struct event_context *ev, struct timed_ev
res = ctdb_dispatch_message(m->ctdb, m->srvid, m->data);
if (res != 0) {
- printf("Failed to dispatch message for srvid=%u\n", m->srvid);
+ DEBUG(0, (__location__ " Failed to dispatch message for srvid=%u\n", m->srvid));
}
talloc_free(m);
}
diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c
index cf0c72a58b..e824e098e5 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 9e13c4c825..674b54d47a 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 "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/tests/cmdline.h b/ctdb/include/cmdline.h
index 785595ee6c..785595ee6c 100644
--- a/ctdb/tests/cmdline.h
+++ b/ctdb/include/cmdline.h
diff --git a/ctdb/include/includes.h b/ctdb/include/includes.h
index e55ddc2c6b..5d3207820c 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/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c
index a1f2d331cf..4d9d8e8386 100644
--- a/ctdb/tcp/tcp_connect.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -43,6 +43,10 @@ void ctdb_tcp_tnode_cb(uint8_t *data, size_t cnt, void *private_data)
struct ctdb_tcp_node *tnode = talloc_get_type(
node->private_data, struct ctdb_tcp_node);
+ if (data == NULL) {
+ node->ctdb->upcalls->node_dead(node);
+ }
+
/* start a new connect cycle to try to re-establish the
link */
close(tnode->fd);
diff --git a/ctdb/tests/ctdb_bench.c b/ctdb/tests/ctdb_bench.c
index 37c095c0c0..8df084b4dc 100644
--- a/ctdb/tests/ctdb_bench.c
+++ b/ctdb/tests/ctdb_bench.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
#include <sys/time.h>
#include <time.h>
diff --git a/ctdb/tests/ctdb_fetch.c b/ctdb/tests/ctdb_fetch.c
index 1ae8e8aafd..91fff3825d 100644
--- a/ctdb/tests/ctdb_fetch.c
+++ b/ctdb/tests/ctdb_fetch.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
#include <sys/time.h>
#include <time.h>
diff --git a/ctdb/tests/ctdb_fetch1.c b/ctdb/tests/ctdb_fetch1.c
index 635311c998..b362eb1510 100644
--- a/ctdb/tests/ctdb_fetch1.c
+++ b/ctdb/tests/ctdb_fetch1.c
@@ -24,7 +24,7 @@
#include "popt.h"
#include "ctdb.h"
#include "ctdb_private.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
#define PARENT_SRVID 0
#define CHILD1_SRVID 1
diff --git a/ctdb/tests/ctdb_messaging.c b/ctdb/tests/ctdb_messaging.c
index d02c2116e8..137acd6163 100644
--- a/ctdb/tests/ctdb_messaging.c
+++ b/ctdb/tests/ctdb_messaging.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
static int timelimit = 10;
static int num_records = 10;
@@ -130,7 +130,7 @@ int main(int argc, const char *argv[])
for (j=0;j<num_clients;j++) {
printf("sending message to %d:%d\n", i, j);
sprintf(buf,"Message from %d to vnn:%d srvid:%d",ctdb_get_vnn(ctdb),i,j);
- data.dptr=buf;
+ data.dptr = (unsigned char *)buf;
data.dsize=strlen(buf)+1;
ctdb_send_message(ctdb, i, j, data);
}
diff --git a/ctdb/tests/ctdb_test.c b/ctdb/tests/ctdb_test.c
index 8125cc4490..dea9066eb2 100644
--- a/ctdb/tests/ctdb_test.c
+++ b/ctdb/tests/ctdb_test.c
@@ -22,7 +22,7 @@
#include "lib/events/events.h"
#include "system/filesys.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
enum my_functions {FUNC_SORT=1, FUNC_FETCH=2};
diff --git a/ctdb/tests/lockwait.c b/ctdb/tests/lockwait.c
index b1c699fe2c..51f88c1168 100644
--- a/ctdb/tests/lockwait.c
+++ b/ctdb/tests/lockwait.c
@@ -23,7 +23,7 @@
#include "system/filesys.h"
#include "system/wait.h"
#include "popt.h"
-#include "tests/cmdline.h"
+#include "cmdline.h"
struct lockwait_handle {