]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:g_lock: split out g_lock_ctx_init_ex()
authorStefan Metzmacher <metze@samba.org>
Thu, 16 Jul 2026 09:10:35 +0000 (11:10 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 4 Aug 2026 09:51:32 +0000 (09:51 +0000)
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 <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/g_lock.h
source3/lib/g_lock.c

index 0ce1576c86f481234e4be9a4af5d123a0df1768c..d81a9828b294551e4b7e1b556c0c1ba7be932be6 100644 (file)
@@ -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);
 
index 1a62c59b1a05d49c041f712e3fcf5874df79019b..08e2b2d7aa7561d7c14032287ec39aaccb6cdc7b 100644 (file)
@@ -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)