mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
ldb_tdb: factor out the (to be) common init code
Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
141148edd3
commit
68423e9f4a
@ -1923,6 +1923,57 @@ static const struct ldb_module_ops ltdb_ops = {
|
||||
.read_unlock = generic_unlock_read,
|
||||
};
|
||||
|
||||
int init_store(struct ltdb_private *ltdb,
|
||||
const char *name,
|
||||
struct ldb_context *ldb,
|
||||
const char *options[],
|
||||
struct ldb_module **_module)
|
||||
{
|
||||
struct ldb_module *module;
|
||||
|
||||
if (getenv("LDB_WARN_UNINDEXED")) {
|
||||
ltdb->warn_unindexed = true;
|
||||
}
|
||||
|
||||
if (getenv("LDB_WARN_REINDEX")) {
|
||||
ltdb->warn_reindex = true;
|
||||
}
|
||||
|
||||
ltdb->sequence_number = 0;
|
||||
|
||||
module = ldb_module_new(ldb, ldb, name, <db_ops);
|
||||
if (!module) {
|
||||
ldb_oom(ldb);
|
||||
talloc_free(ltdb);
|
||||
return LDB_ERR_OPERATIONS_ERROR;
|
||||
}
|
||||
ldb_module_set_private(module, ltdb);
|
||||
talloc_steal(module, ltdb);
|
||||
|
||||
if (ltdb_cache_load(module) != 0) {
|
||||
ldb_asprintf_errstring(ldb, "Unable to load ltdb cache "
|
||||
"records for backend '%s'", name);
|
||||
talloc_free(module);
|
||||
return LDB_ERR_OPERATIONS_ERROR;
|
||||
}
|
||||
|
||||
*_module = module;
|
||||
/*
|
||||
* Set the maximum key length
|
||||
*/
|
||||
{
|
||||
const char *len_str =
|
||||
ldb_options_find(ldb, options,
|
||||
"max_key_len_for_self_test");
|
||||
if (len_str != NULL) {
|
||||
unsigned len = strtoul(len_str, NULL, 0);
|
||||
ltdb->max_key_length = len;
|
||||
}
|
||||
}
|
||||
|
||||
return LDB_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
connect to the database
|
||||
*/
|
||||
@ -1930,7 +1981,6 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
|
||||
unsigned int flags, const char *options[],
|
||||
struct ldb_module **_module)
|
||||
{
|
||||
struct ldb_module *module;
|
||||
const char *path;
|
||||
int tdb_flags, open_flags;
|
||||
struct ltdb_private *ltdb;
|
||||
@ -1995,6 +2045,8 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
|
||||
open_flags = O_CREAT | O_RDWR;
|
||||
}
|
||||
|
||||
ltdb->kv_ops = &key_value_ops;
|
||||
|
||||
/* note that we use quite a large default hash size */
|
||||
ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000,
|
||||
tdb_flags, open_flags,
|
||||
@ -2011,48 +2063,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
|
||||
return LDB_ERR_OPERATIONS_ERROR;
|
||||
}
|
||||
|
||||
if (getenv("LDB_WARN_UNINDEXED")) {
|
||||
ltdb->warn_unindexed = true;
|
||||
}
|
||||
|
||||
if (getenv("LDB_WARN_REINDEX")) {
|
||||
ltdb->warn_reindex = true;
|
||||
}
|
||||
|
||||
ltdb->sequence_number = 0;
|
||||
ltdb->kv_ops = &key_value_ops;
|
||||
|
||||
module = ldb_module_new(ldb, ldb, "ldb_tdb backend", <db_ops);
|
||||
if (!module) {
|
||||
ldb_oom(ldb);
|
||||
talloc_free(ltdb);
|
||||
return LDB_ERR_OPERATIONS_ERROR;
|
||||
}
|
||||
ldb_module_set_private(module, ltdb);
|
||||
talloc_steal(module, ltdb);
|
||||
|
||||
if (ltdb_cache_load(module) != 0) {
|
||||
ldb_asprintf_errstring(ldb,
|
||||
"Unable to load ltdb cache records of tdb '%s'", path);
|
||||
talloc_free(module);
|
||||
return LDB_ERR_OPERATIONS_ERROR;
|
||||
}
|
||||
|
||||
*_module = module;
|
||||
|
||||
/*
|
||||
* Set the maximum key length
|
||||
*/
|
||||
{
|
||||
const char *len_str =
|
||||
ldb_options_find(ldb, options,
|
||||
"max_key_len_for_self_test");
|
||||
if (len_str != NULL) {
|
||||
unsigned len = strtoul(len_str, NULL, 0);
|
||||
ltdb->max_key_length = len;
|
||||
}
|
||||
}
|
||||
return LDB_SUCCESS;
|
||||
return init_store(ltdb, "ldb_tdb backend", ldb, options, _module);
|
||||
}
|
||||
|
||||
int ldb_tdb_init(const char *version)
|
||||
|
@ -196,3 +196,6 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
|
||||
const char *path, int hash_size, int tdb_flags,
|
||||
int open_flags, mode_t mode,
|
||||
struct ldb_context *ldb);
|
||||
int init_store(struct ltdb_private *ltdb, const char *name,
|
||||
struct ldb_context *ldb, const char *options[],
|
||||
struct ldb_module **_module);
|
||||
|
Loading…
Reference in New Issue
Block a user