dovecot-2.0: mdbox: Added mdbox_preallocate_space setting to pre...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 20 19:51:16 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/b884441a713f
changeset: 12320:b884441a713f
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Oct 20 17:51:07 2010 +0100
description:
mdbox: Added mdbox_preallocate_space setting to preallocate size for newly created files.

diffstat:

 doc/example-config/conf.d/10-mail.conf            |   5 ++
 src/lib-storage/index/dbox-multi/mdbox-file.c     |  37 +++++++++++++++---
 src/lib-storage/index/dbox-multi/mdbox-settings.c |   2 +
 src/lib-storage/index/dbox-multi/mdbox-settings.h |   1 +
 src/lib-storage/index/dbox-multi/mdbox-storage.c  |   1 +
 src/lib-storage/index/dbox-multi/mdbox-storage.h  |   1 +
 6 files changed, 41 insertions(+), 6 deletions(-)

diffs (128 lines):

diff -r 22c81f884032 -r b884441a713f doc/example-config/conf.d/10-mail.conf
--- 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
diff -r 22c81f884032 -r b884441a713f src/lib-storage/index/dbox-multi/mdbox-file.c
--- 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);
-	return file->fd == -1 ? -1 : 0;
+	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;
+
+	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;
 }
 
diff -r 22c81f884032 -r b884441a713f src/lib-storage/index/dbox-multi/mdbox-settings.c
--- 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
 };
diff -r 22c81f884032 -r b884441a713f src/lib-storage/index/dbox-multi/mdbox-settings.h
--- 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;
 };
diff -r 22c81f884032 -r b884441a713f src/lib-storage/index/dbox-multi/mdbox-storage.c
--- 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";
diff -r 22c81f884032 -r b884441a713f src/lib-storage/index/dbox-multi/mdbox-storage.h
--- 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 {


More information about the dovecot-cvs mailing list