[dovecot-cvs] dovecot/src/lib-index mail-index-sync-update.c, 1.86, 1.87 mail-index.c, 1.206, 1.207 mail-transaction-log.c, 1.100, 1.101

cras at dovecot.org cras at dovecot.org
Sat Aug 27 15:40:55 EEST 2005


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

Modified Files:
	mail-index-sync-update.c mail-index.c mail-transaction-log.c 
Log Message:
When refreshing transaction log while trying to find new log file, don't
recreate the log file if it wasn't found or was corrupted. Things have
already broken at that point and recreating it could cause recurseive
mail_index_map() call with mmap_disable=yes.

Also added more assert()s to check that we don't try to recursively call
mail_index_map().



Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- mail-index-sync-update.c	4 Jul 2005 11:32:20 -0000	1.86
+++ mail-index-sync-update.c	27 Aug 2005 12:40:53 -0000	1.87
@@ -297,6 +297,7 @@
 		return 0;
 
 	i_assert(map == index->map);
+	i_assert(!index->mapping); /* mail_index_sync_from_transactions() */
 
 	size = map->hdr.header_size +
 		(map->records_count + count) * map->hdr.record_size;

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -d -r1.206 -r1.207
--- mail-index.c	27 Aug 2005 10:20:39 -0000	1.206
+++ mail-index.c	27 Aug 2005 12:40:53 -0000	1.207
@@ -1635,6 +1635,8 @@
 		return mail_index_reopen_if_needed(index);
 	}
 
+	i_assert(!index->mapping);
+
 	/* 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)

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- mail-transaction-log.c	27 Aug 2005 10:31:45 -0000	1.100
+++ mail-transaction-log.c	27 Aug 2005 12:40:53 -0000	1.101
@@ -715,6 +715,31 @@
 	return mail_transaction_log_file_fd_open_or_create(log, path, fd);
 }
 
+static struct mail_transaction_log_file *
+mail_transaction_log_file_open(struct mail_transaction_log *log,
+			       const char *path)
+{
+	struct mail_transaction_log_file *file;
+	int fd, ret;
+
+	fd = open(path, O_RDWR);
+	if (fd == -1) {
+		mail_index_file_set_syscall_error(log->index, path, "open()");
+		return NULL;
+	}
+
+	ret = mail_transaction_log_file_fd_open(log, &file, path, fd, TRUE);
+	if (ret <= 0) {
+		/* error / corrupted */
+		if (ret == 0)
+			mail_transaction_log_file_close(file);
+		return NULL;
+	}
+
+	mail_transaction_log_file_add_to_head(file);
+	return file;
+}
+
 void mail_transaction_logs_clean(struct mail_transaction_log *log)
 {
 	struct mail_transaction_log_file **p, *next;
@@ -779,7 +804,8 @@
 	return 0;
 }
 
-static int mail_transaction_log_refresh(struct mail_transaction_log *log)
+static int mail_transaction_log_refresh(struct mail_transaction_log *log,
+					int create_if_needed)
 {
         struct mail_transaction_log_file *file;
 	struct stat st;
@@ -802,7 +828,9 @@
 		return 0;
 	}
 
-	file = mail_transaction_log_file_open_or_create(log, path);
+	file = create_if_needed ?
+		mail_transaction_log_file_open_or_create(log, path) :
+		mail_transaction_log_file_open(log, path);
 	if (file == NULL)
 		return -1;
 
@@ -827,7 +855,10 @@
 	int ret, fd;
 
 	if (file_seq > log->head->hdr.file_seq) {
-		if (mail_transaction_log_refresh(log) < 0)
+		/* don't try to recreate log file if it gets lost. we're
+		   already in trouble and with mmap_disable the creation
+		   could cause a recursive mail_index_map() call */
+		if (mail_transaction_log_refresh(log, FALSE) < 0)
 			return -1;
 	}
 
@@ -1153,7 +1184,7 @@
 			return -1;
 
 		file->refcount++;
-		ret = mail_transaction_log_refresh(log);
+		ret = mail_transaction_log_refresh(log, TRUE);
 		if (--file->refcount == 0) {
 			mail_transaction_logs_clean(log);
 			file = NULL;



More information about the dovecot-cvs mailing list