mail-transaction-log-private.h revision 2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224b
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#ifndef __MAIL_TRANSACTION_LOG_VIEW_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define __MAIL_TRANSACTION_LOG_VIEW_H
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#include "file-dotlock.h"
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#include "mail-transaction-log.h"
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#if 0 // FIXME
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*4)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* If log is larger than MAX_SIZE, rotate regardless of the time */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*16)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_ROTATE_TIME (30)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#else
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE (1024*256)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch/* If log is larger than MAX_SIZE, rotate regardless of the time */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch#endif
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Boschstruct mail_transaction_log_file {
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch struct mail_transaction_log *log;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch struct mail_transaction_log_file *next;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* refcount=0 is a valid state. files start that way, and they're
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch freed only when mail_transaction_logs_clean() is called. */
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch int refcount;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch char *filepath;
96fbbe9c6fd04bca25770020bf94eec50888bc9bStephan Bosch int fd;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
659f431cb56f26ec07e308db4d6c563c0eaa5300Stephan Bosch ino_t st_ino;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch dev_t st_dev;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch time_t last_mtime;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch uoff_t last_size;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch struct mail_transaction_log_header hdr;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch buffer_t *buffer;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch uoff_t buffer_offset;
659f431cb56f26ec07e308db4d6c563c0eaa5300Stephan Bosch void *mmap_base;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch size_t mmap_size;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch
96fbbe9c6fd04bca25770020bf94eec50888bc9bStephan Bosch /* points to the next uncommitted transaction. usually same as EOF. */
620b60321d04006b32a116824d49b88b61be7131Stephan Bosch uoff_t sync_offset;
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch /* saved_offset is the offset that was last written to transaction log.
620b60321d04006b32a116824d49b88b61be7131Stephan Bosch max_offset is what should be written to the log the next time a
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch transaction is written. transaction log handling may update
f9511e684858bf5f6ac77ab12254b85b737beae8Stephan Bosch max_offset automatically by making it skip external transactions
after the last saved offset (to avoid re-reading them unneededly). */
uoff_t mailbox_sync_saved_offset, mailbox_sync_max_offset;
struct file_lock *file_lock;
unsigned int locked:1;
};
struct mail_transaction_log {
struct mail_index *index;
struct mail_transaction_log_view *views;
/* files is a linked list of all the opened log files. the list is
sorted by the log file sequence, so that transaction views can use
them easily. head contains a pointer to the newest log file. */
struct mail_transaction_log_file *files, *head;
/* open_file is used temporarily while opening the log file.
if _open() failed, it's left there for _create(). */
struct mail_transaction_log_file *open_file;
unsigned int dotlock_count;
struct dotlock_settings dotlock_settings, new_dotlock_settings;
struct dotlock *dotlock;
};
void
mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
const char *fmt, ...)
__attr_format__(2, 3);
struct mail_transaction_log_file *
mail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
struct mail_transaction_log_file *
mail_transaction_log_file_alloc(struct mail_transaction_log *log,
const char *path);
void mail_transaction_log_file_free(struct mail_transaction_log_file **file);
int mail_transaction_log_file_open(struct mail_transaction_log_file *file,
bool check_existing);
int mail_transaction_log_file_create(struct mail_transaction_log_file *file);
int mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
int mail_transaction_log_find_file(struct mail_transaction_log *log,
uint32_t file_seq,
struct mail_transaction_log_file **file_r);
/* Returns 1 if ok, 0 if file is corrupted or offset range is invalid,
-1 if I/O error */
int mail_transaction_log_file_map(struct mail_transaction_log_file *file,
uoff_t start_offset, uoff_t end_offset);
void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
*file);
void mail_transaction_logs_clean(struct mail_transaction_log *log);
bool mail_transaction_log_want_rotate(struct mail_transaction_log *log);
int mail_transaction_log_rotate(struct mail_transaction_log *log);
int mail_transaction_log_lock_head(struct mail_transaction_log *log);
void mail_transaction_log_file_unlock(struct mail_transaction_log_file *file);
#endif