Mercurial > dovecot > core-2.2
diff src/lib-storage/index/dbox-multi/mdbox-storage.c @ 11216:de0ed7bea201 HEAD
mdbox: Avoid rebuilding storage if another process already did it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 29 Apr 2010 18:43:02 +0300 |
parents | 944f4335845f |
children | 6e1bbf87749f |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Thu Apr 29 17:52:40 2010 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Thu Apr 29 18:43:02 2010 +0300 @@ -127,8 +127,7 @@ { struct mdbox_storage *mstorage = (struct mdbox_storage *)box->storage; - if (mstorage->storage.files_corrupted && - !mstorage->rebuilding_storage) + if (mstorage->corrupted && !mstorage->rebuilding_storage) (void)mdbox_storage_rebuild(mstorage); index_storage_mailbox_close(box); @@ -145,8 +144,9 @@ if (data_size < MDBOX_INDEX_HEADER_MIN_SIZE && (!mbox->creating || data_size != 0)) { mail_storage_set_critical(&mbox->storage->storage.storage, - "dbox %s: Invalid dbox header size", - mbox->box.path); + "dbox %s: Invalid dbox header size: %"PRIuSIZE_T, + mbox->box.path, data_size); + mdbox_storage_set_corrupted(mbox->storage); return -1; } memset(hdr, 0, sizeof(*hdr)); @@ -244,6 +244,30 @@ return ret; } +void mdbox_storage_set_corrupted(struct mdbox_storage *storage) +{ + if (storage->corrupted) { + /* already set it corrupted (possibly recursing back here) */ + return; + } + + storage->corrupted = TRUE; + storage->corrupted_rebuild_count = (uint32_t)-1; + + if (dbox_map_open(storage->map) > 0 && + dbox_map_refresh(storage->map) == 0) { + storage->corrupted_rebuild_count = + mdbox_map_get_rebuild_count(storage->map); + } +} + +static void mdbox_set_file_corrupted(struct dbox_file *file) +{ + struct mdbox_storage *mstorage = (struct mdbox_storage *)file->storage; + + mdbox_storage_set_corrupted(mstorage); +} + static int mdbox_mailbox_get_guid(struct mailbox *box, uint8_t guid[MAIL_GUID_128_SIZE]) { @@ -388,5 +412,6 @@ mdbox_file_unrefed, mdbox_file_create_fd, mdbox_mail_open, - mdbox_mailbox_create_indexes + mdbox_mailbox_create_indexes, + mdbox_set_file_corrupted };