From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/modules/vfs_cacheprime.c | 200 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 source3/modules/vfs_cacheprime.c (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c new file mode 100644 index 0000000000..196441c4dd --- /dev/null +++ b/source3/modules/vfs_cacheprime.c @@ -0,0 +1,200 @@ +/* + * Copyright (c) James Peach 2005-2006 + * + * 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" + +/* Cache priming module. + * + * The purpose of this module is to do RAID stripe width reads to prime the + * buffer cache to do zero-copy I/O for subsequent sendfile calls. The idea is + * to do a single large read at the start of the file to make sure that most or + * all of the file is pulled into the buffer cache. Subsequent I/Os have + * reduced latency. + * + * Tunables. + * + * cacheprime:rsize Amount of readahead in bytes. This should be a + * multiple of the RAID stripe width. + * cacheprime:debug Debug level at which to emit messages. + */ + +#define READAHEAD_MIN (128 * 1024) /* min is 128 KiB */ +#define READAHEAD_MAX (100 * 1024 * 1024) /* max is 100 MiB */ + +#define MODULE "cacheprime" + +static int module_debug; +static ssize_t g_readsz = 0; +static void * g_readbuf = NULL; + +/* Prime the kernel buffer cache with data from the specified file. We use + * per-fsp data to make sure we only ever do this once. If pread is being + * emulated by seek/read/seek, when this will suck quite a lot. + */ +static BOOL prime_cache( + struct vfs_handle_struct * handle, + files_struct * fsp, + int fd, + SMB_OFF_T offset, + size_t count) +{ + SMB_OFF_T * last; + ssize_t nread; + + last = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T); + if (!last) { + return False; + } + + if (*last == -1) { + /* Readahead disabled. */ + return False; + } + + if ((*last + g_readsz) > (offset + count)) { + /* Skip readahead ... we've already been here. */ + return False; + } + + DEBUG(module_debug, + ("%s: doing readahead of %lld bytes at %lld for %s\n", + MODULE, (long long)g_readsz, (long long)*last, + fsp->fsp_name)); + + nread = sys_pread(fd, g_readbuf, g_readsz, *last); + if (nread < 0) { + *last = -1; + return False; + } + + *last += nread; + return True; +} + +static int cprime_connect( + struct vfs_handle_struct * handle, + const char * service, + const char * user) +{ + module_debug = lp_parm_int(SNUM(handle->conn), MODULE, "debug", 100); + if (g_readbuf) { + /* Only allocate g_readbuf once. If the config changes and + * another client multiplexes onto this smbd, we don't want + * to risk memory corruption. + */ + return SMB_VFS_NEXT_CONNECT(handle, service, user); + } + + g_readsz = conv_str_size(lp_parm_const_string(SNUM(handle->conn), + MODULE, "rsize", NULL)); + + if (g_readsz < READAHEAD_MIN) { + DEBUG(module_debug, ("%s: %ld bytes of readahead " + "requested, using minimum of %u\n", + MODULE, (long)g_readsz, READAHEAD_MIN)); + g_readsz = READAHEAD_MIN; + } else if (g_readsz > READAHEAD_MAX) { + DEBUG(module_debug, ("%s: %ld bytes of readahead " + "requested, using maximum of %u\n", + MODULE, (long)g_readsz, READAHEAD_MAX)); + g_readsz = READAHEAD_MAX; + } + + if ((g_readbuf = SMB_MALLOC(g_readsz)) == NULL) { + /* Turn off readahead if we can't get a buffer. */ + g_readsz = 0; + } + + return SMB_VFS_NEXT_CONNECT(handle, service, user); +} + +static ssize_t cprime_sendfile( + struct vfs_handle_struct * handle, + int tofd, + files_struct * fsp, + int fromfd, + const DATA_BLOB * header, + SMB_OFF_T offset, + size_t count) +{ + if (g_readbuf && offset == 0) { + prime_cache(handle, fsp, fromfd, offset, count); + } + + return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, fromfd, + header, offset, count); +} + +static ssize_t cprime_read( + vfs_handle_struct * handle, + files_struct * fsp, + int fd, + void * data, + size_t count) +{ + SMB_OFF_T offset; + + offset = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + if (offset >= 0 && g_readbuf) { + prime_cache(handle, fsp, fd, offset, count); + SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET); + } + + return SMB_VFS_NEXT_READ(handle, fsp, fd, data, count); +} + +static ssize_t cprime_pread( + vfs_handle_struct * handle, + files_struct * fsp, + int fd, + void * data, + size_t count, + SMB_OFF_T offset) +{ + if (g_readbuf) { + prime_cache(handle, fsp, fd, offset, count); + } + + return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset); +} + +static vfs_op_tuple cprime_ops [] = +{ + {SMB_VFS_OP(cprime_sendfile), + SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(cprime_pread), + SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(cprime_read), + SMB_VFS_OP_READ, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(cprime_connect), + SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + +/* ------------------------------------------------------------------------- + * Samba module initialisation entry point. + * ------------------------------------------------------------------------- + */ + +NTSTATUS vfs_cacheprime_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE, cprime_ops); +} + +/* vim: set sw=4 ts=4 tw=79 et: */ -- cgit From 55ed1d59455566d90a03e7123fbf7a05a4bd4539 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 19 Dec 2006 20:16:52 +0000 Subject: r20261: merge 20260 from samba_3_0_24 clean up a bunch of no previous prototype warnings (This used to be commit c60687db112405262adf26dbf267804b04074e67) --- source3/modules/vfs_cacheprime.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 196441c4dd..61a92a0232 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -192,6 +192,7 @@ static vfs_op_tuple cprime_ops [] = * ------------------------------------------------------------------------- */ +NTSTATUS vfs_cacheprime_init(void); NTSTATUS vfs_cacheprime_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE, cprime_ops); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/modules/vfs_cacheprime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 61a92a0232..04fc91ded4 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -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, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/modules/vfs_cacheprime.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 04fc91ded4..c6f7fad906 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -12,8 +12,7 @@ * 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 . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/modules/vfs_cacheprime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index c6f7fad906..9574087d9d 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -45,7 +45,7 @@ static void * g_readbuf = NULL; * per-fsp data to make sure we only ever do this once. If pread is being * emulated by seek/read/seek, when this will suck quite a lot. */ -static BOOL prime_cache( +static bool prime_cache( struct vfs_handle_struct * handle, files_struct * fsp, int fd, -- cgit From ca275e254985727c50b1b988c958a3743a7bc8ce Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 7 Jan 2008 00:14:19 +0100 Subject: Remove unneeded parameter fd from SMB_VFS_PREAD(). Michael (This used to be commit 73e28806ce87d829ea7c38ed3440020845bb13bf) --- source3/modules/vfs_cacheprime.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 9574087d9d..6eb74e66ed 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -160,16 +160,15 @@ static ssize_t cprime_read( static ssize_t cprime_pread( vfs_handle_struct * handle, files_struct * fsp, - int fd, void * data, size_t count, SMB_OFF_T offset) { if (g_readbuf) { - prime_cache(handle, fsp, fd, offset, count); + prime_cache(handle, fsp, fsp->fh->fd, offset, count); } - return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset); + return SMB_VFS_NEXT_PREAD(handle, fsp, data, count, offset); } static vfs_op_tuple cprime_ops [] = -- cgit From 1d66f4d58b5fdd9c4e0c022cd2724e05d144510b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 10 Jan 2008 15:33:51 +0100 Subject: Remove redundant parameter fd from SMB_VFS_READ(). Michael (This used to be commit a8fc2ddad8d5f7c6c00cb36c74a32a02d69d1d04) --- source3/modules/vfs_cacheprime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 6eb74e66ed..4ac78437c3 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -154,7 +154,7 @@ static ssize_t cprime_read( SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET); } - return SMB_VFS_NEXT_READ(handle, fsp, fd, data, count); + return SMB_VFS_NEXT_READ(handle, fsp, data, count); } static ssize_t cprime_pread( -- cgit From e17642e849b28c323ba6bd7cc212455d727901db Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 10 Jan 2008 23:40:13 +0100 Subject: Fix the build of the cacheprime VFS module after API changes. Sorry, that had escaped my attention. Michael (This used to be commit 88102b5b7c4eaad5445e9cb96e547dd918abc0c2) --- source3/modules/vfs_cacheprime.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 4ac78437c3..5675108f1e 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -142,16 +142,15 @@ static ssize_t cprime_sendfile( static ssize_t cprime_read( vfs_handle_struct * handle, files_struct * fsp, - int fd, void * data, size_t count) { SMB_OFF_T offset; - offset = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + offset = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR); if (offset >= 0 && g_readbuf) { - prime_cache(handle, fsp, fd, offset, count); - SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET); + prime_cache(handle, fsp, fsp->fh->fd, offset, count); + SMB_VFS_LSEEK(fsp, offset, SEEK_SET); } return SMB_VFS_NEXT_READ(handle, fsp, data, count); -- cgit From 4caab9ca25e1163378714de825d835e79e27dd4f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 11 Jan 2008 00:51:19 +0100 Subject: Combine fsp and fromfd to fromfsp in SMB_VFS_SENDFILE(). Michael (This used to be commit a52cfb7d777157c93c9dc26c67f457be592dd537) --- source3/modules/vfs_cacheprime.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 5675108f1e..15c8167a07 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -125,17 +125,16 @@ static int cprime_connect( static ssize_t cprime_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) { if (g_readbuf && offset == 0) { - prime_cache(handle, fsp, fromfd, offset, count); + prime_cache(handle, fromfsp, fromfsp->fh->fd, offset, count); } - return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, fromfd, + return SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, header, offset, count); } -- cgit From 14d45bedfa844dfbf646e792d1cf84544997de25 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 11 Jan 2008 00:56:06 +0100 Subject: Remove now redundant parameter fd from prime_cache(). Michael (This used to be commit 63acaf1b9755cd5be5342929e1210afa06e170f3) --- source3/modules/vfs_cacheprime.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index 15c8167a07..be934f6bd6 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -48,7 +48,6 @@ static void * g_readbuf = NULL; static bool prime_cache( struct vfs_handle_struct * handle, files_struct * fsp, - int fd, SMB_OFF_T offset, size_t count) { @@ -75,7 +74,7 @@ static bool prime_cache( MODULE, (long long)g_readsz, (long long)*last, fsp->fsp_name)); - nread = sys_pread(fd, g_readbuf, g_readsz, *last); + nread = sys_pread(fsp->fh->fd, g_readbuf, g_readsz, *last); if (nread < 0) { *last = -1; return False; @@ -131,7 +130,7 @@ static ssize_t cprime_sendfile( size_t count) { if (g_readbuf && offset == 0) { - prime_cache(handle, fromfsp, fromfsp->fh->fd, offset, count); + prime_cache(handle, fromfsp, offset, count); } return SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, @@ -148,7 +147,7 @@ static ssize_t cprime_read( offset = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR); if (offset >= 0 && g_readbuf) { - prime_cache(handle, fsp, fsp->fh->fd, offset, count); + prime_cache(handle, fsp, offset, count); SMB_VFS_LSEEK(fsp, offset, SEEK_SET); } @@ -163,7 +162,7 @@ static ssize_t cprime_pread( SMB_OFF_T offset) { if (g_readbuf) { - prime_cache(handle, fsp, fsp->fh->fd, offset, count); + prime_cache(handle, fsp, offset, count); } return SMB_VFS_NEXT_PREAD(handle, fsp, data, count, offset); -- cgit From c57f1ab34537b43755c85c6a92b5a4708d532e0f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 20 Apr 2008 21:49:01 +0200 Subject: vfs_cacheprime: fix C++ warning - make implicit cast explicit Michael (This used to be commit 04d671b8c9bd5bf811e6dbd6981f1874eb49740c) --- source3/modules/vfs_cacheprime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/modules/vfs_cacheprime.c') diff --git a/source3/modules/vfs_cacheprime.c b/source3/modules/vfs_cacheprime.c index be934f6bd6..fed051ca8d 100644 --- a/source3/modules/vfs_cacheprime.c +++ b/source3/modules/vfs_cacheprime.c @@ -54,7 +54,7 @@ static bool prime_cache( SMB_OFF_T * last; ssize_t nread; - last = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T); + last = (SMB_OFF_T *)VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T); if (!last) { return False; } -- cgit