svn commit: samba r22132 - in branches: SAMBA_3_0/source/modules SAMBA_3_0/source/smbd SAMBA_3_0_25/source/modules SAMBA_3_0_25/source/smbd

jra at samba.org jra at samba.org
Sun Apr 8 19:41:48 GMT 2007


Author: jra
Date: 2007-04-08 19:41:47 +0000 (Sun, 08 Apr 2007)
New Revision: 22132

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

Log:
I hate inefficiency. Don't call conv_str_size()
on every pread/sendfile call, initialize these
variables in an allocated struct at connection
time and just refer to them directly.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/modules/vfs_readahead.c
   branches/SAMBA_3_0/source/smbd/vfs.c
   branches/SAMBA_3_0_25/source/modules/vfs_readahead.c
   branches/SAMBA_3_0_25/source/smbd/vfs.c


Changeset:
Modified: branches/SAMBA_3_0/source/modules/vfs_readahead.c
===================================================================
--- branches/SAMBA_3_0/source/modules/vfs_readahead.c	2007-04-08 17:05:41 UTC (rev 22131)
+++ branches/SAMBA_3_0/source/modules/vfs_readahead.c	2007-04-08 19:41:47 UTC (rev 22132)
@@ -22,36 +22,22 @@
 static BOOL didmsg;
 #endif
 
+struct readahead_data {
+	SMB_OFF_T off_bound;
+	SMB_OFF_T len;
+	BOOL didmsg;
+};
+
 /* 
  * This module copes with Vista AIO read requests on Linux
  * by detecting the initial 0x80000 boundary reads and causing
  * the buffer cache to be filled in advance.
  */
 
-static unsigned long get_offset_boundary(struct vfs_handle_struct *handle)
-{
-	SMB_OFF_T off_bound = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
-						"readahead",
-						"offset",
-						NULL));
-	if (off_bound == 0) {
-		off_bound = 0x80000;
-	}
-	return (unsigned long)off_bound;
-}
+/*******************************************************************
+ sendfile wrapper that does readahead/posix_fadvise.
+*******************************************************************/
 
-static unsigned long get_offset_length(struct vfs_handle_struct *handle, unsigned long def_val)
-{
-	SMB_OFF_T len = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
-						"readahead",
-						"length",
-						NULL));
-	if (len == 0) {
-		len = def_val;
-	}
-	return (unsigned long)len;
-}
-
 static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
 					int tofd,
 					files_struct *fsp,
@@ -60,27 +46,27 @@
 					SMB_OFF_T offset,
 					size_t count)
 {
-	unsigned long off_bound = get_offset_boundary(handle);
-	if ( offset % off_bound == 0) {
-		unsigned long len = get_offset_length(handle, off_bound);
+	struct readahead_data *rhd = (struct readahead_data *)handle->data;
+
+	if ( offset % rhd->off_bound == 0) {
 #if defined(HAVE_LINUX_READAHEAD)
-		int err = readahead(fromfd, offset, (size_t)len);
+		int err = readahead(fromfd, offset, (size_t)rhd->len);
 		DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fromfd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 		        err ));
 #elif defined(HAVE_POSIX_FADVISE)
-		int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+		int err = posix_fadvise(fromfd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
 		DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fromfd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 			err ));
 #else
-		if (!didmsg) {
+		if (!rhd->didmsg) {
 			DEBUG(0,("readahead_sendfile: no readahead on this platform\n"));
-			didmsg = True;
+			rhd->didmsg = True;
 		}
 #endif
 	}
@@ -93,6 +79,10 @@
 					count);
 }
 
+/*******************************************************************
+ pread wrapper that does readahead/posix_fadvise.
+*******************************************************************/
+
 static ssize_t readahead_pread(vfs_handle_struct *handle,
 				files_struct *fsp,
 				int fd,
@@ -100,40 +90,97 @@
 				size_t count,
 				SMB_OFF_T offset)
 {
-	unsigned long off_bound = get_offset_boundary(handle);
-	if ( offset % off_bound == 0) {
-		unsigned long len = get_offset_length(handle, off_bound);
+	struct readahead_data *rhd = (struct readahead_data *)handle->data;
+
+	if ( offset % rhd->off_bound == 0) {
 #if defined(HAVE_LINUX_READAHEAD)
-		int err = readahead(fd, offset, (size_t)len);
+		int err = readahead(fd, offset, (size_t)rhd->len);
 		DEBUG(10,("readahead_pread: readahead on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 			err ));
 #elif defined(HAVE_POSIX_FADVISE)
-		int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+		int err = posix_fadvise(fromfd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
 		DEBUG(10,("readahead_pread: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 			(err ));
 #else
-		if (!didmsg) {
+		if (!rhd->didmsg) {
 			DEBUG(0,("readahead_pread: no readahead on this platform\n"));
-			didmsg = True;
+			rhd->didmsg = True;
 		}
 #endif
         }
         return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset);
 }
 
+/*******************************************************************
+ Directly called from main smbd when freeing handle.
+*******************************************************************/
+
+static void free_readahead_data(void **pptr)
+{
+	SAFE_FREE(*pptr);
+}
+
+/*******************************************************************
+ Allocate the handle specific data so we don't call the expensive
+ conv_str_size function for each sendfile/pread.
+*******************************************************************/
+
+static int readahead_connect(struct vfs_handle_struct *handle,
+				const char *service,
+				const char *user)
+{
+	struct readahead_data *rhd = SMB_MALLOC_P(struct readahead_data);
+	if (!rhd) {
+		DEBUG(0,("readahead_connect: out of memory\n"));
+		return -1;
+	}
+	ZERO_STRUCTP(rhd);
+
+	rhd->didmsg = False;
+	rhd->off_bound = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
+						"readahead",
+						"offset",
+						NULL));
+	if (rhd->off_bound == 0) {
+		rhd->off_bound = 0x80000;
+	}
+	rhd->len = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
+						"readahead",
+						"length",
+						NULL));
+	if (rhd->len == 0) {
+		rhd->len = rhd->off_bound;
+	}
+
+	handle->data = (void *)rhd;
+	handle->free_data = free_readahead_data;
+	return 0;
+}
+
+/*******************************************************************
+ Functions we're replacing.
+ We don't replace read as it isn't used from smbd to read file
+ data.
+*******************************************************************/
+
 static vfs_op_tuple readahead_ops [] =
 {
 	{SMB_VFS_OP(readahead_sendfile), SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT},
 	{SMB_VFS_OP(readahead_pread), SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT},
+        {SMB_VFS_OP(readahead_connect), SMB_VFS_OP_CONNECT,  SMB_VFS_LAYER_TRANSPARENT},
 	{SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
 };
 
+/*******************************************************************
+ Module initialization boilerplate.
+*******************************************************************/
+
 NTSTATUS vfs_readahead_init(void);
 NTSTATUS vfs_readahead_init(void)
 {

Modified: branches/SAMBA_3_0/source/smbd/vfs.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/vfs.c	2007-04-08 17:05:41 UTC (rev 22131)
+++ branches/SAMBA_3_0/source/smbd/vfs.c	2007-04-08 19:41:47 UTC (rev 22132)
@@ -174,7 +174,7 @@
 		DEBUG(5, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
 		if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
 			/* If this operation was already made opaque by different module, it
-			 * will be overridded here.
+			 * will be overridden here.
 			 */
 			DEBUGADD(5, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
 			vfs_set_operation(&conn->vfs_opaque, ops[i].type, handle, ops[i].op);

Modified: branches/SAMBA_3_0_25/source/modules/vfs_readahead.c
===================================================================
--- branches/SAMBA_3_0_25/source/modules/vfs_readahead.c	2007-04-08 17:05:41 UTC (rev 22131)
+++ branches/SAMBA_3_0_25/source/modules/vfs_readahead.c	2007-04-08 19:41:47 UTC (rev 22132)
@@ -22,36 +22,22 @@
 static BOOL didmsg;
 #endif
 
+struct readahead_data {
+	SMB_OFF_T off_bound;
+	SMB_OFF_T len;
+	BOOL didmsg;
+};
+
 /* 
  * This module copes with Vista AIO read requests on Linux
  * by detecting the initial 0x80000 boundary reads and causing
  * the buffer cache to be filled in advance.
  */
 
-static unsigned long get_offset_boundary(struct vfs_handle_struct *handle)
-{
-	SMB_OFF_T off_bound = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
-						"readahead",
-						"offset",
-						NULL));
-	if (off_bound == 0) {
-		off_bound = 0x80000;
-	}
-	return (unsigned long)off_bound;
-}
+/*******************************************************************
+ sendfile wrapper that does readahead/posix_fadvise.
+*******************************************************************/
 
-static unsigned long get_offset_length(struct vfs_handle_struct *handle, unsigned long def_val)
-{
-	SMB_OFF_T len = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
-						"readahead",
-						"length",
-						NULL));
-	if (len == 0) {
-		len = def_val;
-	}
-	return (unsigned long)len;
-}
-
 static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
 					int tofd,
 					files_struct *fsp,
@@ -60,27 +46,27 @@
 					SMB_OFF_T offset,
 					size_t count)
 {
-	unsigned long off_bound = get_offset_boundary(handle);
-	if ( offset % off_bound == 0) {
-		unsigned long len = get_offset_length(handle, off_bound);
+	struct readahead_data *rhd = (struct readahead_data *)handle->data;
+
+	if ( offset % rhd->off_bound == 0) {
 #if defined(HAVE_LINUX_READAHEAD)
-		int err = readahead(fromfd, offset, (size_t)len);
+		int err = readahead(fromfd, offset, (size_t)rhd->len);
 		DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fromfd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 		        err ));
 #elif defined(HAVE_POSIX_FADVISE)
-		int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+		int err = posix_fadvise(fromfd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
 		DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fromfd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 			err ));
 #else
-		if (!didmsg) {
+		if (!rhd->didmsg) {
 			DEBUG(0,("readahead_sendfile: no readahead on this platform\n"));
-			didmsg = True;
+			rhd->didmsg = True;
 		}
 #endif
 	}
@@ -93,6 +79,10 @@
 					count);
 }
 
+/*******************************************************************
+ pread wrapper that does readahead/posix_fadvise.
+*******************************************************************/
+
 static ssize_t readahead_pread(vfs_handle_struct *handle,
 				files_struct *fsp,
 				int fd,
@@ -100,40 +90,97 @@
 				size_t count,
 				SMB_OFF_T offset)
 {
-	unsigned long off_bound = get_offset_boundary(handle);
-	if ( offset % off_bound == 0) {
-		unsigned long len = get_offset_length(handle, off_bound);
+	struct readahead_data *rhd = (struct readahead_data *)handle->data;
+
+	if ( offset % rhd->off_bound == 0) {
 #if defined(HAVE_LINUX_READAHEAD)
-		int err = readahead(fd, offset, (size_t)len);
+		int err = readahead(fd, offset, (size_t)rhd->len);
 		DEBUG(10,("readahead_pread: readahead on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 			err ));
 #elif defined(HAVE_POSIX_FADVISE)
-		int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+		int err = posix_fadvise(fromfd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
 		DEBUG(10,("readahead_pread: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
 			(unsigned int)fd,
 			(unsigned long long)offset,
-			(unsigned int)len,
+			(unsigned int)rhd->len,
 			(err ));
 #else
-		if (!didmsg) {
+		if (!rhd->didmsg) {
 			DEBUG(0,("readahead_pread: no readahead on this platform\n"));
-			didmsg = True;
+			rhd->didmsg = True;
 		}
 #endif
         }
         return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset);
 }
 
+/*******************************************************************
+ Directly called from main smbd when freeing handle.
+*******************************************************************/
+
+static void free_readahead_data(void **pptr)
+{
+	SAFE_FREE(*pptr);
+}
+
+/*******************************************************************
+ Allocate the handle specific data so we don't call the expensive
+ conv_str_size function for each sendfile/pread.
+*******************************************************************/
+
+static int readahead_connect(struct vfs_handle_struct *handle,
+				const char *service,
+				const char *user)
+{
+	struct readahead_data *rhd = SMB_MALLOC_P(struct readahead_data);
+	if (!rhd) {
+		DEBUG(0,("readahead_connect: out of memory\n"));
+		return -1;
+	}
+	ZERO_STRUCTP(rhd);
+
+	rhd->didmsg = False;
+	rhd->off_bound = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
+						"readahead",
+						"offset",
+						NULL));
+	if (rhd->off_bound == 0) {
+		rhd->off_bound = 0x80000;
+	}
+	rhd->len = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
+						"readahead",
+						"length",
+						NULL));
+	if (rhd->len == 0) {
+		rhd->len = rhd->off_bound;
+	}
+
+	handle->data = (void *)rhd;
+	handle->free_data = free_readahead_data;
+	return 0;
+}
+
+/*******************************************************************
+ Functions we're replacing.
+ We don't replace read as it isn't used from smbd to read file
+ data.
+*******************************************************************/
+
 static vfs_op_tuple readahead_ops [] =
 {
 	{SMB_VFS_OP(readahead_sendfile), SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT},
 	{SMB_VFS_OP(readahead_pread), SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT},
+        {SMB_VFS_OP(readahead_connect), SMB_VFS_OP_CONNECT,  SMB_VFS_LAYER_TRANSPARENT},
 	{SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
 };
 
+/*******************************************************************
+ Module initialization boilerplate.
+*******************************************************************/
+
 NTSTATUS vfs_readahead_init(void);
 NTSTATUS vfs_readahead_init(void)
 {

Modified: branches/SAMBA_3_0_25/source/smbd/vfs.c
===================================================================
--- branches/SAMBA_3_0_25/source/smbd/vfs.c	2007-04-08 17:05:41 UTC (rev 22131)
+++ branches/SAMBA_3_0_25/source/smbd/vfs.c	2007-04-08 19:41:47 UTC (rev 22132)
@@ -174,7 +174,7 @@
 		DEBUG(5, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
 		if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
 			/* If this operation was already made opaque by different module, it
-			 * will be overridded here.
+			 * will be overridden here.
 			 */
 			DEBUGADD(5, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
 			vfs_set_operation(&conn->vfs_opaque, ops[i].type, handle, ops[i].op);



More information about the samba-cvs mailing list