[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Jan 17 17:12:04 MST 2014


The branch, master has been updated
       via  dad72a3 s3: rpc_server/srvsvc: Avoiding the loop around locking tdb traversal.
       via  de89975 s3: rpc_server/srvsvc: Adding functions to determine open files on all sessions.
       via  090f010 s3: rpc_server/srvsvc: Ensure we don't continually realloc inside init_srv_sess_info_1().
      from  da891e2 waf:lib/replace gettext configure checks

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


- Log -----------------------------------------------------------------
commit dad72a3b7ae310f8049cd76681d9d9d89ce6da52
Author: Shekhar Amlekar <samlekar at in.ibm.com>
Date:   Thu Jan 16 11:10:56 2014 -0800

    s3: rpc_server/srvsvc: Avoiding the loop around locking tdb traversal.
    
    The current code for determining the number of open files iterates
    over the session list and for each session it traverses the locking
    tdb to get the open files. This scales badly for a large server
    with many sessions and open files. Instead, get the list of
    sessions first, and then determine the number of open files on all
    sessions in a single traversal of locking tdb.
    
    Signed-off-by: Shekhar Amlekar <samlekar at in.ibm.com>
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Sat Jan 18 01:11:32 CET 2014 on sn-devel-104

commit de899754ac201c8a63646e1bc684f2a6a6e5c821
Author: Shekhar Amlekar <samlekar at in.ibm.com>
Date:   Wed Jan 8 11:32:21 2014 +0530

    s3: rpc_server/srvsvc: Adding functions to determine open files on all sessions.
    
    Introduce helper functions for counting the number of open files on an
    array of sessions.
    
    Signed-off-by: Shekhar Amlekar <samlekar at in.ibm.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 090f010006a0105a070ee4e0347a877814200d19
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jan 16 10:43:30 2014 -0800

    s3: rpc_server/srvsvc: Ensure we don't continually realloc inside init_srv_sess_info_1().
    
    Just allocate the return value directly. Makes iteration of open files much easier.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

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

Summary of changes:
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c |  107 +++++++++++++++++-----------
 1 files changed, 65 insertions(+), 42 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index 6707805..f6db6fc 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -54,10 +54,11 @@ struct file_enum_count {
 	struct srvsvc_NetFileCtr3 *ctr3;
 };
 
-struct sess_file_count {
-	struct server_id pid;
-	uid_t uid;
-	int count;
+struct sess_file_info {
+	struct srvsvc_NetSessCtr1 *ctr;
+	struct sessionid *session_list;
+	uint32_t resume_handle;
+	uint32_t num_entries;
 };
 
 /*******************************************************************
@@ -805,36 +806,52 @@ static WERROR init_srv_sess_info_0(struct pipes_struct *p,
 	return WERR_OK;
 }
 
-/*******************************************************************
-********************************************************************/
+/***********************************************************************
+ * find out the session on which this file is open and bump up its count
+ **********************************************************************/
 
-static void sess_file_fn( const struct share_mode_entry *e,
-                          const char *sharepath, const char *fname,
-			  void *data )
+static void count_sess_files_fn(const struct share_mode_entry *e,
+				const char *sharepath, const char *fname,
+				void *data)
 {
-	struct sess_file_count *sess = (struct sess_file_count *)data;
+	struct sess_file_info *info = data;
+	uint32_t rh = info->resume_handle;
+	int i;
 
-	if (serverid_equal(&e->pid, &sess->pid) && (sess->uid == e->uid)) {
-		sess->count++;
+	for (i=0; i < info->num_entries; i++) {
+		/* rh+info->num_entries is safe, as we've
+		   ensured that:
+		   *total_entries > resume_handle &&
+		   info->num_entries = *total_entries - resume_handle;
+		   inside init_srv_sess_info_1() below.
+		*/
+		struct sessionid *sess = &info->session_list[rh + i];
+		if ((e->uid == sess->uid) &&
+		     serverid_equal(&e->pid, &sess->pid)) {
+
+			info->ctr->array[i].num_open++;
+			return;
+		}
 	}
-
-	return;
 }
 
 /*******************************************************************
-********************************************************************/
+ * count the num of open files on all sessions
+ *******************************************************************/
 
-static int net_count_files( uid_t uid, struct server_id pid )
+static void net_count_files_for_all_sess(struct srvsvc_NetSessCtr1 *ctr1,
+					 struct sessionid *session_list,
+					 uint32_t resume_handle,
+					 uint32_t num_entries)
 {
-	struct sess_file_count s_file_cnt;
-
-	s_file_cnt.count = 0;
-	s_file_cnt.uid = uid;
-	s_file_cnt.pid = pid;
+	struct sess_file_info s_file_info;
 
-	share_mode_forall( sess_file_fn, &s_file_cnt );
+	s_file_info.ctr = ctr1;
+	s_file_info.session_list = session_list;
+	s_file_info.resume_handle = resume_handle;
+	s_file_info.num_entries = num_entries;
 
-	return s_file_cnt.count;
+	share_mode_forall(count_sess_files_fn, &s_file_info);
 }
 
 /*******************************************************************
@@ -862,40 +879,46 @@ static WERROR init_srv_sess_info_1(struct pipes_struct *p,
 
 	*total_entries = list_sessions(p->mem_ctx, &session_list);
 
-	for (; resume_handle < *total_entries; resume_handle++) {
-		uint32 num_files;
+	if (resume_handle >= *total_entries) {
+		if (resume_handle_p) {
+			*resume_handle_p = 0;
+		}
+		return WERR_OK;
+	}
+
+	/* We know num_entries must be positive, due to
+	   the check resume_handle >= *total_entries above. */
+
+	num_entries = *total_entries - resume_handle;
+
+	ctr1->array = talloc_zero_array(p->mem_ctx,
+				   struct srvsvc_NetSessInfo1,
+				   num_entries);
+
+	W_ERROR_HAVE_NO_MEMORY(ctr1->array);
+
+	for (num_entries = 0; resume_handle < *total_entries; num_entries++, resume_handle++) {
 		uint32 connect_time;
-		struct passwd *pw = getpwnam(session_list[resume_handle].username);
 		bool guest;
 
-		if ( !pw ) {
-			DEBUG(10,("init_srv_sess_info_1: failed to find owner: %s\n",
-				session_list[resume_handle].username));
-			continue;
-		}
-
 		connect_time = (uint32_t)(now - session_list[resume_handle].connect_start);
-		num_files = net_count_files(pw->pw_uid, session_list[resume_handle].pid);
 		guest = strequal( session_list[resume_handle].username, lp_guestaccount() );
 
-		ctr1->array = talloc_realloc(p->mem_ctx,
-						   ctr1->array,
-						   struct srvsvc_NetSessInfo1,
-						   num_entries+1);
-		W_ERROR_HAVE_NO_MEMORY(ctr1->array);
-
 		ctr1->array[num_entries].client		= session_list[resume_handle].remote_machine;
 		ctr1->array[num_entries].user		= session_list[resume_handle].username;
-		ctr1->array[num_entries].num_open	= num_files;
+		ctr1->array[num_entries].num_open	= 0;/* computed later */
 		ctr1->array[num_entries].time		= connect_time;
 		ctr1->array[num_entries].idle_time	= 0;
 		ctr1->array[num_entries].user_flags	= guest;
-
-		num_entries++;
 	}
 
 	ctr1->count = num_entries;
 
+	/* count open files on all sessions in single tdb traversal */
+	net_count_files_for_all_sess(ctr1, session_list,
+				     resume_handle_p ? *resume_handle_p : 0,
+				     num_entries);
+
 	if (resume_handle_p) {
 		if (*resume_handle_p >= *total_entries) {
 			*resume_handle_p = 0;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list