[dovecot-cvs] dovecot/src/lib-index mail-index-open.c,1.12,1.13 mail-index-update-cache.c,1.9,1.10 mail-index.c,1.66,1.67 mail-index.h,1.48,1.49 mail-tree.c,1.8,1.9
cras at procontrol.fi
cras at procontrol.fi
Sat Nov 2 22:10:23 EET 2002
- Previous message: [dovecot-cvs] dovecot/src/lib-index/maildir maildir-index.h,1.9,1.10 maildir-sync.c,1.15,1.16
- Next message: [dovecot-cvs] dovecot/src/lib-index/mbox mbox-index.c,1.42,1.43 mbox-index.h,1.19,1.20 mbox-lock.c,1.10,1.11 mbox-rewrite.c,1.34,1.35 mbox-sync-full.c,1.2,1.3 mbox-sync.c,1.16,1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv8907/lib-index
Modified Files:
mail-index-open.c mail-index-update-cache.c mail-index.c
mail-index.h mail-tree.c
Log Message:
Mostly mbox locking/syncing fixes. Still some problems though.
Index: mail-index-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-open.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mail-index-open.c 23 Oct 2002 20:41:35 -0000 1.12
+++ mail-index-open.c 2 Nov 2002 20:10:20 -0000 1.13
@@ -212,9 +212,9 @@
return FALSE;
}
- /* sync before updating cached fields so it won't print
- warnings if mails were deleted */
- if (!index->sync(index))
+ /* sync ourself - before updating cache and compression which
+ may happen because of this. */
+ if (!index->sync_and_lock(index, MAIL_LOCK_EXCLUSIVE, NULL))
return FALSE;
if (!fast && (index->header->flags & MAIL_INDEX_FLAG_CACHE_FIELDS)) {
Index: mail-index-update-cache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-update-cache.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-index-update-cache.c 27 Oct 2002 06:37:18 -0000 1.9
+++ mail-index-update-cache.c 2 Nov 2002 20:10:20 -0000 1.10
@@ -38,10 +38,6 @@
if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
return FALSE;
- /* make sure the index is ok before doing this */
- if (!index->fsck(index))
- return FALSE;
-
cache_fields = index->header->cache_fields;
rec = index->lookup(index, 1);
Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- mail-index.c 29 Oct 2002 06:46:47 -0000 1.66
+++ mail-index.c 2 Nov 2002 20:10:20 -0000 1.67
@@ -248,23 +248,6 @@
}
}
-int mail_index_try_lock(MailIndex *index, MailLockType lock_type)
-{
- int ret;
-
- if (index->lock_type == lock_type)
- return TRUE;
-
- if (index->anon_mmap)
- return TRUE;
-
- ret = file_try_lock(index->fd, MAIL_LOCK_TO_FLOCK(lock_type));
- if (ret < 0)
- index_set_syscall_error(index, "file_try_lock()");
-
- return ret > 0;
-}
-
static int mail_index_write_header_changes(MailIndex *index)
{
int failed;
@@ -274,12 +257,21 @@
if (file_wait_lock(index->fd, F_WRLCK, DEFAULT_LOCK_TIMEOUT) <= 0)
return index_set_syscall_error(index, "file_wait_lock()");
+#ifdef DEBUG
+ mprotect(index->mmap_base, index->mmap_used_length,
+ PROT_READ|PROT_WRITE);
+#endif
+
mail_index_update_header_changes(index);
failed = msync(index->mmap_base, sizeof(MailIndexHeader), MS_SYNC) < 0;
if (failed)
index_set_syscall_error(index, "msync()");
+#ifdef DEBUG
+ mprotect(index->mmap_base, index->mmap_used_length, PROT_NONE);
+#endif
+
if (file_wait_lock(index->fd, F_UNLCK, 0) <= 0)
return index_set_syscall_error(index, "file_wait_lock()");
@@ -313,10 +305,13 @@
return TRUE;
}
-static int mail_index_lock_change(MailIndex *index, MailLockType lock_type)
+static int mail_index_lock_change(MailIndex *index, MailLockType lock_type,
+ int try_lock)
{
- /* shared -> exclusive isn't allowed */
- i_assert(lock_type != MAIL_LOCK_EXCLUSIVE ||
+ int ret, fd_lock_type;
+
+ /* shared -> exclusive isn't allowed without try_lock */
+ i_assert(try_lock || lock_type != MAIL_LOCK_EXCLUSIVE ||
index->lock_type != MAIL_LOCK_SHARED);
if (index->inconsistent) {
@@ -325,9 +320,20 @@
return FALSE;
}
- if (file_wait_lock(index->fd, MAIL_LOCK_TO_FLOCK(lock_type),
- DEFAULT_LOCK_TIMEOUT) <= 0)
- return index_set_syscall_error(index, "file_wait_lock()");
+ fd_lock_type = MAIL_LOCK_TO_FLOCK(lock_type);
+ if (try_lock) {
+ ret = file_try_lock(index->fd, fd_lock_type);
+ if (ret < 0)
+ index_set_syscall_error(index, "file_try_lock()");
+ if (ret <= 0)
+ return FALSE;
+ } else {
+ if (file_wait_lock(index->fd, fd_lock_type,
+ DEFAULT_LOCK_TIMEOUT) <= 0) {
+ return index_set_syscall_error(index,
+ "file_wait_lock()");
+ }
+ }
index->lock_type = lock_type;
debug_mprotect(index->mmap_base, index->mmap_full_length, index);
@@ -389,7 +395,8 @@
return TRUE;
}
-int mail_index_set_lock(MailIndex *index, MailLockType lock_type)
+int mail_index_lock_full(MailIndex *index, MailLockType lock_type,
+ int try_lock)
{
int keep_fsck;
@@ -425,7 +432,17 @@
if (lock_type == MAIL_LOCK_UNLOCK)
return mail_index_lock_remove(index);
else
- return mail_index_lock_change(index, lock_type);
+ return mail_index_lock_change(index, lock_type, try_lock);
+}
+
+int mail_index_set_lock(MailIndex *index, MailLockType lock_type)
+{
+ return mail_index_lock_full(index, lock_type, FALSE);
+}
+
+int mail_index_try_lock(MailIndex *index, MailLockType lock_type)
+{
+ return mail_index_lock_full(index, lock_type, TRUE);
}
int mail_index_verify_hole_range(MailIndex *index)
Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- mail-index.h 29 Oct 2002 06:46:47 -0000 1.48
+++ mail-index.h 2 Nov 2002 20:10:20 -0000 1.49
@@ -199,9 +199,13 @@
Same locking issues as with rebuild(). */
int (*fsck)(MailIndex *index);
- /* Synchronize the index with the mailbox. Same locking issues as
- with rebuild(). */
- int (*sync)(MailIndex *index);
+ /* Synchronize the index with the mailbox. Index must not have shared
+ lock when calling this function. The lock_type specifies what
+ locking state the index will be left, also locking mailbox file
+ if needed. If changes is non-NULL, it's set to TRUE if any changes
+ were noticed. */
+ int (*sync_and_lock)(MailIndex *index, MailLockType lock_type,
+ int *changes);
/* Returns the index header (never fails). The index needs to be
locked before calling this function, and must be kept locked as
@@ -329,7 +333,6 @@
int mbox_fd;
IBuffer *mbox_inbuf;
MailLockType mbox_lock_type;
- MailLockType mbox_lock_next_sync;
/* these counters can be used to check that we've synced the mailbox
after locking it */
@@ -371,7 +374,7 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0, 0, 0, 0, 0
+ 0, 0, 0, 0
/* defaults - same as above but prefixed with mail_index_. */
int mail_index_open(MailIndex *index, int update_recent, int fast);
Index: mail-tree.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-tree.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mail-tree.c 28 Oct 2002 09:31:40 -0000 1.8
+++ mail-tree.c 2 Nov 2002 20:10:20 -0000 1.9
@@ -125,6 +125,9 @@
int _mail_tree_mmap_update(MailTree *tree, int forced)
{
+ debug_mprotect(tree->mmap_base, tree->mmap_full_length,
+ tree->index);
+
if (!forced && tree->header != NULL &&
tree->sync_id == tree->header->sync_id) {
/* make sure file size hasn't changed */
- Previous message: [dovecot-cvs] dovecot/src/lib-index/maildir maildir-index.h,1.9,1.10 maildir-sync.c,1.15,1.16
- Next message: [dovecot-cvs] dovecot/src/lib-index/mbox mbox-index.c,1.42,1.43 mbox-index.h,1.19,1.20 mbox-lock.c,1.10,1.11 mbox-rewrite.c,1.34,1.35 mbox-sync-full.c,1.2,1.3 mbox-sync.c,1.16,1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list