dbwrap ctdb: add a partial mapping from tdb_error to NTSTATUS and use it for store.
authorMichael Adam <obnox@samba.org>
Wed, 6 Aug 2008 20:22:23 +0000 (22:22 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 13 Aug 2008 09:54:07 +0000 (11:54 +0200)
Michael
(This used to be commit eaf76c751f9bde2843174b400c109304831df83e)

source3/lib/dbwrap_ctdb.c

index 1cccecbad93efd6035dc2fa5f44291aa4a1c1292..69b3631c04d9fb9876a758879f963e2c997a1ea7 100644 (file)
@@ -38,6 +38,26 @@ static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx,
                                               TDB_DATA key,
                                               bool persistent);
 
+static NTSTATUS tdb_error_to_ntstatus(struct tdb_context *tdb)
+{
+       NTSTATUS status;
+       enum TDB_ERROR tret = tdb_error(tdb);
+
+       switch (tret) {
+       case TDB_ERR_EXISTS:
+               status = NT_STATUS_OBJECT_NAME_COLLISION;
+               break;
+       case TDB_ERR_NOEXIST:
+               status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               break;
+       default:
+               status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+               break;
+       }
+
+       return status;
+}
+
 static NTSTATUS db_ctdb_store(struct db_record *rec, TDB_DATA data, int flag)
 {
        struct db_ctdb_rec *crec = talloc_get_type_abort(
@@ -58,7 +78,8 @@ static NTSTATUS db_ctdb_store(struct db_record *rec, TDB_DATA data, int flag)
 
        SAFE_FREE(cdata.dptr);
 
-       return (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION;
+       return (ret == 0) ? NT_STATUS_OK
+                         : tdb_error_to_ntstatus(crec->ctdb_ctx->wtdb->tdb);
 }
 
 
@@ -125,8 +146,10 @@ static NTSTATUS db_ctdb_store_persistent(struct db_record *rec, TDB_DATA data, i
                if (NT_STATUS_IS_OK(status)) {
                        ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key,
                                        cdata, TDB_REPLACE);
-                       status = (ret == 0) ? NT_STATUS_OK
-                                           : NT_STATUS_INTERNAL_DB_CORRUPTION;
+                       status = (ret == 0)
+                                       ? NT_STATUS_OK
+                                       : tdb_error_to_ntstatus(
+                                               crec->ctdb_ctx->wtdb->tdb);
                }
 
                /*