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