summaryrefslogtreecommitdiffstats
path: root/ctdb/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'ctdb/protocol')
-rw-r--r--ctdb/protocol/protocol.h1074
-rw-r--r--ctdb/protocol/protocol_api.h682
-rw-r--r--ctdb/protocol/protocol_basic.c400
-rw-r--r--ctdb/protocol/protocol_basic.h86
-rw-r--r--ctdb/protocol/protocol_call.c581
-rw-r--r--ctdb/protocol/protocol_client.c2352
-rw-r--r--ctdb/protocol/protocol_control.c1998
-rw-r--r--ctdb/protocol/protocol_debug.c742
-rw-r--r--ctdb/protocol/protocol_header.c169
-rw-r--r--ctdb/protocol/protocol_keepalive.c95
-rw-r--r--ctdb/protocol/protocol_message.c476
-rw-r--r--ctdb/protocol/protocol_packet.c48
-rw-r--r--ctdb/protocol/protocol_private.h300
-rw-r--r--ctdb/protocol/protocol_sock.c81
-rw-r--r--ctdb/protocol/protocol_tunnel.c114
-rw-r--r--ctdb/protocol/protocol_types.c5348
-rw-r--r--ctdb/protocol/protocol_util.c755
-rw-r--r--ctdb/protocol/protocol_util.h80
18 files changed, 15381 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol.h b/ctdb/protocol/protocol.h
new file mode 100644
index 0000000..fb6e39f
--- /dev/null
+++ b/ctdb/protocol/protocol.h
@@ -0,0 +1,1074 @@
+/*
+ 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_H__
+#define __CTDB_PROTOCOL_H__
+
+#include <tdb.h>
+
+#define CTDB_MAGIC 0x43544442 /* CTDB */
+#define CTDB_PROTOCOL 1
+
+enum ctdb_operation {
+ CTDB_REQ_CALL = 0,
+ CTDB_REPLY_CALL = 1,
+ CTDB_REQ_DMASTER = 2,
+ CTDB_REPLY_DMASTER = 3,
+ CTDB_REPLY_ERROR = 4,
+ CTDB_REQ_MESSAGE = 5,
+ /* #6 removed */
+ CTDB_REQ_CONTROL = 7,
+ CTDB_REPLY_CONTROL = 8,
+ CTDB_REQ_KEEPALIVE = 9,
+ CTDB_REQ_TUNNEL = 10,
+};
+
+/* used on the domain socket, send a pdu to the local daemon */
+#define CTDB_CURRENT_NODE 0xF0000001
+/* send a broadcast to all nodes in the cluster, active or not */
+#define CTDB_BROADCAST_ALL 0xF0000002
+/* send a broadcast to all nodes in the current vnn map */
+#define CTDB_BROADCAST_ACTIVE 0xF0000003
+/* send a broadcast to all connected nodes */
+#define CTDB_BROADCAST_CONNECTED 0xF0000004
+/* send a broadcast to selected connected nodes */
+#define CTDB_MULTICAST 0xF0000005
+
+#define CTDB_UNKNOWN_PNN 0xFFFFFFFF
+
+/* the key used to store persistent db sequence number */
+#define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
+
+struct ctdb_req_header {
+ uint32_t length;
+ uint32_t ctdb_magic;
+ uint32_t ctdb_version;
+ uint32_t generation;
+ uint32_t operation;
+ uint32_t destnode;
+ uint32_t srcnode;
+ uint32_t reqid;
+};
+
+struct ctdb_req_call {
+ uint32_t flags;
+ uint32_t db_id;
+ uint32_t callid;
+ uint32_t hopcount;
+ TDB_DATA key;
+ TDB_DATA calldata;
+};
+
+struct ctdb_reply_call {
+ int32_t status;
+ TDB_DATA data;
+};
+
+struct ctdb_reply_error {
+ int32_t status;
+ TDB_DATA msg;
+};
+
+struct ctdb_req_dmaster {
+ uint32_t db_id;
+ uint64_t rsn;
+ uint32_t dmaster;
+ TDB_DATA key;
+ TDB_DATA data;
+};
+
+struct ctdb_reply_dmaster {
+ uint32_t db_id;
+ uint64_t rsn;
+ TDB_DATA key;
+ TDB_DATA data;
+};
+
+#define CTDB_NULL_FUNC 0xFF000001
+#define CTDB_FETCH_FUNC 0xFF000002
+#define CTDB_FETCH_WITH_HEADER_FUNC 0xFF000003
+
+struct ctdb_call {
+ int call_id;
+ TDB_DATA key;
+ TDB_DATA call_data;
+ TDB_DATA reply_data;
+ uint32_t status;
+#define CTDB_IMMEDIATE_MIGRATION 0x00000001
+#define CTDB_CALL_FLAG_VACUUM_MIGRATION 0x00000002
+#define CTDB_WANT_READONLY 0x00000004
+ uint32_t flags;
+};
+
+/* SRVID to catch all messages */
+#define CTDB_SRVID_ALL (~(uint64_t)0)
+
+/* SRVID prefix used during recovery for pulling and pushing databases */
+#define CTDB_SRVID_RECOVERY 0xF001000000000000LL
+
+/* SRVID to assign of banning credits */
+#define CTDB_SRVID_BANNING 0xF002000000000000LL
+
+/* SRVID to inform of election data */
+#define CTDB_SRVID_ELECTION 0xF100000000000000LL
+
+/* SRVID for broadcasting leader */
+#define CTDB_SRVID_LEADER 0xF101000000000000LL
+
+/* SRVID to inform clients that the cluster has been reconfigured */
+#define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
+
+/* SRVID to inform clients an IP address has been released */
+#define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
+
+/* SRVID to inform clients that an IP address has been taken over */
+#define CTDB_SRVID_TAKE_IP 0xF301000000000000LL
+
+/* SRVID to inform recovery daemon of the node flags - OBSOLETE */
+#define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
+
+/* SRVID to inform recovery daemon to update public ip assignment */
+#define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
+
+/* SRVID to inform recovery daemon to migrate a set of records */
+#define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
+
+/* SRVID to inform recovery daemon to detach a database */
+#define CTDB_SRVID_DETACH_DATABASE 0xF701000000000000LL
+
+/* SRVID to inform recovery daemon to dump talloc memdump to the log */
+#define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
+
+/* SRVID to inform recovery daemon to send logs */
+#define CTDB_SRVID_GETLOG 0xF801000000000000LL
+
+/* SRVID to inform recovery daemon to clear logs */
+#define CTDB_SRVID_CLEARLOG 0xF802000000000000LL
+
+/* SRVID to inform recovery daemon to push the node flags to other nodes */
+#define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
+
+/* SRVID to inform recovery daemon to reload the nodes file */
+#define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
+
+/* SRVID to inform recovery daemon to perform a takeover run */
+#define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
+
+/* SRVID to inform recovery daemon to rebalance ips for a node. */
+#define CTDB_SRVID_REBALANCE_NODE 0xFB01000000000000LL
+
+/* SRVID to inform recovery daemon to stop takeover runs from occurring */
+#define CTDB_SRVID_DISABLE_TAKEOVER_RUNS 0xFB03000000000000LL
+
+/* SRVID to inform recovery daemon to stop recoveries from occurring */
+#define CTDB_SRVID_DISABLE_RECOVERIES 0xFB04000000000000LL
+
+/* SRVID to inform recovery daemon to disable the public ip checks */
+#define CTDB_SRVID_DISABLE_IP_CHECK 0xFC00000000000000LL
+
+/* A range of ports reserved for registering a PID (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * registering a SRVID that matches the process-id of the requesting process
+ */
+#define CTDB_SRVID_PID_RANGE 0x0000000000000000LL
+
+/* A range of ports reserved for samba (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * CIFS server
+ */
+#define CTDB_SRVID_SAMBA_NOTIFY 0xFE00000000000000LL
+#define CTDB_SRVID_SAMBA_RANGE 0xFE00000000000000LL
+
+/* A range of ports reserved for a CTDB NFS server (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * NFS server
+ */
+#define CTDB_SRVID_NFSD_RANGE 0xEE00000000000000LL
+
+/* A range of ports reserved for a CTDB ISCSI server (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * ISCSI server
+ */
+#define CTDB_SRVID_ISCSID_RANGE 0xDE00000000000000LL
+
+/* A range of ports reserved for CTDB tool (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * CTDB tool
+ */
+#define CTDB_SRVID_TOOL_RANGE 0xCE00000000000000LL
+
+/* A range of ports reserved by client (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * CTDB client code
+ */
+#define CTDB_SRVID_CLIENT_RANGE 0xBE00000000000000LL
+
+/* Range of ports reserved for test applications (top 8 bits)
+ * All ports matching the 8 top bits are reserved for exclusive use by
+ * test applications
+ */
+#define CTDB_SRVID_TEST_RANGE 0xAE00000000000000LL
+
+
+enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
+ CTDB_CONTROL_STATISTICS = 1,
+ /* #2 removed */
+ CTDB_CONTROL_PING = 3,
+ CTDB_CONTROL_GETDBPATH = 4,
+ CTDB_CONTROL_GETVNNMAP = 5,
+ CTDB_CONTROL_SETVNNMAP = 6,
+ CTDB_CONTROL_GET_DEBUG = 7,
+ CTDB_CONTROL_SET_DEBUG = 8,
+ CTDB_CONTROL_GET_DBMAP = 9,
+ CTDB_CONTROL_GET_NODEMAPv4 = 10, /* obsolete */
+ CTDB_CONTROL_SET_DMASTER = 11, /* obsolete */
+ /* #12 removed */
+ CTDB_CONTROL_PULL_DB = 13, /* obsolete */
+ CTDB_CONTROL_PUSH_DB = 14, /* obsolete */
+ CTDB_CONTROL_GET_RECMODE = 15,
+ CTDB_CONTROL_SET_RECMODE = 16,
+ CTDB_CONTROL_STATISTICS_RESET = 17,
+ CTDB_CONTROL_DB_ATTACH = 18,
+ CTDB_CONTROL_SET_CALL = 19, /* obsolete */
+ CTDB_CONTROL_TRAVERSE_START = 20,
+ CTDB_CONTROL_TRAVERSE_ALL = 21,
+ CTDB_CONTROL_TRAVERSE_DATA = 22,
+ CTDB_CONTROL_REGISTER_SRVID = 23,
+ CTDB_CONTROL_DEREGISTER_SRVID = 24,
+ CTDB_CONTROL_GET_DBNAME = 25,
+ CTDB_CONTROL_ENABLE_SEQNUM = 26,
+ CTDB_CONTROL_UPDATE_SEQNUM = 27,
+ /* #28 removed */
+ CTDB_CONTROL_DUMP_MEMORY = 29,
+ CTDB_CONTROL_GET_PID = 30,
+ CTDB_CONTROL_GET_RECMASTER = 31, /* obsolete */
+ CTDB_CONTROL_SET_RECMASTER = 32, /* obsolete */
+ CTDB_CONTROL_FREEZE = 33,
+ CTDB_CONTROL_THAW = 34, /* obsolete */
+ CTDB_CONTROL_GET_PNN = 35,
+ CTDB_CONTROL_SHUTDOWN = 36,
+ CTDB_CONTROL_GET_MONMODE = 37, /* obsolete */
+ /* #38 removed */
+ /* #39 removed */
+ /* #40 removed */
+ /* #41 removed */
+ CTDB_CONTROL_TAKEOVER_IPv4 = 42, /* obsolete */
+ CTDB_CONTROL_RELEASE_IPv4 = 43, /* obsolete */
+ CTDB_CONTROL_TCP_CLIENT = 44,
+ CTDB_CONTROL_TCP_ADD = 45,
+ CTDB_CONTROL_TCP_REMOVE = 46,
+ CTDB_CONTROL_STARTUP = 47,
+ CTDB_CONTROL_SET_TUNABLE = 48,
+ CTDB_CONTROL_GET_TUNABLE = 49,
+ CTDB_CONTROL_LIST_TUNABLES = 50,
+ CTDB_CONTROL_GET_PUBLIC_IPSv4 = 51, /* obsolete */
+ CTDB_CONTROL_MODIFY_FLAGS = 52,
+ CTDB_CONTROL_GET_ALL_TUNABLES = 53,
+ CTDB_CONTROL_KILL_TCP = 54, /* obsolete */
+ CTDB_CONTROL_GET_TCP_TICKLE_LIST = 55,
+ CTDB_CONTROL_SET_TCP_TICKLE_LIST = 56,
+ CTDB_CONTROL_REGISTER_SERVER_ID = 57, /* obsolete */
+ CTDB_CONTROL_UNREGISTER_SERVER_ID = 58, /* obsolete */
+ CTDB_CONTROL_CHECK_SERVER_ID = 59, /* obsolete */
+ CTDB_CONTROL_GET_SERVER_ID_LIST = 60, /* obsolete */
+ CTDB_CONTROL_DB_ATTACH_PERSISTENT = 61,
+ CTDB_CONTROL_PERSISTENT_STORE = 62, /* obsolete */
+ CTDB_CONTROL_UPDATE_RECORD = 63,
+ CTDB_CONTROL_SEND_GRATUITOUS_ARP = 64,
+ CTDB_CONTROL_TRANSACTION_START = 65, /* obsolete */
+ CTDB_CONTROL_TRANSACTION_COMMIT = 66, /* obsolete */
+ CTDB_CONTROL_WIPE_DATABASE = 67,
+ /* #68 removed */
+ CTDB_CONTROL_UPTIME = 69,
+ CTDB_CONTROL_START_RECOVERY = 70,
+ CTDB_CONTROL_END_RECOVERY = 71,
+ CTDB_CONTROL_RELOAD_NODES_FILE = 72,
+ /* #73 removed */
+ CTDB_CONTROL_TRY_DELETE_RECORDS = 74,
+ CTDB_CONTROL_ENABLE_MONITOR = 75, /* obsolete */
+ CTDB_CONTROL_DISABLE_MONITOR = 76, /* obsolete */
+ CTDB_CONTROL_ADD_PUBLIC_IP = 77,
+ CTDB_CONTROL_DEL_PUBLIC_IP = 78,
+ CTDB_CONTROL_RUN_EVENTSCRIPTS = 79, /* obsolete */
+ CTDB_CONTROL_GET_CAPABILITIES = 80,
+ CTDB_CONTROL_START_PERSISTENT_UPDATE = 81, /* obsolete */
+ CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82, /* obsolete */
+ CTDB_CONTROL_TRANS2_COMMIT = 83, /* obsolete */
+ CTDB_CONTROL_TRANS2_FINISHED = 84, /* obsolete */
+ CTDB_CONTROL_TRANS2_ERROR = 85, /* obsolete */
+ CTDB_CONTROL_TRANS2_COMMIT_RETRY = 86, /* obsolete */
+ CTDB_CONTROL_RECD_PING = 87,
+ CTDB_CONTROL_RELEASE_IP = 88,
+ CTDB_CONTROL_TAKEOVER_IP = 89,
+ CTDB_CONTROL_GET_PUBLIC_IPS = 90,
+ CTDB_CONTROL_GET_NODEMAP = 91,
+ /* missing */
+ CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96, /* obsolete */
+ CTDB_CONTROL_TRAVERSE_KILL = 97,
+ CTDB_CONTROL_RECD_RECLOCK_LATENCY = 98,
+ CTDB_CONTROL_GET_RECLOCK_FILE = 99,
+ CTDB_CONTROL_SET_RECLOCK_FILE = 100, /* obsolete */
+ CTDB_CONTROL_STOP_NODE = 101,
+ CTDB_CONTROL_CONTINUE_NODE = 102,
+ CTDB_CONTROL_SET_NATGWSTATE = 103, /* obsolete */
+ CTDB_CONTROL_SET_LMASTERROLE = 104,
+ CTDB_CONTROL_SET_RECMASTERROLE = 105,
+ CTDB_CONTROL_ENABLE_SCRIPT = 107, /* obsolete */
+ CTDB_CONTROL_DISABLE_SCRIPT = 108, /* obsolete */
+ CTDB_CONTROL_SET_BAN_STATE = 109,
+ CTDB_CONTROL_GET_BAN_STATE = 110,
+ CTDB_CONTROL_SET_DB_PRIORITY = 111, /* obsolete */
+ CTDB_CONTROL_GET_DB_PRIORITY = 112, /* obsolete */
+ CTDB_CONTROL_TRANSACTION_CANCEL = 113, /* obsolete */
+ CTDB_CONTROL_REGISTER_NOTIFY = 114,
+ CTDB_CONTROL_DEREGISTER_NOTIFY = 115,
+ CTDB_CONTROL_TRANS2_ACTIVE = 116, /* obsolete */
+ CTDB_CONTROL_GET_LOG = 117, /* obsolete */
+ CTDB_CONTROL_CLEAR_LOG = 118, /* obsolete */
+ CTDB_CONTROL_TRANS3_COMMIT = 119,
+ CTDB_CONTROL_GET_DB_SEQNUM = 120,
+ CTDB_CONTROL_DB_SET_HEALTHY = 121,
+ CTDB_CONTROL_DB_GET_HEALTH = 122,
+ CTDB_CONTROL_GET_PUBLIC_IP_INFO = 123,
+ CTDB_CONTROL_GET_IFACES = 124,
+ CTDB_CONTROL_SET_IFACE_LINK_STATE = 125,
+ CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE = 126,
+ CTDB_CONTROL_GET_STAT_HISTORY = 127,
+ CTDB_CONTROL_SCHEDULE_FOR_DELETION = 128,
+ CTDB_CONTROL_SET_DB_READONLY = 129,
+ CTDB_CONTROL_CHECK_SRVIDS = 130, /* obsolete */
+ CTDB_CONTROL_TRAVERSE_START_EXT = 131,
+ CTDB_CONTROL_GET_DB_STATISTICS = 132,
+ CTDB_CONTROL_SET_DB_STICKY = 133,
+ CTDB_CONTROL_RELOAD_PUBLIC_IPS = 134,
+ CTDB_CONTROL_TRAVERSE_ALL_EXT = 135,
+ CTDB_CONTROL_RECEIVE_RECORDS = 136, /* obsolete */
+ CTDB_CONTROL_IPREALLOCATED = 137,
+ CTDB_CONTROL_GET_RUNSTATE = 138,
+ CTDB_CONTROL_DB_DETACH = 139,
+ CTDB_CONTROL_GET_NODES_FILE = 140,
+ CTDB_CONTROL_DB_FREEZE = 141,
+ CTDB_CONTROL_DB_THAW = 142,
+ CTDB_CONTROL_DB_TRANSACTION_START = 143,
+ CTDB_CONTROL_DB_TRANSACTION_COMMIT = 144,
+ CTDB_CONTROL_DB_TRANSACTION_CANCEL = 145,
+ CTDB_CONTROL_DB_PULL = 146,
+ CTDB_CONTROL_DB_PUSH_START = 147,
+ CTDB_CONTROL_DB_PUSH_CONFIRM = 148,
+ CTDB_CONTROL_DB_OPEN_FLAGS = 149,
+ CTDB_CONTROL_DB_ATTACH_REPLICATED = 150,
+ CTDB_CONTROL_CHECK_PID_SRVID = 151,
+ CTDB_CONTROL_TUNNEL_REGISTER = 152,
+ CTDB_CONTROL_TUNNEL_DEREGISTER = 153,
+ CTDB_CONTROL_VACUUM_FETCH = 154,
+ CTDB_CONTROL_DB_VACUUM = 155,
+ CTDB_CONTROL_ECHO_DATA = 156,
+ CTDB_CONTROL_DISABLE_NODE = 157,
+ CTDB_CONTROL_ENABLE_NODE = 158,
+};
+
+#define MAX_COUNT_BUCKETS 16
+#define MAX_HOT_KEYS 10
+
+struct ctdb_latency_counter {
+ int num;
+ double min;
+ double max;
+ double total;
+};
+
+struct ctdb_statistics {
+ uint32_t num_clients;
+ uint32_t frozen;
+ uint32_t recovering;
+ uint32_t client_packets_sent;
+ uint32_t client_packets_recv;
+ uint32_t node_packets_sent;
+ uint32_t node_packets_recv;
+ uint32_t keepalive_packets_sent;
+ uint32_t keepalive_packets_recv;
+ struct {
+ uint32_t req_call;
+ uint32_t reply_call;
+ uint32_t req_dmaster;
+ uint32_t reply_dmaster;
+ uint32_t reply_error;
+ uint32_t req_message;
+ uint32_t req_control;
+ uint32_t reply_control;
+ uint32_t req_tunnel;
+ } node;
+ struct {
+ uint32_t req_call;
+ uint32_t req_message;
+ uint32_t req_control;
+ uint32_t req_tunnel;
+ } client;
+ struct {
+ uint32_t call;
+ uint32_t control;
+ uint32_t traverse;
+ } timeouts;
+ struct {
+ struct ctdb_latency_counter ctdbd;
+ struct ctdb_latency_counter recd;
+ } reclock;
+ struct {
+ uint32_t num_calls;
+ uint32_t num_current;
+ uint32_t num_pending;
+ uint32_t num_failed;
+ struct ctdb_latency_counter latency;
+ uint32_t buckets[MAX_COUNT_BUCKETS];
+ } locks;
+ uint32_t total_calls;
+ uint32_t pending_calls;
+ uint32_t childwrite_calls;
+ uint32_t pending_childwrite_calls;
+ uint32_t memory_used;
+ uint32_t __last_counter; /* hack */
+ uint32_t max_hop_count;
+ uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
+ struct ctdb_latency_counter call_latency;
+ struct ctdb_latency_counter childwrite_latency;
+ uint32_t num_recoveries;
+ struct timeval statistics_start_time;
+ struct timeval statistics_current_time;
+ uint32_t total_ro_delegations;
+ uint32_t total_ro_revokes;
+};
+
+#define INVALID_GENERATION 1
+/* table that contains the mapping between a hash value and lmaster
+ */
+struct ctdb_vnn_map {
+ uint32_t generation;
+ uint32_t size;
+ uint32_t *map;
+};
+
+struct ctdb_dbid {
+ uint32_t db_id;
+#define CTDB_DB_FLAGS_PERSISTENT 0x01
+#define CTDB_DB_FLAGS_READONLY 0x02
+#define CTDB_DB_FLAGS_STICKY 0x04
+#define CTDB_DB_FLAGS_REPLICATED 0x08
+ uint8_t flags;
+};
+
+struct ctdb_dbid_map {
+ uint32_t num;
+ struct ctdb_dbid *dbs;
+};
+
+struct ctdb_pulldb {
+ uint32_t db_id;
+#define CTDB_LMASTER_ANY 0xffffffff
+ uint32_t lmaster;
+};
+
+struct ctdb_pulldb_ext {
+ uint32_t db_id;
+ uint32_t lmaster;
+ uint64_t srvid;
+};
+
+#define CTDB_RECOVERY_NORMAL 0
+#define CTDB_RECOVERY_ACTIVE 1
+
+/*
+ the extended header for records in the ltdb
+*/
+struct ctdb_ltdb_header {
+ uint64_t rsn;
+ uint32_t dmaster;
+ uint32_t reserved1;
+#define CTDB_REC_FLAG_DEFAULT 0x00000000
+#define CTDB_REC_FLAG_MIGRATED_WITH_DATA 0x00010000
+#define CTDB_REC_FLAG_VACUUM_MIGRATED 0x00020000
+#define CTDB_REC_FLAG_AUTOMATIC 0x00040000
+#define CTDB_REC_RO_HAVE_DELEGATIONS 0x01000000
+#define CTDB_REC_RO_HAVE_READONLY 0x02000000
+#define CTDB_REC_RO_REVOKING_READONLY 0x04000000
+#define CTDB_REC_RO_REVOKE_COMPLETE 0x08000000
+#define CTDB_REC_RO_FLAGS (CTDB_REC_RO_HAVE_DELEGATIONS|\
+ CTDB_REC_RO_HAVE_READONLY|\
+ CTDB_REC_RO_REVOKING_READONLY|\
+ CTDB_REC_RO_REVOKE_COMPLETE)
+ uint32_t flags;
+};
+
+struct ctdb_rec_data {
+ uint32_t reqid;
+ struct ctdb_ltdb_header *header;
+ TDB_DATA key, data;
+};
+
+struct ctdb_rec_buffer {
+ uint32_t db_id;
+ uint32_t count;
+ uint8_t *buf;
+ size_t buflen;
+};
+
+typedef int (*ctdb_rec_parser_func_t)(uint32_t reqid,
+ struct ctdb_ltdb_header *header,
+ TDB_DATA key, TDB_DATA data,
+ void *private_data);
+
+struct ctdb_traverse_start {
+ uint32_t db_id;
+ uint32_t reqid;
+ uint64_t srvid;
+};
+
+struct ctdb_traverse_all {
+ uint32_t db_id;
+ uint32_t reqid;
+ uint32_t pnn;
+ uint32_t client_reqid;
+ uint64_t srvid;
+};
+
+struct ctdb_traverse_start_ext {
+ uint32_t db_id;
+ uint32_t reqid;
+ uint64_t srvid;
+ bool withemptyrecords;
+};
+
+struct ctdb_traverse_all_ext {
+ uint32_t db_id;
+ uint32_t reqid;
+ uint32_t pnn;
+ uint32_t client_reqid;
+ uint64_t srvid;
+ bool withemptyrecords;
+};
+
+typedef union {
+ struct sockaddr sa;
+ struct sockaddr_in ip;
+ struct sockaddr_in6 ip6;
+} ctdb_sock_addr;
+
+struct ctdb_connection {
+ union {
+ ctdb_sock_addr src;
+ ctdb_sock_addr server;
+ };
+ union {
+ ctdb_sock_addr dst;
+ ctdb_sock_addr client;
+ };
+};
+
+struct ctdb_connection_list {
+ uint32_t num;
+ struct ctdb_connection *conn;
+};
+
+struct ctdb_tunable {
+ const char *name;
+ uint32_t value;
+};
+
+struct ctdb_var_list {
+ int count;
+ const char **var;
+};
+
+struct ctdb_node_flag_change {
+ uint32_t pnn;
+ uint32_t new_flags;
+ uint32_t old_flags;
+};
+
+/* all tunable variables go in here */
+struct ctdb_tunable_list {
+ uint32_t max_redirect_count;
+ uint32_t seqnum_interval; /* unit is ms */
+ uint32_t control_timeout;
+ uint32_t traverse_timeout;
+ uint32_t keepalive_interval;
+ uint32_t keepalive_limit;
+ uint32_t recover_timeout;
+ uint32_t recover_interval;
+ uint32_t election_timeout;
+ uint32_t takeover_timeout;
+ uint32_t monitor_interval;
+ uint32_t tickle_update_interval;
+ uint32_t script_timeout;
+ uint32_t monitor_timeout_count; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
+ uint32_t script_unhealthy_on_timeout; /* obsolete */
+ uint32_t recovery_grace_period;
+ uint32_t recovery_ban_period;
+ uint32_t database_hash_size;
+ uint32_t database_max_dead;
+ uint32_t rerecovery_timeout;
+ uint32_t enable_bans;
+ uint32_t deterministic_public_ips;
+ uint32_t reclock_ping_period;
+ uint32_t no_ip_failback;
+ uint32_t disable_ip_failover;
+ uint32_t verbose_memory_names;
+ uint32_t recd_ping_timeout;
+ uint32_t recd_ping_failcount;
+ uint32_t log_latency_ms;
+ uint32_t reclock_latency_ms;
+ uint32_t recovery_drop_all_ips;
+ uint32_t verify_recovery_lock;
+ uint32_t vacuum_interval;
+ uint32_t vacuum_max_run_time;
+ uint32_t repack_limit;
+ uint32_t vacuum_limit;
+ uint32_t max_queue_depth_drop_msg;
+ uint32_t allow_unhealthy_db_read;
+ uint32_t stat_history_interval;
+ uint32_t deferred_attach_timeout;
+ uint32_t vacuum_fast_path_count;
+ uint32_t lcp2_public_ip_assignment;
+ uint32_t allow_client_db_attach;
+ uint32_t recover_pdb_by_seqnum;
+ uint32_t deferred_rebalance_on_node_add;
+ uint32_t fetch_collapse;
+ uint32_t hopcount_make_sticky;
+ uint32_t sticky_duration;
+ uint32_t sticky_pindown;
+ uint32_t no_ip_takeover;
+ uint32_t db_record_count_warn;
+ uint32_t db_record_size_warn;
+ uint32_t db_size_warn;
+ uint32_t pulldb_preallocation_size;
+ uint32_t no_ip_host_on_all_disabled;
+ uint32_t samba3_hack;
+ uint32_t mutex_enabled;
+ uint32_t lock_processes_per_db;
+ uint32_t rec_buffer_size_limit;
+ uint32_t queue_buffer_size;
+ uint32_t ip_alloc_algorithm;
+ uint32_t allow_mixed_versions;
+};
+
+struct ctdb_tickle_list {
+ ctdb_sock_addr addr;
+ uint32_t num;
+ struct ctdb_connection *conn;
+};
+
+struct ctdb_addr_info {
+ ctdb_sock_addr addr;
+ uint32_t mask;
+ const char *iface;
+};
+
+struct ctdb_transdb {
+ uint32_t db_id;
+ uint32_t tid;
+};
+
+struct ctdb_uptime {
+ struct timeval current_time;
+ struct timeval ctdbd_start_time;
+ struct timeval last_recovery_started;
+ struct timeval last_recovery_finished;
+};
+
+struct ctdb_public_ip {
+ uint32_t pnn;
+ ctdb_sock_addr addr;
+};
+
+struct ctdb_public_ip_list {
+ uint32_t num;
+ struct ctdb_public_ip *ip;
+};
+
+/*
+ * Node flags
+ */
+#define NODE_FLAGS_DISCONNECTED 0x00000001 /* node isn't connected */
+#define NODE_FLAGS_UNHEALTHY 0x00000002 /* monitoring says node is unhealthy */
+#define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
+#define NODE_FLAGS_BANNED 0x00000008 /* recovery daemon has banned the node */
+#define NODE_FLAGS_DELETED 0x00000010 /* this node has been deleted */
+#define NODE_FLAGS_STOPPED 0x00000020 /* this node has been stopped */
+#define NODE_FLAGS_DISABLED (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
+#define NODE_FLAGS_INACTIVE (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)
+
+/*
+ * Node capabilities
+ */
+#define CTDB_CAP_RECMASTER 0x00000001
+#define CTDB_CAP_LMASTER 0x00000002
+#define CTDB_CAP_LVS 0x00000004 /* obsolete */
+#define CTDB_CAP_NATGW 0x00000008 /* obsolete */
+
+/*
+ * Node features
+ */
+#define CTDB_CAP_PARALLEL_RECOVERY 0x00010000
+#define CTDB_CAP_FRAGMENTED_CONTROLS 0x00020000
+
+#define CTDB_CAP_FEATURES (CTDB_CAP_PARALLEL_RECOVERY | \
+ CTDB_CAP_FRAGMENTED_CONTROLS)
+
+#define CTDB_CAP_DEFAULT (CTDB_CAP_RECMASTER | \
+ CTDB_CAP_LMASTER | \
+ CTDB_CAP_FEATURES)
+
+struct ctdb_node_and_flags {
+ uint32_t pnn;
+ uint32_t flags;
+ ctdb_sock_addr addr;
+};
+
+struct ctdb_node_map {
+ uint32_t num;
+ struct ctdb_node_and_flags *node;
+};
+
+enum ctdb_event {
+ CTDB_EVENT_INIT, /* CTDB starting up: no args */
+ CTDB_EVENT_SETUP, /* CTDB starting up after transport is readdy: no args. */
+ CTDB_EVENT_STARTUP, /* CTDB starting up after initial recovery: no args. */
+ CTDB_EVENT_START_RECOVERY, /* CTDB recovery starting: no args. */
+ CTDB_EVENT_RECOVERED, /* CTDB recovery finished: no args. */
+ CTDB_EVENT_TAKE_IP, /* IP taken: interface, IP address, netmask bits. */
+ CTDB_EVENT_RELEASE_IP, /* IP released: interface, IP address, netmask bits. */
+ CTDB_EVENT_STOPPED, /* Deprecated, do not use. */
+ CTDB_EVENT_MONITOR, /* Please check if service is healthy: no args. */
+ CTDB_EVENT_STATUS, /* Deprecated, do not use. */
+ CTDB_EVENT_SHUTDOWN, /* CTDB shutting down: no args. */
+ CTDB_EVENT_RELOAD, /* Deprecated, do not use */
+ CTDB_EVENT_UPDATE_IP, /* IP updating: old interface, new interface, IP address, netmask bits. */
+ CTDB_EVENT_IPREALLOCATED, /* when a takeover_run() completes */
+ CTDB_EVENT_MAX
+};
+
+#define MAX_SCRIPT_NAME 31
+#define MAX_SCRIPT_OUTPUT 511
+
+struct ctdb_script {
+ char name[MAX_SCRIPT_NAME+1];
+ struct timeval start;
+ struct timeval finished;
+ int32_t status;
+ char output[MAX_SCRIPT_OUTPUT+1];
+};
+
+struct ctdb_script_list {
+ uint32_t num_scripts;
+ struct ctdb_script *script;
+};
+
+struct ctdb_ban_state {
+ uint32_t pnn;
+ uint32_t time;
+};
+
+struct ctdb_notify_data {
+ uint64_t srvid;
+ TDB_DATA data;
+};
+
+#ifdef IFNAMSIZ
+#define CTDB_IFACE_SIZE IFNAMSIZ
+#else
+#define CTDB_IFACE_SIZE 16
+#endif
+
+struct ctdb_iface {
+ char name[CTDB_IFACE_SIZE+2];
+ uint16_t link_state;
+ uint32_t references;
+};
+
+struct ctdb_iface_list {
+ uint32_t num;
+ struct ctdb_iface *iface;
+};
+
+struct ctdb_public_ip_info {
+ struct ctdb_public_ip ip;
+ uint32_t active_idx;
+ struct ctdb_iface_list *ifaces;
+};
+
+struct ctdb_statistics_list {
+ int num;
+ struct ctdb_statistics *stats;
+};
+
+struct ctdb_key_data {
+ uint32_t db_id;
+ struct ctdb_ltdb_header header;
+ TDB_DATA key;
+};
+
+struct ctdb_db_statistics {
+ struct {
+ uint32_t num_calls;
+ uint32_t num_current;
+ uint32_t num_pending;
+ uint32_t num_failed;
+ struct ctdb_latency_counter latency;
+ uint32_t buckets[MAX_COUNT_BUCKETS];
+ } locks;
+ struct {
+ struct ctdb_latency_counter latency;
+ } vacuum;
+ uint32_t db_ro_delegations;
+ uint32_t db_ro_revokes;
+ uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
+ uint32_t num_hot_keys;
+ struct {
+ uint32_t count;
+ TDB_DATA key;
+ } hot_keys[MAX_HOT_KEYS];
+};
+
+enum ctdb_runstate {
+ CTDB_RUNSTATE_UNKNOWN,
+ CTDB_RUNSTATE_INIT,
+ CTDB_RUNSTATE_SETUP,
+ CTDB_RUNSTATE_FIRST_RECOVERY,
+ CTDB_RUNSTATE_STARTUP,
+ CTDB_RUNSTATE_RUNNING,
+ CTDB_RUNSTATE_SHUTDOWN,
+};
+
+struct ctdb_pid_srvid {
+ pid_t pid;
+ uint64_t srvid;
+};
+
+struct ctdb_db_vacuum {
+ uint32_t db_id;
+ bool full_vacuum_run;
+
+};
+
+struct ctdb_echo_data {
+ uint32_t timeout;
+ TDB_DATA buf;
+};
+
+struct ctdb_req_control_data {
+ uint32_t opcode;
+ union {
+ pid_t pid;
+ uint32_t db_id;
+ struct ctdb_vnn_map *vnnmap;
+ uint32_t loglevel;
+ struct ctdb_pulldb *pulldb;
+ struct ctdb_pulldb_ext *pulldb_ext;
+ struct ctdb_rec_buffer *recbuf;
+ uint32_t recmode;
+ const char *db_name;
+ struct ctdb_traverse_start *traverse_start;
+ struct ctdb_traverse_all *traverse_all;
+ struct ctdb_rec_data *rec_data;
+ uint32_t recmaster;
+ struct ctdb_connection *conn;
+ struct ctdb_tunable *tunable;
+ const char *tun_var;
+ struct ctdb_node_flag_change *flag_change;
+ ctdb_sock_addr *addr;
+ struct ctdb_tickle_list *tickles;
+ struct ctdb_client_id *cid;
+ struct ctdb_addr_info *addr_info;
+ struct ctdb_transdb *transdb;
+ struct ctdb_public_ip *pubip;
+ enum ctdb_event event;
+ double reclock_latency;
+ uint32_t role;
+ struct ctdb_ban_state *ban_state;
+ struct ctdb_notify_data *notify;
+ uint64_t srvid;
+ struct ctdb_iface *iface;
+ struct ctdb_key_data *key;
+ struct ctdb_traverse_start_ext *traverse_start_ext;
+ struct ctdb_traverse_all_ext *traverse_all_ext;
+ struct ctdb_pid_srvid *pid_srvid;
+ struct ctdb_db_vacuum *db_vacuum;
+ struct ctdb_echo_data *echo_data;
+ } data;
+};
+
+struct ctdb_reply_control_data {
+ uint32_t opcode;
+ union {
+ struct ctdb_statistics *stats;
+ const char *db_path;
+ struct ctdb_vnn_map *vnnmap;
+ uint32_t loglevel;
+ struct ctdb_dbid_map *dbmap;
+ struct ctdb_rec_buffer *recbuf;
+ uint32_t db_id;
+ const char *db_name;
+ const char *mem_str;
+ uint32_t tun_value;
+ struct ctdb_var_list *tun_var_list;
+ struct ctdb_tunable_list *tun_list;
+ struct ctdb_tickle_list *tickles;
+ struct ctdb_client_id_map *cid_map;
+ struct ctdb_uptime *uptime;
+ uint32_t caps;
+ struct ctdb_public_ip_list *pubip_list;
+ struct ctdb_node_map *nodemap;
+ const char *reclock_file;
+ struct ctdb_ban_state *ban_state;
+ uint64_t seqnum;
+ const char *reason;
+ struct ctdb_public_ip_info *ipinfo;
+ struct ctdb_iface_list *iface_list;
+ struct ctdb_statistics_list *stats_list;
+ struct ctdb_db_statistics *dbstats;
+ enum ctdb_runstate runstate;
+ uint32_t num_records;
+ int tdb_flags;
+ struct ctdb_echo_data *echo_data;
+ } data;
+};
+
+struct ctdb_req_control {
+ uint32_t opcode;
+ uint32_t pad;
+ uint64_t srvid;
+ uint32_t client_id;
+#define CTDB_CTRL_FLAG_NOREPLY 1
+#define CTDB_CTRL_FLAG_OPCODE_SPECIFIC 0xFFFF0000
+/* Ugly overloading of this field... */
+#define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
+#define CTDB_CTRL_FLAG_ATTACH_RECOVERY 0x00020000
+ uint32_t flags;
+ struct ctdb_req_control_data rdata;
+};
+
+struct ctdb_reply_control {
+ int32_t status;
+ const char *errmsg;
+ struct ctdb_reply_control_data rdata;
+};
+
+struct ctdb_election_message {
+ uint32_t num_connected;
+ struct timeval priority_time;
+ uint32_t pnn;
+ uint32_t node_flags;
+};
+
+struct ctdb_srvid_message {
+ uint32_t pnn;
+ uint64_t srvid;
+};
+
+struct ctdb_disable_message {
+ uint32_t pnn;
+ uint64_t srvid;
+ uint32_t timeout;
+};
+
+union ctdb_message_data {
+ /* SRVID_ELECTION */
+ struct ctdb_election_message *election;
+ /* SRVID_RELEASE_IP, SRVID_TAKE_IP */
+ const char *ipaddr;
+ /* SRVID_SET_NODE_FLAGS, SERVID_PUSH_NODE_FLAGS */
+ struct ctdb_node_flag_change *flag_change;
+ /* SRVID_RECD_UPDATE_IP */
+ struct ctdb_public_ip *pubip;
+ /* SRVID_VACUUM_FETCH */
+ struct ctdb_rec_buffer *recbuf;
+ /* SRVID_DETACH_DATABASE */
+ uint32_t db_id;
+ /* SRVID_MEM_DUMP, SRVID_TAKEOVER_RUN */
+ struct ctdb_srvid_message *msg;
+ /* SRVID_BANNING, SRVID_REBALANCE_NODE, SRVID_LEADER */
+ uint32_t pnn;
+ /* SRVID_DISABLE_TAKEOVER_RUNS, SRVID_DISABLE_RECOVERIES */
+ struct ctdb_disable_message *disable;
+ /* SRVID_DISABLE_IP_CHECK */
+ uint32_t timeout;
+ /* Other */
+ TDB_DATA data;
+};
+
+struct ctdb_req_message {
+ uint64_t srvid;
+ union ctdb_message_data data;
+};
+
+struct ctdb_req_message_data {
+ uint64_t srvid;
+ TDB_DATA data;
+};
+
+struct ctdb_req_keepalive {
+ uint32_t version;
+ uint32_t uptime;
+};
+
+#define CTDB_TUNNEL_TEST 0xffffffff00000000
+
+#define CTDB_TUNNEL_FLAG_REQUEST 0x00000001
+#define CTDB_TUNNEL_FLAG_REPLY 0x00000002
+#define CTDB_TUNNEL_FLAG_NOREPLY 0x00000010
+
+struct ctdb_req_tunnel {
+ uint64_t tunnel_id;
+ uint32_t flags;
+ TDB_DATA data;
+};
+
+
+/* This is equivalent to server_id */
+struct ctdb_server_id {
+ uint64_t pid;
+ uint32_t task_id;
+ uint32_t vnn;
+ uint64_t unique_id;
+};
+
+enum ctdb_g_lock_type {
+ CTDB_G_LOCK_READ = 0,
+ CTDB_G_LOCK_WRITE = 1,
+};
+
+struct ctdb_g_lock {
+ enum ctdb_g_lock_type type;
+ struct ctdb_server_id sid;
+};
+
+struct ctdb_g_lock_list {
+ unsigned int num;
+ struct ctdb_g_lock *lock;
+};
+
+/*
+ * Generic packet header
+ */
+
+struct sock_packet_header {
+ uint32_t length;
+ uint32_t reqid;
+};
+
+#endif /* __CTDB_PROTOCOL_H__ */
diff --git a/ctdb/protocol/protocol_api.h b/ctdb/protocol/protocol_api.h
new file mode 100644
index 0000000..48e4e84
--- /dev/null
+++ b/ctdb/protocol/protocol_api.h
@@ -0,0 +1,682 @@
+/*
+ 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 <talloc.h>
+
+#include "protocol/protocol.h"
+
+/* From protocol/protocol_types.c */
+
+size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in);
+void ctdb_ltdb_header_push(struct ctdb_ltdb_header *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_ltdb_header *out, size_t *npull);
+
+int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header);
+
+size_t ctdb_rec_data_len(struct ctdb_rec_data *in);
+void ctdb_rec_data_push(struct ctdb_rec_data *in, uint8_t *buf, size_t *npush);
+int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_data **out, size_t *npull);
+
+size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *in);
+void ctdb_rec_buffer_push(struct ctdb_rec_buffer *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_buffer **out, size_t *npull);
+
+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);
+
+int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd);
+int ctdb_rec_buffer_read(int fd, TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_buffer **out);
+
+size_t ctdb_server_id_len(struct ctdb_server_id *in);
+void ctdb_server_id_push(struct ctdb_server_id *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_server_id_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_server_id *out, size_t *npull);
+
+size_t ctdb_g_lock_len(struct ctdb_g_lock *in);
+void ctdb_g_lock_push(struct ctdb_g_lock *in, uint8_t *buf, size_t *npush);
+int ctdb_g_lock_pull(uint8_t *buf, size_t buflen, struct ctdb_g_lock *out,
+ size_t *npull);
+
+size_t ctdb_g_lock_list_len(struct ctdb_g_lock_list *in);
+void ctdb_g_lock_list_push(struct ctdb_g_lock_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_g_lock_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_g_lock_list **out, size_t *npull);
+
+/* 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);
+
+size_t ctdb_req_header_len(struct ctdb_req_header *in);
+void ctdb_req_header_push(struct ctdb_req_header *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_req_header_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *out, size_t *npull);
+
+int ctdb_req_header_verify(struct ctdb_req_header *h, uint32_t operation);
+
+/* From protocol/protocol_call.c */
+
+size_t ctdb_req_call_len(struct ctdb_req_header *h,
+ struct ctdb_req_call *c);
+
+int ctdb_req_call_push(struct ctdb_req_header *h,
+ struct ctdb_req_call *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_call_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_call *c);
+
+size_t ctdb_reply_call_len(struct ctdb_req_header *h,
+ struct ctdb_reply_call *c);
+
+int ctdb_reply_call_push(struct ctdb_req_header *h,
+ struct ctdb_reply_call *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_reply_call_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_call *c);
+
+size_t ctdb_reply_error_len(struct ctdb_req_header *h,
+ struct ctdb_reply_error *c);
+
+int ctdb_reply_error_push(struct ctdb_req_header *h,
+ struct ctdb_reply_error *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_reply_error_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_error *c);
+
+size_t ctdb_req_dmaster_len(struct ctdb_req_header *h,
+ struct ctdb_req_dmaster *c);
+
+int ctdb_req_dmaster_push(struct ctdb_req_header *h,
+ struct ctdb_req_dmaster *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_dmaster_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_dmaster *c);
+
+size_t ctdb_reply_dmaster_len(struct ctdb_req_header *h,
+ struct ctdb_reply_dmaster *c);
+
+int ctdb_reply_dmaster_push(struct ctdb_req_header *h,
+ struct ctdb_reply_dmaster *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_reply_dmaster_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_dmaster *c);
+
+/* From protocol/protocol_control.c */
+
+size_t ctdb_req_control_len(struct ctdb_req_header *h,
+ struct ctdb_req_control *c);
+
+int ctdb_req_control_push(struct ctdb_req_header *h,
+ struct ctdb_req_control *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_control *c);
+
+size_t ctdb_reply_control_len(struct ctdb_req_header *h,
+ struct ctdb_reply_control *c);
+
+int ctdb_reply_control_push(struct ctdb_req_header *h,
+ struct ctdb_reply_control *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, 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,
+ int *debug_level);
+
+void ctdb_req_control_set_debug(struct ctdb_req_control *request,
+ int 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_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);
+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_freeze(struct ctdb_req_control *request,
+ uint32_t priority);
+int ctdb_reply_control_freeze(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_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_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_db_attach_persistent(struct ctdb_req_control *request,
+ const char *name);
+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_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_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_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,
+ bool available_only);
+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_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_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_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_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_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_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_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);
+
+void ctdb_req_control_db_freeze(struct ctdb_req_control *request,
+ uint32_t db_id);
+int ctdb_reply_control_db_freeze(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_thaw(struct ctdb_req_control *request,
+ uint32_t db_id);
+int ctdb_reply_control_db_thaw(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_transaction_start(struct ctdb_req_control *request,
+ struct ctdb_transdb *transdb);
+int ctdb_reply_control_db_transaction_start(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_transaction_commit(struct ctdb_req_control *request,
+ struct ctdb_transdb *transdb);
+int ctdb_reply_control_db_transaction_commit(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_transaction_cancel(struct ctdb_req_control *request,
+ uint32_t db_id);
+int ctdb_reply_control_db_transaction_cancel(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_pull(struct ctdb_req_control *request,
+ struct ctdb_pulldb_ext *pulldb_ext);
+int ctdb_reply_control_db_pull(struct ctdb_reply_control *reply,
+ uint32_t *num_records);
+
+void ctdb_req_control_db_push_start(struct ctdb_req_control *request,
+ struct ctdb_pulldb_ext *pulldb_ext);
+int ctdb_reply_control_db_push_start(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_push_confirm(struct ctdb_req_control *request,
+ uint32_t db_id);
+int ctdb_reply_control_db_push_confirm(struct ctdb_reply_control *reply,
+ uint32_t *num_records);
+
+void ctdb_req_control_db_open_flags(struct ctdb_req_control *request,
+ uint32_t db_id);
+int ctdb_reply_control_db_open_flags(struct ctdb_reply_control *reply,
+ int *tdb_flags);
+
+void ctdb_req_control_db_attach_replicated(struct ctdb_req_control *request,
+ const char *db_name);
+int ctdb_reply_control_db_attach_replicated(struct ctdb_reply_control *reply,
+ uint32_t *db_id);
+
+void ctdb_req_control_check_pid_srvid(struct ctdb_req_control *request,
+ struct ctdb_pid_srvid *pid_srvid);
+int ctdb_reply_control_check_pid_srvid(struct ctdb_reply_control *reply,
+ int *status);
+
+void ctdb_req_control_tunnel_register(struct ctdb_req_control *request,
+ uint64_t tunnel_id);
+int ctdb_reply_control_tunnel_register(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_tunnel_deregister(struct ctdb_req_control *request,
+ uint64_t tunnel_id);
+int ctdb_reply_control_tunnel_deregister(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_vacuum_fetch(struct ctdb_req_control *request,
+ struct ctdb_rec_buffer *recbuf);
+int ctdb_reply_control_vacuum_fetch(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_db_vacuum(struct ctdb_req_control *request,
+ struct ctdb_db_vacuum *db_vacuum);
+int ctdb_reply_control_db_vacuum(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_echo_data(struct ctdb_req_control *request,
+ struct ctdb_echo_data *echo_data);
+int ctdb_reply_control_echo_data(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_disable_node(struct ctdb_req_control *request);
+int ctdb_reply_control_disable_node(struct ctdb_reply_control *reply);
+
+void ctdb_req_control_enable_node(struct ctdb_req_control *request);
+int ctdb_reply_control_enable_node(struct ctdb_reply_control *reply);
+
+/* From protocol/protocol_debug.c */
+
+void ctdb_packet_print(uint8_t *buf, size_t buflen, FILE *fp);
+
+/* From protocol/protocol_message.c */
+
+size_t ctdb_req_message_len(struct ctdb_req_header *h,
+ struct ctdb_req_message *c);
+
+int ctdb_req_message_push(struct ctdb_req_header *h,
+ struct ctdb_req_message *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_message_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_message *c);
+
+size_t ctdb_req_message_data_len(struct ctdb_req_header *h,
+ struct ctdb_req_message_data *c);
+
+int ctdb_req_message_data_push(struct ctdb_req_header *h,
+ struct ctdb_req_message_data *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_message_data_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_message_data *c);
+
+/* From protocol/protocol_keepalive.c */
+
+size_t ctdb_req_keepalive_len(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c);
+
+int ctdb_req_keepalive_push(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_keepalive_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_keepalive *c);
+
+/* From protocol/protocol_tunnel.c */
+
+size_t ctdb_req_tunnel_len(struct ctdb_req_header *h,
+ struct ctdb_req_tunnel *c);
+
+int ctdb_req_tunnel_push(struct ctdb_req_header *h,
+ struct ctdb_req_tunnel *c,
+ uint8_t *buf, size_t *buflen);
+
+int ctdb_req_tunnel_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_tunnel *c);
+
+/* From protocol/protocol_packet.c */
+
+int ctdb_allocate_pkt(TALLOC_CTX *mem_ctx, size_t datalen,
+ uint8_t **buf, size_t *buflen);
+
+/* From protocol/protocol_sock.c */
+
+size_t sock_packet_header_len(struct sock_packet_header *in);
+void sock_packet_header_push(struct sock_packet_header *in, uint8_t *buf,
+ size_t *npush);
+int sock_packet_header_pull(uint8_t *buf, size_t buflen,
+ struct sock_packet_header *out, size_t *npull);
+
+void sock_packet_header_set_reqid(struct sock_packet_header *h,
+ uint32_t reqid);
+void sock_packet_header_set_length(struct sock_packet_header *h,
+ uint32_t length);
+
+#endif /* __CTDB_PROTOCOL_API_H__ */
diff --git a/ctdb/protocol/protocol_basic.c b/ctdb/protocol/protocol_basic.c
new file mode 100644
index 0000000..42f2077
--- /dev/null
+++ b/ctdb/protocol/protocol_basic.c
@@ -0,0 +1,400 @@
+/*
+ CTDB protocol marshalling
+
+ Copyright (C) Amitay Isaacs 2015-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 <talloc.h>
+
+#include "protocol_basic.h"
+
+/*
+ * Basic data types
+ */
+
+size_t ctdb_uint8_len(uint8_t *in)
+{
+ return sizeof(uint8_t);
+}
+
+void ctdb_uint8_push(uint8_t *in, uint8_t *buf, size_t *npush)
+{
+ *buf = *in;
+ *npush = sizeof(uint8_t);
+}
+
+int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull)
+{
+ if (buflen < sizeof(uint8_t)) {
+ return EMSGSIZE;
+ }
+
+ *out = *buf;
+ *npull = sizeof(uint8_t);
+ return 0;
+}
+
+size_t ctdb_uint16_len(uint16_t *in)
+{
+ return sizeof(uint16_t);
+}
+
+void ctdb_uint16_push(uint16_t *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(uint16_t));
+ *npush = sizeof(uint16_t);
+}
+
+int ctdb_uint16_pull(uint8_t *buf, size_t buflen, uint16_t *out, size_t *npull)
+{
+ if (buflen < sizeof(uint16_t)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(uint16_t));
+ *npull = sizeof(uint16_t);
+ return 0;
+}
+
+size_t ctdb_int32_len(int32_t *in)
+{
+ return sizeof(int32_t);
+}
+
+void ctdb_int32_push(int32_t *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(int32_t));
+ *npush = sizeof(int32_t);
+}
+
+int ctdb_int32_pull(uint8_t *buf, size_t buflen, int32_t *out, size_t *npull)
+{
+ if (buflen < sizeof(int32_t)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(int32_t));
+ *npull = sizeof(int32_t);
+ return 0;
+}
+
+size_t ctdb_uint32_len(uint32_t *in)
+{
+ return sizeof(uint32_t);
+}
+
+void ctdb_uint32_push(uint32_t *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(uint32_t));
+ *npush = sizeof(uint32_t);
+}
+
+int ctdb_uint32_pull(uint8_t *buf, size_t buflen, uint32_t *out, size_t *npull)
+{
+ if (buflen < sizeof(uint32_t)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(uint32_t));
+ *npull = sizeof(uint32_t);
+ return 0;
+}
+
+size_t ctdb_uint64_len(uint64_t *in)
+{
+ return sizeof(uint64_t);
+}
+
+void ctdb_uint64_push(uint64_t *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(uint64_t));
+ *npush = sizeof(uint64_t);
+}
+
+int ctdb_uint64_pull(uint8_t *buf, size_t buflen, uint64_t *out, size_t *npull)
+{
+ if (buflen < sizeof(uint64_t)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(uint64_t));
+ *npull = sizeof(uint64_t);
+ return 0;
+}
+
+size_t ctdb_double_len(double *in)
+{
+ return sizeof(double);
+}
+
+void ctdb_double_push(double *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(double));
+ *npush = sizeof(double);
+}
+
+int ctdb_double_pull(uint8_t *buf, size_t buflen, double *out, size_t *npull)
+{
+ if (buflen < sizeof(double)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(double));
+ *npull = sizeof(double);
+ return 0;
+}
+
+size_t ctdb_bool_len(bool *in)
+{
+ uint8_t u8 = 0;
+
+ return ctdb_uint8_len(&u8);
+}
+
+void ctdb_bool_push(bool *in, uint8_t *buf, size_t *npush)
+{
+ size_t np;
+ uint8_t u8 = *in;
+
+ ctdb_uint8_push(&u8, buf, &np);
+ *npush = np;
+}
+
+int ctdb_bool_pull(uint8_t *buf, size_t buflen, bool *out, size_t *npull)
+{
+ size_t np;
+ uint8_t u8;
+ int ret;
+
+ ret = ctdb_uint8_pull(buf, buflen, &u8, &np);
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (u8 == 0) {
+ *out = false;
+ } else if (u8 == 1) {
+ *out = true;
+ } else {
+ return EINVAL;
+ }
+
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_chararray_len(char *in, size_t len)
+{
+ return len;
+}
+
+void ctdb_chararray_push(char *in, size_t len, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, len);
+ *npush = len;
+}
+
+int ctdb_chararray_pull(uint8_t *buf, size_t buflen, char *out, size_t len,
+ size_t *npull)
+{
+ if (buflen < len) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, len);
+ out[len-1] = '\0';
+ *npull = len;
+ return 0;
+}
+
+size_t ctdb_string_len(const char **in)
+{
+ if (*in == NULL) {
+ return 0;
+ }
+
+ return strlen(*in) + 1;
+}
+
+void ctdb_string_push(const char **in, uint8_t *buf, size_t *npush)
+{
+ size_t len;
+
+ len = ctdb_string_len(in);
+ if (len > 0) {
+ memcpy(buf, *in, len);
+ }
+
+ *npush = len;
+}
+
+int ctdb_string_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ const char **out, size_t *npull)
+{
+ const char *str;
+
+ if (buflen > UINT32_MAX) {
+ return EMSGSIZE;
+ }
+
+ if (buflen == 0) {
+ *out = NULL;
+ *npull = 0;
+ return 0;
+ }
+
+ str = talloc_strndup(mem_ctx, (char *)buf, buflen);
+ if (str == NULL) {
+ return ENOMEM;
+ }
+
+ *out = str;
+ *npull = ctdb_string_len(&str);
+ return 0;
+}
+
+size_t ctdb_stringn_len(const char **in)
+{
+ uint32_t u32 = ctdb_string_len(in);
+
+ return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_stringn_push(const char **in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t u32 = ctdb_string_len(in);
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_string_push(in, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_stringn_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ const char **out, size_t *npull)
+{
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < u32) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_string_pull(buf+offset, u32, mem_ctx, out, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+/*
+ * System defined data types
+ */
+
+size_t ctdb_pid_len(pid_t *in)
+{
+ return sizeof(pid_t);
+}
+
+void ctdb_pid_push(pid_t *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(pid_t));
+ *npush = sizeof(pid_t);
+}
+
+int ctdb_pid_pull(uint8_t *buf, size_t buflen, pid_t *out, size_t *npull)
+{
+ if (buflen < sizeof(pid_t)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(pid_t));
+ *npull = sizeof(pid_t);
+ return 0;
+}
+
+size_t ctdb_timeval_len(struct timeval *in)
+{
+ return sizeof(struct timeval);
+}
+
+void ctdb_timeval_push(struct timeval *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(struct timeval));
+ *npush = sizeof(struct timeval);
+}
+
+int ctdb_timeval_pull(uint8_t *buf, size_t buflen, struct timeval *out,
+ size_t *npull)
+{
+ if (buflen < sizeof(struct timeval)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(struct timeval));
+ *npull = sizeof(struct timeval);
+ return 0;
+}
+
+/*
+ * Dummy type to tackle structure padding
+ */
+
+size_t ctdb_padding_len(int count)
+{
+ return count % SIZEOF_VOID_P;
+}
+
+void ctdb_padding_push(int count, uint8_t *buf, size_t *npush)
+{
+ uint8_t padding[count];
+ size_t aligned_count = count % SIZEOF_VOID_P;
+
+ if (aligned_count > 0) {
+ memset(padding, 0, aligned_count);
+ memcpy(buf, padding, aligned_count);
+ }
+ *npush = aligned_count;
+}
+
+int ctdb_padding_pull(uint8_t *buf, size_t buflen, int count, size_t *npull)
+{
+ size_t aligned_count = count % SIZEOF_VOID_P;
+
+ if (buflen < aligned_count) {
+ return EMSGSIZE;
+ }
+
+ *npull = aligned_count;
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_basic.h b/ctdb/protocol/protocol_basic.h
new file mode 100644
index 0000000..4086e81
--- /dev/null
+++ b/ctdb/protocol/protocol_basic.h
@@ -0,0 +1,86 @@
+/*
+ CTDB protocol marshalling
+
+ Copyright (C) Amitay Isaacs 2018
+
+ 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_BASIC_H__
+#define __PROTOCOL_BASIC_H__
+
+/*
+ * From protocol/protocol_basic.c
+ */
+
+size_t ctdb_uint8_len(uint8_t *in);
+void ctdb_uint8_push(uint8_t *in, uint8_t *buf, size_t *npush);
+int ctdb_uint8_pull(uint8_t *buf, size_t buflen, uint8_t *out, size_t *npull);
+
+size_t ctdb_uint16_len(uint16_t *in);
+void ctdb_uint16_push(uint16_t *in, uint8_t *buf, size_t *npush);
+int ctdb_uint16_pull(uint8_t *buf, size_t buflen, uint16_t *out,
+ size_t *npull);
+
+size_t ctdb_int32_len(int32_t *in);
+void ctdb_int32_push(int32_t *in, uint8_t *buf, size_t *npush);
+int ctdb_int32_pull(uint8_t *buf, size_t buflen, int32_t *out, size_t *npull);
+
+size_t ctdb_uint32_len(uint32_t *in);
+void ctdb_uint32_push(uint32_t *in, uint8_t *buf, size_t *npush);
+int ctdb_uint32_pull(uint8_t *buf, size_t buflen, uint32_t *out,
+ size_t *npull);
+
+size_t ctdb_uint64_len(uint64_t *in);
+void ctdb_uint64_push(uint64_t *in, uint8_t *buf, size_t *npush);
+int ctdb_uint64_pull(uint8_t *buf, size_t buflen, uint64_t *out,
+ size_t *npull);
+
+size_t ctdb_double_len(double *in);
+void ctdb_double_push(double *in, uint8_t *buf, size_t *npush);
+int ctdb_double_pull(uint8_t *buf, size_t buflen, double *out, size_t *npull);
+
+size_t ctdb_bool_len(bool *in);
+void ctdb_bool_push(bool *in, uint8_t *buf, size_t *npush);
+int ctdb_bool_pull(uint8_t *buf, size_t buflen, bool *out, size_t *npull);
+
+size_t ctdb_chararray_len(char *in, size_t len);
+void ctdb_chararray_push(char *in, size_t len, uint8_t *buf, size_t *npush);
+int ctdb_chararray_pull(uint8_t *buf, size_t buflen, char *out, size_t len,
+ size_t *npull);
+
+size_t ctdb_string_len(const char **in);
+void ctdb_string_push(const char **in, uint8_t *buf, size_t *npush);
+int ctdb_string_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ const char **out, size_t *npull);
+
+size_t ctdb_stringn_len(const char **in);
+void ctdb_stringn_push(const char **in, uint8_t *buf, size_t *npush);
+int ctdb_stringn_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ const char **out, size_t *npull);
+
+size_t ctdb_pid_len(pid_t *in);
+void ctdb_pid_push(pid_t *in, uint8_t *buf, size_t *npush);
+int ctdb_pid_pull(uint8_t *buf, size_t buflen, pid_t *out, size_t *npull);
+
+size_t ctdb_timeval_len(struct timeval *in);
+void ctdb_timeval_push(struct timeval *in, uint8_t *buf, size_t *npush);
+int ctdb_timeval_pull(uint8_t *buf, size_t buflen, struct timeval *out,
+ size_t *npull);
+
+size_t ctdb_padding_len(int count);
+void ctdb_padding_push(int count, uint8_t *buf, size_t *npush);
+int ctdb_padding_pull(uint8_t *buf, size_t buflen, int count, size_t *npull);
+
+#endif /* __PROTOCOL_BASIC_H__ */
diff --git a/ctdb/protocol/protocol_call.c b/ctdb/protocol/protocol_call.c
new file mode 100644
index 0000000..393b118
--- /dev/null
+++ b/ctdb/protocol/protocol_call.c
@@ -0,0 +1,581 @@
+/*
+ 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"
+
+size_t ctdb_req_call_len(struct ctdb_req_header *h, struct ctdb_req_call *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint32_len(&c->flags) +
+ ctdb_uint32_len(&c->db_id) +
+ ctdb_uint32_len(&c->callid) +
+ ctdb_uint32_len(&c->hopcount) +
+ ctdb_tdb_datan_len(&c->key) +
+ ctdb_tdb_datan_len(&c->calldata);
+}
+
+int ctdb_req_call_push(struct ctdb_req_header *h, struct ctdb_req_call *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0;
+ size_t length, np;
+ uint32_t u32;
+
+ if (c->key.dsize == 0) {
+ return EINVAL;
+ }
+
+ length = ctdb_req_call_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->callid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->hopcount, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&c->key);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&c->calldata);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&c->key, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&c->calldata, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_req_call_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_call *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->db_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->callid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->hopcount, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ c->key.dsize = u32;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ c->calldata.dsize = u32;
+
+ if (buflen-offset < c->key.dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, c->key.dsize, mem_ctx, &c->key,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < c->calldata.dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, c->calldata.dsize,
+ mem_ctx, &c->calldata, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
+
+size_t ctdb_reply_call_len(struct ctdb_req_header *h,
+ struct ctdb_reply_call *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_int32_len(&c->status) +
+ ctdb_tdb_datan_len(&c->data);
+}
+
+int ctdb_reply_call_push(struct ctdb_req_header *h, struct ctdb_reply_call *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+
+ length = ctdb_reply_call_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_int32_push(&c->status, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&c->data, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_reply_call_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_call *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset,
+ mem_ctx, &c->data, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
+
+size_t ctdb_reply_error_len(struct ctdb_req_header *h,
+ struct ctdb_reply_error *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_int32_len(&c->status) +
+ ctdb_tdb_datan_len(&c->msg);
+}
+
+int ctdb_reply_error_push(struct ctdb_req_header *h, struct ctdb_reply_error *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+
+ length = ctdb_reply_error_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_int32_push(&c->status, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&c->msg, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_reply_error_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_error *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, mem_ctx, &c->msg,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
+
+size_t ctdb_req_dmaster_len(struct ctdb_req_header *h,
+ struct ctdb_req_dmaster *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint32_len(&c->db_id) +
+ ctdb_padding_len(4) +
+ ctdb_uint64_len(&c->rsn) +
+ ctdb_uint32_len(&c->dmaster) +
+ ctdb_tdb_datan_len(&c->key) +
+ ctdb_tdb_datan_len(&c->data);
+}
+
+int ctdb_req_dmaster_push(struct ctdb_req_header *h, struct ctdb_req_dmaster *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+ uint32_t u32;
+
+ length = ctdb_req_dmaster_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&c->rsn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->dmaster, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&c->key);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&c->data);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&c->key, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&c->data, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_req_dmaster_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_dmaster *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->db_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->rsn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ c->key.dsize = u32;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ c->data.dsize = u32;
+
+ if (buflen-offset < c->key.dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, c->key.dsize, mem_ctx, &c->key,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < c->data.dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, c->data.dsize, mem_ctx, &c->data,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
+
+size_t ctdb_reply_dmaster_len(struct ctdb_req_header *h,
+ struct ctdb_reply_dmaster *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint32_len(&c->db_id) +
+ ctdb_padding_len(4) +
+ ctdb_uint64_len(&c->rsn) +
+ ctdb_tdb_datan_len(&c->key) +
+ ctdb_tdb_datan_len(&c->data);
+}
+
+int ctdb_reply_dmaster_push(struct ctdb_req_header *h,
+ struct ctdb_reply_dmaster *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+ uint32_t u32;
+
+ length = ctdb_reply_dmaster_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&c->rsn, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&c->key);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&c->data);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&c->key, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&c->data, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_reply_dmaster_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_dmaster *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->db_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->rsn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ c->key.dsize = u32;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ c->data.dsize = u32;
+
+ if (buflen-offset < c->key.dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, c->key.dsize, mem_ctx, &c->key,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < c->data.dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, c->data.dsize, mem_ctx, &c->data,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_client.c b/ctdb/protocol/protocol_client.c
new file mode 100644
index 0000000..9ca2d4e
--- /dev/null
+++ b/ctdb/protocol/protocol_client.c
@@ -0,0 +1,2352 @@
+/*
+ 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"
+
+/*
+void ctdb_req_call_fill(struct ctdb_req_call *c,
+ uint32_t db_id, uint32_t flags,
+ uint32_t call_id, TDB_DATA key)
+{
+ request->flags = flags;
+ c->db_id = db_id;
+ c->call_id = call_id;
+ c->key = key;
+ c->calldata = tdb_null;
+}
+*/
+
+static int ctdb_reply_control_generic(struct ctdb_reply_control *reply,
+ uint32_t opcode)
+{
+ if (reply->rdata.opcode != opcode) {
+ return EPROTO;
+ }
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_PROCESS_EXISTS */
+
+void ctdb_req_control_process_exists(struct ctdb_req_control *request,
+ pid_t pid)
+{
+ request->opcode = CTDB_CONTROL_PROCESS_EXISTS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_PROCESS_EXISTS;
+ request->rdata.data.pid = pid;
+
+}
+
+int ctdb_reply_control_process_exists(struct ctdb_reply_control *reply,
+ int *status)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_PROCESS_EXISTS) {
+ return EPROTO;
+ }
+
+ *status = reply->status;
+ reply->status = 0;
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_STATISTICS */
+
+void ctdb_req_control_statistics(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_STATISTICS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_STATISTICS;
+}
+
+int ctdb_reply_control_statistics(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics **stats)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_STATISTICS) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *stats = talloc_steal(mem_ctx, reply->rdata.data.stats);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_PING */
+
+void ctdb_req_control_ping(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_PING;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_PING;
+}
+
+int ctdb_reply_control_ping(struct ctdb_reply_control *reply,
+ int *num_clients)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_PING) {
+ return EPROTO;
+ }
+
+ if (reply->status >= 0) {
+ *num_clients = reply->status;
+ reply->status = 0;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GETDBPATH */
+
+void ctdb_req_control_getdbpath(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_GETDBPATH;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GETDBPATH;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_getdbpath(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx, const char **db_path)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GETDBPATH) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *db_path = talloc_steal(mem_ctx, reply->rdata.data.db_path);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GETVNNMAP */
+
+void ctdb_req_control_getvnnmap(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GETVNNMAP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GETVNNMAP;
+}
+
+int ctdb_reply_control_getvnnmap(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_vnn_map **vnnmap)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GETVNNMAP) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *vnnmap = talloc_steal(mem_ctx, reply->rdata.data.vnnmap);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SETVNNMAP */
+
+void ctdb_req_control_setvnnmap(struct ctdb_req_control *request,
+ struct ctdb_vnn_map *vnnmap)
+{
+ request->opcode = CTDB_CONTROL_SETVNNMAP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SETVNNMAP;
+ request->rdata.data.vnnmap = vnnmap;
+}
+
+int ctdb_reply_control_setvnnmap(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SETVNNMAP);
+}
+
+/* CTDB_CONTROL_GET_DEBUG */
+
+void ctdb_req_control_get_debug(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_DEBUG;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_DEBUG;
+}
+
+int ctdb_reply_control_get_debug(struct ctdb_reply_control *reply,
+ int *loglevel)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_DEBUG) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *loglevel = (int)reply->rdata.data.loglevel;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SET_DEBUG */
+
+void ctdb_req_control_set_debug(struct ctdb_req_control *request,
+ int loglevel)
+{
+ request->opcode = CTDB_CONTROL_SET_DEBUG;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_DEBUG;
+ request->rdata.data.loglevel = (uint32_t)loglevel;
+}
+
+int ctdb_reply_control_set_debug(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_DEBUG);
+}
+
+/* CTDB_CONTROL_GET_DBMAP */
+
+void ctdb_req_control_get_dbmap(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_DBMAP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_DBMAP;
+}
+
+int ctdb_reply_control_get_dbmap(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid_map **dbmap)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_DBMAP) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *dbmap = talloc_steal(mem_ctx, reply->rdata.data.dbmap);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GET_RECMODE */
+
+void ctdb_req_control_get_recmode(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_RECMODE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_RECMODE;
+}
+
+int ctdb_reply_control_get_recmode(struct ctdb_reply_control *reply,
+ int *recmode)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_RECMODE) {
+ return EPROTO;
+ }
+
+ if (reply->status >= 0) {
+ *recmode = reply->status;
+ reply->status = 0;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SET_RECMODE */
+
+void ctdb_req_control_set_recmode(struct ctdb_req_control *request,
+ int recmode)
+{
+ request->opcode = CTDB_CONTROL_SET_RECMODE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_RECMODE;
+ request->rdata.data.recmode = recmode;
+}
+
+int ctdb_reply_control_set_recmode(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_RECMODE);
+}
+
+/* CTDB_CONTROL_STATISTICS_RESET */
+
+void ctdb_req_control_statistics_reset(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_STATISTICS_RESET;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_STATISTICS_RESET;
+}
+
+int ctdb_reply_control_statistics_reset(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_STATISTICS_RESET);
+}
+
+/* CTDB_CONTROL_DB_ATTACH */
+
+void ctdb_req_control_db_attach(struct ctdb_req_control *request,
+ const char *db_name)
+{
+ request->opcode = CTDB_CONTROL_DB_ATTACH;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_ATTACH;
+ request->rdata.data.db_name = db_name;
+}
+
+int ctdb_reply_control_db_attach(struct ctdb_reply_control *reply,
+ uint32_t *db_id)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_ATTACH) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *db_id = reply->rdata.data.db_id;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_TRAVERSE_START */
+
+void ctdb_req_control_traverse_start(struct ctdb_req_control *request,
+ struct ctdb_traverse_start *traverse)
+{
+ request->opcode = CTDB_CONTROL_TRAVERSE_START;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TRAVERSE_START;
+ request->rdata.data.traverse_start = traverse;
+}
+
+int ctdb_reply_control_traverse_start(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TRAVERSE_START);
+}
+
+/* CTDB_CONTROL_TRAVERSE_ALL */
+/* CTDB_CONTROL_TRAVERSE_DATA */
+
+/* CTDB_CONTROL_REGISTER_SRVID */
+
+void ctdb_req_control_register_srvid(struct ctdb_req_control *request,
+ uint64_t srvid)
+{
+ request->opcode = CTDB_CONTROL_REGISTER_SRVID;
+ request->pad = 0;
+ request->srvid = srvid;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_REGISTER_SRVID;
+}
+
+int ctdb_reply_control_register_srvid(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_REGISTER_SRVID);
+}
+
+/* CTDB_CONTROL_DEREGISTER_SRVID */
+
+void ctdb_req_control_deregister_srvid(struct ctdb_req_control *request,
+ uint64_t srvid)
+{
+ request->opcode = CTDB_CONTROL_DEREGISTER_SRVID;
+ request->pad = 0;
+ request->srvid = srvid;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DEREGISTER_SRVID;
+}
+
+int ctdb_reply_control_deregister_srvid(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_DEREGISTER_SRVID);
+}
+
+/* CTDB_CONTROL_GET_DBNAME */
+
+void ctdb_req_control_get_dbname(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_GET_DBNAME;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_DBNAME;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_get_dbname(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx, const char **db_name)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_DBNAME) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *db_name = talloc_steal(mem_ctx, reply->rdata.data.db_name);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_ENABLE_SEQNUM */
+
+void ctdb_req_control_enable_seqnum(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_ENABLE_SEQNUM;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_ENABLE_SEQNUM;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_enable_seqnum(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_ENABLE_SEQNUM);
+}
+
+/* CTDB_CONTROL_UPDATE_SEQNUM */
+
+void ctdb_req_control_update_seqnum(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_UPDATE_SEQNUM;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_UPDATE_SEQNUM;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_update_seqnum(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_UPDATE_SEQNUM);
+}
+
+/* CTDB_CONTROL_DUMP_MEMORY */
+
+void ctdb_req_control_dump_memory(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_DUMP_MEMORY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DUMP_MEMORY;
+}
+
+int ctdb_reply_control_dump_memory(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx, const char **mem_str)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DUMP_MEMORY) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *mem_str = talloc_steal(mem_ctx, reply->rdata.data.mem_str);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GET_PID */
+
+void ctdb_req_control_get_pid(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_PID;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_PID;
+}
+
+int ctdb_reply_control_get_pid(struct ctdb_reply_control *reply,
+ pid_t *pid)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_PID) {
+ return EPROTO;
+ }
+
+ *pid = reply->status;
+ reply->status = 0;
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_FREEZE */
+
+void ctdb_req_control_freeze(struct ctdb_req_control *request,
+ uint32_t priority)
+{
+ request->opcode = CTDB_CONTROL_FREEZE;
+ request->pad = 0;
+ request->srvid = priority;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_FREEZE;
+}
+
+int ctdb_reply_control_freeze(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_FREEZE);
+}
+
+/* CTDB_CONTROL_GET_PNN */
+
+void ctdb_req_control_get_pnn(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_PNN;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_PNN;
+}
+
+int ctdb_reply_control_get_pnn(struct ctdb_reply_control *reply,
+ uint32_t *pnn)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_PNN) {
+ return EPROTO;
+ }
+
+ if (reply->status >= 0) {
+ *pnn = reply->status;
+ reply->status = 0;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SHUTDOWN */
+
+void ctdb_req_control_shutdown(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_SHUTDOWN;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = CTDB_CTRL_FLAG_NOREPLY;
+
+ request->rdata.opcode = CTDB_CONTROL_SHUTDOWN;
+}
+
+int ctdb_reply_control_shutdown(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SHUTDOWN);
+}
+
+/* CTDB_CONTROL_TCP_CLIENT */
+
+void ctdb_req_control_tcp_client(struct ctdb_req_control *request,
+ struct ctdb_connection *conn)
+{
+ request->opcode = CTDB_CONTROL_TCP_CLIENT;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TCP_CLIENT;
+ request->rdata.data.conn = conn;
+}
+
+int ctdb_reply_control_tcp_client(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TCP_CLIENT);
+}
+
+/* CTDB_CONTROL_TCP_ADD */
+
+void ctdb_req_control_tcp_add(struct ctdb_req_control *request,
+ struct ctdb_connection *conn)
+{
+ request->opcode = CTDB_CONTROL_TCP_ADD;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TCP_ADD;
+ request->rdata.data.conn = conn;
+}
+
+int ctdb_reply_control_tcp_add(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TCP_ADD);
+}
+
+/* CTDB_CONTROL_TCP_REMOVE */
+
+void ctdb_req_control_tcp_remove(struct ctdb_req_control *request,
+ struct ctdb_connection *conn)
+{
+ request->opcode = CTDB_CONTROL_TCP_REMOVE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TCP_REMOVE;
+ request->rdata.data.conn = conn;
+}
+
+int ctdb_reply_control_tcp_remove(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TCP_REMOVE);
+}
+
+/* CTDB_CONTROL_STARTUP */
+
+void ctdb_req_control_startup(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_STARTUP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_STARTUP;
+}
+
+int ctdb_reply_control_startup(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_STARTUP);
+}
+
+/* CTDB_CONTROL_SET_TUNABLE */
+
+void ctdb_req_control_set_tunable(struct ctdb_req_control *request,
+ struct ctdb_tunable *tunable)
+{
+ request->opcode = CTDB_CONTROL_SET_TUNABLE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_TUNABLE;
+ request->rdata.data.tunable = tunable;
+}
+
+int ctdb_reply_control_set_tunable(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_TUNABLE);
+}
+
+/* CTDB_CONTROL_GET_TUNABLE */
+
+void ctdb_req_control_get_tunable(struct ctdb_req_control *request,
+ const char *name)
+{
+ request->opcode = CTDB_CONTROL_GET_TUNABLE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_TUNABLE;
+ request->rdata.data.tun_var = discard_const(name);
+}
+
+int ctdb_reply_control_get_tunable(struct ctdb_reply_control *reply,
+ uint32_t *value)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_TUNABLE) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *value = reply->rdata.data.tun_value;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_LIST_TUNABLES */
+
+void ctdb_req_control_list_tunables(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_LIST_TUNABLES;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_LIST_TUNABLES;
+}
+
+int ctdb_reply_control_list_tunables(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_var_list **tun_var_list)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_LIST_TUNABLES) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *tun_var_list = talloc_steal(mem_ctx,
+ reply->rdata.data.tun_var_list);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_MODIFY_FLAGS */
+
+void ctdb_req_control_modify_flags(struct ctdb_req_control *request,
+ struct ctdb_node_flag_change *flag_change)
+{
+ request->opcode = CTDB_CONTROL_MODIFY_FLAGS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_MODIFY_FLAGS;
+ request->rdata.data.flag_change = flag_change;
+}
+
+int ctdb_reply_control_modify_flags(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_MODIFY_FLAGS);
+}
+
+/* CTDB_CONTROL_GET_ALL_TUNABLES */
+
+void ctdb_req_control_get_all_tunables(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_ALL_TUNABLES;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_ALL_TUNABLES;
+}
+
+int ctdb_reply_control_get_all_tunables(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable_list **tun_list)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_ALL_TUNABLES) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *tun_list = talloc_steal(mem_ctx, reply->rdata.data.tun_list);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GET_TCP_TICKLE_LIST */
+
+void ctdb_req_control_get_tcp_tickle_list(struct ctdb_req_control *request,
+ ctdb_sock_addr *addr)
+{
+ request->opcode = CTDB_CONTROL_GET_TCP_TICKLE_LIST;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_TCP_TICKLE_LIST;
+ request->rdata.data.addr = addr;
+}
+
+int ctdb_reply_control_get_tcp_tickle_list(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_tickle_list **tickles)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_TCP_TICKLE_LIST) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *tickles = talloc_steal(mem_ctx, reply->rdata.data.tickles);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SET_TCP_TICKLE_LIST */
+
+void ctdb_req_control_set_tcp_tickle_list(struct ctdb_req_control *request,
+ struct ctdb_tickle_list *tickles)
+{
+ request->opcode = CTDB_CONTROL_SET_TCP_TICKLE_LIST;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_TCP_TICKLE_LIST;
+ request->rdata.data.tickles = tickles;
+}
+
+int ctdb_reply_control_set_tcp_tickle_list(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_SET_TCP_TICKLE_LIST);
+}
+
+/* CTDB_CONTROL_DB_ATTACH_PERSISTENT */
+
+void ctdb_req_control_db_attach_persistent(struct ctdb_req_control *request,
+ const char *db_name)
+{
+ request->opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
+ request->rdata.data.db_name = db_name;
+}
+
+int ctdb_reply_control_db_attach_persistent(struct ctdb_reply_control *reply,
+ uint32_t *db_id)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_ATTACH_PERSISTENT) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *db_id = reply->rdata.data.db_id;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_UPDATE_RECORD */
+
+void ctdb_req_control_update_record(struct ctdb_req_control *request,
+ struct ctdb_rec_buffer *recbuf)
+{
+ request->opcode = CTDB_CONTROL_UPDATE_RECORD;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_UPDATE_RECORD;
+ request->rdata.data.recbuf = recbuf;
+}
+
+int ctdb_reply_control_update_record(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_UPDATE_RECORD);
+}
+
+/* CTDB_CONTROL_SEND_GRATUITOUS_ARP */
+
+void ctdb_req_control_send_gratuitous_arp(struct ctdb_req_control *request,
+ struct ctdb_addr_info *addr_info)
+{
+ request->opcode = CTDB_CONTROL_SEND_GRATUITOUS_ARP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SEND_GRATUITOUS_ARP;
+ request->rdata.data.addr_info = addr_info;
+}
+
+int ctdb_reply_control_send_gratuitous_arp(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_SEND_GRATUITOUS_ARP);
+}
+
+/* CTDB_CONTROL_WIPE_DATABASE */
+
+void ctdb_req_control_wipe_database(struct ctdb_req_control *request,
+ struct ctdb_transdb *transdb)
+{
+ request->opcode = CTDB_CONTROL_WIPE_DATABASE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_WIPE_DATABASE;
+ request->rdata.data.transdb = transdb;
+}
+
+int ctdb_reply_control_wipe_database(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_WIPE_DATABASE);
+}
+
+/* CTDB_CONTROL_UPTIME */
+
+void ctdb_req_control_uptime(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_UPTIME;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_UPTIME;
+}
+
+int ctdb_reply_control_uptime(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx, struct ctdb_uptime **uptime)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_UPTIME) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *uptime = talloc_steal(mem_ctx, reply->rdata.data.uptime);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_START_RECOVERY */
+
+void ctdb_req_control_start_recovery(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_START_RECOVERY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_START_RECOVERY;
+}
+
+int ctdb_reply_control_start_recovery(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_START_RECOVERY);
+}
+
+/* CTDB_CONTROL_END_RECOVERY */
+
+void ctdb_req_control_end_recovery(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_END_RECOVERY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_END_RECOVERY;
+}
+
+int ctdb_reply_control_end_recovery(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_END_RECOVERY);
+}
+
+/* CTDB_CONTROL_RELOAD_NODES_FILE */
+
+void ctdb_req_control_reload_nodes_file(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_RELOAD_NODES_FILE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_RELOAD_NODES_FILE;
+}
+
+int ctdb_reply_control_reload_nodes_file(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_RELOAD_NODES_FILE);
+}
+
+/* CTDB_CONTROL_TRY_DELETE_RECORDS */
+
+void ctdb_req_control_try_delete_records(struct ctdb_req_control *request,
+ struct ctdb_rec_buffer *recbuf)
+{
+ request->opcode = CTDB_CONTROL_TRY_DELETE_RECORDS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TRY_DELETE_RECORDS;
+ request->rdata.data.recbuf = recbuf;
+}
+
+int ctdb_reply_control_try_delete_records(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_buffer **recbuf)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_TRY_DELETE_RECORDS) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *recbuf = talloc_steal(mem_ctx, reply->rdata.data.recbuf);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_ADD_PUBLIC_IP */
+
+void ctdb_req_control_add_public_ip(struct ctdb_req_control *request,
+ struct ctdb_addr_info *addr_info)
+{
+ request->opcode = CTDB_CONTROL_ADD_PUBLIC_IP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_ADD_PUBLIC_IP;
+ request->rdata.data.addr_info = addr_info;
+}
+
+int ctdb_reply_control_add_public_ip(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_ADD_PUBLIC_IP);
+}
+
+/* CTDB_CONTROL_DEL_PUBLIC_IP */
+
+void ctdb_req_control_del_public_ip(struct ctdb_req_control *request,
+ struct ctdb_addr_info *addr_info)
+{
+ request->opcode = CTDB_CONTROL_DEL_PUBLIC_IP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DEL_PUBLIC_IP;
+ request->rdata.data.addr_info = addr_info;
+}
+
+int ctdb_reply_control_del_public_ip(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DEL_PUBLIC_IP);
+}
+
+/* CTDB_CONTROL_GET_CAPABILITIES */
+
+void ctdb_req_control_get_capabilities(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_CAPABILITIES;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_CAPABILITIES;
+}
+
+int ctdb_reply_control_get_capabilities(struct ctdb_reply_control *reply,
+ uint32_t *caps)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_CAPABILITIES) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *caps = reply->rdata.data.caps;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_RECD_PING */
+
+void ctdb_req_control_recd_ping(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_RECD_PING;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_RECD_PING;
+}
+
+int ctdb_reply_control_recd_ping(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_RECD_PING);
+}
+
+/* CTDB_CONTROL_RELEASE_IP */
+
+void ctdb_req_control_release_ip(struct ctdb_req_control *request,
+ struct ctdb_public_ip *pubip)
+{
+ request->opcode = CTDB_CONTROL_RELEASE_IP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_RELEASE_IP;
+ request->rdata.data.pubip = pubip;
+}
+
+int ctdb_reply_control_release_ip(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_RELEASE_IP);
+}
+
+/* CTDB_CONTROL_TAKEOVER_IP */
+
+void ctdb_req_control_takeover_ip(struct ctdb_req_control *request,
+ struct ctdb_public_ip *pubip)
+{
+ request->opcode = CTDB_CONTROL_TAKEOVER_IP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TAKEOVER_IP;
+ request->rdata.data.pubip = pubip;
+}
+
+int ctdb_reply_control_takeover_ip(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TAKEOVER_IP);
+}
+
+/* CTDB_CONTROL_GET_PUBLIC_IPS */
+
+void ctdb_req_control_get_public_ips(struct ctdb_req_control *request,
+ bool available_only)
+{
+ request->opcode = CTDB_CONTROL_GET_PUBLIC_IPS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_PUBLIC_IPS;
+ if (available_only) {
+ request->flags = CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE;
+ }
+}
+
+int ctdb_reply_control_get_public_ips(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip_list **pubip_list)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_PUBLIC_IPS) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *pubip_list = talloc_steal(mem_ctx,
+ reply->rdata.data.pubip_list);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GET_NODEMAP */
+
+void ctdb_req_control_get_nodemap(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_NODEMAP;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_NODEMAP;
+}
+
+int ctdb_reply_control_get_nodemap(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_node_map **nodemap)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_NODEMAP) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *nodemap = talloc_steal(mem_ctx, reply->rdata.data.nodemap);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_TRAVERSE_KILL */
+
+void ctdb_req_control_traverse_kill(struct ctdb_req_control *request,
+ struct ctdb_traverse_start *traverse)
+{
+ request->opcode = CTDB_CONTROL_TRAVERSE_KILL;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TRAVERSE_KILL;
+ request->rdata.data.traverse_start = traverse;
+}
+
+int ctdb_reply_control_traverse_kill(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TRAVERSE_KILL);
+}
+
+/* CTDB_CONTROL_RECD_RECLOCK_LATENCY */
+
+void ctdb_req_control_recd_reclock_latency(struct ctdb_req_control *request,
+ double reclock_latency)
+{
+ request->opcode = CTDB_CONTROL_RECD_RECLOCK_LATENCY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_RECD_RECLOCK_LATENCY;
+ request->rdata.data.reclock_latency = reclock_latency;
+}
+
+int ctdb_reply_control_recd_reclock_latency(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_RECD_RECLOCK_LATENCY);
+}
+
+/* CTDB_CONTROL_GET_RECLOCK_FILE */
+
+void ctdb_req_control_get_reclock_file(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_RECLOCK_FILE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_RECLOCK_FILE;
+}
+
+int ctdb_reply_control_get_reclock_file(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ const char **reclock_file)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_RECLOCK_FILE) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *reclock_file = talloc_steal(mem_ctx,
+ reply->rdata.data.reclock_file);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_STOP_NODE */
+
+void ctdb_req_control_stop_node(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_STOP_NODE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_STOP_NODE;
+}
+
+int ctdb_reply_control_stop_node(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_STOP_NODE);
+}
+
+/* CTDB_CONTROL_CONTINUE_NODE */
+
+void ctdb_req_control_continue_node(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_CONTINUE_NODE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_CONTINUE_NODE;
+}
+
+int ctdb_reply_control_continue_node(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_CONTINUE_NODE);
+}
+
+/* CTDB_CONTROL_SET_LMASTERROLE */
+
+void ctdb_req_control_set_lmasterrole(struct ctdb_req_control *request,
+ uint32_t lmaster_role)
+{
+ request->opcode = CTDB_CONTROL_SET_LMASTERROLE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_LMASTERROLE;
+ request->rdata.data.role = lmaster_role;
+}
+
+int ctdb_reply_control_set_lmasterrole(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_LMASTERROLE);
+}
+
+/* CTDB_CONTROL_SET_RECMASTERROLE */
+
+void ctdb_req_control_set_recmasterrole(struct ctdb_req_control *request,
+ uint32_t recmaster_role)
+{
+ request->opcode = CTDB_CONTROL_SET_RECMASTERROLE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_RECMASTERROLE;
+ request->rdata.data.role = recmaster_role;
+}
+
+int ctdb_reply_control_set_recmasterrole(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_SET_RECMASTERROLE);
+}
+
+/* CTDB_CONTROL_SET_BAN_STATE */
+
+void ctdb_req_control_set_ban_state(struct ctdb_req_control *request,
+ struct ctdb_ban_state *ban_state)
+{
+ request->opcode = CTDB_CONTROL_SET_BAN_STATE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_BAN_STATE;
+ request->rdata.data.ban_state = ban_state;
+}
+
+int ctdb_reply_control_set_ban_state(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_BAN_STATE);
+}
+
+/* CTDB_CONTROL_GET_BAN_STATE */
+
+void ctdb_req_control_get_ban_state(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_BAN_STATE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_BAN_STATE;
+}
+
+int ctdb_reply_control_get_ban_state(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_ban_state **ban_state)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_BAN_STATE) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *ban_state = talloc_steal(mem_ctx,
+ reply->rdata.data.ban_state);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_REGISTER_NOTIFY */
+
+void ctdb_req_control_register_notify(struct ctdb_req_control *request,
+ struct ctdb_notify_data *notify)
+{
+ request->opcode = CTDB_CONTROL_REGISTER_NOTIFY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_REGISTER_NOTIFY;
+ request->rdata.data.notify = notify;
+}
+
+int ctdb_reply_control_register_notify(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_REGISTER_NOTIFY);
+}
+
+/* CTDB_CONTROL_DEREGISTER_NOTIFY */
+
+void ctdb_req_control_deregister_notify(struct ctdb_req_control *request,
+ uint64_t srvid)
+{
+ request->opcode = CTDB_CONTROL_DEREGISTER_NOTIFY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DEREGISTER_NOTIFY;
+ request->rdata.data.srvid = srvid;
+}
+
+int ctdb_reply_control_deregister_notify(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_DEREGISTER_NOTIFY);
+}
+
+/* CTDB_CONTROL_TRANS3_COMMIT */
+
+void ctdb_req_control_trans3_commit(struct ctdb_req_control *request,
+ struct ctdb_rec_buffer *recbuf)
+{
+ request->opcode = CTDB_CONTROL_TRANS3_COMMIT;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TRANS3_COMMIT;
+ request->rdata.data.recbuf = recbuf;
+}
+
+int ctdb_reply_control_trans3_commit(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_TRANS3_COMMIT);
+}
+
+/* CTDB_CONTROL_GET_DB_SEQNUM */
+
+void ctdb_req_control_get_db_seqnum(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_GET_DB_SEQNUM;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_DB_SEQNUM;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_get_db_seqnum(struct ctdb_reply_control *reply,
+ uint64_t *seqnum)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_DB_SEQNUM) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *seqnum = reply->rdata.data.seqnum;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_SET_HEALTHY */
+
+void ctdb_req_control_db_set_healthy(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_SET_HEALTHY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_SET_HEALTHY;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_set_healthy(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_SET_HEALTHY);
+}
+
+/* CTDB_CONTROL_DB_GET_HEALTH */
+
+void ctdb_req_control_db_get_health(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_GET_HEALTH;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_GET_HEALTH;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_get_health(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx, const char **reason)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_GET_HEALTH) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *reason = talloc_steal(mem_ctx, reply->rdata.data.reason);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GET_PUBLIC_IP_INFO */
+
+void ctdb_req_control_get_public_ip_info(struct ctdb_req_control *request,
+ ctdb_sock_addr *addr)
+{
+ request->opcode = CTDB_CONTROL_GET_PUBLIC_IP_INFO;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_PUBLIC_IP_INFO;
+ request->rdata.data.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)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_PUBLIC_IP_INFO) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *ipinfo = talloc_steal(mem_ctx, reply->rdata.data.ipinfo);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_GET_IFACES */
+
+void ctdb_req_control_get_ifaces(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_IFACES;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_IFACES;
+}
+
+int ctdb_reply_control_get_ifaces(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_iface_list **iface_list)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_IFACES) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *iface_list = talloc_steal(mem_ctx,
+ reply->rdata.data.iface_list);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SET_IFACE_LINK_STATE */
+
+void ctdb_req_control_set_iface_link_state(struct ctdb_req_control *request,
+ struct ctdb_iface *iface)
+{
+ request->opcode = CTDB_CONTROL_SET_IFACE_LINK_STATE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_IFACE_LINK_STATE;
+ request->rdata.data.iface = iface;
+}
+
+int ctdb_reply_control_set_iface_link_state(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_SET_IFACE_LINK_STATE);
+}
+
+/* CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE */
+
+void ctdb_req_control_tcp_add_delayed_update(struct ctdb_req_control *request,
+ struct ctdb_connection *conn)
+{
+ request->opcode = CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE;
+ request->rdata.data.conn = conn;
+}
+
+int ctdb_reply_control_tcp_add_delayed_update(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE);
+}
+
+/* CTDB_CONTROL_GET_STAT_HISTORY */
+
+void ctdb_req_control_get_stat_history(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_STAT_HISTORY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_STAT_HISTORY;
+}
+
+int ctdb_reply_control_get_stat_history(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics_list **stats_list)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_STAT_HISTORY) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *stats_list = talloc_steal(mem_ctx,
+ reply->rdata.data.stats_list);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SCHEDULE_FOR_DELETION */
+
+void ctdb_req_control_schedule_for_deletion(struct ctdb_req_control *request,
+ struct ctdb_key_data *key)
+{
+ request->opcode = CTDB_CONTROL_SCHEDULE_FOR_DELETION;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SCHEDULE_FOR_DELETION;
+ request->rdata.data.key = key;
+}
+
+int ctdb_reply_control_schedule_for_deletion(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_SCHEDULE_FOR_DELETION);
+}
+
+/* CTDB_CONTROL_SET_DB_READONLY */
+
+void ctdb_req_control_set_db_readonly(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_SET_DB_READONLY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_DB_READONLY;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_set_db_readonly(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_DB_READONLY);
+}
+
+/* CTDB_CONTROL_TRAVERSE_START_EXT */
+
+void ctdb_req_control_traverse_start_ext(struct ctdb_req_control *request,
+ struct ctdb_traverse_start_ext *traverse)
+{
+ request->opcode = CTDB_CONTROL_TRAVERSE_START_EXT;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TRAVERSE_START_EXT;
+ request->rdata.data.traverse_start_ext = traverse;
+}
+
+int ctdb_reply_control_traverse_start_ext(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_TRAVERSE_START_EXT);
+}
+
+/* CTDB_CONTROL_GET_DB_STATISTICS */
+
+void ctdb_req_control_get_db_statistics(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_GET_DB_STATISTICS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_DB_STATISTICS;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_get_db_statistics(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_db_statistics **dbstats)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_DB_STATISTICS) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *dbstats = talloc_steal(mem_ctx, reply->rdata.data.dbstats);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_SET_DB_STICKY */
+
+void ctdb_req_control_set_db_sticky(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_SET_DB_STICKY;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_SET_DB_STICKY;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_set_db_sticky(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_DB_STICKY);
+}
+
+/* CTDB_CONTROL_RELOAD_PUBLIC_IPS */
+
+void ctdb_req_control_reload_public_ips(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_RELOAD_PUBLIC_IPS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_RELOAD_PUBLIC_IPS;
+}
+
+int ctdb_reply_control_reload_public_ips(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_RELOAD_PUBLIC_IPS);
+}
+
+/* CTDB_CONTROL_TRAVERSE_ALL_EXT */
+
+/* CTDB_CONTROL_IPREALLOCATED */
+
+void ctdb_req_control_ipreallocated(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_IPREALLOCATED;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_IPREALLOCATED;
+}
+
+int ctdb_reply_control_ipreallocated(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_IPREALLOCATED);
+}
+
+/* CTDB_CONTROL_GET_RUNSTATE */
+
+void ctdb_req_control_get_runstate(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_RUNSTATE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_RUNSTATE;
+}
+
+int ctdb_reply_control_get_runstate(struct ctdb_reply_control *reply,
+ enum ctdb_runstate *runstate)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_RUNSTATE) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *runstate = reply->rdata.data.runstate;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_DETACH */
+
+void ctdb_req_control_db_detach(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_DETACH;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_DETACH;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_detach(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_DETACH);
+}
+
+/* CTDB_CONTROL_GET_NODES_FILE */
+
+void ctdb_req_control_get_nodes_file(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_GET_NODES_FILE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_GET_NODES_FILE;
+}
+
+int ctdb_reply_control_get_nodes_file(struct ctdb_reply_control *reply,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_node_map **nodemap)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_GET_NODES_FILE) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *nodemap = talloc_steal(mem_ctx, reply->rdata.data.nodemap);
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_FREEZE */
+
+void ctdb_req_control_db_freeze(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_FREEZE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_FREEZE;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_freeze(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_FREEZE);
+}
+
+/* CTDB_CONTROL_DB_THAW */
+
+void ctdb_req_control_db_thaw(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_THAW;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_THAW;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_thaw(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_THAW);
+}
+
+/* CTDB_CONTROL_DB_TRANSACTION_START */
+
+void ctdb_req_control_db_transaction_start(struct ctdb_req_control *request,
+ struct ctdb_transdb *transdb)
+{
+ request->opcode = CTDB_CONTROL_DB_TRANSACTION_START;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_TRANSACTION_START;
+ request->rdata.data.transdb = transdb;
+}
+
+int ctdb_reply_control_db_transaction_start(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_DB_TRANSACTION_START);
+}
+
+/* CTDB_CONTROL_DB_TRANSACTION_COMMIT */
+
+void ctdb_req_control_db_transaction_commit(struct ctdb_req_control *request,
+ struct ctdb_transdb *transdb)
+{
+ request->opcode = CTDB_CONTROL_DB_TRANSACTION_COMMIT;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_TRANSACTION_COMMIT;
+ request->rdata.data.transdb = transdb;
+}
+
+int ctdb_reply_control_db_transaction_commit(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_DB_TRANSACTION_COMMIT);
+}
+
+/* CTDB_CONTROL_DB_TRANSACTION_CANCEL */
+
+void ctdb_req_control_db_transaction_cancel(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_TRANSACTION_CANCEL;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_TRANSACTION_CANCEL;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_transaction_cancel(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply,
+ CTDB_CONTROL_DB_TRANSACTION_CANCEL);
+}
+
+/* CTDB_CONTROL_DB_PULL */
+
+void ctdb_req_control_db_pull(struct ctdb_req_control *request,
+ struct ctdb_pulldb_ext *pulldb_ext)
+{
+ request->opcode = CTDB_CONTROL_DB_PULL;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_PULL;
+ request->rdata.data.pulldb_ext = pulldb_ext;
+}
+
+int ctdb_reply_control_db_pull(struct ctdb_reply_control *reply,
+ uint32_t *num_records)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_PULL) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *num_records = reply->rdata.data.num_records;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_PUSH_START */
+
+void ctdb_req_control_db_push_start(struct ctdb_req_control *request,
+ struct ctdb_pulldb_ext *pulldb_ext)
+{
+ request->opcode = CTDB_CONTROL_DB_PUSH_START;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_PUSH_START;
+ request->rdata.data.pulldb_ext = pulldb_ext;
+}
+
+int ctdb_reply_control_db_push_start(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_PUSH_START);
+}
+
+/* CTDB_CONTROL_DB_PUSH_CONFIRM */
+
+void ctdb_req_control_db_push_confirm(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_PUSH_CONFIRM;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_PUSH_CONFIRM;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_push_confirm(struct ctdb_reply_control *reply,
+ uint32_t *num_records)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_PUSH_CONFIRM) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *num_records = reply->rdata.data.num_records;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_OPEN_FLAGS */
+
+void ctdb_req_control_db_open_flags(struct ctdb_req_control *request,
+ uint32_t db_id)
+{
+ request->opcode = CTDB_CONTROL_DB_OPEN_FLAGS;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_OPEN_FLAGS;
+ request->rdata.data.db_id = db_id;
+}
+
+int ctdb_reply_control_db_open_flags(struct ctdb_reply_control *reply,
+ int *tdb_flags)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_OPEN_FLAGS) {
+ return EPROTO;
+ }
+
+ if (reply->status == 0) {
+ *tdb_flags = reply->rdata.data.tdb_flags;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_ATTACH_REPLICATED */
+
+void ctdb_req_control_db_attach_replicated(struct ctdb_req_control *request,
+ const char *db_name)
+{
+ request->opcode = CTDB_CONTROL_DB_ATTACH_REPLICATED;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_ATTACH_REPLICATED;
+ request->rdata.data.db_name = db_name;
+}
+
+int ctdb_reply_control_db_attach_replicated(struct ctdb_reply_control *reply,
+ uint32_t *db_id)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_ATTACH_REPLICATED) {
+ return EPROTO;
+ }
+ if (reply->status == 0) {
+ *db_id = reply->rdata.data.db_id;
+ }
+ return reply->status;
+}
+
+/* CTDB_CONTROL_CHECK_PID_SRVID */
+
+void ctdb_req_control_check_pid_srvid(struct ctdb_req_control *request,
+ struct ctdb_pid_srvid *pid_srvid)
+{
+ request->opcode = CTDB_CONTROL_CHECK_PID_SRVID;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_CHECK_PID_SRVID;
+ request->rdata.data.pid_srvid = pid_srvid;
+}
+
+int ctdb_reply_control_check_pid_srvid(struct ctdb_reply_control *reply,
+ int *status)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_CHECK_PID_SRVID) {
+ return EPROTO;
+ }
+
+ *status = reply->status;
+ reply->status = 0;
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_TUNNEL_REGISTER */
+
+void ctdb_req_control_tunnel_register(struct ctdb_req_control *request,
+ uint64_t tunnel_id)
+{
+ request->opcode = CTDB_CONTROL_TUNNEL_REGISTER;
+ request->pad = 0;
+ request->srvid = tunnel_id;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TUNNEL_REGISTER;
+}
+
+int ctdb_reply_control_tunnel_register(struct ctdb_reply_control *reply)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_TUNNEL_REGISTER) {
+ return EPROTO;
+ }
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_TUNNEL_DEREGISTER */
+
+void ctdb_req_control_tunnel_deregister(struct ctdb_req_control *request,
+ uint64_t tunnel_id)
+{
+ request->opcode = CTDB_CONTROL_TUNNEL_DEREGISTER;
+ request->pad = 0;
+ request->srvid = tunnel_id;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_TUNNEL_DEREGISTER;
+}
+
+int ctdb_reply_control_tunnel_deregister(struct ctdb_reply_control *reply)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_TUNNEL_DEREGISTER) {
+ return EPROTO;
+ }
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_VACUUM_FETCH */
+
+void ctdb_req_control_vacuum_fetch(struct ctdb_req_control *request,
+ struct ctdb_rec_buffer *recbuf)
+{
+ request->opcode = CTDB_CONTROL_VACUUM_FETCH;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_VACUUM_FETCH;
+ request->rdata.data.recbuf = recbuf;
+}
+
+int ctdb_reply_control_vacuum_fetch(struct ctdb_reply_control *reply)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_VACUUM_FETCH) {
+ return EPROTO;
+ }
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DB_VACUUM */
+
+void ctdb_req_control_db_vacuum(struct ctdb_req_control *request,
+ struct ctdb_db_vacuum *db_vacuum)
+{
+ request->opcode = CTDB_CONTROL_DB_VACUUM;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DB_VACUUM;
+ request->rdata.data.db_vacuum = db_vacuum;
+}
+
+int ctdb_reply_control_db_vacuum(struct ctdb_reply_control *reply)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_DB_VACUUM) {
+ return EPROTO;
+ }
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_ECHO_DATA */
+
+void ctdb_req_control_echo_data(struct ctdb_req_control *request,
+ struct ctdb_echo_data *echo_data)
+{
+ request->opcode = CTDB_CONTROL_ECHO_DATA;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_ECHO_DATA;
+ request->rdata.data.echo_data = echo_data;
+}
+
+int ctdb_reply_control_echo_data(struct ctdb_reply_control *reply)
+{
+ if (reply->rdata.opcode != CTDB_CONTROL_ECHO_DATA) {
+ return EPROTO;
+ }
+
+ return reply->status;
+}
+
+/* CTDB_CONTROL_DISABLE_NODE */
+
+void ctdb_req_control_disable_node(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_DISABLE_NODE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_DISABLE_NODE;
+}
+
+int ctdb_reply_control_disable_node(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_DISABLE_NODE);
+}
+
+/* CTDB_CONTROL_ENABLE_NODE */
+
+void ctdb_req_control_enable_node(struct ctdb_req_control *request)
+{
+ request->opcode = CTDB_CONTROL_ENABLE_NODE;
+ request->pad = 0;
+ request->srvid = 0;
+ request->client_id = 0;
+ request->flags = 0;
+
+ request->rdata.opcode = CTDB_CONTROL_ENABLE_NODE;
+}
+
+int ctdb_reply_control_enable_node(struct ctdb_reply_control *reply)
+{
+ return ctdb_reply_control_generic(reply, CTDB_CONTROL_ENABLE_NODE);
+}
diff --git a/ctdb/protocol/protocol_control.c b/ctdb/protocol/protocol_control.c
new file mode 100644
index 0000000..a7c797f
--- /dev/null
+++ b/ctdb/protocol/protocol_control.c
@@ -0,0 +1,1998 @@
+/*
+ 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"
+
+static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
+{
+ size_t len = 0;
+ uint32_t u32;
+
+ if (cd == NULL) {
+ return 0;
+ }
+
+ switch (cd->opcode) {
+ case CTDB_CONTROL_PROCESS_EXISTS:
+ len = ctdb_pid_len(&cd->data.pid);
+ break;
+
+ case CTDB_CONTROL_STATISTICS:
+ break;
+
+ case CTDB_CONTROL_PING:
+ break;
+
+ case CTDB_CONTROL_GETDBPATH:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_GETVNNMAP:
+ break;
+
+ case CTDB_CONTROL_SETVNNMAP:
+ len = ctdb_vnn_map_len(cd->data.vnnmap);
+ break;
+
+ case CTDB_CONTROL_GET_DEBUG:
+ break;
+
+ case CTDB_CONTROL_SET_DEBUG:
+ len = ctdb_uint32_len(&cd->data.loglevel);
+ break;
+
+ case CTDB_CONTROL_GET_DBMAP:
+ break;
+
+ case CTDB_CONTROL_GET_RECMODE:
+ break;
+
+ case CTDB_CONTROL_SET_RECMODE:
+ len = ctdb_uint32_len(&cd->data.recmode);
+ break;
+
+ case CTDB_CONTROL_STATISTICS_RESET:
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH:
+ len = ctdb_string_len(&cd->data.db_name);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START:
+ len = ctdb_traverse_start_len(cd->data.traverse_start);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL:
+ len = ctdb_traverse_all_len(cd->data.traverse_all);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_DATA:
+ len = ctdb_rec_data_len(cd->data.rec_data);
+ break;
+
+ case CTDB_CONTROL_REGISTER_SRVID:
+ break;
+
+ case CTDB_CONTROL_DEREGISTER_SRVID:
+ break;
+
+ case CTDB_CONTROL_GET_DBNAME:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_ENABLE_SEQNUM:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_UPDATE_SEQNUM:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DUMP_MEMORY:
+ break;
+
+ case CTDB_CONTROL_GET_PID:
+ break;
+
+ case CTDB_CONTROL_FREEZE:
+ break;
+
+ case CTDB_CONTROL_GET_PNN:
+ break;
+
+ case CTDB_CONTROL_SHUTDOWN:
+ break;
+
+ case CTDB_CONTROL_TCP_CLIENT:
+ len = ctdb_connection_len(cd->data.conn);
+ break;
+
+ case CTDB_CONTROL_TCP_ADD:
+ len = ctdb_connection_len(cd->data.conn);
+ break;
+
+ case CTDB_CONTROL_TCP_REMOVE:
+ len = ctdb_connection_len(cd->data.conn);
+ break;
+
+ case CTDB_CONTROL_STARTUP:
+ break;
+
+ case CTDB_CONTROL_SET_TUNABLE:
+ len = ctdb_tunable_len(cd->data.tunable);
+ break;
+
+ case CTDB_CONTROL_GET_TUNABLE:
+ len = ctdb_stringn_len(&cd->data.tun_var);
+ break;
+
+ case CTDB_CONTROL_LIST_TUNABLES:
+ break;
+
+ case CTDB_CONTROL_MODIFY_FLAGS:
+ len = ctdb_node_flag_change_len(cd->data.flag_change);
+ break;
+
+ case CTDB_CONTROL_GET_ALL_TUNABLES:
+ break;
+
+ case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
+ len = ctdb_sock_addr_len(cd->data.addr);
+ break;
+
+ case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
+ len = ctdb_tickle_list_len(cd->data.tickles);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
+ len = ctdb_string_len(&cd->data.db_name);
+ break;
+
+ case CTDB_CONTROL_UPDATE_RECORD:
+ len = ctdb_rec_buffer_len(cd->data.recbuf);
+ break;
+
+ case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
+ len = ctdb_addr_info_len(cd->data.addr_info);
+ break;
+
+ case CTDB_CONTROL_WIPE_DATABASE:
+ len = ctdb_transdb_len(cd->data.transdb);
+ break;
+
+ case CTDB_CONTROL_UPTIME:
+ break;
+
+ case CTDB_CONTROL_START_RECOVERY:
+ break;
+
+ case CTDB_CONTROL_END_RECOVERY:
+ break;
+
+ case CTDB_CONTROL_RELOAD_NODES_FILE:
+ break;
+
+ case CTDB_CONTROL_TRY_DELETE_RECORDS:
+ len = ctdb_rec_buffer_len(cd->data.recbuf);
+ break;
+
+ case CTDB_CONTROL_ADD_PUBLIC_IP:
+ len = ctdb_addr_info_len(cd->data.addr_info);
+ break;
+
+ case CTDB_CONTROL_DEL_PUBLIC_IP:
+ len = ctdb_addr_info_len(cd->data.addr_info);
+ break;
+
+ case CTDB_CONTROL_GET_CAPABILITIES:
+ break;
+
+ case CTDB_CONTROL_RECD_PING:
+ break;
+
+ case CTDB_CONTROL_RELEASE_IP:
+ len = ctdb_public_ip_len(cd->data.pubip);
+ break;
+
+ case CTDB_CONTROL_TAKEOVER_IP:
+ len = ctdb_public_ip_len(cd->data.pubip);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IPS:
+ break;
+
+ case CTDB_CONTROL_GET_NODEMAP:
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_KILL:
+ len = ctdb_traverse_start_len(cd->data.traverse_start);
+ break;
+
+ case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
+ len = ctdb_double_len(&cd->data.reclock_latency);
+ break;
+
+ case CTDB_CONTROL_GET_RECLOCK_FILE:
+ break;
+
+ case CTDB_CONTROL_STOP_NODE:
+ break;
+
+ case CTDB_CONTROL_CONTINUE_NODE:
+ break;
+
+ case CTDB_CONTROL_SET_LMASTERROLE:
+ len = ctdb_uint32_len(&cd->data.role);
+ break;
+
+ case CTDB_CONTROL_SET_RECMASTERROLE:
+ len = ctdb_uint32_len(&cd->data.role);
+ break;
+
+ case CTDB_CONTROL_SET_BAN_STATE:
+ len = ctdb_ban_state_len(cd->data.ban_state);
+ break;
+
+ case CTDB_CONTROL_GET_BAN_STATE:
+ break;
+
+ case CTDB_CONTROL_REGISTER_NOTIFY:
+ len = ctdb_notify_data_len(cd->data.notify);
+ break;
+
+ case CTDB_CONTROL_DEREGISTER_NOTIFY:
+ len = ctdb_uint64_len(&cd->data.srvid);
+ break;
+
+ case CTDB_CONTROL_TRANS3_COMMIT:
+ len = ctdb_rec_buffer_len(cd->data.recbuf);
+ break;
+
+ case CTDB_CONTROL_GET_DB_SEQNUM:
+ u32 = 0;
+ len = ctdb_uint32_len(&cd->data.db_id) + ctdb_uint32_len(&u32);
+ break;
+
+ case CTDB_CONTROL_DB_SET_HEALTHY:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DB_GET_HEALTH:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
+ len = ctdb_sock_addr_len(cd->data.addr);
+ break;
+
+ case CTDB_CONTROL_GET_IFACES:
+ break;
+
+ case CTDB_CONTROL_SET_IFACE_LINK_STATE:
+ len = ctdb_iface_len(cd->data.iface);
+ break;
+
+ case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
+ len = ctdb_connection_len(cd->data.conn);
+ break;
+
+ case CTDB_CONTROL_GET_STAT_HISTORY:
+ break;
+
+ case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
+ len = ctdb_key_data_len(cd->data.key);
+ break;
+
+ case CTDB_CONTROL_SET_DB_READONLY:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START_EXT:
+ len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
+ break;
+
+ case CTDB_CONTROL_GET_DB_STATISTICS:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_SET_DB_STICKY:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL_EXT:
+ len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
+ break;
+
+ case CTDB_CONTROL_IPREALLOCATED:
+ break;
+
+ case CTDB_CONTROL_GET_RUNSTATE:
+ break;
+
+ case CTDB_CONTROL_DB_DETACH:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_GET_NODES_FILE:
+ break;
+
+ case CTDB_CONTROL_DB_FREEZE:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DB_THAW:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_START:
+ len = ctdb_transdb_len(cd->data.transdb);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
+ len = ctdb_transdb_len(cd->data.transdb);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DB_PULL:
+ len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_START:
+ len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_CONFIRM:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DB_OPEN_FLAGS:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_REPLICATED:
+ len = ctdb_string_len(&cd->data.db_name);
+ break;
+
+ case CTDB_CONTROL_CHECK_PID_SRVID:
+ len = ctdb_pid_srvid_len(cd->data.pid_srvid);
+ break;
+
+ case CTDB_CONTROL_TUNNEL_REGISTER:
+ break;
+
+ case CTDB_CONTROL_TUNNEL_DEREGISTER:
+ break;
+
+ case CTDB_CONTROL_VACUUM_FETCH:
+ len = ctdb_rec_buffer_len(cd->data.recbuf);
+ break;
+
+ case CTDB_CONTROL_DB_VACUUM:
+ len = ctdb_db_vacuum_len(cd->data.db_vacuum);
+ break;
+
+ case CTDB_CONTROL_ECHO_DATA:
+ len = ctdb_echo_data_len(cd->data.echo_data);
+ break;
+
+ case CTDB_CONTROL_DISABLE_NODE:
+ break;
+
+ case CTDB_CONTROL_ENABLE_NODE:
+ break;
+ }
+
+ return len;
+}
+
+static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
+ uint8_t *buf, size_t *npush)
+{
+ size_t np = 0, offset;
+ uint32_t u32;
+
+ switch (cd->opcode) {
+ case CTDB_CONTROL_PROCESS_EXISTS:
+ ctdb_pid_push(&cd->data.pid, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GETDBPATH:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SETVNNMAP:
+ ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_DEBUG:
+ ctdb_uint32_push(&cd->data.loglevel, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_RECMODE:
+ ctdb_uint32_push(&cd->data.recmode, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH:
+ ctdb_string_push(&cd->data.db_name, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START:
+ ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL:
+ ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_DATA:
+ ctdb_rec_data_push(cd->data.rec_data, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DBNAME:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_ENABLE_SEQNUM:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_UPDATE_SEQNUM:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_CLIENT:
+ ctdb_connection_push(cd->data.conn, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_ADD:
+ ctdb_connection_push(cd->data.conn, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_REMOVE:
+ ctdb_connection_push(cd->data.conn, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_TUNABLE:
+ ctdb_tunable_push(cd->data.tunable, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_TUNABLE:
+ ctdb_stringn_push(&cd->data.tun_var, buf, &np);
+ break;
+
+ case CTDB_CONTROL_MODIFY_FLAGS:
+ ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
+ ctdb_sock_addr_push(cd->data.addr, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
+ ctdb_tickle_list_push(cd->data.tickles, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
+ ctdb_string_push(&cd->data.db_name, buf, &np);
+ break;
+
+ case CTDB_CONTROL_UPDATE_RECORD:
+ ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
+ ctdb_addr_info_push(cd->data.addr_info, buf, &np);
+ break;
+
+ case CTDB_CONTROL_WIPE_DATABASE:
+ ctdb_transdb_push(cd->data.transdb, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRY_DELETE_RECORDS:
+ ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
+ break;
+
+ case CTDB_CONTROL_ADD_PUBLIC_IP:
+ ctdb_addr_info_push(cd->data.addr_info, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DEL_PUBLIC_IP:
+ ctdb_addr_info_push(cd->data.addr_info, buf, &np);
+ break;
+
+ case CTDB_CONTROL_RELEASE_IP:
+ ctdb_public_ip_push(cd->data.pubip, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TAKEOVER_IP:
+ ctdb_public_ip_push(cd->data.pubip, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_KILL:
+ ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
+ break;
+
+ case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
+ ctdb_double_push(&cd->data.reclock_latency, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_LMASTERROLE:
+ ctdb_uint32_push(&cd->data.role, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_RECMASTERROLE:
+ ctdb_uint32_push(&cd->data.role, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_BAN_STATE:
+ ctdb_ban_state_push(cd->data.ban_state, buf, &np);
+ break;
+
+ case CTDB_CONTROL_REGISTER_NOTIFY:
+ ctdb_notify_data_push(cd->data.notify, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DEREGISTER_NOTIFY:
+ ctdb_uint64_push(&cd->data.srvid, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRANS3_COMMIT:
+ ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_SEQNUM:
+ u32 = 0;
+ offset = 0;
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ offset += np;
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+ np = offset;
+ break;
+
+ case CTDB_CONTROL_DB_SET_HEALTHY:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_GET_HEALTH:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
+ ctdb_sock_addr_push(cd->data.addr, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_IFACE_LINK_STATE:
+ ctdb_iface_push(cd->data.iface, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
+ ctdb_connection_push(cd->data.conn, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
+ ctdb_key_data_push(cd->data.key, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_DB_READONLY:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START_EXT:
+ ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
+ &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_STATISTICS:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_SET_DB_STICKY:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL_EXT:
+ ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
+ &np);
+ break;
+
+ case CTDB_CONTROL_DB_DETACH:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_FREEZE:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_THAW:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_START:
+ ctdb_transdb_push(cd->data.transdb, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
+ ctdb_transdb_push(cd->data.transdb, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PULL:
+ ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_START:
+ ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_CONFIRM:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_OPEN_FLAGS:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_REPLICATED:
+ ctdb_string_push(&cd->data.db_name, buf, &np);
+ break;
+
+ case CTDB_CONTROL_CHECK_PID_SRVID:
+ ctdb_pid_srvid_push(cd->data.pid_srvid, buf, &np);
+ break;
+
+ case CTDB_CONTROL_VACUUM_FETCH:
+ ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_VACUUM:
+ ctdb_db_vacuum_push(cd->data.db_vacuum, buf, &np);
+ break;
+
+ case CTDB_CONTROL_ECHO_DATA:
+ ctdb_echo_data_push(cd->data.echo_data, buf, &np);
+ break;
+ }
+
+ *npush = np;
+}
+
+static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
+ uint32_t opcode,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_control_data *cd,
+ size_t *npull)
+{
+ size_t np = 0, offset;
+ uint32_t u32;
+ int ret = 0;
+
+ cd->opcode = opcode;
+
+ switch (opcode) {
+ case CTDB_CONTROL_PROCESS_EXISTS:
+ ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
+ break;
+
+ case CTDB_CONTROL_GETDBPATH:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_SETVNNMAP:
+ ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
+ &cd->data.vnnmap, &np);
+ break;
+
+ case CTDB_CONTROL_SET_DEBUG:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
+ break;
+
+ case CTDB_CONTROL_SET_RECMODE:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.db_name, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START:
+ ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
+ &cd->data.traverse_start, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL:
+ ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
+ &cd->data.traverse_all, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_DATA:
+ ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
+ &cd->data.rec_data, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DBNAME:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_ENABLE_SEQNUM:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_UPDATE_SEQNUM:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_CLIENT:
+ ret = ctdb_connection_pull(buf, buflen, mem_ctx,
+ &cd->data.conn, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_ADD:
+ ret = ctdb_connection_pull(buf, buflen, mem_ctx,
+ &cd->data.conn, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_REMOVE:
+ ret = ctdb_connection_pull(buf, buflen, mem_ctx,
+ &cd->data.conn, &np);
+ break;
+
+ case CTDB_CONTROL_SET_TUNABLE:
+ ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
+ &cd->data.tunable, &np);
+ break;
+
+ case CTDB_CONTROL_GET_TUNABLE:
+ ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
+ &cd->data.tun_var, &np);
+ break;
+
+ case CTDB_CONTROL_MODIFY_FLAGS:
+ ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
+ &cd->data.flag_change, &np);
+ break;
+
+ case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
+ ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
+ &cd->data.addr, &np);
+ break;
+
+ case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
+ ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
+ &cd->data.tickles, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.db_name, &np);
+ break;
+
+ case CTDB_CONTROL_UPDATE_RECORD:
+ ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
+ &cd->data.recbuf, &np);
+ break;
+
+ case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
+ ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
+ &cd->data.addr_info, &np);
+ break;
+
+ case CTDB_CONTROL_WIPE_DATABASE:
+ ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
+ &cd->data.transdb, &np);
+ break;
+
+ case CTDB_CONTROL_TRY_DELETE_RECORDS:
+ ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
+ &cd->data.recbuf, &np);
+ break;
+
+ case CTDB_CONTROL_ADD_PUBLIC_IP:
+ ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
+ &cd->data.addr_info, &np);
+ break;
+
+ case CTDB_CONTROL_DEL_PUBLIC_IP:
+ ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
+ &cd->data.addr_info, &np);
+ break;
+
+ case CTDB_CONTROL_RELEASE_IP:
+ ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
+ &cd->data.pubip, &np);
+ break;
+
+ case CTDB_CONTROL_TAKEOVER_IP:
+ ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
+ &cd->data.pubip, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_KILL:
+ ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
+ &cd->data.traverse_start, &np);
+ break;
+
+ case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
+ ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
+ &np);
+ break;
+
+ case CTDB_CONTROL_SET_LMASTERROLE:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
+ break;
+
+ case CTDB_CONTROL_SET_RECMASTERROLE:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
+ break;
+
+ case CTDB_CONTROL_SET_BAN_STATE:
+ ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
+ &cd->data.ban_state, &np);
+ break;
+
+ case CTDB_CONTROL_REGISTER_NOTIFY:
+ ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
+ &cd->data.notify, &np);
+ break;
+
+ case CTDB_CONTROL_DEREGISTER_NOTIFY:
+ ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
+ break;
+
+ case CTDB_CONTROL_TRANS3_COMMIT:
+ ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
+ &cd->data.recbuf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_SEQNUM:
+ offset = 0;
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ if (ret != 0) {
+ break;
+ }
+ offset += np;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ offset += np;
+ np = offset;
+ break;
+
+ case CTDB_CONTROL_DB_SET_HEALTHY:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_GET_HEALTH:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
+ ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
+ &cd->data.addr, &np);
+ break;
+
+ case CTDB_CONTROL_SET_IFACE_LINK_STATE:
+ ret = ctdb_iface_pull(buf, buflen, mem_ctx,
+ &cd->data.iface, &np);
+ break;
+
+ case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
+ ret = ctdb_connection_pull(buf, buflen, mem_ctx,
+ &cd->data.conn, &np);
+ break;
+
+ case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
+ ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
+ &cd->data.key, &np);
+ break;
+
+ case CTDB_CONTROL_SET_DB_READONLY:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START_EXT:
+ ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
+ &cd->data.traverse_start_ext,
+ &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_STATISTICS:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_SET_DB_STICKY:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL_EXT:
+ ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
+ &cd->data.traverse_all_ext,
+ &np);
+ break;
+
+ case CTDB_CONTROL_DB_DETACH:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_FREEZE:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_THAW:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_START:
+ ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
+ &cd->data.transdb, &np);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
+ ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
+ &cd->data.transdb, &np);
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PULL:
+ ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
+ &cd->data.pulldb_ext, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_START:
+ ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
+ &cd->data.pulldb_ext, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_CONFIRM:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_OPEN_FLAGS:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_REPLICATED:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.db_name, &np);
+ break;
+
+ case CTDB_CONTROL_CHECK_PID_SRVID:
+ ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
+ &cd->data.pid_srvid, &np);
+ break;
+
+ case CTDB_CONTROL_VACUUM_FETCH:
+ ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
+ &cd->data.recbuf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_VACUUM:
+ ret = ctdb_db_vacuum_pull(buf,
+ buflen,
+ mem_ctx,
+ &cd->data.db_vacuum,
+ &np);
+ break;
+
+ case CTDB_CONTROL_ECHO_DATA:
+ ret = ctdb_echo_data_pull(buf,
+ buflen,
+ mem_ctx,
+ &cd->data.echo_data,
+ &np);
+ break;
+ }
+
+ if (ret != 0) {
+ return ret;
+ }
+
+ *npull = np;
+ return 0;
+}
+
+static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
+{
+ size_t len = 0;
+
+ if (cd == NULL) {
+ return 0;
+ }
+
+ switch (cd->opcode) {
+ case CTDB_CONTROL_PROCESS_EXISTS:
+ break;
+
+ case CTDB_CONTROL_STATISTICS:
+ len = ctdb_statistics_len(cd->data.stats);
+ break;
+
+ case CTDB_CONTROL_PING:
+ break;
+
+ case CTDB_CONTROL_GETDBPATH:
+ len = ctdb_string_len(&cd->data.db_path);
+ break;
+
+ case CTDB_CONTROL_GETVNNMAP:
+ len = ctdb_vnn_map_len(cd->data.vnnmap);
+ break;
+
+ case CTDB_CONTROL_SETVNNMAP:
+ break;
+
+ case CTDB_CONTROL_GET_DEBUG:
+ len = ctdb_uint32_len(&cd->data.loglevel);
+ break;
+
+ case CTDB_CONTROL_SET_DEBUG:
+ break;
+
+ case CTDB_CONTROL_GET_DBMAP:
+ len = ctdb_dbid_map_len(cd->data.dbmap);
+ break;
+
+ case CTDB_CONTROL_GET_RECMODE:
+ break;
+
+ case CTDB_CONTROL_SET_RECMODE:
+ break;
+
+ case CTDB_CONTROL_STATISTICS_RESET:
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START:
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL:
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_DATA:
+ break;
+
+ case CTDB_CONTROL_REGISTER_SRVID:
+ break;
+
+ case CTDB_CONTROL_DEREGISTER_SRVID:
+ break;
+
+ case CTDB_CONTROL_GET_DBNAME:
+ len = ctdb_string_len(&cd->data.db_name);
+ break;
+
+ case CTDB_CONTROL_ENABLE_SEQNUM:
+ break;
+
+ case CTDB_CONTROL_UPDATE_SEQNUM:
+ break;
+
+ case CTDB_CONTROL_DUMP_MEMORY:
+ len = ctdb_string_len(&cd->data.mem_str);
+ break;
+
+ case CTDB_CONTROL_GET_PID:
+ break;
+
+ case CTDB_CONTROL_FREEZE:
+ break;
+
+ case CTDB_CONTROL_GET_PNN:
+ break;
+
+ case CTDB_CONTROL_SHUTDOWN:
+ break;
+
+ case CTDB_CONTROL_TCP_CLIENT:
+ break;
+
+ case CTDB_CONTROL_TCP_ADD:
+ break;
+
+ case CTDB_CONTROL_TCP_REMOVE:
+ break;
+
+ case CTDB_CONTROL_STARTUP:
+ break;
+
+ case CTDB_CONTROL_SET_TUNABLE:
+ break;
+
+ case CTDB_CONTROL_GET_TUNABLE:
+ len = ctdb_uint32_len(&cd->data.tun_value);
+ break;
+
+ case CTDB_CONTROL_LIST_TUNABLES:
+ len = ctdb_var_list_len(cd->data.tun_var_list);
+ break;
+
+ case CTDB_CONTROL_MODIFY_FLAGS:
+ break;
+
+ case CTDB_CONTROL_GET_ALL_TUNABLES:
+ len = ctdb_tunable_list_len(cd->data.tun_list);
+ break;
+
+ case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
+ len = ctdb_tickle_list_len(cd->data.tickles);
+ break;
+
+ case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_UPDATE_RECORD:
+ break;
+
+ case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
+ break;
+
+ case CTDB_CONTROL_WIPE_DATABASE:
+ break;
+
+ case CTDB_CONTROL_UPTIME:
+ len = ctdb_uptime_len(cd->data.uptime);
+ break;
+
+ case CTDB_CONTROL_START_RECOVERY:
+ break;
+
+ case CTDB_CONTROL_END_RECOVERY:
+ break;
+
+ case CTDB_CONTROL_RELOAD_NODES_FILE:
+ break;
+
+ case CTDB_CONTROL_TRY_DELETE_RECORDS:
+ len = ctdb_rec_buffer_len(cd->data.recbuf);
+ break;
+
+ case CTDB_CONTROL_ADD_PUBLIC_IP:
+ break;
+
+ case CTDB_CONTROL_DEL_PUBLIC_IP:
+ break;
+
+ case CTDB_CONTROL_GET_CAPABILITIES:
+ len = ctdb_uint32_len(&cd->data.caps);
+ break;
+
+ case CTDB_CONTROL_RECD_PING:
+ break;
+
+ case CTDB_CONTROL_RELEASE_IP:
+ break;
+
+ case CTDB_CONTROL_TAKEOVER_IP:
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IPS:
+ len = ctdb_public_ip_list_len(cd->data.pubip_list);
+ break;
+
+ case CTDB_CONTROL_GET_NODEMAP:
+ len = ctdb_node_map_len(cd->data.nodemap);
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_KILL:
+ break;
+
+ case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
+ break;
+
+ case CTDB_CONTROL_GET_RECLOCK_FILE:
+ len = ctdb_string_len(&cd->data.reclock_file);
+ break;
+
+ case CTDB_CONTROL_STOP_NODE:
+ break;
+
+ case CTDB_CONTROL_CONTINUE_NODE:
+ break;
+
+ case CTDB_CONTROL_SET_LMASTERROLE:
+ break;
+
+ case CTDB_CONTROL_SET_RECMASTERROLE:
+ break;
+
+ case CTDB_CONTROL_SET_BAN_STATE:
+ break;
+
+ case CTDB_CONTROL_GET_BAN_STATE:
+ len = ctdb_ban_state_len(cd->data.ban_state);
+ break;
+
+ case CTDB_CONTROL_REGISTER_NOTIFY:
+ break;
+
+ case CTDB_CONTROL_DEREGISTER_NOTIFY:
+ break;
+
+ case CTDB_CONTROL_TRANS3_COMMIT:
+ break;
+
+ case CTDB_CONTROL_GET_DB_SEQNUM:
+ len = ctdb_uint64_len(&cd->data.seqnum);
+ break;
+
+ case CTDB_CONTROL_DB_SET_HEALTHY:
+ break;
+
+ case CTDB_CONTROL_DB_GET_HEALTH:
+ len = ctdb_string_len(&cd->data.reason);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
+ len = ctdb_public_ip_info_len(cd->data.ipinfo);
+ break;
+
+ case CTDB_CONTROL_GET_IFACES:
+ len = ctdb_iface_list_len(cd->data.iface_list);
+ break;
+
+ case CTDB_CONTROL_SET_IFACE_LINK_STATE:
+ break;
+
+ case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
+ break;
+
+ case CTDB_CONTROL_GET_STAT_HISTORY:
+ len = ctdb_statistics_list_len(cd->data.stats_list);
+ break;
+
+ case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
+ break;
+
+ case CTDB_CONTROL_SET_DB_READONLY:
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_START_EXT:
+ break;
+
+ case CTDB_CONTROL_GET_DB_STATISTICS:
+ len = ctdb_db_statistics_len(cd->data.dbstats);
+ break;
+
+ case CTDB_CONTROL_SET_DB_STICKY:
+ break;
+
+ case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
+ break;
+
+ case CTDB_CONTROL_TRAVERSE_ALL_EXT:
+ break;
+
+ case CTDB_CONTROL_IPREALLOCATED:
+ break;
+
+ case CTDB_CONTROL_GET_RUNSTATE:
+ len = ctdb_uint32_len(&cd->data.runstate);
+ break;
+
+ case CTDB_CONTROL_DB_DETACH:
+ break;
+
+ case CTDB_CONTROL_GET_NODES_FILE:
+ len = ctdb_node_map_len(cd->data.nodemap);
+ break;
+
+ case CTDB_CONTROL_DB_FREEZE:
+ break;
+
+ case CTDB_CONTROL_DB_THAW:
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_START:
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
+ break;
+
+ case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
+ break;
+
+ case CTDB_CONTROL_DB_PULL:
+ len = ctdb_uint32_len(&cd->data.num_records);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_START:
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_CONFIRM:
+ len = ctdb_uint32_len(&cd->data.num_records);
+ break;
+
+ case CTDB_CONTROL_DB_OPEN_FLAGS:
+ len = ctdb_int32_len(&cd->data.tdb_flags);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_REPLICATED:
+ len = ctdb_uint32_len(&cd->data.db_id);
+ break;
+
+ case CTDB_CONTROL_CHECK_PID_SRVID:
+ break;
+
+ case CTDB_CONTROL_TUNNEL_REGISTER:
+ break;
+
+ case CTDB_CONTROL_TUNNEL_DEREGISTER:
+ break;
+
+ case CTDB_CONTROL_VACUUM_FETCH:
+ break;
+
+ case CTDB_CONTROL_DB_VACUUM:
+ break;
+
+ case CTDB_CONTROL_ECHO_DATA:
+ len = ctdb_echo_data_len(cd->data.echo_data);
+ break;
+
+ case CTDB_CONTROL_DISABLE_NODE:
+ break;
+
+ case CTDB_CONTROL_ENABLE_NODE:
+ break;
+ }
+
+ return len;
+}
+
+static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
+ uint8_t *buf, size_t *npush)
+{
+ size_t np = 0;
+
+ switch (cd->opcode) {
+ case CTDB_CONTROL_STATISTICS:
+ ctdb_statistics_push(cd->data.stats, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GETDBPATH:
+ ctdb_string_push(&cd->data.db_path, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GETVNNMAP:
+ ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DEBUG:
+ ctdb_uint32_push(&cd->data.loglevel, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DBMAP:
+ ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DBNAME:
+ ctdb_string_push(&cd->data.db_name, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DUMP_MEMORY:
+ ctdb_string_push(&cd->data.mem_str, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PID:
+ break;
+
+ case CTDB_CONTROL_GET_TUNABLE:
+ ctdb_uint32_push(&cd->data.tun_value, buf, &np);
+ break;
+
+ case CTDB_CONTROL_LIST_TUNABLES:
+ ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_ALL_TUNABLES:
+ ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
+ ctdb_tickle_list_push(cd->data.tickles, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_UPTIME:
+ ctdb_uptime_push(cd->data.uptime, buf, &np);
+ break;
+
+ case CTDB_CONTROL_TRY_DELETE_RECORDS:
+ ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_CAPABILITIES:
+ ctdb_uint32_push(&cd->data.caps, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IPS:
+ ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_NODEMAP:
+ ctdb_node_map_push(cd->data.nodemap, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_RECLOCK_FILE:
+ ctdb_string_push(&cd->data.reclock_file, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_BAN_STATE:
+ ctdb_ban_state_push(cd->data.ban_state, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_SEQNUM:
+ ctdb_uint64_push(&cd->data.seqnum, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_GET_HEALTH:
+ ctdb_string_push(&cd->data.reason, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
+ ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_IFACES:
+ ctdb_iface_list_push(cd->data.iface_list, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_STAT_HISTORY:
+ ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_STATISTICS:
+ ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_RUNSTATE:
+ ctdb_uint32_push(&cd->data.runstate, buf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_NODES_FILE:
+ ctdb_node_map_push(cd->data.nodemap, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PULL:
+ ctdb_uint32_push(&cd->data.num_records, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_CONFIRM:
+ ctdb_uint32_push(&cd->data.num_records, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_OPEN_FLAGS:
+ ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_REPLICATED:
+ ctdb_uint32_push(&cd->data.db_id, buf, &np);
+ break;
+
+ case CTDB_CONTROL_CHECK_PID_SRVID:
+ break;
+
+ case CTDB_CONTROL_VACUUM_FETCH:
+ break;
+
+ case CTDB_CONTROL_DB_VACUUM:
+ break;
+
+ case CTDB_CONTROL_ECHO_DATA:
+ ctdb_echo_data_push(cd->data.echo_data, buf, &np);
+ break;
+ }
+
+ *npush = np;
+}
+
+static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
+ uint32_t opcode, TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_control_data *cd,
+ size_t *npull)
+{
+ size_t np = 0;
+ int ret = 0;
+
+ cd->opcode = opcode;
+
+ switch (opcode) {
+ case CTDB_CONTROL_STATISTICS:
+ ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
+ &cd->data.stats, &np);
+ break;
+
+ case CTDB_CONTROL_GETDBPATH:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.db_path, &np);
+ break;
+
+ case CTDB_CONTROL_GETVNNMAP:
+ ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
+ &cd->data.vnnmap, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DEBUG:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DBMAP:
+ ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
+ &cd->data.dbmap, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DBNAME:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.db_name, &np);
+ break;
+
+ case CTDB_CONTROL_DUMP_MEMORY:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.mem_str, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PID:
+ break;
+
+ case CTDB_CONTROL_GET_TUNABLE:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
+ &np);
+ break;
+
+ case CTDB_CONTROL_LIST_TUNABLES:
+ ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
+ &cd->data.tun_var_list, &np);
+ break;
+
+ case CTDB_CONTROL_GET_ALL_TUNABLES:
+ ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
+ &cd->data.tun_list, &np);
+ break;
+
+ case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
+ ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
+ &cd->data.tickles, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_UPTIME:
+ ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
+ &cd->data.uptime, &np);
+ break;
+
+ case CTDB_CONTROL_TRY_DELETE_RECORDS:
+ ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
+ &cd->data.recbuf, &np);
+ break;
+
+ case CTDB_CONTROL_GET_CAPABILITIES:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IPS:
+ ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
+ &cd->data.pubip_list, &np);
+ break;
+
+ case CTDB_CONTROL_GET_NODEMAP:
+ ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
+ &cd->data.nodemap, &np);
+ break;
+
+ case CTDB_CONTROL_GET_RECLOCK_FILE:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.reclock_file, &np);
+ break;
+
+ case CTDB_CONTROL_GET_BAN_STATE:
+ ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
+ &cd->data.ban_state, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_SEQNUM:
+ ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
+ break;
+
+ case CTDB_CONTROL_DB_GET_HEALTH:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx,
+ &cd->data.reason, &np);
+ break;
+
+ case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
+ ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
+ &cd->data.ipinfo, &np);
+ break;
+
+ case CTDB_CONTROL_GET_IFACES:
+ ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
+ &cd->data.iface_list, &np);
+ break;
+
+ case CTDB_CONTROL_GET_STAT_HISTORY:
+ ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
+ &cd->data.stats_list, &np);
+ break;
+
+ case CTDB_CONTROL_GET_DB_STATISTICS:
+ ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
+ &cd->data.dbstats, &np);
+ break;
+
+ case CTDB_CONTROL_GET_RUNSTATE:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
+ break;
+
+ case CTDB_CONTROL_GET_NODES_FILE:
+ ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
+ &cd->data.nodemap, &np);
+ break;
+
+ case CTDB_CONTROL_DB_PULL:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
+ &np);
+ break;
+
+ case CTDB_CONTROL_DB_PUSH_CONFIRM:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
+ &np);
+ break;
+
+ case CTDB_CONTROL_DB_OPEN_FLAGS:
+ ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
+ break;
+
+ case CTDB_CONTROL_DB_ATTACH_REPLICATED:
+ ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
+ break;
+
+ case CTDB_CONTROL_CHECK_PID_SRVID:
+ break;
+
+ case CTDB_CONTROL_VACUUM_FETCH:
+ break;
+
+ case CTDB_CONTROL_DB_VACUUM:
+ break;
+
+ case CTDB_CONTROL_ECHO_DATA:
+ ret = ctdb_echo_data_pull(buf,
+ buflen,
+ mem_ctx,
+ &cd->data.echo_data,
+ &np);
+ break;
+ }
+
+ if (ret != 0) {
+ return ret;
+ }
+
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_req_control_len(struct ctdb_req_header *h,
+ struct ctdb_req_control *c)
+{
+ uint32_t u32 = 0;
+
+ return ctdb_req_header_len(h) +
+ ctdb_uint32_len(&c->opcode) +
+ ctdb_uint32_len(&c->pad) +
+ ctdb_uint64_len(&c->srvid) +
+ ctdb_uint32_len(&c->client_id) +
+ ctdb_uint32_len(&c->flags) +
+ ctdb_uint32_len(&u32) +
+ ctdb_req_control_data_len(&c->rdata);
+}
+
+int ctdb_req_control_push(struct ctdb_req_header *h,
+ struct ctdb_req_control *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+ uint32_t u32;
+
+ length = ctdb_req_control_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->opcode, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->pad, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&c->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->client_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->flags, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_req_control_data_len(&c->rdata);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
+ offset += np;
+
+ if (offset > *buflen) {
+ return EMSGSIZE;
+ }
+
+ return 0;
+}
+
+int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_control *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (u32 > buflen-offset) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
+ &c->rdata, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (offset > buflen) {
+ return EMSGSIZE;
+ }
+
+ return 0;
+}
+
+size_t ctdb_reply_control_len(struct ctdb_req_header *h,
+ struct ctdb_reply_control *c)
+{
+ uint32_t dsize, esize;
+
+ if (c->status == 0) {
+ dsize = ctdb_reply_control_data_len(&c->rdata);
+ esize = 0;
+ } else {
+ dsize = 0;
+ esize = ctdb_string_len(&c->errmsg);
+ }
+
+ return ctdb_req_header_len(h) +
+ ctdb_int32_len(&c->status) +
+ ctdb_uint32_len(&dsize) +
+ ctdb_uint32_len(&esize) +
+ dsize + esize;
+}
+
+int ctdb_reply_control_push(struct ctdb_req_header *h,
+ struct ctdb_reply_control *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+ uint32_t dsize, esize;
+
+ length = ctdb_reply_control_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_int32_push(&c->status, buf+offset, &np);
+ offset += np;
+
+ if (c->status == 0) {
+ dsize = ctdb_reply_control_data_len(&c->rdata);
+ esize = 0;
+ } else {
+ dsize = 0;
+ esize = ctdb_string_len(&c->errmsg);
+ }
+
+ ctdb_uint32_push(&dsize, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&esize, buf+offset, &np);
+ offset += np;
+
+ if (c->status == 0) {
+ ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
+ } else {
+ ctdb_string_push(&c->errmsg, buf+offset, &np);
+ }
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_reply_control *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ uint32_t dsize, esize;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ c->errmsg = NULL;
+
+ if (c->status == 0) {
+ if (buflen-offset < dsize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_reply_control_data_pull(buf+offset, dsize,
+ opcode, mem_ctx, &c->rdata,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ } else {
+ if (buflen-offset < esize) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_debug.c b/ctdb/protocol/protocol_debug.c
new file mode 100644
index 0000000..d94cb54
--- /dev/null
+++ b/ctdb/protocol/protocol_debug.c
@@ -0,0 +1,742 @@
+/*
+ CTDB 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 "system/locale.h"
+
+#include <talloc.h>
+#include <tdb.h>
+
+#include <protocol/protocol.h>
+#include <protocol/protocol_api.h>
+
+/*
+ * Utility functions
+ */
+struct uint32_map {
+ uint32_t key;
+#define MAP_END 0xffffffff
+ const char *name;
+};
+
+
+static void uint32_map_print(struct uint32_map *map, uint32_t key, FILE *fp)
+{
+ int i = 0;
+
+ while (map[i].key != MAP_END) {
+ if (key == map[i].key) {
+ fprintf(fp, "%s", map[i].name);
+ return;
+ }
+ i = i+1;
+ }
+
+ fprintf(fp, "UNKNOWN(%u)", key);
+}
+
+static void tdb_data_print(TDB_DATA d, FILE *fp)
+{
+ unsigned char *p = (unsigned char *)d.dptr;
+ int len = d.dsize;
+ while (len--) {
+ if (isprint(*p) && !strchr("\"\\", *p)) {
+ fputc(*p, fp);
+ } else {
+ fprintf(fp, "\\%02X", *p);
+ }
+ p++;
+ }
+}
+
+/*
+ * Data types
+ */
+
+static void ctdb_operation_print(uint32_t operation, FILE *fp)
+{
+ struct uint32_map map[] = {
+ { CTDB_REQ_CALL, "REQ_CALL" },
+ { CTDB_REPLY_CALL, "REPLY_CALL" },
+ { CTDB_REQ_DMASTER, "REQ_DMASTER" },
+ { CTDB_REPLY_DMASTER, "REPLY_DMASTER" },
+ { CTDB_REPLY_ERROR, "REPLY_ERROR" },
+ { CTDB_REQ_MESSAGE, "REQ_MESSAGE" },
+ { CTDB_REQ_CONTROL, "REQ_CONTROL", },
+ { CTDB_REPLY_CONTROL, "REPLY_CONTROL" },
+ { CTDB_REQ_KEEPALIVE, "REQ_KEEPALIVE" },
+ { MAP_END, "" },
+ };
+
+ uint32_map_print(map, operation, fp);
+}
+
+static void ctdb_callid_print(uint32_t callid, FILE *fp)
+{
+ struct uint32_map map[] = {
+ { CTDB_NULL_FUNC, "NULL" },
+ { CTDB_FETCH_FUNC, "FETCH" },
+ { CTDB_FETCH_WITH_HEADER_FUNC, "FETCH_WITH_HEADER" },
+ { MAP_END, "" },
+ };
+
+ uint32_map_print(map, callid, fp);
+}
+
+static void ctdb_opcode_print(uint32_t opcode, FILE *fp)
+{
+ struct uint32_map map[] = {
+ { CTDB_CONTROL_PROCESS_EXISTS, "PROCESS_EXISTS" },
+ { CTDB_CONTROL_STATISTICS, "STATISTICS" },
+ { CTDB_CONTROL_PING, "PING" },
+ { CTDB_CONTROL_GETDBPATH, "GETDBPATH" },
+ { CTDB_CONTROL_GETVNNMAP, "GETVNNMAP" },
+ { CTDB_CONTROL_SETVNNMAP, "SETVNNMAP" },
+ { CTDB_CONTROL_GET_DEBUG, "GET_DEBUG" },
+ { CTDB_CONTROL_SET_DEBUG, "SET_DEBUG" },
+ { CTDB_CONTROL_GET_DBMAP, "GET_DBMAP" },
+ { CTDB_CONTROL_GET_NODEMAPv4, "GET_NODEMAPv4" },
+ { CTDB_CONTROL_SET_DMASTER, "SET_DMASTER" },
+ { CTDB_CONTROL_GET_RECMODE, "GET_RECMODE" },
+ { CTDB_CONTROL_SET_RECMODE, "SET_RECMODE" },
+ { CTDB_CONTROL_STATISTICS_RESET, "STATISTICS_RESET" },
+ { CTDB_CONTROL_DB_ATTACH, "DB_ATTACH" },
+ { CTDB_CONTROL_SET_CALL, "SET_CALL" },
+ { CTDB_CONTROL_TRAVERSE_START, "TRAVERSE_START" },
+ { CTDB_CONTROL_TRAVERSE_ALL, "TRAVERSE_ALL" },
+ { CTDB_CONTROL_TRAVERSE_DATA, "TRAVERSE_DATA" },
+ { CTDB_CONTROL_REGISTER_SRVID, "REGISTER_SRVID" },
+ { CTDB_CONTROL_DEREGISTER_SRVID, "DEREGISTER_SRVID" },
+ { CTDB_CONTROL_GET_DBNAME, "GET_DBNAME" },
+ { CTDB_CONTROL_ENABLE_SEQNUM, "ENABLE_SEQNUM" },
+ { CTDB_CONTROL_UPDATE_SEQNUM, "UPDATE_SEQNUM" },
+ { CTDB_CONTROL_DUMP_MEMORY, "DUMP_MEMORY" },
+ { CTDB_CONTROL_GET_PID, "GET_PID" },
+ { CTDB_CONTROL_GET_RECMASTER, "GET_RECMASTER" },
+ { CTDB_CONTROL_SET_RECMASTER, "SET_RECMASTER" },
+ { CTDB_CONTROL_FREEZE, "FREEZE" },
+ { CTDB_CONTROL_THAW, "THAW" },
+ { CTDB_CONTROL_GET_PNN, "GET_PNN" },
+ { CTDB_CONTROL_SHUTDOWN, "SHUTDOWN" },
+ { CTDB_CONTROL_GET_MONMODE, "GET_MONMODE" },
+ { CTDB_CONTROL_TAKEOVER_IPv4, "TAKEOVER_IPv4" },
+ { CTDB_CONTROL_RELEASE_IPv4, "RELEASE_IPv4" },
+ { CTDB_CONTROL_TCP_CLIENT, "TCP_CLIENT" },
+ { CTDB_CONTROL_TCP_ADD, "TCP_ADD" },
+ { CTDB_CONTROL_TCP_REMOVE, "TCP_REMOVE" },
+ { CTDB_CONTROL_STARTUP, "STARTUP" },
+ { CTDB_CONTROL_SET_TUNABLE, "SET_TUNABLE" },
+ { CTDB_CONTROL_GET_TUNABLE, "GET_TUNABLE" },
+ { CTDB_CONTROL_LIST_TUNABLES, "LIST_TUNABLES" },
+ { CTDB_CONTROL_GET_PUBLIC_IPSv4, "GET_PUBLIC_IPSv4" },
+ { CTDB_CONTROL_MODIFY_FLAGS, "MODIFY_FLAGS" },
+ { CTDB_CONTROL_GET_ALL_TUNABLES, "GET_ALL_TUNABLES" },
+ { CTDB_CONTROL_KILL_TCP, "KILL_TCP" },
+ { CTDB_CONTROL_GET_TCP_TICKLE_LIST, "GET_TCP_TICKLE_LIST" },
+ { CTDB_CONTROL_SET_TCP_TICKLE_LIST, "SET_TCP_TICKLE_LIST" },
+ { CTDB_CONTROL_REGISTER_SERVER_ID, "REGISTER_SERVER_ID" },
+ { CTDB_CONTROL_UNREGISTER_SERVER_ID, "UNREGISTER_SERVER_ID" },
+ { CTDB_CONTROL_CHECK_SERVER_ID, "CHECK_SERVER_ID" },
+ { CTDB_CONTROL_GET_SERVER_ID_LIST, "GET_SERVER_ID_LIST" },
+ { CTDB_CONTROL_DB_ATTACH_PERSISTENT, "DB_ATTACH_PERSISTENT" },
+ { CTDB_CONTROL_PERSISTENT_STORE, "PERSISTENT_STORE" },
+ { CTDB_CONTROL_UPDATE_RECORD, "UPDATE_RECORD" },
+ { CTDB_CONTROL_SEND_GRATUITOUS_ARP, "SEND_GRATUITOUS_ARP" },
+ { CTDB_CONTROL_TRANSACTION_START, "TRANSACTION_START" },
+ { CTDB_CONTROL_TRANSACTION_COMMIT, "TRANSACTION_COMMIT" },
+ { CTDB_CONTROL_WIPE_DATABASE, "WIPE_DATABASE" },
+ { CTDB_CONTROL_UPTIME, "UPTIME" },
+ { CTDB_CONTROL_START_RECOVERY, "START_RECOVERY" },
+ { CTDB_CONTROL_END_RECOVERY, "END_RECOVERY" },
+ { CTDB_CONTROL_RELOAD_NODES_FILE, "RELOAD_NODES_FILE" },
+ { CTDB_CONTROL_TRY_DELETE_RECORDS, "TRY_DELETE_RECORDS" },
+ { CTDB_CONTROL_ENABLE_MONITOR, "ENABLE_MONITOR" },
+ { CTDB_CONTROL_DISABLE_MONITOR, "DISABLE_MONITOR" },
+ { CTDB_CONTROL_ADD_PUBLIC_IP, "ADD_PUBLIC_IP" },
+ { CTDB_CONTROL_DEL_PUBLIC_IP, "DEL_PUBLIC_IP" },
+ { CTDB_CONTROL_RUN_EVENTSCRIPTS, "RUN_EVENTSCRIPTS" },
+ { CTDB_CONTROL_GET_CAPABILITIES, "GET_CAPABILITIES" },
+ { CTDB_CONTROL_START_PERSISTENT_UPDATE, "START_PERSISTENT_UPDATE" },
+ { CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE, "CANCEL_PERSISTENT_UPDATE" },
+ { CTDB_CONTROL_TRANS2_COMMIT, "TRANS2_COMMIT" },
+ { CTDB_CONTROL_TRANS2_FINISHED, "TRANS2_FINISHED" },
+ { CTDB_CONTROL_TRANS2_ERROR, "TRANS2_ERROR" },
+ { CTDB_CONTROL_TRANS2_COMMIT_RETRY, "TRANS2_COMMIT_RETRY" },
+ { CTDB_CONTROL_RECD_PING, "RECD_PING" },
+ { CTDB_CONTROL_RELEASE_IP, "RELEASE_IP" },
+ { CTDB_CONTROL_TAKEOVER_IP, "TAKEOVER_IP" },
+ { CTDB_CONTROL_GET_PUBLIC_IPS, "GET_PUBLIC_IPS" },
+ { CTDB_CONTROL_GET_NODEMAP, "GET_NODEMAP" },
+ { CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, "GET_EVENT_SCRIPT_STATUS" },
+ { CTDB_CONTROL_TRAVERSE_KILL, "TRAVERSE_KILL" },
+ { CTDB_CONTROL_RECD_RECLOCK_LATENCY, "RECD_RECLOCK_LATENCY" },
+ { CTDB_CONTROL_GET_RECLOCK_FILE, "GET_RECLOCK_FILE" },
+ { CTDB_CONTROL_STOP_NODE, "STOP_NODE" },
+ { CTDB_CONTROL_CONTINUE_NODE, "CONTINUE_NODE" },
+ { CTDB_CONTROL_SET_NATGWSTATE, "SET_NATGWSTATE" },
+ { CTDB_CONTROL_SET_LMASTERROLE, "SET_LMASTERROLE" },
+ { CTDB_CONTROL_SET_RECMASTERROLE, "SET_RECMASTERROLE" },
+ { CTDB_CONTROL_ENABLE_SCRIPT, "ENABLE_SCRIPT" },
+ { CTDB_CONTROL_DISABLE_SCRIPT, "DISABLE_SCRIPT" },
+ { CTDB_CONTROL_SET_BAN_STATE, "SET_BAN_STATE" },
+ { CTDB_CONTROL_GET_BAN_STATE, "GET_BAN_STATE" },
+ { CTDB_CONTROL_SET_DB_PRIORITY, "SET_DB_PRIORITY" },
+ { CTDB_CONTROL_GET_DB_PRIORITY, "GET_DB_PRIORITY" },
+ { CTDB_CONTROL_TRANSACTION_CANCEL, "TRANSACTION_CANCEL" },
+ { CTDB_CONTROL_REGISTER_NOTIFY, "REGISTER_NOTIFY" },
+ { CTDB_CONTROL_DEREGISTER_NOTIFY, "DEREGISTER_NOTIFY" },
+ { CTDB_CONTROL_TRANS2_ACTIVE, "TRANS2_ACTIVE" },
+ { CTDB_CONTROL_GET_LOG, "GET_LOG" },
+ { CTDB_CONTROL_CLEAR_LOG, "CLEAR_LOG" },
+ { CTDB_CONTROL_TRANS3_COMMIT, "TRANS3_COMMIT" },
+ { CTDB_CONTROL_GET_DB_SEQNUM, "GET_DB_SEQNUM" },
+ { CTDB_CONTROL_DB_SET_HEALTHY, "DB_SET_HEALTHY" },
+ { CTDB_CONTROL_DB_GET_HEALTH, "DB_GET_HEALTH" },
+ { CTDB_CONTROL_GET_PUBLIC_IP_INFO, "GET_PUBLIC_IP_INFO" },
+ { CTDB_CONTROL_GET_IFACES, "GET_IFACES" },
+ { CTDB_CONTROL_SET_IFACE_LINK_STATE, "SET_IFACE_LINK_STATE" },
+ { CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE, "TCP_ADD_DELAYED_UPDATE" },
+ { CTDB_CONTROL_GET_STAT_HISTORY, "GET_STAT_HISTORY" },
+ { CTDB_CONTROL_SCHEDULE_FOR_DELETION, "SCHEDULE_FOR_DELETION" },
+ { CTDB_CONTROL_SET_DB_READONLY, "SET_DB_READONLY" },
+ { CTDB_CONTROL_CHECK_SRVIDS, "CHECK_SRVIDS" },
+ { CTDB_CONTROL_TRAVERSE_START_EXT, "TRAVERSE_START_EXT" },
+ { CTDB_CONTROL_GET_DB_STATISTICS, "GET_DB_STATISTICS" },
+ { CTDB_CONTROL_SET_DB_STICKY, "SET_DB_STICKY" },
+ { CTDB_CONTROL_RELOAD_PUBLIC_IPS, "RELOAD_PUBLIC_IPS" },
+ { CTDB_CONTROL_TRAVERSE_ALL_EXT, "TRAVERSE_ALL_EXT" },
+ { CTDB_CONTROL_RECEIVE_RECORDS, "RECEIVE_RECORDS" },
+ { CTDB_CONTROL_IPREALLOCATED, "IPREALLOCATED" },
+ { CTDB_CONTROL_GET_RUNSTATE, "GET_RUNSTATE" },
+ { CTDB_CONTROL_DB_DETACH, "DB_DETACH" },
+ { CTDB_CONTROL_GET_NODES_FILE, "GET_NODES_FILE" },
+ { CTDB_CONTROL_DB_FREEZE, "DB_FREEZE" },
+ { CTDB_CONTROL_DB_THAW, "DB_THAW" },
+ { CTDB_CONTROL_DB_TRANSACTION_START, "DB_TRANSACTION_START" },
+ { CTDB_CONTROL_DB_TRANSACTION_COMMIT, "DB_TRANSACTION_COMMIT" },
+ { CTDB_CONTROL_DB_TRANSACTION_CANCEL, "DB_TRANSACTION_CANCEL" },
+ { CTDB_CONTROL_DB_PULL, "DB_PULL" },
+ { CTDB_CONTROL_DB_PUSH_START, "DB_PUSH_START" },
+ { CTDB_CONTROL_DB_PUSH_CONFIRM, "DB_PUSH_CONFIRM" },
+ { CTDB_CONTROL_DB_OPEN_FLAGS, "DB_OPEN_FLAGS" },
+ { CTDB_CONTROL_DB_ATTACH_REPLICATED, "DB_ATTACH_REPLICATED" },
+ { CTDB_CONTROL_CHECK_PID_SRVID, "CHECK_PID_SRVID" },
+ { CTDB_CONTROL_TUNNEL_REGISTER, "TUNNEL_REGISTER" },
+ { CTDB_CONTROL_TUNNEL_DEREGISTER, "TUNNEL_DEREGISTER" },
+ { CTDB_CONTROL_VACUUM_FETCH, "VACUUM_FETCH" },
+ { CTDB_CONTROL_DB_VACUUM, "DB_VACUUM" },
+ { CTDB_CONTROL_ECHO_DATA, "ECHO_DATA" },
+ { CTDB_CONTROL_DISABLE_NODE, "DISABLE_NODE" },
+ { CTDB_CONTROL_ENABLE_NODE, "ENABLE_NODE" },
+ { MAP_END, "" },
+ };
+
+ uint32_map_print(map, opcode, fp);
+}
+
+static void ctdb_control_flags_print(uint32_t flags, FILE *fp)
+{
+ if (flags & CTDB_CTRL_FLAG_NOREPLY) {
+ fprintf(fp, "NOREPLY ");
+ }
+ if (flags & CTDB_CTRL_FLAG_OPCODE_SPECIFIC) {
+ fprintf(fp, "OPCODE_SPECIFIC ");
+ }
+}
+
+static void ctdb_pnn_print(uint32_t pnn, FILE *fp)
+{
+ if (pnn == CTDB_CURRENT_NODE) {
+ fprintf(fp, "CURRENT");
+ } else if (pnn == CTDB_BROADCAST_ALL) {
+ fprintf(fp, "ALL");
+ } else if (pnn == CTDB_BROADCAST_ACTIVE) {
+ fprintf(fp, "ACTIVE");
+ } else if (pnn == CTDB_BROADCAST_CONNECTED) {
+ fprintf(fp, "CONNECTED");
+ } else if (pnn == CTDB_MULTICAST) {
+ fprintf(fp, "MULTICAST");
+ } else if (pnn == CTDB_UNKNOWN_PNN) {
+ fprintf(fp, "UNKNOWN");
+ } else {
+ fprintf(fp, "%u", pnn);
+ }
+}
+
+static void ctdb_srvid_print(uint64_t srvid, FILE *fp)
+{
+ uint64_t prefix = 0xFFFF000000000000LL;
+
+ if (srvid == CTDB_SRVID_ALL) {
+ fprintf(fp, "ALL");
+ } else if ((srvid & prefix) == CTDB_SRVID_RECOVERY) {
+ srvid = srvid & ~CTDB_SRVID_RECOVERY;
+ fprintf(fp, "RECOVERY-%"PRIx64"", srvid);
+ } else if (srvid == CTDB_SRVID_BANNING) {
+ fprintf(fp, "BANNING");
+ } else if (srvid == CTDB_SRVID_ELECTION) {
+ fprintf(fp, "ELECTION");
+ } else if (srvid == CTDB_SRVID_RECONFIGURE) {
+ fprintf(fp, "RECONFIGURE");
+ } else if (srvid == CTDB_SRVID_RELEASE_IP) {
+ fprintf(fp, "RELEASE_IP");
+ } else if (srvid == CTDB_SRVID_TAKE_IP) {
+ fprintf(fp, "TAKE_IP");
+ } else if (srvid == CTDB_SRVID_SET_NODE_FLAGS) {
+ fprintf(fp, "SET_NODE_FLAGS");
+ } else if (srvid == CTDB_SRVID_RECD_UPDATE_IP) {
+ fprintf(fp, "RECD_UPDATE_IP");
+ } else if (srvid == CTDB_SRVID_VACUUM_FETCH) {
+ fprintf(fp, "VACUUM_FETCH");
+ } else if (srvid == CTDB_SRVID_DETACH_DATABASE) {
+ fprintf(fp, "DETACH_DATABASE");
+ } else if (srvid == CTDB_SRVID_MEM_DUMP) {
+ fprintf(fp, "MEM_DUMP");
+ } else if (srvid == CTDB_SRVID_GETLOG) {
+ fprintf(fp, "GETLOG");
+ } else if (srvid == CTDB_SRVID_CLEARLOG) {
+ fprintf(fp, "CLEARLOG");
+ } else if (srvid == CTDB_SRVID_PUSH_NODE_FLAGS) {
+ fprintf(fp, "PUSH_NODE_FLAGS");
+ } else if (srvid == CTDB_SRVID_RELOAD_NODES) {
+ fprintf(fp, "RELOAD_NODES");
+ } else if (srvid == CTDB_SRVID_TAKEOVER_RUN) {
+ fprintf(fp, "TAKEOVER_RUN");
+ } else if (srvid == CTDB_SRVID_REBALANCE_NODE) {
+ fprintf(fp, "REBALANCE_NODE");
+ } else if (srvid == CTDB_SRVID_DISABLE_TAKEOVER_RUNS) {
+ fprintf(fp, "DISABLE_TAKEOVER_RUNS");
+ } else if (srvid == CTDB_SRVID_DISABLE_RECOVERIES) {
+ fprintf(fp, "DISABLE_RECOVERIES");
+ } else if (srvid == CTDB_SRVID_DISABLE_IP_CHECK) {
+ fprintf(fp, "DISABLE_IP_CHECK");
+ } else if ((srvid & prefix) == CTDB_SRVID_SAMBA_RANGE) {
+ if (srvid == CTDB_SRVID_SAMBA_NOTIFY) {
+ fprintf(fp, "SAMBA_NOTIFY");
+ } else {
+ srvid &= ~CTDB_SRVID_SAMBA_RANGE;
+ fprintf(fp, "samba-0x%"PRIx64"", srvid);
+ }
+ } else if ((srvid & prefix) == CTDB_SRVID_NFSD_RANGE) {
+ srvid &= ~CTDB_SRVID_NFSD_RANGE;
+ fprintf(fp, "nfsd-0x%"PRIx64"", srvid);
+ } else if ((srvid & prefix) == CTDB_SRVID_ISCSID_RANGE) {
+ srvid &= ~CTDB_SRVID_ISCSID_RANGE;
+ fprintf(fp, "iscsi-0x%"PRIx64"", srvid);
+ } else if ((srvid & prefix) == CTDB_SRVID_TOOL_RANGE) {
+ srvid &= ~CTDB_SRVID_TOOL_RANGE;
+ fprintf(fp, "tool-0x%"PRIx64"", srvid);
+ } else if ((srvid & prefix) == CTDB_SRVID_TEST_RANGE) {
+ srvid &= ~CTDB_SRVID_TEST_RANGE;
+ fprintf(fp, "test-0x%"PRIx64"", srvid);
+ } else if ((srvid & prefix) == CTDB_SRVID_PID_RANGE) {
+ if (srvid < UINT16_MAX) {
+ fprintf(fp, "pid-%"PRIu64, srvid);
+ } else {
+ fprintf(fp, "pid-0x%"PRIx64, srvid);
+ }
+ } else {
+ fprintf(fp, "0x%"PRIx64, srvid);
+ }
+}
+
+static void ctdb_tunnel_id_print(uint64_t tunnel_id, FILE *fp)
+{
+ if ((tunnel_id & CTDB_TUNNEL_TEST) == CTDB_TUNNEL_TEST) {
+ fprintf(fp, "TEST-%"PRIx64, tunnel_id);
+ } else {
+ fprintf(fp, "0x%"PRIx64, tunnel_id);
+ }
+}
+
+static void ctdb_tunnel_flags_print(uint32_t flags, FILE *fp)
+{
+ if (flags & CTDB_TUNNEL_FLAG_REQUEST) {
+ fprintf(fp, "REQUEST ");
+ }
+ if (flags & CTDB_TUNNEL_FLAG_REPLY) {
+ fprintf(fp, "REPLY ");
+ }
+ if (flags & CTDB_TUNNEL_FLAG_NOREPLY) {
+ fprintf(fp, "NOREPLY ");
+ }
+}
+
+/*
+ * Print routines
+ */
+
+static void ctdb_req_header_print(struct ctdb_req_header *h, FILE *fp)
+{
+ fprintf(fp, "Header\n");
+ fprintf(fp, " length:%u magic:0x%"PRIx32" version:%u generation:0x%"PRIx32"\n",
+ h->length, h->ctdb_magic, h->ctdb_version, h->generation);
+ fprintf(fp, " ");
+ ctdb_operation_print(h->operation, fp);
+ fprintf(fp, " dst:");
+ ctdb_pnn_print(h->destnode, fp);
+ fprintf(fp, " src:");
+ ctdb_pnn_print(h->srcnode, fp);
+ fprintf(fp, " reqid:0x%"PRIx32"\n", h->reqid);
+}
+
+static void ctdb_req_call_print(struct ctdb_req_call *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " db:0x%"PRIx32" ", c->db_id);
+ ctdb_callid_print(c->callid, fp);
+ fprintf(fp, "\n");
+ fprintf(fp, " key:");
+ tdb_data_print(c->key, fp);
+ fprintf(fp, "\n");
+}
+
+static void ctdb_reply_call_print(struct ctdb_reply_call *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " status:%d\n", c->status);
+ if (c->status == 0) {
+ fprintf(fp, " data:");
+ tdb_data_print(c->data, fp);
+ fprintf(fp, "\n");
+ }
+}
+
+static void ctdb_req_dmaster_print(struct ctdb_req_dmaster *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " db:0x%"PRIx32" rsn:0x%"PRIx64" dmaster:%u\n",
+ c->db_id, c->rsn, c->dmaster);
+ fprintf(fp, " key:");
+ tdb_data_print(c->key, fp);
+ fprintf(fp, "\n");
+ fprintf(fp, " data:");
+ tdb_data_print(c->data, fp);
+ fprintf(fp, "\n");
+}
+
+static void ctdb_reply_dmaster_print(struct ctdb_reply_dmaster *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " db:0x%"PRIx32" rsn:0x%"PRIx64"\n", c->db_id, c->rsn);
+ fprintf(fp, " key:");
+ tdb_data_print(c->key, fp);
+ fprintf(fp, "\n");
+ fprintf(fp, " data:");
+ tdb_data_print(c->data, fp);
+ fprintf(fp, "\n");
+}
+
+static void ctdb_reply_error_print(struct ctdb_reply_error *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " status:%d\n", c->status);
+ if (c->status != 0) {
+ fprintf(fp, " msg:");
+ tdb_data_print(c->msg, fp);
+ fprintf(fp, "\n");
+ }
+}
+
+static void ctdb_req_message_data_print(struct ctdb_req_message_data *c,
+ FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " srvid:");
+ ctdb_srvid_print(c->srvid, fp);
+ fprintf(fp, "\n");
+ fprintf(fp, " data:");
+ tdb_data_print(c->data, fp);
+ fprintf(fp, "\n");
+}
+
+static void ctdb_req_control_print(struct ctdb_req_control *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " ");
+ ctdb_opcode_print(c->opcode, fp);
+ fprintf(fp, " srvid:");
+ ctdb_srvid_print(c->srvid, fp);
+ fprintf(fp, " client_id:0x%"PRIx32" ", c->client_id);
+ ctdb_control_flags_print(c->flags, fp);
+ fprintf(fp, "\n");
+}
+
+static void ctdb_reply_control_print(struct ctdb_reply_control *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " status:%d ", c->status);
+ if (c->errmsg != NULL) {
+ fprintf(fp, "errmsg: %s", c->errmsg);
+ }
+ fprintf(fp, "\n");
+}
+
+static void ctdb_req_keepalive_print(struct ctdb_req_keepalive *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " version:0x%"PRIx32, c->version);
+ fprintf(fp, " uptime:%"PRIu32, c->uptime);
+ fprintf(fp, "\n");
+}
+
+static void ctdb_req_tunnel_print(struct ctdb_req_tunnel *c, FILE *fp)
+{
+ fprintf(fp, "Data\n");
+ fprintf(fp, " tunnel_id:");
+ ctdb_tunnel_id_print(c->tunnel_id, fp);
+ ctdb_tunnel_flags_print(c->flags, fp);
+ tdb_data_print(c->data, fp);
+ fprintf(fp, "\n");
+}
+
+/*
+ * Parse routines
+ */
+
+static void ctdb_req_call_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_call c;
+ int ret;
+
+ ret = ctdb_req_call_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_CALL\n");
+ return;
+ }
+
+ ctdb_req_call_print(&c, fp);
+}
+
+static void ctdb_reply_call_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_reply_call c;
+ int ret;
+
+ ret = ctdb_reply_call_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REPLY_CALL\n");
+ return;
+ }
+
+ ctdb_reply_call_print(&c, fp);
+}
+
+static void ctdb_req_dmaster_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_dmaster c;
+ int ret;
+
+ ret = ctdb_req_dmaster_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_DMASTER\n");
+ return;
+ }
+
+ ctdb_req_dmaster_print(&c, fp);
+}
+
+static void ctdb_reply_dmaster_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_reply_dmaster c;
+ int ret;
+
+ ret = ctdb_reply_dmaster_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REPLY_DMASTER\n");
+ return;
+ }
+
+ ctdb_reply_dmaster_print(&c, fp);
+}
+
+static void ctdb_reply_error_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_reply_error c;
+ int ret;
+
+ ret = ctdb_reply_error_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REPLY_ERROR\n");
+ return;
+ }
+
+ ctdb_reply_error_print(&c, fp);
+}
+
+static void ctdb_req_message_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_message_data c;
+ int ret;
+
+ ret = ctdb_req_message_data_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_MESSAGE\n");
+ return;
+ }
+
+ ctdb_req_message_data_print(&c, fp);
+}
+
+static void ctdb_req_control_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_control c;
+ int ret;
+
+ ret = ctdb_req_control_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_CONTROL\n");
+ return;
+ }
+
+ ctdb_req_control_print(&c, fp);
+}
+
+static void ctdb_reply_control_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_reply_control c;
+ int ret;
+
+ ret = ctdb_reply_control_pull(buf, buflen, -1, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REPLY_CONTROL\n");
+ return;
+ }
+
+ ctdb_reply_control_print(&c, fp);
+}
+
+static void ctdb_req_keepalive_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_keepalive c;
+ int ret;
+
+ ret = ctdb_req_keepalive_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_KEEPALIVE\n");
+ return;
+ }
+
+ ctdb_req_keepalive_print(&c, fp);
+}
+
+static void ctdb_req_tunnel_parse(uint8_t *buf, size_t buflen, FILE *fp,
+ TALLOC_CTX *mem_ctx)
+{
+ struct ctdb_req_tunnel c;
+ int ret;
+
+ ret = ctdb_req_tunnel_pull(buf, buflen, NULL, mem_ctx, &c);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse CTDB_REQ_TUNNEL\n");
+ return;
+ }
+
+ ctdb_req_tunnel_print(&c, fp);
+}
+
+/*
+ * Packet print
+ */
+
+void ctdb_packet_print(uint8_t *buf, size_t buflen, FILE *fp)
+{
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ struct ctdb_req_header h;
+ size_t np;
+ int ret;
+
+ fprintf(fp, "Buffer len:%zu\n", buflen);
+
+ ret = ctdb_req_header_pull(buf, buflen, &h, &np);
+ if (ret != 0) {
+ fprintf(fp, "Failed to parse ctdb packet header\n");
+ return;
+ }
+
+ ctdb_req_header_print(&h, fp);
+
+ if (h.length > buflen) {
+ fprintf(fp, "Packet length mismatch\n");
+ }
+
+ ret = ctdb_req_header_verify(&h, 0);
+ if (ret != 0) {
+ fprintf(fp, "Invalid ctdb packet header\n");
+ return;
+ }
+
+ switch (h.operation) {
+ case CTDB_REQ_CALL:
+ ctdb_req_call_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REPLY_CALL:
+ ctdb_reply_call_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REQ_DMASTER:
+ ctdb_req_dmaster_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REPLY_DMASTER:
+ ctdb_reply_dmaster_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REPLY_ERROR:
+ ctdb_reply_error_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REQ_MESSAGE:
+ ctdb_req_message_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REQ_CONTROL:
+ ctdb_req_control_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REPLY_CONTROL:
+ ctdb_reply_control_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REQ_KEEPALIVE:
+ ctdb_req_keepalive_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ case CTDB_REQ_TUNNEL:
+ ctdb_req_tunnel_parse(buf, buflen, fp, mem_ctx);
+ break;
+
+ default:
+ fprintf(fp, "Invalid ctdb operation\n");
+ break;
+ }
+
+ talloc_free(mem_ctx);
+}
diff --git a/ctdb/protocol/protocol_header.c b/ctdb/protocol/protocol_header.c
new file mode 100644
index 0000000..a6be7f5
--- /dev/null
+++ b/ctdb/protocol/protocol_header.c
@@ -0,0 +1,169 @@
+/*
+ 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"
+
+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;
+}
+
+size_t ctdb_req_header_len(struct ctdb_req_header *in)
+{
+ return ctdb_uint32_len(&in->length) +
+ ctdb_uint32_len(&in->ctdb_magic) +
+ ctdb_uint32_len(&in->ctdb_version) +
+ ctdb_uint32_len(&in->generation) +
+ ctdb_uint32_len(&in->operation) +
+ ctdb_uint32_len(&in->destnode) +
+ ctdb_uint32_len(&in->srcnode) +
+ ctdb_uint32_len(&in->reqid);
+}
+
+void ctdb_req_header_push(struct ctdb_req_header *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->length, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->ctdb_magic, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->ctdb_version, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->generation, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->operation, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->destnode, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->srcnode, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_req_header_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->length, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->ctdb_magic,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->ctdb_version,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->generation,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->operation,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->destnode, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->srcnode, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reqid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_keepalive.c b/ctdb/protocol/protocol_keepalive.c
new file mode 100644
index 0000000..3a1fc0e
--- /dev/null
+++ b/ctdb/protocol/protocol_keepalive.c
@@ -0,0 +1,95 @@
+/*
+ CTDB protocol marshalling
+
+ 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 <talloc.h>
+#include <tdb.h>
+
+#include "protocol.h"
+#include "protocol_api.h"
+#include "protocol_private.h"
+
+size_t ctdb_req_keepalive_len(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint32_len(&c->version) +
+ ctdb_uint32_len(&c->uptime);
+}
+
+int ctdb_req_keepalive_push(struct ctdb_req_header *h,
+ struct ctdb_req_keepalive *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t length, offset = 0, np;
+
+ length = ctdb_req_keepalive_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->version, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->uptime, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_req_keepalive_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_keepalive *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf, buflen, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->version, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->uptime, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_message.c b/ctdb/protocol/protocol_message.c
new file mode 100644
index 0000000..e2202bb
--- /dev/null
+++ b/ctdb/protocol/protocol_message.c
@@ -0,0 +1,476 @@
+/*
+ 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"
+
+
+static size_t ctdb_message_data_len(union ctdb_message_data *mdata,
+ uint64_t srvid)
+{
+ size_t len = 0;
+
+ switch (srvid) {
+ case CTDB_SRVID_BANNING:
+ len = ctdb_uint32_len(&mdata->pnn);
+ break;
+
+ case CTDB_SRVID_ELECTION:
+ len = ctdb_election_message_len(mdata->election);
+ break;
+
+ case CTDB_SRVID_LEADER:
+ len = ctdb_uint32_len(&mdata->pnn);
+ 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_GETLOG:
+ break;
+
+ case CTDB_SRVID_CLEARLOG:
+ 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;
+
+ default:
+ len = ctdb_tdb_data_len(&mdata->data);
+ break;
+ }
+
+ return len;
+}
+
+static void ctdb_message_data_push(union ctdb_message_data *mdata,
+ uint64_t srvid, uint8_t *buf,
+ size_t *npush)
+{
+ size_t np = 0;
+
+ switch (srvid) {
+ case CTDB_SRVID_BANNING:
+ ctdb_uint32_push(&mdata->pnn, buf, &np);
+ break;
+
+ case CTDB_SRVID_ELECTION:
+ ctdb_election_message_push(mdata->election, buf, &np);
+ break;
+
+ case CTDB_SRVID_LEADER:
+ ctdb_uint32_push(&mdata->pnn, buf, &np);
+ break;
+
+ case CTDB_SRVID_RECONFIGURE:
+ break;
+
+ case CTDB_SRVID_RELEASE_IP:
+ ctdb_string_push(&mdata->ipaddr, buf, &np);
+ break;
+
+ case CTDB_SRVID_TAKE_IP:
+ ctdb_string_push(&mdata->ipaddr, buf, &np);
+ break;
+
+ case CTDB_SRVID_SET_NODE_FLAGS:
+ ctdb_node_flag_change_push(mdata->flag_change, buf, &np);
+ break;
+
+ case CTDB_SRVID_RECD_UPDATE_IP:
+ ctdb_public_ip_push(mdata->pubip, buf, &np);
+ break;
+
+ case CTDB_SRVID_VACUUM_FETCH:
+ ctdb_rec_buffer_push(mdata->recbuf, buf, &np);
+ break;
+
+ case CTDB_SRVID_DETACH_DATABASE:
+ ctdb_uint32_push(&mdata->db_id, buf, &np);
+ break;
+
+ case CTDB_SRVID_MEM_DUMP:
+ ctdb_srvid_message_push(mdata->msg, buf, &np);
+ break;
+
+ case CTDB_SRVID_GETLOG:
+ break;
+
+ case CTDB_SRVID_CLEARLOG:
+ break;
+
+ case CTDB_SRVID_PUSH_NODE_FLAGS:
+ ctdb_node_flag_change_push(mdata->flag_change, buf, &np);
+ break;
+
+ case CTDB_SRVID_RELOAD_NODES:
+ break;
+
+ case CTDB_SRVID_TAKEOVER_RUN:
+ ctdb_srvid_message_push(mdata->msg, buf, &np);
+ break;
+
+ case CTDB_SRVID_REBALANCE_NODE:
+ ctdb_uint32_push(&mdata->pnn, buf, &np);
+ break;
+
+ case CTDB_SRVID_DISABLE_TAKEOVER_RUNS:
+ ctdb_disable_message_push(mdata->disable, buf, &np);
+ break;
+
+ case CTDB_SRVID_DISABLE_RECOVERIES:
+ ctdb_disable_message_push(mdata->disable, buf, &np);
+ break;
+
+ case CTDB_SRVID_DISABLE_IP_CHECK:
+ ctdb_uint32_push(&mdata->timeout, buf, &np);
+ break;
+
+ default:
+ ctdb_tdb_data_push(&mdata->data, buf, &np);
+ break;
+ }
+
+ *npush = np;
+}
+
+static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
+ uint64_t srvid, TALLOC_CTX *mem_ctx,
+ union ctdb_message_data *mdata,
+ size_t *npull)
+{
+ int ret = 0;
+ size_t np = 0;
+
+ switch (srvid) {
+ case CTDB_SRVID_BANNING:
+ ret = ctdb_uint32_pull(buf, buflen, &mdata->pnn, &np);
+ break;
+
+ case CTDB_SRVID_ELECTION:
+ ret = ctdb_election_message_pull(buf, buflen, mem_ctx,
+ &mdata->election, &np);
+ break;
+
+ case CTDB_SRVID_LEADER:
+ ret = ctdb_uint32_pull(buf, buflen, &mdata->pnn, &np);
+ break;
+
+ case CTDB_SRVID_RECONFIGURE:
+ break;
+
+ case CTDB_SRVID_RELEASE_IP:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx, &mdata->ipaddr,
+ &np);
+ break;
+
+ case CTDB_SRVID_TAKE_IP:
+ ret = ctdb_string_pull(buf, buflen, mem_ctx, &mdata->ipaddr,
+ &np);
+ break;
+
+ case CTDB_SRVID_SET_NODE_FLAGS:
+ ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
+ &mdata->flag_change, &np);
+ break;
+
+ case CTDB_SRVID_RECD_UPDATE_IP:
+ ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
+ &mdata->pubip, &np);
+ break;
+
+ case CTDB_SRVID_VACUUM_FETCH:
+ ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
+ &mdata->recbuf, &np);
+ break;
+
+ case CTDB_SRVID_DETACH_DATABASE:
+ ret = ctdb_uint32_pull(buf, buflen, &mdata->db_id, &np);
+ break;
+
+ case CTDB_SRVID_MEM_DUMP:
+ ret = ctdb_srvid_message_pull(buf, buflen, mem_ctx,
+ &mdata->msg, &np);
+ break;
+
+ case CTDB_SRVID_GETLOG:
+ break;
+
+ case CTDB_SRVID_CLEARLOG:
+ break;
+
+ case CTDB_SRVID_PUSH_NODE_FLAGS:
+ ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
+ &mdata->flag_change, &np);
+ break;
+
+ case CTDB_SRVID_RELOAD_NODES:
+ break;
+
+ case CTDB_SRVID_TAKEOVER_RUN:
+ ret = ctdb_srvid_message_pull(buf, buflen, mem_ctx,
+ &mdata->msg, &np);
+ break;
+
+ case CTDB_SRVID_REBALANCE_NODE:
+ ret = ctdb_uint32_pull(buf, buflen, &mdata->pnn, &np);
+ break;
+
+ case CTDB_SRVID_DISABLE_TAKEOVER_RUNS:
+ ret = ctdb_disable_message_pull(buf, buflen, mem_ctx,
+ &mdata->disable, &np);
+ break;
+
+ case CTDB_SRVID_DISABLE_RECOVERIES:
+ ret = ctdb_disable_message_pull(buf, buflen, mem_ctx,
+ &mdata->disable, &np);
+ break;
+
+ case CTDB_SRVID_DISABLE_IP_CHECK:
+ ret = ctdb_uint32_pull(buf, buflen, &mdata->timeout, &np);
+ break;
+
+ default:
+ ret = ctdb_tdb_data_pull(buf, buflen, mem_ctx, &mdata->data,
+ &np);
+ break;
+ }
+
+ if (ret != 0) {
+ return ret;
+ }
+
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_req_message_len(struct ctdb_req_header *h,
+ struct ctdb_req_message *c)
+{
+ uint32_t u32 = ctdb_message_data_len(&c->data, c->srvid);
+
+ return ctdb_req_header_len(h) +
+ ctdb_uint64_len(&c->srvid) +
+ ctdb_uint32_len(&u32) + u32;
+}
+
+int ctdb_req_message_push(struct ctdb_req_header *h,
+ struct ctdb_req_message *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+ uint32_t u32;
+
+ length = ctdb_req_message_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&c->srvid, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_message_data_len(&c->data, c->srvid);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_message_data_push(&c->data, c->srvid, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_req_message_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_message *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < u32) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_message_data_pull(buf+offset, u32, c->srvid,
+ mem_ctx, &c->data, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return ret;
+}
+
+size_t ctdb_req_message_data_len(struct ctdb_req_header *h,
+ struct ctdb_req_message_data *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint64_len(&c->srvid) +
+ ctdb_tdb_datan_len(&c->data);
+}
+
+int ctdb_req_message_data_push(struct ctdb_req_header *h,
+ struct ctdb_req_message_data *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t offset = 0, np;
+ size_t length;
+
+ length = ctdb_req_message_data_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&c->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&c->data, buf+offset, &np);
+ offset += np;
+
+ return 0;
+}
+
+int ctdb_req_message_data_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_message_data *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset,
+ mem_ctx, &c->data, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_packet.c b/ctdb/protocol/protocol_packet.c
new file mode 100644
index 0000000..d5fd96b
--- /dev/null
+++ b/ctdb/protocol/protocol_packet.c
@@ -0,0 +1,48 @@
+/*
+ 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_api.h"
+
+#define CTDB_DS_ALIGNMENT 8
+
+int ctdb_allocate_pkt(TALLOC_CTX *mem_ctx, size_t length,
+ uint8_t **buf, size_t *buflen)
+{
+ size_t new_length;
+
+ if (buf == NULL || buflen == NULL) {
+ return EINVAL;
+ }
+
+ 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;
+}
diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h
new file mode 100644
index 0000000..cbbba39
--- /dev/null
+++ b/ctdb/protocol/protocol_private.h
@@ -0,0 +1,300 @@
+/*
+ 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"
+#include "protocol_basic.h"
+
+/*
+ * From protocol/protocol_types.c
+ */
+
+size_t ctdb_tdb_data_len(TDB_DATA *in);
+void ctdb_tdb_data_push(TDB_DATA *in, uint8_t *buf, size_t *npush);
+int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ TDB_DATA *out, size_t *npull);
+
+size_t ctdb_tdb_datan_len(TDB_DATA *in);
+void ctdb_tdb_datan_push(TDB_DATA *in, uint8_t *buf, size_t *npush);
+int ctdb_tdb_datan_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ TDB_DATA *out, size_t *npull);
+
+size_t ctdb_latency_counter_len(struct ctdb_latency_counter *in);
+void ctdb_latency_counter_push(struct ctdb_latency_counter *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_latency_counter_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_latency_counter *out, size_t *npull);
+
+size_t ctdb_statistics_len(struct ctdb_statistics *in);
+void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics **out, size_t *npull);
+
+size_t ctdb_statistics_list_len(struct ctdb_statistics_list *in);
+void ctdb_statistics_list_push(struct ctdb_statistics_list *in,
+ uint8_t *buf, size_t *npull);
+int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics_list **out,
+ size_t *npull);
+
+size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in);
+void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush);
+int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_vnn_map **out, size_t *npull);
+
+size_t ctdb_dbid_len(struct ctdb_dbid *in);
+void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush);
+int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid **out, size_t *npull);
+
+size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in);
+void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid_map **out, size_t *npull);
+
+size_t ctdb_pulldb_len(struct ctdb_pulldb *in);
+void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush);
+int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_pulldb **out, size_t *npull);
+
+size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *in);
+void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_pulldb_ext **out, size_t *npull);
+
+size_t ctdb_db_vacuum_len(struct ctdb_db_vacuum *in);
+void ctdb_db_vacuum_push(struct ctdb_db_vacuum *in,
+ uint8_t *buf,
+ size_t *npush);
+int ctdb_db_vacuum_pull(uint8_t *buf,
+ size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_db_vacuum **out,
+ size_t *npull);
+
+size_t ctdb_echo_data_len(struct ctdb_echo_data *in);
+void ctdb_echo_data_push(struct ctdb_echo_data *in,
+ uint8_t *buf,
+ size_t *npush);
+int ctdb_echo_data_pull(uint8_t *buf,
+ size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_echo_data **out,
+ size_t *npull);
+
+size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in);
+void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_start **out, size_t *npull);
+
+size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in);
+void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_all **out, size_t *npull);
+
+size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *in);
+void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *in,
+ uint8_t *buf, size_t *npush);
+int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_start_ext **out,
+ size_t *npull);
+
+size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *in);
+void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *in,
+ uint8_t *buf, size_t *npush);
+int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_all_ext **out,
+ size_t *npull);
+
+size_t ctdb_sock_addr_len(ctdb_sock_addr *in);
+void ctdb_sock_addr_push(ctdb_sock_addr *in, uint8_t *buf, size_t *npush);
+int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, ctdb_sock_addr *out,
+ size_t *npull);
+int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ ctdb_sock_addr **out, size_t *npull);
+
+size_t ctdb_connection_len(struct ctdb_connection *in);
+void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_connection **out, size_t *npull);
+
+size_t ctdb_connection_list_len(struct ctdb_connection_list *in);
+void ctdb_connection_list_push(struct ctdb_connection_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_connection_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list **out, size_t *npull);
+
+size_t ctdb_tunable_len(struct ctdb_tunable *in);
+void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush);
+int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable **out, size_t *npull);
+
+size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in);
+void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
+ uint8_t *buf, size_t *npush);
+int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_node_flag_change **out,
+ size_t *npull);
+
+size_t ctdb_var_list_len(struct ctdb_var_list *in);
+void ctdb_var_list_push(struct ctdb_var_list *in, uint8_t *buf, size_t *npush);
+int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_var_list **out, size_t *npull);
+
+size_t ctdb_tunable_list_len(struct ctdb_tunable_list *in);
+void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable_list **out, size_t *npull);
+
+size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in);
+void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_tickle_list **out, size_t *npull);
+
+size_t ctdb_addr_info_len(struct ctdb_addr_info *in);
+void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_addr_info **out, size_t *npull);
+
+size_t ctdb_transdb_len(struct ctdb_transdb *in);
+void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush);
+int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_transdb **out, size_t *npull);
+
+size_t ctdb_uptime_len(struct ctdb_uptime *in);
+void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush);
+int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_uptime **out, size_t *npull);
+
+size_t ctdb_public_ip_len(struct ctdb_public_ip *in);
+void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip **out, size_t *npull);
+
+size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *in);
+void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip_list **out, size_t *npull);
+
+size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in);
+void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_node_and_flags **out, size_t *npull);
+
+size_t ctdb_node_map_len(struct ctdb_node_map *in);
+void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush);
+int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_node_map **out, size_t *npull);
+
+size_t ctdb_script_len(struct ctdb_script *in);
+void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush);
+int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_script **out, size_t *npull);
+
+size_t ctdb_script_list_len(struct ctdb_script_list *in);
+void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_script_list **out, size_t *npull);
+
+size_t ctdb_ban_state_len(struct ctdb_ban_state *in);
+void ctdb_ban_state_push(struct ctdb_ban_state *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_ban_state **out, size_t *npull);
+
+size_t ctdb_notify_data_len(struct ctdb_notify_data *in);
+void ctdb_notify_data_push(struct ctdb_notify_data *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_notify_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_notify_data **out, size_t *npull);
+
+size_t ctdb_iface_len(struct ctdb_iface *in);
+void ctdb_iface_push(struct ctdb_iface *in, uint8_t *buf, size_t *npush);
+int ctdb_iface_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_iface **out, size_t *npull);
+
+size_t ctdb_iface_list_len(struct ctdb_iface_list *in);
+void ctdb_iface_list_push(struct ctdb_iface_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_iface_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_iface_list **out, size_t *npull);
+
+size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *in);
+void ctdb_public_ip_info_push(struct ctdb_public_ip_info *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip_info **out, size_t *npull);
+
+size_t ctdb_key_data_len(struct ctdb_key_data *in);
+void ctdb_key_data_push(struct ctdb_key_data *in, uint8_t *buf, size_t *npush);
+int ctdb_key_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_key_data **out, size_t *npull);
+
+size_t ctdb_db_statistics_len(struct ctdb_db_statistics *in);
+void ctdb_db_statistics_push(struct ctdb_db_statistics *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_db_statistics **out, size_t *npull);
+
+size_t ctdb_pid_srvid_len(struct ctdb_pid_srvid *in);
+void ctdb_pid_srvid_push(struct ctdb_pid_srvid *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_pid_srvid **out, size_t *npull);
+
+size_t ctdb_election_message_len(struct ctdb_election_message *in);
+void ctdb_election_message_push(struct ctdb_election_message *in,
+ uint8_t *buf, size_t *npush);
+int ctdb_election_message_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_election_message **out,
+ size_t *npull);
+
+size_t ctdb_srvid_message_len(struct ctdb_srvid_message *in);
+void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_srvid_message **out, size_t *npull);
+
+size_t ctdb_disable_message_len(struct ctdb_disable_message *in);
+void ctdb_disable_message_push(struct ctdb_disable_message *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_disable_message **out,
+ size_t *npull);
+
+#endif /* __PROTOCOL_PRIVATE_H__ */
diff --git a/ctdb/protocol/protocol_sock.c b/ctdb/protocol/protocol_sock.c
new file mode 100644
index 0000000..e32f087
--- /dev/null
+++ b/ctdb/protocol/protocol_sock.c
@@ -0,0 +1,81 @@
+/*
+ CTDB generic sock packet marshalling
+
+ 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 <talloc.h>
+
+#include "protocol.h"
+#include "protocol_private.h"
+#include "protocol_api.h"
+
+size_t sock_packet_header_len(struct sock_packet_header *in)
+{
+ return ctdb_uint32_len(&in->length) +
+ ctdb_uint32_len(&in->reqid);
+}
+
+void sock_packet_header_push(struct sock_packet_header *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->length, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int sock_packet_header_pull(uint8_t *buf, size_t buflen,
+ struct sock_packet_header *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->length, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reqid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+void sock_packet_header_set_reqid(struct sock_packet_header *h,
+ uint32_t reqid)
+{
+ h->reqid = reqid;
+}
+
+void sock_packet_header_set_length(struct sock_packet_header *h,
+ uint32_t length)
+{
+ h->length = length;
+}
diff --git a/ctdb/protocol/protocol_tunnel.c b/ctdb/protocol/protocol_tunnel.c
new file mode 100644
index 0000000..d31d9d5
--- /dev/null
+++ b/ctdb/protocol/protocol_tunnel.c
@@ -0,0 +1,114 @@
+/*
+ CTDB protocol marshalling
+
+ 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 <talloc.h>
+#include <tdb.h>
+
+#include "protocol.h"
+#include "protocol_api.h"
+#include "protocol_private.h"
+
+size_t ctdb_req_tunnel_len(struct ctdb_req_header *h,
+ struct ctdb_req_tunnel *c)
+{
+ return ctdb_req_header_len(h) +
+ ctdb_uint64_len(&c->tunnel_id) +
+ ctdb_uint32_len(&c->flags) +
+ ctdb_tdb_datan_len(&c->data);
+}
+
+int ctdb_req_tunnel_push(struct ctdb_req_header *h,
+ struct ctdb_req_tunnel *c,
+ uint8_t *buf, size_t *buflen)
+{
+ size_t length, offset = 0, np;
+
+ length = ctdb_req_tunnel_len(h, c);
+ if (*buflen < length) {
+ *buflen = length;
+ return EMSGSIZE;
+ }
+
+ h->length = *buflen;
+ ctdb_req_header_push(h, buf, &np);
+ offset += np;
+
+ ctdb_uint64_push(&c->tunnel_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&c->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&c->data, buf+offset, &np);
+ offset += np;
+
+ if (offset > *buflen) {
+ return EMSGSIZE;
+ }
+
+ return 0;
+}
+
+int ctdb_req_tunnel_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_req_header *h,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_req_tunnel *c)
+{
+ struct ctdb_req_header header;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_req_header_pull(buf, buflen, &header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (h != NULL) {
+ *h = header;
+ }
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->tunnel_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, mem_ctx,
+ &c->data, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (offset > buflen) {
+ return EMSGSIZE;
+ }
+
+ return 0;
+}
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c
new file mode 100644
index 0000000..0eb1923
--- /dev/null
+++ b/ctdb/protocol/protocol_types.c
@@ -0,0 +1,5348 @@
+/*
+ CTDB protocol marshalling
+
+ Copyright (C) Amitay Isaacs 2015-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 <talloc.h>
+#include <tdb.h>
+
+#include "protocol.h"
+#include "protocol_private.h"
+#include "protocol_api.h"
+
+size_t ctdb_tdb_data_len(TDB_DATA *in)
+{
+ return in->dsize > UINT32_MAX ? UINT32_MAX : in->dsize;
+}
+
+void ctdb_tdb_data_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
+{
+ size_t len = ctdb_tdb_data_len(in);
+
+ if (len > 0) {
+ memcpy(buf, in->dptr, len);
+ }
+
+ *npush = len;
+}
+
+int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ TDB_DATA *out, size_t *npull)
+{
+ TDB_DATA val;
+
+ if (buflen > UINT32_MAX) {
+ return EMSGSIZE;
+ }
+
+ val.dsize = buflen;
+ if (val.dsize > 0) {
+ val.dptr = talloc_memdup(mem_ctx, buf, buflen);
+ if (val.dptr == NULL) {
+ return ENOMEM;
+ }
+ } else {
+ val.dptr = NULL;
+ }
+
+ *out = val;
+ *npull = buflen;
+ return 0;
+}
+
+size_t ctdb_tdb_datan_len(TDB_DATA *in)
+{
+ uint32_t u32 = ctdb_tdb_data_len(in);
+
+ return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_tdb_datan_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t u32 = ctdb_tdb_data_len(in);
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(in, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_tdb_datan_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ TDB_DATA *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < u32) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, u32, mem_ctx, out, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_latency_counter_len(struct ctdb_latency_counter *in)
+{
+ return ctdb_int32_len(&in->num) +
+ ctdb_padding_len(4) +
+ ctdb_double_len(&in->min) +
+ ctdb_double_len(&in->max) +
+ ctdb_double_len(&in->total);
+}
+
+void ctdb_latency_counter_push(struct ctdb_latency_counter *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_int32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_double_push(&in->min, buf+offset, &np);
+ offset += np;
+
+ ctdb_double_push(&in->max, buf+offset, &np);
+ offset += np;
+
+ ctdb_double_push(&in->total, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_latency_counter_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_latency_counter *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->num, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_double_pull(buf+offset, buflen-offset, &out->min, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_double_pull(buf+offset, buflen-offset, &out->max, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_double_pull(buf+offset, buflen-offset, &out->total, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_statistics_len(struct ctdb_statistics *in)
+{
+ return ctdb_uint32_len(&in->num_clients) +
+ ctdb_uint32_len(&in->frozen) +
+ ctdb_uint32_len(&in->recovering) +
+ ctdb_uint32_len(&in->client_packets_sent) +
+ ctdb_uint32_len(&in->client_packets_recv) +
+ ctdb_uint32_len(&in->node_packets_sent) +
+ ctdb_uint32_len(&in->node_packets_recv) +
+ ctdb_uint32_len(&in->keepalive_packets_sent) +
+ ctdb_uint32_len(&in->keepalive_packets_recv) +
+ ctdb_uint32_len(&in->node.req_call) +
+ ctdb_uint32_len(&in->node.reply_call) +
+ ctdb_uint32_len(&in->node.req_dmaster) +
+ ctdb_uint32_len(&in->node.reply_dmaster) +
+ ctdb_uint32_len(&in->node.reply_error) +
+ ctdb_uint32_len(&in->node.req_message) +
+ ctdb_uint32_len(&in->node.req_control) +
+ ctdb_uint32_len(&in->node.reply_control) +
+ ctdb_uint32_len(&in->node.req_tunnel) +
+ ctdb_uint32_len(&in->client.req_call) +
+ ctdb_uint32_len(&in->client.req_message) +
+ ctdb_uint32_len(&in->client.req_control) +
+ ctdb_uint32_len(&in->client.req_tunnel) +
+ ctdb_uint32_len(&in->timeouts.call) +
+ ctdb_uint32_len(&in->timeouts.control) +
+ ctdb_uint32_len(&in->timeouts.traverse) +
+ ctdb_padding_len(4) +
+ ctdb_latency_counter_len(&in->reclock.ctdbd) +
+ ctdb_latency_counter_len(&in->reclock.recd) +
+ ctdb_uint32_len(&in->locks.num_calls) +
+ ctdb_uint32_len(&in->locks.num_current) +
+ ctdb_uint32_len(&in->locks.num_pending) +
+ ctdb_uint32_len(&in->locks.num_failed) +
+ ctdb_latency_counter_len(&in->locks.latency) +
+ MAX_COUNT_BUCKETS * ctdb_uint32_len(&in->locks.buckets[0]) +
+ ctdb_uint32_len(&in->total_calls) +
+ ctdb_uint32_len(&in->pending_calls) +
+ ctdb_uint32_len(&in->childwrite_calls) +
+ ctdb_uint32_len(&in->pending_childwrite_calls) +
+ ctdb_uint32_len(&in->memory_used) +
+ ctdb_uint32_len(&in->__last_counter) +
+ ctdb_uint32_len(&in->max_hop_count) +
+ MAX_COUNT_BUCKETS *
+ ctdb_uint32_len(&in->hop_count_bucket[0]) +
+ ctdb_padding_len(4) +
+ ctdb_latency_counter_len(&in->call_latency) +
+ ctdb_latency_counter_len(&in->childwrite_latency) +
+ ctdb_uint32_len(&in->num_recoveries) +
+ ctdb_padding_len(4) +
+ ctdb_timeval_len(&in->statistics_start_time) +
+ ctdb_timeval_len(&in->statistics_current_time) +
+ ctdb_uint32_len(&in->total_ro_delegations) +
+ ctdb_uint32_len(&in->total_ro_revokes);
+}
+
+void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ int i;
+
+ ctdb_uint32_push(&in->num_clients, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->frozen, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovering, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_packets_sent, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_packets_recv, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node_packets_sent, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node_packets_recv, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_packets_sent, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_packets_recv, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_dmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_dmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_error, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_message, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_tunnel, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_message, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_tunnel, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeouts.call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeouts.control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeouts.traverse, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->reclock.ctdbd, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->reclock.recd, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
+ offset += np;
+ }
+
+ ctdb_uint32_push(&in->total_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pending_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->childwrite_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pending_childwrite_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->memory_used, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->__last_counter, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->max_hop_count, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
+ offset += np;
+ }
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->call_latency, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->childwrite_latency, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->num_recoveries, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->statistics_start_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->statistics_current_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->total_ro_delegations, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->total_ro_revokes, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_statistics_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret, i;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->num_clients,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->frozen, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->recovering,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client_packets_sent, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client_packets_recv, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node_packets_sent, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node_packets_recv, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_packets_sent, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_packets_recv, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_error, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_message, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_tunnel, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_message, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_tunnel, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->timeouts.call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->timeouts.control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->timeouts.traverse, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->reclock.ctdbd, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->reclock.recd, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_current, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_pending, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_failed, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->locks.latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.buckets[i], &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->total_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->pending_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->childwrite_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->pending_childwrite_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->memory_used,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->__last_counter, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->max_hop_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->hop_count_bucket[i], &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->call_latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->childwrite_latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->num_recoveries, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &out->statistics_start_time, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &out->statistics_current_time, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->total_ro_delegations, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->total_ro_revokes, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics **out, size_t *npull)
+{
+ struct ctdb_statistics *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_statistics);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_statistics_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_statistics_list_len(struct ctdb_statistics_list *in)
+{
+ size_t len;
+
+ len = ctdb_int32_len(&in->num) + ctdb_padding_len(4);
+ if (in->num > 0) {
+ len += in->num * ctdb_statistics_len(&in->stats[0]);
+ }
+
+ return len;
+}
+
+void ctdb_statistics_list_push(struct ctdb_statistics_list *in,
+ uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ int i;
+
+ ctdb_int32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_statistics_push(&in->stats[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics_list **out,
+ size_t *npull)
+{
+ struct ctdb_statistics_list *val;
+ size_t offset = 0, np;
+ int ret, i;
+
+ val = talloc(mem_ctx, struct ctdb_statistics_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->stats = NULL;
+ goto done;
+ }
+
+ val->stats = talloc_array(val, struct ctdb_statistics, val->num);
+ if (val->stats == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_statistics_pull_elems(buf+offset, buflen-offset,
+ val, &val->stats[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->generation) + ctdb_uint32_len(&in->size);
+ if (in->size > 0) {
+ len += in->size * ctdb_uint32_len(&in->map[0]);
+ }
+
+ return len;
+}
+
+void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->generation, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->size, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->size; i++) {
+ ctdb_uint32_push(&in->map[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_vnn_map **out, size_t *npull)
+{
+ struct ctdb_vnn_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_vnn_map);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->generation,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->size, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->size == 0) {
+ val->map = NULL;
+ goto done;
+ }
+
+ val->map = talloc_array(val, uint32_t, val->size);
+ if (val->map == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->size; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &val->map[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_dbid_len(struct ctdb_dbid *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint8_len(&in->flags) +
+ ctdb_padding_len(3);
+}
+
+void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint8_push(&in->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(3, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->db_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint8_pull(buf+offset, buflen-offset, &out->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 3, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid **out, size_t *npull)
+{
+ struct ctdb_dbid *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_dbid);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_dbid_len(&in->dbs[0]);
+ }
+
+ return len;
+}
+
+void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_dbid_push(&in->dbs[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid_map **out, size_t *npull)
+{
+ struct ctdb_dbid_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_dbid_map);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->dbs = NULL;
+ goto done;
+ }
+
+ val->dbs = talloc_array(val, struct ctdb_dbid, val->num);
+ if (val->dbs == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_dbid_pull_elems(buf+offset, buflen-offset, val,
+ &val->dbs[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_pulldb_len(struct ctdb_pulldb *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->lmaster);
+}
+
+void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lmaster, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_pulldb **out, size_t *npull)
+{
+ struct ctdb_pulldb *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_pulldb);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->lmaster) +
+ ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_pulldb_ext **out, size_t *npull)
+{
+ struct ctdb_pulldb_ext *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_pulldb_ext);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_db_vacuum_len(struct ctdb_db_vacuum *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_bool_len(&in->full_vacuum_run);
+}
+
+void ctdb_db_vacuum_push(struct ctdb_db_vacuum *in,
+ uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_bool_push(&in->full_vacuum_run, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_db_vacuum_pull(uint8_t *buf,
+ size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_db_vacuum **out,
+ size_t *npull)
+{
+ struct ctdb_db_vacuum *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_db_vacuum);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset,
+ buflen-offset,
+ &val->db_id,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_bool_pull(buf+offset,
+ buflen-offset,
+ &val->full_vacuum_run,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_echo_data_len(struct ctdb_echo_data *in)
+{
+ /*
+ * No overflow check, none of the routines in this file do it
+ * and there's no way to report it anyway.
+ */
+ return ctdb_uint32_len(&in->timeout) + ctdb_tdb_datan_len(&in->buf);
+}
+
+void ctdb_echo_data_push(struct ctdb_echo_data *in,
+ uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ /*
+ * No overflow check, none of the routines in this file do it
+ * and there's no way to report it anyway.
+ */
+
+ ctdb_uint32_push(&in->timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&in->buf, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_echo_data_pull(uint8_t *buf,
+ size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_echo_data **out,
+ size_t *npull)
+{
+ struct ctdb_echo_data *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_echo_data);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset,
+ buflen-offset,
+ &val->timeout,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset,
+ buflen-offset,
+ val,
+ &val->buf,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in)
+{
+ return ctdb_uint64_len(&in->rsn) +
+ ctdb_uint32_len(&in->dmaster) +
+ ctdb_uint32_len(&in->reserved1) +
+ ctdb_uint32_len(&in->flags) +
+ ctdb_padding_len(4);
+}
+
+void ctdb_ltdb_header_push(struct ctdb_ltdb_header *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint64_push(&in->rsn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->dmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reserved1, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_ltdb_header *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->rsn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reserved1,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header)
+{
+ size_t np;
+ int ret;
+
+ ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header, &np);
+ if (ret != 0) {
+ return ret;
+ }
+
+ data->dptr += np;
+ data->dsize -= np;
+
+ return 0;
+}
+
+size_t ctdb_rec_data_len(struct ctdb_rec_data *in)
+{
+ uint32_t u32;
+
+ u32 = ctdb_uint32_len(&in->reqid) +
+ ctdb_tdb_datan_len(&in->key) +
+ ctdb_tdb_datan_len(&in->data);
+
+ if (in->header != NULL) {
+ u32 += ctdb_ltdb_header_len(in->header);
+ }
+
+ return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_rec_data_push(struct ctdb_rec_data *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t u32;
+
+ u32 = ctdb_rec_data_len(in);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&in->key);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&in->data);
+ if (in->header != NULL) {
+ u32 += ctdb_ltdb_header_len(in->header);
+ }
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&in->key, buf+offset, &np);
+ offset += np;
+
+ /* If ltdb header is not NULL, then it is pushed as part of the data */
+ if (in->header != NULL) {
+ ctdb_ltdb_header_push(in->header, buf+offset, &np);
+ offset += np;
+ }
+ ctdb_tdb_data_push(&in->data, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_rec_data_pull_data(uint8_t *buf, size_t buflen,
+ uint32_t *reqid,
+ TDB_DATA *key, TDB_DATA *data,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ size_t len;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen < u32) {
+ return EMSGSIZE;
+ }
+ len = u32;
+
+ ret = ctdb_uint32_pull(buf+offset, len-offset, reqid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ key->dsize = u32;
+
+ ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ data->dsize = u32;
+
+ if (len-offset < key->dsize) {
+ return EMSGSIZE;
+ }
+
+ key->dptr = buf+offset;
+ offset += key->dsize;
+
+ if (len-offset < data->dsize) {
+ return EMSGSIZE;
+ }
+
+ data->dptr = buf+offset;
+ offset += data->dsize;
+
+ *npull = offset;
+ return 0;
+}
+
+static int ctdb_rec_data_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_data *out,
+ size_t *npull)
+{
+ uint32_t reqid;
+ TDB_DATA key, data;
+ size_t np;
+ int ret;
+
+ ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &key, &data, &np);
+ if (ret != 0) {
+ return ret;
+ }
+
+ out->reqid = reqid;
+
+ /* Always set header to NULL. If it is required, extract it using
+ * ctdb_rec_data_extract_header()
+ */
+ out->header = NULL;
+
+ out->key.dsize = key.dsize;
+ if (key.dsize > 0) {
+ out->key.dptr = talloc_memdup(mem_ctx, key.dptr, key.dsize);
+ if (out->key.dptr == NULL) {
+ return ENOMEM;
+ }
+ }
+
+ out->data.dsize = data.dsize;
+ if (data.dsize > 0) {
+ out->data.dptr = talloc_memdup(mem_ctx, data.dptr, data.dsize);
+ if (out->data.dptr == NULL) {
+ return ENOMEM;
+ }
+ }
+
+ *npull = np;
+ return 0;
+}
+
+int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_data **out, size_t *npull)
+{
+ struct ctdb_rec_data *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_rec_data);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_rec_data_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ TALLOC_FREE(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->count) +
+ in->buflen;
+}
+
+void ctdb_rec_buffer_push(struct ctdb_rec_buffer *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->count, buf+offset, &np);
+ offset += np;
+
+ memcpy(buf+offset, in->buf, in->buflen);
+ offset += in->buflen;
+
+ *npush = offset;
+}
+
+int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_buffer **out, size_t *npull)
+{
+ struct ctdb_rec_buffer *val;
+ size_t offset = 0, np;
+ size_t length;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_rec_buffer);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->count, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ /* Since there is no buflen provided, walk the records to
+ * validate the length of the buffer.
+ */
+ val->buf = buf+offset;
+ val->buflen = buflen-offset;
+
+ length = 0;
+ ret = ctdb_rec_buffer_traverse(val, NULL, &length);
+ if (ret != 0) {
+ goto fail;
+ }
+
+ if (length > buflen-offset) {
+ ret = EMSGSIZE;
+ goto fail;
+ }
+
+ val->buf = talloc_memdup(val, buf+offset, length);
+ if (val->buf == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+ val->buflen = length;
+ offset += length;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
+ uint32_t db_id)
+{
+ struct ctdb_rec_buffer *recbuf;
+
+ recbuf = talloc_zero(mem_ctx, struct ctdb_rec_buffer);
+ if (recbuf == NULL) {
+ return recbuf;
+ }
+
+ recbuf->db_id = db_id;
+
+ return recbuf;
+}
+
+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)
+{
+ struct ctdb_rec_data recdata;
+ size_t len, np;
+ uint8_t *ptr;
+
+ recdata.reqid = reqid;
+ recdata.header = header;
+ recdata.key = key;
+ recdata.data = data;
+
+ len = ctdb_rec_data_len(&recdata);
+
+ ptr = talloc_realloc(mem_ctx, recbuf->buf, uint8_t,
+ recbuf->buflen + len);
+ if (ptr == NULL) {
+ return ENOMEM;
+ }
+
+ ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen], &np);
+
+ recbuf->count++;
+ recbuf->buf = ptr;
+ recbuf->buflen += np;
+ return 0;
+}
+
+int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
+ ctdb_rec_parser_func_t func,
+ void *private_data)
+{
+ TDB_DATA key, data;
+ uint32_t reqid;
+ size_t offset, reclen;
+ unsigned int i;
+ int ret = 0;
+
+ offset = 0;
+ for (i=0; i<recbuf->count; i++) {
+ ret = ctdb_rec_data_pull_data(&recbuf->buf[offset],
+ recbuf->buflen - offset,
+ &reqid, &key, &data, &reclen);
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (func != NULL) {
+ ret = func(reqid, NULL, key, data, private_data);
+ if (ret != 0) {
+ break;
+ }
+ }
+
+ offset += reclen;
+ }
+
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (func == NULL) {
+ size_t *length = (size_t *)private_data;
+
+ *length = offset;
+ }
+
+ return 0;
+}
+
+int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)
+{
+ ssize_t n;
+
+ n = write(fd, &recbuf->db_id, sizeof(uint32_t));
+ if (n == -1 || (size_t)n != sizeof(uint32_t)) {
+ return (errno != 0 ? errno : EIO);
+ }
+ n = write(fd, &recbuf->count, sizeof(uint32_t));
+ if (n == -1 || (size_t)n != sizeof(uint32_t)) {
+ return (errno != 0 ? errno : EIO);
+ }
+ n = write(fd, &recbuf->buflen, sizeof(size_t));
+ if (n == -1 || (size_t)n != sizeof(size_t)) {
+ return (errno != 0 ? errno : EIO);
+ }
+ n = write(fd, recbuf->buf, recbuf->buflen);
+ if (n == -1 || (size_t)n != recbuf->buflen) {
+ return (errno != 0 ? errno : EIO);
+ }
+
+ return 0;
+}
+
+int ctdb_rec_buffer_read(int fd, TALLOC_CTX *mem_ctx,
+ struct ctdb_rec_buffer **out)
+{
+ struct ctdb_rec_buffer *recbuf;
+ ssize_t n;
+
+ recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
+ if (recbuf == NULL) {
+ return ENOMEM;
+ }
+
+ n = read(fd, &recbuf->db_id, sizeof(uint32_t));
+ if (n == -1 || (size_t)n != sizeof(uint32_t)) {
+ return (errno != 0 ? errno : EIO);
+ }
+ n = read(fd, &recbuf->count, sizeof(uint32_t));
+ if (n == -1 || (size_t)n != sizeof(uint32_t)) {
+ return (errno != 0 ? errno : EIO);
+ }
+ n = read(fd, &recbuf->buflen, sizeof(size_t));
+ if (n == -1 || (size_t)n != sizeof(size_t)) {
+ return (errno != 0 ? errno : EIO);
+ }
+
+ recbuf->buf = talloc_size(recbuf, recbuf->buflen);
+ if (recbuf->buf == NULL) {
+ return ENOMEM;
+ }
+
+ n = read(fd, recbuf->buf, recbuf->buflen);
+ if (n == -1 || (size_t)n != recbuf->buflen) {
+ return (errno != 0 ? errno : EIO);
+ }
+
+ *out = recbuf;
+ return 0;
+}
+
+size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_start **out, size_t *npull)
+{
+ struct ctdb_traverse_start *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_traverse_start);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->client_reqid) +
+ ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_all **out, size_t *npull)
+{
+ struct ctdb_traverse_all *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_traverse_all);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint64_len(&in->srvid) +
+ ctdb_bool_len(&in->withemptyrecords) +
+ ctdb_padding_len(7);
+}
+
+void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *in,
+ uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(7, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_start_ext **out,
+ size_t *npull)
+{
+ struct ctdb_traverse_start_ext *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_traverse_start_ext);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_bool_pull(buf+offset, buflen-offset,
+ &val->withemptyrecords, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->client_reqid) +
+ ctdb_uint64_len(&in->srvid) +
+ ctdb_bool_len(&in->withemptyrecords) +
+ ctdb_padding_len(7);
+}
+
+void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *in,
+ uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(7, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_traverse_all_ext **out,
+ size_t *npull)
+{
+ struct ctdb_traverse_all_ext *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_traverse_all_ext);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_bool_pull(buf+offset, buflen-offset,
+ &val->withemptyrecords, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_sock_addr_len(ctdb_sock_addr *in)
+{
+ return sizeof(ctdb_sock_addr);
+}
+
+void ctdb_sock_addr_push(ctdb_sock_addr *in, uint8_t *buf, size_t *npush)
+{
+ memcpy(buf, in, sizeof(ctdb_sock_addr));
+ *npush = sizeof(ctdb_sock_addr);
+}
+
+int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, ctdb_sock_addr *out,
+ size_t *npull)
+{
+ if (buflen < sizeof(ctdb_sock_addr)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(ctdb_sock_addr));
+ *npull = sizeof(ctdb_sock_addr);
+
+ return 0;
+}
+
+int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ ctdb_sock_addr **out, size_t *npull)
+{
+ ctdb_sock_addr *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, ctdb_sock_addr);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_sock_addr_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_connection_len(struct ctdb_connection *in)
+{
+ return ctdb_sock_addr_len(&in->src) +
+ ctdb_sock_addr_len(&in->dst);
+}
+
+void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_sock_addr_push(&in->src, buf+offset, &np);
+ offset += np;
+
+ ctdb_sock_addr_push(&in->dst, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_connection *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
+ mem_ctx, &out->src, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
+ mem_ctx, &out->dst, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_connection **out, size_t *npull)
+{
+ struct ctdb_connection *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_connection);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_connection_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_connection_list_len(struct ctdb_connection_list *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_connection_len(&in->conn[0]);
+ }
+
+ return len;
+}
+
+void ctdb_connection_list_push(struct ctdb_connection_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_connection_push(&in->conn[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_connection_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list **out, size_t *npull)
+{
+ struct ctdb_connection_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_connection_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->conn = NULL;
+ goto done;
+ }
+
+ val->conn = talloc_array(val, struct ctdb_connection, val->num);
+ if (val->conn == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
+ val, &val->conn[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_tunable_len(struct ctdb_tunable *in)
+{
+ return ctdb_uint32_len(&in->value) +
+ ctdb_stringn_len(&in->name);
+}
+
+void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->value, buf+offset, &np);
+ offset += np;
+
+ ctdb_stringn_push(&in->name, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable **out, size_t *npull)
+{
+ struct ctdb_tunable *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_tunable);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->value, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_stringn_pull(buf+offset, buflen-offset, mem_ctx,
+ &val->name, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in)
+{
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->new_flags) +
+ ctdb_uint32_len(&in->old_flags);
+}
+
+void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
+ uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->new_flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->old_flags, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_node_flag_change **out,
+ size_t *npull)
+{
+ struct ctdb_node_flag_change *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_node_flag_change);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->new_flags,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->old_flags,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_var_list_len(struct ctdb_var_list *in)
+{
+ uint32_t u32 = 0;
+ int i;
+
+ for (i=0; i<in->count; i++) {
+ u32 += ctdb_string_len(&in->var[i]);
+ }
+
+ return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_var_list_push(struct ctdb_var_list *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t u32;
+ int i;
+ uint8_t sep = ':';
+
+ /* The length only corresponds to the payload size */
+ u32 = ctdb_var_list_len(in);
+ u32 -= ctdb_uint32_len(&u32);
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ /* The variables are separated by ':' and the complete string is null
+ * terminated.
+ */
+ for (i=0; i<in->count; i++) {
+ ctdb_string_push(&in->var[i], buf+offset, &np);
+ offset += np;
+
+ if (i < in->count - 1) {
+ /* Replace '\0' with ':' */
+ ctdb_uint8_push(&sep, buf+offset-1, &np);
+ }
+ }
+
+ *npush = offset;
+}
+
+int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_var_list **out, size_t *npull)
+{
+ struct ctdb_var_list *val;
+ const char *str, **list;
+ char *s, *tok, *ptr = NULL;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ val = talloc_zero(mem_ctx, struct ctdb_var_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (buflen-offset < u32) {
+ ret = EMSGSIZE;
+ goto fail;
+ }
+
+ ret = ctdb_string_pull(buf+offset, u32, val, &str, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ s = discard_const(str);
+ while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
+ list = talloc_realloc(val, val->var, const char *,
+ val->count+1);
+ if (list == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ val->var = list;
+
+ s = talloc_strdup(val, tok);
+ if (s == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ val->var[val->count] = s;
+ val->count += 1;
+ s = NULL;
+ }
+
+ talloc_free(discard_const(str));
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_tunable_list_len(struct ctdb_tunable_list *in)
+{
+ return ctdb_uint32_len(&in->max_redirect_count) +
+ ctdb_uint32_len(&in->seqnum_interval) +
+ ctdb_uint32_len(&in->control_timeout) +
+ ctdb_uint32_len(&in->traverse_timeout) +
+ ctdb_uint32_len(&in->keepalive_interval) +
+ ctdb_uint32_len(&in->keepalive_limit) +
+ ctdb_uint32_len(&in->recover_timeout) +
+ ctdb_uint32_len(&in->recover_interval) +
+ ctdb_uint32_len(&in->election_timeout) +
+ ctdb_uint32_len(&in->takeover_timeout) +
+ ctdb_uint32_len(&in->monitor_interval) +
+ ctdb_uint32_len(&in->tickle_update_interval) +
+ ctdb_uint32_len(&in->script_timeout) +
+ ctdb_uint32_len(&in->monitor_timeout_count) +
+ ctdb_uint32_len(&in->script_unhealthy_on_timeout) +
+ ctdb_uint32_len(&in->recovery_grace_period) +
+ ctdb_uint32_len(&in->recovery_ban_period) +
+ ctdb_uint32_len(&in->database_hash_size) +
+ ctdb_uint32_len(&in->database_max_dead) +
+ ctdb_uint32_len(&in->rerecovery_timeout) +
+ ctdb_uint32_len(&in->enable_bans) +
+ ctdb_uint32_len(&in->deterministic_public_ips) +
+ ctdb_uint32_len(&in->reclock_ping_period) +
+ ctdb_uint32_len(&in->no_ip_failback) +
+ ctdb_uint32_len(&in->disable_ip_failover) +
+ ctdb_uint32_len(&in->verbose_memory_names) +
+ ctdb_uint32_len(&in->recd_ping_timeout) +
+ ctdb_uint32_len(&in->recd_ping_failcount) +
+ ctdb_uint32_len(&in->log_latency_ms) +
+ ctdb_uint32_len(&in->reclock_latency_ms) +
+ ctdb_uint32_len(&in->recovery_drop_all_ips) +
+ ctdb_uint32_len(&in->verify_recovery_lock) +
+ ctdb_uint32_len(&in->vacuum_interval) +
+ ctdb_uint32_len(&in->vacuum_max_run_time) +
+ ctdb_uint32_len(&in->repack_limit) +
+ ctdb_uint32_len(&in->vacuum_limit) +
+ ctdb_uint32_len(&in->max_queue_depth_drop_msg) +
+ ctdb_uint32_len(&in->allow_unhealthy_db_read) +
+ ctdb_uint32_len(&in->stat_history_interval) +
+ ctdb_uint32_len(&in->deferred_attach_timeout) +
+ ctdb_uint32_len(&in->vacuum_fast_path_count) +
+ ctdb_uint32_len(&in->lcp2_public_ip_assignment) +
+ ctdb_uint32_len(&in->allow_client_db_attach) +
+ ctdb_uint32_len(&in->recover_pdb_by_seqnum) +
+ ctdb_uint32_len(&in->deferred_rebalance_on_node_add) +
+ ctdb_uint32_len(&in->fetch_collapse) +
+ ctdb_uint32_len(&in->hopcount_make_sticky) +
+ ctdb_uint32_len(&in->sticky_duration) +
+ ctdb_uint32_len(&in->sticky_pindown) +
+ ctdb_uint32_len(&in->no_ip_takeover) +
+ ctdb_uint32_len(&in->db_record_count_warn) +
+ ctdb_uint32_len(&in->db_record_size_warn) +
+ ctdb_uint32_len(&in->db_size_warn) +
+ ctdb_uint32_len(&in->pulldb_preallocation_size) +
+ ctdb_uint32_len(&in->no_ip_host_on_all_disabled) +
+ ctdb_uint32_len(&in->samba3_hack) +
+ ctdb_uint32_len(&in->mutex_enabled) +
+ ctdb_uint32_len(&in->lock_processes_per_db) +
+ ctdb_uint32_len(&in->rec_buffer_size_limit) +
+ ctdb_uint32_len(&in->queue_buffer_size) +
+ ctdb_uint32_len(&in->ip_alloc_algorithm) +
+ ctdb_uint32_len(&in->allow_mixed_versions);
+}
+
+void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->max_redirect_count, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->seqnum_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->control_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->traverse_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recover_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recover_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->election_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->takeover_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->monitor_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->tickle_update_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->script_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->monitor_timeout_count, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->script_unhealthy_on_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovery_grace_period, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovery_ban_period, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->database_hash_size, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->database_max_dead, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->rerecovery_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->enable_bans, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->deterministic_public_ips, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reclock_ping_period, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->no_ip_failback, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->disable_ip_failover, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->verbose_memory_names, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recd_ping_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recd_ping_failcount, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->log_latency_ms, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reclock_latency_ms, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovery_drop_all_ips, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->verify_recovery_lock, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_max_run_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->repack_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->max_queue_depth_drop_msg, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->allow_unhealthy_db_read, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->stat_history_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->deferred_attach_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_fast_path_count, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lcp2_public_ip_assignment, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->allow_client_db_attach, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recover_pdb_by_seqnum, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->deferred_rebalance_on_node_add, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->fetch_collapse, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->hopcount_make_sticky, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->sticky_duration, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->sticky_pindown, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->no_ip_takeover, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_record_count_warn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_record_size_warn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_size_warn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pulldb_preallocation_size, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->no_ip_host_on_all_disabled, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->samba3_hack, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->mutex_enabled, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lock_processes_per_db, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->rec_buffer_size_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->queue_buffer_size, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->ip_alloc_algorithm, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->allow_mixed_versions, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_tunable_list_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable_list *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->max_redirect_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->seqnum_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->control_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->traverse_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recover_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recover_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->election_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->takeover_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->monitor_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->tickle_update_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->script_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->monitor_timeout_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->script_unhealthy_on_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recovery_grace_period, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recovery_ban_period, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->database_hash_size, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->database_max_dead, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->rerecovery_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->enable_bans, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->deterministic_public_ips, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->reclock_ping_period, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->no_ip_failback, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->disable_ip_failover, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->verbose_memory_names, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recd_ping_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recd_ping_failcount, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->log_latency_ms, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->reclock_latency_ms, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recovery_drop_all_ips, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->verify_recovery_lock, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_max_run_time, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->repack_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->max_queue_depth_drop_msg, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->allow_unhealthy_db_read, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->stat_history_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->deferred_attach_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_fast_path_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->lcp2_public_ip_assignment, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->allow_client_db_attach, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recover_pdb_by_seqnum, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->deferred_rebalance_on_node_add, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->fetch_collapse, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->hopcount_make_sticky, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->sticky_duration, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->sticky_pindown, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->no_ip_takeover, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_record_count_warn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_record_size_warn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_size_warn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->pulldb_preallocation_size, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->no_ip_host_on_all_disabled, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->samba3_hack, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->mutex_enabled, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->lock_processes_per_db, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->rec_buffer_size_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->queue_buffer_size, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->ip_alloc_algorithm, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->allow_mixed_versions, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable_list **out, size_t *npull)
+{
+ struct ctdb_tunable_list *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_tunable_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_tunable_list_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in)
+{
+ size_t len;
+
+ len = ctdb_sock_addr_len(&in->addr) +
+ ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_connection_len(&in->conn[0]);
+ }
+
+ return len;
+}
+
+void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_connection_push(&in->conn[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_tickle_list **out, size_t *npull)
+{
+ struct ctdb_tickle_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_tickle_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
+ &val->addr, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->conn = NULL;
+ goto done;
+ }
+
+ val->conn = talloc_array(val, struct ctdb_connection, val->num);
+ if (val->conn == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
+ val, &val->conn[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_addr_info_len(struct ctdb_addr_info *in)
+{
+ return ctdb_sock_addr_len(&in->addr) +
+ ctdb_uint32_len(&in->mask) +
+ ctdb_stringn_len(&in->iface);
+}
+
+void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->mask, buf+offset, &np);
+ offset += np;
+
+ ctdb_stringn_push(&in->iface, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_addr_info **out, size_t *npull)
+{
+ struct ctdb_addr_info *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_addr_info);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
+ &val->addr, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->mask, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_stringn_pull(buf+offset, buflen-offset, val, &val->iface,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_transdb_len(struct ctdb_transdb *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->tid);
+}
+
+void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->tid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_transdb **out, size_t *npull)
+{
+ struct ctdb_transdb *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_transdb);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->tid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_uptime_len(struct ctdb_uptime *in)
+{
+ return ctdb_timeval_len(&in->current_time) +
+ ctdb_timeval_len(&in->ctdbd_start_time) +
+ ctdb_timeval_len(&in->last_recovery_started) +
+ ctdb_timeval_len(&in->last_recovery_finished);
+}
+
+void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_timeval_push(&in->current_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->ctdbd_start_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->last_recovery_started, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->last_recovery_finished, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_uptime **out, size_t *npull)
+{
+ struct ctdb_uptime *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_uptime);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &val->current_time,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->ctdbd_start_time, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->last_recovery_started, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->last_recovery_finished, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_public_ip_len(struct ctdb_public_ip *in)
+{
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_sock_addr_len(&in->addr);
+}
+
+void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_public_ip_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
+ &out->addr, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip **out, size_t *npull)
+{
+ struct ctdb_public_ip *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_public_ip);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_public_ip_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ TALLOC_FREE(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_public_ip_len(&in->ip[0]);
+ }
+
+ return len;
+}
+
+void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_public_ip_push(&in->ip[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip_list **out, size_t *npull)
+{
+ struct ctdb_public_ip_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_public_ip_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->ip = NULL;
+ goto done;
+ }
+
+ val->ip = talloc_array(val, struct ctdb_public_ip, val->num);
+ if (val->ip == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset,
+ val->ip, &val->ip[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in)
+{
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->flags) +
+ ctdb_sock_addr_len(&in->addr);
+}
+
+void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_node_and_flags_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_node_and_flags *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
+ &out->addr, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_node_and_flags **out, size_t *npull)
+{
+ struct ctdb_node_and_flags *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_node_and_flags);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_node_and_flags_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ TALLOC_FREE(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_node_map_len(struct ctdb_node_map *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_node_and_flags_len(&in->node[0]);
+ }
+
+ return len;
+}
+
+void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_node_and_flags_push(&in->node[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_node_map **out, size_t *npull)
+{
+ struct ctdb_node_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_node_map);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->node = NULL;
+ goto done;
+ }
+
+ val->node = talloc_array(val, struct ctdb_node_and_flags, val->num);
+ if (val->node == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_node_and_flags_pull_elems(buf+offset,
+ buflen-offset,
+ val->node, &val->node[i],
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_script_len(struct ctdb_script *in)
+{
+ return ctdb_chararray_len(in->name, MAX_SCRIPT_NAME+1) +
+ ctdb_timeval_len(&in->start) +
+ ctdb_timeval_len(&in->finished) +
+ ctdb_int32_len(&in->status) +
+ ctdb_chararray_len(in->output, MAX_SCRIPT_OUTPUT+1) +
+ ctdb_padding_len(4);
+}
+
+void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_chararray_push(in->name, MAX_SCRIPT_NAME+1, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->start, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->finished, buf+offset, &np);
+ offset += np;
+
+ ctdb_int32_push(&in->status, buf+offset, &np);
+ offset += np;
+
+ ctdb_chararray_push(in->output, MAX_SCRIPT_OUTPUT+1, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_script_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_script *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->name, MAX_SCRIPT_NAME+1, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->start, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->finished,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->status, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->output, MAX_SCRIPT_OUTPUT+1, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_script **out, size_t *npull)
+{
+ struct ctdb_script *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_script);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_script_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ TALLOC_FREE(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_script_list_len(struct ctdb_script_list *in)
+{
+ size_t len;
+
+ if (in == NULL) {
+ return 0;
+ }
+
+ len = ctdb_uint32_len(&in->num_scripts) + ctdb_padding_len(4);
+ if (in->num_scripts > 0) {
+ len += in->num_scripts * ctdb_script_len(&in->script[0]);
+ }
+
+ return len;
+}
+
+void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ if (in == NULL) {
+ *npush = 0;
+ return;
+ }
+
+ ctdb_uint32_push(&in->num_scripts, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num_scripts; i++) {
+ ctdb_script_push(&in->script[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_script_list **out, size_t *npull)
+{
+ struct ctdb_script_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ /* If event scripts have never been run, the result will be NULL */
+ if (buflen == 0) {
+ val = NULL;
+ goto done;
+ }
+
+ val = talloc(mem_ctx, struct ctdb_script_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_scripts,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num_scripts == 0) {
+ val->script = NULL;
+ goto done;
+ }
+
+ val->script = talloc_array(val, struct ctdb_script, val->num_scripts);
+ if (val->script == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num_scripts; i++) {
+ ret = ctdb_script_pull_elems(buf+offset, buflen-offset,
+ val, &val->script[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_ban_state_len(struct ctdb_ban_state *in)
+{
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->time);
+}
+
+void ctdb_ban_state_push(struct ctdb_ban_state *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->time, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_ban_state **out, size_t *npull)
+{
+ struct ctdb_ban_state *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_ban_state);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->time, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_notify_data_len(struct ctdb_notify_data *in)
+{
+ return ctdb_uint64_len(&in->srvid) +
+ ctdb_tdb_datan_len(&in->data);
+}
+
+void ctdb_notify_data_push(struct ctdb_notify_data *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&in->data, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_notify_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_notify_data **out, size_t *npull)
+{
+ struct ctdb_notify_data *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_notify_data);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, val, &val->data,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_iface_len(struct ctdb_iface *in)
+{
+ return ctdb_chararray_len(in->name, CTDB_IFACE_SIZE+2) +
+ ctdb_uint16_len(&in->link_state) +
+ ctdb_uint32_len(&in->references);
+}
+
+void ctdb_iface_push(struct ctdb_iface *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_chararray_push(in->name, CTDB_IFACE_SIZE+2, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint16_push(&in->link_state, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->references, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_iface_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_iface *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->name, CTDB_IFACE_SIZE+2, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint16_pull(buf+offset, buflen-offset, &out->link_state,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->references,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_iface_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_iface **out, size_t *npull)
+{
+ struct ctdb_iface *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_iface);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_iface_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return ret;
+}
+
+size_t ctdb_iface_list_len(struct ctdb_iface_list *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_iface_len(&in->iface[0]);
+ }
+
+ return len;
+}
+
+void ctdb_iface_list_push(struct ctdb_iface_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_iface_push(&in->iface[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_iface_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_iface_list **out, size_t *npull)
+{
+ struct ctdb_iface_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_iface_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->iface = NULL;
+ goto done;
+ }
+
+ val->iface = talloc_array(val, struct ctdb_iface, val->num);
+ if (val->iface == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_iface_pull_elems(buf+offset, buflen-offset,
+ val, &val->iface[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *in)
+{
+ return ctdb_public_ip_len(&in->ip) +
+ ctdb_uint32_len(&in->active_idx) +
+ ctdb_iface_list_len(in->ifaces);
+}
+
+void ctdb_public_ip_info_push(struct ctdb_public_ip_info *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_public_ip_push(&in->ip, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->active_idx, buf+offset, &np);
+ offset += np;
+
+ ctdb_iface_list_push(in->ifaces, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_public_ip_info **out, size_t *npull)
+{
+ struct ctdb_public_ip_info *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_public_ip_info);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset, val,
+ &val->ip, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->active_idx,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_iface_list_pull(buf+offset, buflen-offset, val,
+ &val->ifaces, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_key_data_len(struct ctdb_key_data *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_padding_len(4) +
+ ctdb_ltdb_header_len(&in->header) +
+ ctdb_tdb_datan_len(&in->key);
+}
+
+void ctdb_key_data_push(struct ctdb_key_data *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_ltdb_header_push(&in->header, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_datan_push(&in->key, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_key_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_key_data **out, size_t *npull)
+{
+ struct ctdb_key_data *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_key_data);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_ltdb_header_pull(buf+offset, buflen-offset, &val->header,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, val, &val->key,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+/* In the tdb_data structure marshalling, we are only interested in dsize.
+ * The dptr value is ignored. The actual tdb_data blob is stored separately.
+ *
+ * This is only required for ctdb_db_statistics and will be dropped in future.
+ */
+
+static size_t tdb_data_struct_len(TDB_DATA *data)
+{
+ return sizeof(void *) + sizeof(size_t);
+}
+
+static void tdb_data_struct_push(TDB_DATA *data, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0;
+
+ memcpy(buf+offset, &data->dptr, sizeof(void *));
+ offset += sizeof(void *);
+
+ memcpy(buf+offset, &data->dsize, sizeof(size_t));
+ offset += sizeof(size_t);
+
+ *npush = offset;
+}
+
+static int tdb_data_struct_pull(uint8_t *buf, size_t buflen, TDB_DATA *data,
+ size_t *npull)
+{
+ size_t offset = 0;
+ void *ptr;
+
+ if (buflen-offset < sizeof(void *)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(&ptr, buf+offset, sizeof(void *));
+ offset += sizeof(void *);
+ data->dptr = NULL;
+
+ if (buflen-offset < sizeof(size_t)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(&data->dsize, buf+offset, sizeof(size_t));
+ offset += sizeof(size_t);
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_db_statistics_len(struct ctdb_db_statistics *in)
+{
+ TDB_DATA data = { 0 };
+ size_t len;
+ uint32_t u32 = 0;
+ int i;
+
+ len = ctdb_uint32_len(&in->locks.num_calls) +
+ ctdb_uint32_len(&in->locks.num_current) +
+ ctdb_uint32_len(&in->locks.num_pending) +
+ ctdb_uint32_len(&in->locks.num_failed) +
+ ctdb_latency_counter_len(&in->locks.latency) +
+ MAX_COUNT_BUCKETS *
+ ctdb_uint32_len(&in->locks.buckets[0]) +
+ ctdb_latency_counter_len(&in->vacuum.latency) +
+ ctdb_uint32_len(&in->db_ro_delegations) +
+ ctdb_uint32_len(&in->db_ro_revokes) +
+ MAX_COUNT_BUCKETS *
+ ctdb_uint32_len(&in->hop_count_bucket[0]) +
+ ctdb_uint32_len(&in->num_hot_keys) +
+ ctdb_padding_len(4) +
+ MAX_HOT_KEYS *
+ (ctdb_uint32_len(&u32) + ctdb_padding_len(4) +
+ tdb_data_struct_len(&data));
+
+ for (i=0; i<MAX_HOT_KEYS; i++) {
+ len += ctdb_tdb_data_len(&in->hot_keys[i].key);
+ }
+
+ return len;
+}
+
+void ctdb_db_statistics_push(struct ctdb_db_statistics *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t num_hot_keys;
+ int i;
+
+ ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
+ offset += np;
+ }
+
+ ctdb_latency_counter_push(&in->vacuum.latency, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_ro_delegations, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_ro_revokes, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
+ offset += np;
+ }
+
+ num_hot_keys = MAX_HOT_KEYS;
+ ctdb_uint32_push(&num_hot_keys, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_HOT_KEYS; i++) {
+ ctdb_uint32_push(&in->hot_keys[i].count, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ tdb_data_struct_push(&in->hot_keys[i].key, buf+offset, &np);
+ offset += np;
+ }
+
+ for (i=0; i<MAX_HOT_KEYS; i++) {
+ ctdb_tdb_data_push(&in->hot_keys[i].key, buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+static int ctdb_db_statistics_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_db_statistics *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret, i;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_current, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_pending, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_failed, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->locks.latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.buckets[i], &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->vacuum.latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_ro_delegations, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_ro_revokes, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->hop_count_bucket[i], &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->num_hot_keys, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_HOT_KEYS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->hot_keys[i].count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = tdb_data_struct_pull(buf+offset, buflen-offset,
+ &out->hot_keys[i].key, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ for (i=0; i<MAX_HOT_KEYS; i++) {
+ ret = ctdb_tdb_data_pull(buf+offset,
+ out->hot_keys[i].key.dsize,
+ out, &out->hot_keys[i].key, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_db_statistics **out, size_t *npull)
+{
+ struct ctdb_db_statistics *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_db_statistics);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_db_statistics_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_pid_srvid_len(struct ctdb_pid_srvid *in)
+{
+ return ctdb_pid_len(&in->pid) +
+ ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_pid_srvid_push(struct ctdb_pid_srvid *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_pid_push(&in->pid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_pid_srvid **out, size_t *npull)
+{
+ struct ctdb_pid_srvid *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_pid_srvid);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_pid_pull(buf+offset, buflen-offset, &val->pid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_election_message_len(struct ctdb_election_message *in)
+{
+ return ctdb_uint32_len(&in->num_connected) +
+ ctdb_padding_len(4) +
+ ctdb_timeval_len(&in->priority_time) +
+ ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->node_flags);
+}
+
+void ctdb_election_message_push(struct ctdb_election_message *in,
+ uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->num_connected, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->priority_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node_flags, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_election_message_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_election_message **out,
+ size_t *npull)
+{
+ struct ctdb_election_message *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_election_message);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_connected,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->priority_time, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->node_flags,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_srvid_message_len(struct ctdb_srvid_message *in)
+{
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_padding_len(4) +
+ ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_srvid_message **out, size_t *npull)
+{
+ struct ctdb_srvid_message *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_srvid_message);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_disable_message_len(struct ctdb_disable_message *in)
+{
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_padding_len(4) +
+ ctdb_uint64_len(&in->srvid) +
+ ctdb_uint32_len(&in->timeout) +
+ ctdb_padding_len(4);
+}
+
+void ctdb_disable_message_push(struct ctdb_disable_message *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_disable_message **out,
+ size_t *npull)
+{
+ struct ctdb_disable_message *val;
+ size_t offset = 0, np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_disable_message);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->timeout, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_server_id_len(struct ctdb_server_id *in)
+{
+ return ctdb_uint64_len(&in->pid) +
+ ctdb_uint32_len(&in->task_id) +
+ ctdb_uint32_len(&in->vnn) +
+ ctdb_uint64_len(&in->unique_id);
+}
+
+void ctdb_server_id_push(struct ctdb_server_id *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint64_push(&in->pid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->task_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->unique_id, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_server_id_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_server_id *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->pid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->task_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->vnn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->unique_id,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_g_lock_len(struct ctdb_g_lock *in)
+{
+ return ctdb_uint32_len(&in->type) +
+ ctdb_padding_len(4) +
+ ctdb_server_id_len(&in->sid);
+}
+
+void ctdb_g_lock_push(struct ctdb_g_lock *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t type;
+
+ type = in->type;
+ ctdb_uint32_push(&type, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_server_id_push(&in->sid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_g_lock_pull(uint8_t *buf, size_t buflen, struct ctdb_g_lock *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+ uint32_t type;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &type, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (type == 0) {
+ out->type = CTDB_G_LOCK_READ;
+ } else if (type == 1) {
+ out->type = CTDB_G_LOCK_WRITE;
+ } else {
+ return EPROTO;
+ }
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_server_id_pull(buf+offset, buflen-offset, &out->sid, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_g_lock_list_len(struct ctdb_g_lock_list *in)
+{
+ size_t len = 0;
+
+ if (in->num > 0) {
+ len += in->num * ctdb_g_lock_len(&in->lock[0]);
+ }
+
+ return len;
+}
+
+void ctdb_g_lock_list_push(struct ctdb_g_lock_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_g_lock_push(&in->lock[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_g_lock_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_g_lock_list **out, size_t *npull)
+{
+ struct ctdb_g_lock_list *val;
+ struct ctdb_g_lock lock = { 0 };
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_g_lock_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ if (buflen == 0) {
+ val->lock = NULL;
+ val->num = 0;
+ goto done;
+ }
+
+ val->num = buflen / ctdb_g_lock_len(&lock);
+
+ val->lock = talloc_array(val, struct ctdb_g_lock, val->num);
+ if (val->lock == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_g_lock_pull(buf+offset, buflen-offset,
+ &val->lock[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
new file mode 100644
index 0000000..fe75765
--- /dev/null
+++ b/ctdb/protocol/protocol_util.c
@@ -0,0 +1,755 @@
+/*
+ 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 "common/line.h"
+
+#include "protocol.h"
+#include "protocol_util.h"
+#include "lib/util/util.h"
+#include "lib/util/smb_strtox.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;
+}
+
+int ctdb_sock_addr_to_buf(char *buf, socklen_t buflen,
+ ctdb_sock_addr *addr, bool with_port)
+{
+ const char *t;
+ size_t len = 0;
+
+ switch (addr->sa.sa_family) {
+ case AF_INET:
+ t = inet_ntop(addr->ip.sin_family, &addr->ip.sin_addr,
+ buf, buflen);
+ if (t == NULL) {
+ return errno;
+ }
+ if (with_port) {
+ len = strlen(buf);
+ }
+ break;
+
+ case AF_INET6: {
+ char tmp[INET6_ADDRSTRLEN];
+
+ t = inet_ntop(addr->ip6.sin6_family,
+ &addr->ip6.sin6_addr,
+ tmp,
+ sizeof(tmp));
+ if (t == NULL) {
+ return errno;
+ }
+
+ if (with_port) {
+ int ret = snprintf(buf, buflen, "[%s]", tmp);
+ if (ret < 0) {
+ return ENOSPC;
+ }
+ len = (size_t)ret;
+ } else {
+ len = strlcpy(buf, tmp, buflen);
+ }
+ if (len >= buflen){
+ return ENOSPC;
+ }
+ break;
+ }
+
+ default:
+ return EAFNOSUPPORT;
+ break;
+ }
+
+ if (with_port) {
+ int ret;
+
+ ret = snprintf(buf+len, buflen-len,
+ ":%u", ctdb_sock_addr_port(addr));
+ if (ret < 0 || (size_t)ret >= buflen-len) {
+ return ENOSPC;
+ }
+ }
+
+ return 0;
+}
+
+char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx,
+ ctdb_sock_addr *addr,
+ bool with_port)
+{
+ size_t len = 64;
+ char *cip;
+ int ret;
+
+ cip = talloc_size(mem_ctx, len);
+
+ if (cip == NULL) {
+ return NULL;
+ }
+
+ ret = ctdb_sock_addr_to_buf(cip, len, addr, with_port);
+ if (ret != 0) {
+ talloc_free(cip);
+ return NULL;
+ }
+
+ return cip;
+}
+
+static int ipv4_from_string(const char *str, struct sockaddr_in *ip)
+{
+ int ret;
+
+ *ip = (struct sockaddr_in) {
+ .sin_family = AF_INET,
+ };
+
+ ret = inet_pton(AF_INET, str, &ip->sin_addr);
+ if (ret != 1) {
+ return EINVAL;
+ }
+
+#ifdef HAVE_SOCK_SIN_LEN
+ ip->sin_len = sizeof(*ip);
+#endif
+ return 0;
+}
+
+static int ipv6_from_string(const char *str, struct sockaddr_in6 *ip6)
+{
+ int ret;
+
+ *ip6 = (struct sockaddr_in6) {
+ .sin6_family = AF_INET6,
+ };
+
+ ret = inet_pton(AF_INET6, str, &ip6->sin6_addr);
+ if (ret != 1) {
+ return EINVAL;
+ }
+
+#ifdef HAVE_SOCK_SIN6_LEN
+ ip6->sin6_len = sizeof(*ip6);
+#endif
+ return 0;
+}
+
+static int ip_from_string(const char *str, ctdb_sock_addr *addr)
+{
+ char *p;
+ int ret;
+
+ if (addr == NULL) {
+ return EINVAL;
+ }
+
+ ZERO_STRUCTP(addr); /* valgrind :-) */
+
+ /* IPv4 or IPv6 address?
+ *
+ * Use strrchr() because we need the right-most ':' below for
+ * IPv4-mapped IPv6 addresses anyway...
+ */
+ p = strrchr(str, ':');
+ if (p == NULL) {
+ ret = ipv4_from_string(str, &addr->ip);
+ } else {
+ static const uint8_t ipv4_mapped_prefix[12] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff
+ };
+ size_t len = strlen(str);
+ char s[64];
+
+ len = strlcpy(s, str, sizeof(s));
+ if (len >= sizeof(s)) {
+ return EINVAL;
+ }
+
+ if ((len >= 2) && (s[0] == '[') && (s[len-1] == ']')) {
+ s[len-1] = '\0';
+ str = s+1;
+ p = strrchr(str, ':');
+ }
+
+ ret = ipv6_from_string(str, &addr->ip6);
+ if (ret != 0) {
+ return ret;
+ }
+
+ /*
+ * Check for IPv4-mapped IPv6 address
+ * (e.g. ::ffff:192.0.2.128) - reparse as IPv4 if
+ * necessary
+ */
+ if (memcmp(&addr->ip6.sin6_addr.s6_addr[0],
+ ipv4_mapped_prefix,
+ sizeof(ipv4_mapped_prefix)) == 0) {
+ /* Initialize addr struct to zero before reparsing as IPV4 */
+ ZERO_STRUCTP(addr);
+
+ /* Reparse as IPv4 */
+ ret = ipv4_from_string(p+1, &addr->ip);
+ }
+ }
+
+ return ret;
+}
+
+int ctdb_sock_addr_from_string(const char *str,
+ ctdb_sock_addr *addr, bool with_port)
+{
+ char *p;
+ char s[64]; /* Much longer than INET6_ADDRSTRLEN */
+ unsigned port;
+ size_t len;
+ int ret;
+
+ if (! with_port) {
+ ret = ip_from_string(str, addr);
+ return ret;
+ }
+
+ /* Parse out port number and then IP address */
+
+ len = strlcpy(s, str, sizeof(s));
+ if (len >= sizeof(s)) {
+ return EINVAL;
+ }
+
+ p = strrchr(s, ':');
+ if (p == NULL) {
+ return EINVAL;
+ }
+
+ port = smb_strtoul(p+1, NULL, 10, &ret, SMB_STR_FULL_STR_CONV);
+ if (ret != 0) {
+ /* Empty string or trailing garbage */
+ return EINVAL;
+ }
+
+ *p = '\0';
+ ret = ip_from_string(s, addr);
+
+ ctdb_sock_addr_set_port(addr, port);
+
+ return ret;
+}
+
+int ctdb_sock_addr_mask_from_string(const char *str,
+ ctdb_sock_addr *addr,
+ unsigned int *mask)
+{
+ char *p;
+ char s[64]; /* Much longer than INET6_ADDRSTRLEN */
+ unsigned int m;
+ size_t len;
+ int ret = 0;
+
+ if (addr == NULL || mask == NULL) {
+ return EINVAL;
+ }
+
+ len = strlcpy(s, str, sizeof(s));
+ if (len >= sizeof(s)) {
+ return EINVAL;
+ }
+
+ p = strrchr(s, '/');
+ if (p == NULL) {
+ return EINVAL;
+ }
+
+ m = smb_strtoul(p+1, NULL, 10, &ret, SMB_STR_FULL_STR_CONV);
+ if (ret != 0) {
+ /* Empty string or trailing garbage */
+ return EINVAL;
+ }
+
+ *p = '\0';
+ ret = ip_from_string(s, addr);
+
+ if (ret == 0) {
+ *mask = m;
+ }
+
+ return ret;
+}
+
+unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr)
+{
+ switch (addr->sa.sa_family) {
+ case AF_INET:
+ return ntohs(addr->ip.sin_port);
+ break;
+ case AF_INET6:
+ return ntohs(addr->ip6.sin6_port);
+ break;
+ default:
+ return 0;
+ }
+}
+
+void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port)
+{
+ switch (addr->sa.sa_family) {
+ case AF_INET:
+ addr->ip.sin_port = htons(port);
+ break;
+ case AF_INET6:
+ addr->ip6.sin6_port = htons(port);
+ break;
+ default:
+ break;
+ }
+}
+
+static int ctdb_sock_addr_cmp_family(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2)
+{
+ /* This is somewhat arbitrary. However, when used for sorting
+ * it just needs to be consistent.
+ */
+ if (addr1->sa.sa_family < addr2->sa.sa_family) {
+ return -1;
+ }
+ if (addr1->sa.sa_family > addr2->sa.sa_family) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2)
+{
+ int ret;
+
+ ret = ctdb_sock_addr_cmp_family(addr1, addr2);
+ if (ret != 0) {
+ return ret;
+ }
+
+ switch (addr1->sa.sa_family) {
+ case AF_INET:
+ ret = memcmp(&addr1->ip.sin_addr.s_addr,
+ &addr2->ip.sin_addr.s_addr, 4);
+ break;
+
+ case AF_INET6:
+ ret = memcmp(addr1->ip6.sin6_addr.s6_addr,
+ addr2->ip6.sin6_addr.s6_addr, 16);
+ break;
+
+ default:
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int ctdb_sock_addr_cmp(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2)
+{
+ int ret = 0;
+
+ ret = ctdb_sock_addr_cmp_ip(addr1, addr2);
+ if (ret != 0) {
+ return ret;
+ }
+
+ switch (addr1->sa.sa_family) {
+ case AF_INET:
+ if (addr1->ip.sin_port < addr2->ip.sin_port) {
+ ret = -1;
+ } else if (addr1->ip.sin_port > addr2->ip.sin_port) {
+ ret = 1;
+ }
+ break;
+
+ case AF_INET6:
+ if (addr1->ip6.sin6_port < addr2->ip6.sin6_port) {
+ ret = -1;
+ } else if (addr1->ip6.sin6_port > addr2->ip6.sin6_port) {
+ ret = 1;
+ }
+ break;
+
+ default:
+ ret = -1;
+ }
+
+ return ret;
+}
+
+bool ctdb_sock_addr_same_ip(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2)
+{
+ return (ctdb_sock_addr_cmp_ip(addr1, addr2) == 0);
+}
+
+bool ctdb_sock_addr_same(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2)
+{
+ return (ctdb_sock_addr_cmp(addr1, addr2) == 0);
+}
+
+int ctdb_connection_to_buf(char *buf,
+ size_t buflen,
+ struct ctdb_connection *conn,
+ bool client_first,
+ const char *sep)
+{
+ char server[64], client[64];
+ int ret;
+
+ ret = ctdb_sock_addr_to_buf(server, sizeof(server),
+ &conn->server, true);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ret = ctdb_sock_addr_to_buf(client, sizeof(client),
+ &conn->client, true);
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (! client_first) {
+ ret = snprintf(buf, buflen, "%s%s%s", server, sep, client);
+ } else {
+ ret = snprintf(buf, buflen, "%s%s%s", client, sep, server);
+ }
+ if (ret < 0 || (size_t)ret >= buflen) {
+ return ENOSPC;
+ }
+
+ return 0;
+}
+
+char *ctdb_connection_to_string(TALLOC_CTX *mem_ctx,
+ struct ctdb_connection *conn,
+ bool client_first)
+{
+ const size_t len = 128;
+ char *out;
+ int ret;
+
+ out = talloc_size(mem_ctx, len);
+ if (out == NULL) {
+ return NULL;
+ }
+
+ ret = ctdb_connection_to_buf(out, len, conn, client_first, " ");
+ if (ret != 0) {
+ talloc_free(out);
+ return NULL;
+ }
+
+ return out;
+}
+
+int ctdb_connection_from_string(const char *str, bool client_first,
+ struct ctdb_connection *conn)
+{
+ char s[128];
+ char *t1 = NULL, *t2 = NULL;
+ size_t len;
+ ctdb_sock_addr *first = (client_first ? &conn->client : &conn->server);
+ ctdb_sock_addr *second = (client_first ? &conn->server : &conn->client);
+ int ret;
+
+ len = strlcpy(s, str, sizeof(s));
+ if (len >= sizeof(s)) {
+ return EINVAL;
+ }
+
+ t1 = strtok(s, " \t\n");
+ if (t1 == NULL) {
+ return EINVAL;
+ }
+
+ t2 = strtok(NULL, " \t\n\0");
+ if (t2 == NULL) {
+ return EINVAL;
+ }
+
+ ret = ctdb_sock_addr_from_string(t1, first, true);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ret = ctdb_sock_addr_from_string(t2, second, true);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ret = ctdb_sock_addr_cmp_family(first, second);
+ if (ret != 0) {
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+int ctdb_connection_list_add(struct ctdb_connection_list *conn_list,
+ struct ctdb_connection *conn)
+{
+ uint32_t len;
+
+ if (conn_list == NULL) {
+ return EINVAL;
+ }
+
+ /* Ensure array is big enough */
+ len = talloc_array_length(conn_list->conn);
+ if (conn_list->num == len) {
+ conn_list->conn = talloc_realloc(conn_list, conn_list->conn,
+ struct ctdb_connection,
+ len+128);
+ if (conn_list->conn == NULL) {
+ return ENOMEM;
+ }
+ }
+
+ conn_list->conn[conn_list->num] = *conn;
+ conn_list->num++;
+
+ return 0;
+}
+
+static int connection_cmp(const void *a, const void *b)
+{
+ const struct ctdb_connection *conn_a = a;
+ const struct ctdb_connection *conn_b = b;
+ int ret;
+
+ ret = ctdb_sock_addr_cmp(&conn_a->server, &conn_b->server);
+ if (ret == 0) {
+ ret = ctdb_sock_addr_cmp(&conn_a->client, &conn_b->client);
+ }
+
+ return ret;
+}
+
+int ctdb_connection_list_sort(struct ctdb_connection_list *conn_list)
+{
+ if (conn_list == NULL) {
+ return EINVAL;
+ }
+
+ if (conn_list->num > 0) {
+ qsort(conn_list->conn, conn_list->num,
+ sizeof(struct ctdb_connection), connection_cmp);
+ }
+
+ return 0;
+}
+
+char *ctdb_connection_list_to_string(
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list *conn_list, bool client_first)
+{
+ uint32_t i;
+ char *out;
+
+ out = talloc_strdup(mem_ctx, "");
+ if (out == NULL) {
+ return NULL;
+ }
+
+ if (conn_list == NULL || conn_list->num == 0) {
+ return out;
+ }
+
+ for (i = 0; i < conn_list->num; i++) {
+ char buf[128];
+ int ret;
+
+ ret = ctdb_connection_to_buf(buf,
+ sizeof(buf),
+ &conn_list->conn[i],
+ client_first,
+ " ");
+ if (ret != 0) {
+ talloc_free(out);
+ return NULL;
+ }
+
+ out = talloc_asprintf_append(out, "%s\n", buf);
+ if (out == NULL) {
+ return NULL;
+ }
+ }
+
+ return out;
+}
+
+struct ctdb_connection_list_read_state {
+ struct ctdb_connection_list *list;
+ bool client_first;
+};
+
+static int ctdb_connection_list_read_line(char *line, void *private_data)
+{
+ struct ctdb_connection_list_read_state *state =
+ (struct ctdb_connection_list_read_state *)private_data;
+ struct ctdb_connection conn;
+ int ret;
+
+ /* Skip empty lines */
+ if (line[0] == '\0') {
+ return 0;
+ }
+
+ /* Comment */
+ if (line[0] == '#') {
+ return 0;
+ }
+
+ ret = ctdb_connection_from_string(line, state->client_first, &conn);
+ if (ret != 0) {
+ return ret;
+ }
+
+ ret = ctdb_connection_list_add(state->list, &conn);
+ if (ret != 0) {
+ return ret;
+ }
+
+ return 0;
+}
+
+int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
+ int fd,
+ bool client_first,
+ struct ctdb_connection_list **conn_list)
+{
+ struct ctdb_connection_list_read_state state;
+ int ret;
+
+ if (conn_list == NULL) {
+ return EINVAL;
+ }
+
+ state.list = talloc_zero(mem_ctx, struct ctdb_connection_list);
+ if (state.list == NULL) {
+ return ENOMEM;
+ }
+
+ state.client_first = client_first;
+
+ ret = line_read(fd,
+ 128,
+ mem_ctx,
+ ctdb_connection_list_read_line,
+ &state,
+ NULL);
+
+ *conn_list = state.list;
+
+ return ret;
+}
diff --git a/ctdb/protocol/protocol_util.h b/ctdb/protocol/protocol_util.h
new file mode 100644
index 0000000..2bdbb0c
--- /dev/null
+++ b/ctdb/protocol/protocol_util.h
@@ -0,0 +1,80 @@
+/*
+ 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_UTIL_H__
+#define __CTDB_PROTOCOL_UTIL_H__
+
+#include <talloc.h>
+
+#include "protocol/protocol.h"
+
+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);
+
+/*
+ * buflen must be long enough to hold the longest possible "address:port".
+ * For example, 1122:3344:5566:7788:99aa:bbcc:ddee:ff00:12345.
+ * 64 is sane value for buflen.
+ */
+int ctdb_sock_addr_to_buf(char *buf, socklen_t buflen,
+ ctdb_sock_addr *addr, bool with_port);
+char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx,
+ ctdb_sock_addr *addr, bool with_port);
+int ctdb_sock_addr_from_string(const char *str,
+ ctdb_sock_addr *addr, bool with_port);
+int ctdb_sock_addr_mask_from_string(const char *str,
+ ctdb_sock_addr *addr,
+ unsigned int *mask);
+unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr);
+void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port);
+int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2);
+int ctdb_sock_addr_cmp(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2);
+bool ctdb_sock_addr_same_ip(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2);
+bool ctdb_sock_addr_same(const ctdb_sock_addr *addr1,
+ const ctdb_sock_addr *addr2);
+
+int ctdb_connection_to_buf(char *buf,
+ size_t buflen,
+ struct ctdb_connection * conn,
+ bool client_first,
+ const char *sep);
+char *ctdb_connection_to_string(TALLOC_CTX *mem_ctx,
+ struct ctdb_connection * conn,
+ bool client_first);
+int ctdb_connection_from_string(const char *str, bool client_first,
+ struct ctdb_connection *conn);
+
+int ctdb_connection_list_add(struct ctdb_connection_list *conn_list,
+ struct ctdb_connection *conn);
+int ctdb_connection_list_sort(struct ctdb_connection_list *conn_list);
+char *ctdb_connection_list_to_string(
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list *conn_list, bool client_first);
+int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
+ int fd,
+ bool client_first,
+ struct ctdb_connection_list **conn_list);
+
+#endif /* __CTDB_PROTOCOL_UTIL_H__ */