summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-09-24 15:42:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:38:52 -0500
commit63b43dd12fb579aaaccedd07aaa630cb1cd7aa88 (patch)
treed54cc9e41c4410c2a2e42f7479ff52a1fa0c156b /source4/lib/ldb/common
parent70b52b02a77c695d32aa57daaeb5689cd6857eba (diff)
downloadsamba-63b43dd12fb579aaaccedd07aaa630cb1cd7aa88.tar.gz
samba-63b43dd12fb579aaaccedd07aaa630cb1cd7aa88.tar.bz2
samba-63b43dd12fb579aaaccedd07aaa630cb1cd7aa88.zip
r10477: expose transactions outside ldb and change the API once more
do not autostart transactions on ldb operations if a transaction is already in place test transactions on winsdb all my tests passes so far tridge please confirm this is ok for you (This used to be commit c2bb2a36bdbe0ec7519697a9a9ba7526a0defac2)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c104
-rw-r--r--source4/lib/ldb/common/ldb_modules.c12
-rw-r--r--source4/lib/ldb/common/ldb_msg.c2
3 files changed, 88 insertions, 30 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index a00c2481d8..a743b2f584 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -93,17 +93,17 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
return LDB_ERR_OTHER;
}
- if (ret != LDB_ERR_SUCCESS) {
+ if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
return ret;
}
- if (ldb_load_modules(ldb, options) != LDB_ERR_SUCCESS) {
+ if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for '%s'\n", url);
return LDB_ERR_OTHER;
}
- return LDB_ERR_SUCCESS;
+ return LDB_SUCCESS;
}
static void ldb_reset_err_string(struct ldb_context *ldb)
@@ -117,17 +117,45 @@ static void ldb_reset_err_string(struct ldb_context *ldb)
/*
start a transaction
*/
-static int ldb_start_trans(struct ldb_context *ldb)
+int ldb_transaction_start(struct ldb_context *ldb)
{
- return ldb->modules->ops->start_transaction(ldb->modules);
+ ldb->transaction_active++;
+
+ ldb_reset_err_string(ldb);
+
+ return ldb->modules->ops->start_transaction(ldb->modules);
}
/*
- end a transaction
+ commit a transaction
*/
-static int ldb_end_trans(struct ldb_context *ldb, int status)
+int ldb_transaction_commit(struct ldb_context *ldb)
{
- return ldb->modules->ops->end_transaction(ldb->modules, status);
+ if (ldb->transaction_active > 0) {
+ ldb->transaction_active--;
+ } else {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ldb_reset_err_string(ldb);
+
+ return ldb->modules->ops->end_transaction(ldb->modules);
+}
+
+/*
+ cancel a transaction
+*/
+int ldb_transaction_cancel(struct ldb_context *ldb)
+{
+ if (ldb->transaction_active > 0) {
+ ldb->transaction_active--;
+ } else {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ ldb_reset_err_string(ldb);
+
+ return ldb->modules->ops->del_transaction(ldb->modules);
}
/*
@@ -180,13 +208,18 @@ int ldb_add(struct ldb_context *ldb,
ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
- if (status != LDB_ERR_SUCCESS) return status;
+ if (status != LDB_SUCCESS) return status;
- status = ldb_start_trans(ldb);
- if (status != LDB_ERR_SUCCESS) return status;
+ if (! ldb->transaction_active) {
+ status = ldb_transaction_start(ldb);
+ if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->add_record(ldb->modules, message);
- return ldb_end_trans(ldb, status);
+ status = ldb->modules->ops->add_record(ldb->modules, message);
+ if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+ return ldb_transaction_commit(ldb);
+ }
+
+ return ldb->modules->ops->add_record(ldb->modules, message);
}
/*
@@ -200,13 +233,18 @@ int ldb_modify(struct ldb_context *ldb,
ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
- if (status != LDB_ERR_SUCCESS) return status;
+ if (status != LDB_SUCCESS) return status;
+
+ if (! ldb->transaction_active) {
+ status = ldb_transaction_start(ldb);
+ if (status != LDB_SUCCESS) return status;
- status = ldb_start_trans(ldb);
- if (status != LDB_ERR_SUCCESS) return status;
+ status = ldb->modules->ops->modify_record(ldb->modules, message);
+ if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+ return ldb_transaction_commit(ldb);
+ }
- status = ldb->modules->ops->modify_record(ldb->modules, message);
- return ldb_end_trans(ldb, status);
+ return ldb->modules->ops->modify_record(ldb->modules, message);
}
@@ -219,11 +257,16 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
ldb_reset_err_string(ldb);
- status = ldb_start_trans(ldb);
- if (status != LDB_ERR_SUCCESS) return status;
+ if (! ldb->transaction_active) {
+ status = ldb_transaction_start(ldb);
+ if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->delete_record(ldb->modules, dn);
- return ldb_end_trans(ldb, status);
+ status = ldb->modules->ops->delete_record(ldb->modules, dn);
+ if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+ return ldb_transaction_commit(ldb);
+ }
+
+ return ldb->modules->ops->delete_record(ldb->modules, dn);
}
/*
@@ -235,13 +278,20 @@ int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct
ldb_reset_err_string(ldb);
- status = ldb_start_trans(ldb);
- if (status != LDB_ERR_SUCCESS) return status;
+ if (! ldb->transaction_active) {
+ status = ldb_transaction_start(ldb);
+ if (status != LDB_SUCCESS) return status;
+
+ status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+ if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
+ return ldb_transaction_commit(ldb);
+ }
- status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
- return ldb_end_trans(ldb, status);
+ return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
}
+
+
/*
return extended error information
*/
@@ -269,7 +319,7 @@ int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value)
o->name = name;
o->value = value;
ldb->opaque = o;
- return LDB_ERR_SUCCESS;
+ return LDB_SUCCESS;
}
/*
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index e1f5b83083..6802cc8955 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -314,12 +314,20 @@ int ldb_next_start_trans(struct ldb_module *module)
return module->next->ops->start_transaction(module->next);
}
-int ldb_next_end_trans(struct ldb_module *module, int status)
+int ldb_next_end_trans(struct ldb_module *module)
{
if (!module->next) {
return -1;
}
- return module->next->ops->end_transaction(module->next, status);
+ return module->next->ops->end_transaction(module->next);
+}
+
+int ldb_next_del_trans(struct ldb_module *module)
+{
+ if (!module->next) {
+ return -1;
+ }
+ return module->next->ops->del_transaction(module->next);
}
void ldb_set_errstring(struct ldb_module *module, char *err_string)
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 1b26d7833b..c2f40f308a 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -527,5 +527,5 @@ int ldb_msg_sanity_check(const struct ldb_message *msg)
}
}
- return LDB_ERR_SUCCESS;
+ return LDB_SUCCESS;
}