[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Wed Dec 14 03:24:03 MST 2011


The branch, master has been updated
       via  c51da25 s3:smbd/server: avoid msg_ctx_to_sconn() in smbd_accept_connection()
       via  1515f7d s3:smbd: remove unused smbd_messaging_context()
       via  78582da s3:smbd/server: maintain the list of child processes under smbd_parent_context
       via  dddaa525 s3:smbd/server: pass smbd_parent_context to smbd_setup_sig_chld_handler()
       via  6d15ca3 s3:smbd/globals: change 'int am_parent' into 'struct smbd_parent_context *am_parent'
      from  010d600 s4-netlogon: Revert patch f02e4ebfafa6e5911e3fe744b1780527ab12c970

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


- Log -----------------------------------------------------------------
commit c51da257699e7900aa2069eb71eb530e66f35fcc
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Dec 13 15:26:34 2011 +0100

    s3:smbd/server: avoid msg_ctx_to_sconn() in smbd_accept_connection()
    
    This is the place where we should create smbd_server_connection,
    when we're ready to remove the global variable.
    
    metze
    
    Autobuild-User: Stefan Metzmacher <metze at samba.org>
    Autobuild-Date: Wed Dec 14 11:23:42 CET 2011 on sn-devel-104

commit 1515f7db00ec3c01bc9c808edddf44052ac91c3f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Dec 13 15:24:24 2011 +0100

    s3:smbd: remove unused smbd_messaging_context()
    
    metze

commit 78582da8b57120d0f1a86577d1f8df1d553769bc
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Dec 13 15:23:08 2011 +0100

    s3:smbd/server: maintain the list of child processes under smbd_parent_context
    
    metze

commit dddaa52552d2e1288fa13f5c2206b183a4c4c032
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Dec 13 15:21:12 2011 +0100

    s3:smbd/server: pass smbd_parent_context to smbd_setup_sig_chld_handler()
    
    metze

commit 6d15ca3482bfdccd9eceef1874f88ec351e3f43f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Dec 13 14:58:50 2011 +0100

    s3:smbd/globals: change 'int am_parent' into 'struct smbd_parent_context *am_parent'
    
    This is a short term solution on the way to get rid of 'am_parent' completely.
    
    metze

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

Summary of changes:
 source3/include/smb.h  |    6 ---
 source3/smbd/globals.c |   14 +-----
 source3/smbd/globals.h |    6 +--
 source3/smbd/proto.h   |    1 -
 source3/smbd/server.c  |  117 +++++++++++++++++++++++++++++-------------------
 5 files changed, 74 insertions(+), 70 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/smb.h b/source3/include/smb.h
index 8c521f8..3451123 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -1359,12 +1359,6 @@ struct smb_filename {
 	SMB_STRUCT_STAT st;
 };
 
-/* struct for maintaining the child processes that get spawned from smbd */
-struct child_pid {
-	struct child_pid *prev, *next;
-	pid_t pid;
-};
-
 /* Used to keep track of deferred opens. */
 struct deferred_open_record;
 
diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c
index 82de70a..3199a37 100644
--- a/source3/smbd/globals.c
+++ b/source3/smbd/globals.c
@@ -98,11 +98,9 @@ int32_t exclusive_oplocks_open = 0;
 int32_t level_II_oplocks_open = 0;
 struct kernel_oplocks *koplocks = NULL;
 
-int am_parent = 1;
+struct smbd_parent_context *am_parent = NULL;
 struct memcache *smbd_memcache_ctx = NULL;
 bool exit_firsttime = true;
-struct child_pid *children = 0;
-int num_children = 0;
 
 struct smbd_server_connection *smbd_server_conn = NULL;
 
@@ -119,16 +117,6 @@ struct smbd_server_connection *msg_ctx_to_sconn(struct messaging_context *msg_ct
 	return smbd_server_conn;
 }
 
-struct messaging_context *smbd_messaging_context(void)
-{
-	struct messaging_context *msg_ctx = server_messaging_context();
-	if (likely(msg_ctx != NULL)) {
-		return msg_ctx;
-	}
-	smb_panic("Could not init smbd's messaging context.\n");
-	return NULL;
-}
-
 struct memcache *smbd_memcache(void)
 {
 	if (!smbd_memcache_ctx) {
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index 559f8fb..d5b2de7 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -113,12 +113,10 @@ extern int32_t exclusive_oplocks_open;
 extern int32_t level_II_oplocks_open;
 extern struct kernel_oplocks *koplocks;
 
-extern int am_parent;
+struct smbd_parent_context;
+extern struct smbd_parent_context *am_parent;
 extern struct memcache *smbd_memcache_ctx;
 extern bool exit_firsttime;
-struct child_pid;
-extern struct child_pid *children;
-extern int num_children;
 
 struct tstream_context;
 struct smbd_smb2_request;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 0cc6b66..64cf944 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -957,7 +957,6 @@ void init_sec_ctx(void);
 
 /* The following definitions come from smbd/server.c  */
 
-struct messaging_context *smbd_messaging_context(void);
 struct memcache *smbd_memcache(void);
 void delete_and_reload_printers(struct tevent_context *ev,
 				struct messaging_context *msg_ctx);
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 7cd1b83..f351b99 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -43,6 +43,7 @@
 #include "lib/param/param.h"
 
 struct smbd_open_socket;
+struct smbd_child_pid;
 
 struct smbd_parent_context {
 	bool interactive;
@@ -52,6 +53,12 @@ struct smbd_parent_context {
 
 	/* the list of listening sockets */
 	struct smbd_open_socket *sockets;
+
+	/* the list of current child processes */
+	struct smbd_child_pid *children;
+	size_t num_children;
+
+	struct timed_event *cleanup_te;
 };
 
 struct smbd_open_socket {
@@ -61,6 +68,11 @@ struct smbd_open_socket {
 	struct tevent_fd *fde;
 };
 
+struct smbd_child_pid {
+	struct smbd_child_pid *prev, *next;
+	pid_t pid;
+};
+
 extern void start_epmd(struct tevent_context *ev_ctx,
 		       struct messaging_context *msg_ctx);
 
@@ -183,10 +195,16 @@ NTSTATUS messaging_send_to_children(struct messaging_context *msg_ctx,
 				    uint32_t msg_type, DATA_BLOB* data)
 {
 	NTSTATUS status;
-	struct child_pid *child;
+	struct smbd_parent_context *parent = am_parent;
+	struct smbd_child_pid *child;
+
+	if (parent == NULL) {
+		return NT_STATUS_INTERNAL_ERROR;
+	}
 
-	for (child = children; child != NULL; child = child->next) {
-		status = messaging_send(msg_ctx, pid_to_procid(child->pid),
+	for (child = parent->children; child != NULL; child = child->next) {
+		status = messaging_send(parent->msg_ctx,
+					pid_to_procid(child->pid),
 					msg_type, data);
 		if (!NT_STATUS_IS_OK(status)) {
 			return status;
@@ -212,18 +230,19 @@ static void smbd_msg_debug(struct messaging_context *msg_ctx,
 	messaging_send_to_children(msg_ctx, MSG_DEBUG, data);
 }
 
-static void add_child_pid(pid_t pid)
+static void add_child_pid(struct smbd_parent_context *parent,
+			  pid_t pid)
 {
-	struct child_pid *child;
+	struct smbd_child_pid *child;
 
-	child = SMB_MALLOC_P(struct child_pid);
+	child = talloc_zero(parent, struct smbd_child_pid);
 	if (child == NULL) {
 		DEBUG(0, ("Could not add child struct -- malloc failed\n"));
 		return;
 	}
 	child->pid = pid;
-	DLIST_ADD(children, child);
-	num_children += 1;
+	DLIST_ADD(parent->children, child);
+	parent->num_children += 1;
 }
 
 /*
@@ -242,23 +261,24 @@ static void cleanup_timeout_fn(struct event_context *event_ctx,
 				struct timeval now,
 				void *private_data)
 {
-	struct timed_event **cleanup_te = (struct timed_event **)private_data;
-	struct messaging_context *msg = smbd_messaging_context();
+	struct smbd_parent_context *parent =
+		talloc_get_type_abort(private_data,
+		struct smbd_parent_context);
+
+	parent->cleanup_te = NULL;
 
 	DEBUG(1,("Cleaning up brl and lock database after unclean shutdown\n"));
-	message_send_all(msg, MSG_SMB_UNLOCK, NULL, 0, NULL);
-	messaging_send_buf(msg, messaging_server_id(msg),
-				MSG_SMB_BRL_VALIDATE, NULL, 0);
-	/* mark the cleanup as having been done */
-	(*cleanup_te) = NULL;
+	message_send_all(parent->msg_ctx, MSG_SMB_UNLOCK, NULL, 0, NULL);
+	messaging_send_buf(parent->msg_ctx,
+			   messaging_server_id(parent->msg_ctx),
+			   MSG_SMB_BRL_VALIDATE, NULL, 0);
 }
 
-static void remove_child_pid(struct tevent_context *ev_ctx,
+static void remove_child_pid(struct smbd_parent_context *parent,
 			     pid_t pid,
 			     bool unclean_shutdown)
 {
-	struct child_pid *child;
-	static struct timed_event *cleanup_te;
+	struct smbd_child_pid *child;
 	struct server_id child_id;
 
 	if (unclean_shutdown) {
@@ -268,13 +288,14 @@ static void remove_child_pid(struct tevent_context *ev_ctx,
                 */
 		DEBUG(3,(__location__ " Unclean shutdown of pid %u\n",
 			(unsigned int)pid));
-		if (!cleanup_te) {
+		if (parent->cleanup_te == NULL) {
 			/* call the cleanup timer, but not too often */
 			int cleanup_time = lp_parm_int(-1, "smbd", "cleanuptime", 20);
-			cleanup_te = event_add_timed(ev_ctx, NULL,
+			parent->cleanup_te = tevent_add_timer(parent->ev_ctx,
+						parent,
 						timeval_current_ofs(cleanup_time, 0),
 						cleanup_timeout_fn,
-						&cleanup_te);
+						parent);
 			DEBUG(1,("Scheduled cleanup of brl and lock database after unclean shutdown\n"));
 		}
 	}
@@ -286,12 +307,12 @@ static void remove_child_pid(struct tevent_context *ev_ctx,
 			  (int)pid));
 	}
 
-	for (child = children; child != NULL; child = child->next) {
+	for (child = parent->children; child != NULL; child = child->next) {
 		if (child->pid == pid) {
-			struct child_pid *tmp = child;
-			DLIST_REMOVE(children, child);
-			SAFE_FREE(tmp);
-			num_children -= 1;
+			struct smbd_child_pid *tmp = child;
+			DLIST_REMOVE(parent->children, child);
+			TALLOC_FREE(tmp);
+			parent->num_children -= 1;
 			return;
 		}
 	}
@@ -304,14 +325,14 @@ static void remove_child_pid(struct tevent_context *ev_ctx,
  Have we reached the process limit ?
 ****************************************************************************/
 
-static bool allowable_number_of_smbd_processes(void)
+static bool allowable_number_of_smbd_processes(struct smbd_parent_context *parent)
 {
 	int max_processes = lp_max_smbd_processes();
 
 	if (!max_processes)
 		return True;
 
-	return num_children < max_processes;
+	return parent->num_children < max_processes;
 }
 
 static void smbd_sig_chld_handler(struct tevent_context *ev,
@@ -323,6 +344,9 @@ static void smbd_sig_chld_handler(struct tevent_context *ev,
 {
 	pid_t pid;
 	int status;
+	struct smbd_parent_context *parent =
+		talloc_get_type_abort(private_data,
+		struct smbd_parent_context);
 
 	while ((pid = sys_waitpid(-1, &status, WNOHANG)) > 0) {
 		bool unclean_shutdown = False;
@@ -340,19 +364,19 @@ static void smbd_sig_chld_handler(struct tevent_context *ev,
 		if (WIFSIGNALED(status)) {
 			unclean_shutdown = True;
 		}
-		remove_child_pid(ev, pid, unclean_shutdown);
+		remove_child_pid(parent, pid, unclean_shutdown);
 	}
 }
 
-static void smbd_setup_sig_chld_handler(struct tevent_context *ev_ctx)
+static void smbd_setup_sig_chld_handler(struct smbd_parent_context *parent)
 {
 	struct tevent_signal *se;
 
-	se = tevent_add_signal(ev_ctx,
-			       ev_ctx, /* mem_ctx */
+	se = tevent_add_signal(parent->ev_ctx,
+			       parent, /* mem_ctx */
 			       SIGCHLD, 0,
 			       smbd_sig_chld_handler,
-			       NULL);
+			       parent);
 	if (!se) {
 		exit_server("failed to setup SIGCHLD handler");
 	}
@@ -375,7 +399,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
 	struct smbd_open_socket *s = talloc_get_type_abort(private_data,
 				     struct smbd_open_socket);
 	struct messaging_context *msg_ctx = s->parent->msg_ctx;
-	struct smbd_server_connection *sconn = msg_ctx_to_sconn(msg_ctx);
+	struct smbd_server_connection *sconn = smbd_server_conn;
 	struct sockaddr_storage addr;
 	socklen_t in_addrlen = sizeof(addr);
 	int fd;
@@ -399,7 +423,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
 		return;
 	}
 
-	if (!allowable_number_of_smbd_processes()) {
+	if (!allowable_number_of_smbd_processes(s->parent)) {
 		close(fd);
 		sconn->sock = -1;
 		return;
@@ -416,7 +440,14 @@ static void smbd_accept_connection(struct tevent_context *ev,
 		NTSTATUS status = NT_STATUS_OK;
 
 		/* Child code ... */
-		am_parent = 0;
+		am_parent = NULL;
+
+		/*
+		 * Can't use TALLOC_FREE here. Nulling out the argument to it
+		 * would overwrite memory we've just freed.
+		 */
+		talloc_free(s->parent);
+		s = NULL;
 
 		set_my_unique_id(unique_id);
 
@@ -430,13 +461,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
 			close_low_fds(False); /* Don't close stderr */
 		}
 
-		/*
-		 * Can't use TALLOC_FREE here. Nulling out the argument to it
-		 * would overwrite memory we've just freed.
-		 */
-		talloc_free(s->parent);
-		s = NULL;
-
 		status = reinit_after_fork(msg_ctx,
 					   ev,
 					   true);
@@ -495,7 +519,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
 	sconn->sock = -1;
 
 	if (pid != 0) {
-		add_child_pid(pid);
+		add_child_pid(s->parent, pid);
 	}
 
 	/* Force parent to check log size after
@@ -599,7 +623,7 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
 #endif
 
 	/* Stop zombies */
-	smbd_setup_sig_chld_handler(ev_ctx);
+	smbd_setup_sig_chld_handler(parent);
 
 	/* use a reasonable default set of ports - listing on 445 and 139 */
 	if (!smb_ports) {
@@ -1146,6 +1170,7 @@ extern void build_options(bool screen);
 	parent->interactive = interactive;
 	parent->ev_ctx = ev_ctx;
 	parent->msg_ctx = msg_ctx;
+	am_parent = parent;
 
 	se = tevent_add_signal(parent->ev_ctx,
 			       parent,
@@ -1310,7 +1335,7 @@ extern void build_options(bool screen);
 #endif
 
 	        /* Stop zombies */
-		smbd_setup_sig_chld_handler(ev_ctx);
+		smbd_setup_sig_chld_handler(parent);
 
 		smbd_process(ev_ctx, smbd_server_conn);
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list