dovecot-2.2: lib-index: dovecot.index file is no longer overwrit...

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 12 08:39:45 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/b7ac3897f3fd
changeset: 15212:b7ac3897f3fd
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 12 08:39:31 2012 +0300
description:
lib-index: dovecot.index file is no longer overwritten, so it doesn't need to be locked.

diffstat:

 src/lib-index/mail-index-lock.c        |  99 ----------------------------------
 src/lib-index/mail-index-map-read.c    |  16 +----
 src/lib-index/mail-index-map.c         |   6 --
 src/lib-index/mail-index-private.h     |   9 +--
 src/lib-index/mail-index-sync-update.c |   3 -
 src/lib-index/mail-index.c             |   6 --
 6 files changed, 3 insertions(+), 136 deletions(-)

diffs (296 lines):

diff -r 16a626119f7b -r b7ac3897f3fd src/lib-index/mail-index-lock.c
--- a/src/lib-index/mail-index-lock.c	Fri Oct 12 07:58:17 2012 +0300
+++ b/src/lib-index/mail-index-lock.c	Fri Oct 12 08:39:31 2012 +0300
@@ -36,45 +36,6 @@
 			      timeout_secs, lock_r);
 }
 
-static int mail_index_lock(struct mail_index *index,
-			   unsigned int timeout_secs, unsigned int *lock_id_r)
-{
-	int ret;
-
-	if (index->lock_type != F_UNLCK) {
-		/* file is already locked */
-		index->shared_lock_count++;
-		*lock_id_r = index->lock_id_counter;
-		return 1;
-	}
-
-	if (index->lock_method == FILE_LOCK_METHOD_DOTLOCK &&
-	    !MAIL_INDEX_IS_IN_MEMORY(index)) {
-		/* FIXME: exclusive locking will rewrite the index file every
-		   time. shouldn't really be needed.. reading doesn't require
-		   locks then, though */
-		index->shared_lock_count++;
-		index->lock_type = F_RDLCK;
-		*lock_id_r = index->lock_id_counter;
-		return 1;
-	}
-
-	i_assert(index->lock_type == F_UNLCK);
-	ret = mail_index_lock_fd(index, index->filepath, index->fd,
-				 F_RDLCK, timeout_secs,
-				 &index->file_lock);
-	if (ret <= 0)
-		return ret;
-
-	if (index->lock_type == F_UNLCK)
-		index->lock_id_counter += 2;
-	index->lock_type = F_RDLCK;
-
-	index->shared_lock_count++;
-	*lock_id_r = index->lock_id_counter;
-	return 1;
-}
-
 void mail_index_flush_read_cache(struct mail_index *index, const char *path,
 				 int fd, bool locked)
 {
@@ -91,63 +52,3 @@
 		nfs_flush_read_cache_unlocked(path, fd);
 	}
 }
-
-int mail_index_lock_shared(struct mail_index *index, unsigned int *lock_id_r)
-{
-	unsigned int timeout_secs;
-	int ret;
-
-	timeout_secs = I_MIN(MAIL_INDEX_SHARED_LOCK_TIMEOUT,
-			     index->max_lock_timeout_secs);
-	ret = mail_index_lock(index, timeout_secs, lock_id_r);
-	if (ret > 0) {
-		mail_index_flush_read_cache(index, index->filepath,
-					    index->fd, TRUE);
-		return 0;
-	}
-	if (ret < 0)
-		return -1;
-
-	mail_index_set_error(index,
-		"Timeout (%us) while waiting for shared lock for index file %s",
-		timeout_secs, index->filepath);
-	index->index_lock_timeout = TRUE;
-	return -1;
-}
-
-void mail_index_unlock(struct mail_index *index, unsigned int *_lock_id)
-{
-	unsigned int lock_id = *_lock_id;
-
-	*_lock_id = 0;
-
-	/* shared lock */
-	if (!mail_index_is_locked(index, lock_id)) {
-		/* unlocking some older generation of the index file.
-		   we've already closed the file so just ignore this. */
-		return;
-	}
-
-	i_assert(index->shared_lock_count > 0);
-	index->shared_lock_count--;
-
-	if (index->shared_lock_count == 0) {
-		index->lock_id_counter += 2;
-		index->lock_type = F_UNLCK;
-		if (index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-			if (!MAIL_INDEX_IS_IN_MEMORY(index))
-				file_unlock(&index->file_lock);
-		}
-		i_assert(index->file_lock == NULL);
-	}
-}
-
-bool mail_index_is_locked(struct mail_index *index, unsigned int lock_id)
-{
-	if ((index->lock_id_counter ^ lock_id) <= 1 && lock_id != 0) {
-		i_assert(index->lock_type != F_UNLCK);
-		return TRUE;
-	}
-
-	return FALSE;
-}
diff -r 16a626119f7b -r b7ac3897f3fd src/lib-index/mail-index-map-read.c
--- a/src/lib-index/mail-index-map-read.c	Fri Oct 12 07:58:17 2012 +0300
+++ b/src/lib-index/mail-index-map-read.c	Fri Oct 12 08:39:31 2012 +0300
@@ -235,8 +235,7 @@
 	return 1;
 }
 
-static int mail_index_read_map(struct mail_index_map *map, uoff_t file_size,
-			       unsigned int *lock_id)
+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 *handlerp;
@@ -264,7 +263,6 @@
 
 		/* ESTALE - reopen index file */
 		mail_index_close_file(index);
-		*lock_id = 0;
 
                 ret = mail_index_try_open_only(index);
 		if (ret <= 0) {
@@ -275,8 +273,6 @@
 			}
 			return -1;
 		}
-		if (mail_index_lock_shared(index, lock_id) < 0)
-			return -1;
 
 		if (fstat(index->fd, &st) == 0)
 			file_size = st.st_size;
@@ -297,7 +293,6 @@
 {
 	struct mail_index_map *old_map, *new_map;
 	struct stat st;
-	unsigned int lock_id;
 	uoff_t file_size;
 	bool use_mmap, unusable = FALSE;
 	int ret, try;
@@ -312,10 +307,6 @@
 		return 1;
 	}
 
-	/* the index file is still open, lock it */
-	if (mail_index_lock_shared(index, &lock_id) < 0)
-		return -1;
-
 	if ((index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0)
 		nfs_flush_attr_cache_fd_locked(index->filepath, index->fd);
 
@@ -324,7 +315,6 @@
 	else {
 		if (!ESTALE_FSTAT(errno)) {
 			mail_index_set_syscall_error(index, "fstat()");
-			mail_index_unlock(index, &lock_id);
 			return -1;
 		}
 		file_size = (uoff_t)-1;
@@ -337,11 +327,9 @@
 
 	new_map = mail_index_map_alloc(index);
 	if (use_mmap) {
-		new_map->rec_map->lock_id = lock_id;
 		ret = mail_index_mmap(new_map, file_size);
 	} else {
-		ret = mail_index_read_map(new_map, file_size, &lock_id);
-		mail_index_unlock(index, &lock_id);
+		ret = mail_index_read_map(new_map, file_size);
 	}
 	if (ret == 0) {
 		/* the index files are unusable */
diff -r 16a626119f7b -r b7ac3897f3fd src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Fri Oct 12 07:58:17 2012 +0300
+++ b/src/lib-index/mail-index-map.c	Fri Oct 12 08:39:31 2012 +0300
@@ -266,9 +266,6 @@
 static void mail_index_record_map_free(struct mail_index_map *map,
 				       struct mail_index_record_map *rec_map)
 {
-	if (rec_map->lock_id != 0)
-		mail_index_unlock(map->index, &rec_map->lock_id);
-
 	if (rec_map->buffer != NULL) {
 		i_assert(rec_map->mmap_base == NULL);
 		buffer_free(&rec_map->buffer);
@@ -466,8 +463,6 @@
 	if (map->rec_map->mmap_base == NULL)
 		return;
 
-	i_assert(map->rec_map->lock_id != 0);
-
 	if (array_count(&map->rec_map->maps) == 1)
 		new_map = map->rec_map;
 	else {
@@ -484,7 +479,6 @@
 		mail_index_record_map_unlink(map);
 		map->rec_map = new_map;
 	} else {
-		mail_index_unlock(map->index, &new_map->lock_id);
 		if (munmap(new_map->mmap_base, new_map->mmap_size) < 0)
 			mail_index_set_syscall_error(map->index, "munmap()");
 		new_map->mmap_base = NULL;
diff -r 16a626119f7b -r b7ac3897f3fd src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Fri Oct 12 07:58:17 2012 +0300
+++ b/src/lib-index/mail-index-private.h	Fri Oct 12 08:39:31 2012 +0300
@@ -119,7 +119,6 @@
 
 	void *mmap_base;
 	size_t mmap_size, mmap_used_size;
-	unsigned int lock_id;
 
 	buffer_t *buffer;
 
@@ -205,7 +204,7 @@
 	/* syncing will update this if non-NULL */
 	struct mail_index_transaction_commit_result *sync_commit_result;
 
-	int lock_type, shared_lock_count;
+	int lock_type;
 	unsigned int lock_id_counter;
 	enum file_lock_method lock_method;
 	unsigned int max_lock_timeout_secs;
@@ -273,12 +272,6 @@
 void mail_index_flush_read_cache(struct mail_index *index, const char *path,
 				 int fd, bool locked);
 
-/* Returns 0 = ok, -1 = error. */
-int mail_index_lock_shared(struct mail_index *index, unsigned int *lock_id_r);
-void mail_index_unlock(struct mail_index *index, unsigned int *lock_id);
-/* Returns TRUE if given lock_id is valid. */
-bool mail_index_is_locked(struct mail_index *index, unsigned int lock_id);
-
 int mail_index_lock_fd(struct mail_index *index, const char *path, int fd,
 		       int lock_type, unsigned int timeout_secs,
 		       struct file_lock **lock_r);
diff -r 16a626119f7b -r b7ac3897f3fd src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c	Fri Oct 12 07:58:17 2012 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Fri Oct 12 08:39:31 2012 +0300
@@ -75,9 +75,6 @@
 {
 	struct mail_index_map *map = ctx->view->map;
 
-	i_assert(MAIL_INDEX_MAP_IS_IN_MEMORY(map) ||
-		 map->rec_map->lock_id != 0);
-
 	if (map->refcount > 1) {
 		map = mail_index_map_clone(map);
 		mail_index_sync_replace_map(ctx, map);
diff -r 16a626119f7b -r b7ac3897f3fd src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Fri Oct 12 07:58:17 2012 +0300
+++ b/src/lib-index/mail-index.c	Fri Oct 12 08:39:31 2012 +0300
@@ -424,7 +424,6 @@
 	if (MAIL_INDEX_IS_IN_MEMORY(index))
 		return 0;
 
-	i_assert(index->map == NULL || index->map->rec_map->lock_id == 0);
 	ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD);
 	if (ret == 0) {
 		/* it's corrupted - recreate it */
@@ -571,7 +570,6 @@
 		i_strdup("(in-memory index)") :
 		i_strconcat(index->dir, "/", index->prefix, NULL);
 
-	index->shared_lock_count = 0;
 	index->lock_type = F_UNLCK;
 	index->lock_id_counter = 2;
 
@@ -629,7 +627,6 @@
 
 	index->lock_id_counter += 2;
 	index->lock_type = F_UNLCK;
-	index->shared_lock_count = 0;
 }
 
 void mail_index_close(struct mail_index *index)
@@ -693,9 +690,6 @@
 {
 	struct stat st1, st2;
 
-	i_assert(index->shared_lock_count == 0 ||
-		 (index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) == 0);
-
 	if (MAIL_INDEX_IS_IN_MEMORY(index))
 		return 0;
 


More information about the dovecot-cvs mailing list