Re: bus error when disk is full, with mmap & sparse file
Richard Laager <[email protected]> Thu, 02 Feb 2012 01:56:46 -0600
| Newsgroups | gmane.comp.db.rrdtool.devel |
|---|---|
| Message-ID | <1328169406.3572.23.camel__1534.65797561712$1328169426$gmane$org@watermelon.coderich.net> |
The posix_fallocate() version is definitely cleaner. Again, this patch is only lightly tested. Also, I happened to notice a tiny bit of duplicated code, so I've attached a separate patch for that. It seems so obviously duplicated that I've looked at it several times to make sure I'm not missing something. -- Richard _______________________________________________ rrd-developers mailing list [email protected] https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
rrdtool-posix_fallocate.patch
(text/x-patch, 1.8 KB)
Index: src/rrd_open.c
===================================================================
--- src/rrd_open.c (revision 2268)
+++ src/rrd_open.c (working copy)
@@ -222,12 +222,20 @@
rrd_file->file_len = statb.st_size;
} 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;
+ }
+#else
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
}
#ifdef HAVE_POSIX_FADVISE
/* In general we need no read-ahead when dealing with rrd_files.
@@ -248,6 +256,7 @@
*/
#ifdef HAVE_MMAP
+#ifndef HAVE_POSIX_FALLOCATE
/* force allocating the file on the underlaying filesystem to prevent any
* future bus error when the filesystem is full and attempting to write
* trough the file mapping. Filling the file using memset on the file
@@ -279,6 +288,7 @@
lseek(rrd_simple_file->fd, 0, SEEK_SET);
}
+#endif
data = mmap(0, rrd_file->file_len,
rrd_simple_file->mm_prot, rrd_simple_file->mm_flags,
Index: configure.ac
===================================================================
--- configure.ac (revision 2268)
+++ configure.ac (working copy)
@@ -281,6 +281,9 @@
#include <fcntl.h>])
AC_CHECK_FUNCS(posix_fadvise)
+dnl can we use posix_fallocate
+AC_CHECK_FUNCS(posix_fallocate)
+
CONFIGURE_PART(Libintl Processing)
AM_GNU_GETTEXT_VERSION(0.17)
rrdtool-open-remove-duplicate-code.patch
(text/x-patch, 385 B)
Index: src/rrd_open.c
===================================================================
--- src/rrd_open.c (revision 2268)
+++ src/rrd_open.c (working copy)
@@ -291,9 +291,6 @@
goto out_close;
}
rrd_simple_file->file_start = data;
- if (rdwr & RRD_CREAT) {
- goto out_done;
- }
#endif
if (rdwr & RRD_CREAT)
goto out_done;
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk8qQbkACgkQbfU6uV4fG852RQCdFVFbaV4UWkqpE6VazLkxRMXt S7wAoMfrMyeL9Z9oCXYRyP4ibPKVCYA6 =1HuH -----END PGP SIGNATURE-----