summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-22 15:07:43 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-22 07:35:17 +0200
commit431667b47c0eac3069ba1e643996619ab61975e5 (patch)
tree5599a4411b439b1f87086b6fb0cdc9cca96ee67b /lib
parent9d97bf3f47a591a71e96cad8a87ef13a2b277c9c (diff)
downloadsamba-431667b47c0eac3069ba1e643996619ab61975e5.tar.gz
samba-431667b47c0eac3069ba1e643996619ab61975e5.tar.bz2
samba-431667b47c0eac3069ba1e643996619ab61975e5.zip
dbwrap: add dbwrap_check() function.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib')
-rw-r--r--lib/dbwrap/dbwrap.c21
-rw-r--r--lib/dbwrap/dbwrap.h1
-rw-r--r--lib/dbwrap/dbwrap_private.h1
-rw-r--r--lib/dbwrap/dbwrap_tdb.c8
4 files changed, 31 insertions, 0 deletions
diff --git a/lib/dbwrap/dbwrap.c b/lib/dbwrap/dbwrap.c
index a393960428..d46044f0c4 100644
--- a/lib/dbwrap/dbwrap.c
+++ b/lib/dbwrap/dbwrap.c
@@ -50,6 +50,19 @@ static int dbwrap_fallback_wipe(struct db_context *db)
return NT_STATUS_IS_OK(status) ? 0 : -1;
}
+static int do_nothing(struct db_record *rec, void *unused)
+{
+ return 0;
+}
+
+/*
+ * Fallback check operation: just traverse.
+ */
+static int dbwrap_fallback_check(struct db_context *db)
+{
+ NTSTATUS status = dbwrap_traverse_read(db, do_nothing, NULL, NULL);
+ return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
/*
* Wrapper functions for the backend methods
@@ -367,6 +380,14 @@ int dbwrap_wipe(struct db_context *db)
return db->wipe(db);
}
+int dbwrap_check(struct db_context *db)
+{
+ if (db->check == NULL) {
+ return dbwrap_fallback_check(db);
+ }
+ return db->check(db);
+}
+
int dbwrap_get_seqnum(struct db_context *db)
{
return db->get_seqnum(db);
diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 6c789e91a4..23a43da019 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -69,6 +69,7 @@ NTSTATUS dbwrap_parse_record(struct db_context *db, TDB_DATA key,
void *private_data),
void *private_data);
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);
int dbwrap_transaction_commit(struct db_context *db);
diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h
index 7f9904c8a5..af8374dbc9 100644
--- a/lib/dbwrap/dbwrap_private.h
+++ b/lib/dbwrap/dbwrap_private.h
@@ -56,6 +56,7 @@ struct db_context {
void *private_data);
int (*exists)(struct db_context *db,TDB_DATA key);
int (*wipe)(struct db_context *db);
+ int (*check)(struct db_context *db);
void (*id)(struct db_context *db, const uint8_t **id, size_t *idlen);
void *private_data;
enum dbwrap_lock_order lock_order;
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index 1452ff7e8a..fb6841bcb6 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -187,6 +187,13 @@ static int db_tdb_wipe(struct db_context *db)
return tdb_wipe_all(ctx->wtdb->tdb);
}
+static int db_tdb_check(struct db_context *db)
+{
+ struct db_tdb_ctx *ctx = talloc_get_type_abort(
+ db->private_data, struct db_tdb_ctx);
+ return tdb_check(ctx->wtdb->tdb, NULL, NULL);
+}
+
struct db_tdb_parse_state {
void (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data);
@@ -434,6 +441,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
result->exists = db_tdb_exists;
result->wipe = db_tdb_wipe;
result->id = db_tdb_id;
+ result->check = db_tdb_check;
result->stored_callback = NULL;
return result;