svn commit: samba r21869 - in branches/SAMBA_3_0/source: param smbd

vlendec at samba.org vlendec at samba.org
Sun Mar 18 10:57:47 GMT 2007


Author: vlendec
Date: 2007-03-18 10:57:46 +0000 (Sun, 18 Mar 2007)
New Revision: 21869

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21869

Log:
Move sending keepalives out of the main processing loop into idle event.

On the way, make lp_keepalive() a proper parameter.

Volker


Modified:
   branches/SAMBA_3_0/source/param/loadparm.c
   branches/SAMBA_3_0/source/smbd/process.c
   branches/SAMBA_3_0/source/smbd/server.c


Changeset:
Modified: branches/SAMBA_3_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_3_0/source/param/loadparm.c	2007-03-18 10:13:35 UTC (rev 21868)
+++ branches/SAMBA_3_0/source/param/loadparm.c	2007-03-18 10:57:46 UTC (rev 21869)
@@ -79,7 +79,6 @@
 #define USERSHARE_VALID 1
 #define USERSHARE_PENDING_DELETE 2
 
-int keepalive = DEFAULT_KEEPALIVE;
 BOOL use_getwd_cache = True;
 
 extern int extra_time_offset;
@@ -315,6 +314,7 @@
 	int iIdmapNegativeTime;
 
 	BOOL bResetOnZeroVC;
+	int iKeepalive;
 	param_opt_struct *param_opt;
 } global;
 
@@ -1008,7 +1008,7 @@
 	{"block size", P_INTEGER, P_LOCAL, &sDefault.iBlock_size, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
 	{"deadtime", P_INTEGER, P_GLOBAL, &Globals.deadtime, NULL, NULL, FLAG_ADVANCED}, 
 	{"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED}, 
-	{"keepalive", P_INTEGER, P_GLOBAL, &keepalive, NULL, NULL, FLAG_ADVANCED}, 
+	{"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED}, 
 	{"change notify", P_BOOL, P_LOCAL, &sDefault.bChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
 	{"kernel change notify", P_BOOL, P_LOCAL, &sDefault.bKernelChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
 
@@ -1666,6 +1666,8 @@
 	/* By default disallow guest access to usershares. */
 	Globals.bUsershareAllowGuests = False;
 
+	Globals.iKeepalive = DEFAULT_KEEPALIVE;
+
 	/* By default no shares out of the registry */
 	Globals.bRegistryShares = False;
 }
@@ -1903,6 +1905,7 @@
 FN_GLOBAL_STRING(lp_idmap_alloc_backend, &Globals.szIdmapAllocBackend)
 FN_GLOBAL_INTEGER(lp_idmap_expire_time, &Globals.iIdmapExpireTime)
 FN_GLOBAL_INTEGER(lp_idmap_negative_time, &Globals.iIdmapNegativeTime)
+FN_GLOBAL_INTEGER(lp_keepalive, &Globals.iKeepalive)
 FN_GLOBAL_BOOL(lp_passdb_expand_explicit, &Globals.bPassdbExpandExplicit)
 
 FN_GLOBAL_STRING(lp_ldap_suffix, &Globals.szLdapSuffix)

Modified: branches/SAMBA_3_0/source/smbd/process.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/process.c	2007-03-18 10:13:35 UTC (rev 21868)
+++ branches/SAMBA_3_0/source/smbd/process.c	2007-03-18 10:57:46 UTC (rev 21869)
@@ -22,7 +22,6 @@
 #include "includes.h"
 
 uint16 global_smbpid;
-extern int keepalive;
 extern struct auth_context *negprot_global_auth_context;
 extern int smb_echo_count;
 
@@ -221,6 +220,7 @@
 struct idle_event {
 	struct timed_event *te;
 	struct timeval interval;
+	char *name;
 	BOOL (*handler)(const struct timeval *now, void *private_data);
 	void *private_data;
 };
@@ -241,17 +241,19 @@
 		return;
 	}
 
-	event->te = event_add_timed(smbd_event_context(), event,
+	event->te = event_add_timed(ctx, event,
 				    timeval_sum(now, &event->interval),
-				    "idle_event_handler",
+				    event->name,
 				    idle_event_handler, event);
 
 	/* We can't do much but fail here. */
 	SMB_ASSERT(event->te != NULL);
 }
 
-struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx,
+struct idle_event *event_add_idle(struct event_context *event_ctx,
+				  TALLOC_CTX *mem_ctx,
 				  struct timeval interval,
+				  const char *name,
 				  BOOL (*handler)(const struct timeval *now,
 						  void *private_data),
 				  void *private_data)
@@ -269,9 +271,15 @@
 	result->handler = handler;
 	result->private_data = private_data;
 
-	result->te = event_add_timed(smbd_event_context(), result,
+	if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
+		DEBUG(0, ("talloc failed\n"));
+		TALLOC_FREE(result);
+		return NULL;
+	}
+
+	result->te = event_add_timed(event_ctx, result,
 				     timeval_sum(&now, &interval),
-				     "idle_event_handler",
+				     result->name,
 				     idle_event_handler, result);
 	if (result->te == NULL) {
 		DEBUG(0, ("event_add_timed failed\n"));
@@ -1363,12 +1371,7 @@
 		last_idle_closed_check = t;
 	}
 
-	if (keepalive && (t - last_keepalive_sent_time)>keepalive) {
-		if (!send_keepalive(smbd_server_fd())) {
-			DEBUG( 2, ( "Keepalive failed - exiting.\n" ) );
-			return False;
-		}
-
+	if (lp_keepalive() && (t - last_keepalive_sent_time)> lp_keepalive()) {
 		/* send a keepalive for a password server or the like.
 			This is attached to the auth_info created in the
 		negprot */

Modified: branches/SAMBA_3_0/source/smbd/server.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/server.c	2007-03-18 10:13:35 UTC (rev 21868)
+++ branches/SAMBA_3_0/source/smbd/server.c	2007-03-18 10:57:46 UTC (rev 21869)
@@ -814,6 +814,18 @@
 	return True;
 }
 
+/*
+ * Send keepalive packets to our client
+ */
+static BOOL keepalive_fn(const struct timeval *now, void *private_data)
+{
+	if (!send_keepalive(smbd_server_fd())) {
+		DEBUG( 2, ( "Keepalive failed - exiting.\n" ) );
+		return False;
+	}
+	return True;
+}
+
 /****************************************************************************
  main program.
 ****************************************************************************/
@@ -1107,6 +1119,20 @@
 	/* register our message handlers */
 	message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis, NULL);
 
+	if (lp_keepalive() != 0) {
+		struct timeval interval;
+
+		interval.tv_sec = lp_keepalive();
+		interval.tv_usec = 0;
+
+		if (!(event_add_idle(smbd_event_context(), NULL,
+				     interval, "keepalive", keepalive_fn,
+				     NULL))) {
+			DEBUG(0, ("Could not add keepalive event\n"));
+			exit(1);
+		}
+	}
+
 	smbd_process();
 
 	namecache_shutdown();



More information about the samba-cvs mailing list