mirror of
https://github.com/samba-team/samba.git
synced 2025-11-20 08:23:50 +03:00
r3897: add a locking infrastructure
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
9fca748fe3
commit
a99c0adb09
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user