[SCM] CTDB repository - branch master updated - ctdb-1.12-220-g02b6248

Ronnie Sahlberg sahlberg at samba.org
Sun Feb 26 13:34:01 MST 2012


The branch, master has been updated
       via  02b62482164a3c69715949074feb7f191a29d534 (commit)
       via  a95c02da6c67dc4bd8716b75318a4188301df6f9 (commit)
      from  d306c3c9a53e012c412c96ab9743de6cd96826e0 (commit)

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


- Log -----------------------------------------------------------------
commit 02b62482164a3c69715949074feb7f191a29d534
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 a95c02da6c67dc4bd8716b75318a4188301df6f9
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 +++
 server/ctdb_takeover.c |   22 +++++++++++++++++++---
 server/eventscript.c   |   26 +++++++++++++++++++-------
 3 files changed, 41 insertions(+), 10 deletions(-)


Changeset truncated at 500 lines:

diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index 272b94a..4b7e675 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -486,6 +486,9 @@ struct ctdb_context {
 
 	/* if we are a child process, do we have a domain socket to send controls on */
 	bool can_send_controls;
+
+	/* list of event script callback functions that are active */
+	struct event_script_callback *script_callbacks;
 };
 
 struct ctdb_db_context {
diff --git a/server/ctdb_takeover.c b/server/ctdb_takeover.c
index 830b751..c91d2f7 100644
--- a/server/ctdb_takeover.c
+++ b/server/ctdb_takeover.c
@@ -2934,9 +2934,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;
 }
 
@@ -2991,7 +3007,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 722ebec..146da9d 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