]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ldb_tdb: Begin abstracting out the base key value operations
authorGarming Sam <garming@catalyst.net.nz>
Tue, 10 Jan 2017 06:05:40 +0000 (19:05 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 5 Mar 2018 19:50:15 +0000 (20:50 +0100)
This will allow us to change the backend from tdb to lmdb.

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ldb_tdb/ldb_tdb.c
lib/ldb/ldb_tdb/ldb_tdb.h

index dcb877312a9a7ceaad2f1240d93068422bb82f58..ee3a78149973f325e4e58a6d3ce8530d4b8ef8d1 100644 (file)
@@ -413,6 +413,16 @@ 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));
+}
+
 /*
   store a record into the db
 */
@@ -635,6 +645,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)
@@ -1671,6 +1686,20 @@ static void ltdb_handle_extended(struct ltdb_context *ctx)
        ltdb_request_extended_done(ctx, ext, ret);
 }
 
+static const char * ltdb_tdb_name(struct ltdb_private *ltdb)
+{
+       return tdb_name(ltdb->tdb);
+}
+
+static const struct kv_db_ops key_value_ops = {
+       .store = ltdb_tdb_store,
+       .delete = ltdb_tdb_delete,
+       .lock_read = ltdb_lock_read,
+       .unlock_read = ltdb_unlock_read,
+       .error = ltdb_error,
+       .name = ltdb_tdb_name,
+};
+
 static void ltdb_callback(struct tevent_context *ev,
                          struct tevent_timer *te,
                          struct timeval t,
@@ -1934,6 +1963,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
        }
 
        ltdb->sequence_number = 0;
+       ltdb->kv_ops = &key_value_ops;
 
        module = ldb_module_new(ldb, ldb, "ldb_tdb backend", &ltdb_ops);
        if (!module) {
index 421ae4d95d6106c3d6f5c5c59e0e3db7d48b9ed7..60ba2652a61d702d996d70f531083e7cb9f1eb8f 100644 (file)
@@ -4,9 +4,20 @@
 #include "tdb.h"
 #include "ldb_module.h"
 
+struct ltdb_private;
+struct kv_db_ops {
+       int (*store)(struct ltdb_private *ltdb, TDB_DATA key, TDB_DATA data, int flags);
+       int (*delete)(struct ltdb_private *ltdb, TDB_DATA key);
+       int (*lock_read)(struct ldb_module *);
+       int (*unlock_read)(struct ldb_module *);
+       int (*error)(struct ltdb_private *ltdb);
+       const char * (*name)(struct ltdb_private *ltdb);
+};
+
 /* this private structure is used by the ltdb backend in the
    ldb_context */
 struct ltdb_private {
+       const struct kv_db_ops *kv_ops;
        TDB_CONTEXT *tdb;
        unsigned int connect_flags;