From 3057f683f3fe1c3490d68db2a8fc936b4652ba91 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Apr 2007 17:59:39 +0200 Subject: [PATCH 1/5] Add timestamps to debug output. (This used to be ctdb commit 197a02384bd2ca42dfff4c0357175424d2321e9c) --- ctdb/Makefile.in | 2 +- ctdb/common/ctdb.c | 5 +++-- ctdb/include/includes.h | 3 ++- ctdb/lib/util/debug.c | 40 ++++++++++++++++++++++++++++++++++++++++ ctdb/lib/util/debug.h | 21 +++++++++++++++++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 ctdb/lib/util/debug.c create mode 100644 ctdb/lib/util/debug.h diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index 14e4487e6d3..7729875f4e3 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 \ - common/cmdline.o lib/util/idtree.o lib/util/db_wrap.o + common/cmdline.o lib/util/idtree.o lib/util/db_wrap.o lib/util/debug.o CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index a69cbdbee72..57ebd131da1 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -215,8 +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)); + DEBUG(3,(__location__ " ctdb request %d of type %d length %d from " + "node %d to %d\n", hdr->reqid, hdr->operation, hdr->length, + hdr->srcnode, hdr->destnode)); switch (hdr->operation) { case CTDB_REQ_CALL: diff --git a/ctdb/include/includes.h b/ctdb/include/includes.h index 5d3207820cb..bffc66b358b 100644 --- a/ctdb/include/includes.h +++ b/ctdb/include/includes.h @@ -6,6 +6,7 @@ #include "idtree.h" #include "ctdb.h" #include "lib/util/dlinklist.h" +#include "lib/util/debug.h" typedef bool BOOL; @@ -14,7 +15,7 @@ typedef bool BOOL; extern int LogLevel; -#define DEBUG(lvl, x) if ((lvl) <= LogLevel) (printf x) +#define DEBUG(lvl, x) if ((lvl) <= LogLevel) (do_debug x) #define _PUBLIC_ diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c new file mode 100644 index 00000000000..a3229015ca8 --- /dev/null +++ b/ctdb/lib/util/debug.c @@ -0,0 +1,40 @@ +/* + Unix SMB/CIFS implementation. + ctdb debug functions + Copyright (C) Volker Lendecke 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "system/time.h" +#include + +void do_debug(const char *format, ...) +{ + struct timeval tm; + va_list ap; + char *s = NULL; + + va_start(ap, format); + vasprintf(&s, format, ap); + va_end(ap); + + gettimeofday(&tm, NULL); + printf("%-8.8d.%-6.6d [%d]: %s", (int)tm.tv_sec, (int)tm.tv_usec, + (int)getpid(), s); + fflush(stdout); + free(s); +} diff --git a/ctdb/lib/util/debug.h b/ctdb/lib/util/debug.h new file mode 100644 index 00000000000..bc1e8f94237 --- /dev/null +++ b/ctdb/lib/util/debug.h @@ -0,0 +1,21 @@ +/* + Unix SMB/CIFS implementation. + ctdb debug functions + Copyright (C) Volker Lendecke 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +void do_debug(const char *format, ...); From 6c597d3e8352bdbcf78772160bbe186f601db513 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Apr 2007 21:23:22 +0200 Subject: [PATCH 2/5] typo (This used to be ctdb commit bf2799504498ae452bb7244ae3eb6a51797afe9b) --- ctdb/common/ctdb_call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c index 65a1a5659c9..f89115b479f 100644 --- a/ctdb/common/ctdb_call.c +++ b/ctdb/common/ctdb_call.c @@ -414,7 +414,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) called when a CTDB_REPLY_CALL packet comes in This packet comes in response to a CTDB_REQ_CALL request packet. It - contains any reply data freom the call + contains any reply data from the call */ void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) { From 84d276a5bec83ee0a0a95622a396048c73f0efa8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Apr 2007 23:03:30 +0200 Subject: [PATCH 3/5] Some more debug and two memleak fixes (This used to be ctdb commit 1e2802422794956827263265306952df5e69b377) --- ctdb/common/ctdb_call.c | 10 ++++++++-- ctdb/common/ctdb_client.c | 11 ++++++++--- ctdb/lib/talloc/talloc.c | 2 +- ctdb/tests/ctdb_fetch.c | 4 ++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c index f89115b479f..4363b189cc4 100644 --- a/ctdb/common/ctdb_call.c +++ b/ctdb/common/ctdb_call.c @@ -422,7 +422,10 @@ void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) struct ctdb_call_state *state; state = idr_find(ctdb->idr, hdr->reqid); - if (state == NULL) return; + if (state == NULL) { + DEBUG(0, ("reqid %d not found\n", hdr->reqid)); + return; + } if (!talloc_get_type(state, struct ctdb_call_state)) { DEBUG(0,("ctdb idr type error at %s\n", __location__)); @@ -707,7 +710,10 @@ struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db, if (ret != 0) return NULL; if (header.dmaster == ctdb->vnn && !(ctdb->flags & CTDB_FLAG_SELF_CONNECT)) { - return ctdb_call_local_send(ctdb_db, call, &header, &data); + struct ctdb_call_state *result; + result = ctdb_call_local_send(ctdb_db, call, &header, &data); + talloc_free(data.dptr); + return result; } talloc_free(data.dptr); diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index 1b5c80c6f47..d14647ba905 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -75,10 +75,15 @@ void ctdb_reply_fetch_lock(struct ctdb_context *ctdb, struct ctdb_req_header *hd struct ctdb_fetch_lock_state *state; state = idr_find(ctdb->idr, hdr->reqid); - if (state == NULL) return; + if (state == NULL) { + DEBUG(0, ("reqid %d not found at %s\n", hdr->reqid, + __location__)); + return; + } if (!talloc_get_type(state, struct ctdb_fetch_lock_state)) { - DEBUG(0, ("ctdb idr type error at %s\n", __location__)); + DEBUG(0, ("ctdb idr type error at %s, it's a %s\n", + __location__, talloc_get_name(state))); return; } @@ -575,7 +580,7 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL talloc_set_destructor(h, fetch_lock_destructor); - ret = ctdb_ltdb_fetch(ctdb_db, key, &h->header, ctdb_db, data); + ret = ctdb_ltdb_fetch(ctdb_db, key, &h->header, h, data); if (ret != 0) { talloc_free(h); return NULL; diff --git a/ctdb/lib/talloc/talloc.c b/ctdb/lib/talloc/talloc.c index 15a44bd0d99..c8161fd63d2 100644 --- a/ctdb/lib/talloc/talloc.c +++ b/ctdb/lib/talloc/talloc.c @@ -1028,7 +1028,7 @@ static void talloc_report_null(void) /* report on any memory hanging off the null context */ -static void talloc_report_null_full(void) +void talloc_report_null_full(void) { if (talloc_total_size(null_context) != 0) { talloc_report_full(null_context, stderr); diff --git a/ctdb/tests/ctdb_fetch.c b/ctdb/tests/ctdb_fetch.c index 91fff3825df..99fbe1fc5e2 100644 --- a/ctdb/tests/ctdb_fetch.c +++ b/ctdb/tests/ctdb_fetch.c @@ -142,6 +142,8 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev) printf("Event loop failed!\n"); break; } + + talloc_report_null_full(); } printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer()); @@ -193,6 +195,8 @@ int main(int argc, const char *argv[]) } } + talloc_enable_leak_report_full(); + /* setup the remaining options for the main program to use */ extra_argv = poptGetArgs(pc); if (extra_argv) { From ed32ad028c8f947d111e5807829650b030f31de9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Apr 2007 23:06:10 +0200 Subject: [PATCH 4/5] Be less verbose (This used to be ctdb commit 7497b5a9031c471c25bf6029c436fd82788b415c) --- ctdb/tests/ctdb_fetch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ctdb/tests/ctdb_fetch.c b/ctdb/tests/ctdb_fetch.c index 99fbe1fc5e2..c5356edab32 100644 --- a/ctdb/tests/ctdb_fetch.c +++ b/ctdb/tests/ctdb_fetch.c @@ -143,7 +143,9 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev) break; } - talloc_report_null_full(); + if (LogLevel > 9) { + talloc_report_null_full(); + } } printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer()); From 27837c197aaf221019d3d0d25896653b5f87659f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Apr 2007 23:40:33 +0200 Subject: [PATCH 5/5] Clean up the call_states correctly (This used to be ctdb commit 9fcc40a2ddd8f7f62bdd8b5ab71d182220e23af0) --- ctdb/common/ctdb_call.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c index 4363b189cc4..aa88829fa1c 100644 --- a/ctdb/common/ctdb_call.c +++ b/ctdb/common/ctdb_call.c @@ -436,7 +436,7 @@ void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) state->call.reply_data.dsize = c->datalen; state->call.status = c->status; - talloc_steal(state, c); + talloc_steal(c, state); /* get an extra reference here - this prevents the free in ctdb_recv_pkt() from freeing the data */ @@ -477,7 +477,7 @@ void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) data.dptr = c->data; data.dsize = c->datalen; - talloc_steal(state, c); + talloc_steal(c, state); /* we're now the dmaster - update our local ltdb with new header and data */ @@ -514,7 +514,7 @@ void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) return; } - talloc_steal(state, c); + talloc_steal(c, state); state->state = CTDB_CALL_ERROR; state->errmsg = (char *)c->msg; @@ -544,7 +544,7 @@ void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) return; } - talloc_steal(state, c); + talloc_steal(c, state); /* don't allow for too many redirects */ if (state->redirect_count++ == CTDB_MAX_REDIRECT) {