mail-transaction-log-file.c revision ce9d23c7c1e621398d2572a1d95171136f7ef6a2
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Copyright (c) 2003-2017 Dovecot authors, see the included COPYING file */
daf029d2a627daa39d05507140f385162828172eTimo Sirainen#define MEMORY_LOG_NAME "(in-memory transaction log file)"
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainenmail_transaction_log_file_sync(struct mail_transaction_log_file *file,
9b7eeffb5752b500ac62ba1fd01c4a8c4ada14e9Timo Sirainenlog_file_set_syscall_error(struct mail_transaction_log_file *file,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_transaction_log_mark_corrupted(struct mail_transaction_log_file *file)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen unsigned int offset =
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen offsetof(struct mail_transaction_log_header, indexid);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ||
211ed7806d8715ec2280ffbf5d10f0d6e4f1beb2Timo Sirainen /* indexid=0 marks the log file as corrupted. we opened the file with
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen O_APPEND, and now we need to drop it for pwrite() to work (at least
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen if (fcntl(file->fd, F_SETFL, flags & ~O_APPEND) < 0) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen mail_index_file_set_syscall_error(file->log->index,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen const char *fmt, ...)
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen "Corrupted transaction log file %s seq %u: %s "
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen t_strdup_vprintf(fmt, va), file->sync_offset);
struct mail_transaction_log_file *
const char *path)
return file;
struct mail_transaction_log_file **p;
if (*p == file) {
struct mail_transaction_log_file **p;
const char *reason;
bool retry;
*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) {
const unsigned int hdr_version =
#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 (ret < 0)
if (rename_existing) {
DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) <= 0) {
bool reset)
if (ret < 0) {
return ret;
const char **reason_r)
bool ignore_estale;
int ret;
if (ret > 0) {
if (ret == 0) {
i == MAIL_INDEX_ESTALE_RETRY_COUNT) {
const char **error_r)
const unsigned int offset_pos =
sizeof(tail_offset));
return TRUE;
for (unsigned int i = 0; i < count; i++) {
return TRUE;
return FALSE;
unsigned int version)
if (*cur_modseq != 0) {
const unsigned int modseq_ext_len =
modseq_ext_len) == 0) {
case MAIL_TRANSACTION_APPEND:
case MAIL_TRANSACTION_FLAG_UPDATE: {
unsigned int count;
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;
const char *reason;
int ret;
if (ret <= 0) {
const char *reason;
int ret;
if (ret <= 0) {
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) {
const char **reason_r)
void *data;
if (ret > 0)
if (ret < 0) {
return TRUE;
return TRUE;
return FALSE;
const char **reason_r)
bool retry;
int ret;
if (ret <= 0)
return ret;
return ret;
const char **reason_r)
return FALSE;
return FALSE;
return TRUE;
const char **reason_r)
MADV_SEQUENTIAL) < 0)
bool retry;
int ret;
!retry)
return ret;
} while (retry);
return ret;
const char **reason_r)
int ret;
if (ret <= 0)
return ret;
*file)
const char *error;