summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2004-11-21 15:51:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:06:02 -0500
commita4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb (patch)
tree734f3b138f68ca776eedd437386ef4e7320a15b8 /source4/lib/ldb/ldb_tdb
parent7e3503e2770a0473cb4f7d8d45b27cbee766d9fa (diff)
downloadsamba-a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb.tar.gz
samba-a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb.tar.bz2
samba-a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb.zip
r3897: add a locking infrastructure
(This used to be commit a99c0adb09e2bc77b876d23cb2d0711ccffd83ca)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 5f6af43f94..4049900a23 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -40,6 +40,8 @@
#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#define LDBLOCK "INT_LDBLOCK"
+
/*
form a TDB_DATA for a record key
caller frees
@@ -122,14 +124,18 @@ failed:
/*
lock the database for write - currently a single lock is used
*/
-static int ltdb_lock(struct ldb_module *module)
+static int ltdb_lock(struct ldb_module *module, const char *lockname)
{
struct ldb_context *ldb = module->ldb;
struct ltdb_private *ltdb = module->private_data;
TDB_DATA key;
int ret;
- key = ltdb_key(module, "LDBLOCK");
+ if (lockname == NULL) {
+ return -1;
+ }
+
+ key = ltdb_key(module, lockname);
if (!key.dptr) {
return -1;
}
@@ -144,20 +150,26 @@ static int ltdb_lock(struct ldb_module *module)
/*
unlock the database after a ltdb_lock()
*/
-static void ltdb_unlock(struct ldb_module *module)
+static int ltdb_unlock(struct ldb_module *module, const char *lockname)
{
struct ldb_context *ldb = module->ldb;
struct ltdb_private *ltdb = module->private_data;
TDB_DATA key;
- key = ltdb_key(module, "LDBLOCK");
+ if (lockname == NULL) {
+ return -1;
+ }
+
+ key = ltdb_key(module, lockname);
if (!key.dptr) {
- return;
+ return -1;
}
tdb_chainunlock(ltdb->tdb, key);
ldb_free(ldb, key.dptr);
+
+ return 0;
}
@@ -231,12 +243,12 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
ltdb->last_err_string = NULL;
- if (ltdb_lock(module) != 0) {
+ if (ltdb_lock(module, LDBLOCK) != 0) {
return -1;
}
if (ltdb_cache_load(module) != 0) {
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return -1;
}
@@ -246,7 +258,7 @@ static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
ltdb_modified(module, msg->dn);
}
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return ret;
}
@@ -284,12 +296,12 @@ static int ltdb_delete(struct ldb_module *module, const char *dn)
ltdb->last_err_string = NULL;
- if (ltdb_lock(module) != 0) {
+ if (ltdb_lock(module, LDBLOCK) != 0) {
return -1;
}
if (ltdb_cache_load(module) != 0) {
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return -1;
}
@@ -316,11 +328,11 @@ static int ltdb_delete(struct ldb_module *module, const char *dn)
ltdb_modified(module, dn);
}
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return ret;
failed:
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return -1;
}
@@ -573,12 +585,12 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg)
ltdb->last_err_string = NULL;
- if (ltdb_lock(module) != 0) {
+ if (ltdb_lock(module, LDBLOCK) != 0) {
return -1;
}
if (ltdb_cache_load(module) != 0) {
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return -1;
}
@@ -588,7 +600,7 @@ static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg)
ltdb_modified(module, msg->dn);
}
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return ret;
}
@@ -606,7 +618,7 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char
ltdb->last_err_string = NULL;
- if (ltdb_lock(module) != 0) {
+ if (ltdb_lock(module, LDBLOCK) != 0) {
return -1;
}
@@ -641,11 +653,11 @@ static int ltdb_rename(struct ldb_module *module, const char *olddn, const char
ltdb->last_err_string = error_str;
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return ret;
failed:
- ltdb_unlock(module);
+ ltdb_unlock(module, LDBLOCK);
return -1;
}
@@ -692,6 +704,8 @@ static const struct ldb_module_ops ltdb_ops = {
ltdb_modify,
ltdb_delete,
ltdb_rename,
+ ltdb_lock,
+ ltdb_unlock,
ltdb_errstring,
ltdb_cache_free
};