[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-167-g81ca585

Jeremy Allison jra at samba.org
Fri Nov 2 19:22:09 GMT 2007


The branch, v3-2-test has been updated
       via  81ca5853b2475f123faab3b550f0a7b24ae3c208 (commit)
       via  319dfbaf1b8d08171731d4575127f4bb5255a229 (commit)
       via  619e33248d12e764e902e4fdb5fb223cb9cfea3b (commit)
      from  95de80218c10a72c7b28541c3c2e475e083b68f1 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 81ca5853b2475f123faab3b550f0a7b24ae3c208
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Nov 2 12:21:34 2007 -0700

    Change the client library to write directly out of
    the incoming buffer in the non-signed case. Speeds
    up writes by over 10% or so. Complete the server
    recvfile implementation.
    Jeremy.

commit 319dfbaf1b8d08171731d4575127f4bb5255a229
Merge: 619e33248d12e764e902e4fdb5fb223cb9cfea3b 95de80218c10a72c7b28541c3c2e475e083b68f1
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Nov 2 12:06:15 2007 -0700

    Merge branch 'v3-2-test' of ssh://jra@git.samba.org/data/git/samba into v3-2-test

commit 619e33248d12e764e902e4fdb5fb223cb9cfea3b
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Nov 2 12:05:17 2007 -0700

    Forgot one more getnameinfo.
    Jeremy.

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

Summary of changes:
 source/client/client.c       |   30 ++++++++++++
 source/include/client.h      |    1 +
 source/include/smb_macros.h  |    4 +-
 source/libsmb/clientgen.c    |   65 ++++++++++++++++++++++++-
 source/libsmb/clireadwrite.c |  106 +++++++++++++++++++++++++++++-------------
 source/smbd/reply.c          |   15 ++++--
 source/utils/nmblookup.c     |    2 +-
 7 files changed, 180 insertions(+), 43 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/client/client.c b/source/client/client.c
index a381d13..27f120c 100644
--- a/source/client/client.c
+++ b/source/client/client.c
@@ -3227,6 +3227,35 @@ static int cmd_show_connect( void )
 	return 0;
 }
 
+/****************************************************************************
+ iosize command
+***************************************************************************/
+
+int cmd_iosize(void)
+{
+	fstring buf;
+	int iosize;
+
+	if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+		DEBUG(0, ("iosize <n> or iosize 0x<n>. "
+			"Minimum is 16384 (0x4000), "
+			"max is 16776960 (0xFFFF00)\n"));
+		return 1;
+	}
+
+	iosize = strtol(buf,NULL,0);
+	if (iosize < 0 || iosize > 0xFFFF00) {
+		DEBUG(0, ("iosize out of range (min = 16384 (0x4000), "
+			"max = 16776960 (0x0xFFFF00)"));
+		return 1;
+	}
+
+	io_bufsize = iosize;
+	d_printf("iosize is now %d\n", io_bufsize);
+	return 0;
+}
+
+
 /* Some constants for completing filename arguments */
 
 #define COMPL_NONE        0          /* No completions */
@@ -3265,6 +3294,7 @@ static struct
   {"hardlink",cmd_hardlink,"<src> <dest> create a Windows hard link",{COMPL_REMOTE,COMPL_REMOTE}},
   {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
   {"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
+  {"iosize",cmd_iosize,"iosize <number> (default 64512)",{COMPL_NONE,COMPL_NONE}},
   {"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
   {"link",cmd_link,"<oldname> <newname> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
   {"lock",cmd_lock,"lock <fnum> [r|w] <hex-start> <hex-len> : set a POSIX lock",{COMPL_REMOTE,COMPL_REMOTE}},
diff --git a/source/include/client.h b/source/include/client.h
index c4669db..e38017f 100644
--- a/source/include/client.h
+++ b/source/include/client.h
@@ -29,6 +29,7 @@
 #define CLI_SAMBA_MAX_LARGE_READX_SIZE (127*1024) /* Works for Samba servers */
 #define CLI_WINDOWS_MAX_LARGE_READX_SIZE ((64*1024)-2) /* Windows servers are broken.... */
 #define CLI_SAMBA_MAX_POSIX_LARGE_READX_SIZE (0xFFFF00) /* 24-bit len. */
+#define CLI_SAMBA_MAX_POSIX_LARGE_WRITEX_SIZE (0xFFFF00) /* 24-bit len. */
 
 /*
  * These definitions depend on smb.h
diff --git a/source/include/smb_macros.h b/source/include/smb_macros.h
index 9af6345..0dfb596 100644
--- a/source/include/smb_macros.h
+++ b/source/include/smb_macros.h
@@ -193,8 +193,8 @@
         buf[2] = (len&0xFF00)>>8; buf[3] = len&0xFF; } while (0)
 
 #define smb_len_large(buf) (PVAL(buf,3)|(PVAL(buf,2)<<8)|(PVAL(buf,1)<<16))
-#define _smb_setlen_large(buf,len) do { buf[0] = 0; buf[1] = (len&0xFF0000)>>16; \
-        buf[2] = (len&0xFF00)>>8; buf[3] = len&0xFF; } while (0)
+#define _smb_setlen_large(buf,len) do { buf[0] = 0; buf[1] = ((len)&0xFF0000)>>16; \
+        buf[2] = ((len)&0xFF00)>>8; buf[3] = (len)&0xFF; } while (0)
 
 /*******************************************************************
 find the difference in milliseconds between two struct timeval
diff --git a/source/libsmb/clientgen.c b/source/libsmb/clientgen.c
index ca05b2e..19210dd 100644
--- a/source/libsmb/clientgen.c
+++ b/source/libsmb/clientgen.c
@@ -251,15 +251,15 @@ bool cli_receive_smb_readX_header(struct cli_state *cli)
 static ssize_t write_socket(int fd, const char *buf, size_t len)
 {
         ssize_t ret=0;
-                                                                                                                                            
+
         DEBUG(6,("write_socket(%d,%d)\n",fd,(int)len));
         ret = write_data(fd,buf,len);
-                                                                                                                                            
+
         DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,(int)len,(int)ret));
         if(ret <= 0)
                 DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n",
                         (int)len, fd, strerror(errno) ));
-                                                                                                                                            
+
         return(ret);
 }
 
@@ -301,6 +301,65 @@ bool cli_send_smb(struct cli_state *cli)
 }
 
 /****************************************************************************
+ Send a "direct" writeX smb to a fd.
+****************************************************************************/
+
+bool cli_send_smb_direct_writeX(struct cli_state *cli,
+				const char *p,
+				size_t extradata)
+{
+	/* First length to send is the offset to the data. */
+	size_t len = SVAL(cli->outbuf,smb_vwv11) + 4;
+	size_t nwritten=0;
+	ssize_t ret;
+
+	/* fd == -1 causes segfaults -- Tom (tom at ninja.nl) */
+	if (cli->fd == -1) {
+		return false;
+	}
+
+	if (client_is_signing_on(cli)) {
+		DEBUG(0,("cli_send_smb_large: cannot send signed packet.\n"));
+		return false;
+	}
+
+	while (nwritten < len) {
+		ret = write_socket(cli->fd,cli->outbuf+nwritten,len - nwritten);
+		if (ret <= 0) {
+			close(cli->fd);
+			cli->fd = -1;
+			cli->smb_rw_error = WRITE_ERROR;
+			DEBUG(0,("Error writing %d bytes to client. %d (%s)\n",
+				(int)len,(int)ret, strerror(errno) ));
+			return false;
+		}
+		nwritten += ret;
+	}
+
+	/* Now write the extra data. */
+	nwritten=0;
+	while (nwritten < extradata) {
+		ret = write_socket(cli->fd,p+nwritten,extradata - nwritten);
+		if (ret <= 0) {
+			close(cli->fd);
+			cli->fd = -1;
+			cli->smb_rw_error = WRITE_ERROR;
+			DEBUG(0,("Error writing %d extradata "
+				"bytes to client. %d (%s)\n",
+				(int)extradata,(int)ret, strerror(errno) ));
+			return False;
+		}
+		nwritten += ret;
+	}
+
+	/* Increment the mid so we can tell between responses. */
+	cli->mid++;
+	if (!cli->mid)
+		cli->mid++;
+	return true;
+}
+
+/****************************************************************************
  Setup basics in a outgoing packet.
 ****************************************************************************/
 
diff --git a/source/libsmb/clireadwrite.c b/source/libsmb/clireadwrite.c
index e2d5337..0c79da9 100644
--- a/source/libsmb/clireadwrite.c
+++ b/source/libsmb/clireadwrite.c
@@ -1,18 +1,18 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    client file read/write routines
    Copyright (C) Andrew Tridgell 1994-1998
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -23,7 +23,7 @@
 Issue a single SMBread and don't wait for a reply.
 ****************************************************************************/
 
-static bool cli_issue_read(struct cli_state *cli, int fnum, off_t offset, 
+static bool cli_issue_read(struct cli_state *cli, int fnum, off_t offset,
 			   size_t size, int i)
 {
 	bool bigoffset = False;
@@ -31,11 +31,11 @@ static bool cli_issue_read(struct cli_state *cli, int fnum, off_t offset,
 	memset(cli->outbuf,'\0',smb_size);
 	memset(cli->inbuf,'\0',smb_size);
 
-	if ((SMB_BIG_UINT)offset >> 32) 
+	if ((SMB_BIG_UINT)offset >> 32)
 		bigoffset = True;
 
 	set_message(cli->outbuf,bigoffset ? 12 : 10,0,True);
-		
+
 	SCVAL(cli->outbuf,smb_com,SMBreadX);
 	SSVAL(cli->outbuf,smb_tid,cli->cnum);
 	cli_setup_packet(cli);
@@ -68,7 +68,7 @@ ssize_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_
 	/* We can only do direct reads if not signing. */
 	bool direct_reads = !client_is_signing_on(cli);
 
-	if (size == 0) 
+	if (size == 0)
 		return 0;
 
 	/*
@@ -280,18 +280,25 @@ ssize_t cli_readraw(struct cli_state *cli, int fnum, char *buf, off_t offset, si
 	return total;
 }
 #endif
+
 /****************************************************************************
-issue a single SMBwrite and don't wait for a reply
+ Issue a single SMBwrite and don't wait for a reply.
 ****************************************************************************/
 
-static bool cli_issue_write(struct cli_state *cli, int fnum, off_t offset, 
-			    uint16 mode, const char *buf,
-			    size_t size, int i)
+static bool cli_issue_write(struct cli_state *cli,
+				int fnum,
+				off_t offset,
+				uint16 mode,
+				const char *buf,
+				size_t size,
+				int i)
 {
 	char *p;
-	bool large_writex = False;
+	bool large_writex = false;
+	/* We can only do direct writes if not signing. */
+	bool direct_writes = !client_is_signing_on(cli);
 
-	if (size + 1 > cli->bufsize) {
+	if (!direct_writes && size + 1 > cli->bufsize) {
 		cli->outbuf = (char *)SMB_REALLOC(cli->outbuf, size + 1024);
 		if (!cli->outbuf) {
 			return False;
@@ -311,10 +318,11 @@ static bool cli_issue_write(struct cli_state *cli, int fnum, off_t offset,
 		large_writex = True;
 	}
 
-	if (large_writex)
+	if (large_writex) {
 		set_message(cli->outbuf,14,0,True);
-	else
+	} else {
 		set_message(cli->outbuf,12,0,True);
+	}
 
 	SCVAL(cli->outbuf,smb_com,SMBwriteX);
 	SSVAL(cli->outbuf,smb_tid,cli->cnum);
@@ -334,7 +342,7 @@ static bool cli_issue_write(struct cli_state *cli, int fnum, off_t offset,
 	 * locally. However, this check might already have been
 	 * done by our callers.
 	 */
-	SSVAL(cli->outbuf,smb_vwv9,((size>>16)&1));
+	SSVAL(cli->outbuf,smb_vwv9,(size>>16));
 	SSVAL(cli->outbuf,smb_vwv10,size);
 	/* +1 is pad byte. */
 	SSVAL(cli->outbuf,smb_vwv11,
@@ -346,13 +354,27 @@ static bool cli_issue_write(struct cli_state *cli, int fnum, off_t offset,
 
 	p = smb_base(cli->outbuf) + SVAL(cli->outbuf,smb_vwv11) -1;
 	*p++ = '\0'; /* pad byte. */
-	memcpy(p, buf, size);
-	cli_setup_bcc(cli, p+size);
+	if (!direct_writes) {
+		memcpy(p, buf, size);
+	}
+	if (size > 0x1FFFF) {
+		/* This is a POSIX 14 word large write. */
+		set_message_bcc(cli->outbuf, 0); /* Set bcc to zero. */
+		_smb_setlen_large(cli->outbuf,smb_size + 28 + 1 /* pad */ + size - 4);
+	} else {
+		cli_setup_bcc(cli, p+size);
+	}
 
 	SSVAL(cli->outbuf,smb_mid,cli->mid + i);
 
 	show_msg(cli->outbuf);
-	return cli_send_smb(cli);
+	if (direct_writes) {
+		/* For direct writes we now need to write the data
+		 * directly out of buf. */
+		return cli_send_smb_direct_writeX(cli, buf, size);
+	} else {
+		return cli_send_smb(cli);
+	}
 }
 
 /****************************************************************************
@@ -371,8 +393,8 @@ ssize_t cli_write(struct cli_state *cli,
 	unsigned int issued = 0;
 	unsigned int received = 0;
 	int mpx = 1;
-	int block = cli->max_xmit - (smb_size+32);
-	int blocks = (size + (block-1)) / block;
+	size_t writesize;
+	int blocks;
 
 	if(cli->max_mux > 1) {
 		mpx = cli->max_mux-1;
@@ -380,11 +402,29 @@ ssize_t cli_write(struct cli_state *cli,
 		mpx = 1;
 	}
 
+        if (!client_is_signing_on(cli) &&
+			(cli->posix_capabilities & CIFS_UNIX_LARGE_WRITE_CAP) &&
+			(cli->capabilities & CAP_LARGE_FILES)) {
+		/* Only do massive writes if we can do them direct
+		 * with no signing. */
+		writesize = CLI_SAMBA_MAX_POSIX_LARGE_WRITEX_SIZE;
+	} else if (cli->capabilities & CAP_LARGE_READX) {
+		if (cli->is_samba) {
+			writesize = CLI_SAMBA_MAX_LARGE_READX_SIZE;
+		} else {
+			writesize = CLI_WINDOWS_MAX_LARGE_READX_SIZE;
+		}
+	} else {
+		writesize = (cli->max_xmit - (smb_size+32)) & ~1023;
+	}
+
+	blocks = (size + (writesize-1)) / writesize;
+
 	while (received < blocks) {
 
 		while ((issued - received < mpx) && (issued < blocks)) {
-			ssize_t bsent = issued * block;
-			ssize_t size1 = MIN(block, size - bsent);
+			ssize_t bsent = issued * writesize;
+			ssize_t size1 = MIN(writesize, size - bsent);
 
 			if (!cli_issue_write(cli, fnum, offset + bsent,
 			                write_mode,
@@ -394,8 +434,9 @@ ssize_t cli_write(struct cli_state *cli,
 			issued++;
 		}
 
-		if (!cli_receive_smb(cli))
+		if (!cli_receive_smb(cli)) {
 			return bwritten;
+		}
 
 		received++;
 
@@ -406,9 +447,10 @@ ssize_t cli_write(struct cli_state *cli,
 		bwritten += (((int)(SVAL(cli->inbuf, smb_vwv4)))<<16);
 	}
 
-	while (received < issued && cli_receive_smb(cli))
+	while (received < issued && cli_receive_smb(cli)) {
 		received++;
-	
+	}
+
 	return bwritten;
 }
 
@@ -424,7 +466,7 @@ ssize_t cli_smbwrite(struct cli_state *cli,
 
 	do {
 		size_t size = MIN(size1, cli->max_xmit - 48);
-		
+
 		memset(cli->outbuf,'\0',smb_size);
 		memset(cli->inbuf,'\0',smb_size);
 
@@ -433,25 +475,25 @@ ssize_t cli_smbwrite(struct cli_state *cli,
 		SCVAL(cli->outbuf,smb_com,SMBwrite);
 		SSVAL(cli->outbuf,smb_tid,cli->cnum);
 		cli_setup_packet(cli);
-		
+
 		SSVAL(cli->outbuf,smb_vwv0,fnum);
 		SSVAL(cli->outbuf,smb_vwv1,size);
 		SIVAL(cli->outbuf,smb_vwv2,offset);
 		SSVAL(cli->outbuf,smb_vwv4,0);
-		
+
 		p = smb_buf(cli->outbuf);
 		*p++ = 1;
 		SSVAL(p, 0, size); p += 2;
 		memcpy(p, buf + total, size); p += size;
 
 		cli_setup_bcc(cli, p);
-		
+
 		if (!cli_send_smb(cli))
 			return -1;
 
 		if (!cli_receive_smb(cli))
 			return -1;
-		
+
 		if (cli_is_error(cli))
 			return -1;
 
diff --git a/source/smbd/reply.c b/source/smbd/reply.c
index 84c1892..a7fa67d 100644
--- a/source/smbd/reply.c
+++ b/source/smbd/reply.c
@@ -3848,12 +3848,12 @@ void reply_write(connection_struct *conn, struct smb_request *req)
 						(2*14) + /* word count (including bcc) */ \
 						1 /* pad byte */)
 
-bool is_valid_writeX_buffer(char *inbuf)
+bool is_valid_writeX_buffer(const char *inbuf)
 {
 	size_t numtowrite;
 	connection_struct *conn = NULL;
 	unsigned int doff = 0;
-	size_t len = smb_len(inbuf);
+	size_t len = smb_len_large(inbuf);
 
 	if (CVAL(inbuf,smb_com) != SMBwriteX ||
 			CVAL(inbuf,smb_vwv0) != 0xFF ||
@@ -3867,14 +3867,19 @@ bool is_valid_writeX_buffer(char *inbuf)
 	if (IS_IPC(conn)) {
 		return false;
 	}
+	doff = SVAL(inbuf,smb_vwv11);
+
 	numtowrite = SVAL(inbuf,smb_vwv10);
-	numtowrite |= ((((size_t)SVAL(inbuf,smb_vwv9)) & 1 )<<16);
+
+	if (len > doff && len - doff > 0xFFFF) {
+		numtowrite |= (((size_t)SVAL(inbuf,smb_vwv9))<<16);
+	}
+
 	if (numtowrite == 0) {
 		return false;
 	}
-	/* Ensure the sizes match up. */
-	doff = SVAL(inbuf,smb_vwv11);
 
+	/* Ensure the sizes match up. */
 	if (doff < STANDARD_WRITE_AND_X_HEADER_SIZE) {
 		/* no pad byte...old smbclient :-( */
 		return false;
diff --git a/source/utils/nmblookup.c b/source/utils/nmblookup.c
index 7293e36..17fbd48 100644
--- a/source/utils/nmblookup.c
+++ b/source/utils/nmblookup.c
@@ -199,7 +199,7 @@ static bool query_one(const char *lookup, unsigned int lookup_type)
 		if (translate_addresses) {
 			char h_name[HOST_NAME_MAX];
 			h_name[0] = '\0';
-			if (getnameinfo((const struct sockaddr *)&ip_list[j],
+			if (sys_getnameinfo((const struct sockaddr *)&ip_list[j],
 					sizeof(struct sockaddr_storage),
 					h_name, sizeof(h_name),
 					NULL, 0,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list