summaryrefslogtreecommitdiff
path: root/source4/cluster/ctdb/include
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-04-16 00:18:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:50:40 -0500
commitc9f04d8648cfdd573d45d47467bc964ef01f754d (patch)
tree115acf98b7b136f07dd8b16bbd50c9f7cbcdd3bb /source4/cluster/ctdb/include
parentbb36705c8d360a2ba865a3d8118c52afa1e46f4e (diff)
downloadsamba-c9f04d8648cfdd573d45d47467bc964ef01f754d.tar.gz
samba-c9f04d8648cfdd573d45d47467bc964ef01f754d.tar.bz2
samba-c9f04d8648cfdd573d45d47467bc964ef01f754d.zip
r22231: merge from bzr ctdb tree
(This used to be commit 807b959082d3b9a929c9f6597714e636638a940e)
Diffstat (limited to 'source4/cluster/ctdb/include')
-rw-r--r--source4/cluster/ctdb/include/ctdb.h28
-rw-r--r--source4/cluster/ctdb/include/ctdb_private.h224
-rw-r--r--source4/cluster/ctdb/include/idtree.h7
-rw-r--r--source4/cluster/ctdb/include/includes.h36
4 files changed, 281 insertions, 14 deletions
diff --git a/source4/cluster/ctdb/include/ctdb.h b/source4/cluster/ctdb/include/ctdb.h
index 9049314401..d5a1b581e5 100644
--- a/source4/cluster/ctdb/include/ctdb.h
+++ b/source4/cluster/ctdb/include/ctdb.h
@@ -50,6 +50,10 @@ struct ctdb_call_info {
ctdb flags
*/
#define CTDB_FLAG_SELF_CONNECT (1<<0)
+/* fork off a separate ctdb daemon */
+#define CTDB_FLAG_DAEMON_MODE (1<<1)
+/* for test code only: make ctdb_start() block until all nodes are connected */
+#define CTDB_FLAG_CONNECT_WAIT (1<<2)
struct event_context;
@@ -70,6 +74,11 @@ int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
/*
+ clear some flags
+*/
+void ctdb_clear_flags(struct ctdb_context *ctdb, unsigned flags);
+
+/*
set max acess count before a dmaster migration
*/
void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
@@ -143,8 +152,14 @@ uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
/* setup a handler for ctdb messages */
typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid,
TDB_DATA data, void *);
-int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
- void *private);
+int ctdb_set_message_handler(struct ctdb_context *ctdb, uint32_t srvid,
+ ctdb_message_fn_t handler,
+ void *private_data);
+
+
+int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+int ctdb_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
/* send a ctdb message */
int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
@@ -164,7 +179,14 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
change the data in a record held with a ctdb_record_handle
if the new data is zero length, this implies a delete of the record
*/
-int ctdb_record_store(struct ctdb_record_handle *rec, TDB_DATA data);
+int ctdb_store_unlock(struct ctdb_record_handle *rec, TDB_DATA data);
+
+int ctdb_register_message_handler(struct ctdb_context *ctdb,
+ TALLOC_CTX *mem_ctx,
+ uint32_t srvid,
+ ctdb_message_fn_t handler,
+ void *private_data);
+struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
#endif
diff --git a/source4/cluster/ctdb/include/ctdb_private.h b/source4/cluster/ctdb/include/ctdb_private.h
index 00b74b2177..c50b481cf3 100644
--- a/source4/cluster/ctdb/include/ctdb_private.h
+++ b/source4/cluster/ctdb/include/ctdb_private.h
@@ -23,6 +23,13 @@
#include "ctdb.h"
+/* location of daemon socket */
+#define CTDB_PATH "/tmp/ctdb.socket"
+
+/* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
+#define CTDB_DS_ALIGNMENT 8
+
+
#define CTDB_FETCH_FUNC 0xf0000001
/*
@@ -43,6 +50,13 @@ struct ctdb_address {
int port;
};
+
+/* called from the queue code when a packet comes in. Called with data==NULL
+ on error */
+typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
+ void *private_data);
+
+
/*
state associated with one node
*/
@@ -50,10 +64,16 @@ struct ctdb_node {
struct ctdb_context *ctdb;
struct ctdb_address address;
const char *name; /* for debug messages */
- void *private; /* private to transport */
+ void *private_data; /* private to transport */
uint32_t vnn;
};
+struct ctdb_record_handle {
+ struct ctdb_db_context *ctdb_db;
+ TDB_DATA key;
+ TDB_DATA *data;
+};
+
/*
transport specific methods
*/
@@ -78,6 +98,22 @@ struct ctdb_upcalls {
void (*node_connected)(struct ctdb_node *);
};
+/* list of message handlers - needs to be changed to a more efficient data
+ structure so we can find a message handler given a srvid quickly */
+struct ctdb_message_list {
+ struct ctdb_context *ctdb;
+ struct ctdb_message_list *next, *prev;
+ uint32_t srvid;
+ ctdb_message_fn_t message_handler;
+ void *message_private;
+};
+
+/* additional data required for the daemon mode */
+struct ctdb_daemon_data {
+ int sd;
+ char *name;
+ struct ctdb_queue *queue;
+};
/* main state of the ctdb daemon */
struct ctdb_context {
@@ -93,11 +129,11 @@ struct ctdb_context {
char *err_msg;
const struct ctdb_methods *methods; /* transport methods */
const struct ctdb_upcalls *upcalls; /* transport upcalls */
- void *private; /* private to transport */
+ void *private_data; /* private to transport */
unsigned max_lacount;
- ctdb_message_fn_t message_handler;
- void *message_private;
struct ctdb_db_context *db_list;
+ struct ctdb_message_list *message_list;
+ struct ctdb_daemon_data daemon;
};
struct ctdb_db_context {
@@ -109,6 +145,7 @@ struct ctdb_db_context {
struct ctdb_registered_call *calls; /* list of registered calls */
};
+
#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)
@@ -141,18 +178,48 @@ struct ctdb_ltdb_header {
uint32_t lacount;
};
+enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
+
+/*
+ state of a in-progress ctdb call
+*/
+struct ctdb_call_state {
+ enum call_state state;
+ struct ctdb_req_call *c;
+ struct ctdb_db_context *ctdb_db;
+ struct ctdb_node *node;
+ const char *errmsg;
+ struct ctdb_call call;
+ int redirect_count;
+ struct ctdb_ltdb_header header;
+ void *fetch_private;
+ struct {
+ void (*fn)(struct ctdb_call_state *);
+ void *private_data;
+ } async;
+};
+
/*
operation IDs
*/
enum ctdb_operation {
- CTDB_REQ_CALL = 0,
- CTDB_REPLY_CALL = 1,
- CTDB_REPLY_REDIRECT = 2,
- CTDB_REQ_DMASTER = 3,
- CTDB_REPLY_DMASTER = 4,
- CTDB_REPLY_ERROR = 5,
- CTDB_REQ_MESSAGE = 6
+ CTDB_REQ_CALL = 0,
+ CTDB_REPLY_CALL = 1,
+ CTDB_REPLY_REDIRECT = 2,
+ CTDB_REQ_DMASTER = 3,
+ CTDB_REPLY_DMASTER = 4,
+ CTDB_REPLY_ERROR = 5,
+ CTDB_REQ_MESSAGE = 6,
+
+ /* only used on the domain socket */
+ CTDB_REQ_REGISTER = 1000,
+ CTDB_REQ_CONNECT_WAIT = 1001,
+ CTDB_REPLY_CONNECT_WAIT = 1002,
+ CTDB_REQ_FETCH_LOCK = 1003,
+ CTDB_REPLY_FETCH_LOCK = 1004,
+ CTDB_REQ_STORE_UNLOCK = 1005,
+ CTDB_REPLY_STORE_UNLOCK = 1006
};
#define CTDB_MAGIC 0x43544442 /* CTDB */
@@ -215,6 +282,11 @@ struct ctdb_reply_dmaster {
uint8_t data[1];
};
+struct ctdb_req_register {
+ struct ctdb_req_header hdr;
+ uint32_t srvid;
+};
+
struct ctdb_req_message {
struct ctdb_req_header hdr;
uint32_t srvid;
@@ -222,6 +294,42 @@ struct ctdb_req_message {
uint8_t data[1];
};
+struct ctdb_req_connect_wait {
+ struct ctdb_req_header hdr;
+};
+
+struct ctdb_reply_connect_wait {
+ struct ctdb_req_header hdr;
+ uint32_t vnn;
+ uint32_t num_connected;
+};
+
+struct ctdb_req_fetch_lock {
+ struct ctdb_req_header hdr;
+ uint32_t db_id;
+ uint32_t keylen;
+ uint8_t key[1]; /* key[] */
+};
+
+struct ctdb_reply_fetch_lock {
+ struct ctdb_req_header hdr;
+ uint32_t state;
+ uint32_t datalen;
+ uint8_t data[1]; /* data[] */
+};
+struct ctdb_req_store_unlock {
+ struct ctdb_req_header hdr;
+ uint32_t db_id;
+ uint32_t keylen;
+ uint32_t datalen;
+ uint8_t data[1]; /* key[] and data[] */
+};
+
+struct ctdb_reply_store_unlock {
+ struct ctdb_req_header hdr;
+ uint32_t state;
+};
+
/* internal prototypes */
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
@@ -246,5 +354,99 @@ int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
struct ctdb_ltdb_header *header, TDB_DATA data);
void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
+ struct ctdb_call *call,
+ struct ctdb_ltdb_header *header,
+ TDB_DATA *data);
+
+
+int ctdbd_start(struct ctdb_context *ctdb);
+struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
+
+/*
+ queue a packet for sending
+*/
+int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
+
+/*
+ setup the fd used by the queue
+ */
+int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
+
+/*
+ setup a packet queue on a socket
+ */
+struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
+ TALLOC_CTX *mem_ctx, int fd, int alignment,
+
+ ctdb_queue_cb_fn_t callback,
+ void *private_data);
+
+/*
+ allocate a packet for use in client<->daemon communication
+ */
+void *ctdbd_allocate_pkt(struct ctdb_context *ctdb, size_t len);
+
+
+/*
+ lock a record in the ltdb, given a key
+ */
+int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
+
+/*
+ unlock a record in the ltdb, given a key
+ */
+int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
+
+
+/*
+ make a ctdb call to the local daemon - async send. Called from client context.
+
+ This constructs a ctdb_call request and queues it for processing.
+ This call never blocks.
+*/
+struct ctdb_call_state *ctdb_client_call_send(struct ctdb_db_context *ctdb_db,
+ struct ctdb_call *call);
+
+/*
+ make a recv call to the local ctdb daemon - called from client context
+
+ This is called when the program wants to wait for a ctdb_call to complete and get the
+ results. This call will block unless the call has already completed.
+*/
+int ctdb_client_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
+
+int ctdb_daemon_set_message_handler(struct ctdb_context *ctdb, uint32_t srvid,
+ ctdb_message_fn_t handler,
+ void *private_data);
+
+int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t vnn,
+ uint32_t srvid, TDB_DATA data);
+
+/*
+ send a ctdb message
+*/
+int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t vnn,
+ uint32_t srvid, TDB_DATA data);
+
+
+/*
+ wait for all nodes to be connected
+*/
+void ctdb_daemon_connect_wait(struct ctdb_context *ctdb);
+
+
+/*
+ do a fetch lock from a client to the local daemon
+*/
+struct ctdb_record_handle *ctdb_client_fetch_lock(struct ctdb_db_context *ctdb_db,
+ TALLOC_CTX *mem_ctx,
+ TDB_DATA key, TDB_DATA *data);
+
+/*
+ do a store unlock from a client to the local daemon
+*/
+int ctdb_client_store_unlock(struct ctdb_record_handle *rec, TDB_DATA data);
#endif
diff --git a/source4/cluster/ctdb/include/idtree.h b/source4/cluster/ctdb/include/idtree.h
new file mode 100644
index 0000000000..259af91005
--- /dev/null
+++ b/source4/cluster/ctdb/include/idtree.h
@@ -0,0 +1,7 @@
+struct idr_context *idr_init(TALLOC_CTX *mem_ctx);
+int idr_get_new(struct idr_context *idp, void *ptr, int limit);
+int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit);
+int idr_get_new_random(struct idr_context *idp, void *ptr, int limit);
+void *idr_find(struct idr_context *idp, int id);
+int idr_remove(struct idr_context *idp, int id);
+
diff --git a/source4/cluster/ctdb/include/includes.h b/source4/cluster/ctdb/include/includes.h
new file mode 100644
index 0000000000..994c25452c
--- /dev/null
+++ b/source4/cluster/ctdb/include/includes.h
@@ -0,0 +1,36 @@
+#define HAVE_UNIXSOCKET 1
+
+#include "replace.h"
+#include "talloc.h"
+#include "tdb.h"
+#include "idtree.h"
+#include "ctdb.h"
+#include "lib/util/dlinklist.h"
+
+typedef bool BOOL;
+
+#define True 1
+#define False 0
+
+#define LogLevel 0
+
+#define DEBUG(lvl, x) if ((lvl) <= LogLevel) (printf x)
+
+#define _PUBLIC_
+
+#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+
+#ifndef discard_const
+#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
+#endif
+
+struct timeval timeval_zero(void);
+bool timeval_is_zero(const struct timeval *tv);
+struct timeval timeval_current(void);
+struct timeval timeval_set(uint32_t secs, uint32_t usecs);
+int timeval_compare(const struct timeval *tv1, const struct timeval *tv2);
+struct timeval timeval_until(const struct timeval *tv1,
+ const struct timeval *tv2);
+_PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs);
+char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx);
+