X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_resize.c;h=ac853184fa91460b5a58becb7a01eb054d26a904;hb=5fe8a76ab35012a0a5e1bd8cc5ff4a6f059f37f5;hp=b242b482f5ee5742681c195c1ac005349e83b2ff;hpb=b9c1a336b13d8093b9841848cbed687a6e01a5c3;p=rrdtool.git diff --git a/src/rrd_resize.c b/src/rrd_resize.c index b242b48..ac85318 100644 --- a/src/rrd_resize.c +++ b/src/rrd_resize.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 + * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_resize.c Alters size of an RRA ***************************************************************************** @@ -60,7 +60,7 @@ int rrd_resize( rrd_free(&rrdold); return (-1); } - if (LockRRD(rrd_file->fd) != 0) { + if (rrd_lock(rrd_file) != 0) { rrd_set_error("could not lock original RRD"); rrd_free(&rrdold); rrd_close(rrd_file); @@ -74,18 +74,23 @@ int rrd_resize( return (-1); } - if (modify < 0) { + if (modify < 0) if ((long) rrdold.rra_def[target_rra].row_cnt <= -modify) { rrd_set_error("This RRA is not that big"); rrd_free(&rrdold); rrd_close(rrd_file); return (-1); } - } else { - /* the size of the new file */ - rrdnew.stat_head = rrd_file->file_len + - (rrdold.stat_head->ds_cnt * sizeof(rrd_value_t) * modify); + /* the size of the new file */ + /* yes we are abusing the float cookie for this, aargh */ + if ((rrdnew.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) { + rrd_set_error("allocating stat_head for new RRD"); + rrd_free(&rrdold); + rrd_close(rrd_file); + return (-1); } + rrdnew.stat_head->float_cookie = rrd_file->file_len + + (rrdold.stat_head->ds_cnt * sizeof(rrd_value_t) * modify); rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE | RRD_CREAT); if (rrd_out_file == NULL) { rrd_set_error("Can't create '%s': %s", outfilename, @@ -93,7 +98,7 @@ int rrd_resize( rrd_free(&rrdnew); return (-1); } - if (LockRRD(rrd_out_file->fd) != 0) { + if (rrd_lock(rrd_out_file) != 0) { rrd_set_error("could not lock new RRD"); rrd_free(&rrdold); rrd_close(rrd_file); @@ -162,8 +167,8 @@ int rrd_resize( /* Adding extra rows; insert unknown values just after the ** current row number. */ - l = rrdnew.stat_head->ds_cnt * (rrdnew.rra_ptr[target_rra].cur_row + - 1); + l = rrdnew.stat_head->ds_cnt * + (rrdnew.rra_ptr[target_rra].cur_row + 1); while (l > 0) { rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1); rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1); @@ -177,8 +182,8 @@ int rrd_resize( l--; } #else - /* for the mmap case, we did already fill the whole new file with DNAN - * before we copied the old values, so nothing to do here. */ + /* for the mmap case, we did already fill the whole new file with DNAN + * before we copied the old values, so nothing to do here. */ #endif } else { /* Removing rows. Normally this would be just after the cursor @@ -212,7 +217,8 @@ int rrd_resize( } } while (modify < 0) { - rrd_seek(rrd_file, sizeof(rrd_value_t) * rrdnew.stat_head->ds_cnt, + rrd_seek(rrd_file, + sizeof(rrd_value_t) * rrdnew.stat_head->ds_cnt, SEEK_CUR); rrdnew.rra_def[target_rra].row_cnt--; modify++; @@ -243,7 +249,6 @@ int rrd_resize( rrd_free(&rrdold); rrd_close(rrd_file); - rrd_free(&rrdnew); rrd_close(rrd_out_file); return (0);