TMP: add a ctdb snapshot of current ctdb master (git://git.samba.org/ctdb.git) to...
[obnox/samba/samba-obnox.git] / ctdb / 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 #include <syslog.h>
10 #include <tdb.h>
11 #include <stddef.h>
12
13 #ifndef offsetof
14 #define offsetof(t,f) ((unsigned int)&((t *)0)->f)
15 #endif
16
17 #ifndef COLD_ATTRIBUTE
18 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
19 #define COLD_ATTRIBUTE __attribute__((cold))
20 #else
21 #define COLD_ATTRIBUTE
22 #endif
23 #endif /* COLD_ATTRIBUTE */
24
25 #define DEBUG(ctdb, lvl, format, args...) do { if (lvl <= ctdb_log_level) { ctdb_do_debug(ctdb, lvl, format , ## args ); }} while(0)
26
27 struct message_handler_info;
28 struct ctdb_reply_call;
29
30 struct ctdb_request {
31         struct ctdb_connection *ctdb;
32         struct ctdb_request *next, *prev;
33         bool cancelled;
34
35         struct io_elem *io;
36         union {
37                 struct ctdb_req_header *hdr;
38                 struct ctdb_req_call *call;
39                 struct ctdb_req_control *control;
40                 struct ctdb_req_message *message;
41         } hdr;
42
43         struct io_elem *reply;
44
45         ctdb_callback_t callback;
46         void *priv_data;
47
48         /* Extra per-request info. */
49         void (*extra_destructor)(struct ctdb_connection *,
50                                  struct ctdb_request *);
51         void *extra;
52 };
53
54 struct ctdb_connection {
55         /* Socket to ctdbd. */
56         int fd;
57         /* Currently our failure mode is simple; return -1 from ctdb_service */
58         bool broken;
59         /* Linked list of pending outgoings. */
60         struct ctdb_request *outq;
61         /* Finished outgoings (awaiting response) */
62         struct ctdb_request *doneq;
63
64         /* Current incoming. */
65         struct io_elem *in;
66         /* Queue of received pdus */
67         struct io_elem *inqueue;
68
69         /* Guess at a good reqid to try next. */
70         uint32_t next_id;
71         /* List of messages */
72         struct message_handler_info *message_handlers;
73         /* PNN of this ctdb: valid by the time we do our first db connection. */
74         uint32_t pnn;
75         /* Chain of locks we hold. */
76         struct ctdb_lock *locks;
77         /* Extra logging. */
78         ctdb_log_fn_t log;
79         void *log_priv;
80 };
81
82 /* ctdb.c */
83 struct ctdb_request *new_ctdb_request(struct ctdb_connection *ctdb, size_t len,
84                                       ctdb_callback_t cb, void *cbdata);
85 struct ctdb_request *new_ctdb_control_request(struct ctdb_connection *ctdb,
86                                               uint32_t opcode,
87                                               uint32_t destnode,
88                                               const void *extra_data,
89                                               size_t extra,
90                                               ctdb_callback_t, void *);
91 uint32_t new_reqid(struct ctdb_connection *ctdb);
92
93 struct ctdb_reply_control *unpack_reply_control(struct ctdb_request *req,
94                                                 enum ctdb_controls control);
95 void ctdb_cancel_callback(struct ctdb_connection *ctdb,
96                           struct ctdb_request *req,
97                           void *unused);
98
99 /* logging.c */
100 void ctdb_tdb_log_bridge(struct tdb_context *tdb,
101                          enum tdb_debug_level level,
102                          const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
103
104 void ctdb_do_debug(struct ctdb_connection *, int, const char *format, ...)
105         PRINTF_ATTRIBUTE(3, 4) COLD_ATTRIBUTE;
106
107 #endif /* _LIBCTDB_PRIVATE_H */