svn commit: samba r11353 - in branches/SAMBA_4_0/source/lib/ldb: common ldb_tdb

tridge at samba.org tridge at samba.org
Fri Oct 28 03:43:40 GMT 2005


Author: tridge
Date: 2005-10-28 03:43:39 +0000 (Fri, 28 Oct 2005)
New Revision: 11353

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11353

Log:

a bit of an improvement to the ldb_tdb error handling

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2005-10-28 03:40:10 UTC (rev 11352)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb.c	2005-10-28 03:43:39 UTC (rev 11353)
@@ -223,6 +223,24 @@
 }
 
 /*
+  check for an error return from an op 
+  if an op fails, but has not setup an error string, then setup one now
+*/
+static int ldb_op_finish(struct ldb_context *ldb, int status)
+{
+	if (status == LDB_SUCCESS) {
+		return ldb_transaction_commit(ldb);
+	}
+	if (ldb->err_string == NULL) {
+		/* no error string was setup by the backend */
+		ldb_set_errstring(ldb->modules, 
+				  talloc_asprintf(ldb, "ldb error %d", status));
+	}
+	ldb_transaction_cancel(ldb);
+	return status;
+}
+
+/*
   add a record to the database. Will fail if a record with the given class and key
   already exists
 */
@@ -244,11 +262,7 @@
 		if (status != LDB_SUCCESS) return status;
 
 		status = module->ops->add_record(module, message);
-		if (status != LDB_SUCCESS) {
-			ldb_transaction_cancel(ldb);
-			return status;
-		}
-		return ldb_transaction_commit(ldb);
+		return ldb_op_finish(ldb, status);
 	}
 
 	return module->ops->add_record(module, message);
@@ -275,11 +289,7 @@
 		if (status != LDB_SUCCESS) return status;
 
 		status = module->ops->modify_record(module, message);
-		if (status != LDB_SUCCESS) {
-			ldb_transaction_cancel(ldb);
-			return status;
-		}
-		return ldb_transaction_commit(ldb);
+		return ldb_op_finish(ldb, status);
 	}
 
 	return module->ops->modify_record(module, message);
@@ -303,11 +313,7 @@
 		if (status != LDB_SUCCESS) return status;
 
 		status = module->ops->delete_record(module, dn);
-		if (status != LDB_SUCCESS) {
-			ldb_transaction_cancel(ldb);
-			return status;
-		}
-		return ldb_transaction_commit(ldb);
+		return ldb_op_finish(ldb, status);
 	}
 
 	return module->ops->delete_record(module, dn);
@@ -330,11 +336,7 @@
 		if (status != LDB_SUCCESS) return status;
 
 		status = module->ops->rename_record(module, olddn, newdn);
-		if (status != LDB_SUCCESS) {
-			ldb_transaction_cancel(ldb);
-			return status;
-		}
-		return ldb_transaction_commit(ldb);
+		return ldb_op_finish(ldb, status);
 	}
 
 	return module->ops->rename_record(module, olddn, newdn);

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c	2005-10-28 03:40:10 UTC (rev 11352)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c	2005-10-28 03:43:39 UTC (rev 11353)
@@ -1119,14 +1119,12 @@
 	/* first traverse the database deleting any @INDEX records */
 	ret = tdb_traverse(ltdb->tdb, delete_index, NULL);
 	if (ret == -1) {
-		errno = EIO;
 		return -1;
 	}
 
 	/* now traverse adding any indexes for normal LDB records */
 	ret = tdb_traverse(ltdb->tdb, re_index, module);
 	if (ret == -1) {
-		errno = EIO;
 		return -1;
 	}
 

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2005-10-28 03:40:10 UTC (rev 11352)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_tdb.c	2005-10-28 03:43:39 UTC (rev 11353)
@@ -41,7 +41,38 @@
 #include "ldb/include/ldb_private.h"
 #include "ldb/ldb_tdb/ldb_tdb.h"
 
+
 /*
+  map a tdb error code to a ldb error code
+*/
+static int ltdb_err_map(enum TDB_ERROR tdb_code)
+{
+	switch (tdb_code) {
+	case TDB_SUCCESS:
+		return LDB_SUCCESS;
+	case TDB_ERR_CORRUPT:
+	case TDB_ERR_OOM:
+	case TDB_ERR_EINVAL:
+		return LDB_ERR_OPERATIONS_ERROR;
+	case TDB_ERR_IO:
+		return LDB_ERR_PROTOCOL_ERROR;
+	case TDB_ERR_LOCK:
+	case TDB_ERR_NOLOCK:
+		return LDB_ERR_BUSY;
+	case TDB_ERR_LOCK_TIMEOUT:
+		return LDB_ERR_TIME_LIMIT_EXCEEDED;
+	case TDB_ERR_EXISTS:
+		return LDB_ERR_ENTRY_ALREADY_EXISTS;
+	case TDB_ERR_NOEXIST:
+		return LDB_ERR_NO_SUCH_OBJECT;
+	case TDB_ERR_RDONLY:
+		return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+	}
+	return LDB_ERR_OTHER;
+}
+
+
+/*
   form a TDB_DATA for a record key
   caller frees
 
@@ -168,7 +199,7 @@
 
 	ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs);
 	if (ret == -1) {
-		ret = LDB_ERR_OTHER;
+		ret = ltdb_err_map(tdb_error(ltdb->tdb));
 		goto done;
 	}
 	
@@ -229,7 +260,9 @@
 	ret = tdb_delete(ltdb->tdb, tdb_key);
 	talloc_free(tdb_key.dptr);
 
-	if (ret != 0) ret = LDB_ERR_OTHER;
+	if (ret != 0) {
+		ret = ltdb_err_map(tdb_error(ltdb->tdb));
+	}
 
 	return ret;
 }
@@ -450,7 +483,7 @@
 	tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
 	if (!tdb_data.dptr) {
 		talloc_free(tdb_key.dptr);
-		return LDB_ERR_OTHER;
+		return ltdb_err_map(tdb_error(ltdb->tdb));
 	}
 
 	msg2 = talloc(tdb_key.dptr, struct ldb_message);
@@ -672,7 +705,7 @@
 	struct ltdb_private *ltdb = module->private_data;
 
 	if (tdb_transaction_start(ltdb->tdb) != 0) {
-		return LDB_ERR_OPERATIONS_ERROR;
+		return ltdb_err_map(tdb_error(ltdb->tdb));
 	}
 
 	return LDB_SUCCESS;
@@ -683,7 +716,7 @@
 	struct ltdb_private *ltdb = module->private_data;
 
 	if (tdb_transaction_commit(ltdb->tdb) != 0) {
-		return LDB_ERR_OPERATIONS_ERROR;
+		return ltdb_err_map(tdb_error(ltdb->tdb));
 	}
 
 	return LDB_SUCCESS;
@@ -694,7 +727,7 @@
 	struct ltdb_private *ltdb = module->private_data;
 
 	if (tdb_transaction_cancel(ltdb->tdb) != 0) {
-		return LDB_ERR_OPERATIONS_ERROR;
+		return ltdb_err_map(tdb_error(ltdb->tdb));
 	}
 
 	return LDB_SUCCESS;



More information about the samba-cvs mailing list