[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-297-gcb38888

Stefan Metzmacher metze at samba.org
Thu Mar 12 13:31:39 GMT 2009


The branch, master has been updated
       via  cb388882cf20a8bc8f20f1230bc22d1caff283dd (commit)
       via  7142ef49bdc5fe731c9140641e8e938ee999327d (commit)
       via  a3d5d8378c8edb6baa9ab42b02cee4711a58840b (commit)
       via  6802394212f7fefc21d1e2ad257fbeee26238b2d (commit)
       via  06f88fe7a2f9ce93f8cdbec0910cc8471c12b1c3 (commit)
       via  bd0f14c1d782b6afe9455e61819caeb2d480af1e (commit)
       via  9932fd2d9af3c71262c5cca61c3b38809b952d95 (commit)
       via  880d9d6d8c209c770185b9b1c9a3019cb56be763 (commit)
       via  43a7d48d24b357872dc31c1088e468ad2b719b73 (commit)
       via  7a8b97ec2bcedb18b56b54fbf61eb0d6e9005193 (commit)
       via  1e4f78cc41d7d44703bea238fee86da618d1587b (commit)
      from  2fdbafbf5475e8936fb5bc3e3bafc7ee19a9b705 (commit)

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


- Log -----------------------------------------------------------------
commit cb388882cf20a8bc8f20f1230bc22d1caff283dd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 10:35:23 2009 +0100

    tevent: add tevent_loop_until()
    
    This is only a hack for samba4 and should not be used
    in new code.
    
    metze

commit 7142ef49bdc5fe731c9140641e8e938ee999327d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 10:23:30 2009 +0100

    tevent: add tevent_loop_set_nesting_hook()
    
    This is an ugly hack to let the s4 server work arround
    some bugs related to nested events and uid changing.
    
    metze

commit a3d5d8378c8edb6baa9ab42b02cee4711a58840b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 10:05:47 2009 +0100

    s4:events: allow nested events until we fixed all code to avoid them
    
    metze

commit 6802394212f7fefc21d1e2ad257fbeee26238b2d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 10:05:05 2009 +0100

    s4:ldb: allow nested events until the code is fixed to avoid them
    
    metze

commit 06f88fe7a2f9ce93f8cdbec0910cc8471c12b1c3
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 09:51:33 2009 +0100

    tevent: don't allow nested tevent_loop_once() anymore
    
    Incompatible caller should use tevent_loop_allow_nesting()
    function.
    
    metze

commit bd0f14c1d782b6afe9455e61819caeb2d480af1e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 09:33:58 2009 +0100

    s3:events: pass __location__ to event_loop_*()
    
    metze

commit 9932fd2d9af3c71262c5cca61c3b38809b952d95
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 09:33:26 2009 +0100

    tevent: pass __location__ to tevent_loop_once/wait()
    
    metze

commit 880d9d6d8c209c770185b9b1c9a3019cb56be763
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 09:22:41 2009 +0100

    tevent: add tevent_set_abort_fn()
    
    metze

commit 43a7d48d24b357872dc31c1088e468ad2b719b73
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 08:48:59 2009 +0100

    tevent: add tevent_signal_support()
    
    Not every tevent backend supports signal events.
    
    metze

commit 7a8b97ec2bcedb18b56b54fbf61eb0d6e9005193
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 08:19:50 2009 +0100

    talloc: add talloc_set_abort_fn()
    
    metze

commit 1e4f78cc41d7d44703bea238fee86da618d1587b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Mar 12 10:04:02 2009 +0100

    s4:ldb: setup tevent debug functions on a selfcreated event context
    
    metze

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

Summary of changes:
 lib/talloc/talloc.c            |   35 +++++++-
 lib/talloc/talloc.h            |    2 +
 lib/tevent/tevent.c            |  170 +++++++++++++++++++++++++++++++++++++++-
 lib/tevent/tevent.h            |   39 +++++++++-
 lib/tevent/tevent_epoll.c      |    6 +-
 lib/tevent/tevent_internal.h   |   12 +++-
 lib/tevent/tevent_select.c     |    6 +-
 lib/tevent/tevent_standard.c   |    6 +-
 source3/lib/events.c           |    6 +-
 source4/lib/events/tevent_s4.c |    2 +
 source4/lib/ldb/common/ldb.c   |   37 +++++++++
 11 files changed, 297 insertions(+), 24 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index c472e9f..60a48ad 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -138,14 +138,30 @@ struct talloc_chunk {
 #define TC_HDR_SIZE ((sizeof(struct talloc_chunk)+15)&~15)
 #define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc))
 
+static void (*talloc_abort_fn)(const char *reason);
+
+void talloc_set_abort_fn(void (*abort_fn)(const char *reason))
+{
+	talloc_abort_fn = abort_fn;
+}
+
+static void talloc_abort(const char *reason)
+{
+	if (!talloc_abort_fn) {
+		TALLOC_ABORT(reason);
+	}
+
+	talloc_abort_fn(reason);
+}
+
 static void talloc_abort_double_free(void)
 {
-	TALLOC_ABORT("Bad talloc magic value - double free"); 
+	talloc_abort("Bad talloc magic value - double free");
 }
 
 static void talloc_abort_unknown_value(void)
 {
-	TALLOC_ABORT("Bad talloc magic value - unknown value"); 
+	talloc_abort("Bad talloc magic value - unknown value");
 }
 
 /* panic if we get a bad magic value */
@@ -564,7 +580,7 @@ static inline int _talloc_free(void *ptr)
 		pool_object_count = talloc_pool_objectcount(pool);
 
 		if (*pool_object_count == 0) {
-			TALLOC_ABORT("Pool object count zero!");
+			talloc_abort("Pool object count zero!");
 		}
 
 		*pool_object_count -= 1;
@@ -810,7 +826,18 @@ static void talloc_abort_type_missmatch(const char *location,
 					const char *name,
 					const char *expected)
 {
-	TALLOC_ABORT("Type missmatch");
+	const char *reason;
+
+	reason = talloc_asprintf(NULL,
+				 "%s: Type mismatch: name[%s] expected[%s]",
+				 location,
+				 name?name:"NULL",
+				 expected);
+	if (!reason) {
+		reason = "Type mismatch";
+	}
+
+	talloc_abort(reason);
 }
 
 void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location)
diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h
index 002e06e..b623934 100644
--- a/lib/talloc/talloc.h
+++ b/lib/talloc/talloc.h
@@ -182,4 +182,6 @@ char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3)
 char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 
+void talloc_set_abort_fn(void (*abort_fn)(const char *reason));
+
 #endif
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index fc82529..a9e18c3 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -59,6 +59,7 @@
 */
 #include "replace.h"
 #include "system/filesys.h"
+#define TEVENT_DEPRECATED 1
 #include "tevent.h"
 #include "tevent_internal.h"
 #include "tevent_util.h"
@@ -305,6 +306,33 @@ void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags)
 	fde->event_ctx->ops->set_fd_flags(fde, flags);
 }
 
+bool tevent_signal_support(struct tevent_context *ev)
+{
+	if (ev->ops->add_signal) {
+		return true;
+	}
+	return false;
+}
+
+static void (*tevent_abort_fn)(const char *reason);
+
+void tevent_set_abort_fn(void (*abort_fn)(const char *reason))
+{
+	tevent_abort_fn = abort_fn;
+}
+
+static void tevent_abort(struct tevent_context *ev, const char *reason)
+{
+	tevent_debug(ev, TEVENT_DEBUG_FATAL,
+		     "abort: %s\n", reason);
+
+	if (!tevent_abort_fn) {
+		abort();
+	}
+
+	tevent_abort_fn(reason);
+}
+
 /*
   add a timer event
   return NULL on failure
@@ -341,18 +369,152 @@ struct tevent_signal *_tevent_add_signal(struct tevent_context *ev,
 				   handler_name, location);
 }
 
+void tevent_loop_allow_nesting(struct tevent_context *ev)
+{
+	ev->nesting.allowed = true;
+}
+
+void tevent_loop_set_nesting_hook(struct tevent_context *ev,
+				  tevent_nesting_hook hook,
+				  void *private_data)
+{
+	ev->nesting.hook_fn = hook;
+	ev->nesting.hook_private = private_data;
+}
+
+static void tevent_abort_nesting(struct tevent_context *ev, const char *location)
+{
+	const char *reason;
+
+	reason = talloc_asprintf(NULL, "tevent_loop_once() nesting at %s",
+				 location);
+	if (!reason) {
+		reason = "tevent_loop_once() nesting";
+	}
+
+	tevent_abort(ev, reason);
+}
+
 /*
   do a single event loop using the events defined in ev 
 */
-int tevent_loop_once(struct tevent_context *ev)
+int _tevent_loop_once(struct tevent_context *ev, const char *location)
+{
+	int ret;
+	void *nesting_stack_ptr = NULL;
+
+	ev->nesting.level++;
+
+	if (ev->nesting.level > 1) {
+		if (!ev->nesting.allowed) {
+			tevent_abort_nesting(ev, location);
+			errno = ELOOP;
+			return -1;
+		}
+		if (ev->nesting.hook_fn) {
+			int ret2;
+			ret2 = ev->nesting.hook_fn(ev,
+						   ev->nesting.hook_private,
+						   ev->nesting.level,
+						   true,
+						   (void *)&nesting_stack_ptr,
+						   location);
+			if (ret2 != 0) {
+				ret = ret2;
+				goto done;
+			}
+		}
+	}
+
+	ret = ev->ops->loop_once(ev, location);
+
+	if (ev->nesting.level > 1) {
+		if (ev->nesting.hook_fn) {
+			int ret2;
+			ret2 = ev->nesting.hook_fn(ev,
+						   ev->nesting.hook_private,
+						   ev->nesting.level,
+						   false,
+						   (void *)&nesting_stack_ptr,
+						   location);
+			if (ret2 != 0) {
+				ret = ret2;
+				goto done;
+			}
+		}
+	}
+
+done:
+	ev->nesting.level--;
+	return ret;
+}
+
+/*
+  this is a performance optimization for the samba4 nested event loop problems
+*/
+int _tevent_loop_until(struct tevent_context *ev,
+		       bool (*finished)(void *private_data),
+		       void *private_data,
+		       const char *location)
 {
-	return ev->ops->loop_once(ev);
+	int ret;
+	void *nesting_stack_ptr = NULL;
+
+	ev->nesting.level++;
+
+	if (ev->nesting.level > 1) {
+		if (!ev->nesting.allowed) {
+			tevent_abort_nesting(ev, location);
+			errno = ELOOP;
+			return -1;
+		}
+		if (ev->nesting.hook_fn) {
+			int ret2;
+			ret2 = ev->nesting.hook_fn(ev,
+						   ev->nesting.hook_private,
+						   ev->nesting.level,
+						   true,
+						   (void *)&nesting_stack_ptr,
+						   location);
+			if (ret2 != 0) {
+				ret = ret2;
+				goto done;
+			}
+		}
+	}
+
+	while (!finished(private_data)) {
+		ret = ev->ops->loop_once(ev, location);
+		if (ret != 0) {
+			break;
+		}
+	}
+
+	if (ev->nesting.level > 1) {
+		if (ev->nesting.hook_fn) {
+			int ret2;
+			ret2 = ev->nesting.hook_fn(ev,
+						   ev->nesting.hook_private,
+						   ev->nesting.level,
+						   false,
+						   (void *)&nesting_stack_ptr,
+						   location);
+			if (ret2 != 0) {
+				ret = ret2;
+				goto done;
+			}
+		}
+	}
+
+done:
+	ev->nesting.level--;
+	return ret;
 }
 
 /*
   return on failure or (with 0) if all fd events are removed
 */
-int tevent_loop_wait(struct tevent_context *ev)
+int _tevent_loop_wait(struct tevent_context *ev, const char *location)
 {
-	return ev->ops->loop_wait(ev);
+	return ev->ops->loop_wait(ev, location);
 }
diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index 2dadfc1..4a3f51a 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -99,8 +99,13 @@ struct tevent_signal *_tevent_add_signal(struct tevent_context *ev,
 	_tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data, \
 			   #handler, __location__)
 
-int tevent_loop_once(struct tevent_context *ev);
-int tevent_loop_wait(struct tevent_context *ev);
+int _tevent_loop_once(struct tevent_context *ev, const char *location);
+#define tevent_loop_once(ev) \
+	_tevent_loop_once(ev, __location__) \
+
+int _tevent_loop_wait(struct tevent_context *ev, const char *location);
+#define tevent_loop_wait(ev) \
+	_tevent_loop_wait(ev, __location__) \
 
 void tevent_fd_set_close_fn(struct tevent_fd *fde,
 			    tevent_fd_close_fn_t close_fn);
@@ -108,6 +113,10 @@ void tevent_fd_set_auto_close(struct tevent_fd *fde);
 uint16_t tevent_fd_get_flags(struct tevent_fd *fde);
 void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
 
+bool tevent_signal_support(struct tevent_context *ev);
+
+void tevent_set_abort_fn(void (*abort_fn)(const char *reason));
+
 /* bits for file descriptor event flags */
 #define TEVENT_FD_READ 1
 #define TEVENT_FD_WRITE 2
@@ -292,6 +301,32 @@ void tevent_queue_stop(struct tevent_queue *queue);
 
 size_t tevent_queue_length(struct tevent_queue *queue);
 
+typedef int (*tevent_nesting_hook)(struct tevent_context *ev,
+				   void *private_data,
+				   uint32_t level,
+				   bool begin,
+				   void *stack_ptr,
+				   const char *location);
+#ifdef TEVENT_DEPRECATED
+#ifndef _DEPRECATED_
+#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
+#define _DEPRECATED_ __attribute__ ((deprecated))
+#else
+#define _DEPRECATED_
+#endif
+#endif
+void tevent_loop_allow_nesting(struct tevent_context *ev) _DEPRECATED_;
+void tevent_loop_set_nesting_hook(struct tevent_context *ev,
+				  tevent_nesting_hook hook,
+				  void *private_data) _DEPRECATED_;
+int _tevent_loop_until(struct tevent_context *ev,
+		       bool (*finished)(void *private_data),
+		       void *private_data,
+		       const char *location) _DEPRECATED_;
+#define tevent_loop_until(ev, finished, private_data) \
+	_tevent_loop_until(ev, finished, private_data, __location__)
+#endif
+
 #ifdef TEVENT_COMPAT_DEFINES
 
 #define event_context	tevent_context
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index 0494f55..b63d299 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -411,7 +411,7 @@ static void epoll_event_set_fd_flags(struct tevent_fd *fde, uint16_t flags)
 /*
   do a single event loop using the events defined in ev 
 */
-static int epoll_event_loop_once(struct tevent_context *ev)
+static int epoll_event_loop_once(struct tevent_context *ev, const char *location)
 {
 	struct epoll_event_context *epoll_ev = talloc_get_type(ev->additional_data,
 		 					   struct epoll_event_context);
@@ -430,12 +430,12 @@ static int epoll_event_loop_once(struct tevent_context *ev)
 /*
   return on failure or (with 0) if all fd events are removed
 */
-static int epoll_event_loop_wait(struct tevent_context *ev)
+static int epoll_event_loop_wait(struct tevent_context *ev, const char *location)
 {
 	struct epoll_event_context *epoll_ev = talloc_get_type(ev->additional_data,
 							   struct epoll_event_context);
 	while (epoll_ev->ev->fd_events) {
-		if (epoll_event_loop_once(ev) != 0) {
+		if (epoll_event_loop_once(ev, location) != 0) {
 			break;
 		}
 	}
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index 5a645ec..f104853 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -153,8 +153,8 @@ struct tevent_ops {
 					    const char *location);
 
 	/* loop functions */
-	int (*loop_once)(struct tevent_context *ev);
-	int (*loop_wait)(struct tevent_context *ev);
+	int (*loop_once)(struct tevent_context *ev, const char *location);
+	int (*loop_wait)(struct tevent_context *ev, const char *location);
 };
 
 struct tevent_fd {
@@ -233,6 +233,14 @@ struct tevent_context {
 
 	/* debugging operations */
 	struct tevent_debug_ops debug_ops;
+
+	/* info about the nesting status */
+	struct {
+		bool allowed;
+		uint32_t level;
+		tevent_nesting_hook hook_fn;
+		void *hook_private;
+	} nesting;
 };
 
 
diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c
index 32678f0..cdddb60 100644
--- a/lib/tevent/tevent_select.c
+++ b/lib/tevent/tevent_select.c
@@ -213,7 +213,7 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru
 /*
   do a single event loop using the events defined in ev 
 */
-static int select_event_loop_once(struct tevent_context *ev)
+static int select_event_loop_once(struct tevent_context *ev, const char *location)
 {
 	struct select_event_context *select_ev = talloc_get_type(ev->additional_data,
 		 					   struct select_event_context);
@@ -230,14 +230,14 @@ static int select_event_loop_once(struct tevent_context *ev)
 /*
   return on failure or (with 0) if all fd events are removed
 */
-static int select_event_loop_wait(struct tevent_context *ev)
+static int select_event_loop_wait(struct tevent_context *ev, const char *location)
 {
 	struct select_event_context *select_ev = talloc_get_type(ev->additional_data,
 							   struct select_event_context);
 	select_ev->exit_code = 0;
 
 	while (ev->fd_events && select_ev->exit_code == 0) {
-		if (select_event_loop_once(ev) != 0) {
+		if (select_event_loop_once(ev, location) != 0) {
 			break;
 		}
 	}
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index bbd5c5d..73a45e8 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -534,7 +534,7 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva
 /*
   do a single event loop using the events defined in ev 
 */
-static int std_event_loop_once(struct tevent_context *ev)
+static int std_event_loop_once(struct tevent_context *ev, const char *location)
 {
 	struct std_event_context *std_ev = talloc_get_type(ev->additional_data,
 		 					   struct std_event_context);
@@ -557,14 +557,14 @@ static int std_event_loop_once(struct tevent_context *ev)
 /*
   return on failure or (with 0) if all fd events are removed
 */
-static int std_event_loop_wait(struct tevent_context *ev)
+static int std_event_loop_wait(struct tevent_context *ev, const char *location)
 {
 	struct std_event_context *std_ev = talloc_get_type(ev->additional_data,
 							   struct std_event_context);
 	std_ev->exit_code = 0;
 
 	while (ev->fd_events && std_ev->exit_code == 0) {
-		if (std_event_loop_once(ev) != 0) {
+		if (std_event_loop_once(ev, location) != 0) {
 			break;
 		}
 	}
diff --git a/source3/lib/events.c b/source3/lib/events.c
index f875e0d..8c56941 100644
--- a/source3/lib/events.c
+++ b/source3/lib/events.c
@@ -145,7 +145,7 @@ struct timeval *get_timed_events_timeout(struct tevent_context *ev,
 	return to_ret;
 }
 
-static int s3_event_loop_once(struct tevent_context *ev)
+static int s3_event_loop_once(struct tevent_context *ev, const char *location)
 {
 	struct timeval now, to;
 	fd_set r_fds, w_fds;
@@ -181,12 +181,12 @@ static int s3_event_loop_once(struct tevent_context *ev)
 	return 0;
 }
 
-static int s3_event_loop_wait(struct tevent_context *ev)
+static int s3_event_loop_wait(struct tevent_context *ev, const char *location)
 {
 	int ret = 0;
 
 	while (ret == 0) {
-		ret = s3_event_loop_once(ev);
+		ret = s3_event_loop_once(ev, location);
 	}
 
 	return ret;
diff --git a/source4/lib/events/tevent_s4.c b/source4/lib/events/tevent_s4.c
index 89ca7bb..06bfbf6 100644
--- a/source4/lib/events/tevent_s4.c
+++ b/source4/lib/events/tevent_s4.c
@@ -17,6 +17,7 @@
 */
 
 #include "includes.h"
+#define TEVENT_DEPRECATED 1
 #include "lib/events/events.h"


-- 
Samba Shared Repository


More information about the samba-cvs mailing list