Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4918:2f9173e103fd HEAD
Added fsync_disable setting. Also added missing fsync()ing to dbox when
saving mails.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 17 Dec 2006 18:35:31 +0200 |
parents | 5d00d8a7888e |
children | d54145736f99 |
files | dovecot-example.conf src/lib-index/mail-cache-compress.c src/lib-index/mail-cache-transaction.c src/lib-index/mail-hash.c src/lib-index/mail-index-lock.c src/lib-index/mail-index-private.h src/lib-index/mail-index.c src/lib-index/mail-index.h src/lib-storage/index/dbox/dbox-uidlist.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-sync.c src/master/master-settings.c src/master/master-settings.h |
diffstat | 16 files changed, 64 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Sun Dec 17 18:34:24 2006 +0200 +++ b/dovecot-example.conf Sun Dec 17 18:35:31 2006 +0200 @@ -280,6 +280,11 @@ # which use separate caches for them, such as OpenBSD. #mmap_no_write = no +# 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 + # Locking method for index files. Alternatives are fcntl, flock and dotlock. # Dotlocking uses some tricks which may create more disk I/O than other locking # methods. NOTE: If you use NFS, remember to change also mmap_disable setting!
--- a/src/lib-index/mail-cache-compress.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-cache-compress.c Sun Dec 17 18:35:31 2006 +0200 @@ -229,10 +229,12 @@ o_stream_destroy(&output); - if (fdatasync(fd) < 0) { - mail_cache_set_syscall_error(cache, "fdatasync()"); - (void)mail_index_transaction_rollback(&t); - return -1; + if (!cache->index->fsync_disable) { + if (fdatasync(fd) < 0) { + mail_cache_set_syscall_error(cache, "fdatasync()"); + (void)mail_index_transaction_rollback(&t); + return -1; + } } return mail_index_transaction_commit(&t, &seq, &offset);
--- a/src/lib-index/mail-cache-transaction.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-cache-transaction.c Sun Dec 17 18:35:31 2006 +0200 @@ -659,7 +659,7 @@ ret = -1; else if (mail_cache_write(cache, data, size, offset) < 0) ret = -1; - else if (fdatasync(cache->fd) < 0) { + else if (!cache->index->fsync_disable && fdatasync(cache->fd) < 0) { mail_cache_set_syscall_error(cache, "fdatasync()"); ret = -1; } else if (mail_cache_header_fields_get_next_offset(cache,
--- a/src/lib-index/mail-hash.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-hash.c Sun Dec 17 18:35:31 2006 +0200 @@ -310,9 +310,11 @@ } } - if (fdatasync(hash->fd) < 0) { - mail_hash_set_syscall_error(hash, "fdatasync()"); - return -1; + if (!hash->index->fsync_disable) { + if (fdatasync(hash->fd) < 0) { + mail_hash_set_syscall_error(hash, "fdatasync()"); + return -1; + } } /* now that the file is guaranteed to be updated, reset the
--- a/src/lib-index/mail-index-lock.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-index-lock.c Sun Dec 17 18:35:31 2006 +0200 @@ -272,10 +272,13 @@ static int mail_index_copy_lock_finish(struct mail_index *index) { - if (fsync(index->fd) < 0) { - mail_index_file_set_syscall_error(index, index->copy_lock_path, - "fsync()"); - return -1; + if (!index->fsync_disable) { + if (fsync(index->fd) < 0) { + mail_index_file_set_syscall_error(index, + index->copy_lock_path, + "fsync()"); + return -1; + } } if (rename(index->copy_lock_path, index->filepath) < 0) {
--- a/src/lib-index/mail-index-private.h Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-index-private.h Sun Dec 17 18:35:31 2006 +0200 @@ -181,6 +181,7 @@ unsigned int opened:1; unsigned int log_locked:1; unsigned int mmap_disable:1; + unsigned int fsync_disable:1; unsigned int mmap_no_write:1; unsigned int readonly:1; unsigned int fsck:1;
--- a/src/lib-index/mail-index.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-index.c Sun Dec 17 18:35:31 2006 +0200 @@ -1569,6 +1569,8 @@ (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) != 0; index->mmap_no_write = (flags & MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE) != 0; + index->fsync_disable = + (flags & MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE) != 0; index->lock_method = lock_method; /* don't even bother to handle dotlocking without mmap being
--- a/src/lib-index/mail-index.h Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-index/mail-index.h Sun Dec 17 18:35:31 2006 +0200 @@ -19,7 +19,9 @@ /* Don't try to write() to mmap()ed index files. Required for the few OSes that don't have unified buffer cache (currently OpenBSD <= 3.5) */ - MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE = 0x08 + MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE = 0x08, + /* Don't fsync() or fdatasync() */ + MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE = 0x10 }; enum mail_index_header_compat_flags {
--- a/src/lib-storage/index/dbox/dbox-uidlist.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-uidlist.c Sun Dec 17 18:35:31 2006 +0200 @@ -806,6 +806,7 @@ static int dbox_uidlist_write_append_offsets(struct dbox_uidlist_append_ctx *ctx) { + struct mail_storage *storage = STORAGE(ctx->uidlist->mbox->storage); struct dbox_save_file *const *files; struct dbox_file_header hdr; unsigned int i, count; @@ -813,6 +814,16 @@ files = array_get(&ctx->files, &count); for (i = 0; i < count; i++) { + if (!ctx->uidlist->mbox->ibox.fsync_disable) { + if (fsync(files[i]->file->fd) < 0) { + mail_storage_set_critical(storage, + "fsync(%s) failed: %m", + files[i]->file->path); + ret = -1; + continue; + } + } + DEC2HEX(hdr.append_offset_hex, files[i]->file->output->offset); @@ -820,10 +831,9 @@ sizeof(hdr.append_offset_hex), offsetof(struct dbox_file_header, append_offset_hex)) < 0) { - mail_storage_set_critical( - STORAGE(ctx->uidlist->mbox->storage), - "pwrite_full(%s) failed: %m", - files[i]->file->path); + mail_storage_set_critical(storage, + "pwrite_full(%s) failed: %m", + files[i]->file->path); ret = -1; } }
--- a/src/lib-storage/index/index-storage.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-storage/index/index-storage.c Sun Dec 17 18:35:31 2006 +0200 @@ -318,12 +318,18 @@ void index_storage_mailbox_open(struct index_mailbox *ibox) { struct mail_storage *storage = &ibox->storage->storage; - enum mail_index_open_flags index_flags; + enum mail_index_open_flags index_flags = 0; int ret; i_assert(!ibox->box.opened); - index_flags = ibox->move_to_memory ? 0 : MAIL_INDEX_OPEN_FLAG_CREATE; + if (getenv("FSYNC_DISABLE") != NULL) { + ibox->fsync_disable = TRUE; + index_flags |= MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE; + } + + if (ibox->move_to_memory) + index_flags |= MAIL_INDEX_OPEN_FLAG_CREATE; if ((storage->flags & MAIL_STORAGE_FLAG_MMAP_DISABLE) != 0) index_flags |= MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE; #ifndef MMAP_CONFLICTS_WRITE
--- a/src/lib-storage/index/index-storage.h Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-storage/index/index-storage.h Sun Dec 17 18:35:31 2006 +0200 @@ -77,6 +77,7 @@ unsigned int notify_pending:1; unsigned int mail_read_mmaped:1; unsigned int move_to_memory:1; + unsigned int fsync_disable:1; }; struct index_transaction_context {
--- a/src/lib-storage/index/maildir/maildir-save.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-storage/index/maildir/maildir-save.c Sun Dec 17 18:35:31 2006 +0200 @@ -396,12 +396,12 @@ output_errno = ctx->output->stream_errno; o_stream_destroy(&ctx->output); - /* FIXME: when saving multiple messages, we could get better - performance if we left the fd open and fsync()ed it later */ - if (fsync(ctx->fd) < 0) { - mail_storage_set_critical(STORAGE(ctx->mbox->storage), - "fsync(%s) failed: %m", path); - ctx->failed = TRUE; + if (!ctx->mbox->ibox.fsync_disable) { + if (fsync(ctx->fd) < 0) { + mail_storage_set_critical(STORAGE(ctx->mbox->storage), + "fsync(%s) failed: %m", path); + ctx->failed = TRUE; + } } if (close(ctx->fd) < 0) { mail_storage_set_critical(STORAGE(ctx->mbox->storage),
--- a/src/lib-storage/index/mbox/mbox-save.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-save.c Sun Dec 17 18:35:31 2006 +0200 @@ -623,7 +623,7 @@ } if (!ctx->synced && ctx->mbox->mbox_fd != -1 && - !ctx->mbox->mbox_writeonly) { + !ctx->mbox->mbox_writeonly && !ctx->mbox->ibox.fsync_disable) { if (fdatasync(ctx->mbox->mbox_fd) < 0) { mbox_set_syscall_error(ctx->mbox, "fdatasync()"); ret = -1;
--- a/src/lib-storage/index/mbox/mbox-sync.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-sync.c Sun Dec 17 18:35:31 2006 +0200 @@ -1758,7 +1758,7 @@ } if (ret == 0 && mbox->mbox_lock_type == F_WRLCK && - !mbox->mbox_writeonly) { + !mbox->mbox_writeonly && !mbox->ibox.fsync_disable) { if (fsync(mbox->mbox_fd) < 0) { mbox_set_syscall_error(mbox, "fsync()"); ret = -1;
--- a/src/master/master-settings.c Sun Dec 17 18:34:24 2006 +0200 +++ b/src/master/master-settings.c Sun Dec 17 18:35:31 2006 +0200 @@ -121,6 +121,7 @@ DEF(SET_BOOL, mail_read_mmaped), DEF(SET_BOOL, mmap_disable), DEF(SET_BOOL, mmap_no_write), + DEF(SET_BOOL, fsync_disable), DEF(SET_STR, lock_method), DEF(SET_BOOL, maildir_stat_dirs), DEF(SET_BOOL, maildir_copy_with_hardlinks), @@ -333,6 +334,7 @@ #else MEMBER(mmap_no_write) FALSE, #endif + MEMBER(fsync_disable) FALSE, MEMBER(lock_method) "fcntl", MEMBER(maildir_stat_dirs) FALSE, MEMBER(maildir_copy_with_hardlinks) FALSE,
--- a/src/master/master-settings.h Sun Dec 17 18:34:24 2006 +0200 +++ b/src/master/master-settings.h Sun Dec 17 18:35:31 2006 +0200 @@ -80,6 +80,7 @@ bool mail_read_mmaped; bool mmap_disable; bool mmap_no_write; + bool fsync_disable; const char *lock_method; bool maildir_stat_dirs; bool maildir_copy_with_hardlinks;