From: Stefan Metzmacher Date: Tue, 14 Jul 2026 14:31:21 +0000 (+0200) Subject: s3:ctdbd_conn: let ctdbd_init_connection_internal() get the pid and start_time of... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef451e21c5d7eb20b798a702d0f3bec3d20bfb4b;p=thirdparty%2Fsamba.git s3:ctdbd_conn: let ctdbd_init_connection_internal() get the pid and start_time of ctdbd This will allow the caller to identify database records valid for the lifetime of the current ctdbd. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h index a146367ed3a..23f4a4ec23f 100644 --- a/source3/include/ctdbd_conn.h +++ b/source3/include/ctdbd_conn.h @@ -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, diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index a7b872beb6f..26777fdd2d3 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -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;