Optimization suggested by Volker. Don't do a stat system call on normal read path.
authorJeremy Allison <jra@samba.org>
Mon, 25 Mar 2013 16:54:50 +0000 (09:54 -0700)
committerKarolin Seeger <kseeger@samba.org>
Fri, 26 Apr 2013 07:25:03 +0000 (09:25 +0200)
Only do it if we need it in the sendfile() path.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Mar 28 17:51:22 CET 2013 on sn-devel-104

Fix bug #9748 - Remove unneeded fstat system call from hot read path.
(cherry picked from commit 60a2fb5ddac02376d82f323f2acb1211bb7929e3)

source3/smbd/reply.c

index ffe128aede9c8245e749a2ddf68ca7ca2e15ff8f..31f4e2fc456046dcd643730863333d2eb5e93382 100644 (file)
@@ -3529,11 +3529,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);
@@ -3543,16 +3538,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
@@ -3566,6 +3551,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));
+                       goto strict_unlock;
+               }
+
+               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;
+               }
+
                /*
                 * Set up the packet header before send. We
                 * assume here the sendfile will work (get the