[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Thu Mar 17 18:14:01 MDT 2011


The branch, master has been updated
       via  066fecd The searches struct is still being used and idled in SMB2 - move it to the global section until we decide if we want to idle SMB2 directory handles.
       via  4c77d62 Fix crash bug on smbd shutdown when using FOPENDIR() found by Volker.
      from  9bc10bd s3: Expose num_opens via api_RNetSessionEnum

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


- Log -----------------------------------------------------------------
commit 066fecd315c4c6e678e1d635e6a346e357a3b7a5
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Mar 17 16:16:54 2011 -0700

    The searches struct is still being used and idled in SMB2 - move it to the global
    section until we decide if we want to idle SMB2 directory handles.
    
    Jeremy.
    
    Autobuild-User: Jeremy Allison <jra at samba.org>
    Autobuild-Date: Fri Mar 18 01:13:53 CET 2011 on sn-devel-104

commit 4c77d620e6cc5ea31f4a8f0bf9c8dab81f5f1002
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Mar 17 15:55:15 2011 -0700

    Fix crash bug on smbd shutdown when using FOPENDIR() found by Volker.
    
    The key was allowing the dptr_idle code to be triggered. We were
    closing the dirp->dir handle without updating the underlying fd
    in the open fsp.
    
    Jeremy.

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

Summary of changes:
 source3/smbd/dir.c     |   66 ++++++++++++++++++++++++++++-------------------
 source3/smbd/globals.h |   12 +++++---
 2 files changed, 46 insertions(+), 32 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index b9791e9..a85e5a7 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -122,14 +122,14 @@ bool make_dir_struct(TALLOC_CTX *ctx,
 
 bool init_dptrs(struct smbd_server_connection *sconn)
 {
-	if (sconn->smb1.searches.dptr_bmap) {
+	if (sconn->searches.dptr_bmap) {
 		return true;
 	}
 
-	sconn->smb1.searches.dptr_bmap = bitmap_talloc(
+	sconn->searches.dptr_bmap = bitmap_talloc(
 		sconn, MAX_DIRECTORY_HANDLES);
 
-	if (sconn->smb1.searches.dptr_bmap == NULL) {
+	if (sconn->searches.dptr_bmap == NULL) {
 		return false;
 	}
 
@@ -159,7 +159,7 @@ static void dptr_idleoldest(struct smbd_server_connection *sconn)
 	/*
 	 * Go to the end of the list.
 	 */
-	dptr = DLIST_TAIL(sconn->smb1.searches.dirptrs);
+	dptr = DLIST_TAIL(sconn->searches.dirptrs);
 
 	if(!dptr) {
 		DEBUG(0,("No dptrs available to idle ?\n"));
@@ -187,10 +187,10 @@ static struct dptr_struct *dptr_get(struct smbd_server_connection *sconn,
 {
 	struct dptr_struct *dptr;
 
-	for(dptr = sconn->smb1.searches.dirptrs; dptr; dptr = dptr->next) {
+	for(dptr = sconn->searches.dirptrs; dptr; dptr = dptr->next) {
 		if(dptr->dnum == key) {
 			if (!forclose && !dptr->dir_hnd) {
-				if (sconn->smb1.searches.dirhandles_open >= MAX_OPEN_DIRECTORIES)
+				if (sconn->searches.dirhandles_open >= MAX_OPEN_DIRECTORIES)
 					dptr_idleoldest(sconn);
 				DEBUG(4,("dptr_get: Reopening dptr key %d\n",key));
 				if (!(dptr->dir_hnd = OpenDir(
@@ -201,7 +201,7 @@ static struct dptr_struct *dptr_get(struct smbd_server_connection *sconn,
 					return False;
 				}
 			}
-			DLIST_PROMOTE(sconn->smb1.searches.dirptrs,dptr);
+			DLIST_PROMOTE(sconn->searches.dirptrs,dptr);
 			return dptr;
 		}
 	}
@@ -258,19 +258,19 @@ static void dptr_close_internal(struct dptr_struct *dptr)
 		goto done;
 	}
 
-	DLIST_REMOVE(sconn->smb1.searches.dirptrs, dptr);
+	DLIST_REMOVE(sconn->searches.dirptrs, dptr);
 
 	/*
 	 * Free the dnum in the bitmap. Remember the dnum value is always 
 	 * biased by one with respect to the bitmap.
 	 */
 
-	if (!bitmap_query(sconn->smb1.searches.dptr_bmap, dptr->dnum - 1)) {
+	if (!bitmap_query(sconn->searches.dptr_bmap, dptr->dnum - 1)) {
 		DEBUG(0,("dptr_close_internal : Error - closing dnum = %d and bitmap not set !\n",
 			dptr->dnum ));
 	}
 
-	bitmap_clear(sconn->smb1.searches.dptr_bmap, dptr->dnum - 1);
+	bitmap_clear(sconn->searches.dptr_bmap, dptr->dnum - 1);
 
 done:
 	TALLOC_FREE(dptr->dir_hnd);
@@ -295,7 +295,7 @@ void dptr_close(struct smbd_server_connection *sconn, int *key)
 	/* OS/2 seems to use -1 to indicate "close all directories" */
 	if (*key == -1) {
 		struct dptr_struct *next;
-		for(dptr = sconn->smb1.searches.dirptrs; dptr; dptr = next) {
+		for(dptr = sconn->searches.dirptrs; dptr; dptr = next) {
 			next = dptr->next;
 			dptr_close_internal(dptr);
 		}
@@ -328,7 +328,7 @@ void dptr_closecnum(connection_struct *conn)
 		return;
 	}
 
-	for(dptr = sconn->smb1.searches.dirptrs; dptr; dptr = next) {
+	for(dptr = sconn->searches.dirptrs; dptr; dptr = next) {
 		next = dptr->next;
 		if (dptr->conn == conn) {
 			dptr_close_internal(dptr);
@@ -349,7 +349,7 @@ void dptr_idlecnum(connection_struct *conn)
 		return;
 	}
 
-	for(dptr = sconn->smb1.searches.dirptrs; dptr; dptr = dptr->next) {
+	for(dptr = sconn->searches.dirptrs; dptr; dptr = dptr->next) {
 		if (dptr->conn == conn && dptr->dir_hnd) {
 			dptr_idle(dptr);
 		}
@@ -364,7 +364,7 @@ void dptr_closepath(struct smbd_server_connection *sconn,
 		    char *path,uint16 spid)
 {
 	struct dptr_struct *dptr, *next;
-	for(dptr = sconn->smb1.searches.dirptrs; dptr; dptr = next) {
+	for(dptr = sconn->searches.dirptrs; dptr; dptr = next) {
 		next = dptr->next;
 		if (spid == dptr->spid && strequal(dptr->path,path))
 			dptr_close_internal(dptr);
@@ -385,7 +385,7 @@ static void dptr_close_oldest(struct smbd_server_connection *sconn,
 	/*
 	 * Go to the end of the list.
 	 */
-	for(dptr = sconn->smb1.searches.dirptrs; dptr && dptr->next; dptr = dptr->next)
+	for(dptr = sconn->searches.dirptrs; dptr && dptr->next; dptr = dptr->next)
 		;
 
 	if(!dptr) {
@@ -455,7 +455,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 		return map_nt_error_from_unix(errno);
 	}
 
-	if (sconn->smb1.searches.dirhandles_open >= MAX_OPEN_DIRECTORIES) {
+	if (sconn->searches.dirhandles_open >= MAX_OPEN_DIRECTORIES) {
 		dptr_idleoldest(sconn);
 	}
 
@@ -475,7 +475,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 		 * value we return will fit in the range 1-255.
 		 */
 
-		dptr->dnum = bitmap_find(sconn->smb1.searches.dptr_bmap, 0);
+		dptr->dnum = bitmap_find(sconn->searches.dptr_bmap, 0);
 
 		if(dptr->dnum == -1 || dptr->dnum > 254) {
 
@@ -488,7 +488,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 			dptr_close_oldest(sconn, true);
 
 			/* Now try again... */
-			dptr->dnum = bitmap_find(sconn->smb1.searches.dptr_bmap, 0);
+			dptr->dnum = bitmap_find(sconn->searches.dptr_bmap, 0);
 			if(dptr->dnum == -1 || dptr->dnum > 254) {
 				DEBUG(0,("dptr_create: returned %d: Error - all old dirptrs in use ?\n", dptr->dnum));
 				SAFE_FREE(dptr);
@@ -503,7 +503,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 		 * a range that will return 256 - MAX_DIRECTORY_HANDLES.
 		 */
 
-		dptr->dnum = bitmap_find(sconn->smb1.searches.dptr_bmap, 255);
+		dptr->dnum = bitmap_find(sconn->searches.dptr_bmap, 255);
 
 		if(dptr->dnum == -1 || dptr->dnum < 255) {
 
@@ -517,7 +517,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 			dptr_close_oldest(sconn, false);
 
 			/* Now try again... */
-			dptr->dnum = bitmap_find(sconn->smb1.searches.dptr_bmap, 255);
+			dptr->dnum = bitmap_find(sconn->searches.dptr_bmap, 255);
 
 			if(dptr->dnum == -1 || dptr->dnum < 255) {
 				DEBUG(0,("dptr_create: returned %d: Error - all new dirptrs in use ?\n", dptr->dnum));
@@ -528,7 +528,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 		}
 	}
 
-	bitmap_set(sconn->smb1.searches.dptr_bmap, dptr->dnum);
+	bitmap_set(sconn->searches.dptr_bmap, dptr->dnum);
 
 	dptr->dnum += 1; /* Always bias the dnum by one - no zero dnums allowed. */
 
@@ -539,7 +539,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 	dptr->expect_close = expect_close;
 	dptr->wcard = SMB_STRDUP(wcard);
 	if (!dptr->wcard) {
-		bitmap_clear(sconn->smb1.searches.dptr_bmap, dptr->dnum - 1);
+		bitmap_clear(sconn->searches.dptr_bmap, dptr->dnum - 1);
 		SAFE_FREE(dptr);
 		TALLOC_FREE(dir_hnd);
 		return NT_STATUS_NO_MEMORY;
@@ -552,7 +552,7 @@ NTSTATUS dptr_create(connection_struct *conn, files_struct *fsp,
 
 	dptr->attr = attr;
 
-	DLIST_ADD(sconn->smb1.searches.dirptrs, dptr);
+	DLIST_ADD(sconn->searches.dirptrs, dptr);
 
 	DEBUG(3,("creating new dirptr %d for path %s, expect_close = %d\n",
 		dptr->dnum,path,expect_close));  
@@ -575,7 +575,9 @@ void dptr_CloseDir(files_struct *fsp)
  * present. I hate Solaris. JRA.
  */
 #ifdef HAVE_DIRFD
-		if (fsp->fh->fd == dirfd(fsp->dptr->dir_hnd->dir)) {
+		if (fsp->fh->fd != -1 &&
+				fsp->dptr->dir_hnd &&
+				dirfd(fsp->dptr->dir_hnd->dir)) {
 			/* The call below closes the underlying fd. */
 			fsp->fh->fd = -1;
 		}
@@ -1311,10 +1313,20 @@ bool is_visible_file(connection_struct *conn, const char *dir_path,
 static int smb_Dir_destructor(struct smb_Dir *dirp)
 {
 	if (dirp->dir) {
+#ifdef HAVE_DIRFD
+		if (dirp->conn->sconn) {
+			files_struct *fsp = file_find_fd(dirp->conn->sconn,
+						dirfd(dirp->dir));
+			if (fsp) {
+				/* The call below closes the underlying fd. */
+				fsp->fh->fd = -1;
+			}
+		}
+#endif
 		SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
 	}
 	if (dirp->conn->sconn) {
-		dirp->conn->sconn->smb1.searches.dirhandles_open--;
+		dirp->conn->sconn->searches.dirhandles_open--;
 	}
 	return 0;
 }
@@ -1345,7 +1357,7 @@ struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn,
 	}
 
 	if (sconn) {
-		sconn->smb1.searches.dirhandles_open++;
+		sconn->searches.dirhandles_open++;
 	}
 	talloc_set_destructor(dirp, smb_Dir_destructor);
 
@@ -1389,7 +1401,7 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, connection_struct *conn,
 	}
 
 	if (sconn) {
-		sconn->smb1.searches.dirhandles_open++;
+		sconn->searches.dirhandles_open++;
 	}
 	talloc_set_destructor(dirp, smb_Dir_destructor);
 
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index de01248..01be31a 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -475,6 +475,13 @@ struct smbd_server_connection {
 	/* number of open connections (tcons) */
 	int num_tcons_open;
 
+	/* open directory handles. */
+	struct {
+		struct bitmap *dptr_bmap;
+		struct dptr_struct *dirptrs;
+		int dirhandles_open;
+	} searches;
+
 	struct {
 		struct fd_event *fde;
 
@@ -549,11 +556,6 @@ struct smbd_server_connection {
 		struct notify_mid_map *notify_mid_maps;
 
 		struct {
-			struct bitmap *dptr_bmap;
-			struct dptr_struct *dirptrs;
-			int dirhandles_open;
-		} searches;
-		struct {
 			/* dlink list we store pending lock records on. */
 			struct blocking_lock_record *blocking_lock_queue;
 			/* dlink list we move cancelled lock records onto. */


-- 
Samba Shared Repository


More information about the samba-cvs mailing list