dovecot-1.2: Mail cache compression: If we can't get lock immedi...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Sep 11 17:01:36 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/2db48458d73b
changeset: 8188:2db48458d73b
user: Timo Sirainen <tss at iki.fi>
date: Thu Sep 11 17:01:32 2008 +0300
description:
Mail cache compression: If we can't get lock immediately, do it later.
diffstat:
3 files changed, 26 insertions(+), 8 deletions(-)
src/lib-index/mail-cache-compress.c | 7 ++++---
src/lib-index/mail-cache-private.h | 1 +
src/lib-index/mail-cache.c | 26 +++++++++++++++++++++-----
diffs (106 lines):
diff -r f1203dce2d8c -r 2db48458d73b src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c Thu Sep 11 16:52:47 2008 +0300
+++ b/src/lib-index/mail-cache-compress.c Thu Sep 11 17:01:32 2008 +0300
@@ -361,11 +361,12 @@ static int mail_cache_compress_locked(st
old_mask = umask(cache->index->mode ^ 0666);
fd = file_dotlock_open(&cache->dotlock_settings, cache->filepath,
- 0, &dotlock);
+ DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
umask(old_mask);
if (fd == -1) {
- mail_cache_set_syscall_error(cache, "file_dotlock_open()");
+ if (errno != EAGAIN)
+ mail_cache_set_syscall_error(cache, "file_dotlock_open()");
return -1;
}
@@ -467,7 +468,7 @@ int mail_cache_compress(struct mail_cach
FALSE);
}
} else {
- switch (mail_cache_lock(cache, FALSE)) {
+ switch (mail_cache_try_lock(cache)) {
case -1:
return -1;
case 0:
diff -r f1203dce2d8c -r 2db48458d73b src/lib-index/mail-cache-private.h
--- a/src/lib-index/mail-cache-private.h Thu Sep 11 16:52:47 2008 +0300
+++ b/src/lib-index/mail-cache-private.h Thu Sep 11 17:01:32 2008 +0300
@@ -224,6 +224,7 @@ int mail_cache_open_and_verify(struct ma
/* Explicitly lock the cache file. Returns -1 if error / timed out,
1 if ok, 0 if cache is broken/doesn't exist */
int mail_cache_lock(struct mail_cache *cache, bool require_same_reset_id);
+int mail_cache_try_lock(struct mail_cache *cache);
/* Returns -1 if cache is / just got corrupted, 0 if ok. */
int mail_cache_unlock(struct mail_cache *cache);
diff -r f1203dce2d8c -r 2db48458d73b src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c Thu Sep 11 16:52:47 2008 +0300
+++ b/src/lib-index/mail-cache.c Thu Sep 11 17:01:32 2008 +0300
@@ -460,7 +460,7 @@ void mail_cache_free(struct mail_cache *
i_free(cache);
}
-static int mail_cache_lock_file(struct mail_cache *cache)
+static int mail_cache_lock_file(struct mail_cache *cache, bool nonblock)
{
int ret;
@@ -468,12 +468,16 @@ static int mail_cache_lock_file(struct m
i_assert(cache->file_lock == NULL);
ret = mail_index_lock_fd(cache->index, cache->filepath,
cache->fd, F_WRLCK,
- MAIL_CACHE_LOCK_TIMEOUT,
+ nonblock ? 0 : MAIL_CACHE_LOCK_TIMEOUT,
&cache->file_lock);
} else {
+ enum dotlock_create_flags flags =
+ nonblock ? DOTLOCK_CREATE_FLAG_NONBLOCK : 0;
+
i_assert(cache->dotlock == NULL);
ret = file_dotlock_create(&cache->dotlock_settings,
- cache->filepath, 0, &cache->dotlock);
+ cache->filepath, flags,
+ &cache->dotlock);
if (ret <= 0) {
mail_cache_set_syscall_error(cache,
"file_dotlock_create()");
@@ -496,7 +500,9 @@ static void mail_cache_unlock_file(struc
(void)file_dotlock_delete(&cache->dotlock);
}
-int mail_cache_lock(struct mail_cache *cache, bool require_same_reset_id)
+static int
+mail_cache_lock_full(struct mail_cache *cache, bool require_same_reset_id,
+ bool nonblock)
{
const struct mail_index_ext *ext;
struct mail_index_view *iview;
@@ -538,7 +544,7 @@ int mail_cache_lock(struct mail_cache *c
break;
}
- if ((ret = mail_cache_lock_file(cache)) <= 0) {
+ if ((ret = mail_cache_lock_file(cache, nonblock)) <= 0) {
ret = -1;
break;
}
@@ -571,6 +577,16 @@ int mail_cache_lock(struct mail_cache *c
i_assert((ret <= 0 && !cache->locked) || (ret > 0 && cache->locked));
return ret;
+}
+
+int mail_cache_lock(struct mail_cache *cache, bool require_same_reset_id)
+{
+ return mail_cache_lock_full(cache, require_same_reset_id, FALSE);
+}
+
+int mail_cache_try_lock(struct mail_cache *cache)
+{
+ return mail_cache_lock_full(cache, FALSE, TRUE);
}
static void mail_cache_update_need_compress(struct mail_cache *cache)
More information about the dovecot-cvs
mailing list