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_delete(struct db_record
*rec
);
76 struct db_record
*dbwrap_fetch_locked(struct db_context
*db
,
79 struct db_record
*dbwrap_try_fetch_locked(struct db_context
*db
,
82 struct db_context
*dbwrap_record_get_db(struct db_record
*rec
);
84 NTSTATUS
dbwrap_delete(struct db_context
*db
, TDB_DATA key
);
85 NTSTATUS
dbwrap_store(struct db_context
*db
, TDB_DATA key
,
86 TDB_DATA data
, int flags
);
87 NTSTATUS
dbwrap_fetch(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
88 TDB_DATA key
, TDB_DATA
*value
);
89 bool dbwrap_exists(struct db_context
*db
, TDB_DATA key
);
90 NTSTATUS
dbwrap_traverse(struct db_context
*db
,
91 int (*f
)(struct db_record
*, void*),
94 NTSTATUS
dbwrap_traverse_read(struct db_context
*db
,
95 int (*f
)(struct db_record
*, void*),
98 NTSTATUS
dbwrap_parse_record(struct db_context
*db
, TDB_DATA key
,
99 void (*parser
)(TDB_DATA key
, TDB_DATA data
,
103 * Async implementation of dbwrap_parse_record
105 * @param[in] mem_ctx talloc memory context to use.
107 * @param[in] ev tevent context to use
109 * @param[in] db Database to query
111 * @param[in] key Record key, the function makes a copy of this
113 * @param[in] parser Parser callback function
115 * @param[in] private_data Private data for the callback function
117 * @param[out] req_state Pointer to a enum dbwrap_req_state variable
119 * @note req_state is updated in the send function. To determine the final
120 * result of the request the caller should therefor not rely on req_state. The
121 * primary use case is to give the caller an indication whether the request is
122 * already sent to ctdb (DBWRAP_REQ_DISPATCHED) or if it's still stuck in the
123 * sendqueue (DBWRAP_REQ_QUEUED).
125 struct tevent_req
*dbwrap_parse_record_send(
127 struct tevent_context
*ev
,
128 struct db_context
*db
,
130 void (*parser
)(TDB_DATA key
, TDB_DATA data
, void *private_data
),
132 enum dbwrap_req_state
*req_state
);
133 NTSTATUS
dbwrap_parse_record_recv(struct tevent_req
*req
);
134 int dbwrap_wipe(struct db_context
*db
);
135 int dbwrap_check(struct db_context
*db
);
136 int dbwrap_get_seqnum(struct db_context
*db
);
137 /* Returns 0 if unknown. */
138 int dbwrap_transaction_start(struct db_context
*db
);
139 NTSTATUS
dbwrap_transaction_start_nonblock(struct db_context
*db
);
140 int dbwrap_transaction_commit(struct db_context
*db
);
141 int dbwrap_transaction_cancel(struct db_context
*db
);
142 size_t dbwrap_db_id(struct db_context
*db
, uint8_t *id
, size_t idlen
);
143 bool dbwrap_is_persistent(struct db_context
*db
);
144 const char *dbwrap_name(struct db_context
*db
);
146 /* The following definitions come from lib/dbwrap_util.c */
148 NTSTATUS
dbwrap_purge(struct db_context
*db
, TDB_DATA key
);
149 NTSTATUS
dbwrap_purge_bystring(struct db_context
*db
, const char *key
);
150 NTSTATUS
dbwrap_delete_bystring(struct db_context
*db
, const char *key
);
151 NTSTATUS
dbwrap_store_bystring(struct db_context
*db
, const char *key
,
152 TDB_DATA data
, int flags
);
153 NTSTATUS
dbwrap_fetch_bystring(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
154 const char *key
, TDB_DATA
*value
);
156 NTSTATUS
dbwrap_fetch_int32(struct db_context
*db
, TDB_DATA key
,
158 NTSTATUS
dbwrap_fetch_int32_bystring(struct db_context
*db
, const char *keystr
,
160 NTSTATUS
dbwrap_store_int32_bystring(struct db_context
*db
, const char *keystr
,
162 NTSTATUS
dbwrap_fetch_uint32_bystring(struct db_context
*db
,
163 const char *keystr
, uint32_t *val
);
164 NTSTATUS
dbwrap_store_uint32_bystring(struct db_context
*db
,
165 const char *keystr
, uint32_t v
);
166 NTSTATUS
dbwrap_change_uint32_atomic_bystring(struct db_context
*db
,
169 uint32_t change_val
);
170 NTSTATUS
dbwrap_trans_change_uint32_atomic_bystring(struct db_context
*db
,
173 uint32_t change_val
);
174 NTSTATUS
dbwrap_change_int32_atomic(struct db_context
*db
,
178 NTSTATUS
dbwrap_change_int32_atomic_bystring(struct db_context
*db
,
182 NTSTATUS
dbwrap_trans_change_int32_atomic_bystring(struct db_context
*db
,
186 NTSTATUS
dbwrap_trans_store(struct db_context
*db
, TDB_DATA key
, TDB_DATA dbuf
,
188 NTSTATUS
dbwrap_trans_delete(struct db_context
*db
, TDB_DATA key
);
189 NTSTATUS
dbwrap_trans_store_int32_bystring(struct db_context
*db
,
192 NTSTATUS
dbwrap_trans_store_uint32_bystring(struct db_context
*db
,
195 NTSTATUS
dbwrap_trans_store_bystring(struct db_context
*db
, const char *key
,
196 TDB_DATA data
, int flags
);
197 NTSTATUS
dbwrap_trans_delete_bystring(struct db_context
*db
, const char *key
);
198 NTSTATUS
dbwrap_trans_do(struct db_context
*db
,
199 NTSTATUS (*action
)(struct db_context
*, void *),
201 NTSTATUS
dbwrap_trans_traverse(struct db_context
*db
,
202 int (*f
)(struct db_record
*, void*),
205 NTSTATUS
dbwrap_delete_bystring_upper(struct db_context
*db
, const char *key
);
206 NTSTATUS
dbwrap_store_bystring_upper(struct db_context
*db
, const char *key
,
207 TDB_DATA data
, int flags
);
208 NTSTATUS
dbwrap_fetch_bystring_upper(struct db_context
*db
, TALLOC_CTX
*mem_ctx
,
209 const char *key
, TDB_DATA
*value
);
211 size_t dbwrap_marshall(struct db_context
*db
, uint8_t *buf
, size_t bufsize
);
212 NTSTATUS
dbwrap_parse_marshall_buf(const uint8_t *buf
, size_t buflen
,
213 bool (*fn
)(TDB_DATA key
, TDB_DATA value
,
216 NTSTATUS
dbwrap_unmarshall(struct db_context
*db
, const uint8_t *buf
,
221 * This opens a tdb file
223 struct db_context
*dbwrap_local_open(TALLOC_CTX
*mem_ctx
,
224 struct loadparm_context
*lp_ctx
,
226 int hash_size
, int tdb_flags
,
227 int open_flags
, mode_t mode
,
228 enum dbwrap_lock_order lock_order
,
229 uint64_t dbwrap_flags
);
231 #endif /* __DBWRAP_H__ */