The branch, master has been updated via 4014499 ldb_tdb: Build a key value operation library via e3d364a partition: Allow a different backend store from @PARTITION via 4d5180e ldb_tdb: Implement a traversal function in key value ops via c9f2ff2 ldb_tdb: Use key value ops for fetch command via 68423e9 ldb_tdb: factor out the (to be) common init code via 141148e ldb_tdb: Add errorstr to the key value ops via c66a005 ldb_tdb: Remove tdb_get_seqnum and use a generic 'has_changed' via e21a476 ldb_tdb: Add lock_read and unlock_read to key value ops via 448101a ldb_tdb: Replace tdb transaction code with generic key value ones via e33fb2c ldb_tdb: Replace exists, name and error_map with key value ops via 9c8f00a ldb_tdb: Begin abstracting out the base key value operations via 2a0e022 dsdb: The schema should be reloaded during the transaction via 8ac1646 samdb/schema_load: do schema loading with one search via 313b0c6 schema_set: Add a missing newline between functions via bca8ac0 remove_dc.py: Abort transaction before throwing an exception via c4c64ff ldb_mod_op_test: Fix core dump on ldb_case_attrs_index_test_teardown via 242cf33 partition: Leave metadata.tdb unlocking until last via 8caf84a schema: Do not read different schema sequence values during a read transaction via 1265346 partition: Use a transaction to write and a read lock to read the LDB_METADATA_SEQ_NUM from c59d5e1 build: fix standalone ctdb build --with-systemd
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 4014499b128cab567a3b27e31ce4ee86e58be4f7 Author: Garming Sam <garm...@catalyst.net.nz> Date: Fri Feb 16 13:26:46 2018 +1300 ldb_tdb: Build a key value operation library This allows sharing of the originally ldb_tdb operations to the new ldb_mdb backend. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Autobuild-User(master): Andrew Bartlett <abart...@samba.org> Autobuild-Date(master): Tue Mar 6 01:39:16 CET 2018 on sn-devel-144 commit e3d364a99b98498b131452e739cedf8ce5a773da Author: Garming Sam <garm...@catalyst.net.nz> Date: Fri Jan 13 11:32:14 2017 +1300 partition: Allow a different backend store from @PARTITION By default, use tdb, but otherwise read the value from backendStore. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 4d5180e45c58dc68f8d5dca09c4a87b6830468af Author: Garming Sam <garm...@catalyst.net.nz> Date: Fri Feb 16 13:06:31 2018 +1300 ldb_tdb: Implement a traversal function in key value ops This can handle both read-only and writable traverses. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c9f2ff275b69bcd13ae236ae07dee8bce0a4e4a2 Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Jan 10 20:43:38 2017 +1300 ldb_tdb: Use key value ops for fetch command Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 68423e9f4a62fb4835c0e0c4a09a656aa02ffa10 Author: Garming Sam <garm...@catalyst.net.nz> Date: Wed Jan 11 11:36:48 2017 +1300 ldb_tdb: factor out the (to be) common init code Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 141148edd34c587f4e0f5b992d71201ade541d70 Author: Gary Lockyer <g...@catalyst.net.nz> Date: Tue Feb 13 15:21:34 2018 +1300 ldb_tdb: Add errorstr to the key value ops Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c66a0054fb99b6519344c11954417d6615e1310b Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Jan 10 23:23:22 2017 +1300 ldb_tdb: Remove tdb_get_seqnum and use a generic 'has_changed' Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit e21a476c278f3963a1dd4ec7ad272e3fa3b09b40 Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Jan 10 23:19:55 2017 +1300 ldb_tdb: Add lock_read and unlock_read to key value ops Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 448101a3fd7375148d1a79a615477ac32b04f3fb Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Jan 10 21:44:11 2017 +1300 ldb_tdb: Replace tdb transaction code with generic key value ones Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit e33fb2c63302b300f9175711b5d615eae58850d1 Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Jan 10 20:45:02 2017 +1300 ldb_tdb: Replace exists, name and error_map with key value ops Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 9c8f00aaba3532ea8055144a882d8fab49f56a8e Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Jan 10 19:05:40 2017 +1300 ldb_tdb: Begin abstracting out the base key value operations This will allow us to change the backend from tdb to lmdb. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 2a0e0227383612c5c13c1b6e67afff274ffd4571 Author: Garming Sam <garm...@catalyst.net.nz> Date: Tue Nov 21 11:31:10 2017 +1300 dsdb: The schema should be reloaded during the transaction Reload the schema just after getting the tranaction lock but before the transaction counter is bumped. This ensures we reload the schema exactly once but with the DB locked. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 8ac1646e92d707705c94bc286c17f1cd0d5505fb Author: Bob Campbell <bobcampb...@catalyst.net.nz> Date: Tue Jul 11 16:40:14 2017 +1200 samdb/schema_load: do schema loading with one search It appears that there was a race condition between searching for the attribute & class definitions, and searching for the schema object, if the schema was changed in-between the two searches. This is likely the cause of ldap_schema being flapping. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12889 Signed-off-by: Bob Campbell <bobcampb...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Garming Sam <garm...@catalyst.net.nz> commit 313b0c60f482c8fef45dcafba5d8dc6c2e29b461 Author: Garming Sam <garm...@catalyst.net.nz> Date: Wed Nov 22 12:37:07 2017 +1300 schema_set: Add a missing newline between functions Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit bca8ac0296b9049fcc126bd775eace265ecc1ced Author: Gary Lockyer <g...@catalyst.net.nz> Date: Fri Jan 19 09:16:04 2018 +1300 remove_dc.py: Abort transaction before throwing an exception Signed-off-by: Gary Lockyer <g...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit c4c64ff51f7ee6a332f71f093ffd37e06745e785 Author: Gary Lockyer <g...@catalyst.net.nz> Date: Tue Jan 23 11:02:28 2018 +1300 ldb_mod_op_test: Fix core dump on ldb_case_attrs_index_test_teardown With no schema syntax, this would occasionally crash as it dereferenced some possibly NULL sequence of memory. Note: Removing all tests except this one, made it crash reliably. Signed-off-by: Gary Lockyer <g...@catalyst.net.nz> Reviewed-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 242cf337e9e9d72f8c919d0772fd5e35fb2422dc Author: Garming Sam <garm...@catalyst.net.nz> Date: Wed Feb 7 23:21:45 2018 +1300 partition: Leave metadata.tdb unlocking until last With the lmdb patches, I have cleanly observed the database being read in between the commit of the metadata.tdb and the eventual commits of the individual partitions. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 8caf84a8d4c4454941c163b7ecd9a2e65060526c Author: Garming Sam <garm...@catalyst.net.nz> Date: Fri Feb 2 12:05:27 2018 +1300 schema: Do not read different schema sequence values during a read transaction During a read lock, we find ourselves seeing an unchanged schema, but reading any updates to the metadata.tdb (in the case of lmdb, where reads do not block writes). The alternative is to read-lock the entire metadata.tdb, however, this allows more concurrency by allowing reads not to block writes. Signed-off-by: Garming Sam <garm...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> commit 1265346f6c8ada27f2f0cf29a4f21a457fb6af00 Author: Andrew Bartlett <abart...@samba.org> Date: Thu Feb 1 17:16:13 2018 +1300 partition: Use a transaction to write and a read lock to read the LDB_METADATA_SEQ_NUM This is critical as otherwise we can read a sequence number in advance of the data that it represents and so have a false cache. Signed-off-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Garming Sam <garm...@catalyst.net.nz> ----------------------------------------------------------------------- Summary of changes: lib/ldb/ldb_tdb/ldb_cache.c | 14 +- lib/ldb/ldb_tdb/ldb_index.c | 77 ++--- lib/ldb/ldb_tdb/ldb_search.c | 40 ++- lib/ldb/ldb_tdb/ldb_tdb.c | 327 ++++++++++++++++----- lib/ldb/ldb_tdb/ldb_tdb.h | 45 ++- .../ldb_options.c => ldb_tdb/ldb_tdb_init.c} | 67 ++--- lib/ldb/tests/ldb_mod_op_test.c | 8 + lib/ldb/wscript | 12 +- python/samba/remove_dc.py | 3 + source4/dsdb/samdb/ldb_modules/partition.c | 32 +- source4/dsdb/samdb/ldb_modules/partition.h | 2 + source4/dsdb/samdb/ldb_modules/partition_init.c | 37 ++- .../dsdb/samdb/ldb_modules/partition_metadata.c | 65 +++- source4/dsdb/samdb/ldb_modules/schema_load.c | 156 +++++++--- source4/dsdb/schema/schema_init.c | 24 +- source4/dsdb/schema/schema_set.c | 1 + 16 files changed, 626 insertions(+), 284 deletions(-) copy lib/ldb/{common/ldb_options.c => ldb_tdb/ldb_tdb_init.c} (51%) Changeset truncated at 500 lines: diff --git a/lib/ldb/ldb_tdb/ldb_cache.c b/lib/ldb/ldb_tdb/ldb_cache.c index 5b90bd9..4790bcd 100644 --- a/lib/ldb/ldb_tdb/ldb_cache.c +++ b/lib/ldb/ldb_tdb/ldb_cache.c @@ -391,8 +391,7 @@ int ltdb_cache_load(struct ldb_module *module) ldb = ldb_module_get_ctx(module); /* a very fast check to avoid extra database reads */ - if (ltdb->cache != NULL && - tdb_get_seqnum(ltdb->tdb) == ltdb->tdb_seqnum) { + if (ltdb->cache != NULL && !ltdb->kv_ops->has_changed(ltdb)) { return 0; } @@ -415,7 +414,7 @@ int ltdb_cache_load(struct ldb_module *module) /* possibly initialise the baseinfo */ if (r == LDB_ERR_NO_SUCH_OBJECT) { - if (tdb_transaction_start(ltdb->tdb) != 0) { + if (ltdb->kv_ops->begin_write(ltdb) != 0) { goto failed; } @@ -423,14 +422,17 @@ int ltdb_cache_load(struct ldb_module *module) looking for the record again. */ ltdb_baseinfo_init(module); - tdb_transaction_commit(ltdb->tdb); + if (ltdb->kv_ops->finish_write(ltdb) != 0) { + goto failed; + } if (ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0) != LDB_SUCCESS) { goto failed; } } - ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb); + /* Ignore the result, and update the sequence number */ + ltdb->kv_ops->has_changed(ltdb); /* if the current internal sequence number is the same as the one in the database then assume the rest of the cache is OK */ @@ -592,7 +594,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) /* updating the tdb_seqnum here avoids us reloading the cache records due to our own modification */ - ltdb->tdb_seqnum = tdb_get_seqnum(ltdb->tdb); + ltdb->kv_ops->has_changed(ltdb); return ret; } diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 739cab0..bb534c3 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -2673,17 +2673,16 @@ int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg) commit, which in turn greatly reduces DB churn as we will likely be able to do a direct update into the old record. */ -static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +static int delete_index(struct ltdb_private *ltdb, struct ldb_val key, struct ldb_val data, void *state) { struct ldb_module *module = state; - struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); const char *dnstr = "DN=" LTDB_INDEX ":"; struct dn_list list; struct ldb_dn *dn; struct ldb_val v; int ret; - if (strncmp((char *)key.dptr, dnstr, strlen(dnstr)) != 0) { + if (strncmp((char *)key.data, dnstr, strlen(dnstr)) != 0) { return 0; } /* we need to put a empty list in the internal tdb for this @@ -2692,8 +2691,8 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, vo list.count = 0; /* the offset of 3 is to remove the DN= prefix. */ - v.data = key.dptr + 3; - v.length = strnlen((char *)key.dptr, key.dsize) - 3; + v.data = key.data + 3; + v.length = strnlen((char *)key.data, key.length) - 3; dn = ldb_dn_from_ldb_val(ltdb, ldb_module_get_ctx(module), &v); @@ -2713,29 +2712,23 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, vo return 0; } -struct ltdb_reindex_context { - struct ldb_module *module; - int error; - uint32_t count; -}; - /* - traversal function that adds @INDEX records during a re index + traversal function that adds @INDEX records during a re index TODO wrong comment */ -static int re_key(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +static int re_key(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ldb_val val, void *state) { struct ldb_context *ldb; struct ltdb_reindex_context *ctx = (struct ltdb_reindex_context *)state; struct ldb_module *module = ctx->module; struct ldb_message *msg; unsigned int nb_elements_in_db; - const struct ldb_val val = { - .data = data.dptr, - .length = data.dsize, - }; int ret; TDB_DATA key2; bool is_record; + TDB_DATA key = { + .dptr = ldb_key.data, + .dsize = ldb_key.length + }; ldb = ldb_module_get_ctx(module); @@ -2790,32 +2783,11 @@ static int re_key(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *st } if (key.dsize != key2.dsize || (memcmp(key.dptr, key2.dptr, key.dsize) != 0)) { - int tdb_ret; - tdb_ret = tdb_delete(tdb, key); - if (tdb_ret != 0) { - ldb_debug(ldb, LDB_DEBUG_ERROR, - "Failed to delete %*.*s " - "for rekey as %*.*s: %s", - (int)key.dsize, (int)key.dsize, - (const char *)key.dptr, - (int)key2.dsize, (int)key2.dsize, - (const char *)key.dptr, - tdb_errorstr(tdb)); - ctx->error = ltdb_err_map(tdb_error(tdb)); - return -1; - } - tdb_ret = tdb_store(tdb, key2, data, 0); - if (tdb_ret != 0) { - ldb_debug(ldb, LDB_DEBUG_ERROR, - "Failed to rekey %*.*s as %*.*s: %s", - (int)key.dsize, (int)key.dsize, - (const char *)key.dptr, - (int)key2.dsize, (int)key2.dsize, - (const char *)key.dptr, - tdb_errorstr(tdb)); - ctx->error = ltdb_err_map(tdb_error(tdb)); - return -1; - } + TDB_DATA data = { + .dptr = val.data, + .dsize = val.length + }; + ltdb->kv_ops->update_in_iterate(ltdb, key, key2, data, ctx); } talloc_free(key2.dptr); @@ -2834,18 +2806,16 @@ static int re_key(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *st /* traversal function that adds @INDEX records during a re index */ -static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +static int re_index(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ldb_val val, void *state) { struct ldb_context *ldb; struct ltdb_reindex_context *ctx = (struct ltdb_reindex_context *)state; struct ldb_module *module = ctx->module; - struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), - struct ltdb_private); struct ldb_message *msg; unsigned int nb_elements_in_db; - const struct ldb_val val = { - .data = data.dptr, - .length = data.dsize, + TDB_DATA key = { + .dptr = ldb_key.data, + .dsize = ldb_key.length }; int ret; bool is_record; @@ -2955,7 +2925,7 @@ int ltdb_reindex(struct ldb_module *module) /* first traverse the database deleting any @INDEX records by * putting NULL entries in the in-memory tdb */ - ret = tdb_traverse(ltdb->tdb, delete_index, module); + ret = ltdb->kv_ops->iterate(ltdb, delete_index, module); if (ret < 0) { struct ldb_context *ldb = ldb_module_get_ctx(module); ldb_asprintf_errstring(ldb, "index deletion traverse failed: %s", @@ -2967,8 +2937,7 @@ int ltdb_reindex(struct ldb_module *module) ctx.error = 0; ctx.count = 0; - /* now traverse adding any indexes for normal LDB records */ - ret = tdb_traverse(ltdb->tdb, re_key, &ctx); + ret = ltdb->kv_ops->iterate(ltdb, re_key, &ctx); if (ret < 0) { struct ldb_context *ldb = ldb_module_get_ctx(module); ldb_asprintf_errstring(ldb, "key correction traverse failed: %s", @@ -2986,7 +2955,7 @@ int ltdb_reindex(struct ldb_module *module) ctx.count = 0; /* now traverse adding any indexes for normal LDB records */ - ret = tdb_traverse(ltdb->tdb, re_index, &ctx); + ret = ltdb->kv_ops->iterate(ltdb, re_index, &ctx); if (ret < 0) { struct ldb_context *ldb = ldb_module_get_ctx(module); ldb_asprintf_errstring(ldb, "reindexing traverse failed: %s", @@ -3004,7 +2973,7 @@ int ltdb_reindex(struct ldb_module *module) ldb_debug(ldb_module_get_ctx(module), LDB_DEBUG_WARNING, "Reindexing: re_index successful on %s, " "final index write-out will be in transaction commit", - tdb_name(ltdb->tdb)); + ltdb->kv_ops->name(ltdb)); } return LDB_SUCCESS; } diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c index d8bf865..78ef8b0 100644 --- a/lib/ldb/ldb_tdb/ldb_search.c +++ b/lib/ldb/ldb_tdb/ldb_search.c @@ -252,11 +252,11 @@ int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb, msg->num_elements = 0; msg->elements = NULL; - ret = tdb_parse_record(ltdb->tdb, tdb_key, - ltdb_parse_data_unpack, &ctx); - + ret = ltdb->kv_ops->fetch_and_parse(ltdb, tdb_key, + ltdb_parse_data_unpack, &ctx); + if (ret == -1) { - ret = ltdb_err_map(tdb_error(ltdb->tdb)); + ret = ltdb->kv_ops->error(ltdb); if (ret == LDB_SUCCESS) { /* * Just to be sure we don't turn errors @@ -487,23 +487,23 @@ failed: /* search function for a non-indexed search */ -static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +static int search_func(struct ltdb_private *ltdb, struct ldb_val key, struct ldb_val val, void *state) { struct ldb_context *ldb; struct ltdb_context *ac; struct ldb_message *msg, *filtered_msg; - const struct ldb_val val = { - .data = data.dptr, - .length = data.dsize, - }; int ret; bool matched; unsigned int nb_elements_in_db; + TDB_DATA tdb_key = { + .dptr = key.data, + .dsize = key.length + }; ac = talloc_get_type(state, struct ltdb_context); ldb = ldb_module_get_ctx(ac->module); - if (ltdb_key_is_record(key) == false) { + if (ltdb_key_is_record(tdb_key) == false) { return 0; } @@ -528,7 +528,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi if (!msg->dn) { msg->dn = ldb_dn_new(msg, ldb, - (char *)key.dptr + 3); + (char *)key.data + 3); if (msg->dn == NULL) { talloc_free(msg); ac->error = LDB_ERR_OPERATIONS_ERROR; @@ -581,11 +581,7 @@ static int ltdb_search_full(struct ltdb_context *ctx) int ret; ctx->error = LDB_SUCCESS; - if (ltdb->in_transaction != 0) { - ret = tdb_traverse(ltdb->tdb, search_func, ctx); - } else { - ret = tdb_traverse_read(ltdb->tdb, search_func, ctx); - } + ret = ltdb->kv_ops->iterate(ltdb, search_func, ctx); if (ret < 0) { return LDB_ERR_OPERATIONS_ERROR; @@ -711,17 +707,17 @@ int ltdb_search(struct ltdb_context *ctx) ldb_request_set_state(req, LDB_ASYNC_PENDING); - if (ltdb_lock_read(module) != 0) { + if (ltdb->kv_ops->lock_read(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } if (ltdb_cache_load(module) != 0) { - ltdb_unlock_read(module); + ltdb->kv_ops->unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } if (req->op.search.tree == NULL) { - ltdb_unlock_read(module); + ltdb->kv_ops->unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } @@ -768,7 +764,7 @@ int ltdb_search(struct ltdb_context *ctx) */ ret = ltdb_search_and_return_base(ltdb, ctx); - ltdb_unlock_read(module); + ltdb->kv_ops->unlock_read(module); return ret; @@ -830,7 +826,7 @@ int ltdb_search(struct ltdb_context *ctx) * full search or we may return * duplicate entries */ - ltdb_unlock_read(module); + ltdb->kv_ops->unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } ret = ltdb_search_full(ctx); @@ -840,7 +836,7 @@ int ltdb_search(struct ltdb_context *ctx) } } - ltdb_unlock_read(module); + ltdb->kv_ops->unlock_read(module); return ret; } diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index dcb8773..4f1c241 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -94,7 +94,7 @@ int ltdb_err_map(enum TDB_ERROR tdb_code) /* lock the database for read - use by ltdb_search and ltdb_sequence_number */ -int ltdb_lock_read(struct ldb_module *module) +static int ltdb_lock_read(struct ldb_module *module) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -124,7 +124,7 @@ int ltdb_lock_read(struct ldb_module *module) /* unlock the database after a ltdb_lock_read() */ -int ltdb_unlock_read(struct ldb_module *module) +static int ltdb_unlock_read(struct ldb_module *module) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -391,7 +391,7 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) if (ltdb->warn_reindex) { ldb_debug(ldb_module_get_ctx(module), LDB_DEBUG_ERROR, "Reindexing %s due to modification on %s", - tdb_name(ltdb->tdb), ldb_dn_get_linearized(dn)); + ltdb->kv_ops->name(ltdb), ldb_dn_get_linearized(dn)); } ret = ltdb_reindex(module); } @@ -413,6 +413,21 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) return ret; } +static int ltdb_tdb_store(struct ltdb_private *ltdb, TDB_DATA key, TDB_DATA data, int flags) +{ + return tdb_store(ltdb->tdb, key, data, flags); +} + +static int ltdb_error(struct ltdb_private *ltdb) +{ + return ltdb_err_map(tdb_error(ltdb->tdb)); +} + +static const char *ltdb_errorstr(struct ltdb_private *ltdb) +{ + return tdb_errorstr(ltdb->tdb); +} + /* store a record into the db */ @@ -449,10 +464,10 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg tdb_data.dptr = ldb_data.data; tdb_data.dsize = ldb_data.length; - ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs); + ret = ltdb->kv_ops->store(ltdb, tdb_key, tdb_data, flgs); if (ret != 0) { bool is_special = ldb_dn_is_special(msg->dn); - ret = ltdb_err_map(tdb_error(ltdb->tdb)); + ret = ltdb->kv_ops->error(ltdb); /* * LDB_ERR_ENTRY_ALREADY_EXISTS means the DN, not @@ -635,6 +650,11 @@ static int ltdb_add(struct ltdb_context *ctx) return ret; } +static int ltdb_tdb_delete(struct ltdb_private *ltdb, TDB_DATA tdb_key) +{ + return tdb_delete(ltdb->tdb, tdb_key); +} + /* delete a record from the database, not updating indexes (used for deleting index records) @@ -662,11 +682,11 @@ int ltdb_delete_noindex(struct ldb_module *module, return LDB_ERR_OTHER; } - ret = tdb_delete(ltdb->tdb, tdb_key); + ret = ltdb->kv_ops->delete(ltdb, tdb_key); TALLOC_FREE(tdb_key_ctx); if (ret != 0) { - ret = ltdb_err_map(tdb_error(ltdb->tdb)); + ret = ltdb->kv_ops->error(ltdb); } return ret; @@ -906,7 +926,6 @@ static int msg_delete_element(struct ldb_module *module, return LDB_ERR_NO_SUCH_ATTRIBUTE; } - /* modify a record - internal interface @@ -1386,6 +1405,26 @@ static int ltdb_rename(struct ltdb_context *ctx) return ret; } +static int ltdb_tdb_transaction_start(struct ltdb_private *ltdb) +{ + return tdb_transaction_start(ltdb->tdb); +} + +static int ltdb_tdb_transaction_cancel(struct ltdb_private *ltdb) +{ + return tdb_transaction_cancel(ltdb->tdb); +} + +static int ltdb_tdb_transaction_prepare_commit(struct ltdb_private *ltdb) +{ + return tdb_transaction_prepare_commit(ltdb->tdb); +} + +static int ltdb_tdb_transaction_commit(struct ltdb_private *ltdb) +{ + return tdb_transaction_commit(ltdb->tdb); +} + static int ltdb_start_trans(struct ldb_module *module) { void *data = ldb_module_get_private(module); @@ -1396,8 +1435,8 @@ static int ltdb_start_trans(struct ldb_module *module) return LDB_ERR_UNWILLING_TO_PERFORM; } - if (tdb_transaction_start(ltdb->tdb) != 0) { - return ltdb_err_map(tdb_error(ltdb->tdb)); + if (ltdb->kv_ops->begin_write(ltdb) != 0) { + return ltdb->kv_ops->error(ltdb); } ltdb->in_transaction++; @@ -1419,19 +1458,19 @@ static int ltdb_prepare_commit(struct ldb_module *module) ret = ltdb_index_transaction_commit(module); if (ret != LDB_SUCCESS) { - tdb_transaction_cancel(ltdb->tdb); + ltdb->kv_ops->abort_write(ltdb); ltdb->in_transaction--; return ret; } - if (tdb_transaction_prepare_commit(ltdb->tdb) != 0) { - ret = ltdb_err_map(tdb_error(ltdb->tdb)); + if (ltdb->kv_ops->prepare_write(ltdb) != 0) { + ret = ltdb->kv_ops->error(ltdb); ltdb->in_transaction--; ldb_debug_set(ldb_module_get_ctx(module), LDB_DEBUG_FATAL, "Failure during " - "tdb_transaction_prepare_commit(): %s -> %s", - tdb_errorstr(ltdb->tdb), + "prepare_write): %s -> %s", -- Samba Shared Repository