2 * Copyright (c) Jeremy Allison 2007.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #if !defined(HAVE_LINUX_READAHEAD) && !defined(HAVE_POSIX_FADVISE)
26 * This module copes with Vista AIO read requests on Linux
27 * by detecting the initial 0x80000 boundary reads and causing
28 * the buffer cache to be filled in advance.
31 static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
35 const DATA_BLOB *header,
39 unsigned long off_bound = lp_parm_ulong(SNUM(handle->conn), "readahead", "offset", 0x80000);
40 if ( offset % off_bound == 0) {
41 unsigned long len = lp_parm_ulong(SNUM(handle->conn), "readahead", "length", off_bound);
42 #if defined(HAVE_LINUX_READAHEAD)
43 int err = readahead(fromfd, offset, (size_t)len);
44 DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
46 (unsigned long long)offset,
49 #elif defined(HAVE_POSIX_FADVISE)
50 int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
51 DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
53 (unsigned long long)offset,
58 DEBUG(0,("readahead_sendfile: no readahead on this platform\n"));
63 return SMB_VFS_NEXT_SENDFILE(handle,
72 static ssize_t readahead_pread(vfs_handle_struct *handle,
79 unsigned long off_bound = lp_parm_ulong(SNUM(handle->conn), "readahead", "offset", 0x80000);
80 if ( offset % off_bound == 0) {
81 unsigned long len = lp_parm_ulong(SNUM(handle->conn), "readahead", "length", off_bound);
82 #if defined(HAVE_LINUX_READAHEAD)
83 int err = readahead(fd, offset, (size_t)len);
84 DEBUG(10,("readahead_pread: readahead on fd %u, offset %llu, len %u returned %d\n",
86 (unsigned long long)offset,
89 #elif defined(HAVE_POSIX_FADVISE)
90 int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
91 DEBUG(10,("readahead_pread: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
93 (unsigned long long)offset,
98 DEBUG(0,("readahead_pread: no readahead on this platform\n"));
103 return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset);
106 static vfs_op_tuple readahead_ops [] =
108 {SMB_VFS_OP(readahead_sendfile), SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT},
109 {SMB_VFS_OP(readahead_pread), SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT},
110 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
113 NTSTATUS vfs_readahead_init(void);
114 NTSTATUS vfs_readahead_init(void)
116 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "readahead", readahead_ops);