From 8af8b463237a06b03425ccc4d4d8164ddb44fb68 Mon Sep 17 00:00:00 2001 From: oetiker Date: Sun, 25 May 2008 20:00:45 +0000 Subject: [PATCH] fix update compatibility with rrd-1.0.x files git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1374 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_format.h | 3 ++- src/rrd_open.c | 22 ++++++++++++++-------- src/rrd_update.c | 5 ++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/rrd_format.h b/src/rrd_format.h index 9deb5ab..8539f02 100644 --- a/src/rrd_format.h +++ b/src/rrd_format.h @@ -383,7 +383,8 @@ typedef struct rrd_t { stat_head_t *stat_head; /* the static header */ ds_def_t *ds_def; /* list of data source definitions */ rra_def_t *rra_def; /* list of round robin archive def */ - live_head_t *live_head; + live_head_t *live_head; /* rrd v >= 3 last_up with us */ + time_t *legacy_last_up; /* rrd v < 3 last_up time */ pdp_prep_t *pdp_prep; /* pdp data prep area */ cdp_prep_t *cdp_prep; /* cdp prep area */ rra_ptr_t *rra_ptr; /* list of rra pointers */ diff --git a/src/rrd_open.c b/src/rrd_open.c index b6f3abb..2ef4309 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -226,12 +226,14 @@ rrd_file_t *rrd_open( rrd_set_error("live_head_t malloc"); goto out_close; } -#ifdef HAVE_MMAP - memmove(&rrd->live_head->last_up, data + offset, sizeof(long)); - offset += sizeof(long); -#else - offset += read(rrd_file->fd, &rrd->live_head->last_up, sizeof(long)); -#endif + +#if defined USE_MADVISE + /* the live_head will be needed soonish, so hint accordingly */ + madvise(data + PAGE_START(offset), + sizeof(time_t), MADV_WILLNEED); +#endif + __rrd_read(rrd->legacy_last_up,time_t,1); + rrd->live_head->last_up = *rrd->legacy_last_up; rrd->live_head->last_up_usec = 0; } else { #if defined USE_MADVISE @@ -512,6 +514,7 @@ void rrd_init( rrd->ds_def = NULL; rrd->rra_def = NULL; rrd->live_head = NULL; + rrd->legacy_last_up = NULL; rrd->rra_ptr = NULL; rrd->pdp_prep = NULL; rrd->cdp_prep = NULL; @@ -522,9 +525,12 @@ void rrd_init( /* free RRD header data. */ #ifdef HAVE_MMAP -inline void rrd_free( - rrd_t UNUSED(*rrd)) +void rrd_free( + rrd_t *rrd) { + if (rrd->legacy_last_up){ /* this gets set for version < 3 only */ + free(rrd->live_head); + } } #else void rrd_free( diff --git a/src/rrd_update.c b/src/rrd_update.c index d861e9e..becce2c 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -832,6 +832,9 @@ static int process_arg( rrd->live_head->last_up = *current_time; rrd->live_head->last_up_usec = *current_time_usec; + if ( version < 3 ){ + *rrd->legacy_last_up = rrd->live_head->last_up; + } free(seasonal_coef); free(last_seasonal_coef); return 0; @@ -2053,7 +2056,7 @@ static int write_changes_to_disk( return -1; } } else { - if (rrd_write(rrd_file, &rrd->live_head->last_up, + if (rrd_write(rrd_file, rrd->legacy_last_up, sizeof(time_t) * 1) != sizeof(time_t) * 1) { rrd_set_error("rrd_write live_head to rrd"); return -1; -- 2.30.2