dovecot: Code cleanup

dovecot at dovecot.org dovecot at dovecot.org
Tue Dec 4 10:49:14 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/4aa0a3a2d3f8
changeset: 6921:4aa0a3a2d3f8
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Dec 04 10:49:10 2007 +0200
description:
Code cleanup

diffstat:

1 file changed, 52 insertions(+), 49 deletions(-)
src/lib-index/mail-transaction-log-file.c |  101 ++++++++++++++---------------

diffs (125 lines):

diff -r 58cf18fc9358 -r 4aa0a3a2d3f8 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Mon Dec 03 19:16:10 2007 +0200
+++ b/src/lib-index/mail-transaction-log-file.c	Tue Dec 04 10:49:10 2007 +0200
@@ -1028,12 +1028,56 @@ mail_transaction_log_file_munmap(struct 
 	buffer_free(&file->buffer);
 }
 
+static int
+mail_transaction_log_file_map_mmap(struct mail_transaction_log_file *file)
+{
+	struct stat st;
+	int ret;
+
+	/* we are going to mmap() this file, but it's not necessarily
+	   mmaped currently. */
+	i_assert(file->buffer_offset == 0 || file->mmap_base == NULL);
+	i_assert(file->mmap_size == 0 || file->mmap_base != NULL);
+
+	if (fstat(file->fd, &st) < 0) {
+		mail_index_file_set_syscall_error(file->log->index,
+						  file->filepath, "fstat()");
+		return -1;
+	}
+	file->last_size = st.st_size;
+
+	if ((uoff_t)st.st_size < file->sync_offset) {
+		mail_transaction_log_file_set_corrupted(file,
+							"file size shrank");
+		return 0;
+	}
+
+	if ((uoff_t)st.st_size == file->mmap_size) {
+		/* we already have the whole file mmaped */
+		if ((ret = mail_transaction_log_file_sync(file)) < 0)
+			return 0;
+		if (ret > 0)
+			return 1;
+		/* size changed, re-mmap */
+	}
+
+	do {
+		mail_transaction_log_file_munmap(file);
+
+		if (mail_transaction_log_file_mmap(file) < 0)
+			return -1;
+		if ((ret = mail_transaction_log_file_sync(file)) < 0)
+			return 0;
+	} while (ret == 0);
+
+	return 1;
+}
+
 int mail_transaction_log_file_map(struct mail_transaction_log_file *file,
 				  uoff_t start_offset, uoff_t end_offset)
 {
 	struct mail_index *index = file->log->index;
 	size_t size;
-	struct stat st;
 	int ret;
 
 	if (file->hdr.indexid == 0) {
@@ -1074,56 +1118,15 @@ int mail_transaction_log_file_map(struct
 						  end_offset);
 	}
 
-	if (!index->mmap_disable) {
-		/* we are going to mmap() this file, but it's not necessarily
-		   mmaped currently. */
-		i_assert(file->buffer_offset == 0 || file->mmap_base == NULL);
-		i_assert(file->mmap_size == 0 || file->mmap_base != NULL);
-
-		if (fstat(file->fd, &st) < 0) {
-			mail_index_file_set_syscall_error(index, file->filepath,
-							  "fstat()");
-			return -1;
-		}
-		file->last_size = st.st_size;
-
-		if ((uoff_t)st.st_size < file->sync_offset) {
-			mail_transaction_log_file_set_corrupted(file,
-				"file size shrank");
-			return 0;
-		}
-
-		if ((uoff_t)st.st_size == file->mmap_size) {
-			/* we already have the whole file mmaped */
-			if ((ret = mail_transaction_log_file_sync(file)) < 0)
-				return 0;
-			if (ret > 0) {
-				return log_file_map_check_offsets(file,
-								  start_offset,
-								  end_offset);
-			}
-			/* size changed, re-mmap */
-		}
-	}
-
-	if (index->mmap_disable) {
+	if (!index->mmap_disable)
+		ret = mail_transaction_log_file_map_mmap(file);
+	else {
 		mail_transaction_log_file_munmap(file);
-
 		ret = mail_transaction_log_file_read(file, start_offset, FALSE);
-		if (ret <= 0)
-			return ret;
-	} else {
-		do {
-			mail_transaction_log_file_munmap(file);
-
-			if (mail_transaction_log_file_mmap(file) < 0)
-				return -1;
-			if ((ret = mail_transaction_log_file_sync(file)) < 0)
-				return 0;
-		} while (ret == 0);
-	}
-
-	return log_file_map_check_offsets(file, start_offset, end_offset);
+	}
+
+	return ret <= 0 ? ret :
+		log_file_map_check_offsets(file, start_offset, end_offset);
 }
 
 void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file


More information about the dovecot-cvs mailing list