[dovecot-cvs] dovecot/src/lib-index mail-index-sync-private.h, 1.10, 1.11 mail-index-sync-update.c, 1.35, 1.36 mail-index-view-sync.c, 1.14, 1.15 mail-transaction-log.c, 1.45, 1.46

cras at procontrol.fi cras at procontrol.fi
Mon Jul 5 01:19:51 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv32313/lib-index

Modified Files:
	mail-index-sync-private.h mail-index-sync-update.c 
	mail-index-view-sync.c mail-transaction-log.c 
Log Message:
fixing crashes from last changes



Index: mail-index-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync-private.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- mail-index-sync-private.h	4 Jul 2004 14:26:22 -0000	1.10
+++ mail-index-sync-private.h	4 Jul 2004 22:19:49 -0000	1.11
@@ -22,6 +22,12 @@
 	unsigned int lock_id;
 
 	unsigned int sync_appends:1;
+};
+
+struct mail_index_sync_map_ctx {
+	struct mail_index_view *view;
+
+	unsigned int update_cache:1;
 	unsigned int cache_locked:1;
 };
 

Index: mail-index-sync-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- mail-index-sync-update.c	4 Jul 2004 21:10:32 -0000	1.35
+++ mail-index-sync-update.c	4 Jul 2004 22:19:49 -0000	1.36
@@ -57,22 +57,25 @@
 		hdr->first_deleted_uid_lowwater = rec->uid;
 }
 
-static void mail_index_sync_cache_expunge(struct mail_index_sync_ctx *sync_ctx,
+static void mail_index_sync_cache_expunge(struct mail_index_sync_map_ctx *ctx,
 					  uoff_t cache_offset)
 {
-	if (!sync_ctx->cache_locked) {
-		if (mail_cache_lock(sync_ctx->view->index->cache) <= 0)
+	if (!ctx->update_cache)
+		return;
+
+	if (!ctx->cache_locked) {
+		if (mail_cache_lock(ctx->view->index->cache) <= 0)
 			return;
-		sync_ctx->cache_locked = TRUE;
+		ctx->cache_locked = TRUE;
 	}
 
-	(void)mail_cache_delete(sync_ctx->index->cache, cache_offset);
+	(void)mail_cache_delete(ctx->view->index->cache, cache_offset);
 }
 
 static int sync_expunge(const struct mail_transaction_expunge *e, void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-	struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+	struct mail_index_view *view = ctx->view;
 	struct mail_index_map *map = view->map;
 	struct mail_index_header *hdr = &map->hdr_copy;
 	struct mail_index_record *rec;
@@ -91,10 +94,8 @@
                 rec = MAIL_INDEX_MAP_IDX(map, seq-1);
 		mail_index_header_update_counts(hdr, rec->flags, 0);
 		
-		if (rec->cache_offset != 0) {
-			mail_index_sync_cache_expunge(sync_ctx,
-						      rec->cache_offset);
-		}
+		if (rec->cache_offset != 0)
+			mail_index_sync_cache_expunge(ctx, rec->cache_offset);
 	}
 
 	/* @UNSAFE */
@@ -117,8 +118,8 @@
 static int sync_append(const struct mail_transaction_append_header *hdr,
 		       const struct mail_index_record *rec, void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-	struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+	struct mail_index_view *view = ctx->view;
 	struct mail_index_map *map = view->map;
 	void *dest;
 
@@ -159,8 +160,8 @@
 static int sync_flag_update(const struct mail_transaction_flag_update *u,
 			    void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-	struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+	struct mail_index_view *view = ctx->view;
 	struct mail_index_record *rec;
 	struct mail_index_header *hdr;
 	uint8_t flag_mask, old_flags;
@@ -209,8 +210,8 @@
 static int sync_cache_reset(const struct mail_transaction_cache_reset *u,
 			    void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-	struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+	struct mail_index_view *view = ctx->view;
 	uint32_t i;
 
 	view->map->hdr_copy.cache_file_seq = u->new_file_seq;
@@ -223,8 +224,8 @@
 static int sync_cache_update(const struct mail_transaction_cache_update *u,
 			     void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-	struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+	struct mail_index_view *view = ctx->view;
 	struct mail_index_record *rec;
 	uint32_t seq;
 	int ret;
@@ -239,12 +240,12 @@
 	}
 
 	rec = MAIL_INDEX_MAP_IDX(view->map, seq-1);
-	if (rec->cache_offset != 0) {
+	if (rec->cache_offset != 0 && ctx->update_cache) {
 		/* we'll need to link the old and new cache records */
-		if (!sync_ctx->cache_locked) {
+		if (!ctx->cache_locked) {
 			if (mail_cache_lock(view->index->cache) <= 0)
 				return -1;
-			sync_ctx->cache_locked = TRUE;
+			ctx->cache_locked = TRUE;
 		}
 
 		if (mail_cache_link(view->index->cache,
@@ -258,10 +259,10 @@
 static int sync_header_update(const struct mail_transaction_header_update *u,
 			      void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
+        struct mail_index_sync_map_ctx *ctx = context;
 	void *data;
 
-	data = PTR_OFFSET(&sync_ctx->view->map->hdr_copy, u->offset);
+	data = PTR_OFFSET(&ctx->view->map->hdr_copy, u->offset);
 	memcpy(data, u->data, u->size);
 	return 1;
 }
@@ -271,8 +272,8 @@
 		      const struct mail_transaction_extra_rec_update *u,
 		      void *context)
 {
-        struct mail_index_sync_ctx *sync_ctx = context;
-	struct mail_index_view *view = sync_ctx->view;
+        struct mail_index_sync_map_ctx *ctx = context;
+	struct mail_index_view *view = ctx->view;
 	struct mail_index_record *rec;
 	uint32_t seq;
 	uint16_t offset, size;
@@ -392,6 +393,7 @@
 	struct mail_index *index = sync_ctx->index;
 	struct mail_index_view *view = sync_ctx->view;
 	struct mail_index_map *map;
+        struct mail_index_sync_map_ctx sync_map_ctx;
 	const struct mail_transaction_header *hdr;
 	const void *data;
 	unsigned int count, old_lock_id;
@@ -399,6 +401,10 @@
 	uoff_t offset;
 	int ret, had_dirty, skipped;
 
+	memset(&sync_map_ctx, 0, sizeof(sync_map_ctx));
+	sync_map_ctx.view = view;
+        sync_map_ctx.update_cache = TRUE;
+
 	/* we'll have to update view->lock_id to avoid mail_index_view_lock()
 	   trying to update the file later. */
 	old_lock_id = view->lock_id;
@@ -463,15 +469,15 @@
 
 		if (mail_transaction_map(index, hdr, data,
 					 &mail_index_map_sync_funcs,
-					 sync_ctx) < 0) {
+					 &sync_map_ctx) < 0) {
 			ret = -1;
 			break;
 		}
 	}
 
-	if (sync_ctx->cache_locked) {
+	if (sync_map_ctx.cache_locked) {
 		mail_cache_unlock(index->cache);
-		sync_ctx->cache_locked = FALSE;
+		sync_map_ctx.cache_locked = FALSE;
 	}
 
 	if (ret < 0) {

Index: mail-index-view-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mail-index-view-sync.c	24 Jun 2004 11:10:41 -0000	1.14
+++ mail-index-view-sync.c	4 Jul 2004 22:19:49 -0000	1.15
@@ -190,8 +190,14 @@
 	   see only updated information. */
 	if (ctx->sync_map_update &&
 	    (ctx->hdr->type & MAIL_TRANSACTION_EXPUNGE) == 0) {
+		struct mail_index_sync_map_ctx sync_map_ctx;
+
+		memset(&sync_map_ctx, 0, sizeof(sync_map_ctx));
+		sync_map_ctx.view = view;
+
 		if (mail_transaction_map(view->index, ctx->hdr, ctx->data,
-					 &mail_index_map_sync_funcs, view) < 0)
+					 &mail_index_map_sync_funcs,
+					 &sync_map_ctx) < 0)
 			return -1;
 	}
 

Index: mail-transaction-log.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mail-transaction-log.c	4 Jul 2004 22:03:21 -0000	1.45
+++ mail-transaction-log.c	4 Jul 2004 22:19:49 -0000	1.46
@@ -970,7 +970,8 @@
 
 	/* make sure we're not writing cache_offsets to old cache file */
 	if (t->new_cache_file_seq == 0 && max_cache_file_seq != 0 &&
-	    max_cache_file_seq != t->last_cache_file_seq) {
+	    max_cache_file_seq != t->last_cache_file_seq &&
+	    t->cache_updates != NULL) {
 		buffer_free(t->cache_updates);
 		t->cache_updates = NULL;
 	}
@@ -1103,8 +1104,10 @@
 	}
 
 	if (mail_index_lock_shared(log->index, TRUE, &lock_id) < 0) {
-		if (!log->index->log_locked)
-			(void)mail_transaction_log_file_lock(file, F_UNLCK);
+		if (!log->index->log_locked) {
+			(void)mail_transaction_log_file_lock(log->head,
+							     F_UNLCK);
+		}
 		return -1;
 	}
 	idx_hdr = *log->index->hdr;



More information about the dovecot-cvs mailing list