diff options
author | Amitay Isaacs <amitay@gmail.com> | 2018-06-21 16:44:02 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2018-07-05 06:52:44 +0200 |
commit | 8250072a8116e04031e6a161c3bbc2af73fae431 (patch) | |
tree | c313ff03d696f90ed47bfd670acf897e3a76b6ea /ctdb | |
parent | 0e444c961c0755129d614963fb23cff737cfcaf1 (diff) | |
download | samba-8250072a8116e04031e6a161c3bbc2af73fae431.tar.gz |
ctdb-protocol: Remove protocol for old event daemon
This breaks the build. The new eventd protocol cannot be introduced without
removing the old eventd protocol.
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/protocol/protocol.h | 75 | ||||
-rw-r--r-- | ctdb/protocol/protocol_api.h | 20 | ||||
-rw-r--r-- | ctdb/protocol/protocol_event.c | 920 | ||||
-rwxr-xr-x | ctdb/tests/cunit/protocol_test_102.sh | 25 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_common_event.c | 285 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_common_event.h | 86 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_event_test.c | 146 | ||||
-rw-r--r-- | ctdb/wscript | 3 |
8 files changed, 0 insertions, 1560 deletions
diff --git a/ctdb/protocol/protocol.h b/ctdb/protocol/protocol.h index 7189fab43f0..6abd0158b32 100644 --- a/ctdb/protocol/protocol.h +++ b/ctdb/protocol/protocol.h @@ -1048,79 +1048,4 @@ struct sock_packet_header { uint32_t reqid; }; -/* - * Eventd protocol - */ - -enum ctdb_event_command { - CTDB_EVENT_COMMAND_RUN = 1, - CTDB_EVENT_COMMAND_STATUS = 2, - CTDB_EVENT_COMMAND_SCRIPT_LIST = 3, - CTDB_EVENT_COMMAND_SCRIPT_ENABLE = 4, - CTDB_EVENT_COMMAND_SCRIPT_DISABLE = 5, -}; - -enum ctdb_event_status_state { - CTDB_EVENT_LAST_RUN = 1, - CTDB_EVENT_LAST_PASS = 2, - CTDB_EVENT_LAST_FAIL = 3, -}; - -struct ctdb_event_request_run { - enum ctdb_event event; - uint32_t timeout; - const char *arg_str; -}; - -struct ctdb_event_request_status { - enum ctdb_event event; - enum ctdb_event_status_state state; -}; - -struct ctdb_event_request_script_enable { - const char *script_name; -}; - -struct ctdb_event_request_script_disable { - const char *script_name; -}; - -struct ctdb_event_request_data { - enum ctdb_event_command command; - union { - struct ctdb_event_request_run *run; - struct ctdb_event_request_status *status; - struct ctdb_event_request_script_enable *script_enable; - struct ctdb_event_request_script_disable *script_disable; - } data; -}; - -struct ctdb_event_reply_status { - int status; - struct ctdb_script_list *script_list; -}; - -struct ctdb_event_reply_script_list { - struct ctdb_script_list *script_list; -}; - -struct ctdb_event_reply_data { - enum ctdb_event_command command; - int32_t result; - union { - struct ctdb_event_reply_status *status; - struct ctdb_event_reply_script_list *script_list; - } data; -}; - -struct ctdb_event_request { - struct sock_packet_header header; - struct ctdb_event_request_data rdata; -}; - -struct ctdb_event_reply { - struct sock_packet_header header; - struct ctdb_event_reply_data rdata; -}; - #endif /* __CTDB_PROTOCOL_H__ */ diff --git a/ctdb/protocol/protocol_api.h b/ctdb/protocol/protocol_api.h index 8b40d1d8c0e..1cd5d7d66e6 100644 --- a/ctdb/protocol/protocol_api.h +++ b/ctdb/protocol/protocol_api.h @@ -667,26 +667,6 @@ int ctdb_req_tunnel_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, struct ctdb_req_tunnel *c); -/* From protocol/protocol_event.c */ - -size_t ctdb_event_request_len(struct ctdb_event_request *in); - -int ctdb_event_request_push(struct ctdb_event_request *in, - uint8_t *buf, size_t *buflen); - -int ctdb_event_request_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request *out); - -size_t ctdb_event_reply_len(struct ctdb_event_reply *in); - -int ctdb_event_reply_push(struct ctdb_event_reply *in, - uint8_t *buf, size_t *buflen); - -int ctdb_event_reply_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_reply *out); - /* From protocol/protocol_packet.c */ int ctdb_allocate_pkt(TALLOC_CTX *mem_ctx, size_t datalen, diff --git a/ctdb/protocol/protocol_event.c b/ctdb/protocol/protocol_event.c deleted file mode 100644 index af6040abd92..00000000000 --- a/ctdb/protocol/protocol_event.c +++ /dev/null @@ -1,920 +0,0 @@ -/* - CTDB eventd protocol marshalling - - Copyright (C) Amitay Isaacs 2016 - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#include "replace.h" -#include "system/network.h" - -#include <talloc.h> - -#include "protocol.h" -#include "protocol_private.h" -#include "protocol_api.h" - -static size_t ctdb_event_len(enum ctdb_event in) -{ - uint32_t u32 = in; - - return ctdb_uint32_len(&u32); -} - -static void ctdb_event_push(enum ctdb_event in, uint8_t *buf, size_t *npush) -{ - size_t np; - uint32_t u32 = in; - - ctdb_uint32_push(&u32, buf, &np); - - *npush = np; -} - -static int ctdb_event_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, enum ctdb_event *out, - size_t *npull) -{ - uint32_t uint32_value; - enum ctdb_event value; - size_t np; - int ret; - - ret = ctdb_uint32_pull(buf, buflen, &uint32_value, &np); - if (ret != 0) { - return ret; - } - - switch (uint32_value) { - case 0: - value = CTDB_EVENT_INIT; - break; - - case 1: - value = CTDB_EVENT_SETUP; - break; - - case 2: - value = CTDB_EVENT_STARTUP; - break; - - case 3: - value = CTDB_EVENT_START_RECOVERY; - break; - - case 4: - value = CTDB_EVENT_RECOVERED; - break; - - case 5: - value = CTDB_EVENT_TAKE_IP; - break; - - case 6: - value = CTDB_EVENT_RELEASE_IP; - break; - - case 7: - value = CTDB_EVENT_STOPPED; - break; - - case 8: - value = CTDB_EVENT_MONITOR; - break; - - case 9: - value = CTDB_EVENT_STATUS; - break; - - case 10: - value = CTDB_EVENT_SHUTDOWN; - break; - - case 11: - value = CTDB_EVENT_RELOAD; - break; - - case 12: - value = CTDB_EVENT_UPDATE_IP; - break; - - case 13: - value = CTDB_EVENT_IPREALLOCATED; - break; - - default: - return EINVAL; - } - - *out = value; - *npull = np; - return 0; -} - -static size_t ctdb_event_command_len(enum ctdb_event_command in) -{ - uint32_t u32 = in; - - return ctdb_uint32_len(&u32); -} - -static void ctdb_event_command_push(enum ctdb_event_command in, uint8_t *buf, - size_t *npush) -{ - size_t np; - uint32_t u32 = in; - - ctdb_uint32_push(&u32, buf, &np); - - *npush = np; -} - -static int ctdb_event_command_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - enum ctdb_event_command *out, - size_t *npull) -{ - uint32_t uint32_value; - enum ctdb_event_command value; - size_t np; - int ret; - - ret = ctdb_uint32_pull(buf, buflen, &uint32_value, &np); - if (ret != 0) { - return ret; - } - - switch (uint32_value) { - case 1: - value = CTDB_EVENT_COMMAND_RUN; - break; - - case 2: - value = CTDB_EVENT_COMMAND_STATUS; - break; - - case 3: - value = CTDB_EVENT_COMMAND_SCRIPT_LIST; - break; - - case 4: - value = CTDB_EVENT_COMMAND_SCRIPT_ENABLE; - break; - - case 5: - value = CTDB_EVENT_COMMAND_SCRIPT_DISABLE; - break; - - default: - return EINVAL; - } - - *out = value; - *npull = np; - return 0; -} - -static size_t ctdb_event_status_state_len(enum ctdb_event_status_state in) -{ - uint32_t u32 = in; - - return ctdb_uint32_len(&u32); -} - -static void ctdb_event_status_state_push(enum ctdb_event_status_state in, - uint8_t *buf, size_t *npush) -{ - size_t np; - uint32_t u32 = in; - - ctdb_uint32_push(&u32, buf, &np); - - *npush = np; -} - -static int ctdb_event_status_state_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - enum ctdb_event_status_state *out, - size_t *npull) -{ - uint32_t uint32_value; - enum ctdb_event_status_state value; - size_t np; - int ret; - - ret = ctdb_uint32_pull(buf, buflen, &uint32_value, &np); - if (ret != 0) { - return ret; - } - - switch (uint32_value) { - case 1: - value = CTDB_EVENT_LAST_RUN; - break; - - case 2: - value = CTDB_EVENT_LAST_PASS; - break; - - case 3: - value = CTDB_EVENT_LAST_FAIL; - break; - - default: - return EINVAL; - } - - *out = value; - *npull = np; - return 0; -} - -static size_t ctdb_event_request_run_len(struct ctdb_event_request_run *in) -{ - return ctdb_event_len(in->event) + - ctdb_uint32_len(&in->timeout) + - ctdb_stringn_len(&in->arg_str); -} - -static void ctdb_event_request_run_push(struct ctdb_event_request_run *in, - uint8_t *buf, size_t *npush) -{ - size_t offset = 0, np; - - ctdb_event_push(in->event, buf, &np); - offset += np; - - ctdb_uint32_push(&in->timeout, buf+offset, &np); - offset += np; - - ctdb_stringn_push(&in->arg_str, buf+offset, &np); - offset += np; - - *npush = offset; -} - -static int ctdb_event_request_run_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request_run **out, - size_t *npull) -{ - struct ctdb_event_request_run *rdata; - size_t offset = 0, np; - int ret; - - rdata = talloc(mem_ctx, struct ctdb_event_request_run); - if (rdata == NULL) { - return ENOMEM; - } - - ret = ctdb_event_pull(buf, buflen, rdata, &rdata->event, &np); - if (ret != 0) { - goto fail; - } - offset += np; - - ret = ctdb_uint32_pull(buf+offset, buflen-offset, &rdata->timeout, - &np); - if (ret != 0) { - goto fail; - } - offset += np; - - ret = ctdb_stringn_pull(buf+offset, buflen-offset, - rdata, &rdata->arg_str, &np); - if (ret != 0) { - goto fail; - } - offset += np; - - *out = rdata; - *npull = offset; - return 0; - -fail: - talloc_free(rdata); - return ret; -} - -static size_t ctdb_event_request_status_len( - struct ctdb_event_request_status *in) -{ - return ctdb_event_len(in->event) + - ctdb_event_status_state_len(in->state); -} - -static void ctdb_event_request_status_push( - struct ctdb_event_request_status *in, - uint8_t *buf, size_t *npush) -{ - size_t offset = 0, np; - - ctdb_event_push(in->event, buf, &np); - offset += np; - - ctdb_event_status_state_push(in->state, buf+offset, &np); - offset += np; - - *npush = offset; -} - -static int ctdb_event_request_status_pull( - uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request_status **out, - size_t *npull) -{ - struct ctdb_event_request_status *rdata; - size_t offset = 0, np; - int ret; - - rdata = talloc(mem_ctx, struct ctdb_event_request_status); - if (rdata == NULL) { - return ENOMEM; - } - - ret = ctdb_event_pull(buf, buflen, rdata, &rdata->event, &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - offset += np; - - ret = ctdb_event_status_state_pull(buf+offset, buflen-offset, - rdata, &rdata->state, &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - offset += np; - - *out = rdata; - *npull = offset; - return 0; -} - -static size_t ctdb_event_request_script_enable_len( - struct ctdb_event_request_script_enable *in) -{ - return ctdb_stringn_len(&in->script_name); -} - -static void ctdb_event_request_script_enable_push( - struct ctdb_event_request_script_enable *in, - uint8_t *buf, size_t *npush) -{ - size_t np; - - ctdb_stringn_push(&in->script_name, buf, &np); - - *npush = np; -} - -static int ctdb_event_request_script_enable_pull( - uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request_script_enable **out, - size_t *npull) -{ - struct ctdb_event_request_script_enable *rdata; - size_t np; - int ret; - - rdata = talloc(mem_ctx, struct ctdb_event_request_script_enable); - if (rdata == NULL) { - return ENOMEM; - } - - ret = ctdb_stringn_pull(buf, buflen, rdata, &rdata->script_name, &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - - *out = rdata; - *npull = np; - return 0; -} - -static size_t ctdb_event_request_script_disable_len( - struct ctdb_event_request_script_disable *in) -{ - return ctdb_stringn_len(&in->script_name); -} - -static void ctdb_event_request_script_disable_push( - struct ctdb_event_request_script_disable *in, - uint8_t *buf, size_t *npush) -{ - size_t np; - - ctdb_stringn_push(&in->script_name, buf, &np); - - *npush = np; -} - -static int ctdb_event_request_script_disable_pull( - uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request_script_disable **out, - size_t *npull) -{ - struct ctdb_event_request_script_disable *rdata; - size_t np; - int ret; - - rdata = talloc(mem_ctx, struct ctdb_event_request_script_disable); - if (rdata == NULL) { - return ENOMEM; - } - - ret = ctdb_stringn_pull(buf, buflen, rdata, &rdata->script_name, &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - - *out = rdata; - *npull = np; - return 0; -} - -static size_t ctdb_event_request_data_len(struct ctdb_event_request_data *in) -{ - size_t len = 0; - - len += ctdb_event_command_len(in->command); - - switch(in->command) { - case CTDB_EVENT_COMMAND_RUN: - len += ctdb_event_request_run_len(in->data.run); - break; - - case CTDB_EVENT_COMMAND_STATUS: - len += ctdb_event_request_status_len(in->data.status); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - len += ctdb_event_request_script_enable_len( - in->data.script_enable); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - len += ctdb_event_request_script_disable_len( - in->data.script_disable); - break; - } - - return len; -} - -static void ctdb_event_request_data_push(struct ctdb_event_request_data *in, - uint8_t *buf, size_t *npush) -{ - size_t offset = 0, np; - - ctdb_event_command_push(in->command, buf, &np); - offset += np; - - np = 0; - switch (in->command) { - case CTDB_EVENT_COMMAND_RUN: - ctdb_event_request_run_push(in->data.run, buf+offset, &np); - break; - - case CTDB_EVENT_COMMAND_STATUS: - ctdb_event_request_status_push(in->data.status, buf+offset, - &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - ctdb_event_request_script_enable_push( - in->data.script_enable, - buf+offset, &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - ctdb_event_request_script_disable_push( - in->data.script_disable, - buf+offset, &np); - break; - } - offset += np; - - *npush = offset; -} - -static int ctdb_event_request_data_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request_data *out, - size_t *npull) -{ - size_t offset = 0, np; - int ret; - - ret = ctdb_event_command_pull(buf, buflen, mem_ctx, &out->command, - &np); - if (ret != 0) { - return ret; - } - offset += np; - - np = 0; - switch (out->command) { - case CTDB_EVENT_COMMAND_RUN: - ret = ctdb_event_request_run_pull(buf+offset, buflen-offset, - mem_ctx, &out->data.run, - &np); - break; - - case CTDB_EVENT_COMMAND_STATUS: - ret = ctdb_event_request_status_pull( - buf+offset, buflen-offset, - mem_ctx, &out->data.status, - &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - ret = 0; - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - ret = ctdb_event_request_script_enable_pull( - buf+offset, buflen-offset, - mem_ctx, - &out->data.script_enable, - &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - ret = ctdb_event_request_script_disable_pull( - buf+offset, buflen-offset, - mem_ctx, - &out->data.script_disable, - &np); - break; - } - - if (ret != 0) { - return ret; - } - - offset += np; - - *npull = offset; - return 0; -} - -static size_t ctdb_event_reply_status_len(struct ctdb_event_reply_status *in) -{ - return ctdb_int32_len(&in->status) + - ctdb_script_list_len(in->script_list); -} - -static void ctdb_event_reply_status_push(struct ctdb_event_reply_status *in, - uint8_t *buf, size_t *npush) -{ - size_t offset = 0, np; - - ctdb_int32_push(&in->status, buf, &np); - offset += np; - - ctdb_script_list_push(in->script_list, buf+offset, &np); - offset += np; - - *npush = offset; -} - -static int ctdb_event_reply_status_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_status **out, - size_t *npull) -{ - struct ctdb_event_reply_status *rdata; - size_t offset = 0, np; - int ret; - - rdata = talloc(mem_ctx, struct ctdb_event_reply_status); - if (rdata == NULL) { - return ENOMEM; - } - - ret = ctdb_int32_pull(buf, buflen, &rdata->status, &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - offset += np; - - ret = ctdb_script_list_pull(buf+offset, buflen-offset, - rdata, &rdata->script_list, &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - offset += np; - - *out = rdata; - *npull = offset; - return 0; -} - -static size_t ctdb_event_reply_script_list_len( - struct ctdb_event_reply_script_list *in) -{ - return ctdb_script_list_len(in->script_list); -} - -static void ctdb_event_reply_script_list_push( - struct ctdb_event_reply_script_list *in, - uint8_t *buf, size_t *npush) -{ - size_t np; - - ctdb_script_list_push(in->script_list, buf, &np); - - *npush = np; -} - -static int ctdb_event_reply_script_list_pull( - uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_script_list **out, - size_t *npull) -{ - struct ctdb_event_reply_script_list *rdata; - size_t np; - int ret; - - rdata = talloc(mem_ctx, struct ctdb_event_reply_script_list); - if (rdata == NULL) { - return ENOMEM; - } - - ret = ctdb_script_list_pull(buf, buflen, rdata, &rdata->script_list, - &np); - if (ret != 0) { - talloc_free(rdata); - return ret; - } - - *out = rdata; - *npull = np; - return 0; -} - -static size_t ctdb_event_reply_data_len(struct ctdb_event_reply_data *in) -{ - size_t len = 0; - - len += ctdb_event_command_len(in->command); - len += ctdb_int32_len(&in->result); - - switch (in->command) { - case CTDB_EVENT_COMMAND_RUN: - break; - - case CTDB_EVENT_COMMAND_STATUS: - len += ctdb_event_reply_status_len(in->data.status); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - len += ctdb_event_reply_script_list_len(in->data.script_list); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - break; - } - - return len; -} - -static void ctdb_event_reply_data_push(struct ctdb_event_reply_data *in, - uint8_t *buf, size_t *npush) -{ - size_t offset = 0, np; - - ctdb_event_command_push(in->command, buf, &np); - offset += np; - - ctdb_int32_push(&in->result, buf+offset, &np); - offset += np; - - np = 0; - switch (in->command) { - case CTDB_EVENT_COMMAND_RUN: - break; - - case CTDB_EVENT_COMMAND_STATUS: - ctdb_event_reply_status_push(in->data.status, buf+offset, &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - ctdb_event_reply_script_list_push(in->data.script_list, - buf+offset, &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - break; - } - offset += np; - - *npush = offset; -} - -static int ctdb_event_reply_data_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_data *out, - size_t *npull) -{ - size_t offset = 0, np; - int ret; - - ret = ctdb_event_command_pull(buf, buflen, mem_ctx, &out->command, - &np); - if (ret != 0) { - return ret; - } - offset += np; - - ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->result, &np); - if (ret != 0) { - return ret; - } - offset += np; - - np = 0; - switch (out->command) { - case CTDB_EVENT_COMMAND_RUN: - break; - - case CTDB_EVENT_COMMAND_STATUS: - ret = ctdb_event_reply_status_pull( - buf+offset, buflen-offset, - mem_ctx, &out->data.status, &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - ret = ctdb_event_reply_script_list_pull( - buf+offset, buflen-offset, - mem_ctx, &out->data.script_list, &np); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - break; - } - - if (ret != 0) { - return ret; - } - - offset += np; - - *npull = offset; - return 0; -} - -size_t ctdb_event_request_len(struct ctdb_event_request *in) -{ - return sock_packet_header_len(&in->header) + - ctdb_event_request_data_len(&in->rdata); -} - -int ctdb_event_request_push(struct ctdb_event_request *in, - uint8_t *buf, size_t *buflen) -{ - size_t len, offset = 0, np; - - len = ctdb_event_request_len(in); - if (*buflen < len) { - *buflen = len; - return EMSGSIZE; - } - - in->header.length = *buflen; - - sock_packet_header_push(&in->header, buf, &np); - offset += np; - - ctdb_event_request_data_push(&in->rdata, buf+offset, &np); - offset += np; - - if (offset > *buflen) { - return EMSGSIZE; - } - - return 0; -} - -int ctdb_event_request_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_request *out) -{ - size_t offset = 0, np; - int ret; - - ret = sock_packet_header_pull(buf, buflen, &out->header, &np); - if (ret != 0) { - return ret; - } - offset += np; - - ret = ctdb_event_request_data_pull(buf+offset, buflen-offset, - mem_ctx, &out->rdata, &np); - if (ret != 0) { - return ret; - } - offset += np; - - if (offset > buflen) { - return EMSGSIZE; - } - - return 0; -} - -size_t ctdb_event_reply_len(struct ctdb_event_reply *in) -{ - return sock_packet_header_len(&in->header) + - ctdb_event_reply_data_len(&in->rdata); -} - -int ctdb_event_reply_push(struct ctdb_event_reply *in, - uint8_t *buf, size_t *buflen) -{ - size_t len, offset = 0, np; - - len = ctdb_event_reply_len(in); - if (*buflen < len) { - *buflen = len; - return EMSGSIZE; - } - - in->header.length = *buflen; - - sock_packet_header_push(&in->header, buf, &np); - offset += np; - - ctdb_event_reply_data_push(&in->rdata, buf+offset, &np); - offset += np; - - if (offset > *buflen) { - return EMSGSIZE; - } - - return 0; -} - -int ctdb_event_reply_pull(uint8_t *buf, size_t buflen, - TALLOC_CTX *mem_ctx, - struct ctdb_event_reply *out) -{ - size_t offset = 0, np; - int ret; - - ret = sock_packet_header_pull(buf, buflen, &out->header, &np); - if (ret != 0) { - return ret; - } - offset += np; - - ret = ctdb_event_reply_data_pull(buf+offset, buflen-offset, - mem_ctx, &out->rdata, &np); - if (ret != 0) { - return ret; - } - offset += np; - - if (offset > buflen) { - return EMSGSIZE; - } - - return 0; -} diff --git a/ctdb/tests/cunit/protocol_test_102.sh b/ctdb/tests/cunit/protocol_test_102.sh deleted file mode 100755 index 0d9795c2102..00000000000 --- a/ctdb/tests/cunit/protocol_test_102.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -. "${TEST_SCRIPTS_DIR}/unit.sh" - -last_command=5 - -generate_output () -{ - for i in $(seq 1 $last_command) ; do - echo "$1 $i" - done -} - -output=$( - generate_output "ctdb_event_request_data" - generate_output "ctdb_event_reply_data" - generate_output "ctdb_event_request" - generate_output "ctdb_event_reply" -) - -ok "$output" - -for i in $(seq 1 100) ; do - unit_test protocol_event_test $i -done diff --git a/ctdb/tests/src/protocol_common_event.c b/ctdb/tests/src/protocol_common_event.c deleted file mode 100644 index 891af8d29bd..00000000000 --- a/ctdb/tests/src/protocol_common_event.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - protocol tests - eventd protocol - - Copyright (C) Amitay Isaacs 2017 - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#include "replace.h" -#include "system/network.h" - -#include <assert.h> - -#include "tests/src/protocol_common.h" -#include "tests/src/protocol_common_event.h" - -/* - * Functions to fill and verify eventd protocol structures - */ - -void fill_ctdb_event_request_run(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_run *p) -{ - p->event = rand_int(CTDB_EVENT_MAX); - p->timeout = rand(); - fill_ctdb_string(mem_ctx, &p->arg_str); -} - -void verify_ctdb_event_request_run(struct ctdb_event_request_run *p1, - struct ctdb_event_request_run *p2) -{ - assert(p1->event == p2->event); - assert(p1->timeout == p2->timeout); - verify_ctdb_string(&p1->arg_str, &p2->arg_str); -} - -void fill_ctdb_event_request_status(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_status *p) -{ - p->event = rand_int(CTDB_EVENT_MAX); - p->state = rand_int(3) + 1; -} - -void verify_ctdb_event_request_status(struct ctdb_event_request_status *p1, - struct ctdb_event_request_status *p2) -{ - assert(p1->event == p2->event); - assert(p1->state == p2->state); -} - -void fill_ctdb_event_request_script_enable(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_script_enable *p) -{ - fill_ctdb_string(mem_ctx, &p->script_name); -} - -void verify_ctdb_event_request_script_enable( - struct ctdb_event_request_script_enable *p1, - struct ctdb_event_request_script_enable *p2) -{ - verify_ctdb_string(&p1->script_name, &p2->script_name); -} - -void fill_ctdb_event_request_script_disable(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_script_disable *p) -{ - fill_ctdb_string(mem_ctx, &p->script_name); -} - -void verify_ctdb_event_request_script_disable( - struct ctdb_event_request_script_disable *p1, - struct ctdb_event_request_script_disable *p2) -{ - verify_ctdb_string(&p1->script_name, &p2->script_name); -} - -void fill_ctdb_event_reply_status(TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_status *p) -{ - if (rand_int(2) == 0) { - p->status = 0; - p->script_list = talloc(mem_ctx, struct ctdb_script_list); - assert(p->script_list != NULL); - fill_ctdb_script_list(mem_ctx, p->script_list); - } else { - p->status = rand32i(); - p->script_list = NULL; - } -} - -void verify_ctdb_event_reply_status(struct ctdb_event_reply_status *p1, - struct ctdb_event_reply_status *p2) -{ - assert(p1->status == p2->status); - if (p1->script_list == NULL) { - assert(p1->script_list == p2->script_list); - } else { - verify_ctdb_script_list(p1->script_list, p2->script_list); - } -} - -void fill_ctdb_event_reply_script_list(TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_script_list *p) -{ - p->script_list = talloc(mem_ctx, struct ctdb_script_list); - assert(p->script_list != NULL); - - fill_ctdb_script_list(mem_ctx, p->script_list); -} - -void verify_ctdb_event_reply_script_list( - struct ctdb_event_reply_script_list *p1, - struct ctdb_event_reply_script_list *p2) -{ - verify_ctdb_script_list(p1->script_list, p2->script_list); -} - -void fill_ctdb_event_request_data(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_data *r, - uint32_t command) -{ - r->command = command; - - switch (command) { - case CTDB_EVENT_COMMAND_RUN: - r->data.run = talloc(mem_ctx, struct ctdb_event_request_run); - assert(r->data.run != NULL); - - fill_ctdb_event_request_run(mem_ctx, r->data.run); - break; - - case CTDB_EVENT_COMMAND_STATUS: - r->data.status = talloc(mem_ctx, - struct ctdb_event_request_status); - assert(r->data.status != NULL); - - fill_ctdb_event_request_status(mem_ctx, r->data.status); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - r->data.script_enable = talloc(mem_ctx, - struct ctdb_event_request_script_enable); - assert(r->data.script_enable != NULL); - - fill_ctdb_event_request_script_enable(mem_ctx, - r->data.script_enable); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - r->data.script_disable = talloc(mem_ctx, - struct ctdb_event_request_script_disable); - assert(r->data.script_disable != NULL); - - fill_ctdb_event_request_script_disable(mem_ctx, - r->data.script_disable); - break; - } -} - -void verify_ctdb_event_request_data(struct ctdb_event_request_data *r, - struct ctdb_event_request_data *r2) -{ - assert(r->command == r2->command); - - switch (r->command) { - case CTDB_EVENT_COMMAND_RUN: - verify_ctdb_event_request_run(r->data.run, r2->data.run); - break; - - case CTDB_EVENT_COMMAND_STATUS: - verify_ctdb_event_request_status(r->data.status, - r2->data.status); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - verify_ctdb_event_request_script_enable(r->data.script_enable, - r2->data.script_enable); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - verify_ctdb_event_request_script_disable(r->data.script_disable, - r2->data.script_disable); - break; - } -} - -void fill_ctdb_event_reply_data(TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_data *r, - uint32_t command) -{ - r->command = command; - r->result = rand32i(); - - switch (command) { - case CTDB_EVENT_COMMAND_STATUS: - r->data.status = talloc(mem_ctx, - struct ctdb_event_reply_status); - assert(r->data.status != NULL); - - fill_ctdb_event_reply_status(mem_ctx, r->data.status); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - r->data.script_list = talloc(mem_ctx, - struct ctdb_event_reply_script_list); - assert(r->data.script_list != NULL); - - fill_ctdb_event_reply_script_list(mem_ctx, - r->data.script_list); - break; - } -} - -void verify_ctdb_event_reply_data(struct ctdb_event_reply_data *r, - struct ctdb_event_reply_data *r2) -{ - assert(r->command == r2->command); - assert(r->result == r2->result); - - switch (r->command) { - case CTDB_EVENT_COMMAND_RUN: - break; - - case CTDB_EVENT_COMMAND_STATUS: - verify_ctdb_event_reply_status(r->data.status, - r2->data.status); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_LIST: - verify_ctdb_event_reply_script_list(r->data.script_list, - r2->data.script_list); - break; - - case CTDB_EVENT_COMMAND_SCRIPT_ENABLE: - break; - - case CTDB_EVENT_COMMAND_SCRIPT_DISABLE: - break; - } -} - -void fill_ctdb_event_request(TALLOC_CTX *mem_ctx, - struct ctdb_event_request *r, uint32_t command) -{ - fill_sock_packet_header(&r->header); - fill_ctdb_event_request_data(mem_ctx, &r->rdata, command); -} - -void verify_ctdb_event_request(struct ctdb_event_request *r, - struct ctdb_event_request *r2) -{ - verify_sock_packet_header(&r->header, &r2->header); - verify_ctdb_event_request_data(&r->rdata, &r2->rdata); -} - -void fill_ctdb_event_reply(TALLOC_CTX *mem_ctx, struct ctdb_event_reply *r, - uint32_t command) -{ - fill_sock_packet_header(&r->header); - fill_ctdb_event_reply_data(mem_ctx, &r->rdata, command); -} - -void verify_ctdb_event_reply(struct ctdb_event_reply *r, - struct ctdb_event_reply *r2) -{ - verify_sock_packet_header(&r->header, &r2->header); - verify_ctdb_event_reply_data(&r->rdata, &r2->rdata); -} diff --git a/ctdb/tests/src/protocol_common_event.h b/ctdb/tests/src/protocol_common_event.h deleted file mode 100644 index e0c237c5b33..00000000000 --- a/ctdb/tests/src/protocol_common_event.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - protocol tests - eventd protocol - - Copyright (C) Amitay Isaacs 2017 - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __CTDB_PROTOCOL_COMMON_EVENT_H__ -#define __CTDB_PROTOCOL_COMMON_EVENT_H__ - -#include "replace.h" -#include "system/network.h" - -#include <talloc.h> -#include <tdb.h> - -#include "protocol/protocol.h" - -void fill_ctdb_event_request_run(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_run *p); -void verify_ctdb_event_request_run(struct ctdb_event_request_run *p1, - struct ctdb_event_request_run *p2); - -void fill_ctdb_event_request_status(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_status *p); -void verify_ctdb_event_request_status(struct ctdb_event_request_status *p1, - struct ctdb_event_request_status *p2); - -void fill_ctdb_event_request_script_enable(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_script_enable *p); -void verify_ctdb_event_request_script_enable( - struct ctdb_event_request_script_enable *p1, - struct ctdb_event_request_script_enable *p2); - -void fill_ctdb_event_request_script_disable(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_script_disable *p); -void verify_ctdb_event_request_script_disable( - struct ctdb_event_request_script_disable *p1, - struct ctdb_event_request_script_disable *p2); - -void fill_ctdb_event_reply_status(TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_status *p); -void verify_ctdb_event_reply_status(struct ctdb_event_reply_status *p1, - struct ctdb_event_reply_status *p2); - -void fill_ctdb_event_reply_script_list(TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_script_list *p); -void verify_ctdb_event_reply_script_list( - struct ctdb_event_reply_script_list *p1, - struct ctdb_event_reply_script_list *p2); - -void fill_ctdb_event_request_data(TALLOC_CTX *mem_ctx, - struct ctdb_event_request_data *r, - uint32_t command); -void verify_ctdb_event_request_data(struct ctdb_event_request_data *r, - struct ctdb_event_request_data *r2); - -void fill_ctdb_event_reply_data(TALLOC_CTX *mem_ctx, - struct ctdb_event_reply_data *r, - uint32_t command); -void verify_ctdb_event_reply_data(struct ctdb_event_reply_data *r, - struct ctdb_event_reply_data *r2); - -void fill_ctdb_event_request(TALLOC_CTX *mem_ctx, - struct ctdb_event_request *r, uint32_t command); -void verify_ctdb_event_request(struct ctdb_event_request *r, - struct ctdb_event_request *r2); - -void fill_ctdb_event_reply(TALLOC_CTX *mem_ctx, struct ctdb_event_reply *r, - uint32_t command); -void verify_ctdb_event_reply(struct ctdb_event_reply *r, - struct ctdb_event_reply *r2); - -#endif /* __CTDB_PROTOCOL_COMMON_EVENT_H__ */ diff --git a/ctdb/tests/src/protocol_event_test.c b/ctdb/tests/src/protocol_event_test.c deleted file mode 100644 index 46123b4eeea..00000000000 --- a/ctdb/tests/src/protocol_event_test.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - protocol types tests - - Copyright (C) Amitay Isaacs 2015 - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#include <assert.h> - -#include "protocol/protocol_basic.c" -#include "protocol/protocol_types.c" -#include "protocol/protocol_event.c" -#include "protocol/protocol_packet.c" -#include "protocol/protocol_sock.c" - -#include "tests/src/protocol_common.h" -#include "tests/src/protocol_common_event.h" - -#define REQID 0x34567890 - - -/* - * Functions to test eventd protocol marshalling - */ - -/* for ctdb_event_request_data, ctdb_event_reply_data */ -#define PROTOCOL_EVENT1_TEST(TYPE, NAME) \ -static void TEST_FUNC(NAME)(uint32_t command) \ -{ \ - TALLOC_CTX *mem_ctx; \ - TYPE c1, c2; \ - uint8_t *buf; \ - size_t buflen, np; \ - int ret; \ -\ - printf("%s %u\n", #NAME, command); \ - fflush(stdout); \ - mem_ctx = talloc_new(NULL); \ - assert(mem_ctx != NULL); \ - FILL_FUNC(NAME)(mem_ctx, &c1, command); \ - buflen = LEN_FUNC(NAME)(&c1); \ - buf = talloc_size(mem_ctx, buflen); \ - assert(buf != NULL); \ - np = 0; \ - PUSH_FUNC(NAME)(&c1, buf, &np); \ - assert(np == buflen); \ - np = 0; \ - ret = PULL_FUNC(NAME)(buf, buflen, mem_ctx, &c2, &np); \ - assert(ret == 0); \ - assert(np == buflen); \ - VERIFY_FUNC(NAME)(&c1, &c2); \ - talloc_free(mem_ctx); \ -} - -#define PROTOCOL_EVENT2_TEST(TYPE, NAME) \ -static void TEST_FUNC(NAME)(uint32_t command) \ -{ \ - TALLOC_CTX *mem_ctx; \ - TYPE c1, c2; \ - uint8_t *buf; \ - size_t buflen, len; \ - int ret; \ -\ - printf("%s %u\n", #NAME, command); \ - fflush(stdout); \ - mem_ctx = talloc_new(NULL); \ - assert(mem_ctx != NULL); \ - FILL_FUNC(NAME)(mem_ctx, &c1, command); \ - buflen = LEN_FUNC(NAME)(&c1); \ - buf = talloc_size(mem_ctx, buflen); \ - assert(buf != NULL); \ - len = 0; \ - ret = PUSH_FUNC(NAME)(&c1, buf, &len); \ - assert(ret == EMSGSIZE); \ - assert(len == buflen); \ - ret = PUSH_FUNC(NAME)(&c1, buf, &buflen); \ - assert(ret == 0); \ - ret = PULL_FUNC(NAME)(buf, buflen, mem_ctx, &c2); \ - assert(ret == 0); \ - assert(c2.header.length == buflen); \ - VERIFY_FUNC(NAME)(&c1, &c2); \ - talloc_free(mem_ctx); \ -} - -#define NUM_COMMANDS 5 - -PROTOCOL_TYPE3_TEST(struct ctdb_event_request_run, ctdb_event_request_run); -PROTOCOL_TYPE3_TEST(struct ctdb_event_request_status, - ctdb_event_request_status); -PROTOCOL_TYPE3_TEST(struct ctdb_event_request_script_enable, - ctdb_event_request_script_enable); -PROTOCOL_TYPE3_TEST(struct ctdb_event_request_script_disable, - ctdb_event_request_script_disable); -PROTOCOL_TYPE3_TEST(struct ctdb_event_reply_status, ctdb_event_reply_status); -PROTOCOL_TYPE3_TEST(struct ctdb_event_reply_script_list, - ctdb_event_reply_script_list); - -PROTOCOL_EVENT1_TEST(struct ctdb_event_request_data, ctdb_event_request_data); -PROTOCOL_EVENT1_TEST(struct ctdb_event_reply_data, ctdb_event_reply_data); -PROTOCOL_EVENT2_TEST(struct ctdb_event_request, ctdb_event_request); -PROTOCOL_EVENT2_TEST(struct ctdb_event_reply, ctdb_event_reply); - -int main(int argc, char *argv[]) -{ - uint32_t command; - - if (argc == 2) { - int seed = atoi(argv[1]); - srandom(seed); - } - - TEST_FUNC(ctdb_event_request_run)(); - TEST_FUNC(ctdb_event_request_status)(); - TEST_FUNC(ctdb_event_request_script_enable)(); - TEST_FUNC(ctdb_event_request_script_disable)(); - TEST_FUNC(ctdb_event_reply_status)(); - TEST_FUNC(ctdb_event_reply_script_list)(); - - for (command=1; command<=NUM_COMMANDS; command++) { - TEST_FUNC(ctdb_event_request_data)(command); - } - for (command=1; command<=NUM_COMMANDS; command++) { - TEST_FUNC(ctdb_event_reply_data)(command); - } - - for (command=1; command<=NUM_COMMANDS; command++) { - TEST_FUNC(ctdb_event_request)(command); - } - for (command=1; command<=NUM_COMMANDS; command++) { - TEST_FUNC(ctdb_event_reply)(command); - } - - return 0; -} diff --git a/ctdb/wscript b/ctdb/wscript index 01350e468bf..f91631feaf1 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -426,7 +426,6 @@ def build(bld): protocol_tunnel.c protocol_client.c protocol_debug.c - protocol_event.c protocol_sock.c'''), includes='include', deps='ctdb-protocol-basic replace talloc tdb') @@ -872,7 +871,6 @@ def build(bld): source=bld.SUBDIR('tests/src', '''protocol_common.c protocol_common_ctdb.c - protocol_common_event.c '''), includes='include', deps='ctdb-protocol-tests-basic replace talloc tdb') @@ -885,7 +883,6 @@ def build(bld): ctdb_protocol_tests = [ 'protocol_types_test', 'protocol_ctdb_test', - 'protocol_event_test', 'protocol_util_test', 'protocol_types_compat_test', 'protocol_ctdb_compat_test', |