dovecot-2.2: lib-index: Code cleanup: Removed mail_cache.data
dovecot at dovecot.org
dovecot at dovecot.org
Mon Oct 29 17:55:54 EET 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/0d1de37ad9d8
changeset: 15312:0d1de37ad9d8
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 18 05:16:54 2012 +0300
description:
lib-index: Code cleanup: Removed mail_cache.data
diffstat:
src/lib-index/mail-cache-lookup.c | 10 +++++++---
src/lib-index/mail-cache-private.h | 8 ++------
src/lib-index/mail-cache.c | 30 +++++++++---------------------
3 files changed, 18 insertions(+), 30 deletions(-)
diffs (176 lines):
diff -r 022d0d21e56d -r 0d1de37ad9d8 src/lib-index/mail-cache-lookup.c
--- 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 */
diff -r 022d0d21e56d -r 0d1de37ad9d8 src/lib-index/mail-cache-private.h
--- 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 {
diff -r 022d0d21e56d -r 0d1de37ad9d8 src/lib-index/mail-cache.c
--- 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;
}
More information about the dovecot-cvs
mailing list