From f6eb187fdab6b8088bb065e418fe604c4eba7751 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jun 2012 15:07:44 +0930 Subject: dbwrap: dbwrap_fetch_locked_timeout(). Implemented for ntdb and tdb; falls back to the non-timeout variant for others. Signed-off-by: Rusty Russell --- lib/dbwrap/dbwrap_tdb.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/dbwrap/dbwrap_tdb.c') diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c index fb6841bcb6..99ea62a3a1 100644 --- a/lib/dbwrap/dbwrap_tdb.c +++ b/lib/dbwrap/dbwrap_tdb.c @@ -158,6 +158,21 @@ static struct db_record *db_tdb_fetch_locked( return db_tdb_fetch_locked_internal(db, mem_ctx, key); } +static struct db_record *db_tdb_fetch_locked_timeout( + struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key, + unsigned int timeout) +{ + struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data, + struct db_tdb_ctx); + + db_tdb_log_key("Locking with timeout ", key); + if (tdb_chainlock_with_timeout(ctx->wtdb->tdb, key, timeout) != 0) { + DEBUG(3, ("tdb_chainlock_with_timeout failed\n")); + return NULL; + } + return db_tdb_fetch_locked_internal(db, mem_ctx, key); +} + static struct db_record *db_tdb_try_fetch_locked( struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key) { @@ -429,6 +444,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, db_tdb->id.ino = st.st_ino; result->fetch_locked = db_tdb_fetch_locked; + result->fetch_locked_timeout = db_tdb_fetch_locked_timeout; result->try_fetch_locked = db_tdb_try_fetch_locked; result->traverse = db_tdb_traverse; result->traverse_read = db_tdb_traverse_read; -- cgit