]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
moved status to ctdb_control
authorAndrew Tridgell <tridge@samba.org>
Thu, 26 Apr 2007 12:51:41 +0000 (14:51 +0200)
committerAndrew Tridgell <tridge@samba.org>
Thu, 26 Apr 2007 12:51:41 +0000 (14:51 +0200)
(This used to be ctdb commit 9a543968ba0379fbf8e977e184f22f4349d6243f)

ctdb/Makefile.in
ctdb/common/ctdb_client.c
ctdb/common/ctdb_control.c
ctdb/common/ctdb_daemon.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tools/ctdb_control.c
ctdb/tools/ctdb_status.c [deleted file]

index a74a52abaf7c163b243594ca97ed18e7fa34d23a..773d612a2120bcdddfaba4570df587c519e10640 100644 (file)
@@ -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)
index e0f438c162a318f117ecf78b52d5608c558178c2..f0589e70a43c7ace298a7273c8d21950ad59fe80 100644 (file)
@@ -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;
+}
index c7af9c764126d3b75869a1e97a5427c2414e11fe..2f961e678282a187db18c9c660c832582653cad5 100644 (file)
@@ -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);
 }
index 69d1195d67af894e6e20f68fc03b4347ecaa7887..efb3f5431ec45d63ac60d87a76e8c4cccdfc135e 100644 (file)
@@ -222,32 +222,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
  */
@@ -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);
index 9691797348f27c20f5af8a108719d0e1ba1b7810..2a9622954971ba7c352de97ec8d996b1182f9798 100644 (file)
@@ -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);
 
index 58c71d9d1b41800cef63758e3cc130052d2ef339..ee8118a750eded2986abf03691b80998a63cf7ae 100644 (file)
@@ -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;
index 6be2484eb92d7a5f1e1ea2236a6128e89d53f5f2..e5a2c22a9d6a36d6088b9125f9ab211b812f0194 100644 (file)
 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
 */
@@ -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 (file)
index 4e931d9..0000000
+++ /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;
-}