ldb_tdb: Add lock_read and unlock_read to key value ops
authorGarming Sam <garming@catalyst.net.nz>
Tue, 10 Jan 2017 10:19:55 +0000 (23:19 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 5 Mar 2018 19:50:15 +0000 (20:50 +0100)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ldb_tdb/ldb_search.c
lib/ldb/ldb_tdb/ldb_tdb.c
lib/ldb/ldb_tdb/ldb_tdb.h

index c82b36618ca928dd5d9714a8eea048b3ea8af890..58cb36d1f33f9ffa399faf6a9fe76692d3171c5c 100644 (file)
@@ -711,17 +711,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 +768,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 +830,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 +840,7 @@ int ltdb_search(struct ltdb_context *ctx)
                }
        }
 
-       ltdb_unlock_read(module);
+       ltdb->kv_ops->unlock_read(module);
 
        return ret;
 }
index 70ab7880090434d4e3e3cc91254d2bfabe750da6..7e95437e79e924b7fb35169733c04531fb8b7563 100644 (file)
@@ -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);
@@ -1529,6 +1529,8 @@ static int ltdb_sequence_number(struct ltdb_context *ctx,
        struct ldb_context *ldb;
        struct ldb_module *module = ctx->module;
        struct ldb_request *req = ctx->req;
+       void *data = ldb_module_get_private(module);
+       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
        TALLOC_CTX *tmp_ctx = NULL;
        struct ldb_seqnum_request *seq;
        struct ldb_seqnum_result *res;
@@ -1547,7 +1549,7 @@ static int ltdb_sequence_number(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;
        }
 
@@ -1609,7 +1611,8 @@ static int ltdb_sequence_number(struct ltdb_context *ctx,
 
 done:
        talloc_free(tmp_ctx);
-       ltdb_unlock_read(module);
+
+       ltdb->kv_ops->unlock_read(module);
        return ret;
 }
 
@@ -1872,6 +1875,21 @@ static int ltdb_init_rootdse(struct ldb_module *module)
        return LDB_SUCCESS;
 }
 
+
+static int generic_lock_read(struct ldb_module *module)
+{
+       void *data = ldb_module_get_private(module);
+       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+       return ltdb->kv_ops->lock_read(module);
+}
+
+static int generic_unlock_read(struct ldb_module *module)
+{
+       void *data = ldb_module_get_private(module);
+       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+       return ltdb->kv_ops->unlock_read(module);
+}
+
 static const struct ldb_module_ops ltdb_ops = {
        .name              = "tdb",
        .init_context      = ltdb_init_rootdse,
@@ -1885,8 +1903,8 @@ static const struct ldb_module_ops ltdb_ops = {
        .end_transaction   = ltdb_end_trans,
        .prepare_commit    = ltdb_prepare_commit,
        .del_transaction   = ltdb_del_trans,
-       .read_lock         = ltdb_lock_read,
-       .read_unlock       = ltdb_unlock_read,
+       .read_lock         = generic_lock_read,
+       .read_unlock       = generic_unlock_read,
 };
 
 /*
@@ -1905,7 +1923,6 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
         * We hold locks, so we must use a private event context
         * on each returned handle
         */
-
        ldb_set_require_private_event_context(ldb);
 
        /* parse the url */
index 0ffe8458e86d0eae39b1d89dbdb20280d2e906b5..4d4805b98efb1818d1a457963211ca4fbf9114f2 100644 (file)
@@ -165,8 +165,6 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
 int ltdb_search(struct ltdb_context *ctx);
 
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c  */
-int ltdb_lock_read(struct ldb_module *module);
-int ltdb_unlock_read(struct ldb_module *module);
 /* 
  * Determine if this key could hold a record.  We allow the new GUID
  * index, the old DN index and a possible future ID=
@@ -185,6 +183,7 @@ int ltdb_idx_to_key(struct ldb_module *module,
                    TALLOC_CTX *mem_ctx,
                    const struct ldb_val *idx_val,
                    TDB_DATA *key);
+TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
 int ltdb_delete_noindex(struct ldb_module *module,