libctdb: add ctdb arg to more functions.
[metze/ctdb/wip.git] / libctdb / libctdb_private.h
1 #ifndef _LIBCTDB_PRIVATE_H
2 #define _LIBCTDB_PRIVATE_H
3 #include <dlinklist.h>
4 #include <stdbool.h>
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <ctdb.h>
8 #include <ctdb_protocol.h>
9
10 #ifndef offsetof
11 #define offsetof(t,f) ((unsigned int)&((t *)0)->f)
12 #endif
13
14 struct message_handler_info;
15 struct ctdb_reply_call;
16
17 struct ctdb_request {
18         struct ctdb_connection *ctdb;
19         struct ctdb_request *next, *prev;
20         bool cancelled;
21
22         struct io_elem *io;
23         union {
24                 struct ctdb_req_header *hdr;
25                 struct ctdb_req_call *call;
26                 struct ctdb_req_control *control;
27                 struct ctdb_req_message *message;
28         } hdr;
29
30         struct io_elem *reply;
31
32         ctdb_callback_t callback;
33         void *priv_data;
34
35         /* Extra per-request info. */
36         void (*extra_destructor)(struct ctdb_connection *,
37                                  struct ctdb_request *);
38         void *extra;
39 };
40
41 struct ctdb_connection {
42         /* Socket to ctdbd. */
43         int fd;
44         /* Currently our failure mode is simple; return -1 from ctdb_service */
45         bool broken;
46         /* Linked list of pending outgoings. */
47         struct ctdb_request *outq;
48         /* Finished outgoings (awaiting response) */
49         struct ctdb_request *doneq;
50         /* Current incoming. */
51         struct io_elem *in;
52         /* Guess at a good reqid to try next. */
53         uint32_t next_id;
54         /* List of messages */
55         struct message_handler_info *message_handlers;
56         /* PNN of this ctdb: valid by the time we do our first db connection. */
57         uint32_t pnn;
58 };
59
60 /* ctdb.c */
61 struct ctdb_request *new_ctdb_request(size_t len, ctdb_callback_t, void *);
62 struct ctdb_request *new_ctdb_control_request(struct ctdb_connection *ctdb,
63                                               uint32_t opcode,
64                                               uint32_t destnode,
65                                               const void *extra_data,
66                                               size_t extra,
67                                               ctdb_callback_t, void *);
68 uint32_t new_reqid(struct ctdb_connection *ctdb);
69
70 struct ctdb_reply_control *unpack_reply_control(struct ctdb_connection *ctdb,
71                                                 struct ctdb_request *req,
72                                                 enum ctdb_controls control);
73 void ctdb_cancel_callback(struct ctdb_connection *ctdb,
74                           struct ctdb_request *req,
75                           void *unused);
76 #endif /* _LIBCTDB_PRIVATE_H */