From adc64aed0a34bb952421b458c992d9446bee9a9b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 May 2007 08:33:35 +1000 Subject: [PATCH] - fixed a crash bug after client disconnect in ctdb_control - added total memory used to ctdb_control status output (This used to be ctdb commit a99ffe4372edc63d83d8c8ebf9a60b3413301f5a) --- ctdb/common/ctdb_control.c | 10 ++++++++-- ctdb/include/ctdb_private.h | 1 + ctdb/tools/ctdb_control.c | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index 837f8ccc88e..41bab7e87ff 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -158,6 +158,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, case CTDB_CONTROL_STATUS: { CHECK_CONTROL_DATA_SIZE(0); ctdb->status.controls.status++; + ctdb->status.memory_used = talloc_total_size(ctdb); outdata->dptr = (uint8_t *)&ctdb->status; outdata->dsize = sizeof(ctdb->status); return 0; @@ -499,8 +500,11 @@ void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) data.dptr = &c->data[0]; data.dsize = c->datalen; + /* make state a child of the packet, so it goes away when the packet + is freed. */ + talloc_steal(hdr, state); + state->callback(ctdb, c->status, data, state->private_data); - talloc_free(state); } static int ctdb_control_destructor(struct ctdb_control_state *state) @@ -528,7 +532,9 @@ int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode, return -1; } - state = talloc(ctdb, struct ctdb_control_state); + /* the state is made a child of private_data if possible. This means any reply + will be discarded if the private_data goes away */ + state = talloc(private_data?private_data:ctdb, struct ctdb_control_state); CTDB_NO_MEMORY(ctdb, state); state->reqid = ctdb_reqid_new(ctdb, state); diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 5bdca6a3ac9..b11f5072219 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -175,6 +175,7 @@ struct ctdb_status { uint32_t lockwait_calls; uint32_t traverse_calls; uint32_t pending_lockwait_calls; + uint32_t memory_used; uint32_t __last_counter; /* hack for control_status_all */ uint32_t max_hop_count; double max_call_latency; diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index 2e2c8efa3c7..8f4ed3f70df 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -135,6 +135,7 @@ static void show_status(struct ctdb_status *s) STATUS_FIELD(lockwait_calls), STATUS_FIELD(traverse_calls), STATUS_FIELD(pending_lockwait_calls), + STATUS_FIELD(memory_used), STATUS_FIELD(max_hop_count), }; printf("CTDB version %u\n", CTDB_VERSION);