summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-02-15 15:08:29 +0100
committerVolker Lendecke <vl@samba.org>2012-04-20 13:42:40 +0200
commit61c97506e8ccb878d06edae72f4216ad58b96a9b (patch)
tree385628abecd54ca285beac4441a567cadf5db9a9
parent8e5b11bc143e8532aeed504e47b881ce53411ce3 (diff)
downloadsamba-61c97506e8ccb878d06edae72f4216ad58b96a9b.tar.gz
samba-61c97506e8ccb878d06edae72f4216ad58b96a9b.tar.bz2
samba-61c97506e8ccb878d06edae72f4216ad58b96a9b.zip
s3-dbwrap: Add dbwrap_set_stored_callback
This is a per-db function that is called whenever some record is modified
-rw-r--r--source3/lib/dbwrap/dbwrap.c38
-rw-r--r--source3/lib/dbwrap/dbwrap.h5
-rw-r--r--source3/lib/dbwrap/dbwrap_ctdb.c1
-rw-r--r--source3/lib/dbwrap/dbwrap_private.h3
-rw-r--r--source3/lib/dbwrap/dbwrap_rbt.c1
-rw-r--r--source3/lib/dbwrap/dbwrap_tdb.c1
6 files changed, 47 insertions, 2 deletions
diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c
index 21d46ea895..14562bb6e4 100644
--- a/source3/lib/dbwrap/dbwrap.c
+++ b/source3/lib/dbwrap/dbwrap.c
@@ -67,12 +67,46 @@ TDB_DATA dbwrap_record_get_value(const struct db_record *rec)
NTSTATUS dbwrap_record_store(struct db_record *rec, TDB_DATA data, int flags)
{
- return rec->store(rec, data, flags);
+ NTSTATUS status;
+ struct db_context *db;
+
+ status = rec->store(rec, data, flags);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+ db = rec->db;
+ if (db->stored_callback != NULL) {
+ db->stored_callback(db, rec,
+ db->stored_callback_private_data);
+ }
+ return NT_STATUS_OK;
+}
+
+void dbwrap_set_stored_callback(
+ struct db_context *db,
+ void (*cb)(struct db_context *db, struct db_record *rec,
+ void *private_data),
+ void *private_data)
+{
+ db->stored_callback = cb;
+ db->stored_callback_private_data = private_data;
}
NTSTATUS dbwrap_record_delete(struct db_record *rec)
{
- return rec->delete_rec(rec);
+ NTSTATUS status;
+ struct db_context *db;
+
+ status = rec->delete_rec(rec);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+ db = rec->db;
+ if (db->stored_callback != NULL) {
+ db->stored_callback(db, rec,
+ db->stored_callback_private_data);
+ }
+ return NT_STATUS_OK;
}
struct dbwrap_lock_order_state {
diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h
index ff41e647ef..3304bcf4a4 100644
--- a/source3/lib/dbwrap/dbwrap.h
+++ b/source3/lib/dbwrap/dbwrap.h
@@ -38,6 +38,11 @@ struct db_record *dbwrap_try_fetch_locked(struct db_context *db,
TALLOC_CTX *mem_ctx,
TDB_DATA key);
struct db_context *dbwrap_record_get_db(struct db_record *rec);
+void dbwrap_set_stored_callback(
+ struct db_context *db,
+ void (*cb)(struct db_context *db, struct db_record *rec,
+ void *private_data),
+ void *private_data);
NTSTATUS dbwrap_delete(struct db_context *db, TDB_DATA key);
NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key,
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 0454e62e69..933cad5ebd 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1610,6 +1610,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
result->transaction_commit = db_ctdb_transaction_commit;
result->transaction_cancel = db_ctdb_transaction_cancel;
result->id = db_ctdb_id;
+ result->stored_callback = NULL;
DEBUG(3,("db_open_ctdb: opened database '%s' with dbid 0x%x\n",
name, db_ctdb->db_id));
diff --git a/source3/lib/dbwrap/dbwrap_private.h b/source3/lib/dbwrap/dbwrap_private.h
index 28da1add53..94993428a4 100644
--- a/source3/lib/dbwrap/dbwrap_private.h
+++ b/source3/lib/dbwrap/dbwrap_private.h
@@ -63,6 +63,9 @@ struct db_context {
void *private_data;
enum dbwrap_lock_order lock_order;
bool persistent;
+ void (*stored_callback)(struct db_context *db, struct db_record *rec,
+ void *private_data);
+ void *stored_callback_private_data;
};
#endif /* __DBWRAP_PRIVATE_H__ */
diff --git a/source3/lib/dbwrap/dbwrap_rbt.c b/source3/lib/dbwrap/dbwrap_rbt.c
index 453efca799..0d0fb02c9c 100644
--- a/source3/lib/dbwrap/dbwrap_rbt.c
+++ b/source3/lib/dbwrap/dbwrap_rbt.c
@@ -444,6 +444,7 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
result->parse_record = db_rbt_parse_record;
result->lock_order = 0;
result->id = db_rbt_id;
+ result->stored_callback = NULL;
return result;
}
diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c
index 9450be0e65..fbbe757ca3 100644
--- a/source3/lib/dbwrap/dbwrap_tdb.c
+++ b/source3/lib/dbwrap/dbwrap_tdb.c
@@ -436,6 +436,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->stored_callback = NULL;
return result;
fail: