Mercurial > dovecot > core-2.2
changeset 22281:c8f9cfc29195
lib-storage: Add VOLATILEDIR setting to mail_location
This is useful for creating temporary locks that could exist in tmpfs.
Currently this is used for .vsize.lock and dovecot.autoexpunge.lock.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 22 Jun 2017 01:28:57 +0300 |
parents | 46597cee3f43 |
children | 6ea40be7e586 |
files | src/lib-storage/mail-storage.c src/lib-storage/mail-user.c src/lib-storage/mailbox-list.c src/lib-storage/mailbox-list.h |
diffstat | 4 files changed, 42 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c Thu Jun 22 02:44:12 2017 +0300 +++ b/src/lib-storage/mail-storage.c Thu Jun 22 01:28:57 2017 +0300 @@ -6,7 +6,9 @@ #include "llist.h" #include "str.h" #include "str-sanitize.h" +#include "sha1.h" #include "unichar.h" +#include "hex-binary.h" #include "file-create-locked.h" #include "istream.h" #include "eacces-error.h" @@ -2782,7 +2784,26 @@ set.gid = perm->file_create_gid; set.gid_origin = perm->file_create_gid_origin; - lock_path = t_strdup_printf("%s/%s", box->index->dir, lock_fname); + if (box->list->set.volatile_dir == NULL) + lock_path = t_strdup_printf("%s/%s", box->index->dir, lock_fname); + else { + unsigned char box_name_sha1[SHA1_RESULTLEN]; + string_t *str = t_str_new(128); + + /* Keep this simple: Use the lock_fname with a SHA1 of the + mailbox name as the suffix. The mailbox name itself could + be too large as a filename and creating the full directory + structure would be pretty troublesome. It would also make + it more difficult to perform the automated deletion of empty + lock directories. */ + str_printfa(str, "%s/%s.", box->list->set.volatile_dir, + lock_fname); + sha1_get_digest(box->name, strlen(box->name), box_name_sha1); + binary_to_hex_append(str, box_name_sha1, sizeof(box_name_sha1)); + lock_path = str_c(str); + set.mkdir_mode = 0700; + } + if (file_create_locked(lock_path, &set, lock_r, &created, error_r) == -1) { *error_r = t_strdup_printf("file_create_locked(%s) failed: %s", lock_path, *error_r);
--- a/src/lib-storage/mail-user.c Thu Jun 22 02:44:12 2017 +0300 +++ b/src/lib-storage/mail-user.c Thu Jun 22 01:28:57 2017 +0300 @@ -23,6 +23,7 @@ #include "mail-storage-service.h" #include "mail-namespace.h" #include "mail-storage.h" +#include "mailbox-list-private.h" #include "mail-autoexpunge.h" #include "mail-user.h" @@ -523,7 +524,16 @@ .lock_timeout_secs = lock_secs, .lock_method = mail_set->parsed_lock_method, }; - path = t_strdup_printf("%s/%s", home, lock_fname); + struct mailbox_list *inbox_list = + mail_namespace_find_inbox(user->namespaces)->list; + if (inbox_list->set.volatile_dir == NULL) + path = t_strdup_printf("%s/%s", home, lock_fname); + else { + path = t_strdup_printf("%s/%s", inbox_list->set.volatile_dir, + lock_fname); + lock_set.mkdir_mode = 0700; + } + if (file_create_locked(path, &lock_set, lock_r, &created, &error) == -1) { *error_r = t_strdup_printf("file_create_locked(%s) failed: %s", path, error); return errno == EAGAIN ? 0 : -1;
--- a/src/lib-storage/mailbox-list.c Thu Jun 22 02:44:12 2017 +0300 +++ b/src/lib-storage/mailbox-list.c Thu Jun 22 01:28:57 2017 +0300 @@ -4,6 +4,7 @@ #include "array.h" #include "abspath.h" #include "ioloop.h" +#include "file-create-locked.h" #include "mkdir-parents.h" #include "str.h" #include "sha1.h" @@ -171,6 +172,7 @@ p_strdup(list->pool, set->mailbox_dir_name); list->set.alt_dir = p_strdup(list->pool, set->alt_dir); list->set.alt_dir_nocheck = set->alt_dir_nocheck; + list->set.volatile_dir = p_strdup(list->pool, set->volatile_dir); list->set.index_control_use_maildir_name = set->index_control_use_maildir_name; @@ -336,6 +338,8 @@ dest = &set_r->maildir_name; else if (strcmp(key, "MAILBOXDIR") == 0) dest = &set_r->mailbox_dir_name; + else if (strcmp(key, "VOLATILEDIR") == 0) + dest = &set_r->volatile_dir; else if (strcmp(key, "LISTINDEX") == 0) dest = &set_r->list_index_fname; else if (strcmp(key, "FULLDIRNAME") == 0) {
--- a/src/lib-storage/mailbox-list.h Thu Jun 22 02:44:12 2017 +0300 +++ b/src/lib-storage/mailbox-list.h Thu Jun 22 01:28:57 2017 +0300 @@ -98,6 +98,11 @@ const char *index_pvt_dir; const char *control_dir; const char *alt_dir; /* FIXME: dbox-specific.. */ + /* Backend-local directory where volatile data, such as lock files, + can be temporarily created. This setting allows specifying a + separate directory for them to reduce disk I/O on the real storage. + The volatile_dir can point to an in-memory filesystem. */ + const char *volatile_dir; const char *inbox_path; const char *subscription_fname;