From: Garming Sam Date: Tue, 10 Jan 2017 22:36:48 +0000 (+1300) Subject: ldb_tdb: factor out the (to be) common init code X-Git-Tag: talloc-2.1.12~251 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=68423e9f4a62fb4835c0e0c4a09a656aa02ffa10;p=thirdparty%2Fsamba.git ldb_tdb: factor out the (to be) common init code Signed-off-by: Garming Sam Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 6cdd5733b98..6593dc2ee93 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -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) diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 5c930bf997a..a40bbad9699 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -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);