]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Remove mail_index_map.hdr_base
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 19 Jan 2021 10:51:07 +0000 (12:51 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 3 May 2021 13:01:05 +0000 (13:01 +0000)
It was just causing unnecessary complexity. Simpler to just keep
hdr_copy_buf always up-to-date and access it directly.

src/lib-index/mail-index-fsck.c
src/lib-index/mail-index-map-read.c
src/lib-index/mail-index-map.c
src/lib-index/mail-index-modseq.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-update.c
src/lib-index/test-mail-index-write.c

index a6b2eaf434b6c4dce42fd99b05dbbed82864010c..d8eb0bf3cc818939cfeb5fe8b9c86ad87904dad4 100644 (file)
@@ -248,7 +248,6 @@ mail_index_fsck_keywords(struct mail_index *index, struct mail_index_map *map,
                diff = dest->used - ext_hdr->hdr_size;
                buffer_copy(map->hdr_copy_buf, hdr_offset + diff,
                            map->hdr_copy_buf, hdr_offset, SIZE_MAX);
-               map->hdr_base = map->hdr_copy_buf->data;
                hdr->header_size += diff;
                *offset_p += diff;
 
@@ -321,7 +320,6 @@ mail_index_fsck_extensions(struct mail_index *index, struct mail_index_map *map,
                buffer_copy(map->hdr_copy_buf, offset,
                            map->hdr_copy_buf, next_offset, SIZE_MAX);
                buffer_set_used_size(map->hdr_copy_buf, hdr->header_size);
-               map->hdr_base = map->hdr_copy_buf->data;
        }
 }
 
index 7ebe42d3ce3513e138a3433d1ec0d13812a33c38..5880b80895e0ea556c1f5103b68215b93affdb8b 100644 (file)
@@ -100,7 +100,6 @@ static int mail_index_mmap(struct mail_index_map *map, uoff_t file_size)
        buffer_set_used_size(map->hdr_copy_buf, 0);
        buffer_append(map->hdr_copy_buf, rec_map->mmap_base, hdr->header_size);
 
-       map->hdr_base = rec_map->mmap_base;
        rec_map->records = PTR_OFFSET(rec_map->mmap_base, map->hdr.header_size);
        return 1;
 }
@@ -244,7 +243,6 @@ mail_index_try_read_map(struct mail_index_map *map,
        map->rec_map->records_count = records_count;
 
        mail_index_map_copy_hdr(map, hdr);
-       map->hdr_base = map->hdr_copy_buf->data;
        i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
        return 1;
 }
index fbd7df662fc504525441d74afc9dd0a0e3a4fcdf..9f28d59626d9821fa13454285798e2755e7f89f8 100644 (file)
@@ -255,8 +255,9 @@ struct mail_index_map *mail_index_map_alloc(struct mail_index *index)
 
        i_zero(&tmp_map);
        mail_index_header_init(index, &tmp_map.hdr);
+       tmp_map.hdr_copy_buf = t_buffer_create(sizeof(tmp_map.hdr));
+       buffer_append(tmp_map.hdr_copy_buf, &tmp_map.hdr, sizeof(tmp_map.hdr));
        tmp_map.index = index;
-       tmp_map.hdr_base = &tmp_map.hdr;
 
        /* a bit kludgy way to do this, but it initializes everything
           nicely and correctly */
@@ -359,7 +360,6 @@ static void mail_index_map_copy_header(struct mail_index_map *dest,
                             MAIL_INDEX_MAP_HDR_OFFSET(src, src->hdr.base_header_size),
                             src->hdr.header_size - src->hdr.base_header_size);
        }
-       dest->hdr_base = buffer_get_modifiable_data(dest->hdr_copy_buf, NULL);
        i_assert(dest->hdr_copy_buf->used == dest->hdr.header_size);
 }
 
index 2f9bff01dab7c810a18700bd2f79a90b1bdb5136..24b10d878122e4bc7e45e40544245e466fdad4c4 100644 (file)
@@ -510,7 +510,6 @@ static void mail_index_modseq_update_header(struct mail_index_modseq_sync *ctx)
 
                buffer_write(map->hdr_copy_buf, ext->hdr_offset,
                             &new_modseq_hdr, sizeof(new_modseq_hdr));
-               map->hdr_base = map->hdr_copy_buf->data;
                i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
        }
 }
index 2a41753ea0977004375076f566a7b54945ec4394..150532a068fc4aaab063007c70a16a6b954a790e 100644 (file)
@@ -119,13 +119,16 @@ struct mail_index_record_map {
 };
 
 #define MAIL_INDEX_MAP_HDR_OFFSET(map, hdr_offset) \
-       CONST_PTR_OFFSET((map)->hdr_base, hdr_offset)
+       CONST_PTR_OFFSET((map)->hdr_copy_buf->data, hdr_offset)
 struct mail_index_map {
        struct mail_index *index;
        int refcount;
 
+       /* Copy of the base header for convenience. Note that base_header_size
+          may be smaller or larger than this struct. If it's smaller, the last
+          fields in the struct are filled with zeroes. */
        struct mail_index_header hdr;
-       const void *hdr_base;
+       /* Copy of the full header. */
        buffer_t *hdr_copy_buf;
 
        pool_t extension_pool;
index e13beea56f06d86fffe224e56dcbfcb55ef430c1..ee6bfec23c84f872116f47328bee428a280a59c0 100644 (file)
@@ -307,7 +307,6 @@ sync_ext_resize(const struct mail_transaction_ext_intro *u,
        }
 
        i_assert((map->hdr_copy_buf->used % sizeof(uint64_t)) == 0);
-       map->hdr_base = map->hdr_copy_buf->data;
        map->hdr.header_size = map->hdr_copy_buf->used;
 
        ext_hdr = get_ext_header(map, ext);
@@ -403,7 +402,6 @@ mail_index_sync_ext_init_new(struct mail_index_sync_map_ctx *ctx,
        i_assert((hdr_buf->used % sizeof(uint64_t)) == 0);
 
        map->hdr.header_size = hdr_buf->used;
-       map->hdr_base = hdr_buf->data;
 
         mail_index_sync_init_handlers(ctx);
        sync_ext_reorder(map, ext_map_idx, 0);
@@ -556,7 +554,6 @@ static void mail_index_sync_ext_clear(struct mail_index_view *view,
 
        memset(buffer_get_space_unsafe(map->hdr_copy_buf, ext->hdr_offset,
                                       ext->hdr_size), 0, ext->hdr_size);
-       map->hdr_base = map->hdr_copy_buf->data;
        i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
 
        for (seq = 1; seq <= view->map->rec_map->records_count; seq++) {
@@ -622,7 +619,6 @@ int mail_index_sync_ext_hdr_update(struct mail_index_sync_map_ctx *ctx,
        }
 
        buffer_write(map->hdr_copy_buf, ext->hdr_offset + offset, data, size);
-       map->hdr_base = map->hdr_copy_buf->data;
        i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
 
        if (ext->index_idx == ctx->view->index->modseq_ext_id)
index 1cbe07a765ec1d1a0caff08e75ecc1940fa36870..2c45156d7e4a8883dfe925f3c662844fbdf602dc 100644 (file)
@@ -189,7 +189,6 @@ keywords_header_add(struct mail_index_sync_map_ctx *ctx,
        }
 
        buffer_copy(map->hdr_copy_buf, ext->hdr_offset, buf, 0, buf->used);
-       map->hdr_base = map->hdr_copy_buf->data;
        i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
 
        if (mail_index_map_parse_keywords(map) < 0)
index 653d8a9346760d60ad0c8e3d7dce2f76f015c0c6..0f194d93a95386b8f05a33cc36ffc113494990a0 100644 (file)
@@ -493,7 +493,6 @@ static int sync_header_update(const struct mail_transaction_header_update *u,
        }
 
        buffer_write(map->hdr_copy_buf, u->offset, u + 1, u->size);
-       map->hdr_base = map->hdr_copy_buf->data;
        i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
 
        /* @UNSAFE */
@@ -988,17 +987,6 @@ int mail_index_sync_map(struct mail_index_map **_map,
        if (had_dirty)
                map->hdr.flags &= ENUM_NEGATE(MAIL_INDEX_HDR_FLAG_HAVE_DIRTY);
 
-       if (map->hdr_base != map->hdr_copy_buf->data) {
-               /* if syncing updates the header, it updates hdr_copy_buf
-                  and updates hdr_base to hdr_copy_buf. so the buffer must
-                  initially contain a valid header or we'll break it when
-                  writing it. */
-               buffer_set_used_size(map->hdr_copy_buf, 0);
-               buffer_append(map->hdr_copy_buf, map->hdr_base,
-                             map->hdr.header_size);
-               map->hdr_base = map->hdr_copy_buf->data;
-       }
-
        mail_transaction_log_view_get_prev_pos(view->log_view,
                                               &prev_seq, &prev_offset);
 
index 1559ab38ecea060f713d6ef2b2715388f6481bf7..1b95424140ec598a6f3528ac39c6765c4e48364c 100644 (file)
@@ -88,6 +88,7 @@ static void test_mail_index_write(void)
        struct mail_index_record_map rec_map = {
                .records_count = 0,
        };
+       buffer_t hdr_copy;
        struct mail_index_map map = {
                .hdr = {
                        .indexid = TEST_INDEXID,
@@ -95,8 +96,10 @@ static void test_mail_index_write(void)
                        .log_file_tail_offset = 100,
                        .log_file_head_offset = LOG_FILE1_HEAD_OFFSET,
                },
+               .hdr_copy_buf = &hdr_copy,
                .rec_map = &rec_map,
        };
+       buffer_create_from_data(&hdr_copy, &map.hdr, sizeof(&map.hdr));
        struct mail_index index = {
                .event = event_create(NULL),
                .log = &log,