[dovecot-cvs] dovecot/src/lib-index mail-transaction-log-private.h, 1.3, 1.4 mail-transaction-log.c, 1.17, 1.18

cras at procontrol.fi cras at procontrol.fi
Tue May 4 01:08:28 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv19265/lib-index

Modified Files:
	mail-transaction-log-private.h mail-transaction-log.c 
Log Message:
file_dotlock_open/delete/replace now has lock_suffix parameter. NULL
defaults to ".lock".

Fixed dotlocking transaction log.



Index: mail-transaction-log-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-transaction-log-private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mail-transaction-log-private.h	28 Apr 2004 23:15:44 -0000	1.3
+++ mail-transaction-log-private.h	3 May 2004 22:08:26 -0000	1.4
@@ -13,7 +13,6 @@
 	char *filepath;
 	int fd;
 	int lock_type;
-	struct dotlock dotlock;
 
 	ino_t st_ino;
 	dev_t st_dev;
@@ -30,6 +29,9 @@
 	struct mail_index *index;
         struct mail_transaction_log_view *views;
 	struct mail_transaction_log_file *head, *tail;
+
+	unsigned int dotlock_count;
+	struct dotlock dotlock;
 };
 
 void

Index: mail-transaction-log.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- mail-transaction-log.c	3 May 2004 14:37:49 -0000	1.17
+++ mail-transaction-log.c	3 May 2004 22:08:26 -0000	1.18
@@ -144,13 +144,16 @@
 	int ret;
 
 	if (lock_type == F_UNLCK) {
-		ret = file_unlock_dotlock(file->filepath, &file->dotlock);
+		file->lock_type = F_UNLCK;
+		if (--file->log->dotlock_count > 0)
+			return 0;
+
+		ret = file_unlock_dotlock(file->filepath, &file->log->dotlock);
 		if (ret < 0) {
 			mail_index_file_set_syscall_error(file->log->index,
 				file->filepath, "file_unlock_dotlock()");
 			return -1;
 		}
-		file->lock_type = F_UNLCK;
 
 		if (ret == 0) {
 			mail_index_set_error(file->log->index,
@@ -161,13 +164,18 @@
 		return 0;
 	}
 
-	ret = file_lock_dotlock(file->filepath, NULL, FALSE,
-				LOG_DOTLOCK_TIMEOUT,
-				LOG_DOTLOCK_STALE_TIMEOUT,
-				LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT,
-				NULL, NULL, &file->dotlock);
+	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);
+	}
 	if (ret > 0) {
-		file->lock_type = F_WRLCK;
+		file->log->dotlock_count++;
+ 		file->lock_type = F_WRLCK;
 		return 0;
 	}
 	if (ret < 0) {
@@ -311,12 +319,16 @@
 mail_transaction_log_file_create(struct mail_transaction_log *log,
 				 const char *path, dev_t dev, ino_t ino)
 {
+#define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
 	struct mail_index *index = log->index;
 	struct mail_transaction_log_header hdr;
 	struct stat st;
 	int fd, fd2, ret;
 
-	fd = file_dotlock_open(path, NULL, LOG_DOTLOCK_TIMEOUT,
+	/* With dotlocking we might already have path.lock created, so this
+	   filename has to be different. */
+	fd = file_dotlock_open(path, NULL, LOG_NEW_DOTLOCK_SUFFIX,
+			       LOG_DOTLOCK_TIMEOUT,
 			       LOG_DOTLOCK_STALE_TIMEOUT,
 			       LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, NULL, NULL);
 	if (fd == -1) {
@@ -334,7 +346,8 @@
 		} else if (st.st_dev == dev && st.st_ino == ino) {
 			/* same file, still broken */
 		} else {
-			(void)file_dotlock_delete(path, fd2);
+			(void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX,
+						  fd2);
 			return fd2;
 		}
 
@@ -364,19 +377,20 @@
 	}
 
 	if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
-		mail_index_file_set_syscall_error(index, path, "write_full()");
-                (void)file_dotlock_delete(path, fd);
+		mail_index_file_set_syscall_error(index, path,
+						  "write_full()");
+                (void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);
 		return -1;
 	}
 
 	fd2 = dup(fd);
 	if (fd2 < 0) {
 		mail_index_file_set_syscall_error(index, path, "dup()");
-                (void)file_dotlock_delete(path, fd);
+                (void)file_dotlock_delete(path, LOG_NEW_DOTLOCK_SUFFIX, fd);
 		return -1;
 	}
 
-	if (file_dotlock_replace(path, fd, FALSE) <= 0)
+	if (file_dotlock_replace(path, LOG_NEW_DOTLOCK_SUFFIX, fd, FALSE) <= 0)
 		return -1;
 
 	/* success */



More information about the dovecot-cvs mailing list