[PATCH] Make ctdbd_conn independent of messages.h

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue May 3 17:19:21 UTC 2016


Hi!

Review appreciated!

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 6159edfe0685e6c6355026d6f6f2a10f05591c44 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 11 Apr 2016 17:15:29 +0200
Subject: [PATCH 01/12] ctdbd_conn: remove ctdb_processes_exist

The singular call was the only user. Remove the complex plural one. We can
always dig it up from git history if we need it.

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

diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index c91f700..026db04 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -49,9 +49,6 @@ int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
 
 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
 			  pid_t pid);
-bool ctdb_processes_exist(struct ctdbd_connection *conn,
-			  const struct server_id *pids, int num_pids,
-			  bool *results);
 
 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 5162242..1a27b49 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -58,13 +58,6 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
 	return ENOSYS;
 }
 
-bool ctdb_processes_exist(struct ctdbd_connection *conn,
-			  const struct server_id *pids, int num_pids,
-			  bool *results)
-{
-	return false;
-}
-
 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid)
 {
 	return false;
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 9ea029a..f14a31a 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -692,126 +692,17 @@ static int ctdbd_control(struct ctdbd_connection *conn,
  */
 bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid)
 {
-	struct server_id id;
-	bool result;
-
-	id.pid = pid;
-	id.vnn = vnn;
+	int32_t cstatus = 0;
+	int ret;
 
-	if (!ctdb_processes_exist(conn, &id, 1, &result)) {
-		DEBUG(10, ("ctdb_processes_exist failed\n"));
+	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 result;
-}
-
-bool ctdb_processes_exist(struct ctdbd_connection *conn,
-			  const struct server_id *pids, int num_pids,
-			  bool *results)
-{
-	TALLOC_CTX *frame = talloc_stackframe();
-	int i, num_received;
-	uint32_t *reqids;
-	bool result = false;
-
-	reqids = talloc_array(talloc_tos(), uint32_t, num_pids);
-	if (reqids == NULL) {
-		goto fail;
-	}
-
-	for (i=0; i<num_pids; i++) {
-		struct ctdb_req_control_old req;
-		pid_t pid;
-		struct iovec iov[2];
-		ssize_t nwritten;
-
-		results[i] = false;
-		reqids[i] = ctdbd_next_reqid(conn);
-
-		ZERO_STRUCT(req);
-
-		/*
-		 * pids[i].pid is uint64_t, scale down to pid_t which
-		 * is the wire protocol towards ctdb.
-		 */
-		pid = pids[i].pid;
-
-		DEBUG(10, ("Requesting PID %d/%d, reqid=%d\n",
-			   (int)pids[i].vnn, (int)pid,
-			   (int)reqids[i]));
-
-		req.hdr.length = offsetof(struct ctdb_req_control_old, data);
-		req.hdr.length += sizeof(pid);
-		req.hdr.ctdb_magic   = CTDB_MAGIC;
-		req.hdr.ctdb_version = CTDB_PROTOCOL;
-		req.hdr.operation    = CTDB_REQ_CONTROL;
-		req.hdr.reqid        = reqids[i];
-		req.hdr.destnode     = pids[i].vnn;
-		req.opcode           = CTDB_CONTROL_PROCESS_EXISTS;
-		req.srvid            = 0;
-		req.datalen          = sizeof(pid);
-		req.flags            = 0;
-
-		DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
-		ctdb_packet_dump(&req.hdr);
-
-		iov[0].iov_base = &req;
-		iov[0].iov_len = offsetof(struct ctdb_req_control_old, data);
-		iov[1].iov_base = &pid;
-		iov[1].iov_len = sizeof(pid);
-
-		nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
-		if (nwritten == -1) {
-			DEBUG(10, ("write_data_iov failed: %s\n",
-				   strerror(errno)));
-			goto fail;
-		}
-	}
-
-	num_received = 0;
-
-	while (num_received < num_pids) {
-		struct ctdb_req_header *hdr;
-		struct ctdb_reply_control_old *reply;
-		uint32_t reqid;
-		int ret;
-
-		ret = ctdb_read_req(conn, 0, talloc_tos(), &hdr);
-		if (ret != 0) {
-			DEBUG(10, ("ctdb_read_req failed: %s\n",
-				   strerror(ret)));
-			goto fail;
-		}
-
-		if (hdr->operation != CTDB_REPLY_CONTROL) {
-			DEBUG(10, ("Received invalid reply\n"));
-			goto fail;
-		}
-		reply = (struct ctdb_reply_control_old *)hdr;
-
-		reqid = reply->hdr.reqid;
-
-		DEBUG(10, ("Received reqid %d\n", (int)reqid));
-
-		for (i=0; i<num_pids; i++) {
-			if (reqid == reqids[i]) {
-				break;
-			}
-		}
-		if (i == num_pids) {
-			DEBUG(10, ("Received unknown record number %u\n",
-				   (unsigned)reqid));
-			goto fail;
-		}
-		results[i] = ((reply->status) == 0);
-		TALLOC_FREE(reply);
-		num_received += 1;
-	}
-
-	result = true;
-fail:
-	TALLOC_FREE(frame);
-	return result;
+	return (cstatus == 0);
 }
 
 /*
-- 
1.9.1


From 1a5151d9adfec29f549d1ec55c039ff2c1d0772c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 19 Apr 2016 16:02:49 +0200
Subject: [PATCH 02/12] ctdbd_conn: Simplify two DEBUGs

msg->hdr.length is a uint32 and we have PRIu32

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

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index f14a31a..82abdf9 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -142,20 +142,19 @@ int register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid,
 static int ctdbd_msg_call_back(struct ctdbd_connection *conn,
 			       struct ctdb_req_message_old *msg)
 {
-	size_t msg_len;
+	uint32_t msg_len;
 	size_t i, num_callbacks;
 
 	msg_len = msg->hdr.length;
 	if (msg_len < offsetof(struct ctdb_req_message_old, data)) {
-		DEBUG(10, ("%s: len %u too small\n", __func__,
-			   (unsigned)msg_len));
+		DBG_DEBUG("len %"PRIu32" too small\n", msg_len);
 		return 0;
 	}
 	msg_len -= offsetof(struct ctdb_req_message_old, data);
 
 	if (msg_len < msg->datalen) {
-		DEBUG(10, ("%s: msg_len=%u < msg->datalen=%u\n", __func__,
-			   (unsigned)msg_len, (unsigned)msg->datalen));
+		DBG_DEBUG("msg_len=%"PRIu32" < msg->datalen=%"PRIu32"\n",
+			  msg_len, msg->datalen);
 		return 0;
 	}
 
-- 
1.9.1


From 994c1b5eef2e641f1636ec4b9ab636807e7e851e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 19 Apr 2016 21:40:40 +0200
Subject: [PATCH 03/12] ctdbd_conn: "sockname" is not needed anymore

Previously it was used in ctdb_traverse(), but with ff72a8a this is no longer
the case

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

diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 82abdf9..1884975 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -47,7 +47,6 @@ struct ctdbd_srvid_cb {
 };
 
 struct ctdbd_connection {
-	const char *sockname;	/* Needed in ctdbd_traverse */
 	struct messaging_context *msg_ctx;
 	uint32_t reqid;
 	uint32_t our_vnn;
@@ -433,20 +432,13 @@ int ctdbd_init_connection(TALLOC_CTX *mem_ctx,
 		return ENOMEM;
 	}
 
-	conn->sockname = talloc_strdup(conn, sockname);
-	if (conn->sockname == NULL) {
-		DBG_ERR("talloc failed\n");
-		ret = ENOMEM;
-		goto fail;
-	}
-
 	conn->timeout = timeout;
 
 	if (conn->timeout == 0) {
 		conn->timeout = -1;
 	}
 
-	ret = ctdbd_connect(conn->sockname, &conn->fd);
+	ret = ctdbd_connect(sockname, &conn->fd);
 	if (ret != 0) {
 		DEBUG(1, ("ctdbd_connect failed: %s\n", strerror(ret)));
 		goto fail;
-- 
1.9.1


From 5408f8a24367b7bc587985318fc2b454437899bd Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 24 Apr 2016 17:36:00 +0200
Subject: [PATCH 04/12] ctdbd_conn: Expose ctdb socket readability handler

This will obsolete ctdbd_register_msg_ctx soon

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/ctdbd_conn.h |  1 +
 source3/lib/ctdbd_conn.c     | 30 ++++++++++++++++++++----------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 026db04..282379d 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -42,6 +42,7 @@ int ctdbd_register_msg_ctx(struct ctdbd_connection *conn,
 struct messaging_context *ctdb_conn_msg_ctx(struct ctdbd_connection *conn);
 
 int ctdbd_conn_get_fd(struct ctdbd_connection *conn);
+void ctdbd_socket_readable(struct ctdbd_connection *conn);
 
 int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
 			     uint32_t dst_vnn, uint64_t dst_srvid,
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 1884975..e54ec7e 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -508,17 +508,8 @@ static int ctdb_handle_message(struct ctdbd_connection *conn,
 	return 0;
 }
 
-/*
- * The ctdbd socket is readable asynchronuously
- */
-
-static void ctdbd_socket_handler(struct tevent_context *event_ctx,
-				 struct tevent_fd *event,
-				 uint16_t flags,
-				 void *private_data)
+void ctdbd_socket_readable(struct ctdbd_connection *conn)
 {
-	struct ctdbd_connection *conn = talloc_get_type_abort(
-		private_data, struct ctdbd_connection);
 	struct ctdb_req_header *hdr = NULL;
 	int ret;
 
@@ -539,6 +530,25 @@ static void ctdbd_socket_handler(struct tevent_context *event_ctx,
 }
 
 /*
+ * The ctdbd socket is readable asynchronuously
+ */
+
+static void ctdbd_socket_handler(struct tevent_context *event_ctx,
+				 struct tevent_fd *event,
+				 uint16_t flags,
+				 void *private_data)
+{
+	struct ctdbd_connection *conn = talloc_get_type_abort(
+		private_data, struct ctdbd_connection);
+
+	if ((flags & TEVENT_FD_READ) == 0) {
+		return;
+	}
+
+	ctdbd_socket_readable(conn);
+}
+
+/*
  * Prepare a ctdbd connection to receive messages
  */
 
-- 
1.9.1


From ff0b1b9f8285d6f7c005c94408cfe3843709d799 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 24 Apr 2016 17:37:33 +0200
Subject: [PATCH 05/12] lib: Move async message handling out of ctdbd_conn

messages_ctdbd.c is the code that is genuinely interested in
async messages from ctdb, so let it take care of them.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/messages_ctdbd.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/source3/lib/messages_ctdbd.c b/source3/lib/messages_ctdbd.c
index a61c773..1645ccf 100644
--- a/source3/lib/messages_ctdbd.c
+++ b/source3/lib/messages_ctdbd.c
@@ -28,6 +28,7 @@
 
 struct messaging_ctdbd_context {
 	struct ctdbd_connection *conn;
+	struct tevent_fd *fde;
 };
 
 /*
@@ -159,13 +160,28 @@ static int messaging_ctdb_recv(
 	return 0;
 }
 
+static void messaging_ctdbd_readable(struct tevent_context *ev,
+				     struct tevent_fd *fde,
+				     uint16_t flags,
+				     void *private_data)
+{
+	struct ctdbd_connection *conn = talloc_get_type_abort(
+		private_data, struct ctdbd_connection);
+
+	if ((flags & TEVENT_FD_READ) == 0) {
+		return;
+	}
+	ctdbd_socket_readable(conn);
+}
+
 int messaging_ctdbd_init(struct messaging_context *msg_ctx,
 			 TALLOC_CTX *mem_ctx,
 			 struct messaging_backend **presult)
 {
 	struct messaging_backend *result;
 	struct messaging_ctdbd_context *ctx;
-	int ret;
+	struct tevent_context *ev;
+	int ret, ctdb_fd;
 
 	if (!(result = talloc(mem_ctx, struct messaging_backend))) {
 		DEBUG(0, ("talloc failed\n"));
@@ -196,16 +212,6 @@ int messaging_ctdbd_init(struct messaging_context *msg_ctx,
 		return ret;
 	}
 
-	ret = ctdbd_register_msg_ctx(ctx->conn, msg_ctx,
-				     messaging_tevent_context(msg_ctx));
-
-	if (ret != 0) {
-		DEBUG(10, ("ctdbd_register_msg_ctx failed: %s\n",
-			   strerror(ret)));
-		TALLOC_FREE(result);
-		return ret;
-	}
-
 	ret = register_with_ctdbd(ctx->conn, getpid(),
 				  messaging_ctdb_recv, msg_ctx);
 	if (ret != 0) {
@@ -215,6 +221,16 @@ int messaging_ctdbd_init(struct messaging_context *msg_ctx,
 		return ret;
 	}
 
+	ctdb_fd = ctdbd_conn_get_fd(ctx->conn);
+	ev = messaging_tevent_context(msg_ctx);
+
+	ctx->fde = tevent_add_fd(ev, ctx, ctdb_fd, TEVENT_FD_READ,
+				 messaging_ctdbd_readable, ctx->conn);
+	if (ctx->fde == NULL) {
+		TALLOC_FREE(result);
+		return ENOMEM;
+	}
+
 	global_ctdb_connection_pid = getpid();
 	global_ctdbd_connection = ctx->conn;
 	talloc_set_destructor(ctx, messaging_ctdbd_destructor);
-- 
1.9.1


From 460422c016c0dac5db455f8e25d01b3e5f3ad270 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 11 Apr 2016 15:45:49 +0200
Subject: [PATCH 06/12] dbwrap_ctdb: Align loop index with terminator

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

diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 532240d..e6b6524 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -357,7 +357,7 @@ static bool parse_newest_in_marshall_buffer(
 	struct ctdb_rec_data_old *rec = NULL;
 	struct ctdb_ltdb_header *h = NULL;
 	TDB_DATA data;
-	int i;
+	uint32_t i;
 
 	if (buf == NULL) {
 		return false;
@@ -1431,7 +1431,7 @@ static int db_ctdb_traverse(struct db_context *db,
 			struct db_context *newkeys = db_open_rbt(talloc_tos());
 			struct ctdb_marshall_buffer *mbuf = ctx->transaction->m_write;
 			struct ctdb_rec_data_old *rec=NULL;
-			int i;
+			uint32_t i;
 			int count = 0;
 			NTSTATUS status;
 
-- 
1.9.1


From 51badfd6d57ceebb690106e28a5c53674a335a2c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 11 Apr 2016 16:01:07 +0200
Subject: [PATCH 07/12] dbwrap_ctdb: Add "conn" to db_ctdb_ctx

This minimizes the use of messaging_ctdbd_connection() to
db_open_ctx(). Next step will move this into db_open().

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/dbwrap/dbwrap_ctdb.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index e6b6524..51e955a 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -49,6 +49,7 @@ struct db_ctdb_transaction_handle {
 
 struct db_ctdb_ctx {
 	struct db_context *db;
+	struct ctdbd_connection *conn;
 	struct tdb_wrap *wtdb;
 	uint32_t db_id;
 	struct db_ctdb_transaction_handle *transaction;
@@ -760,8 +761,7 @@ static int db_ctdb_transaction_commit(struct db_context *db)
 
 again:
 	/* tell ctdbd to commit to the other nodes */
-	ret = ctdbd_control_local(messaging_ctdbd_connection(),
-				  CTDB_CONTROL_TRANS3_COMMIT,
+	ret = ctdbd_control_local(ctx->conn, CTDB_CONTROL_TRANS3_COMMIT,
 				  h->ctx->db_id, 0,
 				  db_ctdb_marshall_finish(h->m_write),
 				  NULL, NULL, &status);
@@ -858,6 +858,7 @@ static NTSTATUS db_ctdb_send_schedule_for_deletion(struct db_record *rec)
 	int32_t cstatus;
 	struct db_ctdb_rec *crec = talloc_get_type_abort(
 		rec->private_data, struct db_ctdb_rec);
+	struct db_ctdb_ctx *ctx = crec->ctdb_ctx;
 
 	indata.dsize = offsetof(struct ctdb_control_schedule_for_deletion, key) + rec->key.dsize;
 	indata.dptr = talloc_zero_array(crec, uint8_t, indata.dsize);
@@ -867,12 +868,12 @@ static NTSTATUS db_ctdb_send_schedule_for_deletion(struct db_record *rec)
 	}
 
 	dd = (struct ctdb_control_schedule_for_deletion *)(void *)indata.dptr;
-	dd->db_id = crec->ctdb_ctx->db_id;
+	dd->db_id = ctx->db_id;
 	dd->hdr = crec->header;
 	dd->keylen = rec->key.dsize;
 	memcpy(dd->key, rec->key.dptr, rec->key.dsize);
 
-	ret = ctdbd_control_local(messaging_ctdbd_connection(),
+	ret = ctdbd_control_local(ctx->conn,
 				  CTDB_CONTROL_SCHEDULE_FOR_DELETION,
 				  crec->ctdb_ctx->db_id,
 				  CTDB_CTRL_FLAG_NOREPLY, /* flags */
@@ -1107,8 +1108,7 @@ again:
 			   ((struct ctdb_ltdb_header *)ctdb_data.dptr)->flags : 0));
 
 		GetTimeOfDay(&ctdb_start_time);
-		ret = ctdbd_migrate(messaging_ctdbd_connection(), ctx->db_id,
-				    key);
+		ret = ctdbd_migrate(ctx->conn, ctx->db_id, key);
 		ctdb_time += timeval_elapsed(&ctdb_start_time);
 
 		if (ret != 0) {
@@ -1295,7 +1295,7 @@ static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key,
 		return NT_STATUS_OK;
 	}
 
-	ret = ctdbd_parse(messaging_ctdbd_connection(), ctx->db_id, key,
+	ret = ctdbd_parse(ctx->conn, ctx->db_id, key,
 			  state.ask_for_readonly_copy, parser, private_data);
 	if (ret != 0) {
 		if (ret == ENOENT) {
@@ -1587,7 +1587,6 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 	struct db_context *result;
 	struct db_ctdb_ctx *db_ctdb;
 	char *db_path;
-	struct ctdbd_connection *conn;
 	struct loadparm_context *lp_ctx;
 	struct ctdb_db_priority prio;
 	int32_t cstatus;
@@ -1620,14 +1619,14 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 	db_ctdb->transaction = NULL;
 	db_ctdb->db = result;
 
-	conn = messaging_ctdbd_connection();
-	if (conn == NULL) {
+	db_ctdb->conn = messaging_ctdbd_connection();
+	if (db_ctdb->conn == NULL) {
 		DEBUG(1, ("Could not connect to ctdb\n"));
 		TALLOC_FREE(result);
 		return NULL;
 	}
 
-	ret = ctdbd_db_attach(conn, name, &db_ctdb->db_id, tdb_flags);
+	ret = ctdbd_db_attach(db_ctdb->conn, name, &db_ctdb->db_id, tdb_flags);
 	if (ret != 0) {
 		DEBUG(0, ("ctdbd_db_attach failed for %s: %s\n", name,
 			  strerror(ret)));
@@ -1635,7 +1634,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 		return NULL;
 	}
 
-	db_path = ctdbd_dbpath(conn, db_ctdb, db_ctdb->db_id);
+	db_path = ctdbd_dbpath(db_ctdb->conn, db_ctdb, db_ctdb->db_id);
 
 	result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
 	result->lock_order = lock_order;
@@ -1648,7 +1647,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 	prio.priority = lock_order;
 
 	ret = ctdbd_control_local(
-		conn, CTDB_CONTROL_SET_DB_PRIORITY, 0, 0,
+		db_ctdb->conn, CTDB_CONTROL_SET_DB_PRIORITY, 0, 0,
 		make_tdb_data((uint8_t *)&prio, sizeof(prio)),
 		NULL, NULL, &cstatus);
 
@@ -1668,8 +1667,8 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 				       sizeof(db_ctdb->db_id));
 
 		ret = ctdbd_control_local(
-			conn, CTDB_CONTROL_SET_DB_READONLY, 0, 0, indata,
-			NULL, NULL, &cstatus);
+			db_ctdb->conn, CTDB_CONTROL_SET_DB_READONLY, 0, 0,
+			indata, NULL, NULL, &cstatus);
 		if ((ret != 0) || (cstatus != 0)) {
 			DEBUG(1, ("CTDB_CONTROL_SET_DB_READONLY failed: "
 				  "%s, %"PRIi32"\n", strerror(ret), cstatus));
@@ -1709,8 +1708,8 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 	}
 
 	if (result->persistent) {
-		db_ctdb->lock_ctx = g_lock_ctx_init(db_ctdb,
-						    ctdb_conn_msg_ctx(conn));
+		db_ctdb->lock_ctx = g_lock_ctx_init(
+			db_ctdb, ctdb_conn_msg_ctx(db_ctdb->conn));
 		if (db_ctdb->lock_ctx == NULL) {
 			DEBUG(0, ("g_lock_ctx_init failed\n"));
 			TALLOC_FREE(result);
-- 
1.9.1


From 07a72f14a0bb009c21b6a1ef367d46a75b56a5d8 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 11 Apr 2016 16:20:32 +0200
Subject: [PATCH 08/12] dbwrap_ctdb: Pass in ctdbd_connection

This removes one circular dependency of dbwrap_ctdb to messages.c: No call to
messaging_ctdbd_connection() anymore from dbwrap_ctdb.c.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/ctdb_dummy.c           |  1 +
 source3/lib/dbwrap/dbwrap_ctdb.c   |  9 ++-------
 source3/lib/dbwrap/dbwrap_ctdb.h   |  2 ++
 source3/lib/dbwrap/dbwrap_open.c   | 12 +++++++++++-
 source3/torture/test_dbwrap_ctdb.c | 12 ++++++++++--
 5 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index 1a27b49..0e061be 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -64,6 +64,7 @@ bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid
 }
 
 struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
+				struct ctdbd_connection *conn,
 				const char *name,
 				int hash_size, int tdb_flags,
 				int open_flags, mode_t mode,
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 51e955a..cf03984 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1578,6 +1578,7 @@ static size_t db_ctdb_id(struct db_context *db, uint8_t *id, size_t idlen)
 }
 
 struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
+				struct ctdbd_connection *conn,
 				const char *name,
 				int hash_size, int tdb_flags,
 				int open_flags, mode_t mode,
@@ -1618,13 +1619,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 
 	db_ctdb->transaction = NULL;
 	db_ctdb->db = result;
-
-	db_ctdb->conn = messaging_ctdbd_connection();
-	if (db_ctdb->conn == NULL) {
-		DEBUG(1, ("Could not connect to ctdb\n"));
-		TALLOC_FREE(result);
-		return NULL;
-	}
+	db_ctdb->conn = conn;
 
 	ret = ctdbd_db_attach(db_ctdb->conn, name, &db_ctdb->db_id, tdb_flags);
 	if (ret != 0) {
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.h b/source3/lib/dbwrap/dbwrap_ctdb.h
index 3196b91..2e4b93c 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.h
+++ b/source3/lib/dbwrap/dbwrap_ctdb.h
@@ -26,8 +26,10 @@
 #include "dbwrap/dbwrap_private.h"
 
 struct db_context;
+struct ctdbd_connection;
 
 struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
+				struct ctdbd_connection *conn,
 				const char *name,
 				int hash_size, int tdb_flags,
 				int open_flags, mode_t mode,
diff --git a/source3/lib/dbwrap/dbwrap_open.c b/source3/lib/dbwrap/dbwrap_open.c
index 98e4f41..805e823 100644
--- a/source3/lib/dbwrap/dbwrap_open.c
+++ b/source3/lib/dbwrap/dbwrap_open.c
@@ -28,6 +28,7 @@
 #include "lib/cluster_support.h"
 #include "util_tdb.h"
 #include "ctdbd_conn.h"
+#include "messages.h"
 
 bool db_is_local(const char *name)
 {
@@ -143,7 +144,16 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
 		}
 		/* allow ctdb for individual databases to be disabled */
 		if (lp_parm_bool(-1, "ctdb", partname, True)) {
-			result = db_open_ctdb(mem_ctx, partname, hash_size,
+			struct ctdbd_connection *conn;
+
+			conn = messaging_ctdbd_connection();
+			if (conn == NULL) {
+				DBG_WARNING("No ctdb connection\n");
+				errno = EIO;
+				return NULL;
+			}
+			result = db_open_ctdb(mem_ctx, conn, partname,
+					      hash_size,
 					      tdb_flags, open_flags, mode,
 					      lock_order, dbwrap_flags);
 			if (result == NULL) {
diff --git a/source3/torture/test_dbwrap_ctdb.c b/source3/torture/test_dbwrap_ctdb.c
index d7380b1..800b9fb 100644
--- a/source3/torture/test_dbwrap_ctdb.c
+++ b/source3/torture/test_dbwrap_ctdb.c
@@ -22,16 +22,24 @@
 #include "system/filesys.h"
 #include "lib/dbwrap/dbwrap.h"
 #include "lib/dbwrap/dbwrap_ctdb.h"
+#include "messages.h"
 
 bool run_local_dbwrap_ctdb(int dummy)
 {
-	struct db_context *db;
+	struct db_context *db = NULL;
 	int res;
 	bool ret = false;
 	NTSTATUS status;
 	uint32_t val;
+	struct ctdbd_connection *conn;
 
-	db = db_open_ctdb(talloc_tos(), "torture.tdb", 0, TDB_DEFAULT,
+	conn = messaging_ctdbd_connection();
+	if (conn == NULL) {
+		fprintf(stderr, "no ctdbd connection\n");
+		goto fail;
+	}
+
+	db = db_open_ctdb(talloc_tos(), conn, "torture.tdb", 0, TDB_DEFAULT,
 			  O_RDWR, 0755, DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
 	if (db == NULL) {
 		perror("db_open_ctdb failed");
-- 
1.9.1


From b4e24c144cb01e3842c58e3e398f532083a5a58f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 24 Apr 2016 17:37:07 +0200
Subject: [PATCH 09/12] dbwrap: Add "msg_ctx" to db_open_ctdb

Another step towards making ctdbd_conn.c independent of messages.c. No call to
ctdb_conn_msg_ctx() anymore

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/ctdb_dummy.c           | 1 +
 source3/lib/dbwrap/dbwrap_ctdb.c   | 4 ++--
 source3/lib/dbwrap/dbwrap_ctdb.h   | 1 +
 source3/lib/dbwrap/dbwrap_open.c   | 5 ++++-
 source3/torture/test_dbwrap_ctdb.c | 5 ++++-
 5 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index 0e061be..ec0bcc4 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -64,6 +64,7 @@ bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid
 }
 
 struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
+				struct messaging_context *msg_ctx,
 				struct ctdbd_connection *conn,
 				const char *name,
 				int hash_size, int tdb_flags,
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index cf03984..ea76abc 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1578,6 +1578,7 @@ static size_t db_ctdb_id(struct db_context *db, uint8_t *id, size_t idlen)
 }
 
 struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
+				struct messaging_context *msg_ctx,
 				struct ctdbd_connection *conn,
 				const char *name,
 				int hash_size, int tdb_flags,
@@ -1703,8 +1704,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
 	}
 
 	if (result->persistent) {
-		db_ctdb->lock_ctx = g_lock_ctx_init(
-			db_ctdb, ctdb_conn_msg_ctx(db_ctdb->conn));
+		db_ctdb->lock_ctx = g_lock_ctx_init(db_ctdb, msg_ctx);
 		if (db_ctdb->lock_ctx == NULL) {
 			DEBUG(0, ("g_lock_ctx_init failed\n"));
 			TALLOC_FREE(result);
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.h b/source3/lib/dbwrap/dbwrap_ctdb.h
index 2e4b93c..3f04702 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.h
+++ b/source3/lib/dbwrap/dbwrap_ctdb.h
@@ -29,6 +29,7 @@ struct db_context;
 struct ctdbd_connection;
 
 struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
+				struct messaging_context *msg_ctx,
 				struct ctdbd_connection *conn,
 				const char *name,
 				int hash_size, int tdb_flags,
diff --git a/source3/lib/dbwrap/dbwrap_open.c b/source3/lib/dbwrap/dbwrap_open.c
index 805e823..feb9f5e 100644
--- a/source3/lib/dbwrap/dbwrap_open.c
+++ b/source3/lib/dbwrap/dbwrap_open.c
@@ -144,6 +144,7 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
 		}
 		/* allow ctdb for individual databases to be disabled */
 		if (lp_parm_bool(-1, "ctdb", partname, True)) {
+			struct messaging_context *msg_ctx;
 			struct ctdbd_connection *conn;
 
 			conn = messaging_ctdbd_connection();
@@ -152,7 +153,9 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
 				errno = EIO;
 				return NULL;
 			}
-			result = db_open_ctdb(mem_ctx, conn, partname,
+			msg_ctx = server_messaging_context();
+
+			result = db_open_ctdb(mem_ctx, msg_ctx, conn, partname,
 					      hash_size,
 					      tdb_flags, open_flags, mode,
 					      lock_order, dbwrap_flags);
diff --git a/source3/torture/test_dbwrap_ctdb.c b/source3/torture/test_dbwrap_ctdb.c
index 800b9fb..b9bab9e 100644
--- a/source3/torture/test_dbwrap_ctdb.c
+++ b/source3/torture/test_dbwrap_ctdb.c
@@ -31,15 +31,18 @@ bool run_local_dbwrap_ctdb(int dummy)
 	bool ret = false;
 	NTSTATUS status;
 	uint32_t val;
+	struct messaging_context *msg_ctx;
 	struct ctdbd_connection *conn;
 
+	msg_ctx = server_messaging_context();
 	conn = messaging_ctdbd_connection();
 	if (conn == NULL) {
 		fprintf(stderr, "no ctdbd connection\n");
 		goto fail;
 	}
 
-	db = db_open_ctdb(talloc_tos(), conn, "torture.tdb", 0, TDB_DEFAULT,
+	db = db_open_ctdb(talloc_tos(), msg_ctx, conn, "torture.tdb",
+			  0, TDB_DEFAULT,
 			  O_RDWR, 0755, DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
 	if (db == NULL) {
 		perror("db_open_ctdb failed");
-- 
1.9.1


From 18209a917a2dd08ba7cd7e1160f22f3db39a841d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 24 Apr 2016 17:39:44 +0200
Subject: [PATCH 10/12] ctdbd_conn: Remove messages.h dependency

This removes a circular dependency

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/ctdbd_conn.h |  5 ----
 source3/lib/ctdbd_conn.c     | 58 --------------------------------------------
 2 files changed, 63 deletions(-)

diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 282379d..11e71ba 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -36,11 +36,6 @@ int ctdbd_init_connection(TALLOC_CTX *mem_ctx,
 
 uint32_t ctdbd_vnn(const struct ctdbd_connection *conn);
 
-int ctdbd_register_msg_ctx(struct ctdbd_connection *conn,
-			   struct messaging_context *msg_ctx,
-			   struct tevent_context *ev);
-struct messaging_context *ctdb_conn_msg_ctx(struct ctdbd_connection *conn);
-
 int ctdbd_conn_get_fd(struct ctdbd_connection *conn);
 void ctdbd_socket_readable(struct ctdbd_connection *conn);
 
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index e54ec7e..6cb6814 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -31,8 +31,6 @@
 #include "lib/util/genrand.h"
 #include "lib/util/fault.h"
 
-#include "messages.h"
-
 /* paths to these include files come from --with-ctdb= in configure */
 
 #include "ctdb_private.h"
@@ -47,7 +45,6 @@ struct ctdbd_srvid_cb {
 };
 
 struct ctdbd_connection {
-	struct messaging_context *msg_ctx;
 	uint32_t reqid;
 	uint32_t our_vnn;
 	uint64_t rand_srvid;
@@ -376,14 +373,6 @@ static int ctdb_read_req(struct ctdbd_connection *conn, uint32_t reqid,
 	if (hdr->operation == CTDB_REQ_MESSAGE) {
 		struct ctdb_req_message_old *msg = (struct ctdb_req_message_old *)hdr;
 
-		if (conn->msg_ctx == NULL) {
-			DEBUG(1, ("Got a message without having a msg ctx, "
-				  "dropping msg %llu\n",
-				  (long long unsigned)msg->srvid));
-			TALLOC_FREE(hdr);
-			goto next_pkt;
-		}
-
 		ret = ctdbd_msg_call_back(conn, msg);
 		if (ret != 0) {
 			TALLOC_FREE(hdr);
@@ -477,11 +466,6 @@ int ctdbd_init_connection(TALLOC_CTX *mem_ctx,
 	return ret;
 }
 
-struct messaging_context *ctdb_conn_msg_ctx(struct ctdbd_connection *conn)
-{
-	return conn->msg_ctx;
-}
-
 int ctdbd_conn_get_fd(struct ctdbd_connection *conn)
 {
 	return conn->fd;
@@ -529,48 +513,6 @@ void ctdbd_socket_readable(struct ctdbd_connection *conn)
 	}
 }
 
-/*
- * The ctdbd socket is readable asynchronuously
- */
-
-static void ctdbd_socket_handler(struct tevent_context *event_ctx,
-				 struct tevent_fd *event,
-				 uint16_t flags,
-				 void *private_data)
-{
-	struct ctdbd_connection *conn = talloc_get_type_abort(
-		private_data, struct ctdbd_connection);
-
-	if ((flags & TEVENT_FD_READ) == 0) {
-		return;
-	}
-
-	ctdbd_socket_readable(conn);
-}
-
-/*
- * Prepare a ctdbd connection to receive messages
- */
-
-int ctdbd_register_msg_ctx(struct ctdbd_connection *conn,
-			   struct messaging_context *msg_ctx,
-			   struct tevent_context *ev)
-{
-	SMB_ASSERT(conn->msg_ctx == NULL);
-	SMB_ASSERT(conn->fde == NULL);
-
-	conn->fde = tevent_add_fd(ev, conn, conn->fd, TEVENT_FD_READ,
-				  ctdbd_socket_handler, conn);
-	if (conn->fde == NULL) {
-		DEBUG(0, ("event_add_fd failed\n"));
-		return ENOMEM;
-	}
-
-	conn->msg_ctx = msg_ctx;
-
-	return 0;
-}
-
 int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
 			     uint32_t dst_vnn, uint64_t dst_srvid,
 			     const struct iovec *iov, int iovlen)
-- 
1.9.1


From 5dd430da07533165537df1ed6a4e8a6565e65549 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 11 Apr 2016 16:07:12 +0200
Subject: [PATCH 11/12] dbwrap_ctdb: Fix some 32-bit hickups

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/dbwrap/dbwrap_ctdb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index ea76abc..d48d999 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1100,9 +1100,11 @@ again:
 
 		migrate_attempts += 1;
 
-		DEBUG(10, ("ctdb_data.dptr = %p, dmaster = %u (%u) %u\n",
+		DEBUG(10, ("ctdb_data.dptr = %p, dmaster = %"PRIu32" "
+			   "(%"PRIu32") %"PRIu32"\n",
 			   ctdb_data.dptr, ctdb_data.dptr ?
-			   ((struct ctdb_ltdb_header *)ctdb_data.dptr)->dmaster : -1,
+			   ((struct ctdb_ltdb_header *)ctdb_data.dptr)->dmaster :
+			   UINT32_MAX,
 			   get_my_vnn(),
 			   ctdb_data.dptr ?
 			   ((struct ctdb_ltdb_header *)ctdb_data.dptr)->flags : 0));
-- 
1.9.1


From fbfdd69581fe34bbfa8052b09505bc19fab4f40c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 11 Apr 2016 16:31:25 +0200
Subject: [PATCH 12/12] dbwrap_ctdb: Remove get_my_vnn dependency

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/dbwrap/dbwrap_ctdb.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index d48d999..df5a34f 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -590,7 +590,7 @@ static NTSTATUS db_ctdb_transaction_store(struct db_ctdb_transaction_handle *h,
 		SAFE_FREE(rec.dptr);
 	}
 
-	header.dmaster = get_my_vnn();
+	header.dmaster = ctdbd_vnn(h->ctx->conn);
 	header.rsn++;
 
 	h->m_write = db_ctdb_marshall_add(h, h->m_write, h->ctx->db_id, 0, key, &header, data);
@@ -978,9 +978,9 @@ static int db_ctdb_record_destr(struct db_record* data)
  * either for reading or for writing.
  */
 static bool db_ctdb_can_use_local_hdr(const struct ctdb_ltdb_header *hdr,
-				      bool read_only)
+				      uint32_t my_vnn, bool read_only)
 {
-	if (hdr->dmaster != get_my_vnn()) {
+	if (hdr->dmaster != my_vnn) {
 		/* If we're not dmaster, it must be r/o copy. */
 		return read_only && (hdr->flags & CTDB_REC_RO_HAVE_READONLY);
 	}
@@ -991,7 +991,8 @@ static bool db_ctdb_can_use_local_hdr(const struct ctdb_ltdb_header *hdr,
 	return read_only || !(hdr->flags & CTDB_REC_RO_HAVE_DELEGATIONS);
 }
 
-static bool db_ctdb_can_use_local_copy(TDB_DATA ctdb_data, bool read_only)
+static bool db_ctdb_can_use_local_copy(TDB_DATA ctdb_data, uint32_t my_vnn,
+				       bool read_only)
 {
 	if (ctdb_data.dptr == NULL) {
 		return false;
@@ -1002,7 +1003,7 @@ static bool db_ctdb_can_use_local_copy(TDB_DATA ctdb_data, bool read_only)
 	}
 
 	return db_ctdb_can_use_local_hdr(
-		(struct ctdb_ltdb_header *)ctdb_data.dptr, read_only);
+		(struct ctdb_ltdb_header *)ctdb_data.dptr, my_vnn, read_only);
 }
 
 static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx,
@@ -1087,7 +1088,8 @@ again:
 	 * take the shortcut and just return it.
 	 */
 
-	if (!db_ctdb_can_use_local_copy(ctdb_data, false)) {
+	if (!db_ctdb_can_use_local_copy(ctdb_data, ctdbd_vnn(ctx->conn),
+					false)) {
 		SAFE_FREE(ctdb_data.dptr);
 		tdb_chainunlock(ctx->wtdb->tdb, key);
 		talloc_set_destructor(result, NULL);
@@ -1105,7 +1107,7 @@ again:
 			   ctdb_data.dptr, ctdb_data.dptr ?
 			   ((struct ctdb_ltdb_header *)ctdb_data.dptr)->dmaster :
 			   UINT32_MAX,
-			   get_my_vnn(),
+			   ctdbd_vnn(ctx->conn),
 			   ctdb_data.dptr ?
 			   ((struct ctdb_ltdb_header *)ctdb_data.dptr)->flags : 0));
 
@@ -1216,6 +1218,7 @@ static struct db_record *db_ctdb_try_fetch_locked(struct db_context *db,
 struct db_ctdb_parse_record_state {
 	void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data);
 	void *private_data;
+	uint32_t my_vnn;
 	bool ask_for_readonly_copy;
 	bool done;
 };
@@ -1236,7 +1239,7 @@ static void db_ctdb_parse_record_parser_nonpersistent(
 	struct db_ctdb_parse_record_state *state =
 		(struct db_ctdb_parse_record_state *)private_data;
 
-	if (db_ctdb_can_use_local_hdr(header, true)) {
+	if (db_ctdb_can_use_local_hdr(header, state->my_vnn, true)) {
 		state->parser(key, data, state->private_data);
 		state->done = true;
 	} else {
@@ -1263,6 +1266,7 @@ static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key,
 
 	state.parser = parser;
 	state.private_data = private_data;
+	state.my_vnn = ctdbd_vnn(ctx->conn);
 
 	if (ctx->transaction != NULL) {
 		struct db_ctdb_transaction_handle *h = ctx->transaction;
-- 
1.9.1



More information about the samba-technical mailing list