[dovecot-cvs] dovecot/src/lib-index mail-cache-compress.c, 1.32, 1.33 mail-cache-private.h, 1.22, 1.23 mail-cache.c, 1.61, 1.62 mail-index-private.h, 1.46, 1.47 mail-transaction-log-private.h, 1.6, 1.7 mail-transaction-log.c, 1.82, 1.83

cras at dovecot.org cras at dovecot.org
Sun Jan 16 21:18:26 EET 2005


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

Modified Files:
	mail-cache-compress.c mail-cache-private.h mail-cache.c 
	mail-index-private.h mail-transaction-log-private.h 
	mail-transaction-log.c 
Log Message:
Changed dotlocking API.



Index: mail-cache-compress.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-compress.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mail-cache-compress.c	7 Dec 2004 00:56:05 -0000	1.32
+++ mail-cache-compress.c	16 Jan 2005 19:18:24 -0000	1.33
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "buffer.h"
 #include "ostream.h"
+#include "file-dotlock.h"
 #include "file-cache.h"
 #include "file-set-size.h"
 #include "mail-cache-private.h"
@@ -236,6 +237,7 @@
 static int mail_cache_compress_locked(struct mail_cache *cache,
 				      struct mail_index_view *view)
 {
+	struct dotlock *dotlock;
         mode_t old_mask;
 	int fd;
 
@@ -248,10 +250,8 @@
 #endif
 
 	old_mask = umask(cache->index->mode ^ 0666);
-	fd = file_dotlock_open(cache->filepath, NULL, NULL,
-			       MAIL_CACHE_LOCK_TIMEOUT,
-			       MAIL_CACHE_LOCK_CHANGE_TIMEOUT,
-			       MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL);
+	fd = file_dotlock_open(&cache->dotlock_settings, cache->filepath,
+			       0, &dotlock);
 	umask(old_mask);
 
 	if (fd == -1) {
@@ -262,18 +262,19 @@
 	if (cache->index->gid != (gid_t)-1 &&
 	    fchown(fd, (uid_t)-1, cache->index->gid) < 0) {
 		mail_cache_set_syscall_error(cache, "fchown()");
+		file_dotlock_delete(&dotlock);
 		return -1;
 	}
 
 	// FIXME: check that cache file wasn't just recreated
 
 	if (mail_cache_copy(cache, view, fd) < 0) {
-		(void)file_dotlock_delete(cache->filepath, NULL, fd);
+		(void)file_dotlock_delete(&dotlock);
 		return -1;
 	}
 
-	if (file_dotlock_replace(cache->filepath, NULL,
-				 -1, FALSE) < 0) {
+	if (file_dotlock_replace(&dotlock,
+				 DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) < 0) {
 		mail_cache_set_syscall_error(cache,
 					     "file_dotlock_replace()");
 		(void)close(fd);

Index: mail-cache-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- mail-cache-private.h	19 Dec 2004 08:19:00 -0000	1.22
+++ mail-cache-private.h	16 Jan 2005 19:18:24 -0000	1.23
@@ -1,6 +1,7 @@
 #ifndef __MAIL_CACHE_PRIVATE_H
 #define __MAIL_CACHE_PRIVATE_H
 
+#include "file-dotlock.h"
 #include "mail-index-private.h"
 #include "mail-cache.h"
 
@@ -125,7 +126,9 @@
 	const void *data;
 	size_t mmap_length;
 	struct file_cache *file_cache;
-	struct dotlock dotlock;
+
+	struct dotlock_settings dotlock_settings;
+	struct dotlock *dotlock;
 
 	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.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- mail-cache.c	16 Jan 2005 18:23:01 -0000	1.61
+++ mail-cache.c	16 Jan 2005 19:18:24 -0000	1.62
@@ -255,11 +255,16 @@
 	cache = i_new(struct mail_cache, 1);
 	cache->index = index;
 	cache->fd = -1;
-        cache->field_pool = pool_alloconly_create("Cache fields", 1024);
+	cache->field_pool = pool_alloconly_create("Cache fields", 1024);
 	cache->field_name_hash =
 		hash_create(default_pool, cache->field_pool, 0,
 			    strcase_hash, (hash_cmp_callback_t *)strcasecmp);
 
+	cache->dotlock_settings.timeout = MAIL_CACHE_LOCK_TIMEOUT;
+	cache->dotlock_settings.stale_timeout = MAIL_CACHE_LOCK_CHANGE_TIMEOUT;
+	cache->dotlock_settings.immediate_stale_timeout =
+		MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT;
+
 	if (mail_cache_open_and_verify(cache) < 0) {
 		/* failed for some reason - doesn't really matter,
 		   it's disabled for now. */
@@ -310,13 +315,10 @@
 	}
 
 	if (lock_type != F_UNLCK) {
-		return file_lock_dotlock(cache->filepath, NULL, FALSE,
-					 MAIL_INDEX_LOCK_SECS, 0,
-					 MAIL_INDEX_LOCK_SECS,
-					 NULL, NULL, &cache->dotlock);
-	} else {
-		return file_unlock_dotlock(cache->filepath, &cache->dotlock);
-	}
+		return file_dotlock_create(&cache->dotlock_settings,
+					   cache->filepath, 0, &cache->dotlock);
+	} else
+		return file_dotlock_delete(&cache->dotlock);
 }
 
 int mail_cache_lock(struct mail_cache *cache)

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- mail-index-private.h	10 Jan 2005 17:37:22 -0000	1.46
+++ mail-index-private.h	16 Jan 2005 19:18:24 -0000	1.47
@@ -5,7 +5,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-#include "file-dotlock.h"
 #include "mail-index.h"
 
 struct mail_transaction_header;
@@ -133,7 +132,7 @@
 	int lock_type, shared_lock_count, excl_lock_count;
 	unsigned int lock_id;
 	char *copy_lock_path;
-	struct dotlock dotlock;
+	struct dotlock *dotlock;
 	enum mail_index_lock_method lock_method;
 
 	/* These are typically same as map->hdr->log_file_*, but with

Index: mail-transaction-log-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-private.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mail-transaction-log-private.h	31 Jul 2004 03:06:48 -0000	1.6
+++ mail-transaction-log-private.h	16 Jan 2005 19:18:24 -0000	1.7
@@ -35,7 +35,8 @@
 	struct mail_transaction_log_file *head, *tail;
 
 	unsigned int dotlock_count;
-	struct dotlock dotlock;
+        struct dotlock_settings dotlock_settings, new_dotlock_settings;
+	struct dotlock *dotlock;
 };
 
 void

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- mail-transaction-log.c	12 Jan 2005 21:26:36 -0000	1.82
+++ mail-transaction-log.c	16 Jan 2005 19:18:24 -0000	1.83
@@ -65,11 +65,9 @@
 	if (file->log->dotlock_count > 0)
 		ret = 1;
 	else {
-		ret = file_lock_dotlock(file->filepath, NULL, FALSE,
-					LOG_DOTLOCK_TIMEOUT,
-					LOG_DOTLOCK_STALE_TIMEOUT,
-					LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT,
-					NULL, NULL, &file->log->dotlock);
+		ret = file_dotlock_create(&file->log->dotlock_settings,
+					  file->filepath, 0,
+					  &file->log->dotlock);
 	}
 	if (ret > 0) {
 		file->log->dotlock_count++;
@@ -79,7 +77,7 @@
 	if (ret < 0) {
 		mail_index_file_set_syscall_error(file->log->index,
 						  file->filepath,
-						  "file_lock_dotlock()");
+						  "file_dotlock_create()");
 		return -1;
 	}
 
@@ -99,10 +97,10 @@
 	if (--file->log->dotlock_count > 0)
 		return 0;
 
-	ret = file_unlock_dotlock(file->filepath, &file->log->dotlock);
+	ret = file_dotlock_delete(&file->log->dotlock);
 	if (ret < 0) {
 		mail_index_file_set_syscall_error(file->log->index,
-			file->filepath, "file_unlock_dotlock()");
+			file->filepath, "file_dotlock_delete()");
 		return -1;
 	}
 
@@ -218,11 +216,19 @@
 	log = i_new(struct mail_transaction_log, 1);
 	log->index = index;
 
+	log->dotlock_settings.timeout = LOG_DOTLOCK_TIMEOUT;
+	log->dotlock_settings.stale_timeout = LOG_DOTLOCK_STALE_TIMEOUT;
+	log->dotlock_settings.immediate_stale_timeout =
+		LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT;
+
+	log->new_dotlock_settings = log->dotlock_settings;
+	log->new_dotlock_settings.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
+
 	path = t_strconcat(log->index->filepath,
 			   MAIL_TRANSACTION_LOG_PREFIX, NULL);
 	log->head = mail_transaction_log_file_open_or_create(log, path);
 	if (log->head == NULL) {
-		i_free(log);
+		mail_transaction_log_close(log);
 		return NULL;
 	}
 
@@ -240,8 +246,10 @@
 {
 	mail_transaction_log_views_close(log);
 
-	log->head->refcount--;
-	mail_transaction_logs_clean(log);
+	if (log->head != NULL) {
+		log->head->refcount--;
+		mail_transaction_logs_clean(log);
+	}
 
 	log->index->log = NULL;
 	i_free(log);
@@ -336,8 +344,7 @@
 		} else if (st.st_ino == ino && CMP_DEV_T(st.st_dev, dev)) {
 			/* same file, still broken */
 		} else {
-			(void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX,
-						  fd);
+			(void)file_dotlock_delete(&log->dotlock);
 			return fd2;
 		}
 
@@ -382,7 +389,7 @@
 		return -1;
 	}
 
-	if (file_dotlock_replace(path, LOG_NEW_DOTLOCK_SUFFIX, fd, FALSE) <= 0)
+	if (file_dotlock_replace(&log->dotlock, 0) <= 0)
 		return -1;
 
 	/* success */
@@ -399,10 +406,8 @@
 	/* With dotlocking we might already have path.lock created, so this
 	   filename has to be different. */
 	old_mask = umask(log->index->mode ^ 0666);
-	fd = file_dotlock_open(path, NULL, LOG_NEW_DOTLOCK_SUFFIX,
-			       LOG_DOTLOCK_TIMEOUT,
-			       LOG_DOTLOCK_STALE_TIMEOUT,
-			       LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, NULL, NULL);
+	fd = file_dotlock_open(&log->new_dotlock_settings, path, 0,
+			       &log->dotlock);
 	umask(old_mask);
 
 	if (fd == -1) {
@@ -414,12 +419,13 @@
 	if (log->index->gid != (gid_t)-1 &&
 	    fchown(fd, (uid_t)-1, log->index->gid) < 0) {
 		mail_index_file_set_syscall_error(log->index, path, "fchown()");
+		(void)file_dotlock_delete(&log->dotlock);
 		return -1;
 	}
 
 	fd2 = mail_transaction_log_file_create2(log, path, fd, dev, ino);
 	if (fd2 < 0) {
-		(void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);
+		(void)file_dotlock_delete(&log->dotlock);
 		return -1;
 	}
 	return fd2;



More information about the dovecot-cvs mailing list