view src/lib-index/mail-transaction-log-private.h @ 9191:b340ecb24469 HEAD

Fix VPATH build of RQUOTA support. Some rpcgen derive #include "..." paths from the infile argument. This will be off for VPATH builds, as the generated rquota_xdr.c code will look in $(srcdir), but we'll generate the rquota.h file in $(builddir). Play safe and copy rquota.x to $(builddir) first. This fixes the build on openSUSE 11.1.
author Matthias Andree <>
date Tue, 07 Jul 2009 21:01:36 +0200
parents c8d63b42e9cc
line wrap: on
line source


#include "file-dotlock.h"
#include "mail-transaction-log.h"

/* Synchronization can take a while sometimes, especially when copying lots of
   mails. */

/* Rotate when log is older than ROTATE_TIME and larger than MIN_SIZE */
/* If log is larger than MAX_SIZE, rotate regardless of the time */

/* Delete .log.2 files older than this many seconds */

#define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)


struct modseq_cache {
	uoff_t offset;
	uint64_t highest_modseq;

struct mail_transaction_log_file {
	struct mail_transaction_log *log;
        struct mail_transaction_log_file *next;

	/* refcount=0 is a valid state. files start that way, and they're
	   freed only when mail_transaction_logs_clean() is called. */
	int refcount;

	char *filepath;
	int fd;

	ino_t st_ino;
	dev_t st_dev;
	time_t last_mtime;
	uoff_t last_size;

	struct mail_transaction_log_header hdr;
	buffer_t *buffer;
	uoff_t buffer_offset;
	void *mmap_base;
	size_t mmap_size;

	/* points to the next uncommitted transaction. usually same as EOF. */
	uoff_t sync_offset;
	/* highest modseq at sync_offset */
	uint64_t sync_highest_modseq;
	/* saved_tail_offset is the offset that was last written to transaction
	   log. max_tail_offset is what should be written to the log the next
	   time a transaction is written. transaction log handling may update
	   max_tail_offset automatically by making it skip external transactions
	   after the last saved offset (to avoid re-reading them unneededly). */
	uoff_t saved_tail_offset, max_tail_offset;
	/* don't give warnings about saved_tail_offset shrinking if
	   sync_offset is less than this. */
	uoff_t saved_tail_sync_offset;

	struct modseq_cache modseq_cache[LOG_FILE_MODSEQ_CACHE_SIZE];

	struct file_lock *file_lock;

	unsigned int locked:1;
	unsigned int corrupted: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;

mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
					const char *fmt, ...)

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,
				     bool reset);
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, bool nfs_flush,
				   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

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, bool reset);
int mail_transaction_log_lock_head(struct mail_transaction_log *log);
void mail_transaction_log_file_unlock(struct mail_transaction_log_file *file);

mail_transaction_header_has_modseq(const struct mail_transaction_header *hdr,
				   const void *data,
				   uint64_t cur_modseq);
int mail_transaction_log_file_get_highest_modseq_at(
		struct mail_transaction_log_file *file,
		uoff_t offset, uint64_t *highest_modseq_r);
int mail_transaction_log_file_get_modseq_next_offset(
		struct mail_transaction_log_file *file,
		uint64_t modseq, uoff_t *next_offset_r);