[dovecot-cvs] dovecot/src/lib-index mail-transaction-log-private.h, 1.8, 1.9 mail-transaction-log-view.c, 1.36, 1.37 mail-transaction-log.c, 1.89, 1.90 mail-transaction-log.h, 1.26, 1.27

cras at dovecot.org cras at dovecot.org
Sat Mar 5 21:23:31 EET 2005


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

Modified Files:
	mail-transaction-log-private.h mail-transaction-log-view.c 
	mail-transaction-log.c mail-transaction-log.h 
Log Message:
Several transaction log cleanups and fixes.



Index: mail-transaction-log-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-private.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mail-transaction-log-private.h	8 Feb 2005 12:28:12 -0000	1.8
+++ mail-transaction-log-private.h	5 Mar 2005 19:23:28 -0000	1.9
@@ -4,6 +4,9 @@
 #include "file-dotlock.h"
 #include "mail-transaction-log.h"
 
+#define MAIL_TRANSACTION_LOG_ROTATE_SIZE (1024*128)
+#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
+
 struct mail_transaction_log_file {
 	struct mail_transaction_log *log;
         struct mail_transaction_log_file *next;

Index: mail-transaction-log-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-view.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- mail-transaction-log-view.c	5 Mar 2005 12:41:22 -0000	1.36
+++ mail-transaction-log-view.c	5 Mar 2005 19:23:28 -0000	1.37
@@ -213,6 +213,7 @@
 	view->type_mask = type_mask;
 	view->broken = FALSE;
 
+	i_assert(view->cur_offset <= view->cur->sync_offset);
 	i_assert(view->cur->hdr.file_seq == min_file_seq);
 	return 0;
 }
@@ -264,25 +265,30 @@
 	if (view->cur == NULL)
 		return 0;
 
+	/* prev_file_offset should point to beginning of previous log record.
+	   when we reach EOF, it should be left there, not to beginning of the
+	   next file. */
 	view->prev_file_seq = view->cur->hdr.file_seq;
 	view->prev_file_offset = view->cur_offset;
 
-	for (;;) {
-		file = view->cur;
-		if (file == NULL)
+	if (view->cur->hdr.file_seq == view->max_file_seq) {
+		/* last file */
+		if (view->cur_offset == view->max_file_offset ||
+		    view->cur_offset == view->cur->sync_offset) {
+			/* we're all finished */
+			view->cur = NULL;
+			return 0;
+		}
+	} else if (view->cur_offset == view->cur->sync_offset) {
+		/* end of file, go to next one */
+		view->cur = view->cur->next;
+		if (view->cur == NULL)
 			return 0;
 
-		if (view->cur_offset != file->sync_offset)
-			break;
-
-		view->cur = file->next;
-		view->cur_offset = file->hdr.hdr_size;
+		view->cur_offset = view->cur->hdr.hdr_size;
+		return log_view_get_next(view, hdr_r, data_r);
 	}
-
-	if (file->hdr.file_seq > view->max_file_seq ||
-	    (view->cur_offset >= view->max_file_offset &&
-	     file->hdr.file_seq == view->max_file_seq))
-		return 0;
+	file = view->cur;
 
 	data = buffer_get_data(file->buffer, &file_size);
 	file_size += file->buffer_offset;

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- mail-transaction-log.c	5 Mar 2005 12:41:22 -0000	1.89
+++ mail-transaction-log.c	5 Mar 2005 19:23:28 -0000	1.90
@@ -23,6 +23,7 @@
 #define LOG_DOTLOCK_STALE_TIMEOUT 0
 #define LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT 300
 
+#define MAIL_TRANSACTION_LOG_PREFIX ".log"
 #define LOG_NEW_DOTLOCK_SUFFIX ".newlock"
 
 static struct mail_transaction_log_file *
@@ -289,6 +290,7 @@
 static int
 mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file)
 {
+        struct mail_transaction_log_file *f;
 	int ret;
 
 	ret = pread_full(file->fd, &file->hdr, sizeof(file->hdr), 0);
@@ -342,6 +344,20 @@
 			file->hdr.indexid, file->log->index->indexid);
 		return 0;
 	}
+
+	/* make sure we already don't have a file with the same sequence
+	   opened. it shouldn't happen unless the old log file was
+	   corrupted. */
+	for (f = file->log->tail; f != NULL; f = f->next) {
+		if (f->hdr.file_seq >= file->hdr.file_seq) {
+			mail_transaction_log_file_set_corrupted(file,
+				"invalid new transaction log sequence "
+				"(%u >= %u)",
+				f->hdr.file_seq, file->hdr.file_seq);
+			return 0;
+		}
+	}
+
 	return 1;
 }
 
@@ -391,6 +407,11 @@
 	if (index->fd != -1) {
 		if (mail_index_lock_shared(index, TRUE, &lock_id) < 0)
 			return -1;
+		if (mail_index_map(index, FALSE) <= 0) {
+			mail_index_unlock(index, lock_id);
+			return -1;
+		}
+
 		hdr.prev_file_seq = index->hdr->log_file_seq;
 		hdr.prev_file_offset = index->hdr->log_file_int_offset;
 	}
@@ -522,16 +543,9 @@
 		file->sync_offset = file->hdr.hdr_size;
 	}
 
-	for (p = &log->tail; *p != NULL; p = &(*p)->next) {
-		if ((*p)->hdr.file_seq >= file->hdr.file_seq) {
-			/* log replaced with file having same sequence as
-			   previous one. shouldn't happen unless previous
-			   log file was corrupted.. */
-			file->next = (*p)->next;
-			(*p)->next = NULL;
-			break;
-		}
-	}
+	/* append to end of list. */
+	for (p = &log->tail; *p != NULL; p = &(*p)->next)
+		i_assert((*p)->hdr.file_seq < file->hdr.file_seq);
 	*p = file;
 
 	return file;
@@ -683,6 +697,9 @@
 
 	data = buffer_get_data(file->buffer, &size);
 
+	if (file->sync_offset < file->buffer_offset)
+		file->sync_offset = file->buffer_offset;
+
 	while (file->sync_offset - file->buffer_offset + sizeof(*hdr) <= size) {
 		hdr = CONST_PTR_OFFSET(data, file->sync_offset -
 				       file->buffer_offset);
@@ -822,12 +839,16 @@
 			return 1;
 	}
 
-	if (file->mmap_base != NULL || use_mmap) {
-		if (fstat(file->fd, &st) < 0) {
-			mail_index_file_set_syscall_error(index, file->filepath,
-							  "fstat()");
-			return -1;
-		}
+	if (fstat(file->fd, &st) < 0) {
+		mail_index_file_set_syscall_error(index, file->filepath,
+						  "fstat()");
+		return -1;
+	}
+	if (start_offset > (uoff_t)st.st_size) {
+		mail_transaction_log_file_set_corrupted(file,
+			"start_offset (%"PRIuUOFF_T") > file size "
+			"(%"PRIuUOFF_T")", start_offset, (uoff_t)st.st_size);
+		return -1;
 	}
 
 	if (file->mmap_base != NULL && (uoff_t)st.st_size == file->mmap_size &&

Index: mail-transaction-log.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mail-transaction-log.h	5 Mar 2005 12:41:22 -0000	1.26
+++ mail-transaction-log.h	5 Mar 2005 19:23:28 -0000	1.27
@@ -5,10 +5,6 @@
 #define MAIL_TRANSACTION_LOG_MINOR_VERSION 0
 #define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
 
-#define MAIL_TRANSACTION_LOG_PREFIX ".log"
-#define MAIL_TRANSACTION_LOG_ROTATE_SIZE (1024*128)
-#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
-
 struct mail_transaction_log_header {
 	uint8_t major_version;
 	uint8_t minor_version;



More information about the dovecot-cvs mailing list