[dovecot-cvs] dovecot/src/lib-index mail-index-open.c,1.14,1.15 mail-modifylog.c,1.34,1.35 mail-tree.c,1.9,1.10
cras at procontrol.fi
cras at procontrol.fi
Wed Nov 6 09:08:06 EET 2002
Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv8073
Modified Files:
mail-index-open.c mail-modifylog.c mail-tree.c
Log Message:
Fixes to make in-memory indexes working again.
Index: mail-index-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-open.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mail-index-open.c 4 Nov 2002 04:47:40 -0000 1.14
+++ mail-index-open.c 6 Nov 2002 07:08:04 -0000 1.15
@@ -362,7 +362,7 @@
{
MailIndexHeader hdr;
const char *path, *index_path;
- int fd;
+ int fd, nodiskspace;
*dir_unlocked = FALSE;
index_path = NULL;
@@ -430,6 +430,7 @@
if (!mail_index_data_create(index))
break;
+ nodiskspace = index->nodiskspace;
if (!index->rebuild(index)) {
if (!index->anon_mmap && index->nodiskspace) {
/* we're out of disk space, keep it in
@@ -443,6 +444,9 @@
break;
}
+ /* rebuild() resets the nodiskspace variable */
+ index->nodiskspace = nodiskspace;
+
if (!mail_tree_create(index))
break;
if (!mail_modifylog_create(index))
@@ -524,7 +528,7 @@
mail_index_cleanup_temp_files(index->dir);
if (mail_index_open(index, update_recent, fast))
- return TRUE;
+ return TRUE;
/* index wasn't found or it was broken. lock the directory and check
again, just to make sure we don't end up having two index files
Index: mail-modifylog.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-modifylog.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- mail-modifylog.c 4 Nov 2002 07:11:32 -0000 1.34
+++ mail-modifylog.c 6 Nov 2002 07:08:04 -0000 1.35
@@ -516,10 +516,12 @@
{
file->mmap_full_length = MODIFY_LOG_INITIAL_SIZE;
file->mmap_base = mmap_anon(file->mmap_full_length);
+ file->header = file->mmap_base;
mail_modifylog_init_header(file->log, file->mmap_base);
- file->header = file->mmap_base;
+
file->mmap_used_length = file->header->used_file_size;
+ file->synced_position = file->mmap_used_length;
file->anon_mmap = TRUE;
file->filepath = i_strdup("(in-memory modify log)");
Index: mail-tree.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-tree.c 2 Nov 2002 20:10:20 -0000 1.9
+++ mail-tree.c 6 Nov 2002 07:08:04 -0000 1.10
@@ -168,27 +168,18 @@
return tree;
}
-static void mail_tree_close(MailTree *tree)
+static MailTree *mail_tree_create_anon(MailIndex *index)
{
- if (tree->anon_mmap) {
- if (munmap_anon(tree->mmap_base, tree->mmap_full_length) < 0)
- tree_set_syscall_error(tree, "munmap_anon()");
- } else if (tree->mmap_base != NULL) {
- if (munmap(tree->mmap_base, tree->mmap_full_length) < 0)
- tree_set_syscall_error(tree, "munmap()");
- }
- tree->mmap_base = NULL;
- tree->mmap_full_length = 0;
- tree->mmap_used_length = 0;
- tree->header = NULL;
+ MailTree *tree;
- if (tree->fd != -1) {
- if (close(tree->fd) < 0)
- tree_set_syscall_error(tree, "close()");
- tree->fd = -1;
- }
+ tree = i_new(MailTree, 1);
+ tree->anon_mmap = TRUE;
+ tree->fd = -1;
+ tree->index = index;
+ tree->filepath = i_strdup("(in-memory tree)");
- i_free(tree->filepath);
+ index->tree = tree;
+ return tree;
}
int mail_tree_create(MailIndex *index)
@@ -197,7 +188,8 @@
i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
- tree = mail_tree_open(index);
+ tree = !index->nodiskspace ? mail_tree_open(index) :
+ mail_tree_create_anon(index);
if (tree == NULL)
return FALSE;
@@ -245,6 +237,29 @@
return FALSE;
}
+static void mail_tree_close(MailTree *tree)
+{
+ if (tree->anon_mmap) {
+ if (munmap_anon(tree->mmap_base, tree->mmap_full_length) < 0)
+ tree_set_syscall_error(tree, "munmap_anon()");
+ } else if (tree->mmap_base != NULL) {
+ if (munmap(tree->mmap_base, tree->mmap_full_length) < 0)
+ tree_set_syscall_error(tree, "munmap()");
+ }
+ tree->mmap_base = NULL;
+ tree->mmap_full_length = 0;
+ tree->mmap_used_length = 0;
+ tree->header = NULL;
+
+ if (tree->fd != -1) {
+ if (close(tree->fd) < 0)
+ tree_set_syscall_error(tree, "close()");
+ tree->fd = -1;
+ }
+
+ i_free(tree->filepath);
+}
+
void mail_tree_free(MailTree *tree)
{
tree->index->tree = NULL;
@@ -262,6 +277,13 @@
hdr.indexid = tree->index->indexid;
hdr.used_file_size = sizeof(MailTreeHeader) + sizeof(MailTreeNode);
+ if (tree->anon_mmap) {
+ tree->mmap_full_length = MAIL_TREE_MIN_SIZE;
+ tree->mmap_base = mmap_anon(tree->mmap_full_length);
+ memcpy(tree->mmap_base, &hdr, sizeof(MailTreeHeader));
+ return mmap_verify(tree);
+ }
+
if (lseek(tree->fd, 0, SEEK_SET) < 0)
return tree_set_syscall_error(tree, "lseek()");
@@ -290,7 +312,7 @@
return FALSE;
if (!mail_tree_init(tree) ||
- !_mail_tree_mmap_update(tree, TRUE)) {
+ (!tree->anon_mmap && !_mail_tree_mmap_update(tree, TRUE))) {
tree->index->header->flags |= MAIL_INDEX_FLAG_REBUILD_TREE;
return FALSE;
}
@@ -354,7 +376,7 @@
tree->mmap_base = base;
tree->mmap_full_length = (size_t)new_fsize;
- return TRUE;
+ return mmap_verify(tree);
}
if (file_set_size(tree->fd, (off_t)new_fsize) < 0) {
More information about the dovecot-cvs
mailing list