]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Lock timeout setting wasn't actually used in all places.
authorTimo Sirainen <tss@iki.fi>
Thu, 2 Sep 2010 16:46:55 +0000 (17:46 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 2 Sep 2010 16:46:55 +0000 (17:46 +0100)
src/lib-index/mail-index-lock.c
src/lib-index/mail-transaction-log-file.c
src/lib-index/mail-transaction-log-private.h
src/lib-index/mail-transaction-log.c

index ddec2e5ee21055eb3e36283e9097ef2e4478a1e2..dc577db81095b74f647cd426264da7f5c48f77a4 100644 (file)
@@ -154,8 +154,8 @@ int mail_index_lock_shared(struct mail_index *index, unsigned int *lock_id_r)
                return -1;
 
        mail_index_set_error(index,
-               "Timeout while waiting for shared lock for index file %s",
-               index->filepath);
+               "Timeout (%us) while waiting for shared lock for index file %s",
+               timeout_secs, index->filepath);
        index->index_lock_timeout = TRUE;
        return -1;
 }
index 4d0f4a1bb7de4a5693c276d5b3b0a38e7499094a..d195ccda67df26373f9b3db9a57f550125dd1f92 100644 (file)
@@ -14,6 +14,7 @@
 
 #define LOG_PREFETCH IO_BLOCK_SIZE
 #define MEMORY_LOG_NAME "(in-memory transaction log file)"
+#define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
 
 static int
 log_file_set_syscall_error(struct mail_transaction_log_file *file,
@@ -268,13 +269,14 @@ mail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log)
 static int
 mail_transaction_log_file_dotlock(struct mail_transaction_log_file *file)
 {
+       struct dotlock_settings dotlock_set;
        int ret;
 
        if (file->log->dotlock_count > 0)
                ret = 1;
        else {
-               ret = file_dotlock_create(&file->log->dotlock_settings,
-                                         file->filepath, 0,
+               mail_transaction_log_get_dotlock_set(file->log, &dotlock_set);
+               ret = file_dotlock_create(&dotlock_set, file->filepath, 0,
                                          &file->log->dotlock);
        }
        if (ret > 0) {
@@ -288,9 +290,9 @@ mail_transaction_log_file_dotlock(struct mail_transaction_log_file *file)
        }
 
        mail_index_set_error(file->log->index,
-                            "Timeout while waiting for "
+                            "Timeout (%us) while waiting for "
                             "dotlock for transaction log file %s",
-                            file->filepath);
+                            dotlock_set.timeout, file->filepath);
        file->log->index->index_lock_timeout = TRUE;
        return -1;
 }
@@ -350,8 +352,9 @@ int mail_transaction_log_file_lock(struct mail_transaction_log_file *file)
        }
 
        mail_index_set_error(file->log->index,
-               "Timeout while waiting for lock for transaction log file %s",
-               file->filepath);
+               "Timeout (%us) while waiting for lock for "
+               "transaction log file %s",
+               lock_timeout_secs, file->filepath);
        file->log->index->index_lock_timeout = TRUE;
        return -1;
 }
@@ -671,6 +674,7 @@ int mail_transaction_log_file_create(struct mail_transaction_log_file *file,
                                     bool reset)
 {
        struct mail_index *index = file->log->index;
+       struct dotlock_settings new_dotlock_set;
        struct dotlock *dotlock;
        mode_t old_mask;
        int fd;
@@ -684,11 +688,13 @@ int mail_transaction_log_file_create(struct mail_transaction_log_file *file,
                return -1;
        }
 
+       mail_transaction_log_get_dotlock_set(file->log, &new_dotlock_set);
+       new_dotlock_set.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
+
        /* With dotlocking we might already have path.lock created, so this
           filename has to be different. */
        old_mask = umask(index->mode ^ 0666);
-       fd = file_dotlock_open(&file->log->new_dotlock_settings,
-                              file->filepath, 0, &dotlock);
+       fd = file_dotlock_open(&new_dotlock_set, file->filepath, 0, &dotlock);
        umask(old_mask);
 
        if (fd == -1)
index cf6285469607c364b05206d70e06ec0ebe4ca0a8..09dae1b6e0b290a42602387c372c1a923a6288c0 100644 (file)
@@ -2,9 +2,10 @@
 #define MAIL_TRANSACTION_LOG_VIEW_H
 
 #include "buffer.h"
-#include "file-dotlock.h"
 #include "mail-transaction-log.h"
 
+struct dotlock_settings;
+
 /* Synchronization can take a while sometimes, especially when copying lots of
    mails. */
 #define MAIL_TRANSCATION_LOG_LOCK_TIMEOUT (3*60)
@@ -91,7 +92,6 @@ struct mail_transaction_log {
        struct mail_transaction_log_file *open_file;
 
        unsigned int dotlock_count;
-        struct dotlock_settings dotlock_settings, new_dotlock_settings;
        struct dotlock *dotlock;
 
        unsigned int nfs_flush:1;
@@ -102,6 +102,9 @@ mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
                                        const char *fmt, ...)
        ATTR_FORMAT(2, 3);
 
+void mail_transaction_log_get_dotlock_set(struct mail_transaction_log *log,
+                                         struct dotlock_settings *set_r);
+
 struct mail_transaction_log_file *
 mail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
 struct mail_transaction_log_file *
index 266857d6df5ebd3cb71bf3dd58f3ba4b5f36e86b..72055299dc052c82cd67970aa0ba8cfe45218c80 100644 (file)
@@ -14,8 +14,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 
-#define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
-
 static void
 mail_transaction_log_set_head(struct mail_transaction_log *log,
                              struct mail_transaction_log_file *file)
@@ -36,15 +34,6 @@ mail_transaction_log_alloc(struct mail_index *index)
 
        log = i_new(struct mail_transaction_log, 1);
        log->index = index;
-
-       log->dotlock_settings.timeout =
-               I_MIN(MAIL_TRANSCATION_LOG_LOCK_TIMEOUT,
-                     index->max_lock_timeout_secs);;
-       log->dotlock_settings.stale_timeout =
-               MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT;
-
-       log->new_dotlock_settings = log->dotlock_settings;
-       log->new_dotlock_settings.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
        return log;
 }
 
@@ -84,12 +73,6 @@ int mail_transaction_log_open(struct mail_transaction_log *log)
           set them here: */
        log->nfs_flush =
                (log->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
-       log->dotlock_settings.use_excl_lock =
-               log->dotlock_settings.nfs_flush =
-               (log->index->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
-       log->dotlock_settings.nfs_flush =
-               log->new_dotlock_settings.nfs_flush =
-               log->nfs_flush;
 
        if (log->open_file != NULL)
                mail_transaction_log_file_free(&log->open_file);
@@ -536,3 +519,17 @@ int mail_transaction_log_get_mtime(struct mail_transaction_log *log,
        *mtime_r = st.st_mtime;
        return 0;
 }
+
+void mail_transaction_log_get_dotlock_set(struct mail_transaction_log *log,
+                                         struct dotlock_settings *set_r)
+{
+       struct mail_index *index = log->index;
+
+       memset(set_r, 0, sizeof(*set_r));
+       set_r->timeout = I_MIN(MAIL_TRANSCATION_LOG_LOCK_TIMEOUT,
+                              index->max_lock_timeout_secs);
+       set_r->stale_timeout = MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT;
+       set_r->nfs_flush = (index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
+       set_r->use_excl_lock =
+               (index->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
+}