projects
/
rrdtool.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bernhard
[rrdtool.git]
/
src
/
rrd_resize.c
diff --git
a/src/rrd_resize.c
b/src/rrd_resize.c
index
1778f42
..
b242b48
100644
(file)
--- a/
src/rrd_resize.c
+++ b/
src/rrd_resize.c
@@
-55,44
+55,49
@@
int rrd_resize(
modify = -modify;
modify = -modify;
- rrd_file = rrd_open(infilename, &rrdold, RRD_READWRITE);
+ rrd_file = rrd_open(infilename, &rrdold, RRD_READWRITE
| RRD_COPY
);
if (rrd_file == NULL) {
if (rrd_file == NULL) {
- rrd_
set_error("could not open RRD"
);
+ rrd_
free(&rrdold
);
return (-1);
}
if (LockRRD(rrd_file->fd) != 0) {
rrd_set_error("could not lock original RRD");
rrd_free(&rrdold);
return (-1);
}
if (LockRRD(rrd_file->fd) != 0) {
rrd_set_error("could not lock original RRD");
rrd_free(&rrdold);
-
close(rrd_file->fd
);
+
rrd_close(rrd_file
);
return (-1);
}
if (target_rra >= rrdold.stat_head->rra_cnt) {
rrd_set_error("no such RRA in this RRD");
rrd_free(&rrdold);
return (-1);
}
if (target_rra >= rrdold.stat_head->rra_cnt) {
rrd_set_error("no such RRA in this RRD");
rrd_free(&rrdold);
-
close(rrd_file->fd
);
+
rrd_close(rrd_file
);
return (-1);
}
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);
if ((long) rrdold.rra_def[target_rra].row_cnt <= -modify) {
rrd_set_error("This RRA is not that big");
rrd_free(&rrdold);
-
close(rrd_file->fd
);
+
rrd_close(rrd_file
);
return (-1);
}
return (-1);
}
-
- rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_CREAT);
+ } else {
+ /* the size of the new file */
+ rrdnew.stat_head = 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,
rrd_strerror(errno));
if (rrd_out_file == NULL) {
rrd_set_error("Can't create '%s': %s", outfilename,
rrd_strerror(errno));
+ rrd_free(&rrdnew);
return (-1);
}
if (LockRRD(rrd_out_file->fd) != 0) {
rrd_set_error("could not lock new RRD");
rrd_free(&rrdold);
return (-1);
}
if (LockRRD(rrd_out_file->fd) != 0) {
rrd_set_error("could not lock new RRD");
rrd_free(&rrdold);
-
close(rrd_file->fd
);
-
close(rrd_out_file->fd
);
+
rrd_close(rrd_file
);
+
rrd_close(rrd_out_file
);
return (-1);
}
/*XXX: do one write for those parts of header that are unchanged */
return (-1);
}
/*XXX: do one write for those parts of header that are unchanged */
@@
-111,15
+116,14
@@
int rrd_resize(
case 1:
rrdold.stat_head->version[3] = '3';
break;
case 1:
rrdold.stat_head->version[3] = '3';
break;
- default:
{
+ default:
rrd_set_error("Do not know how to handle RRD version %s",
rrdold.stat_head->version);
rrd_set_error("Do not know how to handle RRD version %s",
rrdold.stat_head->version);
+ rrd_close(rrd_file);
rrd_free(&rrdold);
rrd_free(&rrdold);
- close(rrd_file->fd);
return (-1);
return (-1);
+ break;
}
}
- }
-
/* XXX: Error checking? */
rrd_write(rrd_out_file, rrdnew.stat_head, sizeof(stat_head_t) * 1);
/* XXX: Error checking? */
rrd_write(rrd_out_file, rrdnew.stat_head, sizeof(stat_head_t) * 1);
@@
-165,12
+169,17
@@
int rrd_resize(
rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1);
l--;
}
rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1);
l--;
}
+#ifndef HAVE_MMAP
buffer = DNAN;
l = rrdnew.stat_head->ds_cnt * modify;
while (l > 0) {
rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1);
l--;
}
buffer = DNAN;
l = rrdnew.stat_head->ds_cnt * modify;
while (l > 0) {
rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1);
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. */
+#endif
} else {
/* Removing rows. Normally this would be just after the cursor
** however this may also mean that we wrap to the beginning of
} else {
/* Removing rows. Normally this would be just after the cursor
** however this may also mean that we wrap to the beginning of
@@
-231,8
+240,11
@@
int rrd_resize(
rrd_write(rrd_out_file, rrdnew.rra_ptr,
sizeof(rra_ptr_t) * rrdnew.stat_head->rra_cnt);
rrd_write(rrd_out_file, rrdnew.rra_ptr,
sizeof(rra_ptr_t) * rrdnew.stat_head->rra_cnt);
- close(rrd_out_file->fd);
rrd_free(&rrdold);
rrd_free(&rrdold);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
+
+ rrd_free(&rrdnew);
+ rrd_close(rrd_out_file);
+
return (0);
}
return (0);
}