From 448101a3fd7375148d1a79a615477ac32b04f3fb Mon Sep 17 00:00:00 2001 From: Garming Sam Date: Tue, 10 Jan 2017 21:44:11 +1300 Subject: [PATCH] ldb_tdb: Replace tdb transaction code with generic key value ones Signed-off-by: Garming Sam Reviewed-by: Andrew Bartlett --- lib/ldb/ldb_tdb/ldb_cache.c | 6 ++++-- lib/ldb/ldb_tdb/ldb_tdb.c | 38 ++++++++++++++++++++++++++++++------- lib/ldb/ldb_tdb/ldb_tdb.h | 4 ++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_cache.c b/lib/ldb/ldb_tdb/ldb_cache.c index 5b90bd99f47..600b73f767e 100644 --- a/lib/ldb/ldb_tdb/ldb_cache.c +++ b/lib/ldb/ldb_tdb/ldb_cache.c @@ -415,7 +415,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,7 +423,9 @@ 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; diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index e5ee4e3d00f..70ab7880090 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1401,6 +1401,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); @@ -1411,7 +1431,7 @@ static int ltdb_start_trans(struct ldb_module *module) return LDB_ERR_UNWILLING_TO_PERFORM; } - if (tdb_transaction_start(ltdb->tdb) != 0) { + if (ltdb->kv_ops->begin_write(ltdb) != 0) { return ltdb->kv_ops->error(ltdb); } @@ -1434,13 +1454,13 @@ 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, @@ -1472,7 +1492,7 @@ static int ltdb_end_trans(struct ldb_module *module) ltdb->in_transaction--; ltdb->prepared_commit = false; - if (tdb_transaction_commit(ltdb->tdb) != 0) { + if (ltdb->kv_ops->finish_write(ltdb) != 0) { ret = ltdb->kv_ops->error(ltdb); ldb_asprintf_errstring(ldb_module_get_ctx(module), "Failure during tdb_transaction_commit(): %s -> %s", @@ -1492,11 +1512,11 @@ static int ltdb_del_trans(struct ldb_module *module) ltdb->in_transaction--; if (ltdb_index_transaction_cancel(module) != 0) { - tdb_transaction_cancel(ltdb->tdb); + ltdb->kv_ops->abort_write(ltdb); return ltdb->kv_ops->error(ltdb); } - tdb_transaction_cancel(ltdb->tdb); + ltdb->kv_ops->abort_write(ltdb); return LDB_SUCCESS; } @@ -1696,6 +1716,10 @@ static const struct kv_db_ops key_value_ops = { .delete = ltdb_tdb_delete, .lock_read = ltdb_lock_read, .unlock_read = ltdb_unlock_read, + .begin_write = ltdb_tdb_transaction_start, + .prepare_write = ltdb_tdb_transaction_prepare_commit, + .finish_write = ltdb_tdb_transaction_commit, + .abort_write = ltdb_tdb_transaction_cancel, .error = ltdb_error, .name = ltdb_tdb_name, }; diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 60ba2652a61..0ffe8458e86 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -10,6 +10,10 @@ struct kv_db_ops { int (*delete)(struct ltdb_private *ltdb, TDB_DATA key); int (*lock_read)(struct ldb_module *); int (*unlock_read)(struct ldb_module *); + int (*begin_write)(struct ltdb_private *); + int (*prepare_write)(struct ltdb_private *); + int (*abort_write)(struct ltdb_private *); + int (*finish_write)(struct ltdb_private *); int (*error)(struct ltdb_private *ltdb); const char * (*name)(struct ltdb_private *ltdb); };