1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-protocol: Add ctdb protocol serialization routines

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2015-04-14 17:20:05 +10:00 committed by Amitay Isaacs
parent 8b45badfda
commit 34a6c99776
16 changed files with 13522 additions and 0 deletions

1002
ctdb/protocol/protocol.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,643 @@
/*
CTDB protocol marshalling
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/>.
*/
#ifndef __CTDB_PROTOCOL_API_H__
#define __CTDB_PROTOCOL_API_H__
#include "protocol/protocol.h"
/* From protocol/protocol_types.c */
size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *header);
void ctdb_ltdb_header_push(struct ctdb_ltdb_header *header, uint8_t *buf);
int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
struct ctdb_ltdb_header *header);
size_t ctdb_rec_data_len(struct ctdb_rec_data *rec);
void ctdb_rec_data_push(struct ctdb_rec_data *rec, uint8_t *buf);
int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_rec_data **out);
size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *recbuf);
void ctdb_rec_buffer_push(struct ctdb_rec_buffer *recbuf, uint8_t *buf);
int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_rec_buffer **out);
struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
uint32_t db_id);
int ctdb_rec_buffer_add(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *recbuf,
uint32_t reqid, struct ctdb_ltdb_header *header,
TDB_DATA key, TDB_DATA data);
int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
ctdb_rec_parser_func_t func,
void *private_data);
size_t ctdb_server_id_len(struct ctdb_server_id *sid);
void ctdb_server_id_push(struct ctdb_server_id *sid, uint8_t *buf);
int ctdb_server_id_pull(uint8_t *buf, size_t buflen,
struct ctdb_server_id *sid);
size_t ctdb_g_lock_len(struct ctdb_g_lock *lock);
void ctdb_g_lock_push(struct ctdb_g_lock *lock, uint8_t *buf);
int ctdb_g_lock_pull(uint8_t *buf, size_t buflen, struct ctdb_g_lock *lock);
size_t ctdb_g_lock_list_len(struct ctdb_g_lock_list *lock_list);
void ctdb_g_lock_list_push(struct ctdb_g_lock_list *lock_list, uint8_t *buf);
int ctdb_g_lock_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_g_lock_list **out);
/* From protocol/protocol_header.c */
void ctdb_req_header_fill(struct ctdb_req_header *h, uint32_t generation,
uint32_t operation, uint32_t destnode,
uint32_t srcnode, uint32_t reqid);
int ctdb_req_header_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h);
int ctdb_req_header_verify(struct ctdb_req_header *h, uint32_t operation);
/* From protocol/protocol_call.c */
int ctdb_req_call_push(struct ctdb_req_header *h,
struct ctdb_req_call *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_req_call_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_call *c);
int ctdb_reply_call_push(struct ctdb_req_header *h,
struct ctdb_reply_call *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_reply_call_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_call *c);
int ctdb_reply_error_push(struct ctdb_req_header *h,
struct ctdb_reply_error *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_reply_error_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_error *c);
int ctdb_req_dmaster_push(struct ctdb_req_header *h,
struct ctdb_req_dmaster *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_req_dmaster_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_dmaster *c);
int ctdb_reply_dmaster_push(struct ctdb_req_header *h,
struct ctdb_reply_dmaster *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_reply_dmaster_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_dmaster *c);
/* From protocol/protocol_control.c */
int ctdb_req_control_push(struct ctdb_req_header *h,
struct ctdb_req_control *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_req_control_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_control *c);
int ctdb_reply_control_push(struct ctdb_req_header *h,
struct ctdb_reply_control *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_reply_control_pull(uint8_t *pkt, size_t pkt_len, uint32_t opcode,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_control *c);
/* From protocol/protocol_client.c */
void ctdb_req_control_process_exists(struct ctdb_req_control *request,
pid_t pid);
int ctdb_reply_control_process_exists(struct ctdb_reply_control *reply,
int *status);
void ctdb_req_control_statistics(struct ctdb_req_control *request);
int ctdb_reply_control_statistics(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_statistics **stats);
void ctdb_req_control_ping(struct ctdb_req_control *request);
int ctdb_reply_control_ping(struct ctdb_reply_control *reply,
int *num_clients);
void ctdb_req_control_getdbpath(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_getdbpath(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx, const char **db_path);
void ctdb_req_control_getvnnmap(struct ctdb_req_control *request);
int ctdb_reply_control_getvnnmap(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_vnn_map **vnnmap);
void ctdb_req_control_setvnnmap(struct ctdb_req_control *request,
struct ctdb_vnn_map *vnnmap);
int ctdb_reply_control_setvnnmap(struct ctdb_reply_control *reply);
void ctdb_req_control_get_debug(struct ctdb_req_control *request);
int ctdb_reply_control_get_debug(struct ctdb_reply_control *reply,
uint32_t *debug_level);
void ctdb_req_control_set_debug(struct ctdb_req_control *request,
uint32_t debug_level);
int ctdb_reply_control_set_debug(struct ctdb_reply_control *reply);
void ctdb_req_control_get_dbmap(struct ctdb_req_control *request);
int ctdb_reply_control_get_dbmap(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_dbid_map **dbmap);
void ctdb_req_control_pull_db(struct ctdb_req_control *request,
struct ctdb_pulldb *pulldb);
int ctdb_reply_control_pull_db(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_rec_buffer **recbuf);
void ctdb_req_control_push_db(struct ctdb_req_control *request,
struct ctdb_rec_buffer *recbuf);
int ctdb_reply_control_push_db(struct ctdb_reply_control *reply);
void ctdb_req_control_get_recmode(struct ctdb_req_control *request);
int ctdb_reply_control_get_recmode(struct ctdb_reply_control *reply,
int *recmode);
void ctdb_req_control_set_recmode(struct ctdb_req_control *request,
int recmode);
int ctdb_reply_control_set_recmode(struct ctdb_reply_control *reply);
void ctdb_req_control_statistics_reset(struct ctdb_req_control *request);
int ctdb_reply_control_statistics_reset(struct ctdb_reply_control *reply);
void ctdb_req_control_db_attach(struct ctdb_req_control *request,
const char *db_name, uint32_t tdb_flags);
int ctdb_reply_control_db_attach(struct ctdb_reply_control *reply,
uint32_t *db_id);
void ctdb_req_control_traverse_start(struct ctdb_req_control *request,
struct ctdb_traverse_start *traverse);
int ctdb_reply_control_traverse_start(struct ctdb_reply_control *reply);
void ctdb_req_control_register_srvid(struct ctdb_req_control *request,
uint64_t srvid);
int ctdb_reply_control_register_srvid(struct ctdb_reply_control *reply);
void ctdb_req_control_deregister_srvid(struct ctdb_req_control *request,
uint64_t srvid);
int ctdb_reply_control_deregister_srvid(struct ctdb_reply_control *reply);
void ctdb_req_control_get_dbname(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_get_dbname(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx, const char **db_name);
void ctdb_req_control_enable_seqnum(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_enable_seqnum(struct ctdb_reply_control *reply);
void ctdb_req_control_update_seqnum(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_update_seqnum(struct ctdb_reply_control *reply);
void ctdb_req_control_dump_memory(struct ctdb_req_control *request);
int ctdb_reply_control_dump_memory(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx, const char **mem_str);
void ctdb_req_control_get_pid(struct ctdb_req_control *request);
int ctdb_reply_control_get_pid(struct ctdb_reply_control *reply,
pid_t *pid);
void ctdb_req_control_get_recmaster(struct ctdb_req_control *request);
int ctdb_reply_control_get_recmaster(struct ctdb_reply_control *reply,
uint32_t *recmaster);
void ctdb_req_control_set_recmaster(struct ctdb_req_control *request,
int recmaster);
int ctdb_reply_control_set_recmaster(struct ctdb_reply_control *reply);
void ctdb_req_control_freeze(struct ctdb_req_control *request,
uint32_t priority);
int ctdb_reply_control_freeze(struct ctdb_reply_control *reply);
void ctdb_req_control_thaw(struct ctdb_req_control *request,
uint32_t priority);
int ctdb_reply_control_thaw(struct ctdb_reply_control *reply);
void ctdb_req_control_get_pnn(struct ctdb_req_control *request);
int ctdb_reply_control_get_pnn(struct ctdb_reply_control *reply,
uint32_t *pnn);
void ctdb_req_control_shutdown(struct ctdb_req_control *request);
int ctdb_reply_control_shutdown(struct ctdb_reply_control *reply);
void ctdb_req_control_get_monmode(struct ctdb_req_control *request);
int ctdb_reply_control_get_monmode(struct ctdb_reply_control *reply,
int *mon_mode);
void ctdb_req_control_tcp_client(struct ctdb_req_control *request,
struct ctdb_connection *conn);
int ctdb_reply_control_tcp_client(struct ctdb_reply_control *reply);
void ctdb_req_control_tcp_add(struct ctdb_req_control *request,
struct ctdb_connection *conn);
int ctdb_reply_control_tcp_add(struct ctdb_reply_control *reply);
void ctdb_req_control_tcp_remove(struct ctdb_req_control *request,
struct ctdb_connection *conn);
int ctdb_reply_control_tcp_remove(struct ctdb_reply_control *reply);
void ctdb_req_control_startup(struct ctdb_req_control *request);
int ctdb_reply_control_startup(struct ctdb_reply_control *reply);
void ctdb_req_control_set_tunable(struct ctdb_req_control *request,
struct ctdb_tunable *tunable);
int ctdb_reply_control_set_tunable(struct ctdb_reply_control *reply);
void ctdb_req_control_get_tunable(struct ctdb_req_control *request,
const char *name);
int ctdb_reply_control_get_tunable(struct ctdb_reply_control *reply,
uint32_t *value);
void ctdb_req_control_list_tunables(struct ctdb_req_control *request);
int ctdb_reply_control_list_tunables(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_var_list **tun_var_list);
void ctdb_req_control_modify_flags(struct ctdb_req_control *request,
struct ctdb_node_flag_change *flag_change);
int ctdb_reply_control_modify_flags(struct ctdb_reply_control *reply);
void ctdb_req_control_get_all_tunables(struct ctdb_req_control *request);
int ctdb_reply_control_get_all_tunables(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_tunable_list **tun_list);
void ctdb_req_control_kill_tcp(struct ctdb_req_control *request,
struct ctdb_connection *conn);
int ctdb_reply_control_kill_tcp(struct ctdb_reply_control *reply);
void ctdb_req_control_get_tcp_tickle_list(struct ctdb_req_control *request,
ctdb_sock_addr *addr);
int ctdb_reply_control_get_tcp_tickle_list(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_tickle_list **tickles);
void ctdb_req_control_set_tcp_tickle_list(struct ctdb_req_control *request,
struct ctdb_tickle_list *tickles);
int ctdb_reply_control_set_tcp_tickle_list(struct ctdb_reply_control *reply);
void ctdb_req_control_register_server_id(struct ctdb_req_control *request,
struct ctdb_client_id *sid);
int ctdb_reply_control_register_server_id(struct ctdb_reply_control *reply);
void ctdb_req_control_unregister_server_id(struct ctdb_req_control *request,
struct ctdb_client_id *sid);
int ctdb_reply_control_unregister_server_id(struct ctdb_reply_control *reply);
void ctdb_req_control_check_server_id(struct ctdb_req_control *request,
struct ctdb_client_id *sid);
int ctdb_reply_control_check_server_id(struct ctdb_reply_control *reply);
void ctdb_req_control_get_server_id_list(struct ctdb_req_control *request);
int ctdb_reply_control_get_server_id_list(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_client_id_map **cid_map);
void ctdb_req_control_db_attach_persistent(struct ctdb_req_control *request,
const char *name,
uint32_t tdb_flags);
int ctdb_reply_control_db_attach_persistent(struct ctdb_reply_control *reply,
uint32_t *db_id);
void ctdb_req_control_update_record(struct ctdb_req_control *request,
struct ctdb_rec_buffer *recbuf);
int ctdb_reply_control_update_record(struct ctdb_reply_control *reply);
void ctdb_req_control_send_gratuitous_arp(struct ctdb_req_control *request,
struct ctdb_addr_info *addr_info);
int ctdb_reply_control_send_gratuitous_arp(struct ctdb_reply_control *reply);
void ctdb_req_control_transaction_start(struct ctdb_req_control *request,
uint32_t tid);
int ctdb_reply_control_transaction_start(struct ctdb_reply_control *reply);
void ctdb_req_control_transaction_commit(struct ctdb_req_control *request,
uint32_t tid);
int ctdb_reply_control_transaction_commit(struct ctdb_reply_control *reply);
void ctdb_req_control_wipe_database(struct ctdb_req_control *request,
struct ctdb_transdb *transdb);
int ctdb_reply_control_wipe_database(struct ctdb_reply_control *reply);
void ctdb_req_control_uptime(struct ctdb_req_control *request);
int ctdb_reply_control_uptime(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_uptime **uptime);
void ctdb_req_control_start_recovery(struct ctdb_req_control *request);
int ctdb_reply_control_start_recovery(struct ctdb_reply_control *reply);
void ctdb_req_control_end_recovery(struct ctdb_req_control *request);
int ctdb_reply_control_end_recovery(struct ctdb_reply_control *reply);
void ctdb_req_control_reload_nodes_file(struct ctdb_req_control *request);
int ctdb_reply_control_reload_nodes_file(struct ctdb_reply_control *reply);
void ctdb_req_control_try_delete_records(struct ctdb_req_control *request,
struct ctdb_rec_buffer *recbuf);
int ctdb_reply_control_try_delete_records(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_rec_buffer **recbuf);
void ctdb_req_control_enable_monitor(struct ctdb_req_control *request);
int ctdb_reply_control_enable_monitor(struct ctdb_reply_control *reply);
void ctdb_req_control_disable_monitor(struct ctdb_req_control *request);
int ctdb_reply_control_disable_monitor(struct ctdb_reply_control *reply);
void ctdb_req_control_add_public_ip(struct ctdb_req_control *request,
struct ctdb_addr_info *addr_info);
int ctdb_reply_control_add_public_ip(struct ctdb_reply_control *reply);
void ctdb_req_control_del_public_ip(struct ctdb_req_control *request,
struct ctdb_addr_info *addr_info);
int ctdb_reply_control_del_public_ip(struct ctdb_reply_control *reply);
void ctdb_req_control_run_eventscripts(struct ctdb_req_control *request,
const char *event_str);
int ctdb_reply_control_run_eventscripts(struct ctdb_reply_control *reply);
void ctdb_req_control_get_capabilities(struct ctdb_req_control *request);
int ctdb_reply_control_get_capabilities(struct ctdb_reply_control *reply,
uint32_t *caps);
void ctdb_req_control_recd_ping(struct ctdb_req_control *request);
int ctdb_reply_control_recd_ping(struct ctdb_reply_control *reply);
void ctdb_req_control_release_ip(struct ctdb_req_control *request,
struct ctdb_public_ip *pubip);
int ctdb_reply_control_release_ip(struct ctdb_reply_control *reply);
void ctdb_req_control_takeover_ip(struct ctdb_req_control *request,
struct ctdb_public_ip *pubip);
int ctdb_reply_control_takeover_ip(struct ctdb_reply_control *reply);
void ctdb_req_control_get_public_ips(struct ctdb_req_control *request);
int ctdb_reply_control_get_public_ips(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_public_ip_list **pubip_list);
void ctdb_req_control_get_nodemap(struct ctdb_req_control *request);
int ctdb_reply_control_get_nodemap(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_node_map **nodemap);
void ctdb_req_control_get_event_script_status(struct ctdb_req_control *request,
uint32_t event);
int ctdb_reply_control_get_event_script_status(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_script_list **script_list);
void ctdb_req_control_traverse_kill(struct ctdb_req_control *request,
struct ctdb_traverse_start *traverse);
int ctdb_reply_control_traverse_kill(struct ctdb_reply_control *reply);
void ctdb_req_control_recd_reclock_latency(struct ctdb_req_control *request,
double reclock_latency);
int ctdb_reply_control_recd_reclock_latency(struct ctdb_reply_control *reply);
void ctdb_req_control_get_reclock_file(struct ctdb_req_control *request);
int ctdb_reply_control_get_reclock_file(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
const char **reclock_file);
void ctdb_req_control_set_reclock_file(struct ctdb_req_control *request,
const char *reclock_file);
int ctdb_reply_control_set_reclock_file(struct ctdb_reply_control *reply);
void ctdb_req_control_stop_node(struct ctdb_req_control *request);
int ctdb_reply_control_stop_node(struct ctdb_reply_control *reply);
void ctdb_req_control_continue_node(struct ctdb_req_control *request);
int ctdb_reply_control_continue_node(struct ctdb_reply_control *reply);
void ctdb_req_control_set_natgwstate(struct ctdb_req_control *request,
uint32_t natgw_role);
int ctdb_reply_control_set_natgwstate(struct ctdb_reply_control *reply);
void ctdb_req_control_set_lmasterrole(struct ctdb_req_control *request,
uint32_t lmaster_role);
int ctdb_reply_control_set_lmasterrole(struct ctdb_reply_control *reply);
void ctdb_req_control_set_recmasterrole(struct ctdb_req_control *request,
uint32_t recmaster_role);
int ctdb_reply_control_set_recmasterrole(struct ctdb_reply_control *reply);
void ctdb_req_control_enable_script(struct ctdb_req_control *request,
const char *script);
int ctdb_reply_control_enable_script(struct ctdb_reply_control *reply);
void ctdb_req_control_disable_script(struct ctdb_req_control *request,
const char *script);
int ctdb_reply_control_disable_script(struct ctdb_reply_control *reply);
void ctdb_req_control_set_ban_state(struct ctdb_req_control *request,
struct ctdb_ban_state *ban_state);
int ctdb_reply_control_set_ban_state(struct ctdb_reply_control *reply);
void ctdb_req_control_get_ban_state(struct ctdb_req_control *request);
int ctdb_reply_control_get_ban_state(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_ban_state **ban_state);
void ctdb_req_control_set_db_priority(struct ctdb_req_control *request,
struct ctdb_db_priority *db_prio);
int ctdb_reply_control_set_db_priority(struct ctdb_reply_control *reply);
void ctdb_req_control_get_db_priority(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_get_db_priority(struct ctdb_reply_control *reply,
uint32_t *priority);
void ctdb_req_control_transaction_cancel(struct ctdb_req_control *request,
uint32_t tid);
int ctdb_reply_control_transaction_cancel(struct ctdb_reply_control *reply);
void ctdb_req_control_register_notify(struct ctdb_req_control *request,
struct ctdb_notify_data *notify);
int ctdb_reply_control_register_notify(struct ctdb_reply_control *reply);
void ctdb_req_control_deregister_notify(struct ctdb_req_control *request,
uint64_t srvid);
int ctdb_reply_control_deregister_notify(struct ctdb_reply_control *reply);
void ctdb_req_control_trans3_commit(struct ctdb_req_control *request,
struct ctdb_rec_buffer *recbuf);
int ctdb_reply_control_trans3_commit(struct ctdb_reply_control *reply);
void ctdb_req_control_get_db_seqnum(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_get_db_seqnum(struct ctdb_reply_control *reply,
uint64_t *seqnum);
void ctdb_req_control_db_set_healthy(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_db_set_healthy(struct ctdb_reply_control *reply);
void ctdb_req_control_db_get_health(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_db_get_health(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
const char **reason);
void ctdb_req_control_get_public_ip_info(struct ctdb_req_control *request,
ctdb_sock_addr *addr);
int ctdb_reply_control_get_public_ip_info(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_public_ip_info **ipinfo);
void ctdb_req_control_get_ifaces(struct ctdb_req_control *request);
int ctdb_reply_control_get_ifaces(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_iface_list **iface_list);
void ctdb_req_control_set_iface_link_state(struct ctdb_req_control *request,
struct ctdb_iface *iface);
int ctdb_reply_control_set_iface_link_state(struct ctdb_reply_control *reply);
void ctdb_req_control_tcp_add_delayed_update(struct ctdb_req_control *request,
struct ctdb_connection *conn);
int ctdb_reply_control_tcp_add_delayed_update(struct ctdb_reply_control *reply);
void ctdb_req_control_get_stat_history(struct ctdb_req_control *request);
int ctdb_reply_control_get_stat_history(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_statistics_list **stats_list);
void ctdb_req_control_schedule_for_deletion(struct ctdb_req_control *request,
struct ctdb_key_data *key);
int ctdb_reply_control_schedule_for_deletion(struct ctdb_reply_control *reply);
void ctdb_req_control_set_db_readonly(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_set_db_readonly(struct ctdb_reply_control *reply);
void ctdb_req_control_check_srvids(struct ctdb_req_control *request,
struct ctdb_uint64_array *u64_array);
int ctdb_reply_control_check_srvids(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_uint8_array **u8_array);
void ctdb_req_control_traverse_start_ext(struct ctdb_req_control *request,
struct ctdb_traverse_start_ext *traverse);
int ctdb_reply_control_traverse_start_ext(struct ctdb_reply_control *reply);
void ctdb_req_control_get_db_statistics(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_get_db_statistics(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_db_statistics **dbstats);
void ctdb_req_control_set_db_sticky(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_set_db_sticky(struct ctdb_reply_control *reply);
void ctdb_req_control_reload_public_ips(struct ctdb_req_control *request);
int ctdb_reply_control_reload_public_ips(struct ctdb_reply_control *reply);
void ctdb_req_control_receive_records(struct ctdb_req_control *request,
struct ctdb_rec_buffer *recbuf);
int ctdb_reply_control_receive_records(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_rec_buffer **recbuf);
void ctdb_req_control_ipreallocated(struct ctdb_req_control *request);
int ctdb_reply_control_ipreallocated(struct ctdb_reply_control *reply);
void ctdb_req_control_get_runstate(struct ctdb_req_control *request);
int ctdb_reply_control_get_runstate(struct ctdb_reply_control *reply,
enum ctdb_runstate *runstate);
void ctdb_req_control_db_detach(struct ctdb_req_control *request,
uint32_t db_id);
int ctdb_reply_control_db_detach(struct ctdb_reply_control *reply);
void ctdb_req_control_get_nodes_file(struct ctdb_req_control *request);
int ctdb_reply_control_get_nodes_file(struct ctdb_reply_control *reply,
TALLOC_CTX *mem_ctx,
struct ctdb_node_map **nodemap);
/* From protocol/protocol_message.c */
int ctdb_req_message_push(struct ctdb_req_header *h,
struct ctdb_req_message *c,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_req_message_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_message *c);
int ctdb_req_message_data_push(struct ctdb_req_header *h,
struct ctdb_req_message_data *message,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len);
int ctdb_req_message_data_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_message_data *message);
/* From protocol/protocol_util.c */
const char *ctdb_runstate_to_string(enum ctdb_runstate runstate);
enum ctdb_runstate ctdb_runstate_from_string(const char *runstate_str);
const char *ctdb_event_to_string(enum ctdb_event event);
enum ctdb_event ctdb_event_from_string(const char *event_str);
#endif /* __CTDB_PROTOCOL_API_H__ */

View File

@ -0,0 +1,446 @@
/*
CTDB protocol marshalling
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 "replace.h"
#include "system/network.h"
#include <talloc.h>
#include <tdb.h>
#include "protocol.h"
#include "protocol_api.h"
#include "protocol_private.h"
struct ctdb_req_call_wire {
struct ctdb_req_header hdr;
uint32_t flags;
uint32_t db_id;
uint32_t callid;
uint32_t hopcount;
uint32_t keylen;
uint32_t calldatalen;
uint8_t data[1]; /* key[] followed by calldata[] */
};
struct ctdb_reply_call_wire {
struct ctdb_req_header hdr;
uint32_t status;
uint32_t datalen;
uint8_t data[1];
};
struct ctdb_reply_error_wire {
struct ctdb_req_header hdr;
uint32_t status;
uint32_t msglen;
uint8_t msg[1];
};
struct ctdb_req_dmaster_wire {
struct ctdb_req_header hdr;
uint32_t db_id;
uint64_t rsn;
uint32_t dmaster;
uint32_t keylen;
uint32_t datalen;
uint8_t data[1];
};
struct ctdb_reply_dmaster_wire {
struct ctdb_req_header hdr;
uint32_t db_id;
uint64_t rsn;
uint32_t keylen;
uint32_t datalen;
uint8_t data[1];
};
int ctdb_req_call_push(struct ctdb_req_header *h, struct ctdb_req_call *c,
TALLOC_CTX *mem_ctx, uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_req_call_wire *wire;
uint8_t *buf;
size_t length, buflen;
int ret;
if (c->key.dsize == 0) {
return EINVAL;
}
length = offsetof(struct ctdb_req_call_wire, data) +
c->key.dsize + c->calldata.dsize;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_req_call_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->flags = c->flags;
wire->db_id = c->db_id;
wire->callid = c->callid;
wire->hopcount = c->hopcount;
wire->keylen = c->key.dsize;
wire->calldatalen = c->calldata.dsize;
memcpy(wire->data, c->key.dptr, c->key.dsize);
if (c->calldata.dsize > 0) {
memcpy(wire->data + c->key.dsize, c->calldata.dptr,
c->calldata.dsize);
}
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_req_call_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_call *c)
{
struct ctdb_req_call_wire *wire;
size_t length;
length = offsetof(struct ctdb_req_call_wire, data);
if (pkt_len < length) {
return EMSGSIZE;
}
wire = (struct ctdb_req_call_wire *)pkt;
if (pkt_len < length + wire->keylen + wire->calldatalen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
c->flags = wire->flags;
c->db_id = wire->db_id;
c->callid = wire->callid;
c->hopcount = wire->hopcount;
c->key.dsize = wire->keylen;
c->key.dptr = talloc_memdup(mem_ctx, wire->data, wire->keylen);
if (c->key.dptr == NULL) {
return ENOMEM;
}
c->calldata.dsize = wire->calldatalen;
if (wire->calldatalen > 0) {
c->calldata.dptr = talloc_memdup(mem_ctx,
wire->data + wire->keylen,
wire->calldatalen);
if (c->calldata.dptr == NULL) {
talloc_free(c->key.dptr);
return ENOMEM;
}
}
return 0;
}
int ctdb_reply_call_push(struct ctdb_req_header *h, struct ctdb_reply_call *c,
TALLOC_CTX *mem_ctx, uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_reply_call_wire *wire;
uint8_t *buf;
size_t length, buflen;
int ret;
length = offsetof(struct ctdb_reply_call_wire, data) + c->data.dsize;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_reply_call_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->status = c->status;
wire->datalen = c->data.dsize;
if (c->data.dsize > 0) {
memcpy(wire->data, c->data.dptr, c->data.dsize);
}
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_reply_call_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_call *c)
{
struct ctdb_reply_call_wire *wire;
size_t length;
length = offsetof(struct ctdb_reply_call_wire, data);
if (pkt_len < length) {
return EMSGSIZE;
}
wire = (struct ctdb_reply_call_wire *)pkt;
if (pkt_len < length + wire->datalen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
c->status = wire->status;
c->data.dsize = wire->datalen;
if (wire->datalen > 0) {
c->data.dptr = talloc_memdup(mem_ctx, wire->data,
wire->datalen);
if (c->data.dptr == NULL) {
return ENOMEM;
}
}
return 0;
}
int ctdb_reply_error_push(struct ctdb_req_header *h, struct ctdb_reply_error *c,
TALLOC_CTX *mem_ctx, uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_reply_error_wire *wire;
uint8_t *buf;
size_t length, buflen;
int ret;
length = offsetof(struct ctdb_reply_error_wire, msg) + c->msg.dsize;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_reply_error_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->status = c->status;
wire->msglen = c->msg.dsize;
if (c->msg.dsize > 0) {
memcpy(wire->msg, c->msg.dptr, c->msg.dsize);
}
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_reply_error_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_error *c)
{
struct ctdb_reply_error_wire *wire;
size_t length;
length = offsetof(struct ctdb_reply_error_wire, msg);
if (pkt_len < length) {
return EMSGSIZE;
}
wire = (struct ctdb_reply_error_wire *)pkt;
if (pkt_len < length + wire->msglen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
c->status = wire->status;
c->msg.dsize = wire->msglen;
if (wire->msglen > 0) {
c->msg.dptr = talloc_memdup(mem_ctx, wire->msg, wire->msglen);
if (c->msg.dptr == NULL) {
return ENOMEM;
}
}
return 0;
}
int ctdb_req_dmaster_push(struct ctdb_req_header *h, struct ctdb_req_dmaster *c,
TALLOC_CTX *mem_ctx, uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_req_dmaster_wire *wire;
uint8_t *buf;
size_t length, buflen;
int ret;
length = offsetof(struct ctdb_req_dmaster_wire, data) +
c->key.dsize + c->data.dsize;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_req_dmaster_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->db_id = c->db_id;
wire->rsn = c->rsn;
wire->dmaster = c->dmaster;
wire->keylen = c->key.dsize;
if (c->key.dsize > 0) {
memcpy(wire->data, c->key.dptr, c->key.dsize);
}
wire->datalen = c->data.dsize;
if (c->data.dsize > 0) {
memcpy(wire->data + c->key.dsize, c->data.dptr, c->data.dsize);
}
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_req_dmaster_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_dmaster *c)
{
struct ctdb_req_dmaster_wire *wire;
size_t length;
length = offsetof(struct ctdb_req_dmaster_wire, data);
if (pkt_len < length) {
return EMSGSIZE;
}
wire = (struct ctdb_req_dmaster_wire *)pkt;
if (pkt_len < length + wire->keylen + wire->datalen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
c->db_id = wire->db_id;
c->rsn = wire->rsn;
c->dmaster = wire->dmaster;
c->key.dsize = wire->keylen;
c->key.dptr = talloc_memdup(mem_ctx, wire->data, wire->keylen);
if (c->key.dptr == NULL) {
return ENOMEM;
}
c->data.dsize = wire->datalen;
if (wire->datalen > 0) {
c->data.dptr = talloc_memdup(mem_ctx, wire->data + wire->keylen,
wire->datalen);
if (c->data.dptr == NULL) {
talloc_free(c->key.dptr);
return ENOMEM;
}
}
return 0;
}
int ctdb_reply_dmaster_push(struct ctdb_req_header *h,
struct ctdb_reply_dmaster *c,
TALLOC_CTX *mem_ctx, uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_reply_dmaster_wire *wire;
uint8_t *buf;
size_t length, buflen;
int ret;
length = offsetof(struct ctdb_reply_dmaster_wire, data) +
c->key.dsize + c->data.dsize;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_reply_dmaster_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->db_id = c->db_id;
wire->rsn = c->rsn;
wire->keylen = c->key.dsize;
if (c->key.dsize > 0) {
memcpy(wire->data, c->key.dptr, c->key.dsize);
}
wire->datalen = c->data.dsize;
if (c->data.dsize > 0) {
memcpy(wire->data + c->key.dsize, c->data.dptr, c->data.dsize);
}
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_reply_dmaster_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_reply_dmaster *c)
{
struct ctdb_reply_dmaster_wire *wire;
size_t length;
length = offsetof(struct ctdb_reply_dmaster_wire, data);
if (pkt_len < length) {
return EMSGSIZE;
}
wire = (struct ctdb_reply_dmaster_wire *)pkt;
if (pkt_len < length + wire->keylen + wire->datalen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
c->db_id = wire->db_id;
c->rsn = wire->rsn;
c->key.dsize = wire->keylen;
c->key.dptr = talloc_memdup(mem_ctx, wire->data, wire->keylen);
if (c->key.dptr == NULL) {
return ENOMEM;
}
c->data.dsize = wire->datalen;
if (wire->datalen > 0) {
c->data.dptr = talloc_memdup(mem_ctx, wire->data + wire->keylen,
wire->datalen);
if (c->data.dptr == NULL) {
talloc_free(c->key.dptr);
return ENOMEM;
}
}
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
/*
CTDB protocol marshalling
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 "replace.h"
#include "system/network.h"
#include <talloc.h>
#include <tdb.h>
#include "protocol.h"
#include "protocol_api.h"
int ctdb_req_header_verify(struct ctdb_req_header *h, uint32_t operation)
{
if (h->length < sizeof(struct ctdb_req_header)) {
return EMSGSIZE;
}
if (h->ctdb_magic != CTDB_MAGIC) {
return EPROTO;
}
if (h->ctdb_version != CTDB_PROTOCOL) {
return EPROTO;
}
if (operation != 0 && h->operation != operation) {
return EPROTO;
}
return 0;
}
void ctdb_req_header_fill(struct ctdb_req_header *h, uint32_t generation,
uint32_t operation, uint32_t destnode,
uint32_t srcnode, uint32_t reqid)
{
h->length = sizeof(struct ctdb_req_header);
h->ctdb_magic = CTDB_MAGIC;
h->ctdb_version = CTDB_PROTOCOL;
h->generation = generation;
h->operation = operation;
h->destnode = destnode;
h->srcnode = srcnode;
h->reqid = reqid;
}
int ctdb_req_header_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h)
{
if (pkt_len < sizeof(struct ctdb_req_header)) {
return EMSGSIZE;
}
memcpy(h, pkt, sizeof(struct ctdb_req_header));
return 0;
}

View File

@ -0,0 +1,383 @@
/*
CTDB protocol marshalling
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 "replace.h"
#include "system/network.h"
#include <talloc.h>
#include <tdb.h>
#include "protocol.h"
#include "protocol_api.h"
#include "protocol_private.h"
struct ctdb_req_message_wire {
struct ctdb_req_header hdr;
uint64_t srvid;
uint32_t datalen;
uint8_t data[1];
};
static size_t ctdb_message_data_len(union ctdb_message_data *mdata,
uint64_t srvid)
{
size_t len = 0;
switch (srvid) {
case CTDB_SRVID_ELECTION:
len = ctdb_election_message_len(mdata->election);
break;
case CTDB_SRVID_RECONFIGURE:
break;
case CTDB_SRVID_RELEASE_IP:
len = ctdb_string_len(mdata->ipaddr);
break;
case CTDB_SRVID_TAKE_IP:
len = ctdb_string_len(mdata->ipaddr);
break;
case CTDB_SRVID_SET_NODE_FLAGS:
len = ctdb_node_flag_change_len(mdata->flag_change);
break;
case CTDB_SRVID_RECD_UPDATE_IP:
len = ctdb_public_ip_len(mdata->pubip);
break;
case CTDB_SRVID_VACUUM_FETCH:
len = ctdb_rec_buffer_len(mdata->recbuf);
break;
case CTDB_SRVID_DETACH_DATABASE:
len = ctdb_uint32_len(mdata->db_id);
break;
case CTDB_SRVID_MEM_DUMP:
len = ctdb_srvid_message_len(mdata->msg);
break;
case CTDB_SRVID_PUSH_NODE_FLAGS:
len = ctdb_node_flag_change_len(mdata->flag_change);
break;
case CTDB_SRVID_RELOAD_NODES:
break;
case CTDB_SRVID_TAKEOVER_RUN:
len = ctdb_srvid_message_len(mdata->msg);
break;
case CTDB_SRVID_REBALANCE_NODE:
len = ctdb_uint32_len(mdata->pnn);
break;
case CTDB_SRVID_DISABLE_TAKEOVER_RUNS:
len = ctdb_disable_message_len(mdata->disable);
break;
case CTDB_SRVID_DISABLE_RECOVERIES:
len = ctdb_disable_message_len(mdata->disable);
break;
case CTDB_SRVID_DISABLE_IP_CHECK:
len = ctdb_uint32_len(mdata->timeout);
break;
}
return len;
}
static void ctdb_message_data_push(union ctdb_message_data *mdata,
uint64_t srvid, uint8_t *buf)
{
switch (srvid) {
case CTDB_SRVID_ELECTION:
ctdb_election_message_push(mdata->election, buf);
break;
case CTDB_SRVID_RECONFIGURE:
break;
case CTDB_SRVID_RELEASE_IP:
ctdb_string_push(mdata->ipaddr, buf);
break;
case CTDB_SRVID_TAKE_IP:
ctdb_string_push(mdata->ipaddr, buf);
break;
case CTDB_SRVID_SET_NODE_FLAGS:
ctdb_node_flag_change_push(mdata->flag_change, buf);
break;
case CTDB_SRVID_RECD_UPDATE_IP:
ctdb_public_ip_push(mdata->pubip, buf);
break;
case CTDB_SRVID_VACUUM_FETCH:
ctdb_rec_buffer_push(mdata->recbuf, buf);
break;
case CTDB_SRVID_DETACH_DATABASE:
ctdb_uint32_push(mdata->db_id, buf);
break;
case CTDB_SRVID_MEM_DUMP:
ctdb_srvid_message_push(mdata->msg, buf);
break;
case CTDB_SRVID_PUSH_NODE_FLAGS:
ctdb_node_flag_change_push(mdata->flag_change, buf);
break;
case CTDB_SRVID_RELOAD_NODES:
break;
case CTDB_SRVID_TAKEOVER_RUN:
ctdb_srvid_message_push(mdata->msg, buf);
break;
case CTDB_SRVID_REBALANCE_NODE:
ctdb_uint32_push(mdata->pnn, buf);
break;
case CTDB_SRVID_DISABLE_TAKEOVER_RUNS:
ctdb_disable_message_push(mdata->disable, buf);
break;
case CTDB_SRVID_DISABLE_RECOVERIES:
ctdb_disable_message_push(mdata->disable, buf);
break;
case CTDB_SRVID_DISABLE_IP_CHECK:
ctdb_uint32_push(mdata->timeout, buf);
break;
}
}
static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
uint64_t srvid, TALLOC_CTX *mem_ctx,
union ctdb_message_data *mdata)
{
int ret = 0;
switch (srvid) {
case CTDB_SRVID_ELECTION:
ret = ctdb_election_message_pull(buf, buflen, mem_ctx,
&mdata->election);
break;
case CTDB_SRVID_RECONFIGURE:
break;
case CTDB_SRVID_RELEASE_IP:
ret = ctdb_string_pull(buf, buflen, mem_ctx, &mdata->ipaddr);
break;
case CTDB_SRVID_TAKE_IP:
ret = ctdb_string_pull(buf, buflen, mem_ctx, &mdata->ipaddr);
break;
case CTDB_SRVID_SET_NODE_FLAGS:
ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
&mdata->flag_change);
break;
case CTDB_SRVID_RECD_UPDATE_IP:
ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
&mdata->pubip);
break;
case CTDB_SRVID_VACUUM_FETCH:
ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
&mdata->recbuf);
break;
case CTDB_SRVID_DETACH_DATABASE:
ret = ctdb_uint32_pull(buf, buflen, mem_ctx, &mdata->db_id);
break;
case CTDB_SRVID_MEM_DUMP:
ret = ctdb_srvid_message_pull(buf, buflen, mem_ctx,
&mdata->msg);
break;
case CTDB_SRVID_PUSH_NODE_FLAGS:
ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
&mdata->flag_change);
break;
case CTDB_SRVID_RELOAD_NODES:
break;
case CTDB_SRVID_TAKEOVER_RUN:
ret = ctdb_srvid_message_pull(buf, buflen, mem_ctx,
&mdata->msg);
break;
case CTDB_SRVID_REBALANCE_NODE:
ret = ctdb_uint32_pull(buf, buflen, mem_ctx, &mdata->pnn);
break;
case CTDB_SRVID_DISABLE_TAKEOVER_RUNS:
ret = ctdb_disable_message_pull(buf, buflen, mem_ctx,
&mdata->disable);
break;
case CTDB_SRVID_DISABLE_RECOVERIES:
ret = ctdb_disable_message_pull(buf, buflen, mem_ctx,
&mdata->disable);
break;
case CTDB_SRVID_DISABLE_IP_CHECK:
ret = ctdb_uint32_pull(buf, buflen, mem_ctx, &mdata->timeout);
break;
}
return ret;
}
int ctdb_req_message_push(struct ctdb_req_header *h,
struct ctdb_req_message *message,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_req_message_wire *wire;
uint8_t *buf;
size_t length, buflen, datalen;
int ret;
datalen = ctdb_message_data_len(&message->data, message->srvid);
length = offsetof(struct ctdb_req_message_wire, data) + datalen;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_req_message_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->srvid = message->srvid;
wire->datalen = datalen;
ctdb_message_data_push(&message->data, message->srvid, wire->data);
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_req_message_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_message *message)
{
struct ctdb_req_message_wire *wire =
(struct ctdb_req_message_wire *)pkt;
size_t length;
int ret;
length = offsetof(struct ctdb_req_message_wire, data);
if (pkt_len < length) {
return EMSGSIZE;
}
if (pkt_len < length + wire->datalen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
message->srvid = wire->srvid;
ret = ctdb_message_data_pull(wire->data, wire->datalen, wire->srvid,
mem_ctx, &message->data);
return ret;
}
int ctdb_req_message_data_push(struct ctdb_req_header *h,
struct ctdb_req_message_data *message,
TALLOC_CTX *mem_ctx,
uint8_t **pkt, size_t *pkt_len)
{
struct ctdb_req_message_wire *wire;
uint8_t *buf;
size_t length, buflen;
int ret;
length = offsetof(struct ctdb_req_message_wire, data) +
message->data.dsize;
ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
if (ret != 0) {
return ret;
}
wire = (struct ctdb_req_message_wire *)buf;
h->length = buflen;
memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));
wire->srvid = message->srvid;
wire->datalen = message->data.dsize;
if (message->data.dsize > 0) {
memcpy(wire->data, message->data.dptr, message->data.dsize);
}
*pkt = buf;
*pkt_len = buflen;
return 0;
}
int ctdb_req_message_data_pull(uint8_t *pkt, size_t pkt_len,
struct ctdb_req_header *h,
TALLOC_CTX *mem_ctx,
struct ctdb_req_message_data *message)
{
struct ctdb_req_message_wire *wire =
(struct ctdb_req_message_wire *)pkt;
size_t length;
length = offsetof(struct ctdb_req_message_wire, data);
if (pkt_len < length) {
return EMSGSIZE;
}
if (pkt_len < length + wire->datalen) {
return EMSGSIZE;
}
memcpy(h, &wire->hdr, sizeof(struct ctdb_req_header));
message->srvid = wire->srvid;
message->data.dsize = wire->datalen;
if (wire->datalen > 0) {
message->data.dptr = talloc_memdup(mem_ctx, wire->data,
wire->datalen);
if (message->data.dptr == NULL) {
return ENOMEM;
}
}
return 0;
}

View File

@ -0,0 +1,44 @@
/*
CTDB protocol marshalling
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 "replace.h"
#include "system/network.h"
#include <talloc.h>
#include <tdb.h>
#include "protocol_private.h"
#define CTDB_DS_ALIGNMENT 8
int allocate_pkt(TALLOC_CTX *mem_ctx, size_t length,
uint8_t **buf, size_t *buflen)
{
size_t new_length;
new_length = (length + CTDB_DS_ALIGNMENT-1) & ~(CTDB_DS_ALIGNMENT-1);
*buflen = new_length;
*buf = talloc_zero_size(mem_ctx, new_length);
if (*buf == NULL) {
return ENOMEM;
}
return 0;
}

View File

@ -0,0 +1,274 @@
/*
CTDB protocol marshalling
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/>.
*/
#ifndef __PROTOCOL_PRIVATE_H__
#define __PROTOCOL_PRIVATE_H__
#include "protocol.h"
int allocate_pkt(TALLOC_CTX *mem_ctx, size_t length,
uint8_t **buf, size_t *buflen);
size_t ctdb_uint32_len(uint32_t val);
void ctdb_uint32_push(uint32_t val, uint8_t *buf);
int ctdb_uint32_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
uint32_t *out);
size_t ctdb_uint64_len(uint64_t val);
void ctdb_uint64_push(uint64_t val, uint8_t *buf);
int ctdb_uint64_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
uint64_t *out);
size_t ctdb_double_len(double val);
void ctdb_double_push(double val, uint8_t *buf);
int ctdb_double_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
double *out);
size_t ctdb_uint8_array_len(struct ctdb_uint8_array *array);
void ctdb_uint8_array_push(struct ctdb_uint8_array *array, uint8_t *buf);
int ctdb_uint8_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_uint8_array **out);
size_t ctdb_uint64_array_len(struct ctdb_uint64_array *array);
void ctdb_uint64_array_push(struct ctdb_uint64_array *array, uint8_t *buf);
int ctdb_uint64_array_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_uint64_array **out);
size_t ctdb_pid_len(pid_t pid);
void ctdb_pid_push(pid_t pid, uint8_t *buf);
int ctdb_pid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
pid_t *out);
size_t ctdb_string_len(const char *str);
void ctdb_string_push(const char *str, uint8_t *buf);
int ctdb_string_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
const char **out);
size_t ctdb_stringn_len(const char *str);
void ctdb_stringn_push(const char *str, uint8_t *buf);
int ctdb_stringn_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
const char **out);
size_t ctdb_statistics_len(struct ctdb_statistics *stats);
void ctdb_statistics_push(struct ctdb_statistics *stats, uint8_t *buf);
int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_statistics **out);
size_t ctdb_statistics_list_len(struct ctdb_statistics_list *stats_list);
void ctdb_statistics_list_push(struct ctdb_statistics_list *stats_list,
uint8_t *buf);
int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_statistics_list **out);
size_t ctdb_vnn_map_len(struct ctdb_vnn_map *vnnmap);
void ctdb_vnn_map_push(struct ctdb_vnn_map *vnnmap, uint8_t *buf);
int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_vnn_map **out);
size_t ctdb_dbid_map_len(struct ctdb_dbid_map *dbmap);
void ctdb_dbid_map_push(struct ctdb_dbid_map *dbmap, uint8_t *buf);
int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_dbid_map **out);
size_t ctdb_pulldb_len(struct ctdb_pulldb *pulldb);
void ctdb_pulldb_push(struct ctdb_pulldb *pulldb, uint8_t *buf);
int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_pulldb **out);
size_t ctdb_traverse_start_len(struct ctdb_traverse_start *traverse);
void ctdb_traverse_start_push(struct ctdb_traverse_start *traverse,
uint8_t *buf);
int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_traverse_start **out);
size_t ctdb_traverse_all_len(struct ctdb_traverse_all *traverse);
void ctdb_traverse_all_push(struct ctdb_traverse_all *traverse, uint8_t *buf);
int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_traverse_all **out);
size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *traverse);
void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *traverse,
uint8_t *buf);
int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_traverse_start_ext **out);
size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *traverse);
void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *traverse,
uint8_t *buf);
int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_traverse_all_ext **out);
size_t ctdb_sock_addr_len(ctdb_sock_addr *addr);
void ctdb_sock_addr_push(ctdb_sock_addr *addr, uint8_t *buf);
int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
ctdb_sock_addr **out);
size_t ctdb_connection_len(struct ctdb_connection *conn);
void ctdb_connection_push(struct ctdb_connection *conn, uint8_t *buf);
int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_connection **out);
size_t ctdb_tunable_len(struct ctdb_tunable *tunable);
void ctdb_tunable_push(struct ctdb_tunable *tunable, uint8_t *buf);
int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_tunable **out);
size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *flag_change);
void ctdb_node_flag_change_push(struct ctdb_node_flag_change *flag_change,
uint8_t *buf);
int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_node_flag_change **out);
size_t ctdb_var_list_len(struct ctdb_var_list *var_list);
void ctdb_var_list_push(struct ctdb_var_list *var_list, uint8_t *buf);
int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_var_list **out);
size_t ctdb_tunable_list_len(struct ctdb_tunable_list *tun_list);
void ctdb_tunable_list_push(struct ctdb_tunable_list *tun_list, uint8_t *buf);
int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_tunable_list **out);
size_t ctdb_tickle_list_len(struct ctdb_tickle_list *tickles);
void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf);
int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_tickle_list **out);
size_t ctdb_client_id_len(struct ctdb_client_id *cid);
void ctdb_client_id_push(struct ctdb_client_id *cid, uint8_t *buf);
int ctdb_client_id_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_client_id **out);
size_t ctdb_client_id_list_len(struct ctdb_client_id_list *cid_list);
void ctdb_client_id_list_push(struct ctdb_client_id_list *cid_list,
uint8_t *buf);
int ctdb_client_id_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_client_id_list **out);
size_t ctdb_client_id_map_len(struct ctdb_client_id_map *cid_map);
void ctdb_client_id_map_push(struct ctdb_client_id_map *cid_map, uint8_t *buf);
int ctdb_client_id_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_client_id_map **out);
size_t ctdb_addr_info_len(struct ctdb_addr_info *addr_info);
void ctdb_addr_info_push(struct ctdb_addr_info *addr_info, uint8_t *buf);
int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_addr_info **out);
size_t ctdb_transdb_len(struct ctdb_transdb *transdb);
void ctdb_transdb_push(struct ctdb_transdb *transdb, uint8_t *buf);
int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_transdb **out);
size_t ctdb_uptime_len(struct ctdb_uptime *uptime);
void ctdb_uptime_push(struct ctdb_uptime *uptime, uint8_t *buf);
int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_uptime **out);
size_t ctdb_public_ip_len(struct ctdb_public_ip *public_ip);
void ctdb_public_ip_push(struct ctdb_public_ip *public_ip, uint8_t *buf);
int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_public_ip **out);
size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *pubip_list);
void ctdb_public_ip_list_push(struct ctdb_public_ip_list *pubip_list,
uint8_t *buf);
int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_public_ip_list **out);
size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *node);
void ctdb_node_and_flags_push(struct ctdb_node_and_flags *node, uint8_t *buf);
int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_node_and_flags **out);
size_t ctdb_node_map_len(struct ctdb_node_map *nodemap);
void ctdb_node_map_push(struct ctdb_node_map *nodemap, uint8_t *buf);
int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_node_map **out);
size_t ctdb_script_len(struct ctdb_script *script);
void ctdb_script_push(struct ctdb_script *script, uint8_t *buf);
int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_script **out);
size_t ctdb_script_list_len(struct ctdb_script_list *script_list);
void ctdb_script_list_push(struct ctdb_script_list *script_list, uint8_t *buf);
int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_script_list **out);
size_t ctdb_ban_state_len(struct ctdb_ban_state *ban_state);
void ctdb_ban_state_push(struct ctdb_ban_state *ban_state, uint8_t *buf);
int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_ban_state **out);
size_t ctdb_db_priority_len(struct ctdb_db_priority *db_prio);
void ctdb_db_priority_push(struct ctdb_db_priority *db_prio, uint8_t *buf);
int ctdb_db_priority_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_db_priority **out);
size_t ctdb_notify_data_len(struct ctdb_notify_data *notify);
void ctdb_notify_data_push(struct ctdb_notify_data *notify, uint8_t *buf);
int ctdb_notify_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_notify_data **out);
size_t ctdb_iface_len(struct ctdb_iface *iface);
void ctdb_iface_push(struct ctdb_iface *iface, uint8_t *buf);
int ctdb_iface_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_iface **out);
size_t ctdb_iface_list_len(struct ctdb_iface_list *iface_list);
void ctdb_iface_list_push(struct ctdb_iface_list *iface_list, uint8_t *buf);
int ctdb_iface_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_iface_list **out);
size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *ipinfo);
void ctdb_public_ip_info_push(struct ctdb_public_ip_info *ipinfo, uint8_t *buf);
int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_public_ip_info **out);
size_t ctdb_key_data_len(struct ctdb_key_data *key);
void ctdb_key_data_push(struct ctdb_key_data *key, uint8_t *buf);
int ctdb_key_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_key_data **out);
size_t ctdb_db_statistics_len(struct ctdb_db_statistics *dbstats);
void ctdb_db_statistics_push(struct ctdb_db_statistics *dbstats, void *buf);
int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_db_statistics **out);
size_t ctdb_election_message_len(struct ctdb_election_message *election);
void ctdb_election_message_push(struct ctdb_election_message *election,
uint8_t *buf);
int ctdb_election_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_election_message **out);
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *msg);
void ctdb_srvid_message_push(struct ctdb_srvid_message *msg, uint8_t *buf);
int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_srvid_message **out);
size_t ctdb_disable_message_len(struct ctdb_disable_message *disable);
void ctdb_disable_message_push(struct ctdb_disable_message *disable,
uint8_t *buf);
int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_disable_message **out);
#endif /* __PROTOCOL_PRIVATE_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,114 @@
/*
CTDB protocol marshalling
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 "replace.h"
#include "system/network.h"
#include <talloc.h>
#include <tdb.h>
#include "protocol.h"
#include "protocol_private.h"
#include "protocol_api.h"
static struct {
enum ctdb_runstate runstate;
const char * label;
} runstate_map[] = {
{ CTDB_RUNSTATE_UNKNOWN, "UNKNOWN" },
{ CTDB_RUNSTATE_INIT, "INIT" },
{ CTDB_RUNSTATE_SETUP, "SETUP" },
{ CTDB_RUNSTATE_FIRST_RECOVERY, "FIRST_RECOVERY" },
{ CTDB_RUNSTATE_STARTUP, "STARTUP" },
{ CTDB_RUNSTATE_RUNNING, "RUNNING" },
{ CTDB_RUNSTATE_SHUTDOWN, "SHUTDOWN" },
{ -1, NULL },
};
const char *ctdb_runstate_to_string(enum ctdb_runstate runstate)
{
int i;
for (i=0; runstate_map[i].label != NULL; i++) {
if (runstate_map[i].runstate == runstate) {
return runstate_map[i].label;
}
}
return runstate_map[0].label;
}
enum ctdb_runstate ctdb_runstate_from_string(const char *runstate_str)
{
int i;
for (i=0; runstate_map[i].label != NULL; i++) {
if (strcasecmp(runstate_map[i].label,
runstate_str) == 0) {
return runstate_map[i].runstate;
}
}
return CTDB_RUNSTATE_UNKNOWN;
}
static struct {
enum ctdb_event event;
const char *label;
} event_map[] = {
{ CTDB_EVENT_INIT, "init" },
{ CTDB_EVENT_SETUP, "setup" },
{ CTDB_EVENT_STARTUP, "startup" },
{ CTDB_EVENT_START_RECOVERY, "startrecovery" },
{ CTDB_EVENT_RECOVERED, "recovered" },
{ CTDB_EVENT_TAKE_IP, "takeip" },
{ CTDB_EVENT_RELEASE_IP, "releaseip" },
{ CTDB_EVENT_MONITOR, "monitor" },
{ CTDB_EVENT_SHUTDOWN, "shutdown" },
{ CTDB_EVENT_UPDATE_IP, "updateip" },
{ CTDB_EVENT_IPREALLOCATED, "ipreallocated" },
{ CTDB_EVENT_MAX, "all" },
{ -1, NULL },
};
const char *ctdb_event_to_string(enum ctdb_event event)
{
int i;
for (i=0; event_map[i].label != NULL; i++) {
if (event_map[i].event == event) {
return event_map[i].label;
}
}
return "unknown";
}
enum ctdb_event ctdb_event_from_string(const char *event_str)
{
int i;
for (i=0; event_map[i].label != NULL; i++) {
if (strcmp(event_map[i].label, event_str) == 0) {
return event_map[i].event;
}
}
return CTDB_EVENT_MAX;
}

View File

@ -0,0 +1,9 @@
#!/bin/sh
. "${TEST_SCRIPTS_DIR}/unit.sh"
ok_null
for i in $(seq 1 1000) ; do
unit_test protocol_types_test $i
done

View File

@ -0,0 +1,36 @@
#!/bin/sh
. "${TEST_SCRIPTS_DIR}/unit.sh"
last_control=140
control_output=$(
for i in $(seq 0 $last_control) ; do
echo -n "$i.. "
done
echo
)
output=$(
echo "ctdb_req_header"
echo "ctdb_req_call"
echo "ctdb_reply_call"
echo "ctdb_reply_error"
echo "ctdb_req_dmaster"
echo "ctdb_reply_dmaster"
echo "ctdb_req_control_data"
echo "$control_output"
echo "ctdb_reply_control_data"
echo "$control_output"
echo "ctdb_req_control"
echo "$control_output"
echo "ctdb_reply_control"
echo "$control_output"
echo "ctdb_req_message"
)
ok "$output"
for i in $(seq 1 100) ; do
unit_test protocol_client_test $i
done

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -340,6 +340,17 @@ def build(bld):
logging.c'''), logging.c'''),
deps='replace talloc tevent tdb tevent-unix-util') deps='replace talloc tevent tdb tevent-unix-util')
bld.SAMBA_SUBSYSTEM('ctdb-protocol',
source=bld.SUBDIR('protocol',
'''protocol_header.c protocol_packet.c
protocol_types.c protocol_call.c
protocol_message.c
protocol_control.c
protocol_client.c
protocol_util.c'''),
includes='include',
deps='replace talloc tdb')
bld.SAMBA_SUBSYSTEM('ctdb-client', bld.SAMBA_SUBSYSTEM('ctdb-client',
source=bld.SUBDIR('client', 'ctdb_client.c'), source=bld.SUBDIR('client', 'ctdb_client.c'),
includes='include include/internal', includes='include include/internal',
@ -584,6 +595,8 @@ def build(bld):
'comm_test', 'comm_test',
'comm_server_test', 'comm_server_test',
'comm_client_test', 'comm_client_test',
'protocol_types_test',
'protocol_client_test',
] ]
for target in ctdb_unit_tests: for target in ctdb_unit_tests: