summaryrefslogtreecommitdiff
path: root/source4/ntvfs/common/opendb_tdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/ntvfs/common/opendb_tdb.c')
-rw-r--r--source4/ntvfs/common/opendb_tdb.c59
1 files changed, 20 insertions, 39 deletions
diff --git a/source4/ntvfs/common/opendb_tdb.c b/source4/ntvfs/common/opendb_tdb.c
index ed8fb9032a..2047a0b314 100644
--- a/source4/ntvfs/common/opendb_tdb.c
+++ b/source4/ntvfs/common/opendb_tdb.c
@@ -40,9 +40,8 @@
#include "includes.h"
#include "system/filesys.h"
-#include "../lib/tdb_compat/tdb_compat.h"
+#include "lib/dbwrap/dbwrap.h"
#include "messaging/messaging.h"
-#include "lib/tdb_wrap/tdb_wrap.h"
#include "lib/messaging/irpc.h"
#include "librpc/gen_ndr/ndr_opendb.h"
#include "ntvfs/ntvfs.h"
@@ -52,7 +51,7 @@
#include "ntvfs/sysdep/sys_lease.h"
struct odb_context {
- struct tdb_wrap *w;
+ struct db_context *db;
struct ntvfs_context *ntvfs_ctx;
bool oplocks;
struct sys_lease_context *lease_ctx;
@@ -64,7 +63,7 @@ struct odb_context {
*/
struct odb_lock {
struct odb_context *odb;
- TDB_DATA key;
+ struct db_record *locked;
struct opendb_file file;
@@ -93,8 +92,9 @@ static struct odb_context *odb_tdb_init(TALLOC_CTX *mem_ctx,
return NULL;
}
- odb->w = cluster_tdb_tmp_open(odb, ntvfs_ctx->lp_ctx, "openfiles.tdb", TDB_DEFAULT);
- if (odb->w == NULL) {
+ odb->db = cluster_db_tmp_open(odb, ntvfs_ctx->lp_ctx,
+ "openfiles", TDB_DEFAULT);
+ if (odb->db == NULL) {
talloc_free(odb);
return NULL;
}
@@ -111,15 +111,6 @@ static struct odb_context *odb_tdb_init(TALLOC_CTX *mem_ctx,
return odb;
}
-/*
- destroy a lock on the database
-*/
-static int odb_lock_destructor(struct odb_lock *lck)
-{
- tdb_chainunlock(lck->odb->w->tdb, lck->key);
- return 0;
-}
-
static NTSTATUS odb_pull_record(struct odb_lock *lck, struct opendb_file *file);
/*
@@ -131,6 +122,7 @@ static struct odb_lock *odb_tdb_lock(TALLOC_CTX *mem_ctx,
{
struct odb_lock *lck;
NTSTATUS status;
+ TDB_DATA key;
lck = talloc(mem_ctx, struct odb_lock);
if (lck == NULL) {
@@ -138,22 +130,21 @@ static struct odb_lock *odb_tdb_lock(TALLOC_CTX *mem_ctx,
}
lck->odb = talloc_reference(lck, odb);
- lck->key.dptr = talloc_memdup(lck, file_key->data, file_key->length);
- lck->key.dsize = file_key->length;
- if (lck->key.dptr == NULL) {
+ key.dptr = talloc_memdup(lck, file_key->data, file_key->length);
+ key.dsize = file_key->length;
+ if (key.dptr == NULL) {
talloc_free(lck);
return NULL;
}
- if (tdb_chainlock(odb->w->tdb, lck->key) != 0) {
+ lck->locked = dbwrap_fetch_locked(odb->db, lck, key);
+ if (!lck->locked) {
talloc_free(lck);
return NULL;
}
ZERO_STRUCT(lck->can_open);
- talloc_set_destructor(lck, odb_lock_destructor);
-
status = odb_pull_record(lck, &lck->file);
if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
/* initialise a blank structure */
@@ -168,7 +159,8 @@ static struct odb_lock *odb_tdb_lock(TALLOC_CTX *mem_ctx,
static DATA_BLOB odb_tdb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck)
{
- return data_blob_talloc(mem_ctx, lck->key.dptr, lck->key.dsize);
+ TDB_DATA key = dbwrap_record_get_key(lck->locked);
+ return data_blob_talloc(mem_ctx, key.dptr, key.dsize);
}
@@ -233,13 +225,12 @@ static NTSTATUS share_conflict(struct opendb_entry *e1,
*/
static NTSTATUS odb_pull_record(struct odb_lock *lck, struct opendb_file *file)
{
- struct odb_context *odb = lck->odb;
TDB_DATA dbuf;
DATA_BLOB blob;
enum ndr_err_code ndr_err;
- dbuf = tdb_fetch_compat(odb->w->tdb, lck->key);
- if (dbuf.dptr == NULL) {
+ dbuf = dbwrap_record_get_value(lck->locked);
+ if (!dbuf.dptr) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
@@ -247,7 +238,6 @@ static NTSTATUS odb_pull_record(struct odb_lock *lck, struct opendb_file *file)
blob.length = dbuf.dsize;
ndr_err = ndr_pull_struct_blob(&blob, lck, file, (ndr_pull_flags_fn_t)ndr_pull_opendb_file);
- free(dbuf.dptr);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
return ndr_map_error2ntstatus(ndr_err);
}
@@ -260,18 +250,13 @@ static NTSTATUS odb_pull_record(struct odb_lock *lck, struct opendb_file *file)
*/
static NTSTATUS odb_push_record(struct odb_lock *lck, struct opendb_file *file)
{
- struct odb_context *odb = lck->odb;
TDB_DATA dbuf;
DATA_BLOB blob;
enum ndr_err_code ndr_err;
- int ret;
+ NTSTATUS status;
if (file->num_entries == 0) {
- ret = tdb_delete(odb->w->tdb, lck->key);
- if (ret != 0) {
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
- return NT_STATUS_OK;
+ return dbwrap_record_delete(lck->locked);
}
ndr_err = ndr_push_struct_blob(&blob, lck, file, (ndr_push_flags_fn_t)ndr_push_opendb_file);
@@ -282,13 +267,9 @@ static NTSTATUS odb_push_record(struct odb_lock *lck, struct opendb_file *file)
dbuf.dptr = blob.data;
dbuf.dsize = blob.length;
- ret = tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE);
+ status = dbwrap_record_store(lck->locked, dbuf, TDB_REPLACE);
data_blob_free(&blob);
- if (ret != 0) {
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
-
- return NT_STATUS_OK;
+ return status;
}
/*