ebf119eda022d10c4bd8bea60e8af4e153cae4d0
[obnox/samba/samba-obnox.git] / ctdb / common / common.h
1 /*
2    ctdb database library
3
4    Copyright (C) Amitay Isaacs  2015
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __CTDB_COMMON_H__
21 #define __CTDB_COMMON_H__
22
23 /* From common/ctdb_fork.c */
24
25 void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...);
26
27 void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid);
28
29 pid_t ctdb_fork(struct ctdb_context *ctdb);
30
31 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
32
33 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
34
35 /* From common/ctdb_io.c */
36
37 int ctdb_queue_length(struct ctdb_queue *queue);
38
39 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
40
41 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
42
43 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
44                                     TALLOC_CTX *mem_ctx, int fd, int alignment,
45                                     ctdb_queue_cb_fn_t callback,
46                                     void *private_data, const char *fmt, ...)
47                                     PRINTF_ATTRIBUTE(7,8);
48
49 /* From common/ctdb_ltdb.c */
50
51 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb,
52                                        const char *name);
53
54 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
55
56 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
57                     TDB_DATA key, struct ctdb_ltdb_header *header,
58                     TALLOC_CTX *mem_ctx, TDB_DATA *data);
59
60 int ctdb_ltdb_fetch_with_header(struct ctdb_db_context *ctdb_db,
61                                 TDB_DATA key, struct ctdb_ltdb_header *header,
62                                 TALLOC_CTX *mem_ctx, TDB_DATA *data);
63
64 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
65                     struct ctdb_ltdb_header *header, TDB_DATA data);
66
67 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
68
69 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
70
71 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key);
72
73 int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn);
74
75 typedef void (*ctdb_trackingdb_cb)(struct ctdb_context *ctdb, uint32_t pnn,
76                                    void *private_data);
77
78 void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data,
79                               ctdb_trackingdb_cb cb, void *private_data);
80
81 int ctdb_null_func(struct ctdb_call_info *call);
82
83 int ctdb_fetch_func(struct ctdb_call_info *call);
84
85 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
86
87 /* from common/ctdb_util.c */
88
89 const char *ctdb_errstr(struct ctdb_context *ctdb);
90
91 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
92
93 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
94
95 void ctdb_die(struct ctdb_context *ctdb, const char *msg);
96
97 bool ctdb_set_helper(const char *type, char *helper, size_t size,
98                      const char *envvar,
99                      const char *dir, const char *file);
100
101 void ctdb_external_trace(void);
102
103 int ctdb_parse_address(TALLOC_CTX *mem_ctx, const char *str,
104                        ctdb_sock_addr *address);
105
106 bool ctdb_same_address(ctdb_sock_addr *a1, ctdb_sock_addr *a2);
107
108 uint32_t ctdb_hash(const TDB_DATA *key);
109
110 struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
111                                            TDB_DATA key,
112                                            struct ctdb_ltdb_header *header,
113                                            TDB_DATA data);
114
115 struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx,
116                                                struct ctdb_marshall_buffer *m,
117                                                uint64_t db_id,
118                                                uint32_t reqid,
119                                                TDB_DATA key,
120                                                struct ctdb_ltdb_header *header,
121                                                TDB_DATA data);
122
123 TDB_DATA ctdb_marshall_finish(struct ctdb_marshall_buffer *m);
124
125 struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m,
126                                               struct ctdb_rec_data *r,
127                                               uint32_t *reqid,
128                                               struct ctdb_ltdb_header *header,
129                                               TDB_DATA *key, TDB_DATA *data);
130
131 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
132
133 bool ctdb_same_ip(const ctdb_sock_addr *tip1, const ctdb_sock_addr *tip2);
134
135 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
136
137 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
138
139 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
140
141 struct ctdb_node_map_old *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
142                                                const char *nlist);
143
144 struct ctdb_node_map_old *ctdb_node_list_to_map(struct ctdb_node **nodes,
145                                                 uint32_t num_nodes,
146                                                 TALLOC_CTX *mem_ctx);
147
148 const char *runstate_to_string(enum ctdb_runstate runstate);
149
150 enum ctdb_runstate runstate_from_string(const char *label);
151
152 void ctdb_set_runstate(struct ctdb_context *ctdb, enum ctdb_runstate runstate);
153
154 uint32_t *ctdb_key_to_idkey(TALLOC_CTX *mem_ctx, TDB_DATA key);
155
156 #endif /* __CTDB_COMMON_H__ */