From 36b14cdfdbba7713d65c4d416b27c94b495b154a Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 17 May 2007 11:38:54 +0000 Subject: [PATCH] now the fadvise code actually compiles ... let the testing begin. git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1064 a5681a0c-68f1-0310-ab6d-d61299d08faa --- configure.ac | 3 ++- src/rrd_create.c | 2 +- src/rrd_fetch.c | 8 ++++---- src/rrd_open.c | 2 +- src/rrd_update.c | 16 ++++++++-------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 8e64c11..f878dcc 100644 --- a/configure.ac +++ b/configure.ac @@ -71,7 +71,8 @@ char *strchr (), *strrchr (); #endif /* enable posix_fadvise on linux */ -#ifdef HAVE_POSIX_FADVISE +#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FCNTL_H) +#include #define __USE_XOPEN2K 1 #endif diff --git a/src/rrd_create.c b/src/rrd_create.c index 521c726..6f4c804 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -690,7 +690,7 @@ rrd_create_fn(const char *file_name, rrd_t *rrd) return(-1); } -#ifdef POSIX_FADVISE +#ifdef HAVE_POSIX_FADVISE /* this file is not going to be read again any time soon, so we drop everything except the header portion from the buffer cache. for this to work, we have to fdsync the file diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 7e92c2c..0676b4a 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -456,11 +456,11 @@ fprintf(stderr,"partial match, not best\n"); fclose(in_file); return(-1); } -#ifdef POSIX_FADVISE +#ifdef HAVE_POSIX_FADVISE /* don't pollute the buffer cache with data read from the file. We do this while reading to keep damage minimal */ if (0 != posix_fadvise(fileno(in_file), rrd_head_size, ftell(in_file), POSIX_FADV_DONTNEED)) { - rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",file_name, rrd_strerror(errno)); + rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",filename, rrd_strerror(errno)); fclose(in_file); return(-1); } @@ -480,10 +480,10 @@ fprintf(stderr,"partial match, not best\n"); } rrd_free(&rrd); -#ifdef POSIX_FADVISE +#ifdef HAVE_POSIX_FADVISE /* and just to be sure we drop everything except the header at the end */ if (0 != posix_fadvise(fileno(in_file), rrd_head_size, 0, POSIX_FADV_DONTNEED)) { - rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",file_name, rrd_strerror(errno)); + rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",filename, rrd_strerror(errno)); fclose(in_file); return(-1); } diff --git a/src/rrd_open.c b/src/rrd_open.c index 8f08176..3740750 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -88,7 +88,7 @@ rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr) return (-1); } -#ifdef POSIX_FADVISE +#ifdef HAVE_POSIX_FADVISE /* In general we need no read-ahead when dealing with rrd_files. When we stop reading, it is highly unlikely that we start up again. In this manner we actually save time and diskaccess (and buffer cache). diff --git a/src/rrd_update.c b/src/rrd_update.c index dc1a492..91a1d1b 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -1398,16 +1398,16 @@ _rrd_update(const char *filename, const char *tmplt, int argc, const char **argv fclose(rrd_file); return(-1); } -#ifdef POSIX_FADVISE +#ifdef HAVE_POSIX_FADVISE /* with update we have write ops, so they will probably not be done by now, this means the buffers will not get freed. But calling this for the whole file - header will let the data off the hook as soon as it is written when if it is from a previous update cycle. Calling fdsync to force things is much too hard here. */ - if (0 != posix_fadvise(fileno(in_file), rra_begin, 0, POSIX_FADV_DONTNEED)) { - rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",file_name, rrd_strerror(errno)); - fclose(in_file); + if (0 != posix_fadvise(fileno(rrd_file), rra_begin, 0, POSIX_FADV_DONTNEED)) { + rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",filename, rrd_strerror(errno)); + fclose(rrd_file); return(-1); } #endif @@ -1449,11 +1449,11 @@ _rrd_update(const char *filename, const char *tmplt, int argc, const char **argv rra_start += rrd.rra_def[i].row_cnt *rrd.stat_head->ds_cnt*sizeof(rrd_value_t); } -#ifdef POSIX_FADVISE +#ifdef HAVE_POSIX_FADVISE /* same procedure as above ... */ - if (0 != posix_fadvise(fileno(in_file), rrd_head_size, 0, POSIX_FADV_DONTNEED)) { - rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",file_name, rrd_strerror(errno)); - fclose(in_file); + if (0 != posix_fadvise(fileno(rrd_file), rra_begin, 0, POSIX_FADV_DONTNEED)) { + rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",filename, rrd_strerror(errno)); + fclose(rrd_file); return(-1); } #endif -- 2.30.2