# 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
#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"
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 *
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;
}
{ 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),
};
static const struct mdbox_settings mdbox_default_settings = {
+ .mdbox_preallocate_space = FALSE,
.mdbox_rotate_size = 2*1024*1024,
.mdbox_rotate_interval = 0
};