dovecot-1.1: Removed mail-hash. It's not used anywhere and its A...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Mar 11 04:25:40 EET 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/ce11885b99a0
changeset: 7402:ce11885b99a0
user: Timo Sirainen <tss at iki.fi>
date: Tue Mar 11 04:25:36 2008 +0200
description:
Removed mail-hash. It's not used anywhere and its API has been redesigned.
diffstat:
3 files changed, 1269 deletions(-)
src/lib-index/Makefile.am | 2
src/lib-index/mail-hash.c | 1135 ---------------------------------------------
src/lib-index/mail-hash.h | 132 -----
diffs (truncated from 1294 to 300 lines):
diff -r f5011bb9a633 -r ce11885b99a0 src/lib-index/Makefile.am
--- a/src/lib-index/Makefile.am Tue Mar 11 04:24:34 2008 +0200
+++ b/src/lib-index/Makefile.am Tue Mar 11 04:25:36 2008 +0200
@@ -12,7 +12,6 @@ libindex_a_SOURCES = \
mail-cache-lookup.c \
mail-cache-transaction.c \
mail-cache-sync-update.c \
- mail-hash.c \
mail-index.c \
mail-index-dummy-view.c \
mail-index-fsck.c \
@@ -37,7 +36,6 @@ headers = \
headers = \
mail-cache.h \
mail-cache-private.h \
- mail-hash.h \
mail-index.h \
mail-index-private.h \
mail-index-sync-private.h \
diff -r f5011bb9a633 -r ce11885b99a0 src/lib-index/mail-hash.c
--- a/src/lib-index/mail-hash.c Tue Mar 11 04:24:34 2008 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1135 +0,0 @@
-/* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "ioloop.h"
-#include "array.h"
-#include "primes.h"
-#include "nfs-workarounds.h"
-#include "file-dotlock.h"
-#include "file-set-size.h"
-#include "read-full.h"
-#include "write-full.h"
-#include "mmap-util.h"
-#include "nfs-workarounds.h"
-#include "mail-index-private.h"
-#include "mail-hash.h"
-
-#include <stdio.h>
-#include <stddef.h>
-#include <utime.h>
-#include <sys/stat.h>
-
-/* How large to create the file initially */
-#define FILE_SIZE_INIT_PERCENTAGE 120
-/* How much larger to grow the file when it needs to be done */
-#define MAIL_HASH_GROW_PERCENTAGE 20
-/* Minimum hash size to use */
-#define MAIL_HASH_MIN_SIZE 109
-
-#define MAIL_HASH_TIMEOUT_SECS 3
-
-struct mail_hash {
- struct mail_index *index;
-
- hash_callback_t *key_hash_cb;
- hash_ctx_cmp_callback_t *key_compare_cb;
- hash_callback_t *rec_hash_cb;
- void *cb_context;
-
- char *filepath;
- char *suffix;
- int fd;
-
- dev_t dev;
- ino_t ino;
-
- unsigned int record_size;
-
- void *mmap_base;
- size_t mmap_size;
-
- time_t mtime, mapped_mtime;
- size_t change_offset_start, change_offset_end;
-
- int lock_type;
- struct file_lock *file_lock;
- struct dotlock *dotlock;
- struct dotlock_settings dotlock_settings;
-
- struct mail_hash_header *hdr;
-
- uint32_t *hash_base;
- void *records_base;
- unsigned int records_mapped;
-
- unsigned int mmap_anon:1;
- unsigned int in_memory:1;
- unsigned int locked:1;
-};
-
-#define MAIL_HASH_IS_IN_MEMORY(hash) \
- ((hash)->in_memory)
-
-#define HASH_RECORD_IDX(hash, idx) \
- PTR_OFFSET((hash)->records_base, ((idx) - 1) * (hash)->record_size)
-
-const struct dotlock_settings default_dotlock_settings = {
- MEMBER(temp_prefix) NULL,
- MEMBER(lock_suffix) NULL,
-
- MEMBER(timeout) 10,
- MEMBER(stale_timeout) 30
-};
-
-static void mail_hash_set_syscall_error(struct mail_hash *hash,
- const char *function)
-{
- if (ENOSPACE(errno)) {
- hash->index->nodiskspace = TRUE;
- return;
- }
-
- mail_index_set_error(hash->index,
- "%s failed with index hash file %s: %m",
- function, hash->filepath);
-}
-
-static int mail_hash_file_set_corrupted(struct mail_hash *hash, bool set)
-{
- size_t offset = offsetof(struct mail_hash_header, corrupted);
- struct stat st;
-
- if (hash->fd == -1)
- return 0;
-
- hash->hdr->corrupted = set ? 1 : 0;
- if (!hash->mmap_anon) {
- if (msync(hash->mmap_base,
- offset + sizeof(hash->hdr->corrupted), MS_SYNC) < 0) {
- mail_hash_set_syscall_error(hash, "msync()");
- return -1;
- }
- } else {
- if (pwrite_full(hash->fd, &hash->hdr->corrupted,
- sizeof(hash->hdr->corrupted), offset) < 0) {
- mail_hash_set_syscall_error(hash, "pwrite_full()");
- return -1;
- }
- }
- if (fstat(hash->fd, &st) < 0 || st.st_mtime == hash->mtime) {
- /* mtime didn't change. have to increase it. */
- struct utimbuf buf;
-
- st.st_mtime++;
- buf.modtime = st.st_mtime;
- buf.actime = ioloop_time;
- if (utime(hash->filepath, &buf) < 0) {
- mail_hash_set_syscall_error(hash, "utime()");
- return -1;
- }
- }
-
- if (!set)
- hash->mapped_mtime = st.st_mtime;
- return 0;
-}
-
-void mail_hash_set_corrupted(struct mail_hash *hash, const char *error)
-{
- mail_index_set_error(hash->index, "Corrupted index hash file %s: %s",
- hash->filepath, error);
-
- (void)mail_hash_file_set_corrupted(hash, TRUE);
-}
-
-static int mail_hash_check_header(struct mail_hash *hash,
- const struct mail_hash_header *hdr)
-{
- uoff_t file_size;
-
- if (hdr->version != MAIL_HASH_VERSION ||
- (hdr->last_uid != 0 &&
- hdr->uid_validity != hash->index->map->hdr.uid_validity) ||
- (hdr->corrupted && hash->change_offset_end == 0)) {
- /* silent rebuild */
- return -1;
- }
-
- if (hdr->record_size != hash->record_size) {
- mail_hash_set_corrupted(hash, "record_size mismatch");
- return -1;
- }
- if (hdr->base_header_size != sizeof(*hdr)) {
- mail_hash_set_corrupted(hash, "base_header_size mismatch");
- return -1;
- }
- if (hdr->header_size < hdr->base_header_size) {
- mail_hash_set_corrupted(hash, "Invalid header_size");
- return -1;
- }
-
- if (hdr->hash_size < primes_closest(1)) {
- mail_hash_set_corrupted(hash, "Invalid hash_size");
- return -1;
- }
-
- file_size = hdr->header_size +
- hdr->hash_size * sizeof(uint32_t) +
- hdr->record_size * hdr->record_count;
- if (hash->mmap_size < file_size) {
- mail_hash_set_corrupted(hash, "File too small");
- return -1;
- }
-
- return 0;
-}
-
-static void mail_hash_file_close(struct mail_hash *hash)
-{
- if (hash->file_lock != NULL)
- file_lock_free(&hash->file_lock);
-
- if (hash->mmap_base != NULL) {
- if (hash->mmap_anon) {
- if (munmap_anon(hash->mmap_base, hash->mmap_size) < 0) {
- mail_hash_set_syscall_error(hash,
- "munmap_anon()");
- }
- } else {
- if (munmap(hash->mmap_base, hash->mmap_size) < 0)
- mail_hash_set_syscall_error(hash, "munmap()");
- }
- hash->mapped_mtime = 0;
- hash->mmap_base = NULL;
- hash->mmap_size = 0;
- hash->mmap_anon = FALSE;
- hash->in_memory = FALSE;
- }
-
- if (hash->fd != -1) {
- if (close(hash->fd) < 0)
- mail_hash_set_syscall_error(hash, "close()");
- hash->fd = -1;
- }
-
- hash->hdr = NULL;
- hash->hash_base = NULL;
- hash->records_base = NULL;
-
- hash->locked = FALSE;
-}
-
-static int mail_hash_file_map_finish(struct mail_hash *hash)
-{
- hash->hdr = hash->mmap_base;
- if (mail_hash_check_header(hash, hash->hdr) < 0) {
- i_assert(!MAIL_HASH_IS_IN_MEMORY(hash));
- mail_hash_file_close(hash);
- return 0;
- }
-
- hash->hash_base = PTR_OFFSET(hash->mmap_base, hash->hdr->header_size);
- hash->records_base = &hash->hash_base[hash->hdr->hash_size];
- hash->records_mapped =
- (hash->mmap_size -
- ((char *)hash->records_base - (char *)hash->mmap_base)) /
- hash->record_size;
- return 1;
-}
-
-static int mail_hash_file_read(struct mail_hash *hash,
- size_t file_size, size_t size)
-{
- int ret;
-
- i_assert(hash->locked);
-
- if (hash->mmap_base == NULL) {
- if (file_size < size)
- file_size = size;
-
- hash->mmap_base = mmap_anon(file_size);
- if (hash->mmap_base == MAP_FAILED) {
- hash->mmap_size = 0;
- hash->mmap_base = NULL;
- i_error("mmap_anon(%"PRIuSIZE_T") failed: %m",
- file_size);
- return -1;
- }
- hash->mmap_size = file_size;
- hash->mmap_anon = TRUE;
- } else if (size > hash->mmap_size) {
- i_assert(hash->mmap_anon);
- hash->mmap_base = mremap_anon(hash->mmap_base, hash->mmap_size,
- size, MREMAP_MAYMOVE);
- if (hash->mmap_base == MAP_FAILED) {
- hash->mmap_size = 0;
- hash->mmap_base = NULL;
- mail_hash_set_syscall_error(hash, "mremap_anon()");
- return -1;
- }
- hash->mmap_size = size;
- }
-
- ret = pread_full(hash->fd, hash->mmap_base, size, 0);
- if (ret < 0) {
- mail_hash_set_syscall_error(hash, "pread_full()");
- return -1;
More information about the dovecot-cvs
mailing list