]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:ctdbd_conn: let ctdbd_init_connection_internal() get the pid and start_time of...
authorStefan Metzmacher <metze@samba.org>
Tue, 14 Jul 2026 14:31:21 +0000 (16:31 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 4 Aug 2026 09:51:32 +0000 (09:51 +0000)
This will allow the caller to identify database records valid for
the lifetime of the current ctdbd.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/ctdbd_conn.h
source3/lib/ctdbd_conn.c

index a146367ed3ac92115e4430b3419ea3c8a568a94c..23f4a4ec23f14a14e4e301cdb0c5971f5d81fd8b 100644 (file)
@@ -40,8 +40,10 @@ int ctdbd_init_async_connection(
        int timeout,
        struct ctdbd_connection **pconn);
 
-uint32_t ctdbd_vnn(const struct ctdbd_connection *conn);
 int ctdbd_generation(struct ctdbd_connection *conn, uint32_t *generation);
+uint32_t ctdbd_vnn(const struct ctdbd_connection *conn);
+pid_t ctdbd_pid(const struct ctdbd_connection *conn);
+struct timeval ctdbd_start_time(const struct ctdbd_connection *conn);
 
 int ctdbd_conn_get_fd(struct ctdbd_connection *conn);
 void ctdbd_socket_readable(struct tevent_context *ev,
index a7b872beb6f54c94e1edb044edc2fca1413f7db7..26777fdd2d3ae0773b8d2aef8e9fad2a2a87ca94 100644 (file)
@@ -54,6 +54,10 @@ struct ctdbd_srvid_cb {
 };
 
 struct ctdbd_connection {
+       struct {
+               pid_t pid;
+               struct timeval start_time;
+       } local_ctdbd;
        uint32_t reqid;
        uint32_t our_vnn;
        uint64_t rand_srvid;
@@ -281,6 +285,56 @@ static int ctdbd_msg_call_back(struct tevent_context *ev,
        return 0;
 }
 
+/*
+ * get the pid of the ctdbd process
+ */
+static int get_ctdbd_pid(struct ctdbd_connection *conn, pid_t *pid)
+{
+       int32_t cstatus=-1;
+       int ret;
+       ret = ctdbd_control_local(conn, CTDB_CONTROL_GET_PID, 0, 0,
+                                 tdb_null, NULL, NULL, &cstatus);
+       if (ret != 0) {
+               DEBUG(1, ("ctdbd_control failed: %s\n", strerror(ret)));
+               return ret;
+       }
+       *pid = (pid_t)cstatus;
+       return ret;
+}
+
+/*
+ * get the start time of the ctdbd process
+ */
+static int get_ctdbd_start_time(struct ctdbd_connection *conn,
+                               struct timeval *st)
+{
+       const struct ctdb_uptime *uptime = NULL;
+       int32_t cstatus=-1;
+       TDB_DATA outdata = {0};
+       int ret;
+
+       ret = ctdbd_control_local(conn, CTDB_CONTROL_UPTIME, 0, 0,
+                                 tdb_null, conn, &outdata, &cstatus);
+       if (ret != 0) {
+               DEBUG(1, ("ctdbd_control failed: %s\n", strerror(ret)));
+               return ret;
+       }
+       if ((cstatus != 0) || (outdata.dptr == NULL)) {
+               DEBUG(2, ("Received invalid ctdb data\n"));
+               return EINVAL;
+       }
+       if (outdata.dsize != sizeof(*uptime)) {
+               talloc_free(outdata.dptr);
+               DEBUG(2, ("Received invalid ctdb data\n"));
+               return EINVAL;
+       }
+
+       uptime = (const struct ctdb_uptime *)outdata.dptr;
+       *st = uptime->ctdbd_start_time;
+       talloc_free(outdata.dptr);
+       return 0;
+}
+
 /*
  * get our vnn from the cluster
  */
@@ -393,6 +447,16 @@ uint32_t ctdbd_vnn(const struct ctdbd_connection *conn)
        return conn->our_vnn;
 }
 
+pid_t ctdbd_pid(const struct ctdbd_connection *conn)
+{
+       return conn->local_ctdbd.pid;
+}
+
+struct timeval ctdbd_start_time(const struct ctdbd_connection *conn)
+{
+       return conn->local_ctdbd.start_time;
+}
+
 /*
  * Get us a ctdb connection
  */
@@ -579,6 +643,18 @@ static int ctdbd_init_connection_internal(TALLOC_CTX *mem_ctx,
                return ret;
        }
 
+       ret = get_ctdbd_pid(conn, &conn->local_ctdbd.pid);
+       if (ret != 0) {
+               DEBUG(10, ("get_ctdbd_pid failed: %s\n", strerror(ret)));
+               return ret;
+       }
+
+       ret = get_ctdbd_start_time(conn, &conn->local_ctdbd.start_time);
+       if (ret != 0) {
+               DEBUG(10, ("get_ctdbd_start_time failed: %s\n", strerror(ret)));
+               return ret;
+       }
+
        if (!ctdbd_working(conn, conn->our_vnn)) {
                DEBUG(2, ("Node is not working, can not connect\n"));
                return EIO;