[PATCH] remove stat between reads

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed Mar 27 09:39:06 MDT 2013


On Mon, Mar 25, 2013 at 10:06:05AM -0700, Jeremy Allison wrote:
> On Mon, Mar 25, 2013 at 12:00:13PM +0100, Volker Lendecke wrote:
> > 
> > From a quick glance this looks exactly like what I had in
> > mind. Thanks!
> 
> Here's it as an official patch. Feel free to push (and
> I'll add a bug report if you do).
> 
> Cheers,
> 
> 	Jeremy.

> From 6d73933e3078e4605c954347b00dd7e1b7a151f1 Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Mon, 25 Mar 2013 09:54:50 -0700
> Subject: [PATCH] Optimization suggested by Volker. Don't do a stat system call
>  on normal read path.
> 
> Only do it if we need it in the sendfile() path.
> 
> Signed-off-by: Jeremy Allison <jra at samba.org>
> ---
>  source3/smbd/reply.c | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
> index 8b500c5..d2e9ac4 100644
> --- a/source3/smbd/reply.c
> +++ b/source3/smbd/reply.c
> @@ -3666,11 +3666,6 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
>  	struct lock_struct lock;
>  	int saved_errno = 0;
>  
> -	if(fsp_stat(fsp) == -1) {
> -		reply_nterror(req, map_nt_error_from_unix(errno));
> -		return;
> -	}
> -
>  	init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
>  	    (uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
>  	    &lock);
> @@ -3680,16 +3675,6 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
>  		return;
>  	}
>  
> -	if (!S_ISREG(fsp->fsp_name->st.st_ex_mode) ||
> -			(startpos > fsp->fsp_name->st.st_ex_size)
> -			|| (smb_maxcnt > (fsp->fsp_name->st.st_ex_size - startpos))) {
> -		/*
> -		 * We already know that we would do a short read, so don't
> -		 * try the sendfile() path.
> -		 */
> -		goto nosendfile_read;
> -	}
> -
>  	/*
>  	 * We can only use sendfile on a non-chained packet
>  	 * but we can use on a non-oplocked file. tridge proved this
> @@ -3704,6 +3689,21 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
>  		uint8 headerbuf[smb_size + 12 * 2];
>  		DATA_BLOB header;
>  
> +		if(fsp_stat(fsp) == -1) {
> +			reply_nterror(req, map_nt_error_from_unix(errno));
> +			return;
> +		}

Is the error return correct here? Don't we have to do a
"goto strict_unlock" or something like that?

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de


More information about the samba-technical mailing list