dovecot-2.0: Renamed fsync_disable to mail_fsync=optimized|alway...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 25 18:21:59 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/7f19062f58fd
changeset: 11634:7f19062f58fd
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 25 16:21:49 2010 +0100
description:
Renamed fsync_disable to mail_fsync=optimized|always|never.

diffstat:

 doc/example-config/conf.d/10-mail.conf            |   9 +++++----
 src/config/old-set-parser.c                       |   8 ++++++++
 src/config/settings-get.pl                        |   1 +
 src/lib-index/mail-cache-compress.c               |   2 +-
 src/lib-index/mail-cache-transaction.c            |   2 +-
 src/lib-index/mail-cache.c                        |   2 +-
 src/lib-index/mail-index-private.h                |   1 +
 src/lib-index/mail-index-write.c                  |   5 ++---
 src/lib-index/mail-index.c                        |  12 +++++++-----
 src/lib-index/mail-index.h                        |  11 +++++------
 src/lib-index/mail-transaction-log-append.c       |   4 ++--
 src/lib-index/mail-transaction-log-file.c         |  14 ++++++--------
 src/lib-index/mail-transaction-log-private.h      |   3 ++-
 src/lib-index/mail-transaction-log.c              |  18 +++++++-----------
 src/lib-index/mailbox-list-index-sync.c           |   3 +--
 src/lib-index/mailbox-list-index.c                |   2 +-
 src/lib-storage/index/cydir/cydir-save.c          |   2 +-
 src/lib-storage/index/cydir/cydir-storage.c       |   7 ++++---
 src/lib-storage/index/dbox-common/dbox-file.c     |  25 ++++++++++++++-----------
 src/lib-storage/index/dbox-multi/mdbox-map.c      |   2 ++
 src/lib-storage/index/dbox-multi/mdbox-save.c     |   6 ++++--
 src/lib-storage/index/dbox-multi/mdbox-storage.c  |   7 ++++---
 src/lib-storage/index/dbox-single/sdbox-save.c    |   6 ++++--
 src/lib-storage/index/dbox-single/sdbox-storage.c |   7 ++++---
 src/lib-storage/index/index-storage.c             |   2 ++
 src/lib-storage/index/maildir/maildir-save.c      |   5 +++--
 src/lib-storage/index/maildir/maildir-uidlist.c   |   2 +-
 src/lib-storage/index/mbox/mbox-save.c            |   2 +-
 src/lib-storage/mail-storage-settings.c           |  23 +++++++++++++++++------
 src/lib-storage/mail-storage-settings.h           |   4 +++-
 src/lib/Makefile.am                               |   1 +
 src/lib/fsync-mode.h                              |  14 ++++++++++++++
 32 files changed, 130 insertions(+), 82 deletions(-)

diffs (truncated from 733 to 300 lines):

diff -r 0dc6f14c271d -r 7f19062f58fd doc/example-config/conf.d/10-mail.conf
--- a/doc/example-config/conf.d/10-mail.conf	Fri Jun 25 15:03:44 2010 +0100
+++ b/doc/example-config/conf.d/10-mail.conf	Fri Jun 25 16:21:49 2010 +0100
@@ -139,10 +139,11 @@
 # since version 3, so this should be safe to use nowadays by default.
 #dotlock_use_excl = yes
 
-# Don't use fsync() or fdatasync() calls. This makes the performance better
-# at the cost of potential data loss if the server (or the file server)
-# goes down.
-#fsync_disable = no
+# When to use fsync() or fdatasync() calls:
+#   optimized (default): Whenever necessary to avoid losing important data
+#   always: Useful with e.g. NFS when write()s are delayed
+#   never: Never use it (best performance, but crashes can lose data)
+#mail_fsync = optimized
 
 # Mail storage exists in NFS. Set this to yes to make Dovecot flush NFS caches
 # whenever needed. If you're using only a single mail server this isn't needed.
diff -r 0dc6f14c271d -r 7f19062f58fd src/config/old-set-parser.c
--- a/src/config/old-set-parser.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/config/old-set-parser.c	Fri Jun 25 16:21:49 2010 +0100
@@ -130,6 +130,14 @@
 		set_rename(ctx, key, "ssl", value);
 		return TRUE;
 	}
+	if (strcmp(key, "fsync_disable") == 0) {
+		if (strcasecmp(value, "yes") == 0)
+			value = "never";
+		else if (strcasecmp(value, "no") == 0)
+			value = "optimized";
+		set_rename(ctx, key, "mail_fsync", value);
+		return TRUE;
+	}
 	if (strcmp(key, "dbox_rotate_size") == 0) {
 		set_rename(ctx, key, "mdbox_rotate_size", value);
 		return TRUE;
diff -r 0dc6f14c271d -r 7f19062f58fd src/config/settings-get.pl
--- a/src/config/settings-get.pl	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/config/settings-get.pl	Fri Jun 25 16:21:49 2010 +0100
@@ -5,6 +5,7 @@
 print '#include "array.h"'."\n";
 print '#include "var-expand.h"'."\n";
 print '#include "file-lock.h"'."\n";
+print '#include "fsync-mode.h"'."\n";
 print '#include "settings-parser.h"'."\n";
 print '#include "all-settings.h"'."\n";
 print '#include <stddef.h>'."\n";
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-cache-compress.c	Fri Jun 25 16:21:49 2010 +0100
@@ -297,7 +297,7 @@
 
 	o_stream_destroy(&output);
 
-	if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+	if (cache->index->fsync_mode == FSYNC_MODE_ALWAYS) {
 		if (fdatasync(fd) < 0) {
 			mail_cache_set_syscall_error(cache, "fdatasync()");
 			array_free(ext_offsets);
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-cache-transaction.c
--- a/src/lib-index/mail-cache-transaction.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-cache-transaction.c	Fri Jun 25 16:21:49 2010 +0100
@@ -836,7 +836,7 @@
 	if (mail_cache_write(cache, buffer->data, size, offset) < 0)
 		return -1;
 
-	if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+	if (cache->index->fsync_mode == FSYNC_MODE_ALWAYS) {
 		if (fdatasync(cache->fd) < 0) {
 			mail_cache_set_syscall_error(cache, "fdatasync()");
 			return -1;
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-cache.c	Fri Jun 25 16:21:49 2010 +0100
@@ -657,7 +657,7 @@
 		mail_cache_update_need_compress(cache);
 	}
 
-	if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+	if (cache->index->fsync_mode == FSYNC_MODE_ALWAYS) {
 		if (fdatasync(cache->fd) < 0)
 			mail_cache_set_syscall_error(cache, "fdatasync()");
 	}
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-index-private.h	Fri Jun 25 16:21:49 2010 +0100
@@ -172,6 +172,7 @@
 
 	unsigned int open_count;
 	enum mail_index_open_flags flags;
+	enum fsync_mode fsync_mode;
 	enum mail_index_sync_type fsync_mask;
 	mode_t mode;
 	gid_t gid;
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-index-write.c
--- a/src/lib-index/mail-index-write.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-index-write.c	Fri Jun 25 16:21:49 2010 +0100
@@ -78,8 +78,7 @@
 	}
 	o_stream_destroy(&output);
 
-	if (ret == 0 &&
-	    (index->flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) == 0) {
+	if (ret == 0 && index->fsync_mode != FSYNC_MODE_NEVER) {
 		if (fdatasync(fd) < 0) {
 			mail_index_file_set_syscall_error(index, path,
 							  "fdatasync()");
@@ -245,7 +244,7 @@
 		ret = mail_index_write_map_over(index);
 		if (ret < 0)
 			mail_index_set_syscall_error(index, "pwrite_full()");
-		else if ((index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+		else if (index->fsync_mode == FSYNC_MODE_ALWAYS) {
 			ret = fdatasync(index->fd);
 			if (ret < 0) {
 				mail_index_set_syscall_error(index,
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-index.c	Fri Jun 25 16:21:49 2010 +0100
@@ -84,10 +84,12 @@
 	i_free(index);
 }
 
-void mail_index_set_fsync_types(struct mail_index *index,
-				enum mail_index_sync_type fsync_mask)
+void mail_index_set_fsync_mode(struct mail_index *index,
+			       enum fsync_mode mode,
+			       enum mail_index_sync_type mask)
 {
-	index->fsync_mask = fsync_mask;
+	index->fsync_mode = mode;
+	index->fsync_mask = mask;
 }
 
 void mail_index_set_permissions(struct mail_index *index,
@@ -519,8 +521,8 @@
 	index->readonly = (flags & MAIL_INDEX_OPEN_FLAG_READONLY) != 0;
 
 	if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 &&
-	    (flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) != 0)
-		i_fatal("nfs flush requires fsync_disable=no");
+	    index->fsync_mode != FSYNC_MODE_ALWAYS)
+		i_fatal("nfs flush requires mail_fsync=always");
 	if ((flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0 &&
 	    (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
 		i_fatal("nfs flush requires mmap_disable=yes");
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-index.h	Fri Jun 25 16:21:49 2010 +0100
@@ -2,6 +2,7 @@
 #define MAIL_INDEX_H
 
 #include "file-lock.h"
+#include "fsync-mode.h"
 #include "mail-types.h"
 #include "seq-range-array.h"
 
@@ -17,8 +18,6 @@
 	MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE	= 0x04,
 	/* Rely on O_EXCL when creating dotlocks */
 	MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL	= 0x10,
-	/* Don't fsync() or fdatasync() */
-	MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE	= 0x20,
 	/* Flush NFS attr/data/write cache when necessary */
 	MAIL_INDEX_OPEN_FLAG_NFS_FLUSH		= 0x40,
 	/* Open the index read-only */
@@ -207,10 +206,10 @@
 struct mail_index *mail_index_alloc(const char *dir, const char *prefix);
 void mail_index_free(struct mail_index **index);
 
-/* Specify the transaction types that are fsynced after writing.
-   Default is to fsync nothing. */
-void mail_index_set_fsync_types(struct mail_index *index,
-				enum mail_index_sync_type fsync_mask);
+/* Specify how often to do fsyncs. If mode is FSYNC_MODE_OPTIMIZED, the mask
+   can be used to specify which transaction types to fsync. */
+void mail_index_set_fsync_mode(struct mail_index *index, enum fsync_mode mode,
+			       enum mail_index_sync_type mask);
 void mail_index_set_permissions(struct mail_index *index,
 				mode_t mode, gid_t gid, const char *gid_origin);
 /* Set locking method and maximum time to wait for a lock (-1U = default). */
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-transaction-log-append.c
--- a/src/lib-index/mail-transaction-log-append.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-transaction-log-append.c	Fri Jun 25 16:21:49 2010 +0100
@@ -109,8 +109,8 @@
 	}
 
 	if ((ctx->want_fsync &&
-	     (file->log->flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) == 0) ||
-	    (file->log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+	     file->log->index->fsync_mode != FSYNC_MODE_NEVER) ||
+	    file->log->index->fsync_mode == FSYNC_MODE_ALWAYS) {
 		if (fdatasync(file->fd) < 0) {
 			mail_index_file_set_syscall_error(ctx->log->index,
 							  file->filepath,
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-transaction-log-file.c	Fri Jun 25 16:21:49 2010 +0100
@@ -548,7 +548,7 @@
 	int fd, ret;
 	bool rename_existing;
 
-	if ((file->log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+	if (file->log->nfs_flush) {
 		/* although we check also mtime and file size below, it's done
 		   only to fix broken log files. we don't bother flushing
 		   attribute cache just for that. */
@@ -614,9 +614,9 @@
 	if (write_full(new_fd, &file->hdr, sizeof(file->hdr)) < 0)
 		return log_file_set_syscall_error(file, "write_full()");
 
-	if ((file->log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0) {
+	if (file->log->index->fsync_mode == FSYNC_MODE_ALWAYS) {
 		/* the header isn't important, so don't bother calling
-		   fdatasync() unless NFS is used */
+		   fdatasync() unless it's required */
 		if (fdatasync(new_fd) < 0)
 			return log_file_set_syscall_error(file, "fdatasync()");
 	}
@@ -1333,8 +1333,6 @@
 mail_transaction_log_file_read(struct mail_transaction_log_file *file,
 			       uoff_t start_offset, bool nfs_flush)
 {
-	bool index_nfs_flush =
-		(file->log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
 	int ret;
 
 	i_assert(file->mmap_base == NULL);
@@ -1344,7 +1342,7 @@
 	   that we really should have read more, flush the cache and try again.
 	   if file is locked, the attribute cache was already flushed when
 	   refreshing the log. */
-	if (index_nfs_flush && nfs_flush) {
+	if (file->log->nfs_flush && nfs_flush) {
 		if (!file->locked)
 			nfs_flush_attr_cache_unlocked(file->filepath);
 		else {
@@ -1369,7 +1367,7 @@
 	if ((ret = mail_transaction_log_file_read_more(file)) <= 0)
 		return ret;
 
-	if (index_nfs_flush && !nfs_flush &&
+	if (file->log->nfs_flush && !nfs_flush &&
 	    mail_transaction_log_file_need_nfs_flush(file)) {
 		/* we didn't read enough data. flush and try again. */
 		return mail_transaction_log_file_read(file, start_offset, TRUE);
@@ -1556,7 +1554,7 @@
 		start_offset = file->sync_offset;
 	}
 
-	if ((file->log->flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
+	if ((file->log->index->flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
 		ret = mail_transaction_log_file_map_mmap(file, start_offset);
 	else {
 		mail_transaction_log_file_munmap(file);
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-transaction-log-private.h
--- a/src/lib-index/mail-transaction-log-private.h	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-transaction-log-private.h	Fri Jun 25 16:21:49 2010 +0100
@@ -80,7 +80,6 @@
 struct mail_transaction_log {
 	struct mail_index *index;
         struct mail_transaction_log_view *views;
-	enum mail_index_open_flags flags;
 	char *filepath, *filepath2;
 
 	/* files is a linked list of all the opened log files. the list is
@@ -94,6 +93,8 @@
 	unsigned int dotlock_count;
         struct dotlock_settings dotlock_settings, new_dotlock_settings;
 	struct dotlock *dotlock;
+
+	unsigned int nfs_flush:1;
 };
 
 void
diff -r 0dc6f14c271d -r 7f19062f58fd src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c	Fri Jun 25 15:03:44 2010 +0100
+++ b/src/lib-index/mail-transaction-log.c	Fri Jun 25 16:21:49 2010 +0100
@@ -80,15 +80,12 @@
 				    MAIL_TRANSACTION_LOG_SUFFIX, NULL);
 	log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
 
-	log->flags = log->index->flags;
+	log->nfs_flush =
+		(log->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
 	log->dotlock_settings.use_excl_lock =
-		(log->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
-	log->dotlock_settings.nfs_flush =
-		(log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
-	log->new_dotlock_settings.use_excl_lock =
-		(log->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
-	log->new_dotlock_settings.nfs_flush =
-		(log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
+		(log->index->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
+	log->dotlock_settings.nfs_flush = log->nfs_flush;
+	log->new_dotlock_settings = log->dotlock_settings;
 
 	if (log->open_file != NULL)
 		mail_transaction_log_file_free(&log->open_file);


More information about the dovecot-cvs mailing list