[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-storage.c, 1.113, 1.114 maildir-sync.c, 1.74, 1.75 maildir-uidlist.c, 1.48, 1.49

cras at dovecot.org cras at dovecot.org
Sun Apr 9 18:50:30 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/maildir
In directory talvi:/tmp/cvs-serv6879/lib-storage/index/maildir

Modified Files:
	maildir-storage.c maildir-sync.c maildir-uidlist.c 
Log Message:
Added MAILBOX_OPEN_KEEP_LOCKED flag to mailbox opening and implemented it
for mbox and maildir. It keeps the mailbox locked the whole time until
mailbox_close() is called.



Index: maildir-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- maildir-storage.c	1 Apr 2006 09:31:15 -0000	1.113
+++ maildir-storage.c	9 Apr 2006 15:50:27 -0000	1.114
@@ -466,6 +466,14 @@
 		mbox->private_flags_mask = MAIL_SEEN;
 	}
 
+	if (mbox->ibox.keep_locked) {
+		if (maildir_uidlist_lock(mbox->uidlist) <= 0) {
+			struct mailbox *box = &mbox->ibox.box;
+
+			mailbox_close(&box);
+			return NULL;
+		}
+	}
 
 	return &mbox->ibox.box;
 }
@@ -878,6 +886,9 @@
 		ret = -1;
 	}*/
 
+	if (mbox->ibox.keep_locked)
+		maildir_uidlist_unlock(mbox->uidlist);
+
 	maildir_keywords_deinit(mbox->keywords);
 	maildir_uidlist_deinit(mbox->uidlist);
         index_storage_mailbox_free(box);

Index: maildir-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-sync.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- maildir-sync.c	2 Apr 2006 16:32:51 -0000	1.74
+++ maildir-sync.c	9 Apr 2006 15:50:27 -0000	1.75
@@ -1344,7 +1344,8 @@
 		ret = maildir_sync_context(ctx, FALSE, FALSE);
 		maildir_sync_deinit(ctx);
 
-		i_assert(!maildir_uidlist_is_locked(mbox->uidlist));
+		i_assert(!maildir_uidlist_is_locked(mbox->uidlist) ||
+			 mbox->ibox.keep_locked);
 
 		if (ret == 0) {
 			/* lost some files from new/, see if thery're in cur/ */

Index: maildir-uidlist.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-uidlist.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- maildir-uidlist.c	26 Feb 2006 10:32:23 -0000	1.48
+++ maildir-uidlist.c	9 Apr 2006 15:50:28 -0000	1.49
@@ -57,6 +57,7 @@
 	unsigned int initial_sync:1;
 
 	unsigned int need_rewrite:1;
+	unsigned int delayed_rewrite:1;
 };
 
 struct maildir_uidlist_sync_ctx {
@@ -98,8 +99,12 @@
 			       &uidlist->dotlock);
 	umask(old_mask);
 	if (fd == -1) {
-		if (errno == EAGAIN)
+		if (errno == EAGAIN) {
+			mail_storage_set_error(STORAGE(uidlist->mbox->storage),
+				"Timeout while waiting for lock");
+			STORAGE(uidlist->mbox->storage)->temporary_error = TRUE;
 			return 0;
+		}
 		mail_storage_set_critical(STORAGE(uidlist->mbox->storage),
 			"file_dotlock_open(%s) failed: %m", path);
 		return -1;
@@ -136,7 +141,20 @@
 	if (--uidlist->lock_count > 0)
 		return;
 
-	(void)file_dotlock_delete(&uidlist->dotlock);
+	if (!uidlist->delayed_rewrite) {
+		(void)file_dotlock_delete(&uidlist->dotlock);
+	} else {
+		if (file_dotlock_replace(&uidlist->dotlock, 0) <= 0) {
+			const char *db_path;
+
+			db_path = t_strconcat(uidlist->mbox->control_dir,
+					      "/" MAILDIR_UIDLIST_NAME, NULL);
+			mail_storage_set_critical(
+				STORAGE(uidlist->mbox->storage),
+				"file_dotlock_replace(%s) failed: %m", db_path);
+		}
+		uidlist->delayed_rewrite = FALSE;
+	}
 	uidlist->lock_fd = -1;
 }
 
@@ -514,6 +532,20 @@
 	const char *filename;
 	int ret = 0;
 
+	if (uidlist->delayed_rewrite) {
+		/* already written, truncate */
+		if (lseek(uidlist->lock_fd, 0, SEEK_SET) < 0) {
+			mail_storage_set_critical(storage,
+				"lseek(%s) failed: %m", temp_path);
+			return -1;
+		}
+		if (ftruncate(uidlist->lock_fd, 0) < 0) {
+			mail_storage_set_critical(storage,
+				"ftruncate(%s) failed: %m", temp_path);
+			return -1;
+		}
+	}
+
 	uidlist->version = 1;
 
 	if (uidlist->uid_validity == 0) {
@@ -583,13 +615,14 @@
 	const char *temp_path, *db_path;
 	int ret;
 
-	i_assert(uidlist->lock_count == 1);
+	i_assert(uidlist->lock_count ==
+		 1 + (uidlist->mbox->ibox.keep_locked ? 1 : 0));
 
 	temp_path = t_strconcat(mbox->control_dir,
 				"/" MAILDIR_UIDLIST_NAME ".lock", NULL);
 	ret = maildir_uidlist_rewrite_fd(uidlist, temp_path);
 
-	if (ret == 0) {
+	if (ret == 0 && !uidlist->mbox->ibox.keep_locked) {
 		db_path = t_strconcat(mbox->control_dir,
 				      "/" MAILDIR_UIDLIST_NAME, NULL);
 
@@ -603,6 +636,8 @@
 		uidlist->lock_fd = -1;
 		uidlist->lock_count--;
 	} else {
+		if (uidlist->mbox->ibox.keep_locked)
+			uidlist->delayed_rewrite = TRUE;
                 maildir_uidlist_unlock(uidlist);
 	}
 
@@ -885,7 +920,12 @@
 
 	if (ctx->uidlist->need_rewrite ||
 	    (ctx->new_files_count != 0 && !ctx->failed)) {
-		if (ctx->uidlist->lock_count > 1) {
+		unsigned int nonrecursive_lock_count = 1;
+
+		if (ctx->uidlist->mbox->ibox.keep_locked)
+			nonrecursive_lock_count++;
+
+		if (ctx->uidlist->lock_count > nonrecursive_lock_count) {
 			/* recursive sync. let the root syncing do
 			   the rewrite */
 			ctx->uidlist->need_rewrite = TRUE;



More information about the dovecot-cvs mailing list