From 0f20ffbcbd41895dd073051539411f7194ae8224 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 15 Feb 2012 14:57:01 +0100 Subject: s3-dbwrap: Add dbwrap_db_id This returns a blob uniquely identifying the database --- source3/lib/dbwrap/dbwrap.c | 5 +++++ source3/lib/dbwrap/dbwrap.h | 1 + source3/lib/dbwrap/dbwrap_ctdb.c | 11 +++++++++++ source3/lib/dbwrap/dbwrap_private.h | 1 + source3/lib/dbwrap/dbwrap_rbt.c | 7 +++++++ source3/lib/dbwrap/dbwrap_tdb.c | 25 +++++++++++++++++++++++++ 6 files changed, 50 insertions(+) (limited to 'source3') diff --git a/source3/lib/dbwrap/dbwrap.c b/source3/lib/dbwrap/dbwrap.c index c78ee747a7..82b1c54ac4 100644 --- a/source3/lib/dbwrap/dbwrap.c +++ b/source3/lib/dbwrap/dbwrap.c @@ -351,3 +351,8 @@ int dbwrap_transaction_cancel(struct db_context *db) { return db->transaction_cancel(db); } + +void dbwrap_db_id(struct db_context *db, const uint8_t **id, size_t *idlen) +{ + db->id(db, id, idlen); +} diff --git a/source3/lib/dbwrap/dbwrap.h b/source3/lib/dbwrap/dbwrap.h index 9981b6dfd9..6fd5999a9d 100644 --- a/source3/lib/dbwrap/dbwrap.h +++ b/source3/lib/dbwrap/dbwrap.h @@ -62,6 +62,7 @@ int dbwrap_get_flags(struct db_context *db); int dbwrap_transaction_start(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); /* The following definitions come from lib/dbwrap_util.c */ diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c index 3d08d1c86f..0454e62e69 100644 --- a/source3/lib/dbwrap/dbwrap_ctdb.c +++ b/source3/lib/dbwrap/dbwrap_ctdb.c @@ -1490,6 +1490,16 @@ static int db_ctdb_get_flags(struct db_context *db) return tdb_get_flags(ctx->wtdb->tdb); } +static void db_ctdb_id(struct db_context *db, const uint8_t **id, + size_t *idlen) +{ + struct db_ctdb_ctx *ctx = talloc_get_type_abort( + db->private_data, struct db_ctdb_ctx); + + *id = (uint8_t *)&ctx->db_id; + *idlen = sizeof(ctx->db_id); +} + struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, @@ -1599,6 +1609,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx, result->transaction_start = db_ctdb_transaction_start; result->transaction_commit = db_ctdb_transaction_commit; result->transaction_cancel = db_ctdb_transaction_cancel; + result->id = db_ctdb_id; 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 f95e305a00..b24e3b370c 100644 --- a/source3/lib/dbwrap/dbwrap_private.h +++ b/source3/lib/dbwrap/dbwrap_private.h @@ -58,6 +58,7 @@ struct db_context { void *private_data); int (*exists)(struct db_context *db,TDB_DATA key); int (*wipe)(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; bool persistent; diff --git a/source3/lib/dbwrap/dbwrap_rbt.c b/source3/lib/dbwrap/dbwrap_rbt.c index 95cd3e82e8..453efca799 100644 --- a/source3/lib/dbwrap/dbwrap_rbt.c +++ b/source3/lib/dbwrap/dbwrap_rbt.c @@ -408,6 +408,12 @@ static int db_rbt_trans_dummy(struct db_context *db) return 0; } +static void db_rbt_id(struct db_context *db, const uint8_t **id, size_t *idlen) +{ + *id = (uint8_t *)db; + *idlen = sizeof(db); +} + struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx) { struct db_context *result; @@ -437,6 +443,7 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx) result->wipe = db_rbt_wipe; result->parse_record = db_rbt_parse_record; result->lock_order = 0; + result->id = db_rbt_id; return result; } diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c index 59ed7910f7..e1b26e4e09 100644 --- a/source3/lib/dbwrap/dbwrap_tdb.c +++ b/source3/lib/dbwrap/dbwrap_tdb.c @@ -23,9 +23,15 @@ #include "dbwrap/dbwrap_tdb.h" #include "lib/tdb_wrap/tdb_wrap.h" #include "util_tdb.h" +#include "system/filesys.h" struct db_tdb_ctx { struct tdb_wrap *wtdb; + + struct { + dev_t dev; + ino_t ino; + } id; }; static NTSTATUS db_tdb_store(struct db_record *rec, TDB_DATA data, int flag); @@ -366,6 +372,14 @@ static int db_tdb_transaction_cancel(struct db_context *db) return 0; } +static void db_tdb_id(struct db_context *db, const uint8_t **id, size_t *idlen) +{ + struct db_tdb_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb_ctx); + *id = (uint8_t *)&db_ctx->id; + *idlen = sizeof(db_ctx->id); +} + struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *name, @@ -375,6 +389,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, { struct db_context *result = NULL; struct db_tdb_ctx *db_tdb; + struct stat st; result = talloc_zero(mem_ctx, struct db_context); if (result == NULL) { @@ -396,6 +411,15 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, goto fail; } + ZERO_STRUCT(db_tdb->id); + + if (fstat(tdb_fd(db_tdb->wtdb->tdb), &st) == -1) { + DEBUG(3, ("fstat failed: %s\n", strerror(errno))); + goto fail; + } + db_tdb->id.dev = st.st_dev; + db_tdb->id.ino = st.st_ino; + result->fetch_locked = db_tdb_fetch_locked; result->try_fetch_locked = db_tdb_try_fetch_locked; result->traverse = db_tdb_traverse; @@ -409,6 +433,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, result->transaction_cancel = db_tdb_transaction_cancel; result->exists = db_tdb_exists; result->wipe = db_tdb_wipe; + result->id = db_tdb_id; return result; fail: -- cgit