[dovecot-cvs] dovecot/src/lib-index mail-cache-compress.c, 1.45, 1.46 mail-cache-private.h, 1.33, 1.34 mail-cache.c, 1.88, 1.89 mail-hash.c, 1.25, 1.26 mail-index-lock.c, 1.55, 1.56 mail-index-private.h, 1.74, 1.75 mail-index.c, 1.245, 1.246 mail-index.h, 1.162, 1.163 mail-transaction-log-private.h, 1.16, 1.17 mail-transaction-log.c, 1.115, 1.116

tss at dovecot.org tss at dovecot.org
Wed Dec 6 15:08:39 UTC 2006


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

Modified Files:
	mail-cache-compress.c mail-cache-private.h mail-cache.c 
	mail-hash.c mail-index-lock.c mail-index-private.h 
	mail-index.c mail-index.h mail-transaction-log-private.h 
	mail-transaction-log.c 
Log Message:
Lock handling changes. Everything goes through file-lock API now and there's
only a single enum listing the different lock methods. This change exposed
some unneeded (or possibly even wrong?) unlock calls in index file handling
which were fixed.



Index: mail-cache-compress.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-compress.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mail-cache-compress.c	12 Nov 2006 18:02:15 -0000	1.45
+++ mail-cache-compress.c	6 Dec 2006 15:08:32 -0000	1.46
@@ -273,7 +273,8 @@
 }
 
 static int mail_cache_compress_locked(struct mail_cache *cache,
-				      struct mail_index_view *view)
+				      struct mail_index_view *view,
+				      bool *unlock)
 {
 	struct dotlock *dotlock;
         mode_t old_mask;
@@ -300,6 +301,12 @@
 		/* was just compressed, forget this */
 		cache->need_compress_file_seq = 0;
 		file_dotlock_delete(&dotlock);
+
+		if (*unlock) {
+			(void)mail_cache_unlock(cache);
+			*unlock = FALSE;
+		}
+
 		return mail_cache_reopen(cache);
 	}
 
@@ -328,6 +335,11 @@
 		return -1;
 	}
 
+	if (*unlock) {
+		(void)mail_cache_unlock(cache);
+		*unlock = FALSE;
+	}
+
 	mail_cache_file_close(cache);
 	cache->fd = fd;
 
@@ -345,15 +357,16 @@
 
 int mail_cache_compress(struct mail_cache *cache, struct mail_index_view *view)
 {
+	bool unlock = FALSE;
 	int ret;
 
 	if (MAIL_INDEX_IS_IN_MEMORY(cache->index))
 		return 0;
 
-	if (cache->index->lock_method == MAIL_INDEX_LOCK_DOTLOCK) {
+	if (cache->index->lock_method == FILE_LOCK_METHOD_DOTLOCK) {
 		/* we're using dotlocking, cache file creation itself creates
 		   the dotlock file we need. */
-		return mail_cache_compress_locked(cache, view);
+		return mail_cache_compress_locked(cache, view, &unlock);
 	}
 
 	switch (mail_cache_lock(cache)) {
@@ -362,12 +375,15 @@
 	case 0:
 		/* couldn't lock, either it's broken or doesn't exist.
 		   just start creating it. */
-		return mail_cache_compress_locked(cache, view);
+		return mail_cache_compress_locked(cache, view, &unlock);
 	default:
 		/* locking succeeded. */
-		ret = mail_cache_compress_locked(cache, view);
-		if (mail_cache_unlock(cache) < 0)
-			ret = -1;
+		unlock = TRUE;
+		ret = mail_cache_compress_locked(cache, view, &unlock);
+		if (unlock) {
+			if (mail_cache_unlock(cache) < 0)
+				ret = -1;
+		}
 		return ret;
 	}
 }

Index: mail-cache-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- mail-cache-private.h	13 Oct 2006 15:33:03 -0000	1.33
+++ mail-cache-private.h	6 Dec 2006 15:08:32 -0000	1.34
@@ -129,6 +129,7 @@
 
 	struct dotlock_settings dotlock_settings;
 	struct dotlock *dotlock;
+	struct file_lock *file_lock;
 
 	const struct mail_cache_header *hdr;
 	struct mail_cache_header hdr_copy;

Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- mail-cache.c	13 Oct 2006 15:33:03 -0000	1.88
+++ mail-cache.c	6 Dec 2006 15:08:32 -0000	1.89
@@ -59,6 +59,10 @@
 	cache->hdr = NULL;
 	cache->mmap_length = 0;
 
+	if (cache->file_lock != NULL)
+		file_lock_free(&cache->file_lock);
+	cache->locked = FALSE;
+
 	if (cache->fd != -1) {
 		if (close(cache->fd) < 0)
 			mail_cache_set_syscall_error(cache, "close()");
@@ -71,6 +75,8 @@
 	struct mail_index_view *view;
 	const struct mail_index_ext *ext;
 
+	i_assert(!cache->locked);
+
 	if (MAIL_CACHE_IS_UNUSABLE(cache) &&
 	    (cache->need_compress_file_seq != 0 ||
 	     MAIL_INDEX_IS_IN_MEMORY(cache->index))) {
@@ -372,17 +378,25 @@
 
 static int mail_cache_lock_file(struct mail_cache *cache, int lock_type)
 {
-	if (cache->index->lock_method != MAIL_INDEX_LOCK_DOTLOCK) {
+	if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
+		i_assert(cache->file_lock == NULL);
 		return mail_index_lock_fd(cache->index, cache->filepath,
 					  cache->fd, lock_type,
-					  MAIL_INDEX_LOCK_SECS);
-	}
-
-	if (lock_type != F_UNLCK) {
+					  MAIL_INDEX_LOCK_SECS,
+					  &cache->file_lock);
+	} else {
+		i_assert(cache->dotlock == NULL);
 		return file_dotlock_create(&cache->dotlock_settings,
 					   cache->filepath, 0, &cache->dotlock);
-	} else
-		return file_dotlock_delete(&cache->dotlock);
+	}
+}
+
+static void mail_cache_unlock_file(struct mail_cache *cache)
+{
+	if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK)
+		file_unlock(&cache->file_lock);
+	else
+		(void)file_dotlock_delete(&cache->dotlock);
 }
 
 int mail_cache_lock(struct mail_cache *cache)
@@ -500,7 +514,7 @@
 		mail_cache_update_need_compress(cache);
 	}
 
-	(void)mail_cache_lock_file(cache, F_UNLCK);
+	mail_cache_unlock_file(cache);
 	return ret;
 }
 

Index: mail-hash.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-hash.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mail-hash.c	26 Nov 2006 15:20:11 -0000	1.25
+++ mail-hash.c	6 Dec 2006 15:08:32 -0000	1.26
@@ -51,6 +51,7 @@
 	size_t change_offset_start, change_offset_end;
 
 	int lock_type;
+	struct file_lock *file_lock;
 	struct dotlock *dotlock;
 
 	struct mail_hash_header *hdr;
@@ -401,19 +402,28 @@
 {
 	i_assert(hash->fd != -1);
 
-	if (hash->index->lock_method != MAIL_INDEX_LOCK_DOTLOCK) {
+	if (hash->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
+		i_assert(hash->file_lock == NULL);
 		return mail_index_lock_fd(hash->index, hash->filepath, hash->fd,
-					  lock_type, MAIL_HASH_TIMEOUT_SECS);
-	}
-
-	if (lock_type != F_UNLCK) {
+					  lock_type, MAIL_HASH_TIMEOUT_SECS,
+					  &hash->file_lock);
+	} else {
+		i_assert(hash->dotlock == NULL);
 		return file_dotlock_create(&dotlock_settings, hash->filepath,
 					   0, &hash->dotlock);
-	} else {
-		return file_dotlock_delete(&hash->dotlock);
 	}
 }
 
+static void mail_hash_file_unlock(struct mail_hash *hash)
+{
+	i_assert(hash->fd != -1);
+
+	if (hash->index->lock_method != FILE_LOCK_METHOD_DOTLOCK)
+		file_unlock(&hash->file_lock);
+	else
+		(void)file_dotlock_delete(&hash->dotlock);
+}
+
 static int mail_hash_file_open(struct mail_hash *hash, bool lock)
 {
 	int ret;
@@ -432,7 +442,7 @@
 
 		ret = mail_hash_file_map(hash, FALSE);
 		if (hash->fd != -1)
-			(void)mail_hash_file_lock(hash, F_UNLCK);
+			mail_hash_file_unlock(hash);
 	} else {
 		if (mail_hash_file_lock(hash, F_WRLCK) <= 0)
 			return -1;
@@ -649,7 +659,7 @@
 			return ret;
 
 		if (mail_hash_file_map(hash, TRUE) <= 0) {
-			(void)mail_hash_file_lock(hash, F_UNLCK);
+			mail_hash_file_unlock(hash);
 			return -1;
 		}
 	}
@@ -671,7 +681,7 @@
 
 	if (hash->fd != -1) {
 		(void)mail_hash_file_write_changes(hash);
-		(void)mail_hash_file_lock(hash, F_UNLCK);
+		mail_hash_file_unlock(hash);
 	}
 }
 

Index: mail-index-lock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-lock.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- mail-index-lock.c	24 Oct 2006 16:10:26 -0000	1.55
+++ mail-index-lock.c	6 Dec 2006 15:08:32 -0000	1.56
@@ -31,95 +31,17 @@
 #  include <sys/file.h>
 #endif
 
-#define MAIL_INDEX_LOCK_WAIT_TIME 120
-
 int mail_index_lock_fd(struct mail_index *index, const char *path, int fd,
-		       int lock_type, unsigned int timeout_secs)
+		       int lock_type, unsigned int timeout_secs,
+		       struct file_lock **lock_r)
 {
-	int ret;
-
 	if (fd == -1) {
 		i_assert(MAIL_INDEX_IS_IN_MEMORY(index));
 		return 1;
 	}
 
-	if (timeout_secs != 0)
-		alarm(MAIL_INDEX_LOCK_WAIT_TIME);
-
-	switch (index->lock_method) {
-	case MAIL_INDEX_LOCK_FCNTL: {
-#ifndef HAVE_FCNTL
-		i_fatal("fcntl() locks not supported");
-#else
-		struct flock fl;
-
-		fl.l_type = lock_type;
-		fl.l_whence = SEEK_SET;
-		fl.l_start = 0;
-		fl.l_len = 0;
-
-		ret = fcntl(fd, timeout_secs ? F_SETLKW : F_SETLK, &fl);
-		if (timeout_secs != 0) alarm(0);
-
-		if (ret == 0)
-			return 1;
-
-		if (timeout_secs == 0 &&
-		    (errno == EACCES || errno == EAGAIN)) {
-			/* locked by another process */
-			return 0;
-		}
-
-		if (errno == EINTR) {
-			/* most likely alarm hit, meaning we timeouted.
-			   even if not, we probably want to be killed
-			   so stop blocking. */
-			errno = EAGAIN;
-			return 0;
-		}
-		mail_index_file_set_syscall_error(index, path, "fcntl()");
-		return -1;
-#endif
-	}
-	case MAIL_INDEX_LOCK_FLOCK: {
-#ifndef HAVE_FLOCK
-		i_fatal("flock() locks not supported "
-			"(see lock_method setting in config file)");
-#else
-		int operation = timeout_secs != 0 ? 0 : LOCK_NB;
-
-		switch (lock_type) {
-		case F_RDLCK:
-			operation |= LOCK_SH;
-			break;
-		case F_WRLCK:
-			operation |= LOCK_EX;
-			break;
-		case F_UNLCK:
-			operation |= LOCK_UN;
-			break;
-		}
-
-		ret = flock(fd, operation);
-		if (timeout_secs != 0) alarm(0);
-
-		if (ret == 0)
-			return 1;
-
-		if (errno == EWOULDBLOCK || errno == EINTR) {
-			/* a) locked by another process,
-			   b) timeouted */
-			return 0;
-		}
-		mail_index_file_set_syscall_error(index, path, "flock()");
-		return -1;
-#endif
-	}
-	case MAIL_INDEX_LOCK_DOTLOCK:
-		/* we shouldn't get here */
-		break;
-	}
-	i_unreached();
+	return file_wait_lock(fd, path, lock_type, index->lock_method,
+			      timeout_secs, lock_r);
 }
 
 static int mail_index_lock(struct mail_index *index, int lock_type,
@@ -161,7 +83,7 @@
 		return 1;
 	}
 
-	if (index->lock_method == MAIL_INDEX_LOCK_DOTLOCK &&
+	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
@@ -180,8 +102,10 @@
 	}
 
 	if (lock_type == F_RDLCK || !index->log_locked) {
+		i_assert(index->file_lock == NULL);
 		ret = mail_index_lock_fd(index, index->filepath, index->fd,
-					 lock_type, timeout_secs);
+					 lock_type, timeout_secs,
+					 &index->file_lock);
 	} else {
 		/* this is kind of kludgy. we wish to avoid deadlocks while
 		   trying to lock transaction log, but it can happen if our
@@ -197,8 +121,13 @@
 		   so, the workaround for this problem is that we simply try
 		   locking once. if it doesn't work, just rewrite the file.
 		   hopefully there won't be any other deadlocking issues. :) */
-		ret = mail_index_lock_fd(index, index->filepath, index->fd,
-					 lock_type, 0);
+		if (index->file_lock == NULL) {
+			ret = mail_index_lock_fd(index, index->filepath,
+						 index->fd, lock_type, 0,
+						 &index->file_lock);
+		} else {
+			ret = file_lock_try_update(index->file_lock, lock_type);
+		}
 	}
 	if (ret <= 0)
 		return ret;
@@ -431,18 +360,18 @@
 	map->write_seq_first = map->write_seq_last = 0;
 }
 
-static void mail_index_excl_unlock_finish(struct mail_index *index)
+static bool mail_index_excl_unlock_finish(struct mail_index *index)
 {
 	if (index->map != NULL && index->map->write_to_disk)
 		mail_index_write_map(index);
 
 	if (index->shared_lock_count > 0 &&
-	    index->lock_method != MAIL_INDEX_LOCK_DOTLOCK) {
+	    index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
 		/* leave ourself shared locked. */
-		(void)mail_index_lock_fd(index, index->filepath, index->fd,
-					 F_RDLCK, 0);
 		i_assert(index->lock_type == F_WRLCK);
 		index->lock_type = F_RDLCK;
+
+		(void)file_lock_try_update(index->file_lock, F_RDLCK);
 	}
 
 	if (index->copy_lock_path != NULL) {
@@ -454,11 +383,15 @@
 		/* We may still have shared locks for the old file, but they
 		   don't matter. They're invalidated when we re-open the new
 		   index file. */
+		return FALSE;
 	}
+	return TRUE;
 }
 
 void mail_index_unlock(struct mail_index *index, unsigned int lock_id)
 {
+	bool unlock = TRUE;
+
 	if ((lock_id & 1) == 0) {
 		/* shared lock */
 		if (!mail_index_is_locked(index, lock_id)) {
@@ -474,16 +407,17 @@
 		i_assert(lock_id == index->lock_id + 1);
 		i_assert(index->excl_lock_count > 0);
 		if (--index->excl_lock_count == 0)
-			mail_index_excl_unlock_finish(index);
+			unlock = mail_index_excl_unlock_finish(index);
 	}
 
 	if (index->shared_lock_count == 0 && index->excl_lock_count == 0) {
 		index->lock_id += 2;
 		index->lock_type = F_UNLCK;
-		if (index->lock_method != MAIL_INDEX_LOCK_DOTLOCK) {
-			(void)mail_index_lock_fd(index, index->filepath,
-						 index->fd, F_UNLCK, 0);
+		if (index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
+			if (unlock)
+				file_unlock(&index->file_lock);
 		}
+		i_assert(index->file_lock == NULL);
 	}
 }
 

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- mail-index-private.h	13 Oct 2006 18:42:50 -0000	1.74
+++ mail-index-private.h	6 Dec 2006 15:08:32 -0000	1.75
@@ -1,10 +1,7 @@
 #ifndef __MAIL_INDEX_PRIVATE_H
 #define __MAIL_INDEX_PRIVATE_H
 
-/* Make sure F_RDLCK, F_WRLCK and F_UNLCK get defined */
-#include <unistd.h>
-#include <fcntl.h>
-
+#include "file-lock.h"
 #include "mail-index.h"
 #include "mail-index-view-private.h"
 #include "mail-index-transaction-private.h"
@@ -157,8 +154,10 @@
 	int lock_type, shared_lock_count, excl_lock_count;
 	unsigned int lock_id;
 	char *copy_lock_path;
+	enum file_lock_method lock_method;
+
+	struct file_lock *file_lock;
 	struct dotlock *dotlock;
-	enum mail_index_lock_method lock_method;
 
 	/* These are typically same as map->hdr->log_file_*, but with
 	   mmap_disable we may have synced more than index */
@@ -225,7 +224,8 @@
 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);
+		       int lock_type, unsigned int timeout_secs,
+		       struct file_lock **lock_r);
 
 /* Reopen index file if it has changed. */
 int mail_index_reopen_if_needed(struct mail_index *index);

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.245
retrieving revision 1.246
diff -u -d -r1.245 -r1.246
--- mail-index.c	12 Nov 2006 18:02:15 -0000	1.245
+++ mail-index.c	6 Dec 2006 15:08:32 -0000	1.246
@@ -1275,6 +1275,7 @@
 	int ret;
 
         i_assert(index->fd == -1);
+	i_assert(index->lock_type == F_UNLCK);
 
 	if (lock_id_r != NULL)
 		*lock_id_r = 0;
@@ -1298,6 +1299,7 @@
 		if (lock_id_r != NULL)
 			*lock_id_r = 0;
 
+		i_assert(index->file_lock == NULL);
 		(void)close(index->fd);
 		index->fd = -1;
 	} else {
@@ -1535,7 +1537,7 @@
 }
 
 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
-		    enum mail_index_lock_method lock_method)
+		    enum file_lock_method lock_method)
 {
 	int i = 0, ret;
 
@@ -1571,7 +1573,7 @@
 
 		/* don't even bother to handle dotlocking without mmap being
 		   disabled. that combination simply doesn't make any sense */
-		if (lock_method == MAIL_INDEX_LOCK_DOTLOCK &&
+		if (lock_method == FILE_LOCK_METHOD_DOTLOCK &&
 		    !index->mmap_disable) {
 			i_fatal("lock_method=dotlock and mmap_disable=no "
 				"combination isn't supported. "
@@ -1611,6 +1613,8 @@
 		mail_index_unmap(index, &index->map);
 	if (index->cache != NULL)
 		mail_cache_free(&index->cache);
+	if (index->file_lock != NULL)
+		file_lock_free(&index->file_lock);
 
 	if (index->fd != -1) {
 		if (close(index->fd) < 0)
@@ -1628,11 +1632,12 @@
 int mail_index_reopen(struct mail_index *index, int fd)
 {
 	struct mail_index_map *old_map;
+	struct file_lock *old_file_lock;
 	unsigned int old_shared_locks, old_lock_id, lock_id = 0;
 	int ret, old_fd, old_lock_type;
 
 	i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
-	i_assert(index->copy_lock_path == NULL || index->excl_lock_count == 0);
+	i_assert(index->excl_lock_count == 0);
 
 	old_map = index->map;
 	old_fd = index->fd;
@@ -1643,11 +1648,13 @@
 	old_lock_type = index->lock_type;
 	old_lock_id = index->lock_id;
 	old_shared_locks = index->shared_lock_count;
- 
+	old_file_lock = index->file_lock;
+
 	if (index->lock_type == F_RDLCK)
 		index->lock_type = F_UNLCK;
 	index->lock_id += 2;
 	index->shared_lock_count = 0;
+	index->file_lock = NULL;
 
 	if (fd != -1) {
 		index->fd = fd;
@@ -1676,11 +1683,14 @@
 
 	if (ret == 0) {
 		mail_index_unmap(index, &old_map);
+		if (old_file_lock != NULL)
+			file_lock_free(&old_file_lock);
 		if (close(old_fd) < 0)
 			mail_index_set_syscall_error(index, "close()");
 	} else {
 		if (index->map != NULL)
 			mail_index_unmap(index, &index->map);
+
 		if (index->fd != -1) {
 			if (close(index->fd) < 0)
 				mail_index_set_syscall_error(index, "close()");
@@ -1689,6 +1699,7 @@
 		index->map = old_map;
 		index->hdr = &index->map->hdr;
 		index->fd = old_fd;
+		index->file_lock = old_file_lock;
 		index->lock_type = old_lock_type;
 		index->lock_id = old_lock_id;
 		index->shared_lock_count = old_shared_locks;
@@ -1824,6 +1835,9 @@
 			ret = -1;
 	}
 
+	if (index->file_lock != NULL)
+		file_lock_free(&index->file_lock);
+
 	/* close the index file. */
 	if (close(index->fd) < 0)
 		mail_index_set_syscall_error(index, "close()");

Index: mail-index.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- mail-index.h	15 Oct 2006 17:56:10 -0000	1.162
+++ mail-index.h	6 Dec 2006 15:08:32 -0000	1.163
@@ -9,6 +9,8 @@
 
 #define MAIL_INDEX_HEADER_MIN_SIZE 120
 
+enum file_lock_method;
+
 enum mail_index_open_flags {
 	/* Create index if it doesn't exist */
 	MAIL_INDEX_OPEN_FLAG_CREATE		= 0x01,
@@ -20,12 +22,6 @@
 	MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE	= 0x08
 };
 
-enum mail_index_lock_method {
-	MAIL_INDEX_LOCK_FCNTL,
-	MAIL_INDEX_LOCK_FLOCK,
-	MAIL_INDEX_LOCK_DOTLOCK
-};
-
 enum mail_index_header_compat_flags {
 	MAIL_INDEX_COMPAT_LITTLE_ENDIAN		= 0x01
 };
@@ -158,7 +154,7 @@
 				mode_t mode, gid_t gid);
 
 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
-		    enum mail_index_lock_method lock_method);
+		    enum file_lock_method lock_method);
 void mail_index_close(struct mail_index *index);
 
 /* Move the index into memory. Returns 0 if ok, -1 if error occurred. */

Index: mail-transaction-log-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-private.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- mail-transaction-log-private.h	18 Nov 2006 21:01:10 -0000	1.16
+++ mail-transaction-log-private.h	6 Dec 2006 15:08:32 -0000	1.17
@@ -34,6 +34,8 @@
 	uoff_t sync_offset;
 	uint32_t first_append_size;
 
+	struct file_lock *file_lock;
+
 	unsigned int locked:1;
 };
 

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- mail-transaction-log.c	18 Nov 2006 21:01:10 -0000	1.115
+++ mail-transaction-log.c	6 Dec 2006 15:08:32 -0000	1.116
@@ -134,11 +134,13 @@
 		return 0;
 	}
 
-	if (file->log->index->lock_method == MAIL_INDEX_LOCK_DOTLOCK)
+	if (file->log->index->lock_method == FILE_LOCK_METHOD_DOTLOCK)
 		return mail_transaction_log_file_dotlock(file);
 
+	i_assert(file->file_lock == NULL);
 	ret = mail_index_lock_fd(file->log->index, file->filepath, file->fd,
-				 F_WRLCK, MAIL_INDEX_LOCK_SECS);
+				 F_WRLCK, MAIL_INDEX_LOCK_SECS,
+				 &file->file_lock);
 	if (ret > 0) {
 		file->locked = TRUE;
 		return 0;
@@ -159,8 +161,6 @@
 
 void mail_transaction_log_file_unlock(struct mail_transaction_log_file *file)
 {
-	int ret;
-
 	if (!file->locked)
 		return;
 
@@ -169,18 +169,12 @@
 	if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file))
 		return;
 
-	if (file->log->index->lock_method == MAIL_INDEX_LOCK_DOTLOCK) {
+	if (file->log->index->lock_method == FILE_LOCK_METHOD_DOTLOCK) {
 		mail_transaction_log_file_undotlock(file);
 		return;
 	}
 
-	ret = mail_index_lock_fd(file->log->index, file->filepath, file->fd,
-				 F_UNLCK, 0);
-	if (ret <= 0) {
-		mail_index_file_set_syscall_error(file->log->index,
-						  file->filepath,
-						  "mail_index_wait_lock_fd()");
-	}
+	file_unlock(&file->file_lock);
 }
 
 #define INDEX_HAS_MISSING_LOGS(index, file) \



More information about the dovecot-cvs mailing list