s3: smbd: Performance optimization for RECVFILE.
[nivanova/samba-autobuild/.git] / source3 / smbd / vfs.c
index dd74d79880012aa2a403bb3b7c2420dffb552327..897bf1f338e37f2ca1dec7ceb49c83853415fa6a 100644 (file)
@@ -472,14 +472,55 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
        ssize_t ret;
 
        if (req && req->unread_bytes) {
+               int sockfd = req->sconn->sock;
                SMB_ASSERT(req->unread_bytes == N);
                /* VFS_RECVFILE must drain the socket
                 * before returning. */
                req->unread_bytes = 0;
-               return SMB_VFS_RECVFILE(req->sconn->sock,
-                                       fsp,
-                                       offset,
-                                       N);
+               /*
+                * Leave the socket non-blocking and
+                * use SMB_VFS_RECVFILE. If it returns
+                * EAGAIN || EWOULDBLOCK temporarily set
+                * the socket blocking and retry
+                * the RECVFILE.
+                */
+               while (total < N) {
+                       ret = SMB_VFS_RECVFILE(sockfd,
+                                               fsp,
+                                               offset + total,
+                                               N - total);
+#if defined(EWOULDBLOCK)
+                       if (ret == 0 || (ret == -1 &&
+                               (errno == EAGAIN || errno == EWOULDBLOCK))) {
+#else /* EWOULDBLOCK */
+                       if (ret == 0 || (ret == -1 && errno == EAGAIN)) {
+#endif /* EWOULDBLOCK */
+                               int old_flags;
+                               /* Ensure the socket is blocking. */
+                               old_flags = fcntl(sockfd, F_GETFL, 0);
+                               if (set_blocking(sockfd, true) == -1) {
+                                       return (ssize_t)-1;
+                               }
+                               ret = SMB_VFS_RECVFILE(sockfd,
+                                                       fsp,
+                                                       offset + total,
+                                                       N - total);
+                               if (fcntl(sockfd, F_SETFL, old_flags) == -1) {
+                                       return (ssize_t)-1;
+                               }
+                               if (ret == -1) {
+                                       return (ssize_t)-1;
+                               }
+                               total += ret;
+                               return (ssize_t)total;
+                       }
+                       /* Any other error case. */
+                       if (ret == -1) {
+                               return ret;
+                       }
+                       total += ret;
+               }
+               return (ssize_t)total;
        }
 
        while (total < N) {
@@ -540,7 +581,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
 
                contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
 
-               flush_write_cache(fsp, SIZECHANGE_FLUSH);
+               flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
                if ((ret = SMB_VFS_FTRUNCATE(fsp, (off_t)len)) != -1) {
                        set_filelen_write_cache(fsp, len);
                }
@@ -550,16 +591,17 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
                return ret;
        }
 
-       if (!lp_strict_allocate(SNUM(fsp->conn)))
-               return 0;
-
        /* Grow - we need to test if we have enough space. */
 
        contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
 
-       /* See if we have a syscall that will allocate beyond end-of-file
-          without changing EOF. */
-       ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_KEEP_SIZE, 0, len);
+       if (lp_strict_allocate(SNUM(fsp->conn))) {
+               /* See if we have a syscall that will allocate beyond
+                  end-of-file without changing EOF. */
+               ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_KEEP_SIZE, 0, len);
+       } else {
+               ret = 0;
+       }
 
        contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
 
@@ -604,7 +646,7 @@ int vfs_set_filelen(files_struct *fsp, off_t len)
 
        DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
                  fsp_str_dbg(fsp), (double)len));
-       flush_write_cache(fsp, SIZECHANGE_FLUSH);
+       flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
        if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
                set_filelen_write_cache(fsp, len);
                notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
@@ -693,7 +735,7 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
 
        contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
 
-       flush_write_cache(fsp, SIZECHANGE_FLUSH);
+       flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
 
        offset = fsp->fsp_name->st.st_ex_size;
        num_to_write = len - fsp->fsp_name->st.st_ex_size;
@@ -816,7 +858,7 @@ int vfs_ChDir(connection_struct *conn, const char *path)
                LastDir = SMB_STRDUP("");
        }
 
-       if (strcsequal(path,".")) {
+       if (ISDOT(path)) {
                return 0;
        }
 
@@ -1193,7 +1235,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
        }
 
        allow_widelinks = lp_widelinks(SNUM(conn));
-       allow_symlinks = lp_symlinks(SNUM(conn));
+       allow_symlinks = lp_follow_symlinks(SNUM(conn));
 
        /* Common widelinks and symlinks checks. */
        if (!allow_widelinks || !allow_symlinks) {
@@ -2188,6 +2230,27 @@ NTSTATUS smb_vfs_call_copy_chunk_recv(struct vfs_handle_struct *handle,
        return handle->fns->copy_chunk_recv_fn(handle, req, copied);
 }
 
+NTSTATUS smb_vfs_call_get_compression(vfs_handle_struct *handle,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct files_struct *fsp,
+                                     struct smb_filename *smb_fname,
+                                     uint16_t *_compression_fmt)
+{
+       VFS_FIND(get_compression);
+       return handle->fns->get_compression_fn(handle, mem_ctx, fsp, smb_fname,
+                                              _compression_fmt);
+}
+
+NTSTATUS smb_vfs_call_set_compression(vfs_handle_struct *handle,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct files_struct *fsp,
+                                     uint16_t compression_fmt)
+{
+       VFS_FIND(set_compression);
+       return handle->fns->set_compression_fn(handle, mem_ctx, fsp,
+                                              compression_fmt);
+}
+
 NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
                                  struct files_struct *fsp,
                                  uint32 security_info,