ctdb-common: Mark ctdb_fatal() and ctdb_die() as _NORETURN_
[samba.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 #include "lib/util/attr.h"
24
25 /* From common/ctdb_io.c */
26
27 typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
28                                    void *private_data);
29
30 int ctdb_queue_length(struct ctdb_queue *queue);
31
32 int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length);
33
34 int ctdb_queue_set_fd(struct ctdb_queue *queue, int fd);
35
36 struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
37                                     TALLOC_CTX *mem_ctx, int fd, int alignment,
38                                     ctdb_queue_cb_fn_t callback,
39                                     void *private_data, const char *fmt, ...)
40                                     PRINTF_ATTRIBUTE(7,8);
41
42 /* From common/ctdb_ltdb.c */
43
44 int ctdb_db_tdb_flags(uint8_t db_flags, bool with_valgrind, bool with_mutex);
45
46 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb,
47                                        const char *name);
48
49 bool ctdb_db_persistent(struct ctdb_db_context *ctdb_db);
50 bool ctdb_db_replicated(struct ctdb_db_context *ctdb_db);
51 bool ctdb_db_volatile(struct ctdb_db_context *ctdb_db);
52
53 bool ctdb_db_readonly(struct ctdb_db_context *ctdb_db);
54 void ctdb_db_set_readonly(struct ctdb_db_context *ctdb_db);
55 void ctdb_db_reset_readonly(struct ctdb_db_context *ctdb_db);
56
57 bool ctdb_db_sticky(struct ctdb_db_context *ctdb_db);
58 void ctdb_db_set_sticky(struct ctdb_db_context *ctdb_db);
59
60 uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
61
62 int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
63                     TDB_DATA key, struct ctdb_ltdb_header *header,
64                     TALLOC_CTX *mem_ctx, TDB_DATA *data);
65
66 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
67                     struct ctdb_ltdb_header *header, TDB_DATA data);
68
69 int ctdb_ltdb_lock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
70
71 int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key);
72
73 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key);
74
75 int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn);
76
77 typedef void (*ctdb_trackingdb_cb)(struct ctdb_context *ctdb, uint32_t pnn,
78                                    void *private_data);
79
80 void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data,
81                               ctdb_trackingdb_cb cb, void *private_data);
82
83 int ctdb_null_func(struct ctdb_call_info *call);
84
85 int ctdb_fetch_func(struct ctdb_call_info *call);
86
87 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
88
89 /* from common/ctdb_util.c */
90
91 const char *ctdb_errstr(struct ctdb_context *ctdb);
92
93 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...)
94                     PRINTF_ATTRIBUTE(2,3);
95
96 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg) _NORETURN_;
97
98 void ctdb_die(struct ctdb_context *ctdb, const char *msg) _NORETURN_;
99
100 bool ctdb_set_helper(const char *type, char *helper, size_t size,
101                      const char *envvar,
102                      const char *dir, const char *file);
103
104 int ctdb_parse_address(TALLOC_CTX *mem_ctx, const char *str,
105                        ctdb_sock_addr *address);
106
107 bool ctdb_same_address(ctdb_sock_addr *a1, ctdb_sock_addr *a2);
108
109 uint32_t ctdb_hash(const TDB_DATA *key);
110
111 struct ctdb_rec_data_old *ctdb_marshall_record(TALLOC_CTX *mem_ctx,
112                                                uint32_t reqid,
113                                                TDB_DATA key,
114                                                struct ctdb_ltdb_header *header,
115                                                TDB_DATA data);
116
117 struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx,
118                                                struct ctdb_marshall_buffer *m,
119                                                uint32_t db_id,
120                                                uint32_t reqid,
121                                                TDB_DATA key,
122                                                struct ctdb_ltdb_header *header,
123                                                TDB_DATA data);
124
125 TDB_DATA ctdb_marshall_finish(struct ctdb_marshall_buffer *m);
126
127 struct ctdb_rec_data_old *ctdb_marshall_loop_next(
128                                         struct ctdb_marshall_buffer *m,
129                                         struct ctdb_rec_data_old *r,
130                                         uint32_t *reqid,
131                                         struct ctdb_ltdb_header *header,
132                                         TDB_DATA *key, TDB_DATA *data);
133
134 void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip);
135
136 bool ctdb_same_ip(const ctdb_sock_addr *tip1, const ctdb_sock_addr *tip2);
137
138 bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
139
140 char *ctdb_addr_to_str(ctdb_sock_addr *addr);
141
142 unsigned ctdb_addr_to_port(ctdb_sock_addr *addr);
143
144 struct ctdb_node_map_old *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
145                                                const char *nlist);
146
147 struct ctdb_node_map_old *ctdb_node_list_to_map(struct ctdb_node **nodes,
148                                                 uint32_t num_nodes,
149                                                 TALLOC_CTX *mem_ctx);
150
151 const char *runstate_to_string(enum ctdb_runstate runstate);
152
153 enum ctdb_runstate runstate_from_string(const char *label);
154
155 void ctdb_set_runstate(struct ctdb_context *ctdb, enum ctdb_runstate runstate);
156
157 uint32_t *ctdb_key_to_idkey(TALLOC_CTX *mem_ctx, TDB_DATA key);
158
159 #endif /* __CTDB_COMMON_H__ */