[SCM] CTDB repository - branch 1.2.40 updated - ctdb-1.9.1-539-g7bbd5f6

Ronnie Sahlberg sahlberg at samba.org
Sun Feb 26 13:32:55 MST 2012


The branch, 1.2.40 has been updated
       via  7bbd5f6c68f0a816249eddbbc64f34bd929c43d3 (commit)
       via  4b34a14912e8fd58f0ce755ef4378cce931b8828 (commit)
       via  f78136d04ff41e8d22c61351c73f1607cbda7dc5 (commit)
      from  22138474060cba8c3a9b8b863488655ff6926258 (commit)

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


- Log -----------------------------------------------------------------
commit 7bbd5f6c68f0a816249eddbbc64f34bd929c43d3
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Feb 27 07:18:19 2012 +1100

    Make KILLTCP structure a child of VNN so that it is freed at the same time
    the referenced VNN structure is.
    
    Also, remove the circular reference between the two objects KIPPCTP and VNN

commit 4b34a14912e8fd58f0ce755ef4378cce931b8828
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Feb 22 17:43:04 2012 +1100

    make tdb valgrind-happy

commit f78136d04ff41e8d22c61351c73f1607cbda7dc5
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Feb 22 17:38:12 2012 +1100

    Eventscripts: remove the horrible horrible circular reference between state and callback since these two structures do not even share the same parent talloc context.
    Instead, tie them together via referencing a permanent linked list hung off the ctdb structure.

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

Summary of changes:
 include/ctdb_private.h |    3 +++
 lib/tdb/common/hash.c  |    1 +
 server/ctdb_takeover.c |   22 +++++++++++++++++++---
 server/eventscript.c   |   26 +++++++++++++++++++-------
 4 files changed, 42 insertions(+), 10 deletions(-)


Changeset truncated at 500 lines:

diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index b48f84a..4edb647 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -495,6 +495,9 @@ struct ctdb_context {
 
 	/* Used to defer db attach requests while in recovery mode */
 	struct ctdb_deferred_attach_context *deferred_attach;
+
+	/* list of event script callback functions that are active */
+	struct event_script_callback *script_callbacks;
 };
 
 struct ctdb_db_context {
diff --git a/lib/tdb/common/hash.c b/lib/tdb/common/hash.c
index c07297e..e8f7555 100644
--- a/lib/tdb/common/hash.c
+++ b/lib/tdb/common/hash.c
@@ -23,6 +23,7 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include "tdb_private.h"
+#define VALGRIND
 
 /* This is based on the hash algorithm from gdbm */
 unsigned int tdb_old_hash(TDB_DATA *key)
diff --git a/server/ctdb_takeover.c b/server/ctdb_takeover.c
index b2e1a8d..9cbafaf 100644
--- a/server/ctdb_takeover.c
+++ b/server/ctdb_takeover.c
@@ -2880,9 +2880,25 @@ static void ctdb_tickle_sentenced_connections(struct event_context *ev, struct t
  */
 static int ctdb_killtcp_destructor(struct ctdb_kill_tcp *killtcp)
 {
-	if (killtcp->vnn) {
-		killtcp->vnn->killtcp = NULL;
+	struct ctdb_vnn *tmpvnn;
+
+	/* verify that this vnn is still active */
+	for (tmpvnn = killtcp->ctdb->vnn; tmpvnn; tmpvnn = tmpvnn->next) {
+		if (tmpvnn == killtcp->vnn) {
+			break;
+		}
+	}
+
+	if (tmpvnn == NULL) {
+		return 0;
 	}
+
+	if (killtcp->vnn->killtcp != killtcp) {
+		return 0;
+	}
+
+	killtcp->vnn->killtcp = NULL;
+
 	return 0;
 }
 
@@ -2937,7 +2953,7 @@ static int ctdb_killtcp_add_connection(struct ctdb_context *ctdb,
 	   a new structure
 	 */
 	if (killtcp == NULL) {
-		killtcp = talloc_zero(ctdb, struct ctdb_kill_tcp);
+		killtcp = talloc_zero(vnn, struct ctdb_kill_tcp);
 		CTDB_NO_MEMORY(ctdb, killtcp);
 
 		killtcp->vnn         = vnn;
diff --git a/server/eventscript.c b/server/eventscript.c
index 17cc3d4..c42aaa4 100644
--- a/server/eventscript.c
+++ b/server/eventscript.c
@@ -26,6 +26,7 @@
 #include "../include/ctdb_private.h"
 #include "lib/tevent/tevent.h"
 #include "../common/rb_tree.h"
+#include "lib/util/dlinklist.h"
 
 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p);
 
@@ -41,7 +42,8 @@ static void sigterm(int sig)
 
 /* This is attached to the event script state. */
 struct event_script_callback {
-	struct ctdb_event_script_state *state;
+	struct event_script_callback *next, *prev;
+	struct ctdb_context *ctdb;
 
 	/* Warning: this can free us! */
 	void (*fn)(struct ctdb_context *, int, void *);
@@ -611,8 +613,18 @@ static int event_script_destructor(struct ctdb_event_script_state *state)
 	}
 
 	/* This is allowed to free us; talloc will prevent double free anyway,
-	 * but beware if you call this outside the destructor! */
-	callback = state->callback;
+	 * but beware if you call this outside the destructor!
+	 * the callback hangs off a different context so we walk the list
+	 * of "active" callbacks until we find the one state points to.
+	 * if we cant find it it means the callback has been removed.
+	 */
+	for (callback = state->ctdb->script_callbacks; callback != NULL; callback = callback->next) {
+		if (callback == state->callback) {
+			break;
+		}
+	}
+	
+	state->callback = NULL;
 
 	if (callback) {
 		/* Make sure destructor doesn't free itself! */
@@ -669,8 +681,7 @@ static bool check_options(enum ctdb_eventscript_call call, const char *options)
 
 static int remove_callback(struct event_script_callback *callback)
 {
-	/* Detach ourselves from the running script state */
-	callback->state->callback = NULL;
+	DLIST_REMOVE(callback->ctdb->script_callbacks, callback);
 	return 0;
 }
 
@@ -694,9 +705,10 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
 	/* The callback isn't done if the context is freed. */
 	state->callback = talloc(mem_ctx, struct event_script_callback);
 	CTDB_NO_MEMORY(ctdb, state->callback);
+	DLIST_ADD(ctdb->script_callbacks, state->callback);
 	talloc_set_destructor(state->callback, remove_callback);
-	state->callback->state = state;
-	state->callback->fn = callback;
+	state->callback->ctdb         = ctdb;
+	state->callback->fn           = callback;
 	state->callback->private_data = private_data;
 
 	state->ctdb = ctdb;


-- 
CTDB repository


More information about the samba-cvs mailing list