dovecot: mail_index_map now contains pointer to index, so all fu...

dovecot at dovecot.org dovecot at dovecot.org
Sun Jul 1 18:40:00 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/d9f319a9d6e0
changeset: 5853:d9f319a9d6e0
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jul 01 18:39:51 2007 +0300
description:
mail_index_map now contains pointer to index, so all functions taking map
parameter don't need index anymore.

diffstat:

11 files changed, 64 insertions(+), 70 deletions(-)
src/lib-index/mail-index-fsck.c          |    2 
src/lib-index/mail-index-map.c           |   65 ++++++++++++++----------------
src/lib-index/mail-index-private.h       |    9 +---
src/lib-index/mail-index-sync-ext.c      |    5 --
src/lib-index/mail-index-sync-keywords.c |    5 --
src/lib-index/mail-index-sync-private.h  |    2 
src/lib-index/mail-index-sync-update.c   |    7 +--
src/lib-index/mail-index-view-private.h  |    3 -
src/lib-index/mail-index-view-sync.c     |    4 -
src/lib-index/mail-index-view.c          |   20 ++++-----
src/lib-index/mail-index.c               |   12 ++---

diffs (truncated from 485 to 300 lines):

diff -r 2f9d38b82364 -r d9f319a9d6e0 src/lib-index/mail-index-fsck.c
--- a/src/lib-index/mail-index-fsck.c	Sun Jul 01 02:12:50 2007 +0300
+++ b/src/lib-index/mail-index-fsck.c	Sun Jul 01 18:39:51 2007 +0300
@@ -150,7 +150,7 @@ int mail_index_fsck(struct mail_index *i
 	i_warning("fscking index file %s", index->filepath);
 
 	map = mail_index_map_clone(index->map);
-	mail_index_unmap(index, &index->map);
+	mail_index_unmap(&index->map);
 	index->map = map;
 
 	ret = mail_index_fsck_map(index, map, &lock, &error);
diff -r 2f9d38b82364 -r d9f319a9d6e0 src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Sun Jul 01 02:12:50 2007 +0300
+++ b/src/lib-index/mail-index-map.c	Sun Jul 01 18:39:51 2007 +0300
@@ -59,8 +59,7 @@ uint32_t mail_index_map_lookup_ext(struc
 }
 
 uint32_t
-mail_index_map_register_ext(struct mail_index *index,
-			    struct mail_index_map *map, const char *name,
+mail_index_map_register_ext(struct mail_index_map *map, const char *name,
 			    uint32_t hdr_offset, uint32_t hdr_size,
 			    uint32_t record_offset, uint32_t record_size,
 			    uint32_t record_align, uint32_t reset_id)
@@ -85,7 +84,7 @@ mail_index_map_register_ext(struct mail_
 	ext->record_align = record_align;
 	ext->reset_id = reset_id;
 
-	ext->index_idx = mail_index_ext_register(index, name, hdr_size,
+	ext->index_idx = mail_index_ext_register(map->index, name, hdr_size,
 						 record_size, record_align);
 
 	/* Update index ext_id -> map ext_id mapping. Fill non-used
@@ -110,9 +109,9 @@ static size_t get_align(size_t name_len)
 	return MAIL_INDEX_HEADER_SIZE_ALIGN(size) - size;
 }
 
-static int mail_index_parse_extensions(struct mail_index *index,
-                                       struct mail_index_map *map)
-{
+static int mail_index_parse_extensions(struct mail_index_map *map)
+{
+	struct mail_index *index = map->index;
 	const struct mail_index_ext_header *ext_hdr;
 	unsigned int i, old_count;
 	const char *name;
@@ -200,7 +199,7 @@ static int mail_index_parse_extensions(s
 			return -1;
 		}
 
-		mail_index_map_register_ext(index, map, name,
+		mail_index_map_register_ext(map, name,
 					    offset, ext_hdr->hdr_size,
 					    ext_hdr->record_offset,
 					    ext_hdr->record_size,
@@ -270,9 +269,9 @@ static bool mail_index_check_header_comp
 	return TRUE;
 }
 
-static int mail_index_check_header(struct mail_index *index,
-				   struct mail_index_map *map)
-{
+static int mail_index_check_header(struct mail_index_map *map)
+{
+	struct mail_index *index = map->index;
 	const struct mail_index_header *hdr = &map->hdr;
 
 	if (!mail_index_check_header_compat(index, hdr, (uoff_t)-1))
@@ -322,8 +321,7 @@ static int mail_index_check_header(struc
 	return 1;
 }
 
-static void mail_index_map_clear(struct mail_index *index,
-				 struct mail_index_map *map)
+static void mail_index_map_clear(struct mail_index_map *map)
 {
 	if (map->buffer != NULL) {
 		i_assert(map->mmap_base == NULL);
@@ -332,7 +330,7 @@ static void mail_index_map_clear(struct 
 	} else if (map->mmap_base != NULL) {
 		i_assert(map->buffer == NULL);
 		if (munmap(map->mmap_base, map->mmap_size) < 0)
-			mail_index_set_syscall_error(index, "munmap()");
+			mail_index_set_syscall_error(map->index, "munmap()");
 		map->mmap_base = NULL;
 	}
 
@@ -358,9 +356,9 @@ static void mail_index_map_copy_hdr(stru
 	}
 }
 
-static int mail_index_mmap(struct mail_index *index, struct mail_index_map *map,
-			   uoff_t file_size)
-{
+static int mail_index_mmap(struct mail_index_map *map, uoff_t file_size)
+{
+	struct mail_index *index = map->index;
 	const struct mail_index_header *hdr;
 	unsigned int records_count;
 
@@ -452,9 +450,10 @@ static int mail_index_read_header(struct
 }
 
 static int
-mail_index_try_read_map(struct mail_index *index, struct mail_index_map *map,
+mail_index_try_read_map(struct mail_index_map *map,
 			uoff_t file_size, bool *retry_r, bool try_retry)
 {
+	struct mail_index *index = map->index;
 	const struct mail_index_header *hdr;
 	unsigned char read_buf[4096];
 	const void *buf;
@@ -563,10 +562,9 @@ mail_index_try_read_map(struct mail_inde
 	return 1;
 }
 
-static int
-mail_index_read_map(struct mail_index *index, struct mail_index_map *map,
-		    uoff_t file_size)
-{
+static int mail_index_read_map(struct mail_index_map *map, uoff_t file_size)
+{
+	struct mail_index *index = map->index;
 	mail_index_sync_lost_handler_t *const *handlers;
 	struct stat st;
 	unsigned int i, count;
@@ -585,7 +583,7 @@ mail_index_read_map(struct mail_index *i
 			ret = 0;
 			retry = try_retry;
 		} else {
-			ret = mail_index_try_read_map(index, map, file_size,
+			ret = mail_index_try_read_map(map, file_size,
 						      &retry, try_retry);
 		}
 		if (ret != 0 || !retry)
@@ -646,6 +644,7 @@ struct mail_index_map *mail_index_map_al
 
 	memset(&tmp_map, 0, sizeof(tmp_map));
 	mail_index_header_init(index, &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
@@ -693,18 +692,18 @@ static int mail_index_map_latest_file(st
 		file_size > MAIL_INDEX_MMAP_MIN_SIZE;
 
 	new_map = mail_index_map_alloc(index);
-	ret = use_mmap ? mail_index_mmap(index, new_map, file_size) :
-		mail_index_read_map(index, new_map, file_size);
+	ret = use_mmap ? mail_index_mmap(new_map, file_size) :
+		mail_index_read_map(new_map, file_size);
 	if (ret > 0) {
 		/* make sure the header is ok before using this mapping */
-		ret = mail_index_check_header(index, new_map);
+		ret = mail_index_check_header(new_map);
 		if (ret >= 0)
-			ret = mail_index_parse_extensions(index, new_map);
+			ret = mail_index_parse_extensions(new_map);
 		if (ret++ == 0)
 			index->fsck = TRUE;
 	}
 	if (ret <= 0) {
-		mail_index_unmap(index, &new_map);
+		mail_index_unmap(&new_map);
 		return ret;
 	}
 
@@ -715,7 +714,7 @@ static int mail_index_map_latest_file(st
 		new_map->hdr.log_file_tail_offset;
 	index->last_read_stat = st;
 
-	mail_index_unmap(index, map);
+	mail_index_unmap(map);
 	*map = new_map;
 	return 1;
 }
@@ -740,7 +739,7 @@ int mail_index_map(struct mail_index *in
 	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, &index->map, type, FALSE);
+		ret = mail_index_sync_map(&index->map, type, FALSE);
 	} else {
 		ret = 0;
 	}
@@ -757,8 +756,7 @@ int mail_index_map(struct mail_index *in
 		if (index->log->head != NULL) {
 			/* and update the map with the latest changes from
 			   transaction log */
-			ret = mail_index_sync_map(index, &index->map,
-						  type, TRUE);
+			ret = mail_index_sync_map(&index->map, type, TRUE);
 		}
 
 		/* we need the lock only if we didn't move the map to memory */
@@ -772,7 +770,7 @@ int mail_index_map(struct mail_index *in
 	return ret;
 }
 
-void mail_index_unmap(struct mail_index *index, struct mail_index_map **_map)
+void mail_index_unmap(struct mail_index_map **_map)
 {
 	struct mail_index_map *map = *_map;
 
@@ -781,7 +779,7 @@ void mail_index_unmap(struct mail_index 
 		return;
 
 	i_assert(map->refcount == 0);
-	mail_index_map_clear(index, map);
+	mail_index_map_clear(map);
 	if (map->extension_pool != NULL)
 		pool_unref(map->extension_pool);
 	if (array_is_created(&map->keyword_idx_map))
@@ -841,6 +839,7 @@ struct mail_index_map *mail_index_map_cl
 	unsigned int i, count;
 
 	mem_map = i_new(struct mail_index_map, 1);
+	mem_map->index = map->index;
 	mem_map->refcount = 1;
 
 	mail_index_map_copy(mem_map, map);
diff -r 2f9d38b82364 -r d9f319a9d6e0 src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Sun Jul 01 02:12:50 2007 +0300
+++ b/src/lib-index/mail-index-private.h	Sun Jul 01 18:39:51 2007 +0300
@@ -103,6 +103,7 @@ struct mail_index_registered_ext {
 };
 
 struct mail_index_map {
+	struct mail_index *index;
 	int refcount;
 
 	struct mail_index_header hdr;
@@ -262,15 +263,14 @@ int mail_index_get_last_written_header(s
 int mail_index_get_last_written_header(struct mail_index *index,
 				       struct mail_index_header *hdr_r);
 /* Unreference given mapping and unmap it if it's dropped to zero. */
-void mail_index_unmap(struct mail_index *index, struct mail_index_map **map);
+void mail_index_unmap(struct mail_index_map **map);
 struct mail_index_map *mail_index_map_clone(const struct mail_index_map *map);
 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);
 uint32_t
-mail_index_map_register_ext(struct mail_index *index,
-			    struct mail_index_map *map, const char *name,
+mail_index_map_register_ext(struct mail_index_map *map, const char *name,
 			    uint32_t hdr_offset, uint32_t hdr_size,
 			    uint32_t record_offset, uint32_t record_size,
 			    uint32_t record_align, uint32_t reset_id);
@@ -279,8 +279,7 @@ const struct mail_index_ext *
 const struct mail_index_ext *
 mail_index_view_get_ext(struct mail_index_view *view, uint32_t ext_id);
 
-int mail_index_map_parse_keywords(struct mail_index *index,
-                                  struct mail_index_map *map);
+int mail_index_map_parse_keywords(struct mail_index_map *map);
 
 void mail_index_view_transaction_ref(struct mail_index_view *view);
 void mail_index_view_transaction_unref(struct mail_index_view *view);
diff -r 2f9d38b82364 -r d9f319a9d6e0 src/lib-index/mail-index-sync-ext.c
--- a/src/lib-index/mail-index-sync-ext.c	Sun Jul 01 02:12:50 2007 +0300
+++ b/src/lib-index/mail-index-sync-ext.c	Sun Jul 01 18:39:51 2007 +0300
@@ -400,9 +400,8 @@ int mail_index_sync_ext_intro(struct mai
 	   sync_ext_reorder() will fix it. */
 	hdr_offset = hdr_buf->used + sizeof(ext_hdr) + strlen(name);
 	hdr_offset = MAIL_INDEX_HEADER_SIZE_ALIGN(hdr_offset);
-	ext_id = mail_index_map_register_ext(ctx->view->index, map, name,
-					     hdr_offset, u->hdr_size, 0,
-					     u->record_size, u->record_align,
+	ext_id = mail_index_map_register_ext(map, name, hdr_offset, u->hdr_size,
+					     0, u->record_size, u->record_align,
 					     u->reset_id);
 
 	ext = array_idx(&map->extensions, ext_id);
diff -r 2f9d38b82364 -r d9f319a9d6e0 src/lib-index/mail-index-sync-keywords.c
--- a/src/lib-index/mail-index-sync-keywords.c	Sun Jul 01 02:12:50 2007 +0300
+++ b/src/lib-index/mail-index-sync-keywords.c	Sun Jul 01 18:39:51 2007 +0300
@@ -16,7 +16,7 @@ keyword_lookup(struct mail_index_sync_ma
 	unsigned int i, count, keyword_idx;
 
 	if (!map->keywords_read) {
-		if (mail_index_map_parse_keywords(ctx->view->index, map) < 0)
+		if (mail_index_map_parse_keywords(map) < 0)
 			return -1;
 	}
 	if (array_is_created(&map->keyword_idx_map) &&
@@ -290,8 +290,7 @@ int mail_index_sync_keywords(struct mail
 	}
 
 	if (!ctx->view->map->keywords_read) {
-		if (mail_index_map_parse_keywords(ctx->view->index,
-                                                  ctx->view->map) < 0)
+		if (mail_index_map_parse_keywords(ctx->view->map) < 0)
 			return -1;
 	}
 
diff -r 2f9d38b82364 -r d9f319a9d6e0 src/lib-index/mail-index-sync-private.h
--- a/src/lib-index/mail-index-sync-private.h	Sun Jul 01 02:12:50 2007 +0300


More information about the dovecot-cvs mailing list