summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in6
-rw-r--r--source3/configure.in23
-rw-r--r--source3/modules/vfs_readahead.c117
3 files changed, 145 insertions, 1 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index e62ee9a571..8f9b775cc7 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -446,6 +446,7 @@ VFS_PREALLOC_OBJ = modules/vfs_prealloc.o
VFS_COMMIT_OBJ = modules/vfs_commit.o
VFS_GPFS_OBJ = modules/vfs_gpfs.o modules/gpfs.o modules/nfs4_acls.o
VFS_NOTIFY_FAM_OBJ = modules/vfs_notify_fam.o
+VFS_LINUX_READAHEAD_OBJ = modules/vfs_readahead.o
PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o
@@ -1606,6 +1607,11 @@ bin/notify_fam.@SHLIBEXT@: $(VFS_NOTIFY_FAM_OBJ)
@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_NOTIFY_FAM_OBJ) \
@SONAMEFLAG@`basename $@`
+bin/readahead.@SHLIBEXT@: $(VFS_LINUX_READAHEAD_OBJ)
+ @echo "Building plugin $@"
+ @$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_LINUX_READAHEAD_OBJ) \
+ @SONAMEFLAG@`basename $@`
+
#########################################################
## IdMap NSS plugins
diff --git a/source3/configure.in b/source3/configure.in
index eb4bd9bcdc..326f81ca00 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -594,7 +594,7 @@ dnl These have to be built static:
default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_winreg rpc_initshutdown rpc_lsa_ds rpc_wkssvc rpc_svcctl rpc_ntsvcs rpc_net rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog rpc_unixinfo rpc_epmapper auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default nss_info_template"
dnl These are preferably build shared, and static if dlopen() is not available
-default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437 auth_script"
+default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy charset_CP850 charset_CP437 auth_script vfs_readahead"
if test "x$developer" = xyes; then
default_static_modules="$default_static_modules rpc_rpcecho"
@@ -5667,6 +5667,26 @@ if test x"$samba_cv_HAVE_LINUX_READAHEAD" = x"yes"; then
[Whether Linux readahead is available])
fi
+############################################
+# See if we have the posix_fadvise syscall.
+
+AC_CACHE_CHECK([for posix_fadvise],
+ samba_cv_HAVE_POSIX_FADVISE,[
+ AC_TRY_LINK([
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#include <fcntl.h>],
+ [ssize_t err = posix_fadvise(0,0,0x80000,POSIX_FADV_WILLNEED);],
+ samba_cv_HAVE_POSIX_FADVISE=yes,
+ samba_cv_HAVE_POSIX_FADVISE=no)])
+
+if test x"$samba_cv_HAVE_POSIX_FADVISE" = x"yes"; then
+ AC_DEFINE(HAVE_POSIX_FADVISE,1,
+ [Whether posix_fadvise is available])
+fi
+
+
#################################################
# Check whether winbind is supported on this platform. If so we need to
@@ -6061,6 +6081,7 @@ SMB_MODULE(vfs_prealloc, \$(VFS_PREALLOC_OBJ), "bin/prealloc.$SHLIBEXT", VFS)
SMB_MODULE(vfs_commit, \$(VFS_COMMIT_OBJ), "bin/commit.$SHLIBEXT", VFS)
SMB_MODULE(vfs_gpfs, \$(VFS_GPFS_OBJ), "bin/gpfs.$SHLIBEXT", VFS)
SMB_MODULE(vfs_notify_fam, \$(VFS_NOTIFY_FAM_OBJ), "bin/notify_fam.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_readahead, \$(VFS_LINUX_READAHEAD_OBJ), "bin/readahead.$SHLIBEXT", VFS)
SMB_SUBSYSTEM(VFS,smbd/vfs.o)
diff --git a/source3/modules/vfs_readahead.c b/source3/modules/vfs_readahead.c
new file mode 100644
index 0000000000..5b08f004c4
--- /dev/null
+++ b/source3/modules/vfs_readahead.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) Jeremy Allison 2007.
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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.
+ */
+
+#include "includes.h"
+
+#if !defined(HAVE_LINUX_READAHEAD) && !defined(HAVE_POSIX_FADVISE)
+static BOOL didmsg;
+#endif
+
+/*
+ * This module copes with Vista AIO read requests on Linux
+ * by detecting the initial 0x80000 boundary reads and causing
+ * the buffer cache to be filled in advance.
+ */
+
+static ssize_t readahead_sendfile(struct vfs_handle_struct *handle,
+ int tofd,
+ files_struct *fsp,
+ int fromfd,
+ const DATA_BLOB *header,
+ SMB_OFF_T offset,
+ size_t count)
+{
+ unsigned long off_bound = lp_parm_ulong(SNUM(handle->conn), "readahead", "offset", 0x80000);
+ if ( offset % off_bound == 0) {
+ unsigned long len = lp_parm_ulong(SNUM(handle->conn), "readahead", "length", off_bound);
+#if defined(HAVE_LINUX_READAHEAD)
+ int err = readahead(fromfd, offset, (size_t)len);
+ DEBUG(10,("readahead_sendfile: readahead on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fromfd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ err ));
+#elif defined(HAVE_POSIX_FADVISE)
+ int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+ DEBUG(10,("readahead_sendfile: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fromfd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ err ));
+#else
+ if (!didmsg) {
+ DEBUG(0,("readahead_sendfile: no readahead on this platform\n"));
+ didmsg = True;
+ }
+#endif
+ }
+ return SMB_VFS_NEXT_SENDFILE(handle,
+ tofd,
+ fsp,
+ fromfd,
+ header,
+ offset,
+ count);
+}
+
+static ssize_t readahead_pread(vfs_handle_struct *handle,
+ files_struct *fsp,
+ int fd,
+ void *data,
+ size_t count,
+ SMB_OFF_T offset)
+{
+ unsigned long off_bound = lp_parm_ulong(SNUM(handle->conn), "readahead", "offset", 0x80000);
+ if ( offset % off_bound == 0) {
+ unsigned long len = lp_parm_ulong(SNUM(handle->conn), "readahead", "length", off_bound);
+#if defined(HAVE_LINUX_READAHEAD)
+ int err = readahead(fd, offset, (size_t)len);
+ DEBUG(10,("readahead_pread: readahead on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ err ));
+#elif defined(HAVE_POSIX_FADVISE)
+ int err = posix_fadvise(fromfd, offset, (off_t)len, POSIX_FADV_WILLNEED);
+ DEBUG(10,("readahead_pread: posix_fadvise on fd %u, offset %llu, len %u returned %d\n",
+ (unsigned int)fd,
+ (unsigned long long)offset,
+ (unsigned int)len,
+ (err ));
+#else
+ if (!didmsg) {
+ DEBUG(0,("readahead_pread: no readahead on this platform\n"));
+ didmsg = True;
+ }
+#endif
+ }
+ return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset);
+}
+
+static vfs_op_tuple readahead_ops [] =
+{
+ {SMB_VFS_OP(readahead_sendfile), SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(readahead_pread), SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+};
+
+NTSTATUS vfs_readahead_init(void);
+NTSTATUS vfs_readahead_init(void)
+{
+ return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "readahead", readahead_ops);
+}