mail-transaction-log-file.c revision 1ff03d2244dd08effadfecec365bec28793a1aa0
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen/* Copyright (c) 2003-2016 Dovecot authors, see the included COPYING file */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen#define MEMORY_LOG_NAME "(in-memory transaction log file)"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenmail_transaction_log_file_sync(struct mail_transaction_log_file *file);
66d2db642fe24d555d113ba463e446b038d476efTimo Sirainenlog_file_set_syscall_error(struct mail_transaction_log_file *file,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainenmail_transaction_log_mark_corrupted(struct mail_transaction_log_file *file)
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen unsigned int offset =
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen offsetof(struct mail_transaction_log_header, indexid);
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ||
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen /* indexid=0 marks the log file as corrupted. we opened the file with
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen O_APPEND, and now we need to drop it for pwrite() to work (at least
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen if (fcntl(file->fd, F_SETFL, flags & ~O_APPEND) < 0) {
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen const char *fmt, ...)
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen "Corrupted transaction log file %s seq %u: %s "
9f431ccfb6932746db56245c8a3d3415717ef545Timo Sirainen t_strdup_vprintf(fmt, va), file->sync_offset);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenmail_transaction_log_file_alloc(struct mail_transaction_log *log,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen file = i_new(struct mail_transaction_log_file, 1);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenvoid mail_transaction_log_file_free(struct mail_transaction_log_file **_file)
66d2db642fe24d555d113ba463e446b038d476efTimo Sirainen struct mail_transaction_log_file *file = *_file;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen for (p = &file->log->files; *p != NULL; p = &(*p)->next) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (munmap(file->mmap_base, file->mmap_size) < 0)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenmail_transaction_log_file_skip_to_head(struct mail_transaction_log_file *file)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen const struct mail_index_modseq_header *modseq_hdr;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (map == NULL || file->hdr.file_seq != map->hdr.log_file_seq ||
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* we can get a valid log offset from index file. initialize
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen sync_offset from it so we don't have to read the whole log
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen file from beginning. */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen modseq_hdr = mail_index_map_get_modseq_header(map);
struct mail_transaction_log_file **p;
*p = file;
#if !WORDS_BIGENDIAN
MAIL_INDEX_SYNC_HANDLER_HEAD) <= 0)
struct mail_transaction_log_file *
return NULL;
return file;
int ret;
if (ret > 0) {
if (ret < 0) {
int ret;
if (ret < 0) {
if (ret == 0) {
unsigned int lock_timeout_secs;
int ret;
if (ret > 0) {
if (ret < 0) {
const char *lock_reason)
unsigned int lock_time;
static ssize_t
void *dest;
yet (hdr.size=0), the buffer must be truncated later */
pos = 0;
if (ret > 0)
int ret;
ret = 0;
return ret;
bool ignore_estale)
struct mail_transaction_log_file *f;
int ret;
if (ret < 0) {
#if !WORDS_BIGENDIAN
return mail_transaction_log_file_fail_dupe(f);
bool ignore_estale)
return TRUE;
return FALSE;
unsigned int hdr_offset;
const char *path2;
if (reset)
FALSE) > 0 &&
if (reset) {
if (need_lock) {
if (ret < 0)
if (rename_existing) {
bool reset)
if (ret < 0) {
return ret;
bool ignore_estale;
int ret;
if (ret > 0) {
if (ret == 0) {
i == MAIL_INDEX_ESTALE_RETRY_COUNT) {
const unsigned int offset_pos =
sizeof(tail_offset));
if (*cur_modseq != 0) {
const unsigned int modseq_ext_len =
modseq_ext_len) == 0) {
case MAIL_TRANSACTION_APPEND:
case MAIL_TRANSACTION_MODSEQ_UPDATE: {
static struct modseq_cache *
if (idx > 0) {
static struct modseq_cache *
return NULL;
best = i;
return NULL;
static struct modseq_cache *
return NULL;
best = i;
return NULL;
int ret;
if (ret <= 0) {
if (ret < 0)
int ret;
if (ret <= 0) {
if (ret < 0)
unsigned int trans_size)
int ret;
if (ret != 0)
case MAIL_TRANSACTION_BOUNDARY: {
const void *data;
int ret;
if (trans_size == 0) {
if (ret < 0)
void *data;
if (ret > 0) {
if (ret == 0) {
void *data;
if (ret > 0)
if (ret < 0) {
return TRUE;
return TRUE;
return FALSE;
int ret;
if (ret <= 0)
return ret;
return ret;
MADV_SEQUENTIAL) < 0)
int ret;
if (ret > 0)
FALSE);
} while (ret == 0);
int ret;
end_offset) == 0)
if (ret <= 0)
return ret;
*file)