mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
ec5d2ddd8e
- added --self-connect option to ctdb_test, allowing testing when a node connects to itself. not as efficient as local bypass, but very useful for testing purposes (easier to work with 1 task in gdb than 2) - split the ctdb_call() into an async triple, in the style of Samba4 async functions. So we now have ctdb_call_send(), ctdb_call_recv() and ctdb_call(). - added the main ctdb_call protocol logic. No error checking yet, but seems to work for simple cases - ensure we initialise the length argument to getsockopt() (This used to be ctdb commit 95fad717ef5ab93be3603aa11d2878876fe868d3)
144 lines
3.8 KiB
C
144 lines
3.8 KiB
C
/*
|
|
ctdb database library
|
|
|
|
Copyright (C) Andrew Tridgell 2006
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library 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
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
|
|
/*
|
|
an installed ctdb remote call
|
|
*/
|
|
struct ctdb_registered_call {
|
|
struct ctdb_registered_call *next, *prev;
|
|
uint32_t id;
|
|
ctdb_fn_t fn;
|
|
};
|
|
|
|
/*
|
|
this address structure might need to be generalised later for some
|
|
transports
|
|
*/
|
|
struct ctdb_address {
|
|
const char *address;
|
|
int port;
|
|
};
|
|
|
|
/*
|
|
state associated with one node
|
|
*/
|
|
struct ctdb_node {
|
|
struct ctdb_context *ctdb;
|
|
struct ctdb_address address;
|
|
const char *name; /* for debug messages */
|
|
void *private; /* private to transport */
|
|
uint32_t vnn;
|
|
};
|
|
|
|
/*
|
|
transport specific methods
|
|
*/
|
|
struct ctdb_methods {
|
|
int (*start)(struct ctdb_context *); /* start protocol processing */
|
|
int (*add_node)(struct ctdb_node *); /* setup a new node */
|
|
int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
|
|
};
|
|
|
|
/*
|
|
transport calls up to the ctdb layer
|
|
*/
|
|
struct ctdb_upcalls {
|
|
/* recv_pkt is called when a packet comes in */
|
|
void (*recv_pkt)(struct ctdb_context *, uint8_t *data, uint32_t length);
|
|
|
|
/* node_dead is called when an attempt to send to a node fails */
|
|
void (*node_dead)(struct ctdb_node *);
|
|
|
|
/* node_connected is called when a connection to a node is established */
|
|
void (*node_connected)(struct ctdb_node *);
|
|
};
|
|
|
|
/* main state of the ctdb daemon */
|
|
struct ctdb_context {
|
|
struct event_context *ev;
|
|
struct ctdb_address address;
|
|
const char *name;
|
|
uint32_t vnn; /* our own vnn */
|
|
uint32_t num_nodes;
|
|
uint32_t num_connected;
|
|
unsigned flags;
|
|
struct idr_context *idr;
|
|
struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
|
|
struct ctdb_registered_call *calls; /* list of registered calls */
|
|
char *err_msg;
|
|
struct tdb_context *ltdb;
|
|
const struct ctdb_methods *methods; /* transport methods */
|
|
const struct ctdb_upcalls *upcalls; /* transport upcalls */
|
|
void *private; /* private to transport */
|
|
};
|
|
|
|
#define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
|
|
ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
|
|
return -1; }} while (0)
|
|
|
|
/* arbitrary maximum timeout for ctdb operations */
|
|
#define CTDB_REQ_TIMEOUT 10
|
|
|
|
|
|
/*
|
|
operation IDs
|
|
*/
|
|
enum ctdb_operation {
|
|
CTDB_REQ_CALL = 0,
|
|
CTDB_REPLY_CALL = 1
|
|
};
|
|
|
|
/*
|
|
packet structures
|
|
*/
|
|
struct ctdb_req_header {
|
|
uint32_t length;
|
|
uint32_t operation;
|
|
uint32_t destnode;
|
|
uint32_t srcnode;
|
|
uint32_t reqid;
|
|
};
|
|
|
|
struct ctdb_req_call {
|
|
struct ctdb_req_header hdr;
|
|
uint32_t callid;
|
|
uint32_t keylen;
|
|
uint32_t calldatalen;
|
|
uint8_t data[0]; /* key[] followed by calldata[] */
|
|
};
|
|
|
|
struct ctdb_reply_call {
|
|
struct ctdb_req_header hdr;
|
|
uint32_t datalen;
|
|
uint8_t data[0];
|
|
};
|
|
|
|
/* internal prototypes */
|
|
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
|
|
bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
|
|
int ctdb_parse_address(struct ctdb_context *ctdb,
|
|
TALLOC_CTX *mem_ctx, const char *str,
|
|
struct ctdb_address *address);
|
|
uint32_t ctdb_hash(TDB_DATA *key);
|
|
void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
|
|
void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
|
|
|