[Aide] Patch to add posix_fadvice

pablo@vapaa.fi pablo at vapaa.fi
Tue May 30 13:05:32 EEST 2006


The patch marks files which are read for hash calculation data will be
accessed only once. It should make AIDE to behave nicely for disk-cache.
It can be enabled with configure script parameter "--enable-fadvice".
One propably should disable mmap to gain improvements...
-------------- next part --------------
--- configure.in	29 Mar 2006 08:08:08 -0000	1.44
+++ configure.in	30 May 2006 09:52:36 -0000
@@ -203,6 +203,11 @@
 
 AC_CHECK_FUNCS(snprintf vsnprintf)
 
+AC_ARG_ENABLE(fadvice,
+	AC_HELP_STRING([--enable-fadvice],[enable posix_fadvice]),
+	AC_DEFINE(USE_FADVISE,1,[Use posix_fadvice]),
+)
+
 AC_CACHE_CHECK(for ISO C99 compliant snprintf,ac_cv_func_snprintf_c99,
 	[AC_TRY_RUN([
 #include <stdio.h>
--- src/do_md.c	22 Apr 2006 14:16:33 -0000	1.16
+++ src/do_md.c	30 May 2006 09:52:36 -0000
@@ -18,7 +18,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
+#define _POSIX_C_SOURCE 200112L
 #include "aide.h"
 
 #include <limits.h>
@@ -124,6 +124,8 @@
   struct AIDE_STAT_TYPE fs;
   int sres=0;
   int stat_diff,filedes;
+
+  error(255,"calc_md called\n");
 #ifdef _PARAMETER_CHECK_
   if (line==NULL) {
     abort();
@@ -136,7 +138,6 @@
 #endif
     filedes=open(line->filename,O_RDONLY);
 
-  error(255,"calc_md called\n");
   if (filedes==-1) {
     char* er=strerror(errno);
     if (er!=NULL) {
@@ -157,6 +158,13 @@
   if(!(line->attr&DB_RDEV))
 	  fs.st_rdev=0;
   
+#ifdef USE_FADVISE
+  if (posix_fadvise(filedes,0,fs.st_size,POSIX_FADV_NOREUSE)!=0) {
+	error(255,"posix_fadvise error %s\n",strerror(errno));
+  } else {
+	error(255,"posix_fadvise(%i,0,%i,POSIX_FADV_NOREUSE) ok\n",filedes,fs.st_size);
+  }
+#endif
   if ((stat_diff=stat_cmp(&fs,old_fs))==RETOK) {
     /*
       Now we have a 'valid' filehandle to read from a file.


More information about the Aide mailing list