From c9bd306bdaa57e9251bd6017f084b11e2af8b42d Mon Sep 17 00:00:00 2001 From: Olivier Sessink Date: Tue, 9 Aug 2011 09:56:38 +0200 Subject: [PATCH] scannedonly module: improve sleep behavior when reading a directory with multiple non-scanned files --- source3/modules/vfs_scannedonly.c | 30 ++++++++++++++++-------------- 1 files changed, 16 insertions(+), 14 deletions(-) diff --git a/source3/modules/vfs_scannedonly.c b/source3/modules/vfs_scannedonly.c index d0eba21..5963259 100644 --- a/source3/modules/vfs_scannedonly.c +++ b/source3/modules/vfs_scannedonly.c @@ -1,7 +1,7 @@ /* - * scannedonly VFS module for Samba 3.5 + * scannedonly VFS module for Samba 3.5 and beyond * - * Copyright 2007,2008,2009,2010 (C) Olivier Sessink + * Copyright 2007,2008,2009,2010,2011 (C) Olivier Sessink * * 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 @@ -88,7 +88,8 @@ struct Tscannedonly { struct scannedonly_DIR { char *base; - int notify_loop_done; + int recheck_tries_done; /* if 0 the directory listing has not yet + been checked for files that need to be scanned. */ SMB_STRUCT_DIR *DIR; }; #define SCANNEDONLY_DEBUG 9 @@ -440,8 +441,7 @@ static bool scannedonly_allow_access(vfs_handle_struct * handle, notify_scanner(handle, smb_fname->base_name); - didloop = 0; - if (loop && sDIR && !sDIR->notify_loop_done) { + if (loop && sDIR && sDIR->recheck_tries_done == 0) { /* check the rest of the directory and notify the scanner if some file needs scanning */ long offset; @@ -466,27 +466,29 @@ static bool scannedonly_allow_access(vfs_handle_struct * handle, talloc_free(smb_fname2); dire = SMB_VFS_NEXT_READDIR(handle, sDIR->DIR,NULL); } - sDIR->notify_loop_done = 1; - didloop = 1; + sDIR->recheck_tries_done = 1; SMB_VFS_NEXT_SEEKDIR(handle, sDIR->DIR, offset); } if (recheck_time > 0 && ((recheck_size > 0 && smb_fname->st.st_ex_size < (1024 * recheck_size)) - || didloop)) { - int i = 0; + || (sDIR && sDIR->recheck_tries_done < recheck_tries) + )) { + int numloops = sDIR ? sDIR->recheck_tries_done : 0; flush_sendbuffer(handle); while (retval != 0 /*&& errno == ENOENT */ - && i < recheck_tries) { + && numloops < recheck_tries) { DEBUG(SCANNEDONLY_DEBUG, ("scannedonly_allow_access, wait (try=%d " "(max %d), %d ms) for %s\n", - i, recheck_tries, + numloops, recheck_tries, recheck_time, cache_smb_fname->base_name)); smb_msleep(recheck_time); retval = SMB_VFS_NEXT_STAT(handle, cache_smb_fname); - i++; + numloops++; } + if (sDIR) + sDIR->recheck_tries_done = numloops; } /* still no cachefile, or still too old, return 0 */ if (retval != 0 @@ -524,7 +526,7 @@ static SMB_STRUCT_DIR *scannedonly_opendir(vfs_handle_struct * handle, DEBUG(SCANNEDONLY_DEBUG, ("scannedonly_opendir, fname=%s, base=%s\n",fname,sDIR->base)); sDIR->DIR = DIRp; - sDIR->notify_loop_done = 0; + sDIR->recheck_tries_done = 0; return (SMB_STRUCT_DIR *) sDIR; } @@ -552,7 +554,7 @@ static SMB_STRUCT_DIR *scannedonly_fdopendir(vfs_handle_struct * handle, DEBUG(SCANNEDONLY_DEBUG, ("scannedonly_fdopendir, fname=%s, base=%s\n",fname,sDIR->base)); sDIR->DIR = DIRp; - sDIR->notify_loop_done = 0; + sDIR->recheck_tries_done = 0; return (SMB_STRUCT_DIR *) sDIR; } -- 1.7.5.4