From: Timo Sirainen Date: Fri, 14 May 2010 14:20:58 +0000 (+0200) Subject: lib-index, mmap_disable=yes: Save data also to memory after appending to transaction... X-Git-Tag: 2.0.beta6~216 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8a786d2069fab818d0b62cd3eaa3ed08fe7c620;p=thirdparty%2Fdovecot%2Fcore.git lib-index, mmap_disable=yes: Save data also to memory after appending to transaction log. This seems to fix a bug at least with CentOS 4.8 kernel (2.6.9-89.0.25.ELsmp) where after a write() a read() didn't realize that data was written, so it returned EOF too early. Of course, this change also improves performance since it avoids re-reading the same data that was just written. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-transaction-log-append.c b/src/lib-index/mail-transaction-log-append.c index f2c7960e88..55b896aac8 100644 --- a/src/lib-index/mail-transaction-log-append.c +++ b/src/lib-index/mail-transaction-log-append.c @@ -98,6 +98,7 @@ static int log_buffer_write(struct mail_transaction_log_append_ctx *ctx) /* now that the whole transaction has been written, rewrite the first record's size so the transaction becomes visible */ + hdr->size = first_size; if (pwrite_full(file->fd, &first_size, sizeof(uint32_t), file->sync_offset + offsetof(struct mail_transaction_header, size)) < 0) { @@ -123,6 +124,17 @@ static int log_buffer_write(struct mail_transaction_log_append_ctx *ctx) if it crashes before doing that, we'll need to overwrite it with a dummy record */ + if (file->mmap_base == NULL) { + /* we're reading from a file. avoid re-reading the data that + we just wrote. this is also important for some NFS clients, + which for some reason sometimes can't read() this data we + just wrote in the same process */ + i_assert(file->buffer != NULL); + i_assert(file->buffer_offset + + file->buffer->used == file->sync_offset); + buffer_append(file->buffer, ctx->output->data, + ctx->output->used); + } file->sync_offset += ctx->output->used; return 0; }