From: Timo Sirainen Date: Sun, 30 May 2004 16:35:18 +0000 (+0300) Subject: fixes X-Git-Tag: 1.1.alpha1~4011 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8830fab191cab8440281eb641dfdd93974b2933b;p=thirdparty%2Fdovecot%2Fcore.git fixes --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index 621b73207f..5259fbcdda 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -65,7 +65,7 @@ static int mail_index_check_header(struct mail_index *index, } if ((map->hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) { - /* either a crash or we've already complained about it */ + /* we've already complained about it */ return -1; } @@ -292,7 +292,12 @@ int mail_index_map(struct mail_index *index, int force) } else if (map->mmap_base != NULL) { /* see if re-mmaping is needed (file has grown) */ hdr = map->mmap_base; - used_size = hdr->header_size + + + /* always check corrupted-flag to avoid errors later */ + if ((map->hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) + return -1; + + used_size = hdr->header_size + hdr->messages_count * sizeof(struct mail_index_record); if (map->mmap_size >= used_size && !force) { map->records_count = hdr->messages_count; @@ -476,9 +481,6 @@ static int mail_index_create(struct mail_index *index, if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0) return -1; - hdr->log_file_seq = seq; - hdr->log_file_offset = offset; - ret = mail_index_try_open(index, NULL); if (ret != 0) { mail_transaction_log_sync_unlock(index->log); diff --git a/src/lib-index/mail-transaction-log-view.c b/src/lib-index/mail-transaction-log-view.c index 8e6327f655..38055341e9 100644 --- a/src/lib-index/mail-transaction-log-view.c +++ b/src/lib-index/mail-transaction-log-view.c @@ -139,7 +139,7 @@ mail_transaction_log_view_set(struct mail_transaction_log_view *view, if (file == NULL || file->hdr.file_seq != seq) { mail_index_set_error(view->log->index, "Lost transaction log file %s seq %u", - file->filepath, seq); + view->log->tail->filepath, seq); return -1; } diff --git a/src/lib-index/mail-transaction-log.c b/src/lib-index/mail-transaction-log.c index 8fb059a85f..33d340974a 100644 --- a/src/lib-index/mail-transaction-log.c +++ b/src/lib-index/mail-transaction-log.c @@ -314,6 +314,8 @@ mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file, return 0; } + /* index file was probably just rebuilt and we don't know + about it yet */ mail_index_set_error(file->log->index, "Transaction log file %s: invalid indexid (%u != %u)", file->filepath, file->hdr.indexid, @@ -344,6 +346,7 @@ mail_transaction_log_file_create(struct mail_transaction_log *log, struct mail_index *index = log->index; struct mail_transaction_log_header hdr; struct stat st; + unsigned int lock_id; int fd, fd2, ret; /* With dotlocking we might already have path.lock created, so this @@ -387,11 +390,16 @@ mail_transaction_log_file_create(struct mail_transaction_log *log, hdr.used_size = sizeof(hdr); if (index->fd != -1) { + if (mail_index_lock_shared(index, TRUE, &lock_id) < 0) + return -1; hdr.prev_file_seq = index->hdr->log_file_seq; hdr.prev_file_offset = index->hdr->log_file_offset; } hdr.file_seq = index->hdr->log_file_seq+1; + if (index->fd != -1) + mail_index_unlock(index, lock_id); + if (log->head != NULL && hdr.file_seq <= log->head->hdr.file_seq) { /* make sure the sequence grows */ hdr.file_seq = log->head->hdr.file_seq+1; @@ -614,6 +622,8 @@ static int mail_transaction_log_refresh(struct mail_transaction_log *log) if (file == NULL) return -1; + i_assert(file->lock_type == F_UNLCK); + if (log->head != NULL) { if (--log->head->refcount == 0) mail_transaction_logs_clean(log); @@ -1021,19 +1031,27 @@ int mail_transaction_log_append(struct mail_index_transaction *t, return -1; } - /* FIXME: index->hdr may not be up-to-date and so log_file_seq check - might go wrong! sync header before we get here. */ - if (log->head->hdr.file_seq == index->hdr->log_file_seq && - log->head->hdr.used_size > MAIL_TRANSACTION_LOG_ROTATE_SIZE && + if (log->head->hdr.used_size > MAIL_TRANSACTION_LOG_ROTATE_SIZE && log->head->last_mtime < ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME) { - /* everything synced in index, we can rotate. */ - if (mail_transaction_log_rotate(log, F_WRLCK) < 0) { - if (!log->index->log_locked) { - (void)mail_transaction_log_file_lock(log->head, - F_UNLCK); + /* we might want to rotate, but check first that head file + sequence matches the one in index header, ie. we have + everything synced in index. */ + unsigned int lock_id; + uint32_t seq; + + if (mail_index_lock_shared(log->index, TRUE, &lock_id) == 0) { + seq = index->hdr->log_file_seq; + mail_index_unlock(log->index, lock_id); + } else { + seq = 0; + } + + if (log->head->hdr.file_seq == seq) { + if (mail_transaction_log_rotate(log, F_WRLCK) < 0) { + /* that didn't work. well, try to continue + anyway */ } - return -1; } }