Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5773:622ab4de7d66 HEAD
Keep index->map always usable, never NULL.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 19 Jun 2007 15:20:13 +0300 |
parents | 002aa9bbfcb2 |
children | 1af7024361e9 |
files | src/lib-index/mail-index-map.c src/lib-index/mail-index-sync-update.c src/lib-index/mail-index.c |
diffstat | 3 files changed, 15 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-map.c Tue Jun 19 15:05:16 2007 +0300 +++ b/src/lib-index/mail-index-map.c Tue Jun 19 15:20:13 2007 +0300 @@ -704,26 +704,27 @@ return 1; } -static int -mail_index_map_update(struct mail_index *index, struct mail_index_map **_map, - enum mail_index_sync_handler_type type, - unsigned int *lock_id_r) +int mail_index_map(struct mail_index *index, + enum mail_index_sync_handler_type type, + unsigned int *lock_id_r) { - struct mail_index_map *map = *_map; unsigned int lock_id = 0; int ret; + i_assert(index->lock_type != F_WRLCK); i_assert(!index->mapping); - i_assert(map->refcount > 0); *lock_id_r = 0; index->mapping = TRUE; + if (index->map == NULL) + index->map = mail_index_map_alloc(index); + /* first try updating the existing mapping from transaction log. */ - if (map->hdr.indexid != 0) { + if (index->map->hdr.indexid != 0) { /* we're not creating the index, or opening transaction log. sync this as a view from transaction log. */ - ret = mail_index_sync_map(index, &map, type, FALSE); + ret = mail_index_sync_map(index, &index->map, type, FALSE); } else { ret = 0; } @@ -733,57 +734,23 @@ any reason, we'll fallback to updating the existing mapping from transaction logs (which we'll also do even if the reopening succeeds) */ - (void)mail_index_map_latest_file(index, &map, &lock_id); + (void)mail_index_map_latest_file(index, &index->map, &lock_id); /* and update the map with the latest changes from transaction log */ - ret = mail_index_sync_map(index, &map, type, TRUE); + ret = mail_index_sync_map(index, &index->map, type, TRUE); /* we need the lock only if we didn't move the map to memory */ - if (!MAIL_INDEX_MAP_IS_IN_MEMORY(map)) + if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) *lock_id_r = lock_id; else mail_index_unlock(index, lock_id); } - if (ret <= 0) { - /* broken index */ - mail_index_map_clear(index, map); - mail_index_unmap(index, &map); - } - - *_map = map; index->mapping = FALSE; return ret; } -int mail_index_map(struct mail_index *index, - enum mail_index_sync_handler_type type, - unsigned int *lock_id_r) -{ - struct mail_index_map *map = index->map; - int ret; - - i_assert(index->lock_type != F_WRLCK); - - if (map == NULL) - map = mail_index_map_alloc(index); - - index->map = NULL; - - ret = mail_index_map_update(index, &map, type, lock_id_r); - i_assert(index->map == NULL); - - if (ret > 0) { - i_assert(map->hdr.messages_count == map->records_count); - index->map = map; - } else { - if (map != NULL) - mail_index_unmap(index, &map); - } - return ret; -} - void mail_index_unmap(struct mail_index *index, struct mail_index_map **_map) { struct mail_index_map *map = *_map;
--- a/src/lib-index/mail-index-sync-update.c Tue Jun 19 15:05:16 2007 +0300 +++ b/src/lib-index/mail-index-sync-update.c Tue Jun 19 15:20:13 2007 +0300 @@ -686,6 +686,8 @@ int ret; bool had_dirty; + i_assert(index->map == map || type == MAIL_INDEX_SYNC_HANDLER_VIEW); + if (!force) { /* see if we'd prefer to reopen the index file instead of syncing the current map from the transaction log */ @@ -740,11 +742,6 @@ map->hdr_base = map->hdr_copy_buf->data; } - if (type != MAIL_INDEX_SYNC_HANDLER_VIEW) { - i_assert(index->map == NULL); - index->map = map; - } - mail_index_sync_map_init(&sync_map_ctx, view, type); map = NULL; @@ -807,10 +804,7 @@ mail_index_sync_map_deinit(&sync_map_ctx); - if (type != MAIL_INDEX_SYNC_HANDLER_VIEW) { - i_assert(index->map == map); - index->map = NULL; - } + i_assert(index->map == map || type == MAIL_INDEX_SYNC_HANDLER_VIEW); *_map = map; return ret < 0 ? -1 : 1;
--- a/src/lib-index/mail-index.c Tue Jun 19 15:05:16 2007 +0300 +++ b/src/lib-index/mail-index.c Tue Jun 19 15:20:13 2007 +0300 @@ -522,8 +522,6 @@ static void mail_index_close_file(struct mail_index *index) { - if (index->map != NULL) - mail_index_unmap(index, &index->map); if (index->file_lock != NULL) file_lock_free(&index->file_lock);