[SCM] CTDB repository - branch 1.2.39 updated - ctdb-1.9.1-495-g1260c1b

Ronnie Sahlberg sahlberg at samba.org
Sun Feb 26 15:26:23 MST 2012


The branch, 1.2.39 has been updated
       via  1260c1b9f301dccd497be8b818be5463858f0603 (commit)
       via  72dc4c9dc955489c312fc0866bf163132895d911 (commit)
      from  2f73114265b6523d6ceed54e70fd042c3738c6a2 (commit)

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


- Log -----------------------------------------------------------------
commit 1260c1b9f301dccd497be8b818be5463858f0603
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 72dc4c9dc955489c312fc0866bf163132895d911
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 675ea49..e3a9a15 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/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