[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.263, 1.264 mail-transaction-log.c, 1.125, 1.126 mail-transaction-log.h, 1.31, 1.32
tss at dovecot.org
tss at dovecot.org
Thu Mar 8 22:02:39 EET 2007
- Previous message: [dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.230.2.20, 1.230.2.21 mail-transaction-log.c, 1.111.2.13, 1.111.2.14 mail-transaction-log.h, 1.31, 1.31.2.1
- Next message: [dovecot-cvs] dovecot/src/lib Makefile.am, 1.69, 1.70 ioloop-epoll.c, 1.20, 1.21 ioloop-internal.h, 1.18, 1.19 ioloop-iolist.c, 1.2, 1.3 ioloop-iolist.h, 1.2, 1.3 ioloop-kqueue.c, 1.15, 1.16 ioloop-notify-dn.c, 1.18, 1.19 ioloop-notify-fd.c, NONE, 1.1 ioloop-notify-fd.h, NONE, 1.1 ioloop-notify-inotify.c, 1.12, 1.13 ioloop-notify-kqueue.c, 1.8, 1.9 ioloop-poll.c, 1.34, 1.35 ioloop-select.c, 1.24, 1.25 ioloop.c, 1.43, 1.44 ioloop.h, 1.20, 1.21
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv1358
Modified Files:
mail-index.c mail-transaction-log.c mail-transaction-log.h
Log Message:
If index file is corrupted, recreate transaction log file instead of trying
to reuse it.
Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.263
retrieving revision 1.264
diff -u -d -r1.263 -r1.264
--- mail-index.c 6 Mar 2007 19:10:54 -0000 1.263
+++ mail-index.c 8 Mar 2007 20:02:36 -0000 1.264
@@ -1548,7 +1548,7 @@
struct mail_index_header hdr;
unsigned int lock_id = 0;
int ret;
- bool created = FALSE;
+ bool create = FALSE, created = FALSE;
ret = mail_index_try_open(index, &lock_id);
if (ret > 0)
@@ -1560,12 +1560,15 @@
return 0;
mail_index_header_init(&hdr);
index->hdr = &hdr;
+ create = TRUE;
} else if (ret < 0)
return -1;
index->indexid = hdr.indexid;
- index->log = mail_transaction_log_open_or_create(index);
+ index->log = create ?
+ mail_transaction_log_create(index) :
+ mail_transaction_log_open_or_create(index);
if (index->log == NULL) {
if (ret == 0)
index->hdr = NULL;
Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- mail-transaction-log.c 7 Mar 2007 00:47:54 -0000 1.125
+++ mail-transaction-log.c 8 Mar 2007 20:02:37 -0000 1.126
@@ -31,6 +31,12 @@
static struct mail_transaction_log_file *
mail_transaction_log_file_open_or_create(struct mail_transaction_log *log,
const char *path);
+static struct mail_transaction_log_file *
+mail_transaction_log_file_alloc_in_memory(struct mail_transaction_log *log);
+static int
+mail_transaction_log_file_create(struct mail_transaction_log_file *file,
+ bool lock, dev_t dev, ino_t ino,
+ uoff_t file_size);
static int
mail_transaction_log_file_read(struct mail_transaction_log_file *file,
uoff_t offset);
@@ -65,6 +71,62 @@
}
}
+static struct mail_transaction_log_file *
+mail_transaction_log_file_alloc(struct mail_transaction_log *log,
+ const char *path)
+{
+ struct mail_transaction_log_file *file;
+
+ file = i_new(struct mail_transaction_log_file, 1);
+ file->log = log;
+ file->filepath = i_strdup(path);
+ file->fd = -1;
+ return file;
+}
+
+static void
+mail_transaction_log_file_free(struct mail_transaction_log_file *file)
+{
+ struct mail_transaction_log_file **p;
+ int old_errno = errno;
+
+ mail_transaction_log_file_unlock(file);
+
+ for (p = &file->log->files; *p != NULL; p = &(*p)->next) {
+ if (*p == file) {
+ *p = file->next;
+ break;
+ }
+ }
+
+ if (file == file->log->head)
+ file->log->head = NULL;
+
+ if (file->buffer != NULL)
+ buffer_free(file->buffer);
+
+ if (file->mmap_base != NULL) {
+ if (munmap(file->mmap_base, file->mmap_size) < 0) {
+ mail_index_file_set_syscall_error(file->log->index,
+ file->filepath,
+ "munmap()");
+ }
+ }
+
+ if (file->fd != -1) {
+ if (close(file->fd) < 0) {
+ mail_index_file_set_syscall_error(file->log->index,
+ file->filepath,
+ "close()");
+ }
+ }
+
+ i_free(file->filepath);
+ i_free(file);
+
+ errno = old_errno;
+}
+
static int
mail_transaction_log_file_dotlock(struct mail_transaction_log_file *file)
{
@@ -214,10 +276,11 @@
return ret;
}
-struct mail_transaction_log *
-mail_transaction_log_open_or_create(struct mail_index *index)
+static struct mail_transaction_log *
+mail_transaction_log_open_int(struct mail_index *index, bool create)
{
struct mail_transaction_log *log;
+ struct mail_transaction_log_file *file;
const char *path;
log = i_new(struct mail_transaction_log, 1);
@@ -230,19 +293,37 @@
log->new_dotlock_settings = log->dotlock_settings;
log->new_dotlock_settings.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
- path = t_strconcat(log->index->filepath,
+ path = t_strconcat(index->filepath,
MAIL_TRANSACTION_LOG_SUFFIX, NULL);
- log->head = mail_transaction_log_file_open_or_create(log, path);
- if (log->head == NULL) {
+ if (MAIL_INDEX_IS_IN_MEMORY(index))
+ file = mail_transaction_log_file_alloc_in_memory(log);
+ else if (create) {
+ struct stat st;
+
+ file = mail_transaction_log_file_alloc(log, path);
+ if (stat(path, &st) < 0)
+ memset(&st, 0, sizeof(st));
+ if (mail_transaction_log_file_create(file, FALSE,
+ st.st_dev, st.st_ino,
+ st.st_size) < 0) {
+ mail_transaction_log_file_free(file);
+ file = NULL;
+ }
+ } else {
+ file = mail_transaction_log_file_open_or_create(log, path);
+ }
+
+ if (file == NULL) {
/* fallback to in-memory indexes */
if (mail_index_move_to_memory(index) < 0) {
mail_transaction_log_close(&log);
return NULL;
}
- log->head = mail_transaction_log_file_open_or_create(log, path);
- i_assert(log->head != NULL);
+ file = mail_transaction_log_file_open_or_create(log, path);
+ i_assert(file != NULL);
}
- log->head->refcount++;
+ file->refcount++;
+ log->head = file;
if (index->fd != -1 &&
INDEX_HAS_MISSING_LOGS(index, log->head)) {
@@ -257,6 +338,18 @@
return log;
}
+struct mail_transaction_log *
+mail_transaction_log_open_or_create(struct mail_index *index)
+{
+ return mail_transaction_log_open_int(index, FALSE);
+}
+
+struct mail_transaction_log *
+mail_transaction_log_create(struct mail_index *index)
+{
+ return mail_transaction_log_open_int(index, TRUE);
+}
+
void mail_transaction_log_close(struct mail_transaction_log **_log)
{
struct mail_transaction_log *log = *_log;
@@ -273,49 +366,6 @@
i_free(log);
}
-static void
-mail_transaction_log_file_free(struct mail_transaction_log_file *file)
-{
- struct mail_transaction_log_file **p;
- int old_errno = errno;
-
- mail_transaction_log_file_unlock(file);
-
- for (p = &file->log->files; *p != NULL; p = &(*p)->next) {
- if (*p == file) {
- *p = file->next;
- break;
- }
- }
-
- if (file == file->log->head)
- file->log->head = NULL;
-
- if (file->buffer != NULL)
- buffer_free(file->buffer);
-
- if (file->mmap_base != NULL) {
- if (munmap(file->mmap_base, file->mmap_size) < 0) {
- mail_index_file_set_syscall_error(file->log->index,
- file->filepath,
- "munmap()");
- }
- }
-
- if (file->fd != -1) {
- if (close(file->fd) < 0) {
- mail_index_file_set_syscall_error(file->log->index,
- file->filepath,
- "close()");
- }
- }
-
- i_free(file->filepath);
- i_free(file);
-
- errno = old_errno;
-}
-
int mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
{
struct mail_transaction_log_file *file = log->head;
@@ -682,19 +732,6 @@
*p = file;
}
-static struct mail_transaction_log_file *
-mail_transaction_log_file_alloc(struct mail_transaction_log *log,
- const char *path)
-{
- struct mail_transaction_log_file *file;
-
- file = i_new(struct mail_transaction_log_file, 1);
- file->log = log;
- file->filepath = i_strdup(path);
- file->fd = -1;
- return file;
-}
-
static int
mail_transaction_log_file_fd_open(struct mail_transaction_log_file *file,
bool head, bool ignore_estale)
Index: mail-transaction-log.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mail-transaction-log.h 14 Jan 2006 18:47:35 -0000 1.31
+++ mail-transaction-log.h 8 Mar 2007 20:02:37 -0000 1.32
@@ -107,6 +107,8 @@
struct mail_transaction_log *
mail_transaction_log_open_or_create(struct mail_index *index);
+struct mail_transaction_log *
+mail_transaction_log_create(struct mail_index *index);
void mail_transaction_log_close(struct mail_transaction_log **log);
int mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
- Previous message: [dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.230.2.20, 1.230.2.21 mail-transaction-log.c, 1.111.2.13, 1.111.2.14 mail-transaction-log.h, 1.31, 1.31.2.1
- Next message: [dovecot-cvs] dovecot/src/lib Makefile.am, 1.69, 1.70 ioloop-epoll.c, 1.20, 1.21 ioloop-internal.h, 1.18, 1.19 ioloop-iolist.c, 1.2, 1.3 ioloop-iolist.h, 1.2, 1.3 ioloop-kqueue.c, 1.15, 1.16 ioloop-notify-dn.c, 1.18, 1.19 ioloop-notify-fd.c, NONE, 1.1 ioloop-notify-fd.h, NONE, 1.1 ioloop-notify-inotify.c, 1.12, 1.13 ioloop-notify-kqueue.c, 1.8, 1.9 ioloop-poll.c, 1.34, 1.35 ioloop-select.c, 1.24, 1.25 ioloop.c, 1.43, 1.44 ioloop.h, 1.20, 1.21
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list