mail-transaction-log.c revision 37598dd7a0613a03b12170c450b53c70f2b3d438
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (C) 2003-2004 Timo Sirainen */
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen/* this lock should never exist for a long time.. */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainenmail_transaction_log_file_open_or_create(struct mail_transaction_log *log,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen const char *path);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainenmail_transaction_log_file_read(struct mail_transaction_log_file *file,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen const char *fmt, ...)
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen "Corrupted transaction log file %s: %s",
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* this may have happened because of broken index.
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen make sure it's ok. */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainenmail_transaction_log_file_dotlock(struct mail_transaction_log_file *file)
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen ret = file_dotlock_create(&file->log->dotlock_settings,
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen "file_dotlock_create()");
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen "Timeout while waiting for release of "
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen "dotlock for transaction log file %s",
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainenmail_transaction_log_file_undotlock(struct mail_transaction_log_file *file)
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen ret = file_dotlock_delete(&file->log->dotlock);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen "Dotlock was lost for transaction log file %s",
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenmail_transaction_log_file_lock(struct mail_transaction_log_file *file)
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
a8ebb72c0fba1a6a71104e530bf5903d5f149351Timo Sirainen if (file->log->index->lock_method == MAIL_INDEX_LOCK_DOTLOCK)
a8ebb72c0fba1a6a71104e530bf5903d5f149351Timo Sirainen return mail_transaction_log_file_dotlock(file);
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen ret = mail_index_lock_fd(file->log->index, file->filepath, file->fd,
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen "mail_index_wait_lock_fd()");
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen "Timeout while waiting for lock for transaction log file %s",
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainenvoid mail_transaction_log_file_unlock(struct mail_transaction_log_file *file)
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file))
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen if (file->log->index->lock_method == MAIL_INDEX_LOCK_DOTLOCK) {
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen ret = mail_index_lock_fd(file->log->index, file->filepath, file->fd,
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen mail_index_file_set_syscall_error(file->log->index,
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen "mail_index_wait_lock_fd()");
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen !(((file)->hdr.file_seq == (index)->hdr->log_file_seq && \
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen (index)->hdr->log_file_int_offset >= (file)->hdr.hdr_size) || \
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen ((file)->hdr.prev_file_seq == (index)->hdr->log_file_seq && \
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen (file)->hdr.prev_file_offset == (index)->hdr->log_file_int_offset))
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic int mail_transaction_log_check_file_seq(struct mail_transaction_log *log)
unsigned int lock_id;
int ret;
if (ret == 0) {
if (ret <= 0)
return ret;
struct mail_transaction_log *
const char *path;
return NULL;
return NULL;
return log;
struct mail_transaction_log_file *f;
int ret;
if (ret < 0) {
if (ret == 0) {
if (head) {
unsigned int lock_id;
const char *path2;
bool found;
return old_fd;
if (ret < 0) {
if (found) {
return new_fd;
const char *path,
int fd;
if (fd < 0) {
return fd;
struct mail_transaction_log_file **p;
*p = file;
struct mail_transaction_log_file **p;
*p = file;
bool ignore_estale)
int ret;
if (ret < 0) {
return ret;
static struct mail_transaction_log_file *
int ret;
!try_retry);
if (ret < 0) {
return NULL;
if (ret == 0) {
!try_retry);
if (ret <= 0) {
return NULL;
return file;
static struct mail_transaction_log_file *
return NULL;
return file;
static struct mail_transaction_log_file *
const char *path)
bool retry;
int fd;
path,
return NULL;
return NULL;
return file;
static struct mail_transaction_log_file *
const char *path)
return NULL;
if (ret > 0)
if (ret == 0)
return NULL;
return file;
if ((*p)->refcount != 0)
p = &(*p)->next;
*p = next;
bool retry;
int fd;
if (lock) {
bool create_if_needed)
const char *path;
const char *path;
if (ret <= 0) {
if (ret == 0) {
if (stale) {
const void *data;
if (hdr_size == 0) {
void *data;
int ret;
if (ret == 0) {
if (ret < 0) {
if (ret > 0)
if (ret == 0) {
if (use_mmap) {
if (!use_mmap) {
if (ret <= 0) {
return ret;
MADV_SEQUENTIAL) < 0) {
int ret = 0;
if (ret < 0)
return ret;