Combine fsp and fromfd to fromfsp in SMB_VFS_SENDFILE().
[jra/samba/.git] / source3 / modules / vfs_readahead.c
index 550562d03d08d15c40ab6539baea0fd7ea940204..df75814b7248dd6932601bbb1ac7424e087a45a7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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 2 of the License, or
+ * 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,
  * 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "includes.h"
 
-#if !defined(HAVE_LINUX_READAHEAD) && !defined(HAVE_POSIX_FADVISE)
-static BOOL didmsg;
-#endif
-
 struct readahead_data {
        SMB_OFF_T off_bound;
        SMB_OFF_T len;
-       BOOL didmsg;
+       bool didmsg;
 };
 
 /* 
@@ -40,8 +35,7 @@ struct readahead_data {
 
 static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
                                        int tofd,
-                                       files_struct *fsp,
-                                       int fromfd,
+                                       files_struct *fromfsp,
                                        const DATA_BLOB *header,
                                        SMB_OFF_T offset,
                                        size_t count)
@@ -50,16 +44,16 @@ static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
 
        if ( offset % rhd->off_bound == 0) {
 #if defined(HAVE_LINUX_READAHEAD)
-               int err = readahead(fromfd, offset, (size_t)rhd->len);
+               int err = readahead(fromfsp->fh->fd, offset, (size_t)rhd->len);
                DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
-                       (unsigned int)fromfd,
+                       (unsigned int)fromfsp->fh->fd,
                        (unsigned long long)offset,
                        (unsigned int)rhd->len,
                        err ));
 #elif defined(HAVE_POSIX_FADVISE)
-               int err = posix_fadvise(fromfd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
+               int err = posix_fadvise(fromfsp->fh->fd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
                DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
-                       (unsigned int)fromfd,
+                       (unsigned int)fromfsp->fh->fd,
                        (unsigned long long)offset,
                        (unsigned int)rhd->len,
                        err ));
@@ -72,8 +66,7 @@ static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
        }
        return SMB_VFS_NEXT_SENDFILE(handle,
                                        tofd,
-                                       fsp,
-                                       fromfd,
+                                       fromfsp,
                                        header,
                                        offset,
                                        count);
@@ -85,7 +78,6 @@ static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
 
 static ssize_t readahead_pread(vfs_handle_struct *handle,
                                files_struct *fsp,
-                               int fd,
                                void *data,
                                size_t count,
                                SMB_OFF_T offset)
@@ -94,19 +86,19 @@ static ssize_t readahead_pread(vfs_handle_struct *handle,
 
        if ( offset % rhd->off_bound == 0) {
 #if defined(HAVE_LINUX_READAHEAD)
-               int err = readahead(fd, offset, (size_t)rhd->len);
+               int err = readahead(fsp->fh->fd, offset, (size_t)rhd->len);
                DEBUG(10,("readahead_pread: readahead on fd %u, offset %llu, len %u returned %d\n",
-                       (unsigned int)fd,
+                       (unsigned int)fsp->fh->fd,
                        (unsigned long long)offset,
                        (unsigned int)rhd->len,
                        err ));
 #elif defined(HAVE_POSIX_FADVISE)
-               int err = posix_fadvise(fromfd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
+               int err = posix_fadvise(fsp->fh->fd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
                DEBUG(10,("readahead_pread: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
-                       (unsigned int)fd,
+                       (unsigned int)fsp->fh->fd,
                        (unsigned long long)offset,
                        (unsigned int)rhd->len,
-                       (err ));
+                       err ));
 #else
                if (!rhd->didmsg) {
                        DEBUG(0,("readahead_pread: no readahead on this platform\n"));
@@ -114,7 +106,7 @@ static ssize_t readahead_pread(vfs_handle_struct *handle,
                }
 #endif
         }
-        return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset);
+        return SMB_VFS_NEXT_PREAD(handle, fsp, data, count, offset);
 }
 
 /*******************************************************************
@@ -160,7 +152,7 @@ static int readahead_connect(struct vfs_handle_struct *handle,
 
        handle->data = (void *)rhd;
        handle->free_data = free_readahead_data;
-       return 0;
+       return SMB_VFS_NEXT_CONNECT(handle, service, user);
 }
 
 /*******************************************************************