[dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.33, 1.33.2.1 mail-cache-private.h, 1.29, 1.29.2.1 mail-cache.c, 1.80.2.3, 1.80.2.4

tss at dovecot.org tss at dovecot.org
Fri Oct 13 16:20:25 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv18206

Modified Files:
      Tag: branch_1_0
	mail-cache-lookup.c mail-cache-private.h mail-cache.c 
Log Message:
Delay opening the cache file until it's actually needed.



Index: mail-cache-lookup.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.33
retrieving revision 1.33.2.1
diff -u -d -r1.33 -r1.33.2.1
--- mail-cache-lookup.c	13 Jan 2006 20:26:13 -0000	1.33
+++ mail-cache-lookup.c	13 Oct 2006 15:19:52 -0000	1.33.2.1
@@ -185,6 +185,9 @@
 	uint32_t offset;
 	int ret;
 
+	if (!view->cache->opened)
+		(void)mail_cache_open_and_verify(view->cache);
+
         if (MAIL_CACHE_IS_UNUSABLE(view->cache))
 		return 0;
 
@@ -269,6 +272,9 @@
 	i_assert(seq > 0);
 	i_assert(field < view->cache->fields_count);
 
+	if (!view->cache->opened)
+		(void)mail_cache_open_and_verify(view->cache);
+
 	file_field = view->cache->field_file_map[field];
 	if (file_field == (uint32_t)-1)
 		return 0;

Index: mail-cache-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.29
retrieving revision 1.29.2.1
diff -u -d -r1.29 -r1.29.2.1
--- mail-cache-private.h	3 May 2006 20:07:13 -0000	1.29
+++ mail-cache-private.h	13 Oct 2006 15:19:52 -0000	1.29.2.1
@@ -147,6 +147,7 @@
 	unsigned int *file_field_map;
 	unsigned int file_fields_count;
 
+	unsigned int opened:1;
 	unsigned int locked:1;
 	unsigned int hdr_modified:1;
 	unsigned int field_header_write_pending:1;
@@ -176,6 +177,8 @@
 					  const void *data, size_t data_size,
 					  void *context);
 
+int mail_cache_open_and_verify(struct mail_cache *cache);
+
 /* Explicitly lock the cache file. Returns -1 if error, 1 if ok, 0 if we
    couldn't lock */
 int mail_cache_lock(struct mail_cache *cache);

Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.80.2.3
retrieving revision 1.80.2.4
diff -u -d -r1.80.2.3 -r1.80.2.4
--- mail-cache.c	13 Oct 2006 15:02:45 -0000	1.80.2.3
+++ mail-cache.c	13 Oct 2006 15:19:52 -0000	1.80.2.4
@@ -251,8 +251,10 @@
 	return 0;
 }
 
-static int mail_cache_open_and_verify(struct mail_cache *cache)
+static int mail_cache_try_open(struct mail_cache *cache)
 {
+	cache->opened = TRUE;
+
 	if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
 		return 0;
 
@@ -273,7 +275,22 @@
 	if (mail_cache_map(cache, 0, sizeof(struct mail_cache_header)) < 0)
 		return -1;
 
-	return mail_cache_header_fields_read(cache);
+	return 1;
+}
+
+int mail_cache_open_and_verify(struct mail_cache *cache)
+{
+	int ret;
+
+	ret = mail_cache_try_open(cache);
+	if (ret > 0)
+		ret = mail_cache_header_fields_read(cache);
+	if (ret < 0) {
+		/* failed for some reason - doesn't really matter,
+		   it's disabled for now. */
+		mail_cache_file_close(cache);
+	}
+	return ret;
 }
 
 static struct mail_cache *mail_cache_alloc(struct mail_index *index)
@@ -322,11 +339,6 @@
 	struct mail_cache *cache;
 
 	cache = mail_cache_alloc(index);
-	if (mail_cache_open_and_verify(cache) < 0) {
-		/* failed for some reason - doesn't really matter,
-		   it's disabled for now. */
-		mail_cache_file_close(cache);
-	}
 	return cache;
 }
 
@@ -335,6 +347,7 @@
 	struct mail_cache *cache;
 
 	cache = mail_cache_alloc(index);
+	cache->opened = TRUE;
 	cache->need_compress_file_seq = (uint32_t)-1;
 	return cache;
 }
@@ -388,6 +401,9 @@
 
 	i_assert(!cache->locked);
 
+	if (!cache->opened)
+		(void)mail_cache_open_and_verify(cache);
+
 	if (MAIL_CACHE_IS_UNUSABLE(cache) ||
 	    MAIL_INDEX_IS_IN_MEMORY(cache->index))
 		return 0;



More information about the dovecot-cvs mailing list