mail-transaction-log.c revision 6c2ddb9f586e6392552ddfb82ab55e57fcfc4110
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen/* Copyright (c) 2003-2010 Dovecot authors, see the included COPYING file */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenmail_transaction_log_set_head(struct mail_transaction_log *log,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen i_assert(log->files->next != NULL || log->files == file);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenmail_transaction_log_alloc(struct mail_index *index)
c02a056b724abd6578fb8c4e439de0e94eaea6feTimo Sirainen log->dotlock_settings.timeout = MAIL_TRANSCATION_LOG_LOCK_TIMEOUT;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen log->new_dotlock_settings = log->dotlock_settings;
c02a056b724abd6578fb8c4e439de0e94eaea6feTimo Sirainen log->new_dotlock_settings.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenstatic void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
c02a056b724abd6578fb8c4e439de0e94eaea6feTimo Sirainen if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time &&
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (unlink(log->filepath2) < 0 && errno != ENOENT) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenint mail_transaction_log_open(struct mail_transaction_log *log)
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen log->filepath = i_strconcat(log->index->filepath,
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen (log->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
ba90e657bc68a72ab3b3021e2f4a874fac9965baTimo Sirainen (log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen (log->flags & MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL) != 0;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen (log->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen mail_transaction_log_file_free(&log->open_file);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen file = mail_transaction_log_file_alloc(log, log->filepath);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if ((ret = mail_transaction_log_file_open(file, FALSE)) <= 0) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* leave the file for _create() */
9c93e2e3e35bff1bddbe59cef7be296aa24bd79dTimo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log, bool reset)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen file = mail_transaction_log_file_alloc_in_memory(log);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen file = mail_transaction_log_file_alloc(log, log->filepath);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* remember what file we tried to open. if someone else created
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen a new file, use it instead of recreating it */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen file->last_mtime = log->open_file->last_mtime;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen mail_transaction_log_file_free(&log->open_file);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (mail_transaction_log_file_create(file, reset) < 0) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenvoid mail_transaction_log_close(struct mail_transaction_log *log)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen mail_transaction_log_file_free(&log->open_file);
a7bee3930831a9261fa6180d02af29c484d862e9Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **_log)
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenvoid mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (!log->index->initial_mapped && log->files != NULL &&
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* we couldn't read dovecot.index and we don't have the first
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen .log file, so just start from scratch */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen log->filepath = i_strconcat(log->index->filepath,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen mail_transaction_log_file_move_to_memory(log->head);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen file = mail_transaction_log_file_alloc_in_memory(log);
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen for (file = log->files; file != NULL; file = file->next) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (file->hdr.indexid != log->index->indexid) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen "indexid changed: %u -> %u",
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen log->head->hdr.indexid != log->index->indexid) {
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen (void)mail_transaction_log_create(log, FALSE);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenvoid mail_transaction_logs_clean(struct mail_transaction_log *log)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen struct mail_transaction_log_file *file, *next;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* remove only files from the beginning. this way if a view has
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen referenced an old file, it can still find the new files even if
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen there aren't any references to it currently. */
dc9bfb7dc057964238e181d3d8b08751527bb08aTimo Sirainen for (file = log->files; file != NULL; file = next) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* if we still have locked files with refcount=0, unlock them */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen i_assert(log->head == NULL || log->files != NULL);
if (reset) {
int ret;
if (!nfs_flush ||
return ret;
int ret = 0;
if (ret < 0)
return ret;
*mtime_r = 0;