added a ctdb_get_config call
[samba.git] / ctdb / include / ctdb.h
1 /* 
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library 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 GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifndef _CTDB_H
22 #define _CTDB_H
23
24 #define CTDB_IMMEDIATE_MIGRATION        0x00000001
25 struct ctdb_call {
26         int call_id;
27         TDB_DATA key;
28         TDB_DATA call_data;
29         TDB_DATA reply_data;
30         uint32_t status;
31         uint32_t flags;
32 };
33
34 /*
35   structure passed to a ctdb call backend function
36 */
37 struct ctdb_call_info {
38         TDB_DATA key;          /* record key */
39         TDB_DATA record_data;  /* current data in the record */
40         TDB_DATA *new_data;    /* optionally updated record data */
41         TDB_DATA *call_data;   /* optionally passed from caller */
42         TDB_DATA *reply_data;  /* optionally returned by function */
43         uint32_t status;       /* optional reply status - defaults to zero */
44 };
45
46 #define CTDB_ERR_INVALID 1
47 #define CTDB_ERR_NOMEM 2
48
49 /*
50   ctdb flags
51 */
52 #define CTDB_FLAG_SELF_CONNECT (1<<0)
53 #define CTDB_FLAG_TORTURE      (1<<1)
54
55
56 /* 
57    a message handler ID meaning "give me all messages"
58  */
59 #define CTDB_SRVID_ALL 0xFFFFFFFF
60
61 struct event_context;
62
63 /*
64   initialise ctdb subsystem
65 */
66 struct ctdb_context *ctdb_init(struct event_context *ev);
67
68 /*
69   choose the transport
70 */
71 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
72
73 /*
74   set the directory for the local databases
75 */
76 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
77
78 /*
79   set some flags
80 */
81 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
82
83 /*
84   clear some flags
85 */
86 void ctdb_clear_flags(struct ctdb_context *ctdb, unsigned flags);
87
88 /*
89   set max acess count before a dmaster migration
90 */
91 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
92
93 /*
94   tell ctdb what address to listen on, in transport specific format
95 */
96 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
97
98 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
99
100 /*
101   tell ctdb what nodes are available. This takes a filename, which will contain
102   1 node address per line, in a transport specific format
103 */
104 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
105
106 /*
107   start the ctdb protocol
108 */
109 int ctdb_start(struct ctdb_context *ctdb);
110
111 /*
112   attach to a ctdb database
113 */
114 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, int tdb_flags, 
115                                     int open_flags, mode_t mode);
116
117 /*
118   find an attached ctdb_db handle given a name
119  */
120 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
121
122 /*
123   error string for last ctdb error
124 */
125 const char *ctdb_errstr(struct ctdb_context *);
126
127 /* a ctdb call function */
128 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
129
130 /*
131   setup a ctdb call function
132 */
133 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, int id);
134
135
136
137 /*
138   make a ctdb call. The associated ctdb call function will be called on the DMASTER
139   for the given record
140 */
141 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
142
143 /*
144   wait for all nodes to be connected - useful for test code
145 */
146 void ctdb_connect_wait(struct ctdb_context *ctdb);
147
148 /*
149   initiate an ordered ctdb cluster shutdown
150   this function will never return
151 */
152 void ctdb_shutdown(struct ctdb_context *ctdb);
153
154 /* return vnn of this node */
155 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
156
157 /*
158   return the number of nodes
159 */
160 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
161
162 /* setup a handler for ctdb messages */
163 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid, 
164                                   TDB_DATA data, void *);
165 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint32_t srvid, 
166                              ctdb_message_fn_t handler,
167                              void *private_data);
168
169
170 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
171 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
172 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
173
174 /* send a ctdb message */
175 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
176                       uint32_t srvid, TDB_DATA data);
177
178
179 /* 
180    Fetch a ctdb record from a remote node
181  . Underneath this will force the
182    dmaster for the record to be moved to the local node. 
183
184 */
185 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
186                                            TDB_DATA key, TDB_DATA *data);
187
188
189 /*
190   do a fetch lock from a client to the local daemon
191 */
192 #define FETCH_LOCK_SUCCESS              0
193 #define FETCH_LOCK_LOCKFAILED           1
194 #define FETCH_LOCK_FETCHFAILED          2
195 #define FETCH_LOCK_DMASTERFAILED        3
196
197 int ctdb_client_fetch_lock(struct ctdb_db_context *ctdb_db, 
198                                                   TALLOC_CTX *mem_ctx, 
199                                                   TDB_DATA key, TDB_DATA *data);
200
201
202 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
203
204 int ctdb_register_message_handler(struct ctdb_context *ctdb, 
205                                   TALLOC_CTX *mem_ctx,
206                                   uint32_t srvid,
207                                   ctdb_message_fn_t handler,
208                                   void *private_data);
209
210 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
211
212
213 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
214
215 struct ctdb_status;
216 int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status);
217
218 int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TDB_DATA *path);
219
220 int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
221
222 int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode);
223
224 int ctdb_get_config(struct ctdb_context *ctdb);
225
226 #endif