s3:ctdbd_conn: add ctdbd_all_ip_foreach() helper
[metze/samba/wip.git] / source3 / include / ctdbd_conn.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba3 ctdb connection handling
4    Copyright (C) Volker Lendecke 2007
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 _CTDBD_CONN_H
21 #define _CTDBD_CONN_H
22
23 #include "replace.h"
24 #include "system/filesys.h"
25 #include "system/network.h"
26 #include "lib/dbwrap/dbwrap.h"
27 #include <tdb.h>
28 #include <tevent.h>
29
30 struct ctdbd_connection;
31 struct messaging_context;
32 struct messaging_rec;
33
34 int ctdbd_init_connection(TALLOC_CTX *mem_ctx,
35                           const char *sockname, int timeout,
36                           struct ctdbd_connection **pconn);
37 int ctdbd_init_async_connection(
38         TALLOC_CTX *mem_ctx,
39         const char *sockname,
40         int timeout,
41         struct ctdbd_connection **pconn);
42 int ctdbd_reinit_connection(TALLOC_CTX *mem_ctx,
43                             const char *sockname, int timeout,
44                             struct ctdbd_connection *conn);
45
46 uint32_t ctdbd_vnn(const struct ctdbd_connection *conn);
47
48 int ctdbd_conn_get_fd(struct ctdbd_connection *conn);
49 void ctdbd_socket_readable(struct tevent_context *ev,
50                            struct ctdbd_connection *conn);
51
52 int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
53                              uint32_t dst_vnn, uint64_t dst_srvid,
54                              const struct iovec *iov, int iovlen);
55
56 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
57                           pid_t pid, uint64_t unique_id);
58
59 char *ctdbd_dbpath(struct ctdbd_connection *conn,
60                    TALLOC_CTX *mem_ctx, uint32_t db_id);
61
62 int ctdbd_db_attach(struct ctdbd_connection *conn, const char *name,
63                     uint32_t *db_id, bool persistent);
64
65 int ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key);
66
67 int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
68                 TDB_DATA key, bool local_copy,
69                 void (*parser)(TDB_DATA key, TDB_DATA data,
70                                void *private_data),
71                 void *private_data);
72
73 int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
74                    void (*fn)(TDB_DATA key, TDB_DATA data,
75                               void *private_data),
76                    void *private_data);
77
78 int ctdbd_register_ips(struct ctdbd_connection *conn,
79                        const struct sockaddr_storage *server,
80                        const struct sockaddr_storage *client,
81                        int (*cb)(struct tevent_context *ev,
82                                  uint32_t src_vnn, uint32_t dst_vnn,
83                                  uint64_t dst_srvid,
84                                  const uint8_t *msg, size_t msglen,
85                                  void *private_data),
86                        void *private_data);
87 void ctdbd_unregister_ips(struct ctdbd_connection *conn,
88                           const struct sockaddr_storage *_server,
89                           const struct sockaddr_storage *_client,
90                           int (*cb)(struct tevent_context *ev,
91                                     uint32_t src_vnn,
92                                     uint32_t dst_vnn,
93                                     uint64_t dst_srvid,
94                                     const uint8_t *msg,
95                                     size_t msglen,
96                                     void *private_data),
97                           void *private_data);
98 void ctdbd_passed_ips(struct ctdbd_connection *conn,
99                       const struct sockaddr_storage *_server,
100                       const struct sockaddr_storage *_client,
101                       int (*cb)(struct tevent_context *ev,
102                                 uint32_t src_vnn,
103                                 uint32_t dst_vnn,
104                                 uint64_t dst_srvid,
105                                 const uint8_t *msg,
106                                 size_t msglen,
107                                 void *private_data),
108                       void *private_data);
109
110 /*
111  * call @cb for each public IP. If @cb returns non-zero, then break the loop
112  * and propagate the return value upwards.
113  * @returns: 0 on success, where all @cb invocations also returned zero
114  *           ENOMEM on memory allocation failure
115  *           EIO on ctdbd connection failure
116  *           @cb() return value if non-zero
117  */
118 int ctdbd_public_ip_foreach(struct ctdbd_connection *conn,
119                             int (*cb)(uint32_t total_ip_count,
120                                       const struct sockaddr_storage *ip,
121                                       bool is_movable_ip,
122                                       void *private_data),
123                             void *private_data);
124 int ctdbd_all_ip_foreach(struct ctdbd_connection *conn,
125                          bool include_node_ips,
126                          bool include_public_ips,
127                          int (*cb)(uint32_t total_ip_count,
128                                    const struct sockaddr_storage *ip,
129                                    uint32_t pinned_pnn,
130                                    uint32_t current_pnn,
131                                    void *private_data),
132                          void *private_data);
133
134 int ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode,
135                         uint64_t srvid, uint32_t flags, TDB_DATA data,
136                         TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
137                         int32_t *cstatus);
138 int ctdb_watch_us(struct ctdbd_connection *conn);
139 int ctdb_unwatch(struct ctdbd_connection *conn);
140
141 struct ctdb_req_message_old;
142
143 int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
144                         int (*cb)(struct tevent_context *ev,
145                                   uint32_t src_vnn, uint32_t dst_vnn,
146                                   uint64_t dst_srvid,
147                                   const uint8_t *msg, size_t msglen,
148                                   void *private_data),
149                         void *private_data);
150 void deregister_from_ctdbd(struct ctdbd_connection *conn,
151                            uint64_t srvid,
152                            int (*cb)(struct tevent_context *ev,
153                                      uint32_t src_vnn,
154                                      uint32_t dst_vnn,
155                                      uint64_t dst_srvid,
156                                      const uint8_t *msg,
157                                      size_t msglen,
158                                      void *private_data),
159                            void *private_data);
160 int ctdbd_probe(const char *sockname, int timeout);
161
162 struct ctdb_req_header;
163 void ctdbd_prep_hdr_next_reqid(
164         struct ctdbd_connection *conn, struct ctdb_req_header *hdr);
165
166 /*
167  * Async ctdb_request. iov[0] must start with an initialized
168  * struct ctdb_req_header
169  */
170 struct tevent_req *ctdbd_req_send(
171         TALLOC_CTX *mem_ctx,
172         struct tevent_context *ev,
173         struct ctdbd_connection *conn,
174         struct iovec *iov,
175         size_t num_iov);
176 int ctdbd_req_recv(
177         struct tevent_req *req,
178         TALLOC_CTX *mem_ctx,
179         struct ctdb_req_header **reply);
180
181 struct tevent_req *ctdbd_parse_send(TALLOC_CTX *mem_ctx,
182                                     struct tevent_context *ev,
183                                     struct ctdbd_connection *conn,
184                                     uint32_t db_id,
185                                     TDB_DATA key,
186                                     bool local_copy,
187                                     void (*parser)(TDB_DATA key,
188                                                    TDB_DATA data,
189                                                    void *private_data),
190                                     void *private_data,
191                                     enum dbwrap_req_state *req_state);
192 int ctdbd_parse_recv(struct tevent_req *req);
193
194 #endif /* _CTDBD_CONN_H */