diff options
author | Andrew Tridgell <tridge@samba.org> | 2007-04-16 00:18:54 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:50:40 -0500 |
commit | c9f04d8648cfdd573d45d47467bc964ef01f754d (patch) | |
tree | 115acf98b7b136f07dd8b16bbd50c9f7cbcdd3bb /source4/cluster/ctdb/include/ctdb_private.h | |
parent | bb36705c8d360a2ba865a3d8118c52afa1e46f4e (diff) | |
download | samba-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/ctdb_private.h')
-rw-r--r-- | source4/cluster/ctdb/include/ctdb_private.h | 224 |
1 files changed, 213 insertions, 11 deletions
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 |