]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Added mdbox_preallocate_space setting to preallocate size for newly created...
authorTimo Sirainen <tss@iki.fi>
Wed, 20 Oct 2010 16:51:07 +0000 (17:51 +0100)
committerTimo Sirainen <tss@iki.fi>
Wed, 20 Oct 2010 16:51:07 +0000 (17:51 +0100)
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

index b28654a7eb0e466bafd6b820c20e51e90e973c0f..1e9443dd248d35cdf15bb005d8ab9d58e9efc637 100644 (file)
 # 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
index b96a15f21d91d407b6d4ddd7c142130f7db26c2a..745c8672c3d92a5c87c076e5f5862aeb23eab95d 100644 (file)
@@ -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 @@ static void mdbox_file_init_paths(struct mdbox_file *file, const char *fname)
        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 @@ mdbox_file_init_full(struct mdbox_storage *storage,
        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;
 }
 
index 2afb6c087372bf9a6156037a73a24eeb35a66bc0..bb19fe149e5f577b16ee8d78a226467c61d54fbf 100644 (file)
@@ -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 setting_define mdbox_setting_defines[] = {
 };
 
 static const struct mdbox_settings mdbox_default_settings = {
+       .mdbox_preallocate_space = FALSE,
        .mdbox_rotate_size = 2*1024*1024,
        .mdbox_rotate_interval = 0
 };
index 968f03a32ac5c199c22517e2fe1527e670c74441..353da69618643c7f5200e1a3a88b8bd5e0f89bb5 100644 (file)
@@ -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;
 };
index 38fa88c92d865298e4a6f2c19f9a111cdf3ef5d5..94ee4b0888d7c64e6b3cbec2a3b9086c9fa7a0bd 100644 (file)
@@ -42,6 +42,7 @@ mdbox_storage_create(struct mail_storage *_storage, struct mail_namespace *ns,
        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";
index efb854f49151d1e2c4eca8700a3c749766eff6ee..c318a95ac60046ace2f0b7b696161f65be7b1260 100644 (file)
@@ -39,6 +39,7 @@ struct mdbox_storage {
 
        unsigned int corrupted:1;
        unsigned int rebuilding_storage:1;
+       unsigned int preallocate_space:1;
 };
 
 struct mdbox_mail_index_record {