From: Stefan Metzmacher Date: Thu, 16 Jul 2026 09:10:35 +0000 (+0200) Subject: s3:g_lock: split out g_lock_ctx_init_ex() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3137e51ea1b8fcce256f9ea8bb552e8b62fa9fdf;p=thirdparty%2Fsamba.git s3:g_lock: split out g_lock_ctx_init_ex() This prepares us to allow to open a persistent database in read-write mode with transactions during early startup where we don't have global state yet. This asserts that g_lock_ctx_init() can't be called recursively. It will be used in db_open_ctdb_ex() in the next step. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h index 0ce1576c86f..d81a9828b29 100644 --- a/source3/include/g_lock.h +++ b/source3/include/g_lock.h @@ -27,6 +27,8 @@ struct g_lock_ctx; struct g_lock_lock_cb_state; struct messaging_context; +struct tevent_context; +struct ctdbd_connection; enum g_lock_type { G_LOCK_READ, @@ -41,6 +43,10 @@ struct g_lock_ctx *g_lock_ctx_init_backend( struct db_context **backend); void g_lock_set_lock_order(struct g_lock_ctx *ctx, enum dbwrap_lock_order lock_order); +struct g_lock_ctx *g_lock_ctx_init_ex(TALLOC_CTX *mem_ctx, + struct messaging_context *msg, + struct tevent_context *ev_ctx_ex, + struct ctdbd_connection *ctdb_conn_ex); struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, struct messaging_context *msg); diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 1a62c59b1a0..08e2b2d7aa7 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -224,20 +224,27 @@ void g_lock_set_lock_order(struct g_lock_ctx *ctx, ctx->lock_order = lock_order; } -struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, - struct messaging_context *msg) +struct g_lock_ctx *g_lock_ctx_init_ex(TALLOC_CTX *mem_ctx, + struct messaging_context *msg, + struct tevent_context *ev_ctx_ex, + struct ctdbd_connection *ctdb_conn_ex) { char *db_path = NULL; struct db_context *backend = NULL; struct g_lock_ctx *ctx = NULL; + SMB_ASSERT(msg != NULL); + db_path = lock_path(mem_ctx, "g_lock.tdb"); if (db_path == NULL) { return NULL; } - backend = db_open( + backend = db_open_ex( mem_ctx, + ev_ctx_ex, + msg, + ctdb_conn_ex, db_path, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_VOLATILE, @@ -255,6 +262,24 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, return ctx; } +struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, + struct messaging_context *msg) +{ + struct g_lock_ctx *ctx = NULL; + static bool busy; + + SMB_ASSERT(!busy); + + busy = true; + ctx = g_lock_ctx_init_ex(mem_ctx, + msg, + NULL, /* ev_ctx_ex */ + NULL); /* ctdb_conn_ex */ + busy = false; + + return ctx; +} + static void g_lock_cleanup_dead( struct g_lock *lck, struct server_id *dead_blocker)