Mercurial > dovecot > core-2.2
changeset 6348:ef1c7b2acc10 HEAD
Only index extension indexes are now called "ext_id". For map extension
indexes use "map_ext_idx".
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 02 Sep 2007 04:28:21 +0300 |
parents | aeaaaaeb64a6 |
children | 75c814287334 |
files | src/lib-index/mail-index-map.c src/lib-index/mail-index-private.h src/lib-index/mail-index-sync-ext.c src/lib-index/mail-index-sync-keywords.c src/lib-index/mail-index-sync-private.h src/lib-index/mail-index-sync-update.c src/lib-index/mail-index.c |
diffstat | 7 files changed, 80 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-map.c Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index-map.c Sun Sep 02 04:28:21 2007 +0300 @@ -42,20 +42,23 @@ p_array_init(&map->ext_id_map, map->extension_pool, initial_count); } -uint32_t mail_index_map_lookup_ext(struct mail_index_map *map, const char *name) +bool mail_index_map_lookup_ext(struct mail_index_map *map, const char *name, + uint32_t *idx_r) { const struct mail_index_ext *extensions; unsigned int i, size; - if (!array_is_created(&map->extensions)) - return (uint32_t)-1; - - extensions = array_get(&map->extensions, &size); - for (i = 0; i < size; i++) { - if (strcmp(extensions[i].name, name) == 0) - return i; + if (array_is_created(&map->extensions)) { + extensions = array_get(&map->extensions, &size); + for (i = 0; i < size; i++) { + if (strcmp(extensions[i].name, name) == 0) { + if (idx_r != NULL) + *idx_r = i; + return TRUE; + } + } } - return (uint32_t)-1; + return FALSE; } static size_t get_ext_size(size_t name_len) @@ -79,7 +82,7 @@ } else { idx = array_count(&map->extensions); } - i_assert(mail_index_map_lookup_ext(map, name) == (uint32_t)-1); + i_assert(!mail_index_map_lookup_ext(map, name, NULL)); ext = array_append_space(&map->extensions); ext->name = p_strdup(map->extension_pool, name); @@ -154,7 +157,7 @@ name = t_strndup(CONST_PTR_OFFSET(map->hdr_base, name_offset), ext_hdr->name_size); - if (mail_index_map_lookup_ext(map, name) != (uint32_t)-1) { + if (mail_index_map_lookup_ext(map, name, NULL)) { mail_index_set_error(index, "Corrupted index file %s: " "Duplicate header extension %s", index->filepath, name);
--- a/src/lib-index/mail-index-private.h Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index-private.h Sun Sep 02 04:28:21 2007 +0300 @@ -277,8 +277,8 @@ /* Move a mmaped map to memory. */ void mail_index_map_move_to_memory(struct mail_index_map *map); -uint32_t mail_index_map_lookup_ext(struct mail_index_map *map, - const char *name); +bool mail_index_map_lookup_ext(struct mail_index_map *map, const char *name, + uint32_t *idx_r); uint32_t mail_index_map_register_ext(struct mail_index_map *map, const char *name, uint32_t ext_offset, uint32_t hdr_size,
--- a/src/lib-index/mail-index-sync-ext.c Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index-sync-ext.c Sun Sep 02 04:28:21 2007 +0300 @@ -140,7 +140,7 @@ return (int)(*e2)->record_align - (int)(*e1)->record_align; } -static void sync_ext_reorder(struct mail_index_map *map, uint32_t ext_id, +static void sync_ext_reorder(struct mail_index_map *map, uint32_t ext_map_idx, uint16_t old_ext_size) { struct mail_index_ext *ext, **sorted; @@ -156,6 +156,7 @@ t_push(); ext = array_get_modifiable(&map->extensions, &count); + i_assert(ext_map_idx < count); /* @UNSAFE */ old_offsets = t_new(uint16_t, count); @@ -170,10 +171,10 @@ qsort(sorted, count, sizeof(struct mail_index_ext *), mail_index_ext_align_cmp); - if (copy_sizes[ext_id] > old_ext_size) { + if (copy_sizes[ext_map_idx] > old_ext_size) { /* we are growing the extension record. remember this so we don't write extra data while copying the record */ - copy_sizes[ext_id] = old_ext_size; + copy_sizes[ext_map_idx] = old_ext_size; } /* we simply try to use the extensions with largest alignment @@ -260,8 +261,8 @@ } static void -sync_ext_resize(const struct mail_transaction_ext_intro *u, uint32_t ext_id, - struct mail_index_sync_map_ctx *ctx) +sync_ext_resize(const struct mail_transaction_ext_intro *u, + uint32_t ext_map_idx, struct mail_index_sync_map_ctx *ctx) { struct mail_index_map *map = ctx->view->map; struct mail_index_ext *ext; @@ -269,7 +270,7 @@ uint32_t old_size, new_size, old_record_size; bool modified = FALSE; - ext = array_idx_modifiable(&map->extensions, ext_id); + ext = array_idx_modifiable(&map->extensions, ext_map_idx); old_size = MAIL_INDEX_HEADER_SIZE_ALIGN(ext->hdr_size); new_size = MAIL_INDEX_HEADER_SIZE_ALIGN(u->hdr_size); @@ -312,11 +313,11 @@ if (new_size != old_size) { /* move all hdr_offset of all extensions after this one */ - unsigned i, count = array_count(&map->extensions); + unsigned int i, count = array_count(&map->extensions); ssize_t diff = (ssize_t)new_size - (ssize_t)old_size; ext = array_idx_modifiable(&map->extensions, 0); - for (i = ext_id + 1; i < count; i++) { + for (i = ext_map_idx + 1; i < count; i++) { ext[i].ext_offset += diff; ext[i].hdr_offset += diff; } @@ -324,7 +325,7 @@ if (old_record_size != u->record_size) { map = mail_index_sync_get_atomic_map(ctx); - sync_ext_reorder(map, ext_id, old_record_size); + sync_ext_reorder(map, ext_map_idx, old_record_size); } else if (modified) { /* header size changed. recreate index file. */ map = mail_index_sync_get_atomic_map(ctx); @@ -333,15 +334,15 @@ static bool mail_index_sync_ext_unknown_complain(struct mail_index_sync_map_ctx *ctx, - uint32_t ext_id) + uint32_t ext_map_idx) { unsigned char *p; if (ctx->unknown_extensions == NULL) { ctx->unknown_extensions = - buffer_create_dynamic(default_pool, ext_id + 8); + buffer_create_dynamic(default_pool, ext_map_idx + 8); } - p = buffer_get_space_unsafe(ctx->unknown_extensions, ext_id, 1); + p = buffer_get_space_unsafe(ctx->unknown_extensions, ext_map_idx, 1); if (*p != 0) { /* we've already complained once */ return FALSE; @@ -358,11 +359,11 @@ const struct mail_index_ext *ext; const char *name; buffer_t *hdr_buf; - uint32_t ext_id; + uint32_t ext_map_idx; /* default to ignoring the following extension updates in case this intro is corrupted */ - ctx->cur_ext_id = 0; + ctx->cur_ext_map_idx = 0; ctx->cur_ext_ignore = TRUE; if (u->ext_id != (uint32_t)-1 && @@ -384,19 +385,20 @@ t_push(); if (u->ext_id != (uint32_t)-1) { name = NULL; - ext_id = u->ext_id; + ext_map_idx = u->ext_id; } else { name = t_strndup(u + 1, u->name_size); - ext_id = mail_index_map_lookup_ext(map, name); + if (!mail_index_map_lookup_ext(map, name, &ext_map_idx)) + ext_map_idx = (uint32_t)-1; } - if (ext_id != (uint32_t)-1) { + if (ext_map_idx != (uint32_t)-1) { /* exists already */ - ext = array_idx(&map->extensions, ext_id); + ext = array_idx(&map->extensions, ext_map_idx); if (u->reset_id == ext->reset_id) { /* check if we need to resize anything */ - sync_ext_resize(u, ext_id, ctx); + sync_ext_resize(u, ext_map_idx, ctx); ctx->cur_ext_ignore = FALSE; } else { /* extension was reset and this transaction hadn't @@ -405,7 +407,7 @@ } t_pop(); - ctx->cur_ext_id = ext_id; + ctx->cur_ext_map_idx = ext_map_idx; return 1; } @@ -426,11 +428,12 @@ /* register record offset initially using zero, sync_ext_reorder() will fix it. */ - ext_id = mail_index_map_register_ext(map, name, hdr_buf->used, - u->hdr_size, 0, u->record_size, - u->record_align, u->reset_id); + ext_map_idx = mail_index_map_register_ext(map, name, hdr_buf->used, + u->hdr_size, 0, + u->record_size, + u->record_align, u->reset_id); - ext = array_idx(&map->extensions, ext_id); + ext = array_idx(&map->extensions, ext_map_idx); /* <ext_hdr> <name> [padding] [header data] */ memset(&ext_hdr, 0, sizeof(ext_hdr)); @@ -456,10 +459,10 @@ t_pop(); mail_index_sync_init_handlers(ctx); - sync_ext_reorder(map, ext_id, 0); + sync_ext_reorder(map, ext_map_idx, 0); ctx->cur_ext_ignore = FALSE; - ctx->cur_ext_id = ext_id; + ctx->cur_ext_map_idx = ext_map_idx; return 1; } @@ -473,7 +476,7 @@ struct mail_index_record *rec; uint32_t i; - if (ctx->cur_ext_id == (uint32_t)-1) { + if (ctx->cur_ext_map_idx == (uint32_t)-1) { mail_index_sync_set_corrupted(ctx, "Extension reset without intro prefix"); return -1; @@ -485,7 +488,7 @@ accidentally used by other processes. */ map = mail_index_sync_get_atomic_map(ctx); - ext = array_idx_modifiable(&map->extensions, ctx->cur_ext_id); + ext = array_idx_modifiable(&map->extensions, ctx->cur_ext_map_idx); ext->reset_id = u->new_reset_id; memset(buffer_get_space_unsafe(map->hdr_copy_buf, ext->hdr_offset, @@ -513,7 +516,7 @@ struct mail_index_map *map = ctx->view->map; const struct mail_index_ext *ext; - if (ctx->cur_ext_id == (uint32_t)-1) { + if (ctx->cur_ext_map_idx == (uint32_t)-1) { mail_index_sync_set_corrupted(ctx, "Extension header update without intro prefix"); return -1; @@ -521,7 +524,7 @@ if (ctx->cur_ext_ignore) return 1; - ext = array_idx(&map->extensions, ctx->cur_ext_id); + ext = array_idx(&map->extensions, ctx->cur_ext_map_idx); buffer_write(map->hdr_copy_buf, ext->hdr_offset + u->offset, u + 1, u->size); map->hdr_base = map->hdr_copy_buf->data; @@ -542,14 +545,14 @@ uint32_t seq; int ret; - i_assert(ctx->cur_ext_id != (uint32_t)-1); + i_assert(ctx->cur_ext_map_idx != (uint32_t)-1); i_assert(!ctx->cur_ext_ignore); mail_index_lookup_uid_range(view, u->uid, u->uid, &seq, &seq); if (seq == 0) return 1; - ext = array_idx(&view->map->extensions, ctx->cur_ext_id); + ext = array_idx(&view->map->extensions, ctx->cur_ext_map_idx); rec = MAIL_INDEX_MAP_IDX(view->map, seq-1); old_data = PTR_OFFSET(rec, ext->record_offset);
--- a/src/lib-index/mail-index-sync-keywords.c Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index-sync-keywords.c Sun Sep 02 04:28:21 2007 +0300 @@ -78,7 +78,7 @@ } static int keywords_ext_register(struct mail_index_sync_map_ctx *ctx, - uint32_t ext_id, uint32_t reset_id, + uint32_t ext_map_idx, uint32_t reset_id, uint32_t hdr_size, uint32_t keywords_count) { buffer_t *ext_intro_buf; @@ -89,7 +89,7 @@ sizeof(*u) + sizeof("keywords")-1); u = buffer_append_space_unsafe(ext_intro_buf, sizeof(*u)); - u->ext_id = ext_id; + u->ext_id = ext_map_idx; u->reset_id = reset_id; u->hdr_size = hdr_size; u->record_size = (keywords_count + CHAR_BIT - 1) / CHAR_BIT; @@ -100,7 +100,7 @@ } u->record_align = 1; - if (ext_id == (uint32_t)-1) { + if (ext_map_idx == (uint32_t)-1) { u->name_size = strlen("keywords"); buffer_append(ext_intro_buf, "keywords", u->name_size); } @@ -116,7 +116,7 @@ const struct mail_index_ext *ext = NULL; struct mail_index_keyword_header *kw_hdr; struct mail_index_keyword_header_rec kw_rec; - uint32_t ext_id; + uint32_t ext_map_idx; buffer_t *buf = NULL; size_t keyword_len, rec_offset, name_offset, name_offset_root; unsigned int keywords_count; @@ -127,10 +127,11 @@ making sure the header is updated atomically. */ map = mail_index_sync_get_atomic_map(ctx); - ext_id = mail_index_map_lookup_ext(map, "keywords"); - if (ext_id != (uint32_t)-1) { + if (!mail_index_map_lookup_ext(map, "keywords", &ext_map_idx)) + ext_map_idx = (uint32_t)-1; + else { /* update existing header */ - ext = array_idx(&map->extensions, ext_id); + ext = array_idx(&map->extensions, ext_map_idx); buf = keywords_get_header_buf(map, ext, 1, &keywords_count, &rec_offset, &name_offset_root, &name_offset); @@ -169,7 +170,7 @@ /* if we need to grow the buffer, add some padding */ buffer_append_zero(buf, 128); - ret = keywords_ext_register(ctx, ext_id, + ret = keywords_ext_register(ctx, ext_map_idx, ext == NULL ? 0 : ext->reset_id, buf->used, keywords_count); if (ret <= 0) @@ -178,11 +179,9 @@ /* map may have changed */ map = ctx->view->map; - if (ext == NULL) { - ext_id = mail_index_map_lookup_ext(map, "keywords"); - i_assert(ext_id != (uint32_t)-1); - } - ext = array_idx(&map->extensions, ext_id); + if (!mail_index_map_lookup_ext(map, "keywords", &ext_map_idx)) + i_unreached(); + ext = array_idx(&map->extensions, ext_map_idx); i_assert(ext->hdr_size == buf->used); } @@ -253,7 +252,7 @@ const char *keyword_name; const struct mail_index_ext *ext; const uint32_t *uid, *end; - uint32_t seqset_offset, ext_id; + uint32_t seqset_offset, ext_map_idx; unsigned int keyword_idx; int ret; @@ -279,9 +278,11 @@ return ret; } - ext_id = mail_index_map_lookup_ext(ctx->view->map, "keywords"); - ext = ext_id == (uint32_t)-1 ? NULL : - array_idx(&ctx->view->map->extensions, ext_id); + if (!mail_index_map_lookup_ext(ctx->view->map, "keywords", + &ext_map_idx)) + ext = NULL; + else + ext = array_idx(&ctx->view->map->extensions, ext_map_idx); if (ext == NULL || ext->record_size == 0) { /* nothing to do */ if (rec->modify_type != MODIFY_REMOVE) { @@ -318,15 +319,14 @@ struct mail_index_record *rec; const struct mail_index_ext *ext; const struct mail_transaction_keyword_reset *end; - uint32_t ext_id, seq1, seq2; + uint32_t ext_map_idx, seq1, seq2; - ext_id = mail_index_map_lookup_ext(map, "keywords"); - if (ext_id == (uint32_t)-1) { + if (!mail_index_map_lookup_ext(map, "keywords", &ext_map_idx)) { /* nothing to do */ return 1; } - ext = array_idx(&map->extensions, ext_id); + ext = array_idx(&map->extensions, ext_map_idx); end = CONST_PTR_OFFSET(r, hdr->size); for (; r != end; r++) { mail_index_lookup_uid_range(ctx->view, r->uid1, r->uid2,
--- a/src/lib-index/mail-index-sync-private.h Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index-sync-private.h Sun Sep 02 04:28:21 2007 +0300 @@ -24,7 +24,7 @@ struct mail_index_sync_map_ctx { struct mail_index_view *view; - uint32_t cur_ext_id; + uint32_t cur_ext_map_idx; uint32_t ext_intro_seq; uoff_t ext_intro_offset, ext_intro_end_offset;
--- a/src/lib-index/mail-index-sync-update.c Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index-sync-update.c Sun Sep 02 04:28:21 2007 +0300 @@ -548,7 +548,7 @@ const struct mail_index_ext *ext; unsigned int i, record_size; - if (ctx->cur_ext_id == (uint32_t)-1) { + if (ctx->cur_ext_map_idx == (uint32_t)-1) { mail_index_sync_set_corrupted(ctx, "Extension record updated " "without intro prefix"); @@ -561,7 +561,8 @@ break; } - ext = array_idx(&ctx->view->map->extensions, ctx->cur_ext_id); + ext = array_idx(&ctx->view->map->extensions, + ctx->cur_ext_map_idx); /* the record is padded to 32bits in the transaction log */ record_size = (sizeof(*rec) + ext->record_size + 3) & ~3; @@ -606,7 +607,7 @@ { memset(sync_map_ctx, 0, sizeof(*sync_map_ctx)); sync_map_ctx->view = view; - sync_map_ctx->cur_ext_id = (uint32_t)-1; + sync_map_ctx->cur_ext_map_idx = (uint32_t)-1; sync_map_ctx->type = type; /* make sure we re-read it in case it has changed */
--- a/src/lib-index/mail-index.c Sun Sep 02 03:35:03 2007 +0300 +++ b/src/lib-index/mail-index.c Sun Sep 02 04:28:21 2007 +0300 @@ -222,18 +222,16 @@ const struct mail_index_keyword_header_rec *kw_rec; const char *name; unsigned int i, name_area_end_offset, old_count; - uint32_t ext_id; + uint32_t idx; map->keywords_read = TRUE; - ext_id = mail_index_map_lookup_ext(map, "keywords"); - if (ext_id == (uint32_t)-1) { + if (!mail_index_map_lookup_ext(map, "keywords", &idx)) { if (array_is_created(&map->keyword_idx_map)) array_clear(&map->keyword_idx_map); return 0; } - - ext = array_idx(&map->extensions, ext_id); + ext = array_idx(&map->extensions, idx); /* Extension header contains: - struct mail_index_keyword_header