4 Copyright (C) Andrew Tridgell 2006
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 an installed ctdb remote call
25 struct ctdb_registered_call {
26 struct ctdb_registered_call *next, *prev;
32 this address structure might need to be generalised later for some
41 state associated with one node
44 struct ctdb_context *ctdb;
45 struct ctdb_address address;
46 const char *name; /* for debug messages */
47 void *private; /* private to transport */
52 transport specific methods
55 int (*start)(struct ctdb_context *); /* start protocol processing */
56 int (*add_node)(struct ctdb_node *); /* setup a new node */
57 int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
61 transport calls up to the ctdb layer
64 /* recv_pkt is called when a packet comes in */
65 void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
67 /* node_dead is called when an attempt to send to a node fails */
68 void (*node_dead)(struct ctdb_node *);
70 /* node_connected is called when a connection to a node is established */
71 void (*node_connected)(struct ctdb_node *);
74 /* main state of the ctdb daemon */
76 struct event_context *ev;
77 struct ctdb_address address;
79 uint32_t vnn; /* our own vnn */
81 uint32_t num_connected;
83 struct idr_context *idr;
84 struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
85 struct ctdb_registered_call *calls; /* list of registered calls */
87 struct tdb_context *ltdb;
88 const struct ctdb_methods *methods; /* transport methods */
89 const struct ctdb_upcalls *upcalls; /* transport upcalls */
90 void *private; /* private to transport */
93 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
94 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
95 return -1; }} while (0)
97 #define CTDB_NO_MEMORY_NULL(ctdb, p) do { if (!(p)) { \
98 ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
99 return NULL; }} while (0)
101 #define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
102 ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
105 /* arbitrary maximum timeout for ctdb operations */
106 #define CTDB_REQ_TIMEOUT 10
108 /* max number of redirects before we ask the lmaster */
109 #define CTDB_MAX_REDIRECT 2
111 /* number of consecutive calls from the same node before we give them
113 #define CTDB_MAX_LACOUNT 7
116 the extended header for records in the ltdb
118 struct ctdb_ltdb_header {
129 enum ctdb_operation {
132 CTDB_REPLY_REDIRECT = 2,
133 CTDB_REQ_DMASTER = 3,
134 CTDB_REPLY_DMASTER = 4,
141 struct ctdb_req_header {
149 struct ctdb_req_call {
150 struct ctdb_req_header hdr;
153 uint32_t calldatalen;
154 uint8_t data[0]; /* key[] followed by calldata[] */
157 struct ctdb_reply_call {
158 struct ctdb_req_header hdr;
163 struct ctdb_reply_error {
164 struct ctdb_req_header hdr;
170 struct ctdb_reply_redirect {
171 struct ctdb_req_header hdr;
175 struct ctdb_req_dmaster {
176 struct ctdb_req_header hdr;
183 struct ctdb_reply_dmaster {
184 struct ctdb_req_header hdr;
189 /* internal prototypes */
190 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
191 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
192 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
193 int ctdb_parse_address(struct ctdb_context *ctdb,
194 TALLOC_CTX *mem_ctx, const char *str,
195 struct ctdb_address *address);
196 uint32_t ctdb_hash(const TDB_DATA *key);
197 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
198 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
199 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
200 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
201 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
202 void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
204 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
205 int ctdb_ltdb_fetch(struct ctdb_context *ctdb,
206 TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data);
207 int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key,
208 struct ctdb_ltdb_header *header, TDB_DATA data);