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