Mercurial > dovecot > core-2.2
changeset 10677:93fe3aa23bdb HEAD
lib-index: Don't close index files if they're still being used by another mailbox.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 09 Feb 2010 04:52:29 +0200 |
parents | 1fd7833c16ca |
children | 9740c4858a57 |
files | 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 |
diffstat | 5 files changed, 17 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-private.h Tue Feb 09 04:11:53 2010 +0200 +++ b/src/lib-index/mail-index-private.h Tue Feb 09 04:52:29 2010 +0200 @@ -170,6 +170,7 @@ 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 @@ 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;
--- a/src/lib-index/mail-index.c Tue Feb 09 04:11:53 2010 +0200 +++ b/src/lib-index/mail-index.c Tue Feb 09 04:52:29 2010 +0200 @@ -63,7 +63,8 @@ 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 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 @@ (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 @@ } 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(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 @@ i_free_and_null(index->filepath); index->indexid = 0; - index->opened = FALSE; } int mail_index_unlink(struct mail_index *index)
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c Tue Feb 09 04:11:53 2010 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c Tue Feb 09 04:52:29 2010 +0200 @@ -125,6 +125,7 @@ *_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);
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c Tue Feb 09 04:11:53 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Tue Feb 09 04:52:29 2010 +0200 @@ -78,8 +78,10 @@ *_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);
--- a/src/lib-storage/index/index-storage.c Tue Feb 09 04:11:53 2010 +0200 +++ b/src/lib-storage/index/index-storage.c Tue Feb 09 04:52:29 2010 +0200 @@ -221,6 +221,7 @@ 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; }