dovecot-2.0: lib-index: Removed unnecessary code from lock handl...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Oct 6 20:20:32 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/814adaed5b00
changeset: 12248:814adaed5b00
user: Timo Sirainen <tss at iki.fi>
date: Wed Oct 06 17:11:52 2010 +0100
description:
lib-index: Removed unnecessary code from lock handling.
The code was intended only for blocking write-locks, but those haven't been
used for a long time now.
diffstat:
src/lib-index/mail-index-lock.c | 62 ++++++++++---------------------
1 files changed, 20 insertions(+), 42 deletions(-)
diffs (81 lines):
diff -r c61cc8fd42ef -r 814adaed5b00 src/lib-index/mail-index-lock.c
--- a/src/lib-index/mail-index-lock.c Wed Oct 06 16:17:08 2010 +0100
+++ b/src/lib-index/mail-index-lock.c Wed Oct 06 17:11:52 2010 +0100
@@ -42,22 +42,25 @@
int ret;
i_assert(lock_type == F_RDLCK || lock_type == F_WRLCK);
+ i_assert(timeout_secs == 0 || lock_type == F_RDLCK);
- if (lock_type == F_RDLCK && index->lock_type != F_UNLCK) {
- index->shared_lock_count++;
- *lock_id_r = index->lock_id_counter;
- ret = 1;
- } else if (lock_type == F_WRLCK && index->lock_type == F_WRLCK) {
- index->excl_lock_count++;
- *lock_id_r = index->lock_id_counter + 1;
- ret = 1;
- } else {
- ret = 0;
- }
+ switch (lock_type) {
+ case F_RDLCK:
+ if (index->lock_type != F_UNLCK) {
+ index->shared_lock_count++;
+ *lock_id_r = index->lock_id_counter;
+ return 1;
+ }
+ break;
+ case F_WRLCK:
+ if (index->lock_type == F_WRLCK) {
+ index->excl_lock_count++;
+ *lock_id_r = index->lock_id_counter + 1;
+ return 1;
+ }
- if (ret > 0) {
- /* file is already locked */
- return 1;
+ i_assert(index->lock_type == F_UNLCK);
+ break;
}
if (index->lock_method == FILE_LOCK_METHOD_DOTLOCK &&
@@ -74,34 +77,9 @@
return 1;
}
- if (lock_type == F_RDLCK || !index->log_locked) {
- i_assert(index->file_lock == NULL);
- ret = mail_index_lock_fd(index, index->filepath, index->fd,
- lock_type, timeout_secs,
- &index->file_lock);
- } else {
- /* this is kind of kludgy. we wish to avoid deadlocks while
- trying to lock transaction log, but it can happen if our
- process is holding transaction log lock and waiting for
- index write lock, while the other process is holding index
- read lock and waiting for transaction log lock.
-
- we don't have a problem with grabbing read index lock
- because the only way for it to block is if it's
- write-locked, which isn't allowed unless transaction log
- is also locked.
-
- so, the workaround for this problem is that we simply try
- locking once. if it doesn't work, just rewrite the file.
- hopefully there won't be any other deadlocking issues. :) */
- if (index->file_lock == NULL) {
- ret = mail_index_lock_fd(index, index->filepath,
- index->fd, lock_type, 0,
- &index->file_lock);
- } else {
- ret = file_lock_try_update(index->file_lock, lock_type);
- }
- }
+ i_assert(index->file_lock == NULL);
+ ret = mail_index_lock_fd(index, index->filepath, index->fd,
+ lock_type, timeout_secs, &index->file_lock);
if (ret <= 0)
return ret;
More information about the dovecot-cvs
mailing list