Drop the implementation of CHECK_SRVIDS control

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Aug 29 14:39:20 UTC 2017


On Mon, Aug 28, 2017 at 11:13:56PM +1000, Amitay Isaacs wrote:
> Wouldn't it be easier to switch to using new control?

Attached find a pretty raw implementation of
CTDB_CONTROL_CHECK_PID_SRVID. Tested manually.

Comments?

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From d05e93db4a32693947bcf95842f5ed0dfc86630a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 15:05:43 +0200
Subject: [PATCH 1/7] lib: Initialize unique_id with NOT_VERIFY in
 server_id_from_string

This makes "net serverid exists" more usable and should not disturb anybody
else using this UI-API.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/server_id.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/util/server_id.c b/lib/util/server_id.c
index 2904e803196..843d25ae56d 100644
--- a/lib/util/server_id.c
+++ b/lib/util/server_id.c
@@ -95,7 +95,8 @@ struct server_id server_id_from_string(uint32_t local_vnn,
 				       const char *pid_string)
 {
 	struct server_id templ = {
-		.vnn = NONCLUSTER_VNN, .pid = UINT64_MAX
+		.vnn = NONCLUSTER_VNN, .pid = UINT64_MAX,
+		.unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY
 	};
 	struct server_id result;
 	int ret;
-- 
2.11.0


From 49e9fc09184012f2357ae0f512ae12748ed315ab Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 10:38:14 +0200
Subject: [PATCH 2/7] ctdbd: Fix a typo

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 ctdb/server/ctdb_daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index 41f042ecd84..523d9fdd489 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -1743,7 +1743,7 @@ struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid
 /* This control is used by samba when probing if a process (of a samba daemon)
    exists on the node.
    Samba does this when it needs/wants to check if a subrecord in one of the
-   databases is still valied, or if it is stale and can be removed.
+   databases is still valid, or if it is stale and can be removed.
    If the node is in unhealthy or stopped state we just kill of the samba
    process holding this sub-record and return to the calling samba that
    the process does not exist.
-- 
2.11.0


From ba4a796ecec0a26110c17d62b520cb8728194645 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 11:40:39 +0200
Subject: [PATCH 3/7] ctdbd: Bring a variable into its scope

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 ctdb/server/ctdb_daemon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index 523d9fdd489..ca16ebc90d1 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -1752,9 +1752,9 @@ struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid
 */
 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid)
 {
-        struct ctdb_client *client;
-
 	if (ctdb->nodes[ctdb->pnn]->flags & (NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)) {
+		struct ctdb_client *client;
+
 		client = ctdb_find_client_by_pid(ctdb, pid);
 		if (client != NULL) {
 			DEBUG(DEBUG_NOTICE,(__location__ " Killing client with pid:%d on banned/stopped node\n", (int)pid));
-- 
2.11.0


From 4f6100b4be17f84a42788be4ee1f22b0bee99779 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 12:51:23 +0200
Subject: [PATCH 4/7] ctdbd: Add "srvid_client_check"

Yes, this a layering violation. But I did not see a proper way to
get all client structs responsible for a pid, ctdb_find_client_by_pid only
hands out one. With the current structure in Samba we have to support multiple
ctdb connections from a single pid. Resolving that is a larger task.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 ctdb/common/srvid.c | 31 +++++++++++++++++++++++++++++++
 ctdb/common/srvid.h | 13 +++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/ctdb/common/srvid.c b/ctdb/common/srvid.c
index f9cd49b4ea3..81d012ed3bf 100644
--- a/ctdb/common/srvid.c
+++ b/ctdb/common/srvid.c
@@ -26,6 +26,9 @@
 #include "common/db_hash.h"
 #include "common/srvid.h"
 
+#include "system/network.h"
+#include "ctdb_private.h"
+
 struct srvid_handler_list;
 
 struct srvid_context {
@@ -238,6 +241,34 @@ int srvid_exists(struct srvid_context *srv, uint64_t srvid)
 }
 
 /*
+ * Check if a client has registered a serverid
+ */
+int srvid_client_check(struct srvid_context *srv, pid_t pid, uint64_t srvid)
+{
+	struct srvid_handler_list *list;
+	struct srvid_handler *h;
+	int ret;
+
+	ret = srvid_fetch(srv, srvid, &list);
+	if (ret != 0) {
+		return ret;
+	}
+	for (h = list->h; h != NULL; h = h->next) {
+		struct ctdb_client *client;
+
+		client = talloc_get_type(h->private_data, struct ctdb_client);
+		if (client == NULL) {
+			continue;
+		}
+
+		if (client->pid == pid) {
+			return 0;
+		}
+	}
+	return ENOENT;
+}
+
+/*
  * Send a message to registered srvid and srvid_all
  */
 int srvid_dispatch(struct srvid_context *srv, uint64_t srvid,
diff --git a/ctdb/common/srvid.h b/ctdb/common/srvid.h
index f048b5c6cbf..e858b8e9830 100644
--- a/ctdb/common/srvid.h
+++ b/ctdb/common/srvid.h
@@ -98,6 +98,19 @@ int srvid_deregister(struct srvid_context *srv, uint64_t srvid,
 int srvid_exists(struct srvid_context *srv, uint64_t srvid);
 
 /**
+ * @brief Check if a particular client has registered a srvid
+ *
+ * @param[in] srv The srvid message handler database context
+ * @param[in] client The client
+ * @param[in] srvid The srvid
+ * @return 0 on success, errno on failure
+ *
+ * If srvid_all passed is 0, the message is not sent to message handlers
+ * registered with special srvid to receive all messages.
+ */
+int srvid_client_check(struct srvid_context *srv, pid_t pid, uint64_t srvid);
+
+/**
  * @brief Call message handlers for given srvid
  *
  * @param[in] srv The srvid message handler database context
-- 
2.11.0


From a175c547a0aaa5ad3f5d4a76ebdc02473f39906b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 11:24:53 +0200
Subject: [PATCH 5/7] ctdbd: Add CTDB_CONTROL_CHECK_PID_SRVID

This checks whether a pid has registered a srvid

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 ctdb/include/ctdb_private.h    |  2 ++
 ctdb/protocol/protocol.h       |  1 +
 ctdb/protocol/protocol_debug.c |  1 +
 ctdb/server/ctdb_control.c     |  8 ++++++++
 ctdb/server/ctdb_daemon.c      | 20 ++++++++++++++++++++
 5 files changed, 32 insertions(+)

diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 5b95b60fb0e..2ef49a96bcb 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -582,6 +582,8 @@ struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb,
 					    pid_t pid);
 
 int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
+int32_t ctdb_control_check_pid_srvid(struct ctdb_context *ctdb, pid_t pid,
+				     uint64_t srvid);
 
 int ctdb_control_getnodesfile(struct ctdb_context *ctdb, uint32_t opcode,
 			      TDB_DATA indata, TDB_DATA *outdata);
diff --git a/ctdb/protocol/protocol.h b/ctdb/protocol/protocol.h
index 67a66c715c1..3ece1601d2f 100644
--- a/ctdb/protocol/protocol.h
+++ b/ctdb/protocol/protocol.h
@@ -369,6 +369,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
 		    CTDB_CONTROL_DB_PUSH_CONFIRM         = 148,
 		    CTDB_CONTROL_DB_OPEN_FLAGS           = 149,
 		    CTDB_CONTROL_DB_ATTACH_REPLICATED    = 150,
+		    CTDB_CONTROL_CHECK_PID_SRVID         = 151,
 };
 
 #define CTDB_MONITORING_ENABLED		0
diff --git a/ctdb/protocol/protocol_debug.c b/ctdb/protocol/protocol_debug.c
index 574f903b2c0..7c6d862a500 100644
--- a/ctdb/protocol/protocol_debug.c
+++ b/ctdb/protocol/protocol_debug.c
@@ -239,6 +239,7 @@ static void ctdb_opcode_print(uint32_t opcode, FILE *fp)
 		{ CTDB_CONTROL_DB_PUSH_CONFIRM, "DB_PUSH_CONFIRM" },
 		{ CTDB_CONTROL_DB_OPEN_FLAGS, "DB_OPEN_FLAGS" },
 		{ CTDB_CONTROL_DB_ATTACH_REPLICATED, "DB_ATTACH_REPLICATED" },
+		{ CTDB_CONTROL_CHECK_PID_SRVID, "CHECK_PID_SRVID" },
 		{ MAP_END, "" },
 	};
 
diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c
index 6e9bbeb2ff5..00910690fa0 100644
--- a/ctdb/server/ctdb_control.c
+++ b/ctdb/server/ctdb_control.c
@@ -701,6 +701,14 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 		return 0;
 	}
 
+	case CTDB_CONTROL_CHECK_PID_SRVID: {
+		CHECK_CONTROL_DATA_SIZE((sizeof(pid_t) + sizeof(uint64_t)));
+		return ctdb_control_check_pid_srvid(
+			ctdb, *(pid_t *)indata.dptr,
+			*(uint64_t *)((char *)indata.dptr + sizeof(pid_t)));
+	}
+
+
 	default:
 		DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
 		return -1;
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index ca16ebc90d1..21860acde11 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -1766,6 +1766,26 @@ int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid)
 	return kill(pid, 0);
 }
 
+int32_t ctdb_control_check_pid_srvid(struct ctdb_context *ctdb, pid_t pid,
+				     uint64_t srvid)
+{
+	int ret;
+
+	DEBUG(DEBUG_NOTICE, (__location__ " Checking pid %d srvid %"PRIu64"\n",
+			     (int)pid, srvid));
+
+	ret = srvid_client_check(ctdb->srv, pid, srvid);
+	DEBUG(DEBUG_NOTICE, (__location__ " srvid_client_check returned %d\n",
+			     ret));
+	if (ret != 0) {
+		return -1;
+	}
+	DEBUG(DEBUG_NOTICE, (__location__ " Pid %d srvid %"PRIu64" exists\n",
+			     (int)pid, srvid));
+	return 0;
+}
+
+
 int ctdb_control_getnodesfile(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
 {
 	struct ctdb_node_map_old *node_map = NULL;
-- 
2.11.0


From 7894b12747a2b82907caf2a772b59128b59c9540 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 13:26:20 +0200
Subject: [PATCH 6/7] lib: Add "unique_id" to ctdbd_process_exists

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/ctdbd_conn.h | 2 +-
 source3/lib/ctdb_dummy.c     | 3 ++-
 source3/lib/ctdbd_conn.c     | 3 ++-
 source3/lib/serverid.c       | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 4e7c1b05ddd..f6040ad833b 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -50,7 +50,7 @@ int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
 			     const struct iovec *iov, int iovlen);
 
 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
-			  pid_t pid);
+			  pid_t pid, uint64_t unique_id);
 
 char *ctdbd_dbpath(struct ctdbd_connection *conn,
 		   TALLOC_CTX *mem_ctx, uint32_t db_id);
diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index 8a06b0cc7cf..144c8507758 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -62,7 +62,8 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
 	return ENOSYS;
 }
 
-bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid)
+bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
+			  pid_t pid, uint64_t unique_id)
 {
 	return false;
 }
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index bab489e71dd..2a7fd444b77 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -781,7 +781,8 @@ static int ctdbd_control(struct ctdbd_connection *conn,
 /*
  * see if a remote process exists
  */
-bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid)
+bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
+			  pid_t pid, uint64_t unique_id)
 {
 	int32_t cstatus = 0;
 	int ret;
diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
index ca4bb271807..73004489bef 100644
--- a/source3/lib/serverid.c
+++ b/source3/lib/serverid.c
@@ -199,7 +199,7 @@ bool serverid_exists(const struct server_id *id)
 
 	if (lp_clustering()) {
 		return ctdbd_process_exists(messaging_ctdb_connection(),
-					    id->vnn, id->pid);
+					    id->vnn, id->pid, id->unique_id);
 	}
 
 	return false;
-- 
2.11.0


From 5fcd0c45e2a8092eb46a1f4164c842e06f7a9751 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 13:31:07 +0200
Subject: [PATCH 7/7] lib: Use CTDB_CONTROL_CHECK_PID_SRVID

Also check the unique ID for remote server ids, just like we do for
local server ids

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/ctdbd_conn.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 2a7fd444b77..521e0168ca3 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -784,12 +784,27 @@ static int ctdbd_control(struct ctdbd_connection *conn,
 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
 			  pid_t pid, uint64_t unique_id)
 {
+	uint8_t buf[sizeof(pid)+sizeof(unique_id)];
 	int32_t cstatus = 0;
 	int ret;
 
-	ret = ctdbd_control(conn, vnn, CTDB_CONTROL_PROCESS_EXISTS, 0, 0,
-			    (TDB_DATA) { .dptr = (uint8_t *)&pid,
-					 .dsize = sizeof(pid) },
+	if (unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
+		ret = ctdbd_control(conn, vnn, CTDB_CONTROL_PROCESS_EXISTS,
+				    0, 0,
+				    (TDB_DATA) { .dptr = (uint8_t *)&pid,
+						    .dsize = sizeof(pid) },
+				    NULL, NULL, &cstatus);
+		if (ret != 0) {
+			return false;
+		}
+		return (cstatus == 0);
+	}
+
+	memcpy(buf, &pid, sizeof(pid));
+	memcpy(buf+sizeof(pid), &unique_id, sizeof(unique_id));
+
+	ret = ctdbd_control(conn, vnn, CTDB_CONTROL_CHECK_PID_SRVID, 0, 0,
+			    (TDB_DATA) { .dptr = buf, .dsize = sizeof(buf) },
 			    NULL, NULL, &cstatus);
 	if (ret != 0) {
 		return false;
-- 
2.11.0



More information about the samba-technical mailing list