diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-12-14 19:34:50 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-12-14 19:34:50 +0300 |
commit | 44311f4235463a8d4d3c4128242bbd7c9d2a203b (patch) | |
tree | 61cf649234696840338a76e6c83a8d5b8f45460f /src | |
parent | 4499fc92189905fde71139822d784ab7819b181c (diff) | |
download | rspamd-44311f4235463a8d4d3c4128242bbd7c9d2a203b.tar.gz rspamd-44311f4235463a8d4d3c4128242bbd7c9d2a203b.zip |
Detect and use fallocate/posix_fallocate.
Diffstat (limited to 'src')
-rw-r--r-- | src/kvstorage_file.c | 1 | ||||
-rw-r--r-- | src/statfile.c | 2 | ||||
-rw-r--r-- | src/util.c | 13 | ||||
-rw-r--r-- | src/util.h | 9 |
4 files changed, 25 insertions, 0 deletions
diff --git a/src/kvstorage_file.c b/src/kvstorage_file.c index 154ccf279..73e5a8a88 100644 --- a/src/kvstorage_file.c +++ b/src/kvstorage_file.c @@ -142,6 +142,7 @@ file_open_fd (const gchar *path, gsize *len, gint flags) if ((flags & O_CREAT) != 0) { /* Open file */ if ((fd = open (path, flags, S_IRUSR|S_IWUSR|S_IRGRP)) != -1) { + rspamd_fallocate (fd, 0, *len); #ifdef HAVE_FADVISE posix_fadvise (fd, 0, *len, POSIX_FADV_SEQUENTIAL); #endif diff --git a/src/statfile.c b/src/statfile.c index d9d42d983..b5b06419e 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -465,6 +465,8 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) return -1; } + rspamd_fallocate (fd, 0, sizeof (header) + sizeof (section) + sizeof (block) * nblocks); + header.create_time = (guint64) time (NULL); if (write (fd, &header, sizeof (header)) == -1) { msg_info ("cannot write header to file %s, error %d, %s", filename, errno, strerror (errno)); diff --git a/src/util.c b/src/util.c index dea3976f1..c5ec0145e 100644 --- a/src/util.c +++ b/src/util.c @@ -1381,6 +1381,19 @@ rspamd_strtoul (const gchar *s, gsize len, gulong *value) return TRUE; } +gint +rspamd_fallocate (gint fd, off_t offset, off_t len) +{ +#if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_KEEP_SIZE) + return fallocate (fd, FALLOC_FL_KEEP_SIZE, offset, len); +#elif defined(HAVE_POSIX_FALLOCATE) + return posix_fallocate (fd, offset, len); +#else + /* Return 0 as nothing can be done on this system */ + return 0; +#endif +} + /* * vi:ts=4 */ diff --git a/src/util.h b/src/util.h index 165b84334..c4fcc80f4 100644 --- a/src/util.h +++ b/src/util.h @@ -241,4 +241,13 @@ gboolean rspamd_strtol (const gchar *s, gsize len, glong *value); */ gboolean rspamd_strtoul (const gchar *s, gsize len, gulong *value); +/** + * Try to allocate a file on filesystem (using fallocate or posix_fallocate) + * @param fd descriptor + * @param offset offset of file + * @param len length to allocate + * @return -1 in case of failure + */ +gint rspamd_fallocate (gint fd, off_t offset, off_t len); + #endif |