dovecot-2.2: lib-index: Handle better race condition there dovec...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Oct 29 17:55:54 EET 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/bcef97fb1202
changeset: 15315:bcef97fb1202
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 18 05:55:30 2012 +0300
description:
lib-index: Handle better race condition there dovecot.index.log and .log.2 are the same link.
diffstat:
src/lib-index/mail-transaction-log-file.c | 15 ++++++++++-----
src/lib-index/mail-transaction-log-private.h | 3 +--
src/lib-index/mail-transaction-log.c | 6 +++---
3 files changed, 14 insertions(+), 10 deletions(-)
diffs (83 lines):
diff -r b7c6215b2b7c -r bcef97fb1202 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c Thu Oct 18 05:23:27 2012 +0300
+++ b/src/lib-index/mail-transaction-log-file.c Thu Oct 18 05:55:30 2012 +0300
@@ -756,6 +756,9 @@
second log file and we're going to overwrite this
first one. */
}
+ /* NOTE: here's a race condition where both .log and .log.2
+ point to the same file. our reading code should ignore that
+ though by comparing the inodes. */
}
if (file_dotlock_replace(dotlock,
@@ -809,8 +812,7 @@
return 0;
}
-int mail_transaction_log_file_open(struct mail_transaction_log_file *file,
- bool check_existing)
+int mail_transaction_log_file_open(struct mail_transaction_log_file *file)
{
struct mail_index *index = file->log->index;
unsigned int i;
@@ -834,10 +836,13 @@
ignore_estale = i < MAIL_INDEX_ESTALE_RETRY_COUNT;
if (mail_transaction_log_file_stat(file, ignore_estale) < 0)
ret = -1;
- else if (check_existing &&
- mail_transaction_log_file_is_dupe(file))
+ else if (mail_transaction_log_file_is_dupe(file)) {
+ /* probably our already opened .log file has been
+ renamed to .log.2 and we're trying to reopen it.
+ also possible that hit a race condition where .log
+ and .log.2 are linked. */
return 0;
- else {
+ } else {
ret = mail_transaction_log_file_read_hdr(file,
ignore_estale);
}
diff -r b7c6215b2b7c -r bcef97fb1202 src/lib-index/mail-transaction-log-private.h
--- a/src/lib-index/mail-transaction-log-private.h Thu Oct 18 05:23:27 2012 +0300
+++ b/src/lib-index/mail-transaction-log-private.h Thu Oct 18 05:55:30 2012 +0300
@@ -117,8 +117,7 @@
const char *path);
void mail_transaction_log_file_free(struct mail_transaction_log_file **file);
-int mail_transaction_log_file_open(struct mail_transaction_log_file *file,
- bool check_existing);
+int mail_transaction_log_file_open(struct mail_transaction_log_file *file);
int mail_transaction_log_file_create(struct mail_transaction_log_file *file,
bool reset);
int mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
diff -r b7c6215b2b7c -r bcef97fb1202 src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c Thu Oct 18 05:23:27 2012 +0300
+++ b/src/lib-index/mail-transaction-log.c Thu Oct 18 05:55:30 2012 +0300
@@ -84,7 +84,7 @@
return 0;
file = mail_transaction_log_file_alloc(log, log->filepath);
- if ((ret = mail_transaction_log_file_open(file, FALSE)) <= 0) {
+ if ((ret = mail_transaction_log_file_open(file)) <= 0) {
/* leave the file for _create() */
log->open_file = file;
return ret;
@@ -322,7 +322,7 @@
}
file = mail_transaction_log_file_alloc(log, log->filepath);
- if (mail_transaction_log_file_open(file, FALSE) <= 0) {
+ if (mail_transaction_log_file_open(file) <= 0) {
mail_transaction_log_file_free(&file);
return -1;
}
@@ -400,7 +400,7 @@
/* see if we have it in log.2 file */
file = mail_transaction_log_file_alloc(log, log->filepath2);
- if ((ret = mail_transaction_log_file_open(file, TRUE)) <= 0) {
+ if ((ret = mail_transaction_log_file_open(file)) <= 0) {
mail_transaction_log_file_free(&file);
return ret;
}
More information about the dovecot-cvs
mailing list