PATCHSET: Avoid coredumps if ctdbd is not around

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Oct 11 04:45:06 MDT 2013


Hi!

Attached find a patchset that avoids nasty corefiles and
error messages if smbd and winbind are started in cluster
mode without ctdbd being functional.

Please review & push!

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

*****************************************************************
visit us on it-sa:IT security exhibitions in Nürnberg, Germany
October 8th - 10th 2013, hall 12, booth 333
free tickets available via code 270691 on: www.it-sa.de/gutschein
******************************************************************
-------------- next part --------------
From bd5128b9a79a9f3443ba33f16550f978a74ed554 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 31 Jan 2013 10:54:48 +0100
Subject: [PATCH 1/4] ctdbd_conn: Lift the cluster_fatal call in
 get_cluster_vnn

We have to report a proper error when ctdbd is not around

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

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index f960541..70ce824 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -128,7 +128,8 @@ static NTSTATUS get_cluster_vnn(struct ctdbd_connection *conn, uint32_t *vnn)
 			       CTDB_CURRENT_NODE, CTDB_CONTROL_GET_PNN, 0, 0,
 			       tdb_null, NULL, NULL, &cstatus);
 	if (!NT_STATUS_IS_OK(status)) {
-		cluster_fatal("ctdbd_control failed\n");
+		DEBUG(1, ("ctdbd_control failed: %s\n", nt_errstr(status)));
+		return status;
 	}
 	*vnn = (uint32_t)cstatus;
 	return status;
@@ -529,6 +530,7 @@ static NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
 
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(10, ("get_cluster_vnn failed: %s\n", nt_errstr(status)));
+		cluster_fatal("get_cluster_vnn failed");
 		goto fail;
 	}
 
-- 
1.7.9.5


From 2cd456b163bbaacb8504ae34d0ee628066fb1717 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 31 Jan 2013 11:02:52 +0100
Subject: [PATCH 2/4] ctdbd_conn: Remove one call to cluster_fatal

This is during startup of a ctdb connection, thus it is not as important
as in other cases to immediately exit to free up resources

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

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 70ce824..d30e680 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -152,7 +152,8 @@ static bool ctdbd_working(struct ctdbd_connection *conn, uint32_t vnn)
 			       CTDB_CONTROL_GET_NODEMAP, 0, 0,
 			       tdb_null, talloc_tos(), &outdata, &cstatus);
 	if (!NT_STATUS_IS_OK(status)) {
-		cluster_fatal("ctdbd_control failed\n");
+		DEBUG(1, ("ctdbd_control failed: %s\n", nt_errstr(status)));
+		return false;
 	}
 	if ((cstatus != 0) || (outdata.dptr == NULL)) {
 		DEBUG(2, ("Received invalid ctdb data\n"));
-- 
1.7.9.5


From e7a92ca3c66333615cda1b2092882b462756cbc7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 31 Jan 2013 11:02:52 +0100
Subject: [PATCH 3/4] ctdbd_conn: Remove one call to cluster_fatal

This is during startup of a ctdb connection, thus it is not as important
as in other cases to immediately exit to free up resources

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/ctdbd_conn.c |    1 -
 1 file changed, 1 deletion(-)

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index d30e680..70833cb 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -531,7 +531,6 @@ static NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
 
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(10, ("get_cluster_vnn failed: %s\n", nt_errstr(status)));
-		cluster_fatal("get_cluster_vnn failed");
 		goto fail;
 	}
 
-- 
1.7.9.5


From cce68fa4052c3b92ebb3cdc85b9d7eed1800f35f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 31 Jan 2013 11:15:09 +0100
Subject: [PATCH 4/4] smbd/winbindd: Do an early check if ctdbd is functional

This will avoid panic calls when smbd and winbind is started in cluster
mode before ctdb is functional. It still logs something sane at debug
level 0, but it does not panic and core anymore.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/ctdbd_conn.h |    1 +
 source3/lib/ctdbd_conn.c     |   19 +++++++++++++++++++
 source3/smbd/server.c        |   11 +++++++++++
 source3/winbindd/winbindd.c  |   12 ++++++++++++
 4 files changed, 43 insertions(+)

diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 64cb1d5..ce5c8ba 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -89,5 +89,6 @@ NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32_t opcode,
 NTSTATUS ctdb_watch_us(struct ctdbd_connection *conn);
 NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn);
 NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid);
+NTSTATUS ctdbd_probe(void);
 
 #endif /* _CTDBD_CONN_H */
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 70833cb..2230c8f 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -1822,6 +1822,25 @@ NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn)
 	return status;
 }
 
+NTSTATUS ctdbd_probe(void)
+{
+	/*
+	 * Do a very early check if ctdbd is around to avoid an abort and core
+	 * later
+	 */
+	struct ctdbd_connection *conn = NULL;
+	NTSTATUS status;
+
+	status = ctdbd_messaging_connection(talloc_tos(), &conn);
+
+	/*
+	 * We only care if we can connect.
+	 */
+	TALLOC_FREE(conn);
+
+	return status;
+}
+
 #else
 
 NTSTATUS ctdbd_messaging_send_blob(struct ctdbd_connection *conn,
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index d3cd33e..3536f18 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1214,6 +1214,17 @@ extern void build_options(bool screen);
 		exit(1);
 	}
 
+	if (lp_clustering()) {
+		NTSTATUS status;
+
+		status = ctdbd_probe();
+		if (!NT_STATUS_IS_OK(status)) {
+			DEBUG(0, ("clustering=yes but ctdbd connect failed: "
+				  "%s\n", nt_errstr(status)));
+			exit(1);
+		}
+	}
+
 	/* Init the security context and global current_user */
 	init_sec_ctx();
 
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 953e208..07a7b39 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -37,6 +37,7 @@
 #include "auth.h"
 #include "messages.h"
 #include "../lib/util/pidfile.h"
+#include "ctdbd_conn.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -1463,6 +1464,17 @@ int main(int argc, char **argv, char **envp)
 		exit(1);
 	}
 
+	if (lp_clustering()) {
+		NTSTATUS status;
+
+		status = ctdbd_probe();
+		if (!NT_STATUS_IS_OK(status)) {
+			DEBUG(0, ("clustering=yes but ctdbd connect failed: "
+				  "%s\n", nt_errstr(status)));
+			exit(1);
+		}
+	}
+
 	/* Initialise messaging system */
 
 	if (winbind_messaging_context() == NULL) {
-- 
1.7.9.5



More information about the samba-technical mailing list