[dovecot-cvs] dovecot/src/lib-index mail-cache-transaction.c, 1.23,
1.24 mail-index-sync-update.c, 1.42, 1.43
cras at dovecot.org
cras at dovecot.org
Sat Sep 11 17:30:09 EEST 2004
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv11630
Modified Files:
mail-cache-transaction.c mail-index-sync-update.c
Log Message:
More fixes to make sure we don't write buffered data to cache file after
it's been reopened.
Index: mail-cache-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- mail-cache-transaction.c 11 Sep 2004 12:08:37 -0000 1.23
+++ mail-cache-transaction.c 11 Sep 2004 14:30:06 -0000 1.24
@@ -49,6 +49,7 @@
ctx->trans = t;
ctx->reservations =
buffer_create_dynamic(system_pool, 256, (size_t)-1);
+ ctx->cache_file_seq = ctx->cache->hdr->file_seq;
i_assert(view->transaction == NULL);
view->transaction = ctx;
@@ -300,8 +301,11 @@
return;
}
- mail_cache_free_space(ctx->cache, ctx->reserved_space_offset,
- ctx->reserved_space);
+ /* check again - locking might have reopened the cache file */
+ if (ctx->reserved_space != 0) {
+ mail_cache_free_space(ctx->cache, ctx->reserved_space_offset,
+ ctx->reserved_space);
+ }
if (!locked)
mail_cache_unlock(ctx->cache);
@@ -323,7 +327,7 @@
if (min_size > ctx->reserved_space) {
if (!locked) {
if (mail_cache_transaction_lock(ctx) <= 0)
- return -1;
+ return 0;
}
ret = mail_cache_transaction_reserve_more(ctx, max_size,
commit);
@@ -360,7 +364,7 @@
struct mail_cache *cache = ctx->cache;
const struct mail_cache_record *rec, *tmp_rec;
const uint32_t *seq;
- uint32_t write_offset, old_offset, rec_pos;
+ uint32_t write_offset, old_offset, rec_pos, cache_file_seq;
size_t size, max_size, seq_idx, seq_limit, seq_count;
int commit;
@@ -382,10 +386,17 @@
for (seq_idx = 0, rec_pos = 0; rec_pos < ctx->prev_pos;) {
max_size = ctx->prev_pos - rec_pos;
+
+ cache_file_seq = ctx->cache_file_seq;
write_offset = mail_cache_transaction_get_space(ctx, rec->size,
max_size,
&max_size,
commit);
+ if (cache_file_seq != ctx->cache_file_seq) {
+ /* cache file reopened - need to abort */
+ return 0;
+ }
+
if (write_offset == 0) {
/* nothing to write / error */
return ctx->prev_pos == 0 ? 0 : -1;
@@ -516,15 +527,15 @@
const uint32_t *buf;
size_t size;
- buf = buffer_get_data(ctx->reservations, &size);
- i_assert(size % sizeof(uint32_t)*2 == 0);
- size /= sizeof(*buf);
-
- if ((ctx->reserved_space > 0 || size > 0) &&
+ if ((ctx->reserved_space > 0 || ctx->reservations->used > 0) &&
!MAIL_CACHE_IS_UNUSABLE(cache)) {
if (mail_cache_transaction_lock(ctx) > 0) {
mail_cache_transaction_free_space(ctx);
+ buf = buffer_get_data(ctx->reservations, &size);
+ i_assert(size % sizeof(uint32_t)*2 == 0);
+ size /= sizeof(*buf);
+
if (size > 0) {
/* free flushed data as well. do it from end to
beginning so we have a better chance of
Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- mail-index-sync-update.c 5 Sep 2004 17:53:45 -0000 1.42
+++ mail-index-sync-update.c 11 Sep 2004 14:30:06 -0000 1.43
@@ -252,6 +252,12 @@
ctx->cache_locked = TRUE;
}
+ if (view->map->hdr->cache_file_seq !=
+ view->index->cache->hdr->file_seq) {
+ /* cache has been compressed, don't modify it */
+ return 1;
+ }
+
if (mail_cache_link(view->index->cache,
rec->cache_offset, u->cache_offset) < 0)
return -1;
More information about the dovecot-cvs
mailing list