Blame SOURCES/dovecot-2.2.10-ed6e472cab0e.patch

386c00
386c00
# HG changeset patch
386c00
# User Timo Sirainen <tss@iki.fi>
386c00
# Date 1399469814 -10800
386c00
# Node ID ed6e472cab0e1b961bddcabdaf7c33c85503079a
386c00
# Parent  2e7ac48c6072d8490b64e145323664b5697b9701
386c00
mdbox: Fixed race condition when creating a new mailbox and another process getting its GUID.
386c00
386c00
diff -r 2e7ac48c6072 -r ed6e472cab0e src/lib-storage/index/dbox-common/dbox-storage.c
386c00
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Wed May 07 13:02:29 2014 +0300
386c00
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Wed May 07 16:36:54 2014 +0300
386c00
@@ -255,9 +255,6 @@
386c00
 			const struct mailbox_update *update, bool directory)
386c00
 {
386c00
 	struct dbox_storage *storage = (struct dbox_storage *)box->storage;
386c00
-	struct mail_index_sync_ctx *sync_ctx;
386c00
-	struct mail_index_view *view;
386c00
-	struct mail_index_transaction *trans;
386c00
 	const char *alt_path;
386c00
 	struct stat st;
386c00
 	int ret;
386c00
@@ -290,6 +287,17 @@
386c00
 		}
386c00
 		/* dir is empty, ignore it */
386c00
 	}
386c00
+	return dbox_mailbox_create_indexes(box, update);
386c00
+}
386c00
+
386c00
+int dbox_mailbox_create_indexes(struct mailbox *box,
386c00
+				const struct mailbox_update *update)
386c00
+{
386c00
+	struct dbox_storage *storage = (struct dbox_storage *)box->storage;
386c00
+	struct mail_index_sync_ctx *sync_ctx;
386c00
+	struct mail_index_view *view;
386c00
+	struct mail_index_transaction *trans;
386c00
+	int ret;
386c00
 
386c00
 	/* use syncing as a lock */
386c00
 	ret = mail_index_sync_begin(box->index, &sync_ctx, &view, &trans, 0);
386c00
diff -r 2e7ac48c6072 -r ed6e472cab0e src/lib-storage/index/dbox-common/dbox-storage.h
386c00
--- a/src/lib-storage/index/dbox-common/dbox-storage.h	Wed May 07 13:02:29 2014 +0300
386c00
+++ b/src/lib-storage/index/dbox-common/dbox-storage.h	Wed May 07 16:36:54 2014 +0300
386c00
@@ -73,6 +73,8 @@
386c00
 int dbox_mailbox_open(struct mailbox *box);
386c00
 int dbox_mailbox_create(struct mailbox *box,
386c00
 			const struct mailbox_update *update, bool directory);
386c00
+int dbox_mailbox_create_indexes(struct mailbox *box,
386c00
+				const struct mailbox_update *update);
386c00
 int dbox_verify_alt_storage(struct mailbox_list *list);
386c00
 bool dbox_header_have_flag(struct mailbox *box, uint32_t ext_id,
386c00
 			   unsigned int flags_offset, uint8_t flag);
386c00
diff -r 2e7ac48c6072 -r ed6e472cab0e src/lib-storage/index/dbox-multi/mdbox-storage.c
386c00
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Wed May 07 13:02:29 2014 +0300
386c00
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Wed May 07 16:36:54 2014 +0300
386c00
@@ -379,10 +379,15 @@
386c00
 
386c00
 	/* there's a race condition between mkdir and getting the mailbox GUID.
386c00
 	   normally this is handled by mdbox syncing, but GUID can be looked up
386c00
-	   without syncing. when mbox->creating=TRUE, the errors are hidden
386c00
-	   and we'll simply finish the mailbox creation */
386c00
+	   without syncing. when we detect this situation we'll try to finish
386c00
+	   creating the indexes first, which usually means just waiting for
386c00
+	   the sync lock to get unlocked by the other process creating them. */
386c00
 	idx_hdr = mail_index_get_header(mbox->box.view);
386c00
-	mbox->creating = idx_hdr->uid_validity == 0 && idx_hdr->next_uid == 1;
386c00
+	if (idx_hdr->uid_validity == 0 && idx_hdr->next_uid == 1) {
386c00
+		if (dbox_mailbox_create_indexes(&mbox->box, NULL) < 0)
386c00
+			return -1;
386c00
+	}
386c00
+
386c00
 	if (mdbox_read_header(mbox, &hdr, &need_resize) < 0)
386c00
 		memset(&hdr, 0, sizeof(hdr));
386c00
 
386c00
@@ -394,7 +399,6 @@
386c00
 	}
386c00
 	if (ret == 0)
386c00
 		memcpy(guid_r, hdr.mailbox_guid, GUID_128_SIZE);
386c00
-	mbox->creating = FALSE;
386c00
 	return ret;
386c00
 }
386c00
 
386c00