]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_storage_lock_create() - add support for dotlocks
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 6 Feb 2018 16:01:04 +0000 (18:01 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 9 Feb 2018 14:09:22 +0000 (16:09 +0200)
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-user.c

index 441b7bc7c6c52cf10ce15a5e6b1f6d982ebdc1fc..a6c0ce2aad501ca2a3b6b50691a6e7d3d474ecfb 100644 (file)
@@ -827,6 +827,7 @@ int mailbox_create_fd(struct mailbox *box, const char *path, int flags,
    -1 and sets error_r on other errors. */
 int mail_storage_lock_create(const char *lock_path,
                             const struct file_create_settings *lock_set,
+                            const struct mail_storage_settings *mail_set,
                             struct file_lock **lock_r, const char **error_r);
 /* Create a lock file to the mailbox with the given filename. Returns the same
    as mail_storage_lock_create(). */
index 7f3c17832539cd2e01455cd1083e8eecd1f346be..b450485bbf34b06515a6dc0b6e49d6f35e3e9ad3 100644 (file)
@@ -9,6 +9,7 @@
 #include "sha1.h"
 #include "unichar.h"
 #include "hex-binary.h"
+#include "file-dotlock.h"
 #include "file-create-locked.h"
 #include "istream.h"
 #include "eacces-error.h"
@@ -2855,12 +2856,42 @@ void mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...)
        va_end(va);
 }
 
+static int
+mail_storage_dotlock_create(const char *lock_path,
+                           const struct file_create_settings *lock_set,
+                           const struct mail_storage_settings *mail_set,
+                           struct file_lock **lock_r, const char **error_r)
+{
+       const struct dotlock_settings dotlock_set = {
+               .timeout = lock_set->lock_timeout_secs,
+               .stale_timeout = I_MAX(60*5, lock_set->lock_timeout_secs),
+               .lock_suffix = "",
+
+               .use_excl_lock = mail_set->dotlock_use_excl,
+               .nfs_flush = mail_set->mail_nfs_storage,
+               .use_io_notify = TRUE,
+       };
+       struct dotlock *dotlock;
+       int ret = file_dotlock_create(&dotlock_set, lock_path, 0, &dotlock);
+       if (ret <= 0) {
+               *error_r = t_strdup_printf("file_dotlock_create(%s) failed: %m",
+                                          lock_path);
+               return ret;
+       }
+       *lock_r = file_lock_from_dotlock(&dotlock);
+       return 1;
+}
+
 int mail_storage_lock_create(const char *lock_path,
                             const struct file_create_settings *lock_set,
+                            const struct mail_storage_settings *mail_set,
                             struct file_lock **lock_r, const char **error_r)
 {
        bool created;
 
+       if (lock_set->lock_method == FILE_LOCK_METHOD_DOTLOCK)
+               return mail_storage_dotlock_create(lock_path, lock_set, mail_set, lock_r, error_r);
+
        if (file_create_locked(lock_path, lock_set, lock_r,
                               &created, error_r) == -1) {
                *error_r = t_strdup_printf("file_create_locked(%s) failed: %s",
@@ -2909,5 +2940,6 @@ int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
                set.mkdir_mode = 0700;
        }
 
-       return mail_storage_lock_create(lock_path, &set, lock_r, error_r);
+       return mail_storage_lock_create(lock_path, &set,
+                                       box->storage->set, lock_r, error_r);
 }
index 69be9638907208725c50f074d4ce60265c057038..efc0dd690151b528d79ec8f8f6006f0ca4e5e245 100644 (file)
@@ -533,7 +533,7 @@ int mail_user_lock_file_create(struct mail_user *user, const char *lock_fname,
                                       lock_fname);
                lock_set.mkdir_mode = 0700;
        }
-       return mail_storage_lock_create(path, &lock_set, lock_r, error_r);
+       return mail_storage_lock_create(path, &lock_set, mail_set, lock_r, error_r);
 }
 
 const char *mail_user_get_anvil_userip_ident(struct mail_user *user)