dovecot-2.0: Added mail_max_lock_timeout setting.

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 23 19:52:19 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/c3ee4421e86a
changeset: 11623:c3ee4421e86a
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 23 17:52:02 2010 +0100
description:
Added mail_max_lock_timeout setting.
This could be useful inside lda/lmtp protocol sections to avoid them from
spending too much time waiting for locks, since they can easily just
return "try again later".

diffstat:

 src/doveadm/doveadm-dump-index.c                      |   6 ++----
 src/lib-index/mail-cache.c                            |   9 +++++++--
 src/lib-index/mail-index-lock.c                       |   6 ++++--
 src/lib-index/mail-index-private.h                    |   1 +
 src/lib-index/mail-index-strmap.c                     |   6 ++++--
 src/lib-index/mail-index.c                            |  19 +++++++++++++------
 src/lib-index/mail-index.h                            |  10 ++++++----
 src/lib-index/mail-transaction-log-file.c             |   5 ++++-
 src/lib-index/mail-transaction-log.c                  |   4 +++-
 src/lib-storage/index/dbox-common/dbox-sync-rebuild.c |   5 +++--
 src/lib-storage/index/dbox-multi/mdbox-map.c          |   6 ++++--
 src/lib-storage/index/index-storage.c                 |  10 +++++-----
 src/lib-storage/index/maildir/maildir-keywords.c      |   4 +++-
 src/lib-storage/index/maildir/maildir-uidlist.c       |   3 ++-
 src/lib-storage/index/mbox/mbox-lock.c                |   7 +++++--
 src/lib-storage/list/index-mailbox-list.c             |   9 ++++-----
 src/lib-storage/mail-storage-private.h                |   2 ++
 src/lib-storage/mail-storage-settings.c               |   2 ++
 src/lib-storage/mail-storage-settings.h               |   1 +
 src/lib-storage/mail-storage.c                        |   7 +++++++
 20 files changed, 82 insertions(+), 40 deletions(-)

diffs (truncated from 446 to 300 lines):

diff -r 182d1834f643 -r c3ee4421e86a src/doveadm/doveadm-dump-index.c
--- a/src/doveadm/doveadm-dump-index.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/doveadm/doveadm-dump-index.c	Wed Jun 23 17:52:02 2010 +0100
@@ -533,8 +533,7 @@
 
 	index = path_open_index(argv[1]);
 	if (index == NULL ||
-	    mail_index_open(index, MAIL_INDEX_OPEN_FLAG_READONLY,
-			    FILE_LOCK_METHOD_FCNTL) <= 0)
+	    mail_index_open(index, MAIL_INDEX_OPEN_FLAG_READONLY) <= 0)
 		i_fatal("Couldn't open index %s", argv[1]);
 	if (argv[2] != NULL)
 		uid = atoi(argv[2]);
@@ -577,8 +576,7 @@
 	if (index == NULL)
 		return FALSE;
 
-	ret = mail_index_open(index, MAIL_INDEX_OPEN_FLAG_READONLY,
-			      FILE_LOCK_METHOD_FCNTL) > 0;
+	ret = mail_index_open(index, MAIL_INDEX_OPEN_FLAG_READONLY) > 0;
 	if (ret > 0)
 		mail_index_close(index);
 	mail_index_free(&index);
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-cache.c	Wed Jun 23 17:52:02 2010 +0100
@@ -414,7 +414,8 @@
 		(index->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
 	cache->dotlock_settings.nfs_flush =
 		(index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
-	cache->dotlock_settings.timeout = MAIL_CACHE_LOCK_TIMEOUT;
+	cache->dotlock_settings.timeout =
+		I_MIN(MAIL_CACHE_LOCK_TIMEOUT, index->max_lock_timeout_secs);
 	cache->dotlock_settings.stale_timeout = MAIL_CACHE_LOCK_CHANGE_TIMEOUT;
 
 	if (!MAIL_INDEX_IS_IN_MEMORY(index) &&
@@ -488,6 +489,7 @@
 
 static int mail_cache_lock_file(struct mail_cache *cache, bool nonblock)
 {
+	unsigned int timeout_secs;
 	int ret;
 
 	if (cache->last_lock_failed) {
@@ -498,9 +500,12 @@
 
 	if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
 		i_assert(cache->file_lock == NULL);
+		timeout_secs = I_MIN(MAIL_CACHE_LOCK_TIMEOUT,
+				     cache->index->max_lock_timeout_secs);
+
 		ret = mail_index_lock_fd(cache->index, cache->filepath,
 					 cache->fd, F_WRLCK,
-					 nonblock ? 0 : MAIL_CACHE_LOCK_TIMEOUT,
+					 nonblock ? 0 : timeout_secs,
 					 &cache->file_lock);
 	} else {
 		enum dotlock_create_flags flags =
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-index-lock.c
--- a/src/lib-index/mail-index-lock.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-index-lock.c	Wed Jun 23 17:52:02 2010 +0100
@@ -139,10 +139,12 @@
 
 int mail_index_lock_shared(struct mail_index *index, unsigned int *lock_id_r)
 {
+	unsigned int timeout_secs;
 	int ret;
 
-	ret = mail_index_lock(index, F_RDLCK, MAIL_INDEX_SHARED_LOCK_TIMEOUT,
-			      lock_id_r);
+	timeout_secs = I_MIN(MAIL_INDEX_SHARED_LOCK_TIMEOUT,
+			     index->max_lock_timeout_secs);
+	ret = mail_index_lock(index, F_RDLCK, timeout_secs, lock_id_r);
 	if (ret > 0) {
 		mail_index_flush_read_cache(index, index->filepath,
 					    index->fd, TRUE);
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-index-private.h	Wed Jun 23 17:52:02 2010 +0100
@@ -208,6 +208,7 @@
 	int lock_type, shared_lock_count, excl_lock_count;
 	unsigned int lock_id_counter;
 	enum file_lock_method lock_method;
+	unsigned int max_lock_timeout_secs;
 
 	struct file_lock *file_lock;
 	struct dotlock *dotlock;
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-index-strmap.c
--- a/src/lib-index/mail-index-strmap.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-index-strmap.c	Wed Jun 23 17:52:02 2010 +0100
@@ -1041,6 +1041,7 @@
 
 static int mail_index_strmap_lock(struct mail_index_strmap *strmap)
 {
+	unsigned int timeout_secs;
 	int ret;
 
 	i_assert(strmap->fd != -1);
@@ -1048,9 +1049,10 @@
 	if (strmap->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
 		i_assert(strmap->file_lock == NULL);
 
+		timeout_secs = I_MIN(MAIL_INDEX_STRMAP_TIMEOUT_SECS,
+				     strmap->index->max_lock_timeout_secs);
 		ret = file_wait_lock(strmap->fd, strmap->path, F_WRLCK,
-				     strmap->index->lock_method,
-				     MAIL_INDEX_STRMAP_TIMEOUT_SECS,
+				     strmap->index->lock_method, timeout_secs,
 				     &strmap->file_lock);
 		if (ret <= 0) {
 			mail_index_strmap_set_syscall_error(strmap,
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-index.c	Wed Jun 23 17:52:02 2010 +0100
@@ -44,6 +44,8 @@
 
 	index->mode = 0600;
 	index->gid = (gid_t)-1;
+	index->lock_method = FILE_LOCK_METHOD_FCNTL;
+	index->max_lock_timeout_secs = -1U;
 
 	index->keywords_ext_id =
 		mail_index_ext_register(index, MAIL_INDEX_EXT_KEYWORDS,
@@ -98,6 +100,14 @@
 	index->gid_origin = i_strdup(gid_origin);
 }
 
+void mail_index_set_lock_method(struct mail_index *index,
+				enum file_lock_method lock_method,
+				unsigned int max_timeout_secs)
+{
+	index->lock_method = lock_method;
+	index->max_lock_timeout_secs = max_timeout_secs;
+}
+
 uint32_t mail_index_ext_register(struct mail_index *index, const char *name,
 				 uint32_t default_hdr_size,
 				 uint16_t default_record_size,
@@ -482,8 +492,7 @@
 	return 1;
 }
 
-int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
-		    enum file_lock_method lock_method)
+int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags)
 {
 	int ret;
 
@@ -508,7 +517,6 @@
 	index->log_locked = FALSE;
 	index->flags = flags;
 	index->readonly = (flags & MAIL_INDEX_OPEN_FLAG_READONLY) != 0;
-	index->lock_method = lock_method;
 
 	if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 &&
 	    (flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) != 0)
@@ -530,13 +538,12 @@
 }
 
 int mail_index_open_or_create(struct mail_index *index,
-			      enum mail_index_open_flags flags,
-			      enum file_lock_method lock_method)
+			      enum mail_index_open_flags flags)
 {
 	int ret;
 
 	flags |= MAIL_INDEX_OPEN_FLAG_CREATE;
-	ret = mail_index_open(index, flags, lock_method);
+	ret = mail_index_open(index, flags);
 	i_assert(ret != 0);
 	return ret < 0 ? -1 : 0;
 }
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-index.h	Wed Jun 23 17:52:02 2010 +0100
@@ -213,15 +213,17 @@
 				enum mail_index_sync_type fsync_mask);
 void mail_index_set_permissions(struct mail_index *index,
 				mode_t mode, gid_t gid, const char *gid_origin);
+/* Set locking method and maximum time to wait for a lock (-1U = default). */
+void mail_index_set_lock_method(struct mail_index *index,
+				enum file_lock_method lock_method,
+				unsigned int max_timeout_secs);
 
 /* Open index. Returns 1 if ok, 0 if index doesn't exist and CREATE flags
    wasn't given, -1 if error. */
-int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
-		    enum file_lock_method lock_method);
+int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags);
 /* Open or create index. Returns 0 if ok, -1 if error. */
 int mail_index_open_or_create(struct mail_index *index,
-			      enum mail_index_open_flags flags,
-			      enum file_lock_method lock_method);
+			      enum mail_index_open_flags flags);
 void mail_index_close(struct mail_index *index);
 /* unlink() all the index files. */
 int mail_index_unlink(struct mail_index *index);
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-transaction-log-file.c	Wed Jun 23 17:52:02 2010 +0100
@@ -320,6 +320,7 @@
 
 int mail_transaction_log_file_lock(struct mail_transaction_log_file *file)
 {
+	unsigned int lock_timeout_secs;
 	int ret;
 
 	if (file->locked)
@@ -334,8 +335,10 @@
 		return mail_transaction_log_file_dotlock(file);
 
 	i_assert(file->file_lock == NULL);
+	lock_timeout_secs = I_MIN(MAIL_TRANSCATION_LOG_LOCK_TIMEOUT,
+				  file->log->index->max_lock_timeout_secs);
 	ret = mail_index_lock_fd(file->log->index, file->filepath, file->fd,
-				 F_WRLCK, MAIL_TRANSCATION_LOG_LOCK_TIMEOUT,
+				 F_WRLCK, lock_timeout_secs,
 				 &file->file_lock);
 	if (ret > 0) {
 		file->locked = TRUE;
diff -r 182d1834f643 -r c3ee4421e86a src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-index/mail-transaction-log.c	Wed Jun 23 17:52:02 2010 +0100
@@ -37,7 +37,9 @@
 	log = i_new(struct mail_transaction_log, 1);
 	log->index = index;
 
-	log->dotlock_settings.timeout = MAIL_TRANSCATION_LOG_LOCK_TIMEOUT;
+	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;
 
diff -r 182d1834f643 -r c3ee4421e86a src/lib-storage/index/dbox-common/dbox-sync-rebuild.c
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c	Wed Jun 23 17:52:02 2010 +0100
@@ -168,8 +168,9 @@
 	if (box->storage->set->mmap_disable)
 #endif
 		open_flags |= MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE;
-	if (mail_index_open(ctx->backup_index, open_flags,
-			    box->storage->set->parsed_lock_method) <= 0)
+	mail_index_set_lock_method(ctx->backup_index,
+				   box->storage->set->parsed_lock_method, -1U);
+	if (mail_index_open(ctx->backup_index, open_flags) <= 0)
 		mail_index_free(&ctx->backup_index);
 	else
 		ctx->backup_view = mail_index_view_open(ctx->backup_index);
diff -r 182d1834f643 -r c3ee4421e86a src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Wed Jun 23 17:52:02 2010 +0100
@@ -57,6 +57,9 @@
 	map->set = storage->set;
 	map->path = i_strdup(path);
 	map->index = mail_index_alloc(path, MDBOX_GLOBAL_INDEX_PREFIX);
+	mail_index_set_lock_method(map->index,
+		MAP_STORAGE(map)->set->parsed_lock_method,
+		mail_storage_get_lock_timeout(MAP_STORAGE(map), -1U));
 	map->root_list = root_list;
 	map->map_ext_id = mail_index_ext_register(map->index, "map",
 				sizeof(struct mdbox_map_mail_index_header),
@@ -137,8 +140,7 @@
 		if (mdbox_map_mkdir_storage(map) < 0)
 			return -1;
 	}
-	ret = mail_index_open(map->index, open_flags,
-			      MAP_STORAGE(map)->set->parsed_lock_method);
+	ret = mail_index_open(map->index, open_flags);
 	if (ret < 0) {
 		mail_storage_set_internal_error(MAP_STORAGE(map));
 		mail_index_reset_error(map->index);
diff -r 182d1834f643 -r c3ee4421e86a src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Wed Jun 23 16:58:18 2010 +0100
+++ b/src/lib-storage/index/index-storage.c	Wed Jun 23 17:52:02 2010 +0100
@@ -187,8 +187,6 @@
 int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory)
 {
 	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
-	enum file_lock_method lock_method =
-		box->storage->set->parsed_lock_method;
 	enum mail_index_open_flags index_flags;
 	int ret;
 
@@ -211,7 +209,7 @@
 		return -1;
 	}
 
-	ret = mail_index_open(box->index, index_flags, lock_method);
+	ret = mail_index_open(box->index, index_flags);
 	if (ret <= 0 || move_to_memory) {
 		if ((index_flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0) {
 			i_assert(ret <= 0);
@@ -223,8 +221,7 @@
 			/* try opening once more. it should be created
 			   directly into memory now. */
 			if (mail_index_open_or_create(box->index,
-						      index_flags,
-						      lock_method) < 0)
+						      index_flags) < 0)


More information about the dovecot-cvs mailing list