| 1 | /*
|
|---|
| 2 | * Copyright (c) Jeremy Allison 2007.
|
|---|
| 3 | *
|
|---|
| 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 3 of the License, or
|
|---|
| 7 | * (at your option) any later version.
|
|---|
| 8 | *
|
|---|
| 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.
|
|---|
| 13 | *
|
|---|
| 14 | * You should have received a copy of the GNU General Public License
|
|---|
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | */
|
|---|
| 17 |
|
|---|
| 18 | #include "includes.h"
|
|---|
| 19 |
|
|---|
| 20 | struct readahead_data {
|
|---|
| 21 | SMB_OFF_T off_bound;
|
|---|
| 22 | SMB_OFF_T len;
|
|---|
| 23 | bool didmsg;
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | /*
|
|---|
| 27 | * This module copes with Vista AIO read requests on Linux
|
|---|
| 28 | * by detecting the initial 0x80000 boundary reads and causing
|
|---|
| 29 | * the buffer cache to be filled in advance.
|
|---|
| 30 | */
|
|---|
| 31 |
|
|---|
| 32 | /*******************************************************************
|
|---|
| 33 | sendfile wrapper that does readahead/posix_fadvise.
|
|---|
| 34 | *******************************************************************/
|
|---|
| 35 |
|
|---|
| 36 | static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
|
|---|
| 37 | int tofd,
|
|---|
| 38 | files_struct *fromfsp,
|
|---|
| 39 | const DATA_BLOB *header,
|
|---|
| 40 | SMB_OFF_T offset,
|
|---|
| 41 | size_t count)
|
|---|
| 42 | {
|
|---|
| 43 | struct readahead_data *rhd = (struct readahead_data *)handle->data;
|
|---|
| 44 |
|
|---|
| 45 | if ( offset % rhd->off_bound == 0) {
|
|---|
| 46 | #if defined(HAVE_LINUX_READAHEAD)
|
|---|
| 47 | int err = readahead(fromfsp->fh->fd, offset, (size_t)rhd->len);
|
|---|
| 48 | DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
|
|---|
| 49 | (unsigned int)fromfsp->fh->fd,
|
|---|
| 50 | (unsigned long long)offset,
|
|---|
| 51 | (unsigned int)rhd->len,
|
|---|
| 52 | err ));
|
|---|
| 53 | #elif defined(HAVE_POSIX_FADVISE)
|
|---|
| 54 | int err = posix_fadvise(fromfsp->fh->fd, offset, (off_t)rhd->len, POSIX_FADV_WILLNEED);
|
|---|
| 55 | DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
|
|---|
| 56 | (unsigned int)fromfsp->fh->fd,
|
|---|
| 57 | (unsigned long long)offset,
|
|---|
| 58 | (unsigned int)rhd->len,
|
|---|
| 59 | err ));
|
|---|
| 60 | #else
|
|---|
| 61 | if (!rhd->didmsg) {
|
|---|
| 62 | DEBUG(0,("readahead_sendfile: no readahead on this platform\n"));
|
|---|
| 63 | rhd->didmsg = True;
|
|---|
| 64 | }
|
|---|
| 65 | #endif
|
|---|
| 66 | }
|
|---|
| 67 | return SMB_VFS_NEXT_SENDFILE(handle,
|
|---|
| 68 | tofd,
|
|---|
| 69 | fromfsp,
|
|---|
| 70 | header,
|
|---|
| 71 | offset,
|
|---|
| 72 | count);
|
|---|
| 73 | }
|
|---|
|
|---|