Mercurial > dovecot > core-2.2
changeset 15312:0d1de37ad9d8
lib-index: Code cleanup: Removed mail_cache.data
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 18 Oct 2012 05:16:54 +0300 |
parents | 022d0d21e56d |
children | 51f2be9aa8ad |
files | src/lib-index/mail-cache-lookup.c src/lib-index/mail-cache-private.h src/lib-index/mail-cache.c |
diffstat | 3 files changed, 18 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache-lookup.c Thu Oct 18 05:10:29 2012 +0300 +++ b/src/lib-index/mail-cache-lookup.c Thu Oct 18 05:16:54 2012 +0300 @@ -272,6 +272,7 @@ field_r->field_idx = field_idx; field_r->data = CONST_PTR_OFFSET(ctx->rec, ctx->pos); field_r->size = data_size; + field_r->offset = ctx->offset + ctx->pos; /* each record begins from 32bit aligned position */ ctx->pos += (data_size + sizeof(uint32_t)-1) & ~(sizeof(uint32_t)-1); @@ -446,8 +447,7 @@ lines_count = i; hdr_data = t_new(struct header_lookup_data, 1); - hdr_data->offset = (const char *)&lines[lines_count+1] - - (const char *)ctx->view->cache->data; + hdr_data->offset = field->offset + (lines_count+1) * sizeof(uint32_t); hdr_data->data_size = data_size; for (i = 0; i < lines_count; i++) { @@ -473,6 +473,7 @@ struct mail_cache_iterate_field field; struct header_lookup_context ctx; struct header_lookup_line *lines; + const void *data; const unsigned char *p, *start, *end; uint8_t *field_state; unsigned int i, count, max_field = 0; @@ -537,7 +538,10 @@ /* then start filling dest buffer from the headers */ for (i = 0; i < count; i++) { - start = CONST_PTR_OFFSET(cache->data, lines[i].data->offset); + if (mail_cache_map(cache, lines[i].data->offset, + lines[i].data->data_size, &data) <= 0) + return -1; + start = data; end = start + lines[i].data->data_size; /* find the end of the (multiline) header */
--- a/src/lib-index/mail-cache-private.h Thu Oct 18 05:10:29 2012 +0300 +++ b/src/lib-index/mail-cache-private.h Thu Oct 18 05:16:54 2012 +0300 @@ -39,10 +39,6 @@ #define MAIL_CACHE_LOCK_TIMEOUT 10 #define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 300 -#define CACHE_RECORD(cache, offset) \ - ((const struct mail_cache_record *) \ - ((const char *) (cache)->data + offset)) - #define MAIL_CACHE_IS_UNUSABLE(cache) \ ((cache)->hdr == NULL) @@ -135,7 +131,6 @@ dev_t st_dev; void *mmap_base; - const void *data; size_t mmap_length; struct file_cache *file_cache; /* mail_cache_map() increases this always. */ @@ -203,8 +198,9 @@ struct mail_cache_iterate_field { unsigned int field_idx; + unsigned int size; const void *data; - unsigned int size; + uoff_t offset; }; struct mail_cache_lookup_iterate_ctx {
--- a/src/lib-index/mail-cache.c Thu Oct 18 05:10:29 2012 +0300 +++ b/src/lib-index/mail-cache.c Thu Oct 18 05:16:54 2012 +0300 @@ -59,7 +59,6 @@ file_cache_set_fd(cache->file_cache, -1); cache->mmap_base = NULL; - cache->data = NULL; cache->hdr = NULL; cache->mmap_length = 0; cache->last_field_header_offset = 0; @@ -214,10 +213,9 @@ cache->need_compress_file_seq = hdr->file_seq; } -static bool mail_cache_verify_header(struct mail_cache *cache) +static bool mail_cache_verify_header(struct mail_cache *cache, + const struct mail_cache_header *hdr) { - const struct mail_cache_header *hdr = cache->data; - /* check that the header is still ok */ if (cache->mmap_length < sizeof(struct mail_cache_header)) { mail_cache_set_corrupted(cache, "File too small"); @@ -278,7 +276,6 @@ size = sizeof(struct mail_cache_header); if (cache->file_cache != NULL) { - cache->data = NULL; cache->hdr = NULL; ret = file_cache_read(cache->file_cache, offset, size); @@ -295,26 +292,24 @@ return -1; } - cache->data = file_cache_get_map(cache->file_cache, - &cache->mmap_length); + data = file_cache_get_map(cache->file_cache, + &cache->mmap_length); if (offset == 0) { - if (!mail_cache_verify_header(cache)) { + if (!mail_cache_verify_header(cache, data)) { cache->need_compress_file_seq = !MAIL_CACHE_IS_UNUSABLE(cache) && cache->hdr->file_seq != 0 ? cache->hdr->file_seq : 0; return -1; } - memcpy(&cache->hdr_ro_copy, cache->data, + memcpy(&cache->hdr_ro_copy, data, sizeof(cache->hdr_ro_copy)); } cache->hdr = &cache->hdr_ro_copy; if (offset == 0) mail_cache_update_need_compress(cache); - data = file_cache_get_map(cache->file_cache, - &cache->mmap_length); if (offset > cache->mmap_length) { *data_r = NULL; return 0; @@ -350,13 +345,11 @@ cache->mmap_base = mmap_ro_file(cache->fd, &cache->mmap_length); if (cache->mmap_base == MAP_FAILED) { cache->mmap_base = NULL; - cache->data = NULL; mail_cache_set_syscall_error(cache, "mmap()"); return -1; } - cache->data = cache->mmap_base; - if (!mail_cache_verify_header(cache)) { + if (!mail_cache_verify_header(cache, cache->mmap_base)) { cache->need_compress_file_seq = !MAIL_CACHE_IS_UNUSABLE(cache) && cache->hdr->file_seq != 0 ? @@ -364,7 +357,7 @@ return -1; } - cache->hdr = cache->data; + cache->hdr = cache->mmap_base; if (offset == 0) mail_cache_update_need_compress(cache); if (offset > cache->mmap_length) { @@ -698,13 +691,8 @@ return -1; } - if (cache->file_cache != NULL) { + if (cache->file_cache != NULL) file_cache_write(cache->file_cache, data, size, offset); - - /* data pointer may change if file cache was grown */ - cache->data = file_cache_get_map(cache->file_cache, - &cache->mmap_length); - } return 0; }