X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Frrd_update.c;h=fa60c0b47d21c26904a1dc1b3e3ce59e04a992f4;hb=271be77064640b1daa3408885d60b8bead1126ad;hp=6ef5d3fe4ed96728e8a9da76001015de6f2942ef;hpb=009ac7ac9dde1ba7c450b230b9118cff2cedc9f6;p=rrdtool.git diff --git a/src/rrd_update.c b/src/rrd_update.c index 6ef5d3f..fa60c0b 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -68,7 +68,7 @@ static inline void normalize_time( } } -static info_t *write_RRA_row( +static inline info_t *write_RRA_row( rrd_file_t *rrd_file, rrd_t *rrd, unsigned long rra_idx, @@ -104,7 +104,7 @@ static info_t *write_RRA_row( if (rrd_write (rrd_file, &(rrd->cdp_prep[cdp_idx].scratch[CDP_scratch_idx].u_val), - sizeof(rrd_value_t) * 1) != sizeof(rrd_value_t) * 1) { + sizeof(rrd_value_t)) != sizeof(rrd_value_t)) { rrd_set_error("writing rrd: %s", rrd_strerror(errno)); return 0; } @@ -135,16 +135,16 @@ info_t *rrd_update_v( char *tmplt = NULL; info_t *result = NULL; infoval rc; + struct option long_options[] = { + {"template", required_argument, 0, 't'}, + {0, 0, 0, 0} + }; rc.u_int = -1; optind = 0; opterr = 0; /* initialize getopt */ while (1) { - static struct option long_options[] = { - {"template", required_argument, 0, 't'}, - {0, 0, 0, 0} - }; int option_index = 0; int opt; @@ -183,6 +183,12 @@ int rrd_update( int argc, char **argv) { + struct option long_options[] = { + {"template", required_argument, 0, 't'}, + {0, 0, 0, 0} + }; + int option_index = 0; + int opt; char *tmplt = NULL; int rc; @@ -190,13 +196,6 @@ int rrd_update( opterr = 0; /* initialize getopt */ while (1) { - static struct option long_options[] = { - {"template", required_argument, 0, 't'}, - {0, 0, 0, 0} - }; - int option_index = 0; - int opt; - opt = getopt_long(argc, argv, "t:", long_options, &option_index); if (opt == EOF) @@ -204,7 +203,7 @@ int rrd_update( switch (opt) { case 't': - tmplt = optarg; + tmplt = strdup(optarg); break; case '?': @@ -222,6 +221,7 @@ int rrd_update( rc = rrd_update_r(argv[optind], tmplt, argc - optind - 1, (const char **) (argv + optind + 1)); + free(tmplt); return rc; } @@ -323,8 +323,10 @@ int _rrd_update( rrd_file = rrd_open(filename, &rrd, RRD_READWRITE); if (rrd_file == NULL) { - goto err_out; + goto err_free; } + /* We are now at the beginning of the rra's */ + rra_current = rra_start = rra_begin = rrd_file->header_len; /* initialize time */ version = atoi(rrd.stat_head->version); @@ -337,26 +339,6 @@ int _rrd_update( current_time_usec = 0; } - rra_current = rra_start = rra_begin = rrd_file->header_len; - /* This is defined in the ANSI C standard, section 7.9.5.3: - - When a file is opened with udpate mode ('+' as the second - or third character in the ... list of mode argument - variables), both input and output may be performed on the - associated stream. However, ... input may not be directly - followed by output without an intervening call to a file - positioning function, unless the input operation encounters - end-of-file. */ -#if 0 //def HAVE_MMAP - rrd_filesize = rrd_file->file_size; - fseek(rrd_file->fd, 0, SEEK_END); - rrd_filesize = ftell(rrd_file->fd); - fseek(rrd_file->fd, rra_current, SEEK_SET); -#else -// fseek(rrd_file->fd, 0, SEEK_CUR); -#endif - - /* get exclusive lock to whole file. * lock gets removed when we close the file. */ @@ -435,26 +417,6 @@ int _rrd_update( rrd_set_error("allocating pdp_new ..."); goto err_free_tmpl_idx; } -#if 0 //def HAVE_MMAP - rrd_mmaped_file = mmap(0, - rrd_file->file_len, - PROT_READ | PROT_WRITE, - MAP_SHARED, fileno(in_file), 0); - if (rrd_mmaped_file == MAP_FAILED) { - rrd_set_error("error mmapping file %s", filename); - free(updvals); - free(pdp_temp); - free(tmpl_idx); - rrd_free(&rrd); - close(rrd_file->fd); - return (-1); - } -#ifdef USE_MADVISE - /* when we use mmaping we tell the kernel the mmap equivalent - of POSIX_FADV_RANDOM */ - madvise(rrd_mmaped_file, rrd_filesize, POSIX_MADV_RANDOM); -#endif -#endif /* loop through the arguments. */ for (arg_i = 0; arg_i < argc; arg_i++) { char *stepper = strdup(argv[arg_i]); @@ -471,7 +433,8 @@ int _rrd_update( } /* initialize all ds input to unknown except the first one which has always got to be set */ - memset(updvals + 1, 'U', rrd.stat_head->ds_cnt); + for (ii = 1; ii <= rrd.stat_head->ds_cnt; ii++) + updvals[ii] = "U"; updvals[0] = stepper; /* separate all ds elements; first must be examined separately due to alternate time syntax */ @@ -558,7 +521,6 @@ int _rrd_update( break; } - /* seek to the beginning of the rra's */ if (rra_current != rra_begin) { #ifndef HAVE_MMAP @@ -1236,6 +1198,7 @@ int _rrd_update( u_val = seasonal_coef[ii]; break; case CF_HWPREDICT: + case CF_MHWPREDICT: /* need to update the null_count and last_null_count. * even do this for non-DNAN pdp_temp because the * algorithm is not learning from batch updates. */ @@ -1334,12 +1297,10 @@ int _rrd_update( (rrd.stat_head->ds_cnt) * (rrd.rra_ptr[i].cur_row) * sizeof(rrd_value_t); if (rra_pos_tmp != rra_current) { -#ifndef HAVE_MMAP if (rrd_seek(rrd_file, rra_pos_tmp, SEEK_SET) != 0) { rrd_set_error("seek error in rrd"); break; } -#endif rra_current = rra_pos_tmp; } #ifdef DEBUG @@ -1421,11 +1382,7 @@ int _rrd_update( free(rra_step_cnt); rpnstack_free(&rpnstack); -#if 0 //def HAVE_MMAP - if (munmap(rrd_file->file_start, rrd_file->file_len) == -1) { - rrd_set_error("error writing(unmapping) file: %s", filename); - } -#else +#if 0 //rrd_flush(rrd_file); //XXX: really needed? #endif /* if we got here and if there is an error and if the file has not been @@ -1444,7 +1401,9 @@ int _rrd_update( rrd_set_error("seek rrd for live header writeback"); goto err_free_pdp_new; } - + /* for mmap, we did already write to the underlying mapping, so we do + not need to write again. */ +#ifndef HAVE_MMAP if (version >= 3) { if (rrd_write(rrd_file, rrd.live_head, sizeof(live_head_t) * 1) != sizeof(live_head_t) * 1) { @@ -1483,6 +1442,7 @@ int _rrd_update( rrd_set_error("rrd_write rra_ptr to rrd"); goto err_free_pdp_new; } +#endif #ifdef HAVE_POSIX_FADVISExxx /* with update we have write ops, so they will probably not be done by now, this means @@ -1531,7 +1491,6 @@ int _rrd_update( } rrd_free(&rrd); - close(rrd_file->fd); rrd_close(rrd_file); free(pdp_new); @@ -1549,9 +1508,9 @@ int _rrd_update( err_free_updvals: free(updvals); err_close: - rrd_free(&rrd); - close(rrd_file->fd); rrd_close(rrd_file); + err_free: + rrd_free(&rrd); err_out: return (-1); }