dovecot-2.2: mdbox: Fixed race condition when mailbox GUID was l...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Nov 6 15:30:26 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/fa6466dcc37a
changeset: 16938:fa6466dcc37a
user: Timo Sirainen <tss at iki.fi>
date: Wed Nov 06 15:30:15 2013 +0200
description:
mdbox: Fixed race condition when mailbox GUID was looked up before mailbox create was finished.
diffstat:
src/lib-storage/index/dbox-multi/mdbox-storage.c | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diffs (39 lines):
diff -r 0505adfe2d8e -r fa6466dcc37a src/lib-storage/index/dbox-multi/mdbox-storage.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Wed Nov 06 13:00:13 2013 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Wed Nov 06 15:30:15 2013 +0200
@@ -370,9 +370,19 @@
static int
mdbox_mailbox_get_guid(struct mdbox_mailbox *mbox, guid_128_t guid_r)
{
+ const struct mail_index_header *idx_hdr;
struct mdbox_index_header hdr;
bool need_resize;
+ int ret = 0;
+ i_assert(!mbox->creating);
+
+ /* there's a race condition between mkdir and getting the mailbox GUID.
+ normally this is handled by mdbox syncing, but GUID can be looked up
+ without syncing. when mbox->creating=TRUE, the errors are hidden
+ and we'll simply finish the mailbox creation */
+ idx_hdr = mail_index_get_header(mbox->box.view);
+ mbox->creating = idx_hdr->uid_validity == 0 && idx_hdr->next_uid == 1;
if (mdbox_read_header(mbox, &hdr, &need_resize) < 0)
memset(&hdr, 0, sizeof(hdr));
@@ -380,10 +390,12 @@
/* regenerate it */
if (mdbox_write_index_header(&mbox->box, NULL, NULL) < 0 ||
mdbox_read_header(mbox, &hdr, &need_resize) < 0)
- return -1;
+ ret = -1;
}
- memcpy(guid_r, hdr.mailbox_guid, GUID_128_SIZE);
- return 0;
+ if (ret == 0)
+ memcpy(guid_r, hdr.mailbox_guid, GUID_128_SIZE);
+ mbox->creating = FALSE;
+ return ret;
}
static int
More information about the dovecot-cvs
mailing list