Hello list At work we have a large archive rrdfiles crerated on i386 and we need to use x86_64 on some newer machines. Long story short I needed to access both 64 bit data from 32 bit hosts and vice versa. Since the common data format is still pending I created this patches to solve my problem. I am posting to the list with the hope thay are useful.
these are intel specific patches I know they are of limited use. Next step is to have updates working correctly on both architectures. Camilo Viecco
Only in rrdtool-1.4.2/bindings/lua: .deps Only in rrdtool-1.4.2/bindings/lua: Makefile Only in rrdtool-1.4.2/bindings: Makefile Only in rrdtool-1.4.2/bindings/perl-piped: Makefile.old Only in rrdtool-1.4.2/bindings/perl-shared: Makefile.old Only in rrdtool-1.4.2/bindings/ruby: mkmf.log Only in rrdtool-1.4.2/bindings/tcl: ifOctets.tcl Only in rrdtool-1.4.2/bindings/tcl: Makefile Only in rrdtool-1.4.2/bindings/tcl: pkgIndex.tcl Only in rrdtool-1.4.2/bindings/tcl: tclrrd1.4.2.so Only in rrdtool-1.4.2: config.h Only in rrdtool-1.4.2: config.log Only in rrdtool-1.4.2: config.status Only in rrdtool-1.4.2/doc: Makefile Only in rrdtool-1.4.2/doc: pod2htmd.tmp Only in rrdtool-1.4.2/doc: pod2htmi.tmp Only in rrdtool-1.4.2/doc: RRDp.pod Only in rrdtool-1.4.2/doc: RRDs.pod Only in rrdtool-1.4.2/examples: 4charts.pl Only in rrdtool-1.4.2/examples: bigtops.pl Only in rrdtool-1.4.2/examples: cgi-demo.cgi Only in rrdtool-1.4.2/examples: Makefile Only in rrdtool-1.4.2/examples: minmax.pl Only in rrdtool-1.4.2/examples: perftest.pl Only in rrdtool-1.4.2/examples: piped-demo.pl Only in rrdtool-1.4.2/examples/rrdcached: Makefile Only in rrdtool-1.4.2/examples: shared-demo.pl Only in rrdtool-1.4.2/examples: stripes.pl Only in rrdtool-1.4.2/intl: Makefile diff -ur -x '*.1' -x '*.html' -x '*.txt' -x '*.spec' -x '*.3' rrdtool-1.4.2-orig/libtool rrdtool-1.4.2/libtool --- rrdtool-1.4.2-orig/libtool 2009-11-15 11:55:33.000000000 +0000 +++ rrdtool-1.4.2/libtool 2010-03-01 16:32:52.000000000 +0000 @@ -1,8 +1,8 @@ -#! /bin/bash +#! /bin/sh # libtool - Provide generalized library-building support services. # Generated automatically by config.status (rrdtool) 1.4.2 -# Libtool was configured on host froburg: +# Libtool was configured on host gmoc-dev.grnoc.iu.edu: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, @@ -56,12 +56,12 @@ # The host system. host_alias= -host=x86_64-unknown-linux-gnu +host=i686-pc-linux-gnu host_os=linux-gnu # The build system. build_alias= -build=x86_64-unknown-linux-gnu +build=i686-pc-linux-gnu build_os=linux-gnu # A sed program that does not truncate output. @@ -86,7 +86,7 @@ LN_S="ln -s" # What is the maximum length of a command? -max_cmd_len=1572864 +max_cmd_len=98304 # Object file suffix (normally "o"). objext=o @@ -150,7 +150,7 @@ objdir=.libs # Shell to use when invoking shell scripts. -SHELL="/bin/bash" +SHELL="/bin/sh" # An echo program that does not interpret backslashes. ECHO="echo" @@ -234,10 +234,10 @@ hardcode_into_libs=yes # Compile-time system search path for libraries. -sys_lib_search_path_spec="/usr/lib/gcc/x86_64-linux-gnu/4.3.3 /usr/lib /lib" +sys_lib_search_path_spec="/usr/lib/gcc/i386-redhat-linux/4.1.2 /usr/lib /lib" # Run-time system search path for libraries. -sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib32/alsa-lib /usr/lib/alsa-lib /usr/local/lib /opt/SUNWut/lib /usr/pack/srss-4.1-mo/usr/lib /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu " +sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/mysql /usr/lib/qt-3.3/lib " # Whether dlopen is supported. dlopen_support=unknown @@ -254,7 +254,7 @@ # The linker used to build libraries. -LD="/usr/bin/ld -m elf_x86_64" +LD="/usr/bin/ld" # Commands used to build an old-style archive. old_archive_cmds="\$AR \$AR_FLAGS \$oldlib\$oldobjs~\$RANLIB \$oldlib" Only in rrdtool-1.4.2: Makefile Only in rrdtool-1.4.2: mmaptestAfHpZh Only in rrdtool-1.4.2/po: Makefile Only in rrdtool-1.4.2/po: Makefile.in Only in rrdtool-1.4.2/po: POTFILES Only in rrdtool-1.4.2/po: remove-potcdate.sed Only in rrdtool-1.4.2: rrd_config.h Only in rrdtool-1.4.2/src: .deps Only in rrdtool-1.4.2/src: librrd.pc Only in rrdtool-1.4.2/src: librrd.sym Only in rrdtool-1.4.2/src: librrd.sym.in Only in rrdtool-1.4.2/src: Makefile diff -ur -x '*.1' -x '*.html' -x '*.txt' -x '*.spec' -x '*.3' rrdtool-1.4.2-orig/src/rrd_format.h rrdtool-1.4.2/src/rrd_format.h --- rrdtool-1.4.2-orig/src/rrd_format.h 2009-11-15 11:54:23.000000000 +0000 +++ rrdtool-1.4.2/src/rrd_format.h 2010-03-01 15:44:53.000000000 +0000 @@ -20,6 +20,7 @@ #endif #include "rrd.h" +#include <stdint.h> /***************************************************************************** * put this in your /usr/lib/magic file (/etc/magic on HPUX) @@ -37,11 +38,21 @@ #define RRD_VERSION3 "0003" #define FLOAT_COOKIE 8.642135E130 +#define MULTI_FORMAT + typedef union unival { - unsigned long u_cnt; + uint64_t u_cnt_64; + uint32_t u_cnt_32; + unsigned long u_cnt; rrd_value_t u_val; } unival; +typedef enum format_compat_t { FILE_NATIVE = 0, /* data source types available */ + FILE_i386, + FILE_x86_64, + FILE_UNKNOWN +}format_compat_t; + /**************************************************************************** * The RRD Database Structure @@ -130,6 +141,51 @@ } stat_head_t; +typedef struct stat_head_32_t { + + /* Data Base Identification Section ** */ + char cookie[4]; /* RRD */ + char version[8]; /* version of the format */ + double float_cookie __attribute((packed)) ; /* is it the correct double + * representation ? */ + + /* Data Base Structure Definition **** */ + uint32_t ds_cnt __attribute((packed)); + /* how many different ds provide + * input to the rrd */ + uint32_t rra_cnt __attribute((packed)); + /* how many rras will be maintained + * in the rrd */ + uint32_t pdp_step __attribute((packed)) ; + /* pdp interval in seconds */ + + unival par[10] __attribute((packed)); /* global parameters ... unused + at the moment */ +} stat_head_32_t; + +typedef struct stat_head_64_t { + + /* Data Base Identification Section ** */ + char cookie[4]; /* RRD */ + char version[12]; /* version of the format */ + double float_cookie __attribute((packed)) ; /* is it the correct double + * representation ? */ + + /* Data Base Structure Definition **** */ + uint64_t ds_cnt __attribute((packed)); + /* how many different ds provide + * input to the rrd */ + uint64_t rra_cnt __attribute((packed)); + /* how many rras will be maintained + * in the rrd */ + uint64_t pdp_step __attribute((packed)) ; + /* pdp interval in seconds */ + + unival par[10] __attribute((packed)); /* global parameters ... unused + at the moment */ +} stat_head_64_t; + + /**************************************************************************** * POS 2: ds_def_t (* ds_cnt) Data Source definitions ****************************************************************************/ @@ -266,6 +322,27 @@ } rra_def_t; +typedef struct rra_def_32_t { + char cf_nam[CF_NAM_SIZE] ; /* consolidation function (null term) */ + uint32_t row_cnt __attribute((packed)) ; /* number of entries in the store */ + uint32_t pdp_cnt __attribute((packed)) ; /* how many primary data points are + * required for a consolidated data + * point?*/ + unival par[MAX_RRA_PAR_EN] __attribute((packed)) ; /* index see rra_param_en */ + +} rra_def_32_t; + +typedef struct rra_def_64_t { + char cf_nam[CF_NAM_SIZE] ; /* consolidation function (null term) */ + uint8_t align[4]; + uint64_t row_cnt __attribute((packed)) ; /* number of entries in the store */ + uint64_t pdp_cnt __attribute((packed)) ; /* how many primary data points are + * required for a consolidated data + * point?*/ + unival par[MAX_RRA_PAR_EN] __attribute((packed)) ; /* index see rra_param_en */ + +} rra_def_64_t; + /**************************************************************************** **************************************************************************** @@ -285,6 +362,22 @@ } live_head_t; + +typedef struct live_head_32_t { + uint32_t last_up __attribute((packed)) ; /* when was rrd last updated */ + uint32_t last_up_usec __attribute((packed)); /* micro seconds part of the + update timestamp. Always >= 0 */ +} live_head_32_t; + + +typedef struct live_head_64_t { + uint64_t last_up __attribute((packed)) ; /* when was rrd last updated */ + uint64_t last_up_usec __attribute((packed)); /* micro seconds part of the + update timestamp. Always >= 0 */ +} live_head_64_t; + + + /**************************************************************************** * POS 5: pdp_prep_t (* ds_cnt) here we prepare the pdps ****************************************************************************/ @@ -385,6 +478,14 @@ unsigned long cur_row; /* current row in the rra */ } rra_ptr_t; +typedef struct rra_ptr_32_t { + uint32_t cur_row; /* current row in the rra */ +} rra_ptr_32_t; + +typedef struct rra_ptr_64_t { + uint64_t cur_row; /* current row in the rra */ +} rra_ptr_64_t; + /**************************************************************************** **************************************************************************** @@ -392,6 +493,7 @@ **************************************************************************** ****************************************************************************/ typedef struct rrd_t { + format_compat_t compat; /* the on disk representation*/ 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 */ diff -ur -x '*.1' -x '*.html' -x '*.txt' -x '*.spec' -x '*.3' rrdtool-1.4.2-orig/src/rrd_open.c rrdtool-1.4.2/src/rrd_open.c --- rrdtool-1.4.2-orig/src/rrd_open.c 2009-11-15 11:54:23.000000000 +0000 +++ rrdtool-1.4.2/src/rrd_open.c 2010-03-01 16:12:31.000000000 +0000 @@ -80,6 +80,8 @@ #endif #endif + + /* Open a database file, return its header and an open filehandle, * positioned to the first cdp in the first rra. * In the error path of rrd_open, only rrd_free(&rrd) has to be called @@ -99,6 +101,22 @@ int flags = 0; int version; + + format_compat_t file_format=FILE_NATIVE; + stat_head_64_t *stat_head_64; + stat_head_32_t *stat_head_32; + rra_def_32_t *rra_def_32; + rra_def_64_t *rra_def_64; + live_head_32_t *live_head_32; + live_head_64_t *live_head_64; + rra_ptr_32_t *rra_ptr_32; + rra_ptr_64_t *rra_ptr_64; + +#define TRANS_BUF_SIZE 12288 + char trans_buf[TRANS_BUF_SIZE]; + + + #ifdef HAVE_MMAP ssize_t _page_size = sysconf(_SC_PAGESIZE); char *data = MAP_FAILED; @@ -273,6 +291,115 @@ } #endif +#ifdef MULTI_FORMAT + if (RRD_READONLY == (rdwr & RRD_READONLY) || 1==1 ){ + /*try native first*/ +#ifdef DEBUG_MF + fprintf(stderr,"trying multi-format\n"); +#endif + + __rrd_read(rrd->stat_head, stat_head_t, + 1); + + /* lets do some test if we are on track ... */ + if (memcmp(rrd->stat_head->cookie, RRD_COOKIE, sizeof(RRD_COOKIE)) != 0) { + rrd_set_error("'%s' is not an RRD file", file_name); + goto out_nullify_head; + } + file_format=FILE_NATIVE; + rrd->compat=FILE_NATIVE; + if (rrd->stat_head->float_cookie != FLOAT_COOKIE) { + //fprintf(stderr,"file=%f cookie=%f\n",rrd->stat_head->float_cookie,FLOAT_COOKIE); + //fprintf(stderr,"file(inhex)=%u\n",(unsigned long ) rrd->stat_head->float_cookie); +//rrd_set_error("This RRD was created on another architecture"); + //rrd_set_error("This RRD was created on another architecture"); +#ifndef HAVE_MMAP + lseek(rrd_file->fd,0,SEEK_SET); + offset=0; +#endif + offset=0; + /*try 32bit arch*/ + rrd->stat_head=malloc(sizeof(stat_head_64_t)); + if(NULL==rrd->stat_head){ + goto out_nullify_head; + } + stat_head_32=(stat_head_32_t *)trans_buf; + stat_head_64=(stat_head_64_t *)trans_buf; + __rrd_read(stat_head_32, stat_head_32_t, + 1); + + //convert to native(32) + memcpy(rrd->stat_head->cookie,stat_head_32->cookie,4); + memcpy(rrd->stat_head->version,stat_head_32->version,5); + rrd->stat_head->float_cookie=stat_head_32->float_cookie; + rrd->stat_head->ds_cnt=stat_head_32->ds_cnt; + rrd->stat_head->rra_cnt=stat_head_32->rra_cnt; + rrd->stat_head->pdp_step=stat_head_32->pdp_step; + memcpy( rrd->stat_head->par, stat_head_32->par, sizeof(unival)*10); + + + if (rrd->stat_head->float_cookie == FLOAT_COOKIE) { + file_format=FILE_i386; + rrd->compat=FILE_i386; + //fprintf(stderr,"is 32!\n"); + + } + else{ + //try 64 +#ifndef HAVE_MMAP + lseek(rrd_file->fd,0,SEEK_SET); + offset=0; +#endif + offset=0; + + + __rrd_read(stat_head_64, stat_head_64_t, + 1); + rrd->stat_head->float_cookie=stat_head_64->float_cookie; + rrd->stat_head->ds_cnt=stat_head_64->ds_cnt; + rrd->stat_head->rra_cnt=stat_head_64->rra_cnt; + rrd->stat_head->pdp_step=stat_head_64->pdp_step; + memcpy( rrd->stat_head->par, stat_head_64->par, sizeof(unival)*10); + if (rrd->stat_head->float_cookie == FLOAT_COOKIE) { + file_format=FILE_x86_64; + rrd->compat=FILE_x86_64; + + } + else{ + + rrd_set_error("This RRD was created with an incompatible architecture/compiler"); + goto out_nullify_head; + + + } + + } + } + + } + else{ + /*do native the native branch*/ + + __rrd_read(rrd->stat_head, stat_head_t, + 1); + + /* lets do some test if we are on track ... */ + if (memcmp(rrd->stat_head->cookie, RRD_COOKIE, sizeof(RRD_COOKIE)) != 0) { + rrd_set_error("'%s' is not an RRD file", file_name); + goto out_nullify_head; + } + + if (rrd->stat_head->float_cookie != FLOAT_COOKIE) { + //fprintf(stderr,"file=%f cookie=%f\n",rrd->stat_head->float_cookie,FLOAT_COOKIE); + //fprintf(stderr,"file(inhex)=%u\n",(unsigned long ) rrd->stat_head->float_cookie); + + rrd_set_error("This RRD was created on another architecture"); + goto out_nullify_head; + } + + } +#else + __rrd_read(rrd->stat_head, stat_head_t, 1); @@ -283,10 +410,20 @@ } if (rrd->stat_head->float_cookie != FLOAT_COOKIE) { + fprintf(stderr,"file=%f cookie=%f\n",rrd->stat_head->float_cookie,FLOAT_COOKIE); + fprintf(stderr,"file(inhex)=%u\n",(unsigned long ) rrd->stat_head->float_cookie); + rrd_set_error("This RRD was created on another architecture"); goto out_nullify_head; } +#endif + + //cviecco + //fprintf(stderr, "ds_cnt=%u \n", rrd->stat_head->ds_cnt); + //fprintf(stderr, "rra_cnt=%u \n", rrd->stat_head->rra_cnt); + //fprintf(stderr, "pdp_step=%u \n", rrd->stat_head->pdp_step); + version = atoi(rrd->stat_head->version); if (version > atoi(RRD_VERSION)) { @@ -299,6 +436,8 @@ madvise(data + PAGE_START(offset), sizeof(ds_def_t) * rrd->stat_head->ds_cnt, MADV_WILLNEED); #endif + + //wow this one if platform independent! __rrd_read(rrd->ds_def, ds_def_t, rrd->stat_head->ds_cnt); @@ -307,11 +446,67 @@ madvise(data + PAGE_START(offset), sizeof(rra_def_t) * rrd->stat_head->rra_cnt, MADV_WILLNEED); #endif - __rrd_read(rrd->rra_def, rra_def_t, - rrd->stat_head->rra_cnt); + switch(file_format){ + case FILE_NATIVE: + __rrd_read(rrd->rra_def, rra_def_t, + rrd->stat_head->rra_cnt); + break; + case FILE_i386: + rra_def_32=(rra_def_32_t *) trans_buf; + rrd->rra_def=malloc(sizeof(rra_def_t)*rrd->stat_head->rra_cnt); + if(NULL==rrd->rra_def){ + goto out_nullify_head; + } + __rrd_read(rra_def_32, rra_def_32_t, + rrd->stat_head->rra_cnt); + //now convert to native + { + uint32_t i; + for(i=0;i<rrd->stat_head->rra_cnt;i++){ + memcpy(rrd->rra_def[i].cf_nam,rra_def_32[i].cf_nam, + CF_NAM_SIZE); + rrd->rra_def[i].row_cnt=rra_def_32[i].row_cnt; + rrd->rra_def[i].pdp_cnt=rra_def_32[i].pdp_cnt; + memcpy(rrd->rra_def[i].par,rra_def_32[i].par,sizeof(unival)*MAX_RRA_PAR_EN); + } + } + break; + + case FILE_x86_64: + rra_def_64=(rra_def_64_t *) trans_buf; + rrd->rra_def=malloc(sizeof(rra_def_t)*rrd->stat_head->rra_cnt); + if(NULL==rrd->rra_def){ + goto out_nullify_head; + } + __rrd_read(rra_def_64, rra_def_64_t, + rrd->stat_head->rra_cnt); + //now convert to native + { + uint32_t i; + for(i=0;i<rrd->stat_head->rra_cnt;i++){ + memcpy(rrd->rra_def[i].cf_nam,rra_def_64[i].cf_nam, + CF_NAM_SIZE); + rrd->rra_def[i].row_cnt=rra_def_64[i].row_cnt; + rrd->rra_def[i].pdp_cnt=rra_def_64[i].pdp_cnt; + //cviecco + //fprintf(stderr,"rra[%i] '%s' num_rows=%lu pdp_cnt%lu\n",i,rrd->rra_def[i].cf_nam,rrd->rra_def[i].row_cnt,rrd->rra_def[i].pdp_cnt); + //fprintf(stderr,"read rra[%i] '%s' num_rows=%llx pdp_cnt%llx\n",i,rra_def_64[i].cf_nam,rra_def_64[i].row_cnt,rra_def_64[i].pdp_cnt); + + memcpy(rrd->rra_def[i].par,rra_def_64[i].par,sizeof(unival)*MAX_RRA_PAR_EN); + } + } + break; + default: + fprintf(stderr,"cannot handle file!\n"); + goto out_nullify_head; + } /* handle different format for the live_head */ if (version < 3) { + if(file_format!=FILE_NATIVE){ + fprintf(stderr,"cannot handle file!, non native low version\n"); + goto out_nullify_head; + } rrd->live_head = (live_head_t *) malloc(sizeof(live_head_t)); if (rrd->live_head == NULL) { rrd_set_error("live_head_t malloc"); @@ -332,15 +527,97 @@ madvise(data + PAGE_START(offset), sizeof(live_head_t), MADV_WILLNEED); #endif - __rrd_read(rrd->live_head, live_head_t, - 1); + switch(file_format){ + case FILE_NATIVE: + __rrd_read(rrd->live_head, live_head_t, + 1); + break; + case FILE_i386: + rrd->live_head = (live_head_t *) malloc(sizeof(live_head_t)); + if (rrd->live_head == NULL) { + rrd_set_error("live_head_t malloc"); + goto out_close; + } + live_head_32=(live_head_32_t *) trans_buf; + __rrd_read(live_head_32, live_head_32_t, + 1); + //convert + rrd->live_head->last_up=live_head_32->last_up; + rrd->live_head->last_up_usec=live_head_32->last_up_usec; + break; + + case FILE_x86_64: + rrd->live_head = (live_head_t *) malloc(sizeof(live_head_t)); + if (rrd->live_head == NULL) { + rrd_set_error("live_head_t malloc"); + goto out_close; + } + live_head_64=(live_head_64_t *) trans_buf; + __rrd_read(live_head_64, live_head_64_t, + 1); + //convert + rrd->live_head->last_up=(time_t)live_head_64->last_up; + rrd->live_head->last_up_usec= (long) live_head_64->last_up_usec; + break; + + default: + rrd_set_error("internal error (incompatible file format)"); + goto out_close; + } } + //These two require no conversion! __rrd_read(rrd->pdp_prep, pdp_prep_t, rrd->stat_head->ds_cnt); __rrd_read(rrd->cdp_prep, cdp_prep_t, rrd->stat_head->rra_cnt * rrd->stat_head->ds_cnt); - __rrd_read(rrd->rra_ptr, rra_ptr_t, - rrd->stat_head->rra_cnt); + + + switch(file_format){ + case FILE_NATIVE: + __rrd_read(rrd->rra_ptr, rra_ptr_t, + rrd->stat_head->rra_cnt); + break; + case FILE_i386: + rrd->rra_ptr = (rra_ptr_t *) + malloc(sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt); + if (rrd->rra_ptr == NULL) { + rrd_set_error("rra_ptr_t malloc"); + goto out_close; + } + rra_ptr_32=(rra_ptr_32_t *) trans_buf; + __rrd_read(rra_ptr_32, rra_ptr_32_t, + rrd->stat_head->rra_cnt); + { + uint32_t i; + for(i=0;i<rrd->stat_head->rra_cnt;i++){ + rrd->rra_ptr[i].cur_row=rra_ptr_32[i].cur_row; + } + } + break; + + + case FILE_x86_64: + rrd->rra_ptr = (rra_ptr_t *) + malloc(sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt); + if (rrd->rra_ptr == NULL) { + rrd_set_error("rra_ptr_t malloc"); + goto out_close; + } + rra_ptr_64=(rra_ptr_64_t *) trans_buf; + __rrd_read(rra_ptr_64, rra_ptr_64_t, + rrd->stat_head->rra_cnt); + { + uint32_t i; + for(i=0;i<rrd->stat_head->rra_cnt;i++){ + rrd->rra_ptr[i].cur_row=rra_ptr_64[i].cur_row; + } + } + break; + } + + //cviecco + //fprintf(stderr,"last_up=%u\n", rrd->live_head->last_up); + //fprintf(stderr,"last_up_usec=%u\n", rrd->live_head->last_up_usec); rrd_file->header_len = offset; rrd_file->pos = offset; @@ -358,6 +635,10 @@ { rrd_set_error("'%s' is too small (should be %ld bytes)", file_name, (long long) correct_len); + //cviecco + fprintf(stderr,"real_len=%u\n", rrd_file->file_len); + fprintf(stderr,"header_len=%u\n", rrd_file->header_len); + goto out_nullify_head; } } @@ -706,18 +987,15 @@ /* free RRD header data. */ -#ifdef HAVE_MMAP void rrd_free( rrd_t *rrd) { +#ifdef HAVE_MMAP if (rrd->legacy_last_up) { /* this gets set for version < 3 only */ free(rrd->live_head); } -} + #else -void rrd_free( - rrd_t *rrd) -{ free(rrd->live_head); free(rrd->stat_head); free(rrd->ds_def); @@ -726,8 +1004,9 @@ free(rrd->pdp_prep); free(rrd->cdp_prep); free(rrd->rrd_value); -} #endif +} + /* routine used by external libraries to free memory allocated by Only in rrdtool-1.4.2/src: rrd_open.c.orig Only in rrdtool-1.4.2/src: rrd_open.c.rej Only in rrdtool-1.4.2/src: .rrd_open.c.rej.swp diff -ur -x '*.1' -x '*.html' -x '*.txt' -x '*.spec' -x '*.3' rrdtool-1.4.2-orig/src/rrd_update.c rrdtool-1.4.2/src/rrd_update.c --- rrdtool-1.4.2-orig/src/rrd_update.c 2009-11-15 11:54:23.000000000 +0000 +++ rrdtool-1.4.2/src/rrd_update.c 2010-01-28 16:04:10.000000000 +0000 @@ -271,12 +271,11 @@ rrd_file_t *rrd_file, unsigned long rra_begin); -#ifndef HAVE_MMAP + static int write_changes_to_disk( rrd_t *rrd, rrd_file_t *rrd_file, int version); -#endif /* * normalize time as returned by gettimeofday. usec part must @@ -577,11 +576,11 @@ if (rrd_test_error()) { goto err_free_structures; } -#ifndef HAVE_MMAP + if (write_changes_to_disk(&rrd, rrd_file, version) == -1) { goto err_free_structures; } -#endif + /* calling the smoothing code here guarantees at most one smoothing * operation per rrd_update call. Unfortunately, it is possible with bulk @@ -2024,7 +2023,7 @@ return 0; } -#ifndef HAVE_MMAP + /* * Flush changes to disk (unless we're using mmap) * @@ -2035,52 +2034,138 @@ rrd_file_t *rrd_file, int version) { - /* we just need to write back the live header portion now */ - if (rrd_seek(rrd_file, (sizeof(stat_head_t) - + sizeof(ds_def_t) * rrd->stat_head->ds_cnt - + sizeof(rra_def_t) * rrd->stat_head->rra_cnt), - SEEK_SET) != 0) { - rrd_set_error("seek rrd for live header writeback"); - return -1; + live_head_32_t live_head_32; + live_head_64_t live_head_64; + rra_ptr_32_t *rra_ptr_32; + rra_ptr_64_t *rra_ptr_64; + int i; + +#ifdef HAVE_MMAP + if (FILE_NATIVE==rrd->compat){ + return 0; } - if (version >= 3) { - if (rrd_write(rrd_file, rrd->live_head, - sizeof(live_head_t) * 1) != sizeof(live_head_t) * 1) { - rrd_set_error("rrd_write live_head to rrd"); - return -1; - } - } else { - if (rrd_write(rrd_file, rrd->legacy_last_up, +#endif + + + switch(rrd->compat) { + + case FILE_NATIVE: + + + + /* we just need to write back the live header portion now */ + if (rrd_seek(rrd_file, (sizeof(stat_head_t) + + sizeof(ds_def_t) * rrd->stat_head->ds_cnt + + sizeof(rra_def_t) * rrd->stat_head->rra_cnt), + SEEK_SET) != 0) { + rrd_set_error("seek rrd for live header writeback"); + return -1; + } + if (version >= 3) { + if (rrd_write(rrd_file, rrd->live_head, + sizeof(live_head_t) * 1) != sizeof(live_head_t) * 1) { + rrd_set_error("rrd_write live_head to rrd"); + return -1; + } + } else { + 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; - } - } + rrd_set_error("rrd_write live_head to rrd"); + return -1; + } + } - if (rrd_write(rrd_file, rrd->pdp_prep, + if (rrd_write(rrd_file, rrd->pdp_prep, sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt) - != (ssize_t) (sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt)) { - rrd_set_error("rrd_write pdp_prep to rrd"); - return -1; - } + != (ssize_t) (sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt)) { + rrd_set_error("rrd_write pdp_prep to rrd"); + return -1; + } + + if (rrd_write(rrd_file, rrd->cdp_prep, + sizeof(cdp_prep_t) * rrd->stat_head->rra_cnt * + rrd->stat_head->ds_cnt) + != (ssize_t) (sizeof(cdp_prep_t) * rrd->stat_head->rra_cnt * + rrd->stat_head->ds_cnt)) { - if (rrd_write(rrd_file, rrd->cdp_prep, - sizeof(cdp_prep_t) * rrd->stat_head->rra_cnt * - rrd->stat_head->ds_cnt) - != (ssize_t) (sizeof(cdp_prep_t) * rrd->stat_head->rra_cnt * - rrd->stat_head->ds_cnt)) { + rrd_set_error("rrd_write cdp_prep to rrd"); + return -1; + } - rrd_set_error("rrd_write cdp_prep to rrd"); - return -1; - } + if (rrd_write(rrd_file, rrd->rra_ptr, + sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt) + != (ssize_t) (sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt)) { + rrd_set_error("rrd_write rra_ptr to rrd"); + return -1; + } + return 0; - if (rrd_write(rrd_file, rrd->rra_ptr, - sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt) - != (ssize_t) (sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt)) { - rrd_set_error("rrd_write rra_ptr to rrd"); - return -1; + break; + case FILE_i386: + ///we need to do some conversions and some mallocs too! + //step1 seek to the live head + if (rrd_seek(rrd_file, (sizeof(stat_head_32_t) + + sizeof(ds_def_t) * rrd->stat_head->ds_cnt + + sizeof(rra_def_32_t) * rrd->stat_head->rra_cnt), + SEEK_SET) != 0) { + rrd_set_error("seek rrd for live header writeback"); + return -1; + } + //step2 write the live head! + if(version<=2){ + rrd_set_error("incompatible rrd version for arch"); + return -1; + } + live_head_32.last_up=rrd->live_head->last_up; + live_head_32.last_up_usec=rrd->live_head->last_up_usec; + if (rrd_write(rrd_file, &live_head_32, + sizeof(live_head_32_t) * 1) != sizeof(live_head_32_t) * 1) { + rrd_set_error("rrd_write live_head to rrd"); + return -1; + } + //step3 write the pdp_preps + if (rrd_write(rrd_file, rrd->pdp_prep, + sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt) + != (ssize_t) (sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt)) { + rrd_set_error("rrd_write pdp_prep to rrd"); + return -1; + } + //step4 write the cdp preps + if (rrd_write(rrd_file, rrd->cdp_prep, + sizeof(cdp_prep_t) * rrd->stat_head->rra_cnt * + rrd->stat_head->ds_cnt) + != (ssize_t) (sizeof(cdp_prep_t) * rrd->stat_head->rra_cnt * + rrd->stat_head->ds_cnt)) { + + rrd_set_error("rrd_write cdp_prep to rrd"); + return -1; + } + //step5 write the pointers! + rra_ptr_32 = (rra_ptr_32_t *) + malloc(sizeof(rra_ptr_32_t) * rrd->stat_head->rra_cnt); + if(NULL== rra_ptr_32){ + rrd_set_error("cannot allocate rrd ptr"); + return -1; + } + for(i=0;i<rrd->stat_head->rra_cnt;i++){ + rra_ptr_32[i].cur_row=rrd->rra_ptr[i].cur_row; + } + + + if (rrd_write(rrd_file, rra_ptr_32, + sizeof(rra_ptr_32_t) * rrd->stat_head->rra_cnt) + != (ssize_t) (sizeof(rra_ptr_32_t) * rrd->stat_head->rra_cnt)) { + rrd_set_error("rrd_write rra_ptr to rrd"); + return -1; + } + free(rra_ptr_32); + return 0; + + default: + fprintf(stderr,"something went bad"); + return -1; + break; //just in case } - return 0; } -#endif + Only in rrdtool-1.4.2/src: rrd_update.c.orig Only in rrdtool-1.4.2: stamp-h1
_______________________________________________ rrd-developers mailing list rrd-developers@lists.oetiker.ch https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers