diff options
author | Andrew Tridgell <tridge@samba.org> | 2007-04-26 14:51:41 +0200 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2007-04-26 14:51:41 +0200 |
commit | 8ae14b4052bc565bee5ff8556121f613155dddd3 (patch) | |
tree | f6e1f459eb5ec63d4426495c9cbf1993422af230 /ctdb | |
parent | d955485e7be3d68554969272bfe110ebe996c360 (diff) | |
download | samba-8ae14b4052bc565bee5ff8556121f613155dddd3.tar.gz samba-8ae14b4052bc565bee5ff8556121f613155dddd3.tar.xz samba-8ae14b4052bc565bee5ff8556121f613155dddd3.zip |
moved status to ctdb_control
(This used to be ctdb commit 9a543968ba0379fbf8e977e184f22f4349d6243f)
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/Makefile.in | 6 | ||||
-rw-r--r-- | ctdb/common/ctdb_client.c | 110 | ||||
-rw-r--r-- | ctdb/common/ctdb_control.c | 9 | ||||
-rw-r--r-- | ctdb/common/ctdb_daemon.c | 38 | ||||
-rw-r--r-- | ctdb/include/ctdb.h | 2 | ||||
-rw-r--r-- | ctdb/include/ctdb_private.h | 18 | ||||
-rw-r--r-- | ctdb/tools/ctdb_control.c | 77 | ||||
-rw-r--r-- | ctdb/tools/ctdb_status.c | 135 |
8 files changed, 120 insertions, 275 deletions
diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index a74a52abaf..773d612a21 100644 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -32,7 +32,7 @@ CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TCP_OBJ) OBJS = @TDBOBJ@ @TALLOCOBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) $(EVENTS_OBJ) $(CTDB_OBJ) -BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait bin/ctdb_status bin/ctdb_control bin/ctdb_dump @INFINIBAND_BINS@ +BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait bin/ctdb_control bin/ctdb_dump @INFINIBAND_BINS@ DIRS = lib bin @@ -59,10 +59,6 @@ bin/ctdbd: $(OBJS) direct/ctdbd.o @echo Linking $@ @$(CC) $(CFLAGS) -o $@ direct/ctdbd.o $(OBJS) $(LIB_FLAGS) -bin/ctdb_status: $(OBJS) tools/ctdb_status.o - @echo Linking $@ - @$(CC) $(CFLAGS) -o $@ tools/ctdb_status.o $(OBJS) $(LIB_FLAGS) - bin/ctdb_control: $(OBJS) tools/ctdb_control.o @echo Linking $@ @$(CC) $(CFLAGS) -o $@ tools/ctdb_control.o $(OBJS) $(LIB_FLAGS) diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index e0f438c162..f0589e70a4 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -91,7 +91,6 @@ static void ctdb_client_reply_call(struct ctdb_context *ctdb, struct ctdb_req_he state->state = CTDB_CALL_DONE; } -static void ctdb_reply_status(struct ctdb_context *ctdb, struct ctdb_req_header *hdr); static void ctdb_reply_getdbpath(struct ctdb_context *ctdb, struct ctdb_req_header *hdr); static void ctdb_client_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr); @@ -149,10 +148,6 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args) ctdb_reply_connect_wait(ctdb, hdr); break; - case CTDB_REPLY_STATUS: - ctdb_reply_status(ctdb, hdr); - break; - case CTDB_REPLY_GETDBPATH: ctdb_reply_getdbpath(ctdb, hdr); break; @@ -627,78 +622,6 @@ void ctdb_shutdown(struct ctdb_context *ctdb) } } -enum ctdb_status_states {CTDB_STATUS_WAIT, CTDB_STATUS_DONE}; - -struct ctdb_status_state { - uint32_t reqid; - struct ctdb_status *status; - enum ctdb_status_states state; -}; - -/* - handle a ctdb_reply_status reply - */ -static void ctdb_reply_status(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) -{ - struct ctdb_reply_status *r = (struct ctdb_reply_status *)hdr; - struct ctdb_status_state *state; - - state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_status_state); - if (state == NULL) { - DEBUG(0,(__location__ " reqid %d not found\n", hdr->reqid)); - return; - } - - if (hdr->reqid != state->reqid) { - /* we found a record but it was the wrong one */ - DEBUG(0, ("Dropped orphaned reply with reqid:%d\n",hdr->reqid)); - return; - } - - *state->status = r->status; - state->state = CTDB_STATUS_DONE; -} - -int ctdb_status(struct ctdb_context *ctdb, struct ctdb_status *status) -{ - struct ctdb_req_status r; - int ret; - struct ctdb_status_state *state; - - /* if the domain socket is not yet open, open it */ - if (ctdb->daemon.sd==-1) { - ctdb_socket_connect(ctdb); - } - - state = talloc(ctdb, struct ctdb_status_state); - CTDB_NO_MEMORY(ctdb, state); - - state->reqid = ctdb_reqid_new(ctdb, state); - state->status = status; - state->state = CTDB_STATUS_WAIT; - - ZERO_STRUCT(r); - r.hdr.length = sizeof(r); - r.hdr.ctdb_magic = CTDB_MAGIC; - r.hdr.ctdb_version = CTDB_VERSION; - r.hdr.operation = CTDB_REQ_STATUS; - r.hdr.reqid = state->reqid; - - ret = ctdb_client_queue_pkt(ctdb, &(r.hdr)); - if (ret != 0) { - talloc_free(state); - return -1; - } - - while (state->state == CTDB_STATUS_WAIT) { - event_loop_once(ctdb->ev); - } - - talloc_free(state); - - return 0; -} - enum ctdb_getdbpath_states {CTDB_GETDBPATH_WAIT, CTDB_GETDBPATH_DONE}; @@ -873,7 +796,7 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint32_t srvid, if (outdata) { *outdata = state->outdata; - outdata->dptr = talloc_steal(mem_ctx, outdata->dptr); + outdata->dptr = talloc_memdup(mem_ctx, outdata->dptr, outdata->dsize); } *status = state->status; @@ -901,9 +824,38 @@ int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid) CTDB_CONTROL_PROCESS_EXISTS, data, NULL, NULL, &status); if (ret != 0) { - DEBUG(0,(__location__ " ctdb_control failed\n")); + DEBUG(0,(__location__ " ctdb_control for process_exists failed\n")); return -1; } return status; } + +/* + get remote status + */ +int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status) +{ + int ret; + TDB_DATA data, outdata; + int32_t res; + + ZERO_STRUCT(data); + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_STATUS, data, + ctdb, &outdata, &res); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for status failed\n")); + return -1; + } + + if (outdata.dsize != sizeof(struct ctdb_status)) { + DEBUG(0,(__location__ " Wrong status size %u - expected %u\n", + outdata.dsize, sizeof(struct ctdb_status))); + return -1; + } + + *status = *(struct ctdb_status *)outdata.dptr; + + return 0; +} diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index c7af9c7641..2f961e6782 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -50,6 +50,11 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, pid = *(pid_t *)indata.dptr; return kill(pid, 0); } + case CTDB_CONTROL_STATUS: { + outdata->dptr = (uint8_t *)&ctdb->status; + outdata->dsize = sizeof(ctdb->status); + return 0; + } default: DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode)); return -1; @@ -86,7 +91,7 @@ void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr r->hdr.srcnode = ctdb->vnn; r->hdr.reqid = hdr->reqid; r->status = status; - c->datalen = outdata.dsize; + r->datalen = outdata.dsize; if (outdata.dsize) { memcpy(&r->data[0], outdata.dptr, outdata.dsize); } @@ -119,6 +124,8 @@ void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr) data.dptr = &c->data[0]; data.dsize = c->datalen; + DEBUG(0,("data.dsize=%u\n", data.dsize)); + state->callback(ctdb, c->status, data, state->private_data); talloc_free(state); } diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index 69d1195d67..efb3f5431e 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -223,32 +223,6 @@ static void daemon_request_connect_wait(struct ctdb_client *client, /* - called when the daemon gets a status request from a client - */ -static void daemon_request_status(struct ctdb_client *client, - struct ctdb_req_status *c) -{ - struct ctdb_reply_status r; - int res; - - /* now send the reply */ - ZERO_STRUCT(r); - - r.hdr.length = sizeof(r); - r.hdr.ctdb_magic = CTDB_MAGIC; - r.hdr.ctdb_version = CTDB_VERSION; - r.hdr.operation = CTDB_REPLY_STATUS; - r.hdr.reqid = c->hdr.reqid; - r.status = client->ctdb->status; - - res = daemon_queue_send(client, &r.hdr); - if (res != 0) { - DEBUG(0,(__location__ " Failed to queue a connect wait response\n")); - return; - } -} - -/* called when the daemon gets a getdbpath request from a client */ static void daemon_request_getdbpath(struct ctdb_client *client, @@ -538,11 +512,6 @@ static void daemon_incoming_packet(void *p, uint8_t *data, uint32_t nread) daemon_request_shutdown(client, (struct ctdb_req_shutdown *)hdr); break; - case CTDB_REQ_STATUS: - ctdb->status.client.req_status++; - daemon_request_status(client, (struct ctdb_req_status *)hdr); - break; - case CTDB_REQ_GETDBPATH: daemon_request_getdbpath(client, (struct ctdb_req_getdbpath *)hdr); break; @@ -786,6 +755,13 @@ static void daemon_control_callback(struct ctdb_context *ctdb, struct ctdb_reply_control *r; size_t len; + DEBUG(0,("callback: size=%u\n", data.dsize)); + DEBUG(0,("callback: size=%u\n", data.dsize)); + DEBUG(0,("callback: size=%u\n", data.dsize)); + DEBUG(0,("callback: size=%u\n", data.dsize)); + DEBUG(0,("callback: size=%u\n", data.dsize)); + DEBUG(0,("callback: size=%u\n", data.dsize)); + /* construct a message to send to the client containing the data */ len = offsetof(struct ctdb_req_control, data) + data.dsize; r = ctdbd_allocate_pkt(client, len); diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 9691797348..2a96229549 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -213,7 +213,7 @@ struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id); struct ctdb_context *ctdb_cmdline_client(struct event_context *ev); struct ctdb_status; -int ctdb_status(struct ctdb_context *ctdb, struct ctdb_status *status); +int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status); int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TDB_DATA *path); diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 58c71d9d1b..ee8118a750 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -145,7 +145,6 @@ struct ctdb_status { uint32_t req_register; uint32_t req_connect_wait; uint32_t req_shutdown; - uint32_t req_status; uint32_t req_control; } client; uint32_t total_calls; @@ -228,7 +227,7 @@ struct ctdb_ltdb_header { uint32_t lacount; }; -enum {CTDB_CONTROL_PROCESS_EXISTS}; +enum {CTDB_CONTROL_PROCESS_EXISTS, CTDB_CONTROL_STATUS}; enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR}; @@ -280,10 +279,8 @@ enum ctdb_operation { CTDB_REQ_CONNECT_WAIT = 1001, CTDB_REPLY_CONNECT_WAIT = 1002, CTDB_REQ_SHUTDOWN = 1003, - CTDB_REQ_STATUS = 1004, - CTDB_REPLY_STATUS = 1005, - CTDB_REQ_GETDBPATH = 1006, - CTDB_REPLY_GETDBPATH = 1007 + CTDB_REQ_GETDBPATH = 1004, + CTDB_REPLY_GETDBPATH = 1005 }; #define CTDB_MAGIC 0x43544442 /* CTDB */ @@ -387,15 +384,6 @@ struct ctdb_reply_getdbpath { uint8_t data[1]; }; -struct ctdb_req_status { - struct ctdb_req_header hdr; -}; - -struct ctdb_reply_status { - struct ctdb_req_header hdr; - struct ctdb_status status; -}; - struct ctdb_req_control { struct ctdb_req_header hdr; uint32_t opcode; diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index 6be2484eb9..e5a2c22a9d 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -32,31 +32,90 @@ static void usage(void) { printf("Usage: ctdb_control [options] <control>\n"); + printf("\nControls:\n"); + printf(" process-exists <vnn:pid>\n"); + printf(" status <vnn>\n"); exit(1); } static int control_process_exists(struct ctdb_context *ctdb, int argc, const char **argv) { - uint32_t srvid; - pid_t pid; + uint32_t vnn, pid; int ret; - if (argc < 2) { + if (argc < 1) { usage(); } - srvid = strtoul(argv[0], NULL, 0); - pid = strtoul(argv[1], NULL, 0); + if (sscanf(argv[0], "%u:%u", &vnn, &pid) != 2) { + printf("Badly formed vnn:pid\n"); + return -1; + } - ret = ctdb_process_exists(ctdb, srvid, pid); + ret = ctdb_process_exists(ctdb, vnn, pid); if (ret == 0) { - printf("%u:%u exists\n", srvid, pid); + printf("%u:%u exists\n", vnn, pid); } else { - printf("%u:%u does not exist\n", srvid, pid); + printf("%u:%u does not exist\n", vnn, pid); } return ret; } /* + display status structure + */ +static void show_status(struct ctdb_status *s) +{ + printf("CTDB version %u\n", CTDB_VERSION); + printf(" client_packets_sent %u\n", s->client_packets_sent); + printf(" client_packets_recv %u\n", s->client_packets_recv); + printf(" req_call %u\n", s->client.req_call); + printf(" req_message %u\n", s->client.req_message); + printf(" req_finished %u\n", s->client.req_finished); + printf(" req_register %u\n", s->client.req_register); + printf(" req_connect_wait %u\n", s->client.req_connect_wait); + printf(" req_shutdown %u\n", s->client.req_shutdown); + printf(" req_control %u\n", s->client.req_control); + printf(" node_packets_sent %u\n", s->node_packets_sent); + printf(" node_packets_recv %u\n", s->node_packets_recv); + printf(" req_call %u\n", s->count.req_call); + printf(" reply_call %u\n", s->count.reply_call); + printf(" reply_redirect %u\n", s->count.reply_redirect); + printf(" req_dmaster %u\n", s->count.req_dmaster); + printf(" reply_dmaster %u\n", s->count.reply_dmaster); + printf(" reply_error %u\n", s->count.reply_error); + printf(" reply_redirect %u\n", s->count.reply_redirect); + printf(" req_message %u\n", s->count.req_message); + printf(" req_finished %u\n", s->count.req_finished); + printf(" total_calls %u\n", s->total_calls); + printf(" pending_calls %u\n", s->pending_calls); + printf(" lockwait_calls %u\n", s->lockwait_calls); + printf(" pending_lockwait_calls %u\n", s->pending_lockwait_calls); + printf(" max_redirect_count %u\n", s->max_redirect_count); + printf(" max_call_latency %.6f sec\n", s->max_call_latency); + printf(" max_lockwait_latency %.6f sec\n", s->max_lockwait_latency); +} + +static int control_status(struct ctdb_context *ctdb, int argc, const char **argv) +{ + uint32_t vnn; + int ret; + struct ctdb_status status; + if (argc < 1) { + usage(); + } + + vnn = strtoul(argv[0], NULL, 0); + + ret = ctdb_status(ctdb, vnn, &status); + if (ret != 0) { + printf("Unable to get status from node %u\n", vnn); + return ret; + } + show_status(&status); + return 0; +} + +/* main program */ int main(int argc, const char *argv[]) @@ -110,6 +169,8 @@ int main(int argc, const char *argv[]) if (strcmp(control, "process-exists") == 0) { ret = control_process_exists(ctdb, extra_argc-1, extra_argv+1); + } else if (strcmp(control, "status") == 0) { + ret = control_status(ctdb, extra_argc-1, extra_argv+1); } else { printf("Unknown control '%s'\n", control); exit(1); diff --git a/ctdb/tools/ctdb_status.c b/ctdb/tools/ctdb_status.c deleted file mode 100644 index 4e931d9179..0000000000 --- a/ctdb/tools/ctdb_status.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - ctdb status tool - - Copyright (C) Andrew Tridgell 2007 - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "includes.h" -#include "lib/events/events.h" -#include "system/filesys.h" -#include "popt.h" -#include "cmdline.h" -#include "../include/ctdb_private.h" - - -/* - display status structure - */ -static void show_status(struct ctdb_status *s) -{ - printf("CTDB version %u\n", CTDB_VERSION); - printf(" client_packets_sent %u\n", s->client_packets_sent); - printf(" client_packets_recv %u\n", s->client_packets_recv); - printf(" req_call %u\n", s->client.req_call); - printf(" req_message %u\n", s->client.req_message); - printf(" req_finished %u\n", s->client.req_finished); - printf(" req_register %u\n", s->client.req_register); - printf(" req_connect_wait %u\n", s->client.req_connect_wait); - printf(" req_shutdown %u\n", s->client.req_shutdown); - printf(" req_status %u\n", s->client.req_status); - printf(" node_packets_sent %u\n", s->node_packets_sent); - printf(" node_packets_recv %u\n", s->node_packets_recv); - printf(" req_call %u\n", s->count.req_call); - printf(" reply_call %u\n", s->count.reply_call); - printf(" reply_redirect %u\n", s->count.reply_redirect); - printf(" req_dmaster %u\n", s->count.req_dmaster); - printf(" reply_dmaster %u\n", s->count.reply_dmaster); - printf(" reply_error %u\n", s->count.reply_error); - printf(" reply_redirect %u\n", s->count.reply_redirect); - printf(" req_message %u\n", s->count.req_message); - printf(" req_finished %u\n", s->count.req_finished); - printf(" total_calls %u\n", s->total_calls); - printf(" pending_calls %u\n", s->pending_calls); - printf(" lockwait_calls %u\n", s->lockwait_calls); - printf(" pending_lockwait_calls %u\n", s->pending_lockwait_calls); - printf(" max_redirect_count %u\n", s->max_redirect_count); - printf(" max_call_latency %.6f sec\n", s->max_call_latency); - printf(" max_lockwait_latency %.6f sec\n", s->max_lockwait_latency); -} - -/* - show usage message - */ -static void usage(void) -{ - printf("Usage: ctdb_status <socketpath>\n"); - exit(1); -} - -/* - main program -*/ -int main(int argc, const char *argv[]) -{ - struct ctdb_context *ctdb; - struct poptOption popt_options[] = { - POPT_AUTOHELP - POPT_CTDB_CMDLINE - POPT_TABLEEND - }; - int opt; - const char **extra_argv; - int extra_argc = 0; - int ret; - poptContext pc; - struct event_context *ev; - const char *ctdb_socket; - struct ctdb_status status; - - pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST); - - while ((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - default: - fprintf(stderr, "Invalid option %s: %s\n", - poptBadOption(pc, 0), poptStrerror(opt)); - exit(1); - } - } - - /* setup the remaining options for the main program to use */ - extra_argv = poptGetArgs(pc); - if (extra_argv) { - extra_argv++; - while (extra_argv[extra_argc]) extra_argc++; - } - - if (extra_argc < 1) { - usage(); - } - - ctdb_socket = extra_argv[0]; - - ev = event_context_init(NULL); - - /* initialise ctdb */ - ctdb = ctdb_cmdline_client(ev); - if (ctdb == NULL) { - printf("Failed to init ctdb\n"); - exit(1); - } - - ret = ctdb_status(ctdb, &status); - if (ret != 0) { - printf("Failed to get ctdb status\n"); - exit(1); - } - - show_status(&status); - - return 0; -} |