[dovecot-cvs] dovecot/src/lib-storage/index index-copy.c,1.18,1.19 index-expunge.c,1.10,1.11 index-fetch.c,1.30,1.31 index-search.c,1.38,1.39 index-status.c,1.17,1.18 index-storage.c,1.18,1.19 index-storage.h,1.17,1.18 index-sync.c,1.17,1.18 Message-Id: <20021102201023.7DAD6238AA@danu.procontrol.fi>

cras at procontrol.fi cras at procontrol.fi
Sat Nov 2 22:10:23 EET 2002


Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv8907/lib-storage/index

Modified Files:
	index-copy.c index-expunge.c index-fetch.c index-search.c 
	index-status.c index-storage.c index-storage.h index-sync.c 
	index-update-flags.c 
Log Message:
Mostly mbox locking/syncing fixes. Still some problems though.



Index: index-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-copy.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- index-copy.c	27 Oct 2002 06:37:18 -0000	1.18
+++ index-copy.c	2 Nov 2002 20:10:21 -0000	1.19
@@ -40,6 +40,7 @@
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
         CopyContext ctx;
+	MailLockType lock_type;
 	int failed;
 
 	if (destbox->readonly) {
@@ -48,10 +49,11 @@
 		return FALSE;
 	}
 
-	if (!ibox->index->sync(ibox->index))
-		return mail_storage_set_index_error(ibox);
+	lock_type = destbox->storage == box->storage &&
+		strcmp(destbox->name, box->name) == 0 ?
+		MAIL_LOCK_EXCLUSIVE : MAIL_LOCK_SHARED;
 
-	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
+	if (!ibox->index->sync_and_lock(ibox->index, lock_type, NULL))
 		return mail_storage_set_index_error(ibox);
 
 	ctx.custom_flags =

Index: index-expunge.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-expunge.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- index-expunge.c	19 Oct 2002 23:33:56 -0000	1.10
+++ index-expunge.c	2 Nov 2002 20:10:21 -0000	1.11
@@ -70,11 +70,8 @@
 		return FALSE;
 	}
 
-	if (!index_storage_sync_index_if_possible(ibox, FALSE))
+	if (!index_storage_sync_and_lock(ibox, FALSE, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
-
-	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_EXCLUSIVE))
-		return mail_storage_set_index_error(ibox);
 
 	/* modifylog must be marked synced before expunging anything new */
 	failed = !index_storage_sync_modifylog(ibox, TRUE);

Index: index-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- index-fetch.c	27 Oct 2002 06:37:18 -0000	1.30
+++ index-fetch.c	2 Nov 2002 20:10:21 -0000	1.31
@@ -347,9 +347,6 @@
 	MailFetchBodyData *sect;
 	int ret;
 
-	if (!index_storage_sync_index_if_possible(ibox, TRUE))
-		return FALSE;
-
 	memset(&ctx, 0, sizeof(ctx));
 
 	if (!box->readonly) {
@@ -364,21 +361,22 @@
 		}
 	}
 
-	if (ctx.update_seen) {
-		/* need exclusive lock to update the \Seen flags */
-		if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_EXCLUSIVE))
-			return mail_storage_set_index_error(ibox);
+	/* need exclusive lock to update the \Seen flags */
+	if (!index_storage_sync_and_lock(ibox, TRUE, ctx.update_seen ?
+					 MAIL_LOCK_EXCLUSIVE :
+					 MAIL_LOCK_SHARED))
+		return FALSE;
 
+	if (ctx.update_seen) {
 		/* if all messages are already seen, there's no point in
 		   keeping exclusive lock */
 		if (ibox->index->header->messages_count ==
-		    ibox->index->header->seen_messages_count)
+		    ibox->index->header->seen_messages_count) {
 			ctx.update_seen = FALSE;
-	}
 
-	if (!ctx.update_seen) {
-		if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
-			return mail_storage_set_index_error(ibox);
+			(void)ibox->index->set_lock(ibox->index,
+						    MAIL_LOCK_SHARED);
+		}
 	}
 
 	ctx.box = box;

Index: index-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- index-search.c	30 Oct 2002 18:26:30 -0000	1.38
+++ index-search.c	2 Nov 2002 20:10:21 -0000	1.39
@@ -903,11 +903,8 @@
 	IndexMailbox *ibox = (IndexMailbox *) box;
 	int failed;
 
-	if (!index_storage_sync_index_if_possible(ibox, TRUE))
+	if (!index_storage_sync_and_lock(ibox, TRUE, MAIL_LOCK_SHARED))
 		return FALSE;
-
-	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
-		return mail_storage_set_index_error(ibox);
 
 	o_buffer_send(outbuf, "* SEARCH", 8);
 	failed = !search_messages(ibox, args, outbuf, uid_result);

Index: index-status.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-status.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- index-status.c	28 Oct 2002 07:50:23 -0000	1.17
+++ index-status.c	2 Nov 2002 20:10:21 -0000	1.18
@@ -75,11 +75,8 @@
 
 	/* if we're doing STATUS for selected mailbox, we have to sync it
 	   first or STATUS reply may give different data */
-	if (!index_storage_sync_index_if_possible(ibox, TRUE))
+	if (!index_storage_sync_and_lock(ibox, TRUE, MAIL_LOCK_SHARED))
 		return FALSE;
-
-	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
-		return mail_storage_set_index_error(ibox);
 
 	if (!index_storage_sync_modifylog(ibox, FALSE)) {
 		if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_UNLOCK))

Index: index-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- index-storage.c	28 Oct 2002 09:46:03 -0000	1.18
+++ index-storage.c	2 Nov 2002 20:10:21 -0000	1.19
@@ -191,7 +191,7 @@
 	return NULL;
 }
 
-void index_storage_close(Mailbox *box)
+int index_storage_close(Mailbox *box)
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
 
@@ -199,6 +199,8 @@
 	index_storage_unref(ibox->index);
 	i_free(box->name);
 	i_free(box);
+
+	return TRUE;
 }
 
 void index_storage_set_sync_callbacks(Mailbox *box,

Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- index-storage.h	27 Oct 2002 06:37:18 -0000	1.17
+++ index-storage.h	2 Nov 2002 20:10:21 -0000	1.18
@@ -35,9 +35,10 @@
 IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box,
 				 MailIndex *index, const char *name,
 				 int readonly, int fast);
-void index_storage_close(Mailbox *box);
+int index_storage_close(Mailbox *box);
 
-int index_storage_sync_index_if_possible(IndexMailbox *ibox, int sync_size);
+int index_storage_sync_and_lock(IndexMailbox *ibox, int sync_size,
+				MailLockType lock_type);
 int index_storage_sync_modifylog(IndexMailbox *ibox, int hide_deleted);
 
 int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags,

Index: index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- index-sync.c	25 Oct 2002 02:52:02 -0000	1.17
+++ index-sync.c	2 Nov 2002 20:10:21 -0000	1.18
@@ -27,12 +27,20 @@
 	}
 }
 
-/* may leave the index locked */
-int index_storage_sync_index_if_possible(IndexMailbox *ibox, int sync_size)
+int index_storage_sync_and_lock(IndexMailbox *ibox, int sync_size,
+				MailLockType lock_type)
 {
 	MailIndex *index = ibox->index;
+	int unlock, changes;
 
-	if (index->sync(index)) {
+	if (lock_type != MAIL_LOCK_UNLOCK)
+		unlock = FALSE;
+	else {
+		unlock = TRUE;
+		lock_type = MAIL_LOCK_SHARED;
+	}
+
+	if (index->sync_and_lock(index, lock_type, &changes)) {
 		/* reset every time it has worked */
 		ibox->sent_diskspace_warning = FALSE;
 	} else {
@@ -53,8 +61,11 @@
 	}
 
 	/* notify about changes in mailbox size. */
-	if (index->lock_type == MAIL_LOCK_UNLOCK)
+	if (!changes) {
+		if (unlock)
+			(void)index->set_lock(index, MAIL_LOCK_UNLOCK);
 		return TRUE; /* no changes - must be no new mail either */
+	}
 
 	if (sync_size)
 		index_storage_sync_size(ibox);
@@ -67,6 +78,9 @@
 			MAIL_CUSTOM_FLAGS_COUNT, ibox->sync_context);
 	}
 
+	if (unlock)
+		(void)index->set_lock(index, MAIL_LOCK_UNLOCK);
+
 	return TRUE;
 }
 
@@ -194,16 +208,13 @@
 	IndexMailbox *ibox = (IndexMailbox *) box;
 	int failed;
 
-	if (!index_storage_sync_index_if_possible(ibox, FALSE))
+	if (!index_storage_sync_and_lock(ibox, FALSE, MAIL_LOCK_SHARED))
 		return FALSE;
 
 	if (!sync_expunges) {
 		/* FIXME: we could still send flag changes */
 		failed = FALSE;
 	} else {
-		if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
-			return mail_storage_set_index_error(ibox);
-
 		failed = !index_storage_sync_modifylog(ibox, FALSE);
 	}
 

Index: index-update-flags.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-update-flags.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- index-update-flags.c	28 Oct 2002 09:46:03 -0000	1.12
+++ index-update-flags.c	2 Nov 2002 20:10:21 -0000	1.13
@@ -72,14 +72,11 @@
 		return FALSE;
 	}
 
-	if (!index_storage_sync_index_if_possible(ibox, TRUE))
-		return FALSE;
-
 	if (!index_mailbox_fix_custom_flags(ibox, &flags, custom_flags))
 		return FALSE;
 
-	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_EXCLUSIVE))
-		return mail_storage_set_index_error(ibox);
+	if (!index_storage_sync_and_lock(ibox, TRUE, MAIL_LOCK_EXCLUSIVE))
+		return FALSE;
 
 	ctx.ibox = ibox;
 	ctx.flags = flags & ~MAIL_RECENT; /* \Recent can't be changed */




More information about the dovecot-cvs mailing list