mail-transaction-log-private.h revision 43d32cbe60fdaef2699d99f1ca259053e9350411
285N/A#ifndef MAIL_TRANSACTION_LOG_VIEW_H
285N/A#define MAIL_TRANSACTION_LOG_VIEW_H
285N/A
285N/A#include "file-dotlock.h"
285N/A#include "mail-transaction-log.h"
285N/A
285N/A/* Synchronization can take a while sometimes, especially when copying lots of
285N/A mails. */
285N/A#define MAIL_TRANSCATION_LOG_LOCK_TIMEOUT (3*60)
285N/A#define MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT (3*60)
285N/A
285N/A/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
285N/A#define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*32)
285N/A/* If log is larger than MAX_SIZE, rotate regardless of the time */
285N/A#define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
285N/A#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
285N/A
285N/A/* Delete .log.2 files older than this many seconds */
285N/A#define MAIL_TRANSACTION_LOG2_STALE_SECS (60*30)
285N/A
285N/A#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
285N/A
285N/Astruct mail_transaction_log_file {
285N/A struct mail_transaction_log *log;
285N/A struct mail_transaction_log_file *next;
285N/A
285N/A /* refcount=0 is a valid state. files start that way, and they're
285N/A freed only when mail_transaction_logs_clean() is called. */
285N/A int refcount;
285N/A
285N/A char *filepath;
285N/A int fd;
285N/A
285N/A ino_t st_ino;
285N/A dev_t st_dev;
285N/A time_t last_mtime;
285N/A uoff_t last_size;
285N/A
285N/A struct mail_transaction_log_header hdr;
285N/A buffer_t *buffer;
285N/A uoff_t buffer_offset;
285N/A void *mmap_base;
285N/A size_t mmap_size;
285N/A
285N/A /* points to the next uncommitted transaction. usually same as EOF. */
285N/A uoff_t sync_offset;
285N/A /* saved_tail_offset is the offset that was last written to transaction
285N/A log. max_tail_offset is what should be written to the log the next
285N/A time a transaction is written. transaction log handling may update
285N/A max_tail_offset automatically by making it skip external transactions
285N/A after the last saved offset (to avoid re-reading them unneededly). */
285N/A uoff_t saved_tail_offset, max_tail_offset;
285N/A
285N/A struct file_lock *file_lock;
285N/A
285N/A unsigned int locked:1;
285N/A unsigned int corrupted:1;
285N/A};
285N/A
285N/Astruct mail_transaction_log {
285N/A struct mail_index *index;
285N/A struct mail_transaction_log_view *views;
285N/A
285N/A /* files is a linked list of all the opened log files. the list is
285N/A sorted by the log file sequence, so that transaction views can use
285N/A them easily. head contains a pointer to the newest log file. */
285N/A struct mail_transaction_log_file *files, *head;
285N/A /* open_file is used temporarily while opening the log file.
285N/A if _open() failed, it's left there for _create(). */
285N/A struct mail_transaction_log_file *open_file;
285N/A
285N/A unsigned int dotlock_count;
285N/A struct dotlock_settings dotlock_settings, new_dotlock_settings;
285N/A struct dotlock *dotlock;
285N/A};
285N/A
285N/Avoid
285N/Amail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
285N/A const char *fmt, ...)
285N/A ATTR_FORMAT(2, 3);
285N/A
285N/Astruct mail_transaction_log_file *
285N/Amail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
285N/Astruct mail_transaction_log_file *
285N/Amail_transaction_log_file_alloc(struct mail_transaction_log *log,
285N/A const char *path);
285N/Avoid mail_transaction_log_file_free(struct mail_transaction_log_file **file);
285N/A
285N/Aint mail_transaction_log_file_open(struct mail_transaction_log_file *file,
285N/A bool check_existing);
285N/Aint mail_transaction_log_file_create(struct mail_transaction_log_file *file,
285N/A bool reset);
285N/Aint mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
285N/A
285N/Aint mail_transaction_log_find_file(struct mail_transaction_log *log,
285N/A uint32_t file_seq,
285N/A struct mail_transaction_log_file **file_r);
285N/A
285N/A/* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
285N/A -1 if I/O error */
285N/Aint mail_transaction_log_file_map(struct mail_transaction_log_file *file,
285N/A uoff_t start_offset, uoff_t end_offset);
285N/Avoid mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
285N/A *file);
285N/A
285N/Avoid mail_transaction_logs_clean(struct mail_transaction_log *log);
285N/A
285N/Abool mail_transaction_log_want_rotate(struct mail_transaction_log *log);
285N/Aint mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset);
285N/Aint mail_transaction_log_lock_head(struct mail_transaction_log *log);
285N/Avoid mail_transaction_log_file_unlock(struct mail_transaction_log_file *file);
285N/A
285N/A#endif
285N/A