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