From: Timo Sirainen Date: Mon, 30 Mar 2020 14:07:14 +0000 (+0300) Subject: lib-index: Make mail_cache_sync_reset_id() public X-Git-Tag: 2.3.11.2~396 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f472710caa4a38e90346da54f2986db0a1e57e55;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Make mail_cache_sync_reset_id() public Also it no longer requires that cache is already locked when being called. --- diff --git a/src/lib-index/mail-cache-private.h b/src/lib-index/mail-cache-private.h index bdea2c9762..066d222fd8 100644 --- a/src/lib-index/mail-cache-private.h +++ b/src/lib-index/mail-cache-private.h @@ -260,6 +260,7 @@ int mail_cache_map_all(struct mail_cache *cache); void mail_cache_file_close(struct mail_cache *cache); bool mail_cache_need_reopen(struct mail_cache *cache); int mail_cache_reopen(struct mail_cache *cache); +int mail_cache_sync_reset_id(struct mail_cache *cache); /* Notify the decision handling code that field was looked up for seq. This should be called even for fields that aren't currently in cache file. diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 92cec89dc9..3efc85f568 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -685,10 +685,9 @@ mail_cache_sync_wait_index(struct mail_cache *cache, uint32_t *reset_id_r) const char *lock_reason = "cache reset_id sync"; uint32_t file_seq; uoff_t file_offset; + bool cache_locked = cache->file_lock != NULL; int ret; - i_assert(cache->file_lock != NULL); - if (cache->index->log_sync_locked) return 0; @@ -697,7 +696,8 @@ mail_cache_sync_wait_index(struct mail_cache *cache, uint32_t *reset_id_r) unlocks it and only then writes the changes to the index and releases the .log lock.) To prevent deadlocks, cache file must be locked after the .log, not before. */ - mail_cache_unlock_file(cache); + if (cache_locked) + mail_cache_unlock_file(cache); if (mail_transaction_log_sync_lock(cache->index->log, lock_reason, &file_seq, &file_offset) < 0) return -1; @@ -723,12 +723,12 @@ mail_cache_sync_wait_index(struct mail_cache *cache, uint32_t *reset_id_r) else ret = mail_cache_verify_reset_id(cache, reset_id_r) ? 1 : 0; mail_transaction_log_sync_unlock(cache->index->log, lock_reason); - if (ret <= 0) + if (ret <= 0 || !cache_locked) mail_cache_unlock_file(cache); return ret; } -static int mail_cache_sync_reset_id(struct mail_cache *cache) +int mail_cache_sync_reset_id(struct mail_cache *cache) { uint32_t reset_id; int ret;