ctdb-daemon: Add client code to talk to new event daemon
authorAmitay Isaacs <amitay@gmail.com>
Thu, 21 Jun 2018 07:16:07 +0000 (17:16 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 5 Jul 2018 04:52:44 +0000 (06:52 +0200)
This fixes the build and now new eventd is integrated completely in CTDB.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/server/ctdb_monitor.c
ctdb/server/eventscript.c
ctdb/wscript

index 59d4a915fd8d2b366d3f1e3586e4fd4b23cb66cf..68884ac5c11a879b57641e4b14f7a02dcf2d30a6 100644 (file)
@@ -129,12 +129,12 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
        rddata.dptr = (uint8_t *)&rd;
        rddata.dsize = sizeof(rd);
 
-       if (status == -ECANCELED) {
+       if (status == ECANCELED) {
                DEBUG(DEBUG_ERR,("Monitoring event was cancelled\n"));
                goto after_change_status;
        }
 
-       if (status == -ETIME) {
+       if (status == ETIME) {
                ctdb->monitor->event_script_timeouts++;
 
                if (ctdb->monitor->event_script_timeouts >=
index c3624f26fa8bdcb4d545dfcb850e563ea259dab5..de05443e66ca0da14cb29a14af7425b695e625fd 100644 (file)
@@ -43,7 +43,8 @@
 #include "common/sock_io.h"
 #include "common/path.h"
 
-#include "protocol/protocol_api.h"
+#include "protocol/protocol_util.h"
+#include "event/event_protocol_api.h"
 
 /*
  * Setting up event daemon
@@ -293,6 +294,7 @@ static int eventd_client_write(struct eventd_context *ectx,
                                                void *private_data),
                               void *private_data)
 {
+       struct ctdb_event_header header;
        struct eventd_client_state *state;
        int ret;
 
@@ -317,16 +319,19 @@ static int eventd_client_write(struct eventd_context *ectx,
 
        talloc_set_destructor(state, eventd_client_state_destructor);
 
-       sock_packet_header_set_reqid(&request->header, state->reqid);
+       header.reqid = state->reqid;
 
-       state->buflen = ctdb_event_request_len(request);
+       state->buflen = ctdb_event_request_len(&header, request);
        state->buf = talloc_size(state, state->buflen);
        if (state->buf == NULL) {
                talloc_free(state);
                return -1;
        }
 
-       ret = ctdb_event_request_push(request, state->buf, &state->buflen);
+       ret = ctdb_event_request_push(&header,
+                                     request,
+                                     state->buf,
+                                     &state->buflen);
        if (ret != 0) {
                talloc_free(state);
                return -1;
@@ -358,6 +363,7 @@ static void eventd_client_read(uint8_t *buf, size_t buflen,
        struct eventd_context *ectx = talloc_get_type_abort(
                private_data, struct eventd_context);
        struct eventd_client_state *state;
+       struct ctdb_event_header header;
        struct ctdb_event_reply *reply;
        int ret;
 
@@ -367,33 +373,27 @@ static void eventd_client_read(uint8_t *buf, size_t buflen,
                return;
        }
 
-       reply = talloc_zero(ectx, struct ctdb_event_reply);
-       if (reply == NULL) {
-               return;
-       }
-
-       ret = ctdb_event_reply_pull(buf, buflen, reply, reply);
+       ret = ctdb_event_reply_pull(buf, buflen, &header, ectx, &reply);
        if (ret != 0) {
                D_ERR("Invalid packet received, ret=%d\n", ret);
-               talloc_free(reply);
                return;
        }
 
-       if (buflen != reply->header.length) {
+       if (buflen != header.length) {
                D_ERR("Packet size mismatch %zu != %"PRIu32"\n",
-                     buflen, reply->header.length);
+                     buflen, header.length);
                talloc_free(reply);
                return;
        }
 
-       state = reqid_find(ectx->idr, reply->header.reqid,
+       state = reqid_find(ectx->idr, header.reqid,
                           struct eventd_client_state);
        if (state == NULL) {
                talloc_free(reply);
                return;
        }
 
-       if (state->reqid != reply->header.reqid) {
+       if (state->reqid != header.reqid) {
                talloc_free(reply);
                return;
        }
@@ -439,12 +439,14 @@ static int eventd_client_run(struct eventd_context *ectx,
        state->callback = callback;
        state->private_data = private_data;
 
-       rdata.event = event;
+       rdata.component = "legacy";
+       rdata.event = ctdb_event_to_string(event);
+       rdata.args = arg_str;
        rdata.timeout = timeout;
-       rdata.arg_str = arg_str;
+       rdata.flags = 0;
 
-       request.rdata.command = CTDB_EVENT_COMMAND_RUN;
-       request.rdata.data.run = &rdata;
+       request.cmd = CTDB_EVENT_CMD_RUN;
+       request.data.run = &rdata;
 
        ret = eventd_client_write(ectx, state, &request,
                                  eventd_client_run_done, state);
@@ -463,7 +465,7 @@ static void eventd_client_run_done(struct ctdb_event_reply *reply,
                private_data, struct eventd_client_run_state);
 
        state = talloc_steal(state->ectx, state);
-       state->callback(reply->rdata.result, state->private_data);
+       state->callback(reply->result, state->private_data);
        talloc_free(state);
 }
 
@@ -560,7 +562,7 @@ static void ctdb_event_script_run_done(int result, void *private_data)
        struct ctdb_event_script_run_state *state = talloc_get_type_abort(
                private_data, struct ctdb_event_script_run_state);
 
-       if (result == -ETIME) {
+       if (result == ETIME) {
                switch (state->event) {
                case CTDB_EVENT_START_RECOVERY:
                case CTDB_EVENT_RECOVERED:
@@ -714,7 +716,7 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_event call,
                tevent_loop_once(ctdb->ev);
        }
 
-       if (state.status == -ETIME) {
+       if (state.status == ETIME) {
                /* Don't ban self if CTDB is starting up or shutting down */
                if (call != CTDB_EVENT_INIT && call != CTDB_EVENT_SHUTDOWN) {
                        DEBUG(DEBUG_ERR,
index f91631feaf1f3f35c40632ff092ea3ed3cb995c1..8ae3f89b1e741e89d4e02cebbea38b5f491a6a5a 100644 (file)
@@ -558,6 +558,7 @@ def build(bld):
                              ctdb-database-conf
                              ctdb-event-conf
                              ctdb-legacy-conf
+                             ctdb-event-protocol
                              talloc tevent tdb-wrap tdb talloc_report''' +
                           ib_deps,
                      install_path='${SBINDIR}',