[SCM] CTDB repository - branch master updated - ctdb-1.10-418-ge255590

Michael Adam obnox at samba.org
Mon Aug 22 09:12:39 MDT 2011


The branch, master has been updated
       via  e25559087c9752502580875f7e33f3c416c05f84 (commit)
       via  04c3d9c7c9ffa8bb95b0bf1513fd79f6c1096a2f (commit)
       via  bb8f68f0256c43fe0671fe45023d1c88e340ad96 (commit)
       via  77ae553249ef1e1d467d792ac033f2aaa4e337e6 (commit)
       via  5a5ed2a43b76bec69494b6cdc6451527f5c472e5 (commit)
       via  06433d20a43d41f05b96a9dda6dc5931539feaa3 (commit)
       via  955f67a02026b157440d2ae87ead193773331e75 (commit)
       via  fa6564c24429e084be728dbe6eea1dec13e58709 (commit)
       via  4bceba374be82e76ba5d9d923172e85e9365b990 (commit)
       via  883b9b185dce03a6bf233fbf2cfabad9883519e5 (commit)
       via  e0f93459e05eef33024096654b4aaf1eb3c6d7c4 (commit)
       via  683caa7bbf45d5b6791e53e2f3ee6d0ac3b08f28 (commit)
      from  4bfdfdae4f8ab23f14bc6ab4c06b66c07714ec17 (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e25559087c9752502580875f7e33f3c416c05f84
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 22 16:40:58 2011 +0200

    Fix a const warning
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 04c3d9c7c9ffa8bb95b0bf1513fd79f6c1096a2f
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 22 16:39:32 2011 +0200

    Remove an unused variable
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit bb8f68f0256c43fe0671fe45023d1c88e340ad96
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 19 17:05:36 2011 +0200

    libctdb: "unpack_reply_control" does not need the ctdb_connection parameter
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 77ae553249ef1e1d467d792ac033f2aaa4e337e6
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 19 17:05:36 2011 +0200

    libctdb: "unpack_reply_call" does not need the ctdb_connection parameter
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 5a5ed2a43b76bec69494b6cdc6451527f5c472e5
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 19 17:05:36 2011 +0200

    libctdb: "ctdb_request_free" does not need the ctdb_connection parameter
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 06433d20a43d41f05b96a9dda6dc5931539feaa3
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 19 16:36:20 2011 +0200

    libctdb: Make sure ctdb_request->ctdb is filled correctly
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 955f67a02026b157440d2ae87ead193773331e75
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 18 14:47:09 2011 +0200

    libctdb: Ensure 0-termination of sun_path
    
    Rusty, please check!
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit fa6564c24429e084be728dbe6eea1dec13e58709
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 18 13:59:48 2011 +0200

    libctdb: Fix a few format warnings
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 4bceba374be82e76ba5d9d923172e85e9365b990
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 18 13:57:58 2011 +0200

    libctdb: Add license header to messages.c
    
    Rusty, please check!
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 883b9b185dce03a6bf233fbf2cfabad9883519e5
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 18 13:37:23 2011 +0200

    libctdb: Reorder attachdb
    
    No code change, this is for easier reading the sequence of what happens
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit e0f93459e05eef33024096654b4aaf1eb3c6d7c4
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 18 13:55:24 2011 +0200

    libctdb: Reorder set_message_handler
    
    No code change, this is for better readability
    
    Signed-off-by: Michael Adam <obnox at samba.org>

commit 683caa7bbf45d5b6791e53e2f3ee6d0ac3b08f28
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 18 13:54:36 2011 +0200

    libctdb: Correct 4bfdfda, stddef.h is needed by libctdb_private.h
    
    Signed-off-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 common/ctdb_ltdb.c        |    2 -
 include/ctdb.h            |    2 +-
 libctdb/control.c         |    8 +-
 libctdb/ctdb.c            |  237 ++++++++++++++++++++++++---------------------
 libctdb/libctdb_private.h |    7 +-
 libctdb/messages.c        |   90 +++++++++++-------
 libctdb/sync.c            |   14 ++--
 libctdb/tst.c             |   10 +-
 server/ctdb_takeover.c    |    2 +-
 9 files changed, 203 insertions(+), 169 deletions(-)


Changeset truncated at 500 lines:

diff --git a/common/ctdb_ltdb.c b/common/ctdb_ltdb.c
index 3ee7fe8..0dc8711 100644
--- a/common/ctdb_ltdb.c
+++ b/common/ctdb_ltdb.c
@@ -206,8 +206,6 @@ int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key)
 */
 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key)
 {
-	struct ctdb_context *ctdb = ctdb_db->ctdb;
-
 	if (ctdb_db->persistent != 0) {
 		DEBUG(DEBUG_ERR,("Trying to delete emty record in persistent database\n"));
 		return 0;
diff --git a/include/ctdb.h b/include/ctdb.h
index c95c2e1..fad3233 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -173,7 +173,7 @@ struct ctdb_request;
  * This frees a request: you should only call it once it has been
  * handed to your callback.  For incomplete requests, see ctdb_cancel().
  */
-void ctdb_request_free(struct ctdb_connection *ctdb, struct ctdb_request *req);
+void ctdb_request_free(struct ctdb_request *req);
 
 /**
  * ctdb_callback_t - callback for completed requests.
diff --git a/libctdb/control.c b/libctdb/control.c
index 07185db..e18a44e 100644
--- a/libctdb/control.c
+++ b/libctdb/control.c
@@ -32,7 +32,7 @@ bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
 {
 	struct ctdb_reply_control *reply;
 
-	reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_RECMASTER);
+	reply = unpack_reply_control(req, CTDB_CONTROL_GET_RECMASTER);
 	if (!reply) {
 		return false;
 	}
@@ -59,7 +59,7 @@ bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
 {
 	struct ctdb_reply_control *reply;
 
-	reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_PNN);
+	reply = unpack_reply_control(req, CTDB_CONTROL_GET_PNN);
 	if (!reply) {
 		return false;
 	}
@@ -86,7 +86,7 @@ bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
 	struct ctdb_reply_control *reply;
 
 	*nodemap = NULL;
-	reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_NODEMAP);
+	reply = unpack_reply_control(req, CTDB_CONTROL_GET_NODEMAP);
 	if (!reply) {
 		return false;
 	}
@@ -133,7 +133,7 @@ bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
 	struct ctdb_reply_control *reply;
 
 	*ips = NULL;
-	reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_PUBLIC_IPS);
+	reply = unpack_reply_control(req, CTDB_CONTROL_GET_PUBLIC_IPS);
 	if (!reply) {
 		return false;
 	}
diff --git a/libctdb/ctdb.c b/libctdb/ctdb.c
index 80f8bb5..e407910 100644
--- a/libctdb/ctdb.c
+++ b/libctdb/ctdb.c
@@ -25,7 +25,6 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/ioctl.h>
-#include <stddef.h>
 #include "libctdb_private.h"
 #include "io_elem.h"
 #include "local_tdb.h"
@@ -134,7 +133,7 @@ static void set_pnn(struct ctdb_connection *ctdb,
 		      "ctdb_connect(async): failed to get pnn");
 		ctdb->broken = true;
 	}
-	ctdb_request_free(ctdb, req);
+	ctdb_request_free(req);
 }
 
 struct ctdb_connection *ctdb_connect(const char *addr,
@@ -167,7 +166,7 @@ struct ctdb_connection *ctdb_connect(const char *addr,
 	sun.sun_family = AF_UNIX;
 	if (!addr)
 		addr = CTDB_PATH;
-	strncpy(sun.sun_path, addr, sizeof(sun.sun_path));
+	strncpy(sun.sun_path, addr, sizeof(sun.sun_path)-1);
 	ctdb->fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (ctdb->fd < 0)
 		goto free_fail;
@@ -200,12 +199,12 @@ void ctdb_disconnect(struct ctdb_connection *ctdb)
 
 	while ((i = ctdb->outq) != NULL) {
 		DLIST_REMOVE(ctdb->outq, i);
-		ctdb_request_free(ctdb, i);
+		ctdb_request_free(i);
 	}
 
 	while ((i = ctdb->doneq) != NULL) {
 		DLIST_REMOVE(ctdb->doneq, i);
-		ctdb_request_free(ctdb, i);
+		ctdb_request_free(i);
 	}
 
 	if (ctdb->in)
@@ -233,7 +232,7 @@ int ctdb_which_events(struct ctdb_connection *ctdb)
 	return events;
 }
 
-struct ctdb_request *new_ctdb_request(size_t len,
+struct ctdb_request *new_ctdb_request(struct ctdb_connection *ctdb, size_t len,
 				      ctdb_callback_t cb, void *cbdata)
 {
 	struct ctdb_request *req = malloc(sizeof(*req));
@@ -244,6 +243,7 @@ struct ctdb_request *new_ctdb_request(size_t len,
 		free(req);
 		return NULL;
 	}
+	req->ctdb = ctdb;
 	req->hdr.hdr = io_elem_data(req->io, NULL);
 	req->reply = NULL;
 	req->callback = cb;
@@ -253,8 +253,10 @@ struct ctdb_request *new_ctdb_request(size_t len,
 	return req;
 }
 
-void ctdb_request_free(struct ctdb_connection *ctdb, struct ctdb_request *req)
+void ctdb_request_free(struct ctdb_request *req)
 {
+	struct ctdb_connection *ctdb = req->ctdb;
+
 	if (req->next || req->prev) {
 		DEBUG(ctdb, LOG_ALERT,
 		      "ctdb_request_free: request not complete! ctdb_cancel? %p (id %u)",
@@ -273,8 +275,7 @@ void ctdb_request_free(struct ctdb_connection *ctdb, struct ctdb_request *req)
 }
 
 /* Sanity-checking wrapper for reply. */
-static struct ctdb_reply_call *unpack_reply_call(struct ctdb_connection *ctdb,
-						 struct ctdb_request *req,
+static struct ctdb_reply_call *unpack_reply_call(struct ctdb_request *req,
 						 uint32_t callid)
 {
 	size_t len;
@@ -283,7 +284,7 @@ static struct ctdb_reply_call *unpack_reply_call(struct ctdb_connection *ctdb,
 	/* Library user error if this isn't a reply to a call. */
 	if (req->hdr.hdr->operation != CTDB_REQ_CALL) {
 		errno = EINVAL;
-		DEBUG(ctdb, LOG_ALERT,
+		DEBUG(req->ctdb, LOG_ALERT,
 		      "This was not a ctdbd call request: operation %u",
 		      req->hdr.hdr->operation);
 		return NULL;
@@ -291,7 +292,7 @@ static struct ctdb_reply_call *unpack_reply_call(struct ctdb_connection *ctdb,
 
 	if (req->hdr.call->callid != callid) {
 		errno = EINVAL;
-		DEBUG(ctdb, LOG_ALERT,
+		DEBUG(req->ctdb, LOG_ALERT,
 		      "This was not a ctdbd %u call request: %u",
 		      callid, req->hdr.call->callid);
 		return NULL;
@@ -300,7 +301,7 @@ static struct ctdb_reply_call *unpack_reply_call(struct ctdb_connection *ctdb,
 	/* ctdbd or our error if this isn't a reply call. */
 	if (len < sizeof(*inhdr) || inhdr->hdr.operation != CTDB_REPLY_CALL) {
 		errno = EIO;
-		DEBUG(ctdb, LOG_CRIT,
+		DEBUG(req->ctdb, LOG_CRIT,
 		      "Invalid ctdbd call reply: len %zu, operation %u",
 		      len, inhdr->hdr.operation);
 		return NULL;
@@ -310,8 +311,7 @@ static struct ctdb_reply_call *unpack_reply_call(struct ctdb_connection *ctdb,
 }
 
 /* Sanity-checking wrapper for reply. */
-struct ctdb_reply_control *unpack_reply_control(struct ctdb_connection *ctdb,
-						struct ctdb_request *req,
+struct ctdb_reply_control *unpack_reply_control(struct ctdb_request *req,
 						enum ctdb_controls control)
 {
 	size_t len;
@@ -320,13 +320,13 @@ struct ctdb_reply_control *unpack_reply_control(struct ctdb_connection *ctdb,
 	/* Library user error if this isn't a reply to a call. */
 	if (len < sizeof(*inhdr)) {
 		errno = EINVAL;
-		DEBUG(ctdb, LOG_ALERT,
+		DEBUG(req->ctdb, LOG_ALERT,
 		      "Short ctdbd control reply: %zu bytes", len);
 		return NULL;
 	}
 	if (req->hdr.hdr->operation != CTDB_REQ_CONTROL) {
 		errno = EINVAL;
-		DEBUG(ctdb, LOG_ALERT,
+		DEBUG(req->ctdb, LOG_ALERT,
 		      "This was not a ctdbd control request: operation %u",
 		      req->hdr.hdr->operation);
 		return NULL;
@@ -335,7 +335,7 @@ struct ctdb_reply_control *unpack_reply_control(struct ctdb_connection *ctdb,
 	/* ... or if it was a different control from what we expected. */
 	if (req->hdr.control->opcode != control) {
 		errno = EINVAL;
-		DEBUG(ctdb, LOG_ALERT,
+		DEBUG(req->ctdb, LOG_ALERT,
 		      "This was not an opcode %u ctdbd control request: %u",
 		      control, req->hdr.control->opcode);
 		return NULL;
@@ -344,7 +344,7 @@ struct ctdb_reply_control *unpack_reply_control(struct ctdb_connection *ctdb,
 	/* ctdbd or our error if this isn't a reply call. */
 	if (inhdr->hdr.operation != CTDB_REPLY_CONTROL) {
 		errno = EIO;
-		DEBUG(ctdb, LOG_CRIT,
+		DEBUG(req->ctdb, LOG_CRIT,
 		      "Invalid ctdbd control reply: operation %u",
 		      inhdr->hdr.operation);
 		return NULL;
@@ -510,7 +510,9 @@ struct ctdb_request *new_ctdb_control_request(struct ctdb_connection *ctdb,
 	struct ctdb_request *req;
 	struct ctdb_req_control *pkt;
 
-	req = new_ctdb_request(offsetof(struct ctdb_req_control, data) + extra, callback, cbdata);
+	req = new_ctdb_request(
+		ctdb, offsetof(struct ctdb_req_control, data) + extra,
+		callback, cbdata);
 	if (!req)
 		return NULL;
 
@@ -533,7 +535,7 @@ void ctdb_cancel_callback(struct ctdb_connection *ctdb,
 			  struct ctdb_request *req,
 			  void *unused)
 {
-	ctdb_request_free(ctdb, req);
+	ctdb_request_free(req);
 }
 
 void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req)
@@ -542,7 +544,7 @@ void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req)
 		DEBUG(ctdb, LOG_ALERT,
 		      "ctdb_cancel: request completed! ctdb_request_free? %p (id %u)",
 		      req, req->hdr.hdr ? req->hdr.hdr->reqid : 0);
-		ctdb_request_free(ctdb, req);
+		ctdb_request_free(req);
 		return;
 	}
 
@@ -560,61 +562,71 @@ void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db)
 	free(db);
 }
 
+static void destroy_req_db(struct ctdb_connection *ctdb,
+			   struct ctdb_request *req);
+static void attachdb_done(struct ctdb_connection *ctdb,
+			  struct ctdb_request *req,
+			  void *_db);
 static void attachdb_getdbpath_done(struct ctdb_connection *ctdb,
 				    struct ctdb_request *req,
-				    void *_db)
-{
-	struct ctdb_db *db = _db;
+				    void *_db);
 
-	/* Do callback on original request. */
-	db->callback(ctdb, req->extra, db->private_data);
-}
-
-struct ctdb_db *ctdb_attachdb_recv(struct ctdb_connection *ctdb,
-				   struct ctdb_request *req)
+struct ctdb_request *
+ctdb_attachdb_send(struct ctdb_connection *ctdb,
+		   const char *name, bool persistent, uint32_t tdb_flags,
+		   ctdb_callback_t callback, void *private_data)
 {
-	struct ctdb_request *dbpath_req = req->extra;
-	struct ctdb_reply_control *reply;
-	struct ctdb_db *db = req->priv_data;
-	uint32_t tdb_flags = db->tdb_flags;
-	struct tdb_logging_context log;
+	struct ctdb_request *req;
+	struct ctdb_db *db;
+	uint32_t opcode;
 
-	/* Never sent the dbpath request?  We've failed. */
-	if (!dbpath_req) {
-		/* FIXME: Save errno? */
-		errno = EINVAL;
+	/* FIXME: Search if db already open. */
+	db = malloc(sizeof(*db));
+	if (!db) {
 		return NULL;
 	}
 
-	reply = unpack_reply_control(ctdb, dbpath_req, CTDB_CONTROL_GETDBPATH);
-	if (!reply) {
-		return NULL;
+	if (persistent) {
+		opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
+	} else {
+		opcode = CTDB_CONTROL_DB_ATTACH;
 	}
-	if (reply->status != 0) {
-		DEBUG(db->ctdb, LOG_ERR,
-		      "ctdb_attachdb_recv: reply status %i", reply->status);
+
+	req = new_ctdb_control_request(ctdb, opcode, CTDB_CURRENT_NODE, name,
+				       strlen(name) + 1, attachdb_done, db);
+	if (!req) {
+		DEBUG(ctdb, LOG_ERR,
+		      "ctdb_attachdb_send: failed allocating DB_ATTACH");
+		free(db);
 		return NULL;
 	}
 
-	tdb_flags = db->persistent ? TDB_DEFAULT : TDB_NOSYNC;
-	tdb_flags |= TDB_DISALLOW_NESTING;
+	db->ctdb = ctdb;
+	db->tdb_flags = tdb_flags;
+	db->persistent = persistent;
+	db->callback = callback;
+	db->private_data = private_data;
 
-	log.log_fn = ctdb_tdb_log_bridge;
-	log.log_private = ctdb;
-	db->tdb = tdb_open_ex((char *)reply->data, 0, tdb_flags, O_RDWR, 0,
-			      &log, NULL);
-	if (db->tdb == NULL) {
-		DEBUG(db->ctdb, LOG_ERR,
-		      "ctdb_attachdb_recv: failed to tdb_open %s",
-		      (char *)reply->data);
-		return NULL;
-	}
+	req->extra_destructor = destroy_req_db;
+	/* This is set non-NULL when we succeed, see ctdb_attachdb_recv */
+	req->extra = NULL;
 
-	/* Finally, separate the db from the request (see destroy_req_db). */
-	req->priv_data = NULL;
+	/* Flags get overloaded into srvid. */
+	req->hdr.control->srvid = tdb_flags;
 	DEBUG(db->ctdb, LOG_DEBUG,
-	      "ctdb_attachdb_recv: db %p, tdb %s", db, (char *)reply->data);
-	return db;
+	      "ctdb_attachdb_send: DB_ATTACH request %p", req);
+	return req;
+}
+
+static void destroy_req_db(struct ctdb_connection *ctdb,
+			   struct ctdb_request *req)
+{
+	/* Incomplete db is in priv_data. */
+	free(req->priv_data);
+	/* second request is chained off this one. */
+	if (req->extra) {
+		ctdb_request_free(req->extra);
+	}
 }
 
 static void attachdb_done(struct ctdb_connection *ctdb,
@@ -630,7 +642,7 @@ static void attachdb_done(struct ctdb_connection *ctdb,
 		control = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
 	}
 
-	reply = unpack_reply_control(ctdb, req, control);
+	reply = unpack_reply_control(req, control);
 	if (!reply || reply->status != 0) {
 		if (reply) {
 			DEBUG(ctdb, LOG_ERR,
@@ -661,62 +673,61 @@ static void attachdb_done(struct ctdb_connection *ctdb,
 	      "ctdb_attachdb_send(async): created getdbpath request");
 }
 
-static void destroy_req_db(struct ctdb_connection *ctdb,
-			   struct ctdb_request *req)
+static void attachdb_getdbpath_done(struct ctdb_connection *ctdb,
+				    struct ctdb_request *req,
+				    void *_db)
 {
-	/* Incomplete db is in priv_data. */
-	free(req->priv_data);
-	/* second request is chained off this one. */
-	if (req->extra) {
-		ctdb_request_free(ctdb, req->extra);
-	}
+	struct ctdb_db *db = _db;
+
+	/* Do callback on original request. */
+	db->callback(ctdb, req->extra, db->private_data);
 }
 
-struct ctdb_request *
-ctdb_attachdb_send(struct ctdb_connection *ctdb,
-		   const char *name, bool persistent, uint32_t tdb_flags,
-		   ctdb_callback_t callback, void *private_data)
+struct ctdb_db *ctdb_attachdb_recv(struct ctdb_connection *ctdb,
+				   struct ctdb_request *req)
 {
-	struct ctdb_request *req;
-	struct ctdb_db *db;
-	uint32_t opcode;
+	struct ctdb_request *dbpath_req = req->extra;
+	struct ctdb_reply_control *reply;
+	struct ctdb_db *db = req->priv_data;
+	uint32_t tdb_flags = db->tdb_flags;
+	struct tdb_logging_context log;
 
-	/* FIXME: Search if db already open. */
-	db = malloc(sizeof(*db));
-	if (!db) {
+	/* Never sent the dbpath request?  We've failed. */
+	if (!dbpath_req) {
+		/* FIXME: Save errno? */
+		errno = EINVAL;
 		return NULL;
 	}
 
-	if (persistent) {
-		opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
-	} else {
-		opcode = CTDB_CONTROL_DB_ATTACH;
+	reply = unpack_reply_control(dbpath_req, CTDB_CONTROL_GETDBPATH);
+	if (!reply) {
+		return NULL;
 	}
-
-	req = new_ctdb_control_request(ctdb, opcode, CTDB_CURRENT_NODE, name,
-				       strlen(name) + 1, attachdb_done, db);
-	if (!req) {
-		DEBUG(ctdb, LOG_ERR,
-		      "ctdb_attachdb_send: failed allocating DB_ATTACH");
-		free(db);
+	if (reply->status != 0) {
+		DEBUG(db->ctdb, LOG_ERR,
+		      "ctdb_attachdb_recv: reply status %i", reply->status);
 		return NULL;
 	}
 
-	db->ctdb = ctdb;
-	db->tdb_flags = tdb_flags;
-	db->persistent = persistent;
-	db->callback = callback;
-	db->private_data = private_data;
+	tdb_flags = db->persistent ? TDB_DEFAULT : TDB_NOSYNC;
+	tdb_flags |= TDB_DISALLOW_NESTING;
 
-	req->extra_destructor = destroy_req_db;
-	/* This is set non-NULL when we succeed, see ctdb_attachdb_recv */
-	req->extra = NULL;
+	log.log_fn = ctdb_tdb_log_bridge;
+	log.log_private = ctdb;
+	db->tdb = tdb_open_ex((char *)reply->data, 0, tdb_flags, O_RDWR, 0,
+			      &log, NULL);
+	if (db->tdb == NULL) {
+		DEBUG(db->ctdb, LOG_ERR,
+		      "ctdb_attachdb_recv: failed to tdb_open %s",
+		      (char *)reply->data);
+		return NULL;
+	}
 
-	/* Flags get overloaded into srvid. */
-	req->hdr.control->srvid = tdb_flags;
+	/* Finally, separate the db from the request (see destroy_req_db). */
+	req->priv_data = NULL;
 	DEBUG(db->ctdb, LOG_DEBUG,
-	      "ctdb_attachdb_send: DB_ATTACH request %p", req);
-	return req;
+	      "ctdb_attachdb_recv: db %p, tdb %s", db, (char *)reply->data);
+	return db;
 }
 
 static unsigned long lock_magic(struct ctdb_lock *lock)
@@ -801,7 +812,7 @@ static void readrecordlock_retry(struct ctdb_connection *ctdb,
 	TDB_DATA data;
 
 	/* OK, we've received reply to noop migration */
-	reply = unpack_reply_call(ctdb, req, CTDB_NULL_FUNC);
+	reply = unpack_reply_call(req, CTDB_NULL_FUNC);
 	if (!reply || reply->status != 0) {
 		if (reply) {
 			DEBUG(ctdb, LOG_ERR,
@@ -809,7 +820,7 @@ static void readrecordlock_retry(struct ctdb_connection *ctdb,
 			      " NULL_FUNC returned %i", reply->status);
 		}
 		lock->callback(lock->ctdb_db, NULL, tdb_null, private);
-		ctdb_request_free(ctdb, req); /* Also frees lock. */
+		ctdb_request_free(req); /* Also frees lock. */
 		return;
 	}
 
@@ -818,7 +829,7 @@ static void readrecordlock_retry(struct ctdb_connection *ctdb,
 		/* Now it's their responsibility to free lock & request! */
 		req->extra_destructor = NULL;
 		lock->callback(lock->ctdb_db, lock, data, private);
-		ctdb_request_free(ctdb, req);
+		ctdb_request_free(req);
 		return;
 	}


-- 
CTDB repository


More information about the samba-cvs mailing list