[dovecot-cvs] dovecot/src/lib-index mail-cache-compress.c, 1.1,
1.2 mail-cache-lookup.c, 1.1, 1.2 mail-cache-old.c, 1.1,
NONE mail-cache-private.h, 1.1, 1.2 mail-cache-transaction.c,
1.1, 1.2 mail-cache.c, 1.27, 1.28 mail-cache.h, 1.8,
1.9 mail-index.c, 1.134, 1.135
cras at procontrol.fi
cras at procontrol.fi
Sun Jun 20 11:05:44 EEST 2004
- Previous message: [dovecot-cvs] dovecot/src/lib-storage/index index-mail.c, 1.33,
1.34 index-storage.c, 1.51, 1.52 index-transaction.c, 1.2, 1.3
- Next message: [dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.2,
1.3 mail-cache-private.h, 1.2, 1.3 mail-cache-transaction.c,
1.2, 1.3 mail-cache.c, 1.28, 1.29 mail-cache.h, 1.9,
1.10 mail-index-private.h, 1.20, 1.21 mail-index-sync-update.c,
1.26, 1.27 mail-index-sync.c, 1.21,
1.22 mail-index-transaction-private.h, 1.4,
1.5 mail-index-transaction.c, 1.11, 1.12 mail-index-view.c,
1.14, 1.15 mail-transaction-log.c, 1.38,
1.39 mail-transaction-log.h, 1.12,
1.13 mail-transaction-util.c, 1.12,
1.13 mail-transaction-util.h, 1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv6435/lib-index
Modified Files:
mail-cache-compress.c mail-cache-lookup.c mail-cache-private.h
mail-cache-transaction.c mail-cache.c mail-cache.h
mail-index.c
Removed Files:
mail-cache-old.c
Log Message:
Beginnings of getting cache file working again. Easy to break currently, but
basics seem to work.
Index: mail-cache-compress.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-compress.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-cache-compress.c 27 Apr 2004 20:25:53 -0000 1.1
+++ mail-cache-compress.c 20 Jun 2004 08:05:41 -0000 1.2
@@ -241,7 +241,7 @@
MAIL_INDEX_HDR_FLAG_COMPRESS_CACHE);
}
- if (!mail_cache_unlock(cache))
+ if (mail_cache_unlock(cache) < 0)
ret = FALSE;
return ret;
Index: mail-cache-lookup.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-cache-lookup.c 27 Apr 2004 20:25:53 -0000 1.1
+++ mail-cache-lookup.c 20 Jun 2004 08:05:41 -0000 1.2
@@ -5,7 +5,6 @@
#include "byteorder.h"
#include "mail-cache-private.h"
-#if 0
const char *
mail_cache_get_header_fields_str(struct mail_cache *cache, unsigned int idx)
{
@@ -17,7 +16,7 @@
if (offset == 0)
return NULL;
- if (!mmap_update(cache, offset, 1024))
+ if (mail_cache_mmap_update(cache, offset, 1024) < 0)
return NULL;
if (offset + sizeof(data_size) > cache->mmap_length) {
@@ -37,7 +36,7 @@
return NULL;
}
- if (!mmap_update(cache, offset, data_size))
+ if (mail_cache_mmap_update(cache, offset, data_size) < 0)
return NULL;
if (offset + data_size > cache->mmap_length) {
@@ -107,17 +106,20 @@
}
struct mail_cache_record *
-mail_cache_get_record(struct mail_cache *cache, uint32_t offset)
+mail_cache_get_record(struct mail_cache *cache, uint32_t offset,
+ int index_offset)
{
#define CACHE_PREFETCH 1024
struct mail_cache_record *cache_rec;
size_t size;
- offset = mail_cache_offset_to_uint32(offset);
+ if (!index_offset)
+ offset = mail_cache_offset_to_uint32(offset);
if (offset == 0)
return NULL;
- if (!mmap_update(cache, offset, sizeof(*cache_rec) + CACHE_PREFETCH))
+ if (mail_cache_mmap_update(cache, offset,
+ sizeof(*cache_rec) + CACHE_PREFETCH) < 0)
return NULL;
if (offset + sizeof(*cache_rec) > cache->mmap_length) {
@@ -132,7 +134,7 @@
return NULL;
}
if (size > CACHE_PREFETCH) {
- if (!mmap_update(cache, offset, size))
+ if (mail_cache_mmap_update(cache, offset, size) < 0)
return NULL;
}
@@ -149,7 +151,7 @@
{
struct mail_cache_record *next;
- next = mail_cache_get_record(cache, rec->next_offset);
+ next = mail_cache_get_record(cache, rec->next_offset, FALSE);
if (next != NULL && next <= rec) {
mail_cache_set_corrupted(cache, "next_offset points backwards");
return NULL;
@@ -165,11 +167,13 @@
if (mail_cache_transaction_autocommit(view, seq, fields) < 0)
return NULL;
- // FIXME: check cache_offset in transaction
- if (mail_index_lookup_latest(view->view, seq, &rec) < 0)
+ /* FIXME: check cache_offset in transaction
+ FIXME: if rec doesn't point to header record, the file seq may
+ be different and the offset wrong */
+ if (mail_index_lookup(view->view, seq, &rec) < 0)
return NULL;
- return mail_cache_get_record(view->cache, rec->cache_offset);
+ return mail_cache_get_record(view->cache, rec->cache_offset, TRUE);
}
enum mail_cache_field
@@ -318,5 +322,10 @@
memcpy(buffer, data, buffer_size);
return TRUE;
}
-#else
-#endif
+
+enum mail_cache_record_flag
+mail_cache_get_record_flags(struct mail_cache_view *view, uint32_t seq)
+{
+ // FIXME:
+ return 0;
+}
--- mail-cache-old.c DELETED ---
Index: mail-cache-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-cache-private.h 27 Apr 2004 20:25:53 -0000 1.1
+++ mail-cache-private.h 20 Jun 2004 08:05:41 -0000 1.2
@@ -95,7 +95,8 @@
mail_cache_split_header(struct mail_cache *cache, const char *header);
struct mail_cache_record *
-mail_cache_get_record(struct mail_cache *cache, uint32_t offset);
+mail_cache_get_record(struct mail_cache *cache, uint32_t offset,
+ int index_offset);
struct mail_cache_record *
mail_cache_get_next_record(struct mail_cache *cache,
struct mail_cache_record *rec);
@@ -108,6 +109,9 @@
mail_cache_transaction_autocommit(struct mail_cache_view *view,
uint32_t seq, enum mail_cache_field fields);
+int mail_cache_mmap_update(struct mail_cache *cache,
+ size_t offset, size_t size);
+
void mail_cache_set_syscall_error(struct mail_cache *cache,
const char *function);
Index: mail-cache-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mail-cache-transaction.c 27 Apr 2004 20:25:53 -0000 1.1
+++ mail-cache-transaction.c 20 Jun 2004 08:05:41 -0000 1.2
@@ -9,7 +9,6 @@
#include <sys/stat.h>
-#if 0
struct mail_cache_transaction_ctx {
struct mail_cache *cache;
struct mail_cache_view *view;
@@ -171,7 +170,7 @@
if (cache->used_file_size + size <= (uoff_t)st.st_size) {
/* no need to grow, just update mmap */
- if (mmap_update(cache, 0, 0) < 0)
+ if (mail_cache_mmap_update(cache, 0, 0) < 0)
return -1;
i_assert(cache->mmap_length >= (uoff_t)st.st_size);
@@ -183,7 +182,7 @@
return -1;
}
- return mmap_update(cache, 0, 0);
+ return mail_cache_mmap_update(cache, 0, 0);
}
static uint32_t mail_cache_append_space(struct mail_cache_transaction_ctx *ctx,
@@ -219,46 +218,54 @@
uint32_t write_offset, update_offset;
const void *buf;
size_t size, buf_size;
+ int ret;
buf = buffer_get_data(ctx->cache_data, &buf_size);
size = sizeof(*cache_rec) + buf_size;
ctx->cache_rec.size = uint32_to_nbo(size);
- write_offset = mail_cache_append_space(ctx, size);
- if (write_offset == 0)
- return -1;
-
// FIXME: check cache_offset in transaction
- if (mail_index_lookup_latest(ctx->view->view, ctx->prev_seq, &rec) < 0)
+ ret = mail_index_lookup(ctx->view->view, ctx->prev_seq, &rec);
+ if (ret < 0)
return -1;
- cache_rec = mail_cache_get_record(cache, rec->cache_offset);
- if (cache_rec == NULL) {
- /* first cache record - update offset in index file */
- mail_index_update_cache(ctx->trans, ctx->prev_seq,
- write_offset);
+ if (ret == 0) {
+ /* it's been expunged already, do nothing */
} else {
- /* find the last cache record */
- while ((next = mail_cache_get_next_record(cache,
- cache_rec)) != NULL)
- cache_rec = next;
+ write_offset = mail_cache_append_space(ctx, size);
+ if (write_offset == 0)
+ return -1;
- /* mark next_offset to be updated later */
- update_offset = (char *) &cache_rec->next_offset -
- (char *) cache->mmap_base;
- mark_update(&ctx->cache_marks, update_offset,
- mail_cache_uint32_to_offset(write_offset));
+ cache_rec = mail_cache_get_record(cache, rec->cache_offset,
+ TRUE);
+ if (cache_rec == NULL) {
+ /* first cache record - update offset in index file */
+ mail_index_update_cache(ctx->trans, ctx->prev_seq,
+ write_offset);
+ } else {
+ /* find the last cache record */
+ while ((next = mail_cache_get_next_record(cache,
+ cache_rec)) != NULL)
+ cache_rec = next;
+
+ /* mark next_offset to be updated later */
+ update_offset = (char *) &cache_rec->next_offset -
+ (char *) cache->mmap_base;
+ mark_update(&ctx->cache_marks, update_offset,
+ mail_cache_uint32_to_offset(write_offset));
+ }
+
+ memcpy((char *) cache->mmap_base + write_offset,
+ &ctx->cache_rec, sizeof(ctx->cache_rec));
+ memcpy((char *) cache->mmap_base + write_offset +
+ sizeof(ctx->cache_rec), buf, buf_size);
}
+
+ /* reset the write context */
ctx->prev_seq = 0;
ctx->prev_fields = 0;
- memcpy((char *) cache->mmap_base + write_offset,
- &ctx->cache_rec, sizeof(ctx->cache_rec));
- memcpy((char *) cache->mmap_base + write_offset +
- sizeof(ctx->cache_rec), buf, buf_size);
-
- /* reset the write context */
memset(&ctx->cache_rec, 0, sizeof(ctx->cache_rec));
buffer_set_used_size(ctx->cache_data, 0);
return 0;
@@ -558,5 +565,9 @@
return 0;
}
-#else
-#endif
+
+int mail_cache_update_record_flags(struct mail_cache_view *view, uint32_t seq,
+ enum mail_cache_record_flag flags)
+{
+ return -1;
+}
Index: mail-cache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- mail-cache.c 2 May 2004 19:24:35 -0000 1.27
+++ mail-cache.c 20 Jun 2004 08:05:41 -0000 1.28
@@ -4,6 +4,7 @@
#include "buffer.h"
#include "byteorder.h"
#include "file-lock.h"
+#include "file-set-size.h"
#include "mmap-util.h"
#include "write-full.h"
#include "mail-cache-private.h"
@@ -38,7 +39,6 @@
MAIL_CACHE_HEADERS4
};
-#if 0
uint32_t mail_cache_uint32_to_offset(uint32_t offset)
{
unsigned char buf[4];
@@ -187,13 +187,15 @@
{
struct stat st;
+#if 0 // FIXME
/* if sequence has changed, the file has to be reopened.
note that if main index isn't locked, it may change again */
if (cache->hdr->file_seq != cache->index->hdr->cache_file_seq &&
cache->mmap_base != NULL) {
- if (!mail_cache_file_reopen(cache))
+ if (mail_cache_file_reopen(cache) < 0)
return -1;
}
+#endif
if (offset < cache->mmap_length &&
size <= cache->mmap_length - offset &&
@@ -244,35 +246,38 @@
return 0;
}
-static int mmap_update(struct mail_cache *cache, size_t offset, size_t size)
+int mail_cache_mmap_update(struct mail_cache *cache, size_t offset, size_t size)
{
int synced, ret;
for (synced = FALSE;; synced = TRUE) {
ret = mmap_update_nocheck(cache, offset, size);
if (ret > 0)
- return TRUE;
+ return 0;
if (ret < 0)
- return FALSE;
+ return -1;
- if (!mmap_verify_header(cache))
- return FALSE;
+ if (mmap_verify_header(cache) <= 0)
+ return -1;
+#if 0 // FIXME
/* see if cache file was rebuilt - do it only once to avoid
infinite looping */
- if (cache->hdr->sync_id == cache->index->cache_sync_id ||
+ if (cache->hdr->file_seq == cache->index->hdr->cache_file_seq ||
synced)
break;
- if (!mail_cache_file_reopen(cache))
- return FALSE;
+ if (mail_cache_file_reopen(cache) < 0)
+ return -1;
+#endif
}
- return TRUE;
+ return 0;
}
static int mail_cache_open_and_verify(struct mail_cache *cache, int silent)
{
struct stat st;
+ int ret;
mail_cache_file_close(cache);
@@ -299,9 +304,9 @@
/* verify that this really is the cache for wanted index */
cache->silent = silent;
- if (!mmap_verify_header(cache)) {
+ if ((ret = mmap_verify_header(cache)) <= 0) {
cache->silent = FALSE;
- return 0;
+ return ret;
}
cache->silent = FALSE;
@@ -318,66 +323,64 @@
ret = mail_cache_open_and_verify(cache, FALSE);
if (ret != 0)
- return ret > 0;
-
- /* we'll have to clear cache_offsets which requires exclusive lock */
- if (!mail_index_set_lock(cache->index, MAIL_LOCK_EXCLUSIVE))
- return FALSE;
+ return ret < 0 ? -1 : 0;
/* maybe a rebuild.. */
- fd = file_dotlock_open(cache->filepath, NULL, MAIL_CACHE_LOCK_TIMEOUT,
+ fd = file_dotlock_open(cache->filepath, NULL, NULL,
+ MAIL_CACHE_LOCK_TIMEOUT,
MAIL_CACHE_LOCK_CHANGE_TIMEOUT,
MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL);
if (fd == -1) {
mail_cache_set_syscall_error(cache, "file_dotlock_open()");
- return FALSE;
+ return -1;
}
/* see if someone else just created the cache file */
ret = mail_cache_open_and_verify(cache, TRUE);
if (ret != 0) {
- (void)file_dotlock_delete(cache->filepath, fd);
- return ret > 0;
+ (void)file_dotlock_delete(cache->filepath, NULL, fd);
+ return ret < 0 ? -1 : 0;
}
/* rebuild then */
if (write_full(fd, hdr, sizeof(*hdr)) < 0) {
mail_cache_set_syscall_error(cache, "write_full()");
- (void)file_dotlock_delete(cache->filepath, fd);
- return FALSE;
+ (void)file_dotlock_delete(cache->filepath, NULL, fd);
+ return -1;
}
if (file_set_size(fd, MAIL_CACHE_INITIAL_SIZE) < 0) {
mail_cache_set_syscall_error(cache, "file_set_size()");
- (void)file_dotlock_delete(cache->filepath, fd);
- return FALSE;
+ (void)file_dotlock_delete(cache->filepath, NULL, fd);
+ return -1;
}
- if (cache->index->hdr.cache_file_seq != 0) {
- // FIXME: recreate index file with cache_offsets cleared
+ if (cache->index->hdr->cache_file_seq != 0) {
+ // FIXME: clear cache_offsets in index file
}
mail_cache_file_close(cache);
cache->fd = dup(fd);
- if (file_dotlock_replace(cache->filepath, fd, FALSE) < 0) {
+ if (file_dotlock_replace(cache->filepath, NULL, fd, FALSE) < 0) {
mail_cache_set_syscall_error(cache, "file_dotlock_replace()");
- return FALSE;
+ return -1;
}
- if (!mmap_update(cache, 0, sizeof(struct mail_cache_header)))
- return FALSE;
+ if (mail_cache_mmap_update(cache, 0,
+ sizeof(struct mail_cache_header)) < 0)
+ return -1;
- return TRUE;
+ return 0;
}
-int mail_cache_open_or_create(struct mail_index *index)
+struct mail_cache *mail_cache_open_or_create(struct mail_index *index)
{
struct mail_cache_header hdr;
struct mail_cache *cache;
memset(&hdr, 0, sizeof(hdr));
hdr.indexid = index->indexid;
- hdr.sync_id = index->hdr->cache_file_seq; // FIXME
+ hdr.file_seq = index->hdr->cache_file_seq + 1;
hdr.used_file_size = uint32_to_nbo(sizeof(hdr));
cache = i_new(struct mail_cache, 1);
@@ -385,25 +388,21 @@
cache->fd = -1;
cache->split_header_pool = pool_alloconly_create("Headers", 512);
- index->cache = cache;
-
/* we'll do anon-mmaping only if initially requested. if we fail
because of out of disk space, we'll just let the main index code
know it and fail. */
- if (!mail_cache_open_or_create_file(cache, &hdr)) {
+ if (mail_cache_open_or_create_file(cache, &hdr) < 0) {
mail_cache_free(cache);
- return FALSE;
+ return NULL;
}
- return TRUE;
+ return cache;
}
void mail_cache_free(struct mail_cache *cache)
{
i_assert(cache->trans_ctx == NULL);
- cache->index->cache = NULL;
-
mail_cache_file_close(cache);
pool_unref(cache->split_header_pool);
@@ -422,18 +421,20 @@
int mail_cache_reset(struct mail_cache *cache)
{
struct mail_cache_header hdr;
- int ret, fd;
+ int fd;
- i_assert(cache->index->lock_type == MAIL_LOCK_EXCLUSIVE);
+ i_assert(cache->index->lock_type == F_WRLCK);
memset(&hdr, 0, sizeof(hdr));
hdr.indexid = cache->index->indexid;
- hdr.sync_id = cache->sync_id = cache->index->cache_sync_id =
- ++cache->index->hdr->cache_sync_id;
+ hdr.file_seq = cache->index->hdr->cache_file_seq + 1;
hdr.used_file_size = uint32_to_nbo(sizeof(hdr));
cache->used_file_size = sizeof(hdr);
- fd = file_dotlock_open(cache->filepath, NULL, MAIL_CACHE_LOCK_TIMEOUT,
+ // FIXME: update cache_offsets in index
+
+ fd = file_dotlock_open(cache->filepath, NULL, NULL,
+ MAIL_CACHE_LOCK_TIMEOUT,
MAIL_CACHE_LOCK_CHANGE_TIMEOUT,
MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT, NULL, NULL);
if (fd == -1) {
@@ -443,25 +444,26 @@
if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
mail_cache_set_syscall_error(cache, "write_full()");
- (void)file_dotlock_delete(cache->filepath, fd);
+ (void)file_dotlock_delete(cache->filepath, NULL, fd);
return -1;
}
if (file_set_size(fd, MAIL_CACHE_INITIAL_SIZE) < 0) {
mail_cache_set_syscall_error(cache, "file_set_size()");
- (void)file_dotlock_delete(cache->filepath, fd);
+ (void)file_dotlock_delete(cache->filepath, NULL, fd);
return -1;
}
mail_cache_file_close(cache);
cache->fd = dup(fd);
- if (file_dotlock_replace(cache->filepath, fd, FALSE) < 0) {
+ if (file_dotlock_replace(cache->filepath, NULL, fd, FALSE) < 0) {
mail_cache_set_syscall_error(cache, "file_dotlock_replace()");
return -1;
}
cache->mmap_refresh = TRUE;
- if (!mmap_update(cache, 0, sizeof(struct mail_cache_header)))
+ if (mail_cache_mmap_update(cache, 0,
+ sizeof(struct mail_cache_header)) < 0)
return -1;
return 0;
@@ -472,7 +474,7 @@
int ret;
if (cache->locks++ != 0)
- return TRUE;
+ return 1;
if (nonblock) {
ret = file_try_lock(cache->fd, F_WRLCK);
@@ -485,20 +487,22 @@
}
if (ret > 0) {
- if (!mmap_update(cache, 0, 0)) {
+ if (mail_cache_mmap_update(cache, 0, 0) < 0) {
(void)mail_cache_unlock(cache);
return -1;
}
- if (cache->sync_id != cache->index->cache_sync_id) {
+#if 0 // FIXME
+ if (cache->hdr->file_seq != cache->index->hdr->cache_file_seq) {
/* we have the cache file locked and sync_id still
doesn't match. it means we crashed between updating
cache file and updating sync_id in index header.
just update the sync_ids so they match. */
i_warning("Updating broken sync_id in cache file %s",
cache->filepath);
- cache->sync_id = cache->hdr->sync_id =
- cache->index->cache_sync_id;
+ cache->hdr->file_seq =
+ cache->index->hdr->cache_file_seq;
}
+#endif
}
return ret;
}
@@ -506,14 +510,14 @@
int mail_cache_unlock(struct mail_cache *cache)
{
if (--cache->locks > 0)
- return TRUE;
+ return 0;
if (file_wait_lock(cache->fd, F_UNLCK) <= 0) {
mail_cache_set_syscall_error(cache, "file_wait_lock(F_UNLCK)");
- return FALSE;
+ return -1;
}
- return TRUE;
+ return 0;
}
int mail_cache_is_locked(struct mail_cache *cache)
@@ -536,128 +540,9 @@
{
i_free(view);
}
-#else
-int mail_cache_open_or_create(struct mail_index *index)
-{
- return 0;
-}
-
-void mail_cache_free(struct mail_cache *cache)
-{
-}
-
-void mail_cache_set_defaults(struct mail_cache *cache,
- enum mail_cache_field default_cache_fields,
- enum mail_cache_field never_cache_fields) {}
-
-/* Compress cache file. */
-int mail_cache_compress(struct mail_cache *cache) {return 0;}
-
-/* Reset the cache file, clearing all data. */
-int mail_cache_reset(struct mail_cache *cache) {return 0;}
-
-/* Explicitly lock the cache file. Returns 1 if ok, 0 if nonblock is TRUE and
- we couldn't immediately get a lock, or -1 if error. */
-int mail_cache_lock(struct mail_cache *cache, int nonblock) {return 0;}
-int mail_cache_unlock(struct mail_cache *cache) {return 0;}
-
-/* Returns TRUE if cache file is locked. */
-int mail_cache_is_locked(struct mail_cache *cache) {return TRUE;}
-
-struct mail_cache_view *
-mail_cache_view_open(struct mail_cache *cache, struct mail_index_view *iview)
-{return i_new(struct mail_cache_view, 1);}
-void mail_cache_view_close(struct mail_cache_view *view) {i_free(view);}
-
-/* Begin transaction. Cache transaction may be committed or rollbacked multiple
- times. It will finish when index transaction is committed or rollbacked.
- The transaction might also be partially committed automatically, so this
- is kind of fake transaction, it's only purpose being optimizing writes.
- Returns same as mail_cache_lock(). */
-int mail_cache_transaction_begin(struct mail_cache_view *view, int nonblock,
- struct mail_index_transaction *t,
- struct mail_cache_transaction_ctx **ctx_r)
+void mail_cache_mark_missing(struct mail_cache_view *view,
+ enum mail_cache_field fields)
{
- *ctx_r = NULL;
- return 1;
+ // FIXME
}
-int mail_cache_transaction_commit(struct mail_cache_transaction_ctx *ctx)
-{return 0;}
-void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx *ctx) {}
-
-/* Should be called only by mail_transaction_commit/rollback: */
-int mail_cache_transaction_end(struct mail_cache_transaction_ctx *ctx)
-{return 0;}
-
-/* Return NULL-terminated list of headers for given index, or NULL if
- header index isn't used. */
-const char *const *mail_cache_get_header_fields(struct mail_cache_view *view,
- unsigned int idx)
-{return NULL;}
-/* Set list of headers for given index. */
-int mail_cache_set_header_fields(struct mail_cache_transaction_ctx *ctx,
- unsigned int idx, const char *const headers[])
-{return 0;}
-
-/* Add new field to given record. Updates are not allowed. Fixed size fields
- must be exactly the expected size and they're converted to network byte
- order in disk. */
-int mail_cache_add(struct mail_cache_transaction_ctx *ctx, uint32_t seq,
- enum mail_cache_field field,
- const void *data, size_t data_size)
-{return 0;}
-
-/* Mark the given record deleted. */
-int mail_cache_delete(struct mail_cache_transaction_ctx *ctx, uint32_t seq)
-{return 0;}
-
-/* Return all fields that are currently cached for record. */
-enum mail_cache_field
-mail_cache_get_fields(struct mail_cache_view *view, uint32_t seq) {return 0;}
-
-/* Set data_r and size_r to point to wanted field in cache file.
- Returns TRUE if field was found. If field contains multiple fields,
- first one found is returned. This is mostly useful for finding headers. */
-int mail_cache_lookup_field(struct mail_cache_view *view, uint32_t seq,
- enum mail_cache_field field,
- const void **data_r, size_t *size_r) {return 0;}
-
-/* Return string field. */
-const char *
-mail_cache_lookup_string_field(struct mail_cache_view *view, uint32_t seq,
- enum mail_cache_field field) {return 0;}
-
-/* Copy fixed size field to given buffer. buffer_size must be exactly the
- expected size. The result will be converted to host byte order.
- Returns TRUE if field was found. */
-int mail_cache_copy_fixed_field(struct mail_cache_view *view, uint32_t seq,
- enum mail_cache_field field,
- void *buffer, size_t buffer_size) {return 0;}
-
-/* Mark given fields as missing, ie. they should be cached when possible. */
-void mail_cache_mark_missing(struct mail_cache_view *view,
- enum mail_cache_field fields) {}
-
-/* Return index flags. */
-enum mail_cache_record_flag
-mail_cache_get_record_flags(struct mail_cache_view *view, uint32_t seq)
-{return 0;}
-
-/* Update index flags. The cache file must be locked and the flags must be
- already inserted to the record. */
-int mail_cache_update_record_flags(struct mail_cache_view *view, uint32_t seq,
- enum mail_cache_record_flag flags)
-{return 0;}
-
-/* Update location offset. External locking is assumed to take care of locking
- readers out to prevent race conditions. */
-int mail_cache_update_location_offset(struct mail_cache_view *view,
- uint32_t seq, uoff_t offset)
-{return 0;}
-
-/* "Error in index cache file %s: ...". */
-void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
-{}
-
-#endif
Index: mail-cache.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mail-cache.h 2 May 2004 19:24:35 -0000 1.8
+++ mail-cache.h 20 Jun 2004 08:05:41 -0000 1.9
@@ -28,12 +28,9 @@
enum mail_cache_field {
/* fixed size fields */
MAIL_CACHE_INDEX_FLAGS = 0x00000001,
- MAIL_CACHE_LOCATION_OFFSET = 0x00000002,
- MAIL_CACHE_MD5 = 0x00000004,
MAIL_CACHE_SENT_DATE = 0x00000008,
MAIL_CACHE_RECEIVED_DATE = 0x00000010,
MAIL_CACHE_VIRTUAL_FULL_SIZE = 0x00000020,
- MAIL_CACHE_PHYSICAL_BODY_SIZE = 0x00000040,
/* variable sized field */
MAIL_CACHE_HEADERS1 = 0x40000000,
@@ -47,12 +44,9 @@
MAIL_CACHE_MESSAGEPART = 0x00400000,
MAIL_CACHE_FIXED_MASK = MAIL_CACHE_INDEX_FLAGS |
- MAIL_CACHE_LOCATION_OFFSET |
- MAIL_CACHE_MD5 |
MAIL_CACHE_SENT_DATE |
MAIL_CACHE_RECEIVED_DATE |
- MAIL_CACHE_VIRTUAL_FULL_SIZE |
- MAIL_CACHE_PHYSICAL_BODY_SIZE,
+ MAIL_CACHE_VIRTUAL_FULL_SIZE,
MAIL_CACHE_HEADERS_MASK = MAIL_CACHE_HEADERS1 |
MAIL_CACHE_HEADERS2 |
MAIL_CACHE_HEADERS3 |
@@ -74,7 +68,7 @@
extern enum mail_cache_field mail_cache_header_fields[MAIL_CACHE_HEADERS_COUNT];
-int mail_cache_open_or_create(struct mail_index *index);
+struct mail_cache *mail_cache_open_or_create(struct mail_index *index);
void mail_cache_free(struct mail_cache *cache);
void mail_cache_set_defaults(struct mail_cache *cache,
@@ -167,11 +161,6 @@
int mail_cache_update_record_flags(struct mail_cache_view *view, uint32_t seq,
enum mail_cache_record_flag flags);
-/* Update location offset. External locking is assumed to take care of locking
- readers out to prevent race conditions. */
-int mail_cache_update_location_offset(struct mail_cache_view *view,
- uint32_t seq, uoff_t offset);
-
/* "Error in index cache file %s: ...". */
void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
__attr_format__(2, 3);
Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -d -r1.134 -r1.135
--- mail-index.c 20 Jun 2004 04:23:16 -0000 1.134
+++ mail-index.c 20 Jun 2004 08:05:41 -0000 1.135
@@ -8,6 +8,7 @@
#include "write-full.h"
#include "mail-index-private.h"
#include "mail-transaction-log.h"
+#include "mail-cache.h"
#include <stdio.h>
#include <stddef.h>
@@ -553,7 +554,7 @@
ret = mail_index_try_open(index, NULL);
if (ret != 0) {
mail_transaction_log_sync_unlock(index->log);
- return ret;
+ return ret < 0 ? -1 : 0;
}
/* create it fully in index.tmp first */
@@ -618,6 +619,7 @@
hdr->next_uid = 1;
}
+/* returns -1 = error, 0 = won't create, 1 = ok */
static int mail_index_open_files(struct mail_index *index,
enum mail_index_open_flags flags)
{
@@ -643,9 +645,27 @@
if (index->log == NULL)
return -1;
- if (lock_id != 0)
- mail_index_unlock(index, lock_id);
- return index->fd != -1 ? 1 : mail_index_create(index, &hdr);
+ if (index->fd == -1) {
+ if (lock_id != 0) {
+ mail_index_unlock(index, lock_id);
+ lock_id = 0;
+ }
+ if (mail_index_create(index, &hdr) < 0)
+ return -1;
+ }
+
+ if (lock_id == 0) {
+ if (mail_index_lock_shared(index, FALSE, &lock_id) < 0)
+ return -1;
+
+ }
+
+ index->cache = mail_cache_open_or_create(index);
+ if (index->cache == NULL)
+ return -1;
+
+ mail_index_unlock(index, lock_id);
+ return 1;
}
int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags)
@@ -711,6 +731,11 @@
index->map = NULL;
}
+ if (index->cache != NULL) {
+ mail_cache_free(index->cache);
+ index->cache = NULL;
+ }
+
if (index->fd != -1) {
if (close(index->fd) < 0)
mail_index_set_syscall_error(index, "close()");
- Previous message: [dovecot-cvs] dovecot/src/lib-storage/index index-mail.c, 1.33,
1.34 index-storage.c, 1.51, 1.52 index-transaction.c, 1.2, 1.3
- Next message: [dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.2,
1.3 mail-cache-private.h, 1.2, 1.3 mail-cache-transaction.c,
1.2, 1.3 mail-cache.c, 1.28, 1.29 mail-cache.h, 1.9,
1.10 mail-index-private.h, 1.20, 1.21 mail-index-sync-update.c,
1.26, 1.27 mail-index-sync.c, 1.21,
1.22 mail-index-transaction-private.h, 1.4,
1.5 mail-index-transaction.c, 1.11, 1.12 mail-index-view.c,
1.14, 1.15 mail-transaction-log.c, 1.38,
1.39 mail-transaction-log.h, 1.12,
1.13 mail-transaction-util.c, 1.12,
1.13 mail-transaction-util.h, 1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list