changeset 4969:5c18ac362f65 HEAD

More dotlock_use_excl uses.
author Timo Sirainen <tss@iki.fi>
date Thu, 28 Dec 2006 18:51:10 +0200
parents 1baf9dd3fc40
children d3b8fcc72c69
files src/lib-storage/index/dbox/dbox-storage.c src/lib-storage/index/dbox/dbox-storage.h src/lib-storage/index/dbox/dbox-sync-expunge.c src/lib-storage/index/dbox/dbox-uidlist.c src/lib-storage/index/maildir/maildir-keywords.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/mbox/mbox-lock.c
diffstat 7 files changed, 89 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-storage.c	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/dbox/dbox-storage.c	Thu Dec 28 18:51:10 2006 +0200
@@ -17,6 +17,45 @@
 
 #define CREATE_MODE 0770 /* umask() should limit it more */
 
+const struct dotlock_settings default_uidlist_dotlock_set = {
+	MEMBER(temp_prefix) NULL,
+	MEMBER(lock_suffix) NULL,
+
+	MEMBER(timeout) 120,
+	MEMBER(stale_timeout) 60,
+
+	MEMBER(callback) NULL,
+	MEMBER(context) NULL,
+
+	MEMBER(use_excl_lock) FALSE
+};
+
+const struct dotlock_settings default_file_dotlock_set = {
+	MEMBER(temp_prefix) NULL,
+	MEMBER(lock_suffix) NULL,
+
+	MEMBER(timeout) 120,
+	MEMBER(stale_timeout) 60,
+
+	MEMBER(callback) NULL,
+	MEMBER(context) NULL,
+
+	MEMBER(use_excl_lock) FALSE
+};
+
+static const struct dotlock_settings default_new_file_dotlock_set = {
+	MEMBER(temp_prefix) NULL,
+	MEMBER(lock_suffix) NULL,
+
+	MEMBER(timeout) 60,
+	MEMBER(stale_timeout) 30,
+
+	MEMBER(callback) NULL,
+	MEMBER(context) NULL,
+
+	MEMBER(use_excl_lock) FALSE
+};
+
 extern struct mail_storage dbox_storage;
 extern struct mailbox dbox_mailbox;
 
@@ -125,6 +164,15 @@
 		return NULL;
 	}
 
+	storage->uidlist_dotlock_set = default_uidlist_dotlock_set;
+	storage->file_dotlock_set = default_file_dotlock_set;
+	storage->new_file_dotlock_set = default_new_file_dotlock_set;
+	if ((flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0) {
+		storage->uidlist_dotlock_set.use_excl_lock = TRUE;
+		storage->file_dotlock_set.use_excl_lock = TRUE;
+		storage->new_file_dotlock_set.use_excl_lock = TRUE;
+	}
+
 	istorage = INDEX_STORAGE(storage);
 	istorage->storage = dbox_storage;
 	istorage->storage.pool = pool;
--- a/src/lib-storage/index/dbox/dbox-storage.h	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/dbox/dbox-storage.h	Thu Dec 28 18:51:10 2006 +0200
@@ -14,6 +14,10 @@
 
 struct dbox_storage {
 	struct index_storage storage;
+
+	struct dotlock_settings uidlist_dotlock_set;
+	struct dotlock_settings file_dotlock_set;
+	struct dotlock_settings new_file_dotlock_set;
 };
 
 struct keyword_map {
--- a/src/lib-storage/index/dbox/dbox-sync-expunge.c	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/dbox/dbox-sync-expunge.c	Thu Dec 28 18:51:10 2006 +0200
@@ -14,19 +14,6 @@
 
 #include <stddef.h>
 
-static const struct dotlock_settings new_file_dotlock_set = {
-	MEMBER(temp_prefix) NULL,
-	MEMBER(lock_suffix) NULL,
-
-	MEMBER(timeout) 60,
-	MEMBER(stale_timeout) 30,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
-};
-
 static int
 dbox_sync_rec_get_uids(struct dbox_sync_context *ctx,
 		       const struct dbox_sync_rec *sync_rec,
@@ -77,6 +64,7 @@
 				  uoff_t orig_offset)
 {
 	struct dbox_mailbox *mbox = ctx->mbox;
+	struct mail_storage *storage = STORAGE(mbox->storage);
 	struct dotlock *dotlock;
 	struct istream *input;
 	struct ostream *output;
@@ -108,7 +96,7 @@
 
 	if (ret <= 0) {
 		if (ret == 0) {
-			mail_storage_set_critical(STORAGE(mbox->storage),
+			mail_storage_set_critical(storage,
 				"%s: Expunging lost UID %u from file %u",
 				mbox->path, first_nonexpunged_uid,
 				orig_entry->file_seq);
@@ -131,13 +119,14 @@
 		path = t_strdup_printf("%s/"DBOX_MAILDIR_NAME"/"
 				       DBOX_MAIL_FILE_FORMAT,
 				       mbox->path, file_seq);
-		fd = file_dotlock_open(&new_file_dotlock_set, path,
-				       DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
+		fd = file_dotlock_open(&mbox->storage->new_file_dotlock_set,
+				       path, DOTLOCK_CREATE_FLAG_NONBLOCK,
+				       &dotlock);
 		if (fd >= 0)
 			break;
 
 		if (errno != EAGAIN) {
-			mail_storage_set_critical(STORAGE(mbox->storage),
+			mail_storage_set_critical(storage,
 				"file_dotlock_open(%s) failed: %m", path);
 			return -1;
 		}
@@ -172,7 +161,7 @@
 		}
 
 		if (seq == 0) {
-			mail_storage_set_critical(STORAGE(mbox->storage),
+			mail_storage_set_critical(storage,
 				"Expunged UID %u reappeared in file %s",
 				uid, path);
 			mail_index_mark_corrupted(mbox->ibox.index);
@@ -196,14 +185,14 @@
 		i_stream_destroy(&input);
 
 		if (bytes < 0) {
-			mail_storage_set_critical(STORAGE(mbox->storage),
+			mail_storage_set_critical(storage,
 				"o_stream_send_istream(%s) failed: %m",
 				lock_path);
 			ret = -1;
 			break;
 		}
 		if ((uoff_t)bytes != full_size) {
-			mail_storage_set_critical(STORAGE(mbox->storage),
+			mail_storage_set_critical(storage,
 				"o_stream_send_istream(%s) wrote only %"
 				PRIuUOFF_T" of %"PRIuUOFF_T" bytes", lock_path,
 				(uoff_t)bytes, full_size);
@@ -251,9 +240,8 @@
 				sizeof(hdr.append_offset_hex),
 				offsetof(struct dbox_file_header,
 					 append_offset_hex)) < 0) {
-			mail_storage_set_critical(STORAGE(mbox->storage),
-						  "pwrite_full(%s) failed: %m",
-						  lock_path);
+			mail_storage_set_critical(storage,
+				"pwrite_full(%s) failed: %m", lock_path);
 			ret = -1;
 		}
 	}
@@ -484,8 +472,8 @@
 		path = t_strdup_printf("%s/"DBOX_MAILDIR_NAME"/"
 				       DBOX_MAIL_FILE_FORMAT,
 				       mbox->path, sync_entry->file_seq);
-		ret = file_dotlock_create(&new_file_dotlock_set, path,
-					  DOTLOCK_CREATE_FLAG_NONBLOCK,
+		ret = file_dotlock_create(&mbox->storage->new_file_dotlock_set,
+					  path, DOTLOCK_CREATE_FLAG_NONBLOCK,
 					  &dotlock);
 		if (ret < 0) {
 			mail_storage_set_critical(STORAGE(mbox->storage),
--- a/src/lib-storage/index/dbox/dbox-uidlist.c	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/dbox/dbox-uidlist.c	Thu Dec 28 18:51:10 2006 +0200
@@ -80,32 +80,6 @@
 	unsigned int modified:1;
 };
 
-const struct dotlock_settings uidlist_dotlock_settings = {
-	MEMBER(temp_prefix) NULL,
-	MEMBER(lock_suffix) NULL,
-
-	MEMBER(timeout) 120,
-	MEMBER(stale_timeout) 60,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
-};
-
-const struct dotlock_settings dbox_file_dotlock_set = {
-	MEMBER(temp_prefix) NULL,
-	MEMBER(lock_suffix) NULL,
-
-	MEMBER(timeout) 120,
-	MEMBER(stale_timeout) 60,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
-};
-
 static int dbox_uidlist_full_rewrite(struct dbox_uidlist *uidlist);
 
 struct dbox_uidlist *dbox_uidlist_init(struct dbox_mailbox *mbox)
@@ -451,19 +425,21 @@
 
 int dbox_uidlist_lock(struct dbox_uidlist *uidlist)
 {
+	struct dbox_mailbox *mbox = uidlist->mbox;
+
 	if (uidlist->lock_count == 0)
 		i_assert(uidlist->lock_fd == -1);
 	else {
-		i_assert(uidlist->mbox->ibox.keep_locked);
+		i_assert(mbox->ibox.keep_locked);
 		uidlist->lock_count++;
 		return 0;
 	}
 
-	uidlist->lock_fd = file_dotlock_open(&uidlist_dotlock_settings,
-					     uidlist->path, 0,
-					     &uidlist->dotlock);
+	uidlist->lock_fd =
+		file_dotlock_open(&mbox->storage->uidlist_dotlock_set,
+				  uidlist->path, 0, &uidlist->dotlock);
 	if (uidlist->lock_fd == -1) {
-		mail_storage_set_critical(STORAGE(uidlist->mbox->storage),
+		mail_storage_set_critical(STORAGE(mbox->storage),
 			"file_dotlock_open(%s) failed: %m", uidlist->path);
 		return -1;
 	}
@@ -1069,7 +1045,8 @@
 		str_truncate(path, 0);
 		str_printfa(path, "%s/"DBOX_MAILDIR_NAME"/"
 			    DBOX_MAIL_FILE_FORMAT, mbox->path, file_seq);
-		ret = file_dotlock_create(&dbox_file_dotlock_set, str_c(path),
+		ret = file_dotlock_create(&mbox->storage->file_dotlock_set,
+					  str_c(path),
 					  DOTLOCK_CREATE_FLAG_NONBLOCK,
 					  dotlock_r);
 		if (ret > 0) {
--- a/src/lib-storage/index/maildir/maildir-keywords.c	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/maildir/maildir-keywords.c	Thu Dec 28 18:51:10 2006 +0200
@@ -20,6 +20,9 @@
 #include <sys/stat.h>
 #include <utime.h>
 
+/* how many seconds to wait before overriding dovecot-keywords.lock */
+#define KEYWORDS_LOCK_STALE_TIMEOUT (60*2)
+
 struct maildir_keywords {
 	struct maildir_mailbox *mbox;
 	char *path;
@@ -56,6 +59,13 @@
 	i_array_init(&mk->list, MAILDIR_MAX_KEYWORDS);
 	mk->hash = hash_create(default_pool, mk->pool, 0,
 			       strcase_hash, (hash_cmp_callback_t *)strcasecmp);
+
+	mk->dotlock_settings.use_excl_lock =
+		(STORAGE(mbox->storage)->flags &
+		 MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
+	mk->dotlock_settings.timeout = KEYWORDS_LOCK_STALE_TIMEOUT + 2;
+	mk->dotlock_settings.stale_timeout = KEYWORDS_LOCK_STALE_TIMEOUT;
+	mk->dotlock_settings.temp_prefix = mbox->storage->temp_prefix;
 	return mk;
 }
 
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Thu Dec 28 18:51:10 2006 +0200
@@ -172,6 +172,9 @@
 				     maildir_hash, maildir_cmp);
 	uidlist->next_uid = 1;
 
+	uidlist->dotlock_settings.use_excl_lock =
+		(STORAGE(mbox->storage)->flags &
+		 MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
 	uidlist->dotlock_settings.timeout = UIDLIST_LOCK_STALE_TIMEOUT + 2;
 	uidlist->dotlock_settings.stale_timeout = UIDLIST_LOCK_STALE_TIMEOUT;
 	uidlist->dotlock_settings.temp_prefix = mbox->storage->temp_prefix;
--- a/src/lib-storage/index/mbox/mbox-lock.c	Thu Dec 28 18:27:53 2006 +0200
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Thu Dec 28 18:51:10 2006 +0200
@@ -249,6 +249,8 @@
         ctx->dotlock_last_stale = -1;
 
 	memset(&set, 0, sizeof(set));
+	set.use_excl_lock = (STORAGE(mbox->storage)->flags &
+			     MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
 	set.timeout = lock_timeout;
 	set.stale_timeout = dotlock_change_timeout;
 	set.callback = dotlock_callback;