X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_create.c;h=e9ac860dca92c184f1012e5617076933b3dcdb99;hb=5fc7ff89bdbced9c593c566fea9840a269935dcd;hp=15412e22ab3424b05eaed4fb59180889b9d1a0ec;hpb=9e6db622e8756105c1322481b34650ecbe15da1a;p=rrdtool.git diff --git a/src/rrd_create.c b/src/rrd_create.c index 15412e2..e9ac860 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.14 Copyright by Tobi Oetiker, 1997-2006 + * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 ***************************************************************************** * rrd_create.c creates new rrds *****************************************************************************/ @@ -10,9 +10,9 @@ #include "rrd_is_thread_safe.h" -unsigned long FnvHash(char *str); +unsigned long FnvHash(const char *str); int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashed_name); -void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx); +void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx); int rrd_create(int argc, char **argv) @@ -84,16 +84,16 @@ rrd_create(int argc, char **argv) } rc = rrd_create_r(argv[optind], pdp_step, last_up, - argc - optind - 1, argv + optind + 1); + argc - optind - 1, (const char **)(argv + optind + 1)); return rc; } /* #define DEBUG */ int -rrd_create_r(char *filename, +rrd_create_r(const char *filename, unsigned long pdp_step, time_t last_up, - int argc, char **argv) + int argc, const char **argv) { rrd_t rrd; long i; @@ -439,7 +439,7 @@ rrd_create_r(char *filename, return rrd_create_fn(filename, &rrd); } -void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx) +void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx) { char minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE]; /* @@ -547,13 +547,15 @@ create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashe /* create and empty rrd file according to the specs given */ int -rrd_create_fn(char *file_name, rrd_t *rrd) +rrd_create_fn(const char *file_name, rrd_t *rrd) { unsigned long i,ii; FILE *rrd_file; rrd_value_t *unknown; int unkn_cnt; - + + long rrd_head_size; + if ((rrd_file = fopen(file_name,"wb")) == NULL ) { rrd_set_error("creating '%s': %s",file_name, rrd_strerror(errno)); free(rrd->stat_head); @@ -658,7 +660,8 @@ rrd_create_fn(char *file_name, rrd_t *rrd) rrd->rra_ptr->cur_row = rrd->rra_def[i].row_cnt - 1; fwrite( rrd->rra_ptr, sizeof(rra_ptr_t),1,rrd_file); } - + rrd_head_size = ftell(rrd_file); + /* write the empty data area */ if ((unknown = (rrd_value_t *)malloc(512 * sizeof(rrd_value_t))) == NULL) { rrd_set_error("allocating unknown"); @@ -687,6 +690,24 @@ rrd_create_fn(char *file_name, rrd_t *rrd) return(-1); } +#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 + first though. This will not be all that fast, but 'good' data + like other rrdfiles headers will stay in cache. Now this only works if creating + a single rrd file is not too large, but I assume this should not be the case + in general. Otherwhise we would have to sync and release while writing all + the unknown data. */ + fflush(rrd_file); + fdatasync(fileno(rrd_file)); + if (0 != posix_fadvise(fileno(rrd_file), rrd_head_size, 0, POSIX_FADV_DONTNEED)) { + rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",file_name, rrd_strerror(errno)); + fclose(rrd_file); + return(-1); + } +#endif + fclose(rrd_file); rrd_free(rrd); return (0);