]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Do delayed storage rebuild when closing mailbox.
authorTimo Sirainen <tss@iki.fi>
Tue, 23 Mar 2010 18:11:07 +0000 (20:11 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 23 Mar 2010 18:11:07 +0000 (20:11 +0200)
Doing it on storage destroy causes problems.

--HG--
branch : HEAD

src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage.h

index 8b76b194912436c39bf756d081abab13e883d21c..13cbb3fb1e054b90a778ba7696bee80e2d165ba2 100644 (file)
@@ -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);
 
index ec600be26d20d7f3337eec8565758de0dd29a223..c68586867a7092e55677510360954c0592013d51 100644 (file)
@@ -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,
index 340e4abe4f4bceea0e39b207c1871ee0a41c41fc..61f3f3e0e551b79678c3a99fbcc1670a0b0aaff4 100644 (file)
@@ -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 {