[dovecot-cvs] dovecot/src/lib-index mail-cache.c, 1.58, 1.59 mail-index-lock.c, 1.37, 1.38 mail-index-private.h, 1.42, 1.43 mail-index-view.c, 1.30, 1.31 mail-index.c, 1.177, 1.178 mail-index.h, 1.138, 1.139

cras at dovecot.org cras at dovecot.org
Sun Dec 5 03:45:56 EET 2004


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

Modified Files:
	mail-cache.c mail-index-lock.c mail-index-private.h 
	mail-index-view.c mail-index.c mail-index.h 
Log Message:
Renamed mail_index_refresh() to mail_index_reopen_if_needed(). Added public
mail_index_refresh() which makes sure index is fully refreshed at the time.
Added mbox code to call it after mbox is locked to avoid using old mbox offsets.



Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- mail-cache.c	5 Dec 2004 01:38:17 -0000	1.58
+++ mail-cache.c	5 Dec 2004 01:45:53 -0000	1.59
@@ -310,7 +310,8 @@
 	if (MAIL_CACHE_IS_UNUSABLE(cache))
 		return 0;
 
-	if (mail_index_view_open_locked(cache->index, &view) < 0)
+	view = mail_index_view_open(cache->index);
+	if (mail_index_refresh(cache->index) < 0)
 		return -1;
 
 	ext = mail_index_view_get_ext(view, cache->ext_id);

Index: mail-index-lock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-lock.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mail-index-lock.c	13 Nov 2004 23:08:07 -0000	1.37
+++ mail-index-lock.c	5 Dec 2004 01:45:53 -0000	1.38
@@ -129,7 +129,7 @@
 
 	if (update_index && index->excl_lock_count == 0) {
 		i_assert(index->lock_type != F_WRLCK);
-		if ((ret2 = mail_index_refresh(index)) < 0)
+		if ((ret2 = mail_index_reopen_if_needed(index)) < 0)
 			return -1;
 		if (ret > 0 && ret2 == 0) {
 			i_assert(lock_type == F_RDLCK);
@@ -149,7 +149,7 @@
 		if (lock_type == F_WRLCK)
 			return 0;
 		if (update_index && index->lock_type == F_UNLCK) {
-			if (mail_index_refresh(index) < 0)
+			if (mail_index_reopen_if_needed(index) < 0)
 				return -1;
 		}
 

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- mail-index-private.h	5 Dec 2004 01:41:45 -0000	1.42
+++ mail-index-private.h	5 Dec 2004 01:45:53 -0000	1.43
@@ -172,7 +172,7 @@
 		       unsigned int timeout_secs);
 
 /* Reopen index file if it has changed. */
-int mail_index_refresh(struct mail_index *index);
+int mail_index_reopen_if_needed(struct mail_index *index);
 
 /* Map index file to memory, replacing the previous mapping for index.
    Returns 1 = ok, 0 = corrupted, -1 = error. If index needs fscking, it

Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mail-index-view.c	28 Nov 2004 23:19:53 -0000	1.30
+++ mail-index-view.c	5 Dec 2004 01:45:53 -0000	1.31
@@ -538,25 +538,6 @@
 	return view;
 }
 
-int mail_index_view_open_locked(struct mail_index *index,
-				struct mail_index_view **view_r)
-{
-	unsigned int lock_id;
-
-	if (mail_index_lock_shared(index, TRUE, &lock_id) < 0)
-		return -1;
-
-	*view_r = mail_index_view_open(index);
-	if (mail_index_view_lock_head(*view_r, FALSE) < 0) {
-		mail_index_view_close(*view_r);
-		mail_index_unlock(index, lock_id);
-		return -1;
-	}
-
-	mail_index_unlock(index, lock_id);
-	return 0;
-}
-
 const struct mail_index_ext *
 mail_index_view_get_ext(struct mail_index_view *view, uint32_t ext_id)
 {

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.177
retrieving revision 1.178
diff -u -d -r1.177 -r1.178
--- mail-index.c	5 Dec 2004 01:41:45 -0000	1.177
+++ mail-index.c	5 Dec 2004 01:45:53 -0000	1.178
@@ -1288,7 +1288,7 @@
 	return ret;
 }
 
-int mail_index_refresh(struct mail_index *index)
+int mail_index_reopen_if_needed(struct mail_index *index)
 {
 	struct stat st1, st2;
 
@@ -1314,6 +1314,32 @@
 	}
 }
 
+int mail_index_refresh(struct mail_index *index)
+{
+	unsigned int lock_id;
+	int ret;
+
+	if (index->excl_lock_count > 0) {
+		/* we have index exclusively locked, nothing could
+		   have changed. */
+		return 0;
+	}
+
+	if (!index->mmap_disable) {
+		/* reopening is all we need */
+		return mail_index_reopen_if_needed(index);
+	}
+
+	/* mail_index_map() simply reads latest changes from transaction log,
+	   which makes us fully refreshed. */
+	if (mail_index_lock_shared(index, TRUE, &lock_id) < 0)
+		return -1;
+
+	ret = mail_index_map(index, FALSE);
+	mail_index_unlock(index, lock_id);
+	return ret <= 0 ? -1 : 0;
+}
+
 struct mail_cache *mail_index_get_cache(struct mail_index *index)
 {
 	return index->cache;

Index: mail-index.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- mail-index.h	28 Nov 2004 23:19:53 -0000	1.138
+++ mail-index.h	5 Dec 2004 01:45:53 -0000	1.139
@@ -151,13 +151,15 @@
 
 struct mail_cache *mail_index_get_cache(struct mail_index *index);
 
+/* Refresh index so mail_index_lookup*() will return latest values. Note that
+   immediately after this call there may already be changes, so if you need to
+   rely on validity of the returned values, use some external locking for it. */
+int mail_index_refresh(struct mail_index *index);
+
 /* View can be used to look into index. Sequence numbers inside view change
    only when you synchronize it. The view acquires required locks
    automatically, but you'll have to drop them manually. */
 struct mail_index_view *mail_index_view_open(struct mail_index *index);
-/* Open view to latest index locked. */
-int mail_index_view_open_locked(struct mail_index *index,
-				struct mail_index_view **view_r);
 void mail_index_view_close(struct mail_index_view *view);
 
 /* Returns the index for given view. */



More information about the dovecot-cvs mailing list