mail-transaction-log-file.c revision 6f5d19886f36fb20777618ef9362be39d3dc4182
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (C) 2003-2007 Timo Sirainen */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen#define MEMORY_LOG_NAME "(in-memory transaction log file)"
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char *fmt, ...)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* indexid=0 marks the log file as corrupted */
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen mail_index_file_set_syscall_error(file->log->index,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Corrupted transaction log file %s: %s",
2598b2f36365b52d9754b9348a5be29569293e46Timo Sirainenmail_transaction_log_file_alloc(struct mail_transaction_log *log,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen file = i_new(struct mail_transaction_log_file, 1);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid mail_transaction_log_file_free(struct mail_transaction_log_file **_file)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_transaction_log_file *file = *_file;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen for (p = &file->log->files; *p != NULL; p = &(*p)->next) {
12cf3d0e03fc70fb0c8b91bc8fd83b4e14d7cdefTimo Sirainen if (munmap(file->mmap_base, file->mmap_size) < 0) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
bf72c930996df0691932fb1143f360d260f27a06Timo Sirainenmail_transaction_log_file_add_to_list(struct mail_transaction_log_file *file)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (map != NULL && file->hdr.file_seq == map->hdr.log_file_seq &&
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* we can get a valid log offset from index file. initialize
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen sync_offset from it so we don't have to read the whole log
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen file from beginning. */
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen if (map->hdr.log_file_head_offset >= file->hdr.hdr_size)
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen file->sync_offset = map->hdr.log_file_head_offset;
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen "%s: log_file_head_offset too small",
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen file->saved_tail_offset = map->hdr.log_file_tail_offset;
97db4761382024093f441e4bc78ba8b6a056504dTimo Sirainen /* insert it to correct position */
97db4761382024093f441e4bc78ba8b6a056504dTimo Sirainen for (p = &log->files; *p != NULL; p = &(*p)->next) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_assert((*p)->hdr.file_seq < file->hdr.file_seq);
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainenmail_transaction_log_init_hdr(struct mail_transaction_log *log,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen unsigned int lock_id = 0;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen hdr->major_version = MAIL_TRANSACTION_LOG_MAJOR_VERSION;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen hdr->minor_version = MAIL_TRANSACTION_LOG_MINOR_VERSION;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen hdr->hdr_size = sizeof(struct mail_transaction_log_header);
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen /* not creating index - make sure we have latest header */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen hdr->prev_file_seq = index->map->hdr.log_file_seq;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen hdr->prev_file_offset = index->map->hdr.log_file_head_offset;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen hdr->file_seq = index->map->hdr.log_file_seq + 1;
caea325346da6fb1cf503b35a619467a997acbfaTimo Sirainen if (log->head != NULL && hdr->file_seq <= log->head->hdr.file_seq) {
caea325346da6fb1cf503b35a619467a997acbfaTimo Sirainen /* make sure the sequence grows */
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) {
int ret;
if (ret > 0) {
if (ret < 0) {
bool ignore_estale)
struct mail_transaction_log_file *f;
int ret;
if (ret < 0) {
if (ret == 0) {
bool ignore_estale)
return TRUE;
return FALSE;
const char *path2;
bool rename_existing;
FALSE) == 0) {
if (ret < 0)
if (rename_existing) {
path2);
int fd;
bool check_existing)
bool ignore_estale;
int ret;
else if (check_existing &&
if (ret > 0) {
if (ret == 0) {
i == MAIL_INDEX_ESTALE_RETRY_COUNT) {
const unsigned int offset_pos =
sizeof(sync_offset));
unsigned int trans_size)
int ret;
sizeof(*hdr));
if (ret != 0)
const void *data;
if (trans_size == 0) {
trans_size) < 0)
if (trans_size != 0) {
void *data;
if (ret > 0) {
if (ret == 0) {
void *data;
int ret;
if (ret <= 0)
return ret;
if (ret > 0)
if (ret == 0) {
int ret;
end_offset) == 0)
if (ret <= 0)
return ret;
MADV_SEQUENTIAL) < 0) {
*file)