[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Jul 29 14:47:29 MDT 2010


The branch, master has been updated
       via  a8cd3ef... s3: Do the ftruncate write cache optimization in one place
       via  a86cad3... Revert "s3: Avoid pwrite calls for the 1-byte writes with zero content"
       via  fec8505... s3: Avoid an unnecessary ftruncate call
      from  4f43030... Fix bug #7589 - ntlm_auth fails to use cached credentials.

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


- Log -----------------------------------------------------------------
commit a8cd3ef99eb70d70b9272b6e3ab5cc737195e06c
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jul 29 14:48:06 2010 +0200

    s3: Do the ftruncate write cache optimization in one place
    
    Instead of hand-tuning all the cases that are below this piece of code, this is
    a general case that we can catch upfront.

commit a86cad3921c4a8ddbcab1929c825356aec4fe76a
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jul 29 14:21:14 2010 +0200

    Revert "s3: Avoid pwrite calls for the 1-byte writes with zero content"
    
    This reverts commit 6763730304627a58139450fd3e03a0ce48e31bb9.

commit fec8505e0be067a09929216cfe476802f21d14fe
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Jul 29 17:04:18 2010 +0200

    s3: Avoid an unnecessary ftruncate call
    
    If we just created the file, it has length 0 by definition. This is still done
    while holding the share mode lock, so no race around wrt other cifs clients.

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

Summary of changes:
 source3/smbd/fileio.c |   85 ++++++++++++++++++++-----------------------------
 source3/smbd/open.c   |    2 +-
 2 files changed, 36 insertions(+), 51 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index e5a2888..b4e8a1d 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -401,6 +401,37 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
 
 	fsp->fh->pos = pos + n;
 
+	if ((n == 1) && (data[0] == '\0') && (pos > wcp->file_size)) {
+		int ret;
+
+		/*
+		 * This is a 1-byte write of a 0 beyond the EOF and
+		 * thus implicitly also beyond the current active
+		 * write cache, the typical file-extending (and
+		 * allocating, but we're using the write cache here)
+		 * write done by Windows. We just have to ftruncate
+		 * the file and rely on posix semantics to return
+		 * zeros for non-written file data that is within the
+		 * file length.
+		 *
+		 * We can not use wcp_file_size_change here because we
+		 * might have an existing write cache, and
+		 * wcp_file_size_change assumes a change to just the
+		 * end of the current write cache.
+		 */
+
+		wcp->file_size = pos + 1;
+		ret = SMB_VFS_FTRUNCATE(fsp, wcp->file_size);
+		if (ret == -1) {
+			DEBUG(0,("wcp_file_size_change (%s): ftruncate of size %.0f"
+				 "error %s\n", fsp_str_dbg(fsp),
+				 (double)wcp->file_size, strerror(errno)));
+			return -1;
+		}
+		return 1;
+	}
+
+
 	/*
 	 * If we have active cache and it isn't contiguous then we flush.
 	 * NOTE: There is a small problem with running out of disk ....
@@ -649,31 +680,10 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
                         */
 
 			flush_write_cache(fsp, WRITE_FLUSH);
-
-			if (data[0] == '\0') {
-				/*
-				 * This is a 1-byte write of a 0
-				 * beyond the EOF, the typical
-				 * file-extending (and allocating, but
-				 * we're using the write cache here)
-				 * write done by Windows. We just have
-				 * to ftruncate the file and rely on
-				 * posix semantics to return zeros for
-				 * non-written file data that is
-				 * within the file length.
-				 *
-				 * We have to cheat the offset to make
-				 * wcp_file_size_change do the right
-				 * thing with the ftruncate call.
-				 */
-				wcp->offset = pos + 1;
-				wcp->data_size = 0;
-			} else {
-				wcp->offset = wcp->file_size;
-				wcp->data_size = pos - wcp->file_size + 1;
-				memset(wcp->data, '\0', wcp->data_size);
-				memcpy(wcp->data + wcp->data_size-1, data, 1);
-			}
+			wcp->offset = wcp->file_size;
+			wcp->data_size = pos - wcp->file_size + 1;
+			memset(wcp->data, '\0', wcp->data_size);
+			memcpy(wcp->data + wcp->data_size-1, data, 1);
 
 			/*
 			 * Update the file size if changed.
@@ -816,31 +826,6 @@ n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
 
 		if ((wcp->data_size == 0)
 		    && (pos > wcp->file_size)
-		    && (n == 1)
-		    && (data[0] == '\0')) {
-			/*
-			 * This is a 1-byte write of a 0 beyond the
-			 * EOF, the typical file-extending (and
-			 * allocating, but we're using the write cache
-			 * here) write done by Windows. We just have
-			 * to ftruncate the file and rely on posix
-			 * semantics to return zeros for non-written
-			 * file data that is within the file length.
-			 *
-			 * We have to cheat the offset to make
-			 * wcp_file_size_change do the right thing
-			 * with the ftruncate call.
-			 */
-			wcp->offset = pos+1;
-			wcp->data_size = 0;
-			if (wcp_file_size_change(fsp) == -1) {
-				return -1;
-			}
-			return 1;
-		}
-
-		if ((wcp->data_size == 0)
-		    && (pos > wcp->file_size)
 		    && (pos + n <= wcp->file_size + wcp->alloc_size)) {
 			/*
 			 * This is a write completely beyond the
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 55ea896..ba1fbf2 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2142,7 +2142,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 	 * If requested, truncate the file.
 	 */
 
-	if (flags2&O_TRUNC) {
+	if (file_existed && (flags2&O_TRUNC)) {
 		/*
 		 * We are modifing the file after open - update the stat
 		 * struct..


-- 
Samba Shared Repository


More information about the samba-cvs mailing list