2 Unix SMB/CIFS implementation.
3 Database interface wrapper around tdb
4 Copyright (C) Volker Lendecke 2005-2007
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.
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.
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/>.
26 #include "libcli/util/ntstatus.h"
28 #include "lib/param/loadparm.h"
33 enum dbwrap_lock_order
{
34 DBWRAP_LOCK_ORDER_NONE
= 0, /* Don't check lock orders for this db. */
36 * We only allow orders 1, 2, 3:
37 * These are the orders that CTDB currently supports.
39 DBWRAP_LOCK_ORDER_1
= 1,
40 DBWRAP_LOCK_ORDER_2
= 2,
41 DBWRAP_LOCK_ORDER_3
= 3
44 #define DBWRAP_FLAG_NONE 0x0000000000000000ULL
45 #define DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS 0x0000000000000001ULL
47 enum dbwrap_req_state
{
49 * We are creating the request
53 * The request is queued and waiting to be dispatched
57 * We are waiting to receive the reply
59 DBWRAP_REQ_DISPATCHED
,
61 * The request is finished
65 * The request errored out
70 /* The following definitions come from lib/dbwrap.c */
72 TDB_DATA
dbwrap_record_get_key(const struct db_record
*rec
);
73 TDB_DATA
dbwrap_record_get_value(const struct db_record
*rec
);
74 NTSTATUS
dbwrap_record_store(struct db_record
*rec
, TDB_DATA data
, int flags
);
75 NTSTATUS
dbwrap_record_storev(struct db_record
*rec
,
76 const TDB_DATA
*dbufs
, int num_dbufs
, int flags
);
77 NTSTATUS
dbwrap_record_delete(struct db_record
*rec
);
78 struct db_record
*dbwrap_fetch_locked(struct db_context
*db
,
81 struct db_record
*dbwrap_try_fetch_locked(struct db_context
*db
,
84 struct db_context
*dbwrap_record_get_db(struct db_record
*rec
);
86 NTSTATUS
dbwrap_do_locked(struct db_context
*db
, TDB_DATA key
,
87 void (*fn
)(struct db_record
*rec
,
91 NTSTATUS
dbwrap_delete(struct db_context
*db
, TDB_DATA key
);
92 NTSTATUS
dbwrap_store(struct db_context
*db
, TDB_DATA key
,
93 TDB_DATA data
, int flags
);
94 NTSTATUS
dbwrap_fetch(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
95 TDB_DATA key
, TDB_DATA
*value
);
96 bool dbwrap_exists(struct db_context
*db
, TDB_DATA key
);
97 NTSTATUS
dbwrap_traverse(struct db_context
*db
,
98 int (*f
)(struct db_record
*, void*),
101 NTSTATUS
dbwrap_traverse_read(struct db_context
*db
,
102 int (*f
)(struct db_record
*, void*),
105 NTSTATUS
dbwrap_parse_record(struct db_context
*db
, TDB_DATA key
,
106 void (*parser
)(TDB_DATA key
, TDB_DATA data
,
110 * Async implementation of dbwrap_parse_record
112 * @param[in] mem_ctx talloc memory context to use.
114 * @param[in] ev tevent context to use
116 * @param[in] db Database to query
118 * @param[in] key Record key, the function makes a copy of this
120 * @param[in] parser Parser callback function
122 * @param[in] private_data Private data for the callback function
124 * @param[out] req_state Pointer to a enum dbwrap_req_state variable
126 * @note req_state is updated in the send function. To determine the final
127 * result of the request the caller should therefor not rely on req_state. The
128 * primary use case is to give the caller an indication whether the request is
129 * already sent to ctdb (DBWRAP_REQ_DISPATCHED) or if it's still stuck in the
130 * sendqueue (DBWRAP_REQ_QUEUED).
132 struct tevent_req
*dbwrap_parse_record_send(
134 struct tevent_context
*ev
,
135 struct db_context
*db
,
137 void (*parser
)(TDB_DATA key
, TDB_DATA data
, void *private_data
),
139 enum dbwrap_req_state
*req_state
);
140 NTSTATUS
dbwrap_parse_record_recv(struct tevent_req
*req
);
141 int dbwrap_wipe(struct db_context
*db
);
142 int dbwrap_check(struct db_context
*db
);
143 int dbwrap_get_seqnum(struct db_context
*db
);
144 /* Returns 0 if unknown. */
145 int dbwrap_transaction_start(struct db_context
*db
);
146 NTSTATUS
dbwrap_transaction_start_nonblock(struct db_context
*db
);
147 int dbwrap_transaction_commit(struct db_context
*db
);
148 int dbwrap_transaction_cancel(struct db_context
*db
);
149 size_t dbwrap_db_id(struct db_context
*db
, uint8_t *id
, size_t idlen
);
150 bool dbwrap_is_persistent(struct db_context
*db
);
151 const char *dbwrap_name(struct db_context
*db
);
153 /* The following definitions come from lib/dbwrap_util.c */
155 NTSTATUS
dbwrap_purge(struct db_context
*db
, TDB_DATA key
);
156 NTSTATUS
dbwrap_purge_bystring(struct db_context
*db
, const char *key
);
157 NTSTATUS
dbwrap_delete_bystring(struct db_context
*db
, const char *key
);
158 NTSTATUS
dbwrap_store_bystring(struct db_context
*db
, const char *key
,
159 TDB_DATA data
, int flags
);
160 NTSTATUS
dbwrap_fetch_bystring(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
161 const char *key
, TDB_DATA
*value
);
163 NTSTATUS
dbwrap_fetch_int32(struct db_context
*db
, TDB_DATA key
,
165 NTSTATUS
dbwrap_fetch_int32_bystring(struct db_context
*db
, const char *keystr
,
167 NTSTATUS
dbwrap_store_int32_bystring(struct db_context
*db
, const char *keystr
,
169 NTSTATUS
dbwrap_fetch_uint32_bystring(struct db_context
*db
,
170 const char *keystr
, uint32_t *val
);
171 NTSTATUS
dbwrap_store_uint32_bystring(struct db_context
*db
,
172 const char *keystr
, uint32_t v
);
173 NTSTATUS
dbwrap_change_uint32_atomic_bystring(struct db_context
*db
,
176 uint32_t change_val
);
177 NTSTATUS
dbwrap_trans_change_uint32_atomic_bystring(struct db_context
*db
,
180 uint32_t change_val
);
181 NTSTATUS
dbwrap_change_int32_atomic(struct db_context
*db
,
185 NTSTATUS
dbwrap_change_int32_atomic_bystring(struct db_context
*db
,
189 NTSTATUS
dbwrap_trans_change_int32_atomic_bystring(struct db_context
*db
,
193 NTSTATUS
dbwrap_trans_store(struct db_context
*db
, TDB_DATA key
, TDB_DATA dbuf
,
195 NTSTATUS
dbwrap_trans_delete(struct db_context
*db
, TDB_DATA key
);
196 NTSTATUS
dbwrap_trans_store_int32_bystring(struct db_context
*db
,
199 NTSTATUS
dbwrap_trans_store_uint32_bystring(struct db_context
*db
,
202 NTSTATUS
dbwrap_trans_store_bystring(struct db_context
*db
, const char *key
,
203 TDB_DATA data
, int flags
);
204 NTSTATUS
dbwrap_trans_delete_bystring(struct db_context
*db
, const char *key
);
205 NTSTATUS
dbwrap_trans_do(struct db_context
*db
,
206 NTSTATUS (*action
)(struct db_context
*, void *),
208 NTSTATUS
dbwrap_trans_traverse(struct db_context
*db
,
209 int (*f
)(struct db_record
*, void*),
212 NTSTATUS
dbwrap_delete_bystring_upper(struct db_context
*db
, const char *key
);
213 NTSTATUS
dbwrap_store_bystring_upper(struct db_context
*db
, const char *key
,
214 TDB_DATA data
, int flags
);
215 NTSTATUS
dbwrap_fetch_bystring_upper(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
216 const char *key
, TDB_DATA
*value
);
218 size_t dbwrap_marshall(struct db_context
*db
, uint8_t *buf
, size_t bufsize
);
219 NTSTATUS
dbwrap_parse_marshall_buf(const uint8_t *buf
, size_t buflen
,
220 bool (*fn
)(TDB_DATA key
, TDB_DATA value
,
223 NTSTATUS
dbwrap_unmarshall(struct db_context
*db
, const uint8_t *buf
,
226 TDB_DATA
dbwrap_merge_dbufs(TALLOC_CTX
*mem_ctx
,
227 const TDB_DATA
*dbufs
, int num_dbufs
);
231 * This opens a tdb file
233 struct db_context
*dbwrap_local_open(TALLOC_CTX
*mem_ctx
,
234 struct loadparm_context
*lp_ctx
,
236 int hash_size
, int tdb_flags
,
237 int open_flags
, mode_t mode
,
238 enum dbwrap_lock_order lock_order
,
239 uint64_t dbwrap_flags
);
241 #endif /* __DBWRAP_H__ */