From: Timo Sirainen Date: Tue, 23 Mar 2010 18:11:07 +0000 (+0200) Subject: mdbox: Do delayed storage rebuild when closing mailbox. X-Git-Tag: 2.0.beta5~299 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1dd054126238349e1a7d3d1ffe7f8bc5fdbacb7a;p=thirdparty%2Fdovecot%2Fcore.git mdbox: Do delayed storage rebuild when closing mailbox. Doing it on storage destroy causes problems. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index 8b76b19491..13cbb3fb1e 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -81,18 +81,25 @@ mdbox_storage_rebuild_init(struct mdbox_storage *storage) { struct mdbox_storage_rebuild_context *ctx; + i_assert(!storage->rebuilding_storage); + ctx = i_new(struct mdbox_storage_rebuild_context, 1); ctx->storage = storage; ctx->pool = pool_alloconly_create("dbox map rebuild", 1024*256); ctx->guid_hash = hash_table_create(default_pool, ctx->pool, 0, guid_hash, guid_cmp); i_array_init(&ctx->msgs, 512); + + ctx->storage->rebuilding_storage = TRUE; return ctx; } static void mdbox_storage_rebuild_deinit(struct mdbox_storage_rebuild_context *ctx) { + i_assert(ctx->storage->rebuilding_storage); + + ctx->storage->rebuilding_storage = FALSE; if (ctx->sync_ctx != NULL) mail_index_sync_rollback(&ctx->sync_ctx); diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index ec600be26d..c68586867a 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -65,11 +65,6 @@ static void mdbox_storage_destroy(struct mail_storage *_storage) { struct mdbox_storage *storage = (struct mdbox_storage *)_storage; - if (storage->storage.files_corrupted) { - if (mdbox_storage_rebuild(storage) < 0) - return; - } - mdbox_files_free(storage); dbox_map_deinit(&storage->map); if (storage->to_close_unused_files != NULL) @@ -122,6 +117,17 @@ mdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list, return &mbox->box; } +static void mdbox_mailbox_close(struct mailbox *box) +{ + struct mdbox_storage *mstorage = (struct mdbox_storage *)box->storage; + + if (mstorage->storage.files_corrupted && + !mstorage->rebuilding_storage) + (void)mdbox_storage_rebuild(mstorage); + + index_storage_mailbox_close(box); +} + int mdbox_read_header(struct mdbox_mailbox *mbox, struct mdbox_index_header *hdr) { @@ -333,7 +339,7 @@ struct mailbox mdbox_mailbox = { index_storage_allow_new_keywords, index_storage_mailbox_enable, dbox_mailbox_open, - index_storage_mailbox_close, + mdbox_mailbox_close, index_storage_mailbox_free, dbox_mailbox_create, mdbox_mailbox_update, diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.h b/src/lib-storage/index/dbox-multi/mdbox-storage.h index 340e4abe4f..61f3f3e0e5 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.h +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h @@ -31,6 +31,8 @@ struct mdbox_storage { ARRAY_DEFINE(open_files, struct mdbox_file *); struct timeout *to_close_unused_files; + + unsigned int rebuilding_storage:1; }; struct mdbox_mail_index_record {