From: Tobias Oetiker Date: Thu, 31 Oct 2013 08:47:55 +0000 (+0100) Subject: properly detect failing fallocate and fall back to seeking X-Git-Tag: v1.4.9~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2244ccab4769fd66c40e704ae49e7e55d56d185;p=thirdparty%2Frrdtool-1.x.git properly detect failing fallocate and fall back to seeking --- diff --git a/src/rrd_open.c b/src/rrd_open.c index d9946420..951225cc 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -222,20 +222,19 @@ rrd_file_t *rrd_open( } else { rrd_file->file_len = newfile_size; #ifdef HAVE_POSIX_FALLOCATE - if (posix_fallocate(rrd_simple_file->fd, 0, newfile_size) == -1) { - rrd_set_error("posix_fallocate '%s': %s", file_name, - rrd_strerror(errno)); - goto out_close; + if (posix_fallocate(rrd_simple_file->fd, 0, newfile_size) == 0){ + /* if all is well we skip the seeking below */ + goto no_lseek_necessary; } -#else +#endif lseek(rrd_simple_file->fd, newfile_size - 1, SEEK_SET); if ( write(rrd_simple_file->fd, "\0", 1) == -1){ /* poke */ rrd_set_error("write '%s': %s", file_name, rrd_strerror(errno)); goto out_close; } lseek(rrd_simple_file->fd, 0, SEEK_SET); -#endif } + no_lseek_necessary: #ifdef HAVE_POSIX_FADVISE /* In general we need no read-ahead when dealing with rrd_files. When we stop reading, it is highly unlikely that we start up again.