dovecot-2.0: mbox: Make sure failed saves get rolled back with NFS.
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 16 20:04:44 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/b0a871a899dd
changeset: 10085:b0a871a899dd
user: Timo Sirainen <tss at iki.fi>
date: Fri Oct 16 13:04:16 2009 -0400
description:
mbox: Make sure failed saves get rolled back with NFS.
diffstat:
1 file changed, 19 insertions(+), 16 deletions(-)
src/lib-storage/index/mbox/mbox-save.c | 35 +++++++++++++++++---------------
diffs (66 lines):
diff -r ede6701cfe7a -r b0a871a899dd src/lib-storage/index/mbox/mbox-save.c
--- a/src/lib-storage/index/mbox/mbox-save.c Fri Oct 16 12:30:59 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-save.c Fri Oct 16 13:04:16 2009 -0400
@@ -713,6 +713,22 @@ static void mbox_transaction_save_deinit
str_free(&ctx->headers);
}
+static void mbox_save_truncate(struct mbox_save_context *ctx)
+{
+ if (ctx->append_offset == (uoff_t)-1 || ctx->mbox->mbox_fd == -1)
+ return;
+
+ i_assert(ctx->mbox->mbox_lock_type == F_WRLCK);
+
+ /* failed, truncate file back to original size. output stream needs to
+ be flushed before truncating so unref() won't write anything. */
+ if (ctx->output != NULL)
+ o_stream_flush(ctx->output);
+
+ if (ftruncate(ctx->mbox->mbox_fd, (off_t)ctx->append_offset) < 0)
+ mbox_set_syscall_error(ctx->mbox, "ftruncate()");
+}
+
int mbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
{
struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx;
@@ -759,11 +775,11 @@ int mbox_transaction_save_commit_pre(str
mbox_set_syscall_error(mbox, "utime()");
}
- if (!ctx->synced && mbox->mbox_fd != -1 &&
- !mbox->mbox_writeonly &&
+ if (mbox->mbox_fd != -1 && !mbox->mbox_writeonly &&
!mbox->storage->storage.set->fsync_disable) {
if (fdatasync(mbox->mbox_fd) < 0) {
mbox_set_syscall_error(mbox, "fdatasync()");
+ mbox_save_truncate(ctx);
ret = -1;
}
}
@@ -792,24 +808,11 @@ void mbox_transaction_save_rollback(stru
void mbox_transaction_save_rollback(struct mail_save_context *_ctx)
{
struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx;
- struct mbox_mailbox *mbox = ctx->mbox;
if (!ctx->finished)
mbox_save_cancel(&ctx->ctx);
- if (ctx->append_offset != (uoff_t)-1 && mbox->mbox_fd != -1) {
- i_assert(mbox->mbox_lock_type == F_WRLCK);
-
- /* failed, truncate file back to original size.
- output stream needs to be flushed before truncating
- so unref() won't write anything. */
- if (ctx->output != NULL)
- o_stream_flush(ctx->output);
-
- if (ftruncate(mbox->mbox_fd, (off_t)ctx->append_offset) < 0)
- mbox_set_syscall_error(mbox, "ftruncate()");
- }
-
+ mbox_save_truncate(ctx);
mbox_transaction_save_deinit(ctx);
i_free(ctx);
}
More information about the dovecot-cvs
mailing list