]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Don't close index files if they're still being used by another mailbox.
authorTimo Sirainen <tss@iki.fi>
Tue, 9 Feb 2010 02:52:29 +0000 (04:52 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 9 Feb 2010 02:52:29 +0000 (04:52 +0200)
--HG--
branch : HEAD

src/lib-index/mail-index-private.h
src/lib-index/mail-index.c
src/lib-storage/index/dbox-common/dbox-sync-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/index-storage.c

index 5f742e62f1af19405f2d57b17562a712c54a5e9f..a03c14393c128f1ec7c7363c85e4f0d7e85cd501 100644 (file)
@@ -170,6 +170,7 @@ struct mail_index {
        struct mail_cache *cache;
        struct mail_transaction_log *log;
 
+       unsigned int open_count;
        enum mail_index_open_flags flags;
        enum mail_index_sync_type fsync_mask;
        mode_t mode;
@@ -225,7 +226,6 @@ struct mail_index {
        unsigned int nodiskspace:1;
        unsigned int index_lock_timeout:1;
 
-       unsigned int opened:1;
        unsigned int index_delete_requested:1; /* next sync sets it deleted */
        unsigned int index_deleted:1; /* no changes allowed anymore */
        unsigned int log_locked:1;
index 97b6118c825bbd5b390af1cd6bacbeba43b765fe..0054abf991250e865347bf2fd46312fb330b19a4 100644 (file)
@@ -63,7 +63,8 @@ void mail_index_free(struct mail_index **_index)
        struct mail_index *index = *_index;
 
        *_index = NULL;
-       mail_index_close(index);
+
+       i_assert(index->open_count == 0);
 
        mail_transaction_log_free(&index->log);
        hash_table_destroy(&index->keywords_hash);
@@ -484,16 +485,10 @@ int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
 {
        int ret;
 
-       if (index->opened) {
-               if (index->map != NULL &&
-                   (index->map->hdr.flags &
-                    MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
-                       /* corrupted, reopen files */
-                        mail_index_close(index);
-               } else {
-                       i_assert(index->map != NULL);
-                       return 1;
-               }
+       if (index->open_count > 0) {
+               i_assert(index->map != NULL);
+               index->open_count++;
+               return 1;
        }
 
        index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ?
@@ -520,6 +515,7 @@ int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
            (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
                i_fatal("nfs flush requires mmap_disable=yes");
 
+       index->open_count++;
        if ((ret = mail_index_open_files(index, flags)) <= 0) {
                /* doesn't exist and create flag not used */
                mail_index_close(index);
@@ -527,7 +523,6 @@ int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
        }
 
        i_assert(index->map != NULL);
-       index->opened = TRUE;
        mail_index_alloc_cache_index_opened(index);
        return 1;
 }
@@ -563,6 +558,10 @@ void mail_index_close_file(struct mail_index *index)
 
 void mail_index_close(struct mail_index *index)
 {
+       i_assert(index->open_count > 0);
+       if (--index->open_count > 0)
+               return;
+
        if (index->map != NULL)
                mail_index_unmap(&index->map);
 
@@ -574,7 +573,6 @@ void mail_index_close(struct mail_index *index)
        i_free_and_null(index->filepath);
 
        index->indexid = 0;
-       index->opened = FALSE;
 }
 
 int mail_index_unlink(struct mail_index *index)
index 7848956719004a568a8e3692c25a72733ab1f98c..fa7fb9ca13066a2c2c64aab967c0987c25acbe65 100644 (file)
@@ -125,6 +125,7 @@ void dbox_sync_index_rebuild_deinit(struct dbox_sync_rebuild_context **_ctx)
        *_ctx = NULL;
        if (ctx->backup_index != NULL) {
                mail_index_view_close(&ctx->backup_view);
+               mail_index_close(ctx->backup_index);
                mail_index_free(&ctx->backup_index);
        }
        i_free(ctx);
index cb521bc34d6159a8738dd8f50e8076f686fb7317..6f5226baa035705578f687c2e7687ed0f41bc954 100644 (file)
@@ -78,8 +78,10 @@ void dbox_map_deinit(struct dbox_map **_map)
 
        *_map = NULL;
 
-       if (map->view != NULL)
+       if (map->view != NULL) {
                mail_index_view_close(&map->view);
+               mail_index_close(map->index);
+       }
        mail_index_free(&map->index);
        i_free(map->path);
        i_free(map);
index 7ef313577af6cbdbf3ad619ae85e6011bb018c40..ac0777dd9fadb304041e59371ce74ed3b6d7a3df 100644 (file)
@@ -221,6 +221,7 @@ int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory)
        ret = mail_index_open(box->index, index_flags, lock_method);
        if (ret <= 0 || move_to_memory) {
                if ((index_flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0) {
+                       i_assert(ret <= 0);
                        mail_storage_set_index_error(box);
                        return -1;
                }