Mercurial > dovecot > core-2.2
changeset 12320:b884441a713f
mdbox: Added mdbox_preallocate_space setting to preallocate size for newly created files.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 20 Oct 2010 17:51:07 +0100 |
parents | 22c81f884032 |
children | 90fb346baeb2 |
files | doc/example-config/conf.d/10-mail.conf src/lib-storage/index/dbox-multi/mdbox-file.c src/lib-storage/index/dbox-multi/mdbox-settings.c src/lib-storage/index/dbox-multi/mdbox-settings.h src/lib-storage/index/dbox-multi/mdbox-storage.c src/lib-storage/index/dbox-multi/mdbox-storage.h |
diffstat | 6 files changed, 41 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/example-config/conf.d/10-mail.conf Wed Oct 20 17:50:03 2010 +0100 +++ b/doc/example-config/conf.d/10-mail.conf Wed Oct 20 17:51:07 2010 +0100 @@ -310,3 +310,8 @@ # Maximum dbox file age until it's rotated. Typically in days. Day begins # from midnight, so 1d = today, 2d = yesterday, etc. 0 = check disabled. #mdbox_rotate_interval = 1d + +# When creating new mdbox files, immediately preallocate their size to +# mdbox_rotate_size. This setting currently works only in Linux with some +# filesystems (ext4, xfs). +#mdbox_preallocate_space = no
--- a/src/lib-storage/index/dbox-multi/mdbox-file.c Wed Oct 20 17:50:03 2010 +0100 +++ b/src/lib-storage/index/dbox-multi/mdbox-file.c Wed Oct 20 17:51:07 2010 +0100 @@ -9,6 +9,7 @@ #include "istream.h" #include "ostream.h" #include "file-lock.h" +#include "file-set-size.h" #include "mkdir-parents.h" #include "fdatasync-path.h" #include "eacces-error.h" @@ -97,14 +98,38 @@ file->file.cur_path = file->file.primary_path; } -static int mdbox_file_create(struct dbox_file *file) +static int mdbox_file_create(struct mdbox_file *file) { + struct dbox_file *_file = &file->file; bool create_parents; + int ret; + + create_parents = dbox_file_is_in_alt(_file); + _file->fd = _file->storage->v. + file_create_fd(_file, _file->cur_path, create_parents); + if (_file->fd == -1) + return -1; - create_parents = dbox_file_is_in_alt(file); - file->fd = file->storage->v. - file_create_fd(file, file->cur_path, create_parents); - return file->fd == -1 ? -1 : 0; + if (file->storage->preallocate_space) { + ret = file_preallocate(_file->fd, + file->storage->set->mdbox_rotate_size); + if (ret < 0) { + switch (errno) { + case ENOSPC: + case EDQUOT: + /* ignore */ + break; + default: + i_error("file_preallocate(%s) failed: %m", + _file->cur_path); + break; + } + } else if (ret == 0) { + /* not supported by filesystem, disable. */ + file->storage->preallocate_space = FALSE; + } + } + return 0; } static struct dbox_file * @@ -142,7 +167,7 @@ if (file_id != 0) array_append(&storage->open_files, &file, 1); else - (void)mdbox_file_create(&file->file); + (void)mdbox_file_create(file); return &file->file; }
--- a/src/lib-storage/index/dbox-multi/mdbox-settings.c Wed Oct 20 17:50:03 2010 +0100 +++ b/src/lib-storage/index/dbox-multi/mdbox-settings.c Wed Oct 20 17:51:07 2010 +0100 @@ -12,6 +12,7 @@ { type, #name, offsetof(struct mdbox_settings, name), NULL } static const struct setting_define mdbox_setting_defines[] = { + DEF(SET_BOOL, mdbox_preallocate_space), DEF(SET_SIZE, mdbox_rotate_size), DEF(SET_TIME, mdbox_rotate_interval), @@ -19,6 +20,7 @@ }; static const struct mdbox_settings mdbox_default_settings = { + .mdbox_preallocate_space = FALSE, .mdbox_rotate_size = 2*1024*1024, .mdbox_rotate_interval = 0 };
--- a/src/lib-storage/index/dbox-multi/mdbox-settings.h Wed Oct 20 17:50:03 2010 +0100 +++ b/src/lib-storage/index/dbox-multi/mdbox-settings.h Wed Oct 20 17:51:07 2010 +0100 @@ -2,6 +2,7 @@ #define MDBOX_SETTINGS_H struct mdbox_settings { + bool mdbox_preallocate_space; uoff_t mdbox_rotate_size; unsigned int mdbox_rotate_interval; };
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Wed Oct 20 17:50:03 2010 +0100 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Wed Oct 20 17:51:07 2010 +0100 @@ -42,6 +42,7 @@ const char *dir; storage->set = mail_storage_get_driver_settings(_storage); + storage->preallocate_space = storage->set->mdbox_preallocate_space; if (*ns->list->set.mailbox_dir_name == '\0') { *error_r = "mdbox: MAILBOXDIR must not be empty";
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.h Wed Oct 20 17:50:03 2010 +0100 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h Wed Oct 20 17:51:07 2010 +0100 @@ -39,6 +39,7 @@ unsigned int corrupted:1; unsigned int rebuilding_storage:1; + unsigned int preallocate_space:1; }; struct mdbox_mail_index_record {