summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-22 15:07:44 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-22 07:35:17 +0200
commit41f799d877961d095401a628307e0c690dfbc124 (patch)
tree5687f03d0009a3f379375a3d52087afbb14591e2 /lib
parentf6eb187fdab6b8088bb065e418fe604c4eba7751 (diff)
downloadsamba-41f799d877961d095401a628307e0c690dfbc124.tar.gz
samba-41f799d877961d095401a628307e0c690dfbc124.tar.bz2
samba-41f799d877961d095401a628307e0c690dfbc124.zip
dbwrap: dbwrap_transaction_start_nonblock().
Implemented for ntdb and tdb; falls back to the blocking variant for others. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib')
-rw-r--r--lib/dbwrap/dbwrap.c10
-rw-r--r--lib/dbwrap/dbwrap.h1
-rw-r--r--lib/dbwrap/dbwrap_private.h1
-rw-r--r--lib/dbwrap/dbwrap_tdb.c14
4 files changed, 26 insertions, 0 deletions
diff --git a/lib/dbwrap/dbwrap.c b/lib/dbwrap/dbwrap.c
index 835bd599ef..afb069221e 100644
--- a/lib/dbwrap/dbwrap.c
+++ b/lib/dbwrap/dbwrap.c
@@ -425,6 +425,16 @@ int dbwrap_transaction_start(struct db_context *db)
return db->transaction_start(db);
}
+NTSTATUS dbwrap_transaction_start_nonblock(struct db_context *db)
+{
+ if (db->transaction_start_nonblock) {
+ return db->transaction_start_nonblock(db);
+ } else {
+ return dbwrap_transaction_start(db) == 0 ? NT_STATUS_OK
+ : NT_STATUS_UNSUCCESSFUL;
+ }
+}
+
int dbwrap_transaction_commit(struct db_context *db)
{
return db->transaction_commit(db);
diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 0b19396b98..366e657680 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -77,6 +77,7 @@ int dbwrap_wipe(struct db_context *db);
int dbwrap_check(struct db_context *db);
int dbwrap_get_seqnum(struct db_context *db);
int dbwrap_transaction_start(struct db_context *db);
+NTSTATUS dbwrap_transaction_start_nonblock(struct db_context *db);
int dbwrap_transaction_commit(struct db_context *db);
int dbwrap_transaction_cancel(struct db_context *db);
void dbwrap_db_id(struct db_context *db, const uint8_t **id, size_t *idlen);
diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h
index dfd365dab2..b0090e39ad 100644
--- a/lib/dbwrap/dbwrap_private.h
+++ b/lib/dbwrap/dbwrap_private.h
@@ -52,6 +52,7 @@ struct db_context {
void *private_data);
int (*get_seqnum)(struct db_context *db);
int (*transaction_start)(struct db_context *db);
+ NTSTATUS (*transaction_start_nonblock)(struct db_context *db);
int (*transaction_commit)(struct db_context *db);
int (*transaction_cancel)(struct db_context *db);
NTSTATUS (*parse_record)(struct db_context *db, TDB_DATA key,
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index 99ea62a3a1..883c7f3c9c 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -374,6 +374,19 @@ static int db_tdb_transaction_start(struct db_context *db)
return tdb_transaction_start(db_ctx->wtdb->tdb) ? -1 : 0;
}
+static NTSTATUS db_tdb_transaction_start_nonblock(struct db_context *db)
+{
+ struct db_tdb_ctx *db_ctx =
+ talloc_get_type_abort(db->private_data, struct db_tdb_ctx);
+ int ret;
+
+ ret = tdb_transaction_start_nonblock(db_ctx->wtdb->tdb);
+ if (ret != 0) {
+ return map_nt_error_from_tdb(tdb_error(db_ctx->wtdb->tdb));
+ }
+ return NT_STATUS_OK;
+}
+
static int db_tdb_transaction_commit(struct db_context *db)
{
struct db_tdb_ctx *db_ctx =
@@ -452,6 +465,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
result->get_seqnum = db_tdb_get_seqnum;
result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
result->transaction_start = db_tdb_transaction_start;
+ result->transaction_start_nonblock = db_tdb_transaction_start_nonblock;
result->transaction_commit = db_tdb_transaction_commit;
result->transaction_cancel = db_tdb_transaction_cancel;
result->exists = db_tdb_exists;