summaryrefslogtreecommitdiff
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
parent7e3503e2770a0473cb4f7d8d45b27cbee766d9fa (diff)
downloadsamba-a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb.tar.gz
samba-a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb.tar.bz2
samba-a4de8cd6a5a882a8d49fdb4b0e625ffdc6b401bb.zip
r3897: add a locking infrastructure
(This used to be commit a99c0adb09e2bc77b876d23cb2d0711ccffd83ca)
-rw-r--r--source4/lib/ldb/common/ldb_modules.c16
-rw-r--r--source4/lib/ldb/include/ldb_private.h4
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c31
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c50
-rw-r--r--source4/lib/ldb/modules/skel.c14
-rw-r--r--source4/lib/ldb/modules/timestamps.c14
6 files changed, 111 insertions, 18 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 1a6a334b8d..71ec3fdc00 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -250,6 +250,22 @@ int ldb_next_rename_record(struct ldb_module *module, const char *olddn, const c
return module->next->ops->rename_record(module->next, olddn, newdn);
}
+int ldb_next_named_lock(struct ldb_module *module, const char *lockname)
+{
+ if (!module->next) {
+ return -1;
+ }
+ return module->next->ops->named_lock(module->next, lockname);
+}
+
+int ldb_next_named_unlock(struct ldb_module *module, const char *lockname)
+{
+ if (!module->next) {
+ return -1;
+ }
+ return module->next->ops->named_unlock(module->next, lockname);
+}
+
const char *ldb_next_errstring(struct ldb_module *module)
{
if (!module->next) {
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index dfd388b8c6..720d8928dd 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -63,6 +63,8 @@ struct ldb_module_ops {
int (*modify_record)(struct ldb_module *, const struct ldb_message *);
int (*delete_record)(struct ldb_module *, const char *);
int (*rename_record)(struct ldb_module *, const char *, const char *);
+ int (*named_lock)(struct ldb_module *, const char *);
+ int (*named_unlock)(struct ldb_module *, const char *);
const char * (*errstring)(struct ldb_module *);
/* this is called when the alloc ops changes to ensure we
@@ -101,6 +103,8 @@ int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *mes
int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message);
int ldb_next_delete_record(struct ldb_module *module, const char *dn);
int ldb_next_rename_record(struct ldb_module *module, const char *olddn, const char *newdn);
+int ldb_next_named_lock(struct ldb_module *module, const char *lockname);
+int ldb_next_named_unlock(struct ldb_module *module, const char *lockname);
const char *ldb_next_errstring(struct ldb_module *module);
void ldb_next_cache_free(struct ldb_module *module);
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 85604dfe76..d9640f247a 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -496,6 +496,35 @@ static int lldb_modify(struct ldb_module *module, const struct ldb_message *msg)
return ret;
}
+static int lldb_lock(struct ldb_module *module, const char *lockname)
+{
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
+ int ret = 0;
+
+ if (lockname == NULL) {
+ return -1;
+ }
+
+ /* TODO implement a local locking mechanism here */
+
+ return ret;
+}
+
+static int lldb_unlock(struct ldb_module *module, const char *lockname)
+{
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
+ int ret = 0;
+
+ if (lockname == NULL) {
+ return -1;
+ }
+
+ /* TODO implement a local unlocking mechanism here */
+
+ return ret;
+}
/*
return extended error information
@@ -516,6 +545,8 @@ static const struct ldb_module_ops lldb_ops = {
lldb_modify,
lldb_delete,
lldb_rename,
+ lldb_lock,
+ lldb_unlock,
lldb_errstring
};
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
};
diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c
index 331a2de5e4..3581969c18 100644
--- a/source4/lib/ldb/modules/skel.c
+++ b/source4/lib/ldb/modules/skel.c
@@ -80,6 +80,18 @@ static int skel_rename_record(struct ldb_module *module, const char *olddn, cons
return ldb_next_rename_record(module, olddn, newdn);
}
+/* named_lock */
+static const char *skel_named_lock(struct ldb_module *module, const char *lockname)
+{
+ return ldb_next_named_lock(module, lockname);
+}
+
+/* named_unlock */
+static const char *skel_named_unlock(struct ldb_module *module, const char *lockname)
+{
+ return ldb_next_named_unlock(module, lockname);
+}
+
/* return extended error information */
static const char *skel_errstring(struct ldb_module *module)
{
@@ -100,6 +112,8 @@ static const struct ldb_module_ops skel_ops = {
skel_modify_record,
skel_delete_record,
skel_rename_record,
+ skel_named_lock,
+ skel_named_unlock,
skel_errstring,
skel_cache_free
};
diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c
index 521c59d241..fde87ef4a6 100644
--- a/source4/lib/ldb/modules/timestamps.c
+++ b/source4/lib/ldb/modules/timestamps.c
@@ -230,6 +230,18 @@ static int timestamps_rename_record(struct ldb_module *module, const char *olddn
return ldb_next_rename_record(module, olddn, newdn);
}
+static int timestamps_lock(struct ldb_module *module, const char *lockname)
+{
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_lock\n");
+ return ldb_next_named_lock(module, lockname);
+}
+
+static int timestamps_unlock(struct ldb_module *module, const char *lockname)
+{
+ ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_unlock\n");
+ return ldb_next_named_unlock(module, lockname);
+}
+
/* return extended error information */
static const char *timestamps_errstring(struct ldb_module *module)
{
@@ -252,6 +264,8 @@ static const struct ldb_module_ops timestamps_ops = {
timestamps_modify_record,
timestamps_delete_record,
timestamps_rename_record,
+ timestamps_lock,
+ timestamps_unlock,
timestamps_errstring,
timestamps_cache_free
};