dovecot-2.2: lib-storage: Added mailbox_get_index_path() and cac...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 24 22:13:30 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/936435377584
changeset: 17833:936435377584
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 25 01:13:12 2014 +0300
description:
lib-storage: Added mailbox_get_index_path() and caching of the index path.
This solves some potential assert-crashes on race conditions when opening a
mailbox while it's being deleted.

diffstat:

 src/lib-storage/index/index-rebuild.c  |   4 +---
 src/lib-storage/mail-storage-private.h |   5 +++++
 src/lib-storage/mail-storage.c         |  17 +++++++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diffs (77 lines):

diff -r 6d4e7ccb24ea -r 936435377584 src/lib-storage/index/index-rebuild.c
--- a/src/lib-storage/index/index-rebuild.c	Thu Sep 25 00:42:56 2014 +0300
+++ b/src/lib-storage/index/index-rebuild.c	Thu Sep 25 01:13:12 2014 +0300
@@ -167,9 +167,7 @@
 	mail_cache_reset(box->cache);
 
 	/* if backup index file exists, try to use it */
-	if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
-				&index_dir) <= 0)
-		i_unreached();
+	index_dir = mailbox_get_index_path(box);
 	backup_path = t_strconcat(box->index_prefix, ".backup", NULL);
 	ctx->backup_index = mail_index_alloc(index_dir, backup_path);
 
diff -r 6d4e7ccb24ea -r 936435377584 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Thu Sep 25 00:42:56 2014 +0300
+++ b/src/lib-storage/mail-storage-private.h	Thu Sep 25 01:13:12 2014 +0300
@@ -291,6 +291,9 @@
 	/* Filled lazily when mailbox is opened, use mailbox_get_path()
 	   to access it */
 	const char *_path;
+	/* Filled lazily when mailbox is opened, use mailbox_get_index_path()
+	   to access it */
+	const char *_index_path;
 
 	/* default vfuncs for new struct mails. */
 	const struct mail_vfuncs *mail_vfuncs;
@@ -646,6 +649,8 @@
    The mailbox must already be opened and the caller must know that the
    storage has mailbox files (i.e. NULL/empty path is never returned). */
 const char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
+/* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */
+const char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE;
 /* Wrapper to mailbox_list_get_path() */
 int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
 			const char **path_r);
diff -r 6d4e7ccb24ea -r 936435377584 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Thu Sep 25 00:42:56 2014 +0300
+++ b/src/lib-storage/mail-storage.c	Thu Sep 25 01:13:12 2014 +0300
@@ -2245,6 +2245,14 @@
 		*path_r = box->_path;
 		return 1;
 	}
+	if (type == MAILBOX_LIST_PATH_TYPE_INDEX && box->_index_path != NULL) {
+		if (box->_index_path[0] == '\0') {
+			*path_r = NULL;
+			return 0;
+		}
+		*path_r = box->_index_path;
+		return 1;
+	}
 	ret = mailbox_list_get_path(box->list, box->name, type, path_r);
 	if (ret < 0) {
 		mail_storage_copy_list_error(box->storage, box->list);
@@ -2252,6 +2260,8 @@
 	}
 	if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX && box->_path == NULL)
 		box->_path = ret == 0 ? "" : p_strdup(box->pool, *path_r);
+	if (type == MAILBOX_LIST_PATH_TYPE_INDEX && box->_index_path == NULL)
+		box->_index_path = ret == 0 ? "" : p_strdup(box->pool, *path_r);
 	return ret;
 }
 
@@ -2262,6 +2272,13 @@
 	return box->_path;
 }
 
+const char *mailbox_get_index_path(struct mailbox *box)
+{
+	i_assert(box->_index_path != NULL);
+	i_assert(box->_index_path[0] != '\0');
+	return box->_index_path;
+}
+
 static void mailbox_get_permissions_if_not_set(struct mailbox *box)
 {
 	if (box->_perm.file_create_mode != 0)


More information about the dovecot-cvs mailing list