dovecot-2.1: maildir: If we notice an unexpectedly inserted file...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 20 01:54:11 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.1/rev/4c05b9447a10
changeset: 14968:4c05b9447a10
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 20 01:52:25 2013 +0300
description:
maildir: If we notice an unexpectedly inserted file, retry the sync to fix it.
Without this doveadm force-resync would just ignore the inserted files.

diffstat:

 src/lib-storage/index/maildir/maildir-sync-index.c |   1 +
 src/lib-storage/index/maildir/maildir-sync.c       |  59 ++++++++++++++-------
 src/lib-storage/index/maildir/maildir-sync.h       |   1 +
 3 files changed, 40 insertions(+), 21 deletions(-)

diffs (121 lines):

diff -r 7389ff729d2e -r 4c05b9447a10 src/lib-storage/index/maildir/maildir-sync-index.c
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Wed May 15 15:26:47 2013 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Mon May 20 01:52:25 2013 +0300
@@ -181,6 +181,7 @@
 	if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RACING) == 0) {
 		/* mark it racy and check in next sync */
 		ctx->mbox->maildir_hdr.cur_check_time = 0;
+		maildir_sync_set_racing(ctx->maildir_sync_ctx);
 		maildir_uidlist_add_flags(ctx->mbox->uidlist, filename,
 					  MAILDIR_UIDLIST_REC_FLAG_RACING);
 		return 0;
diff -r 7389ff729d2e -r 4c05b9447a10 src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c	Wed May 15 15:26:47 2013 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Mon May 20 01:52:25 2013 +0300
@@ -229,8 +229,14 @@
 
 	unsigned int partial:1;
 	unsigned int locked:1;
+	unsigned int racing:1;
 };
 
+void maildir_sync_set_racing(struct maildir_sync_context *ctx)
+{
+	ctx->racing = TRUE;
+}
+
 void maildir_sync_notify(struct maildir_sync_context *ctx)
 {
 	time_t now;
@@ -980,26 +986,43 @@
 	return maildir_uidlist_lookup(mbox->uidlist, uid, flags_r, fname_r);
 }
 
+static int maildir_sync_run(struct maildir_mailbox *mbox,
+			    enum mailbox_sync_flags flags, bool force_resync,
+			    uint32_t *uid, bool *lost_files_r)
+{
+	struct maildir_sync_context *ctx;
+	bool retry, lost_files;
+	int ret;
+
+	T_BEGIN {
+		ctx = maildir_sync_context_new(mbox, flags);
+		ret = maildir_sync_context(ctx, force_resync, uid, lost_files_r);
+		retry = ctx->racing;
+		maildir_sync_deinit(ctx);
+	} T_END;
+
+	if (retry) T_BEGIN {
+		/* we're racing some file. retry the sync again to see if the
+		   file is really gone or not. if it is, this is a bit of
+		   unnecessary work, but if it's not, this is necessary for
+		   e.g. doveadm force-resync to work. */
+		ctx = maildir_sync_context_new(mbox, 0);
+		ret = maildir_sync_context(ctx, TRUE, NULL, &lost_files);
+		maildir_sync_deinit(ctx);
+	} T_END;
+	return ret;
+}
+
 int maildir_storage_sync_force(struct maildir_mailbox *mbox, uint32_t uid)
 {
-        struct maildir_sync_context *ctx;
 	bool lost_files;
 	int ret;
 
-	T_BEGIN {
-		ctx = maildir_sync_context_new(mbox, MAILBOX_SYNC_FLAG_FAST);
-		ret = maildir_sync_context(ctx, TRUE, &uid, &lost_files);
-		maildir_sync_deinit(ctx);
-	} T_END;
-
+	ret = maildir_sync_run(mbox, MAILBOX_SYNC_FLAG_FAST,
+			       TRUE, &uid, &lost_files);
 	if (uid != 0) {
 		/* maybe it's expunged. check again. */
-		T_BEGIN {
-			ctx = maildir_sync_context_new(mbox, 0);
-			ret = maildir_sync_context(ctx, TRUE, NULL,
-						   &lost_files);
-			maildir_sync_deinit(ctx);
-		} T_END;
+		ret = maildir_sync_run(mbox, 0, TRUE, NULL, &lost_files);
 	}
 	return ret;
 }
@@ -1036,7 +1059,6 @@
 maildir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
 	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
-	struct maildir_sync_context *ctx;
 	bool lost_files, force_resync;
 	int ret = 0;
 
@@ -1047,13 +1069,8 @@
 
 	force_resync = (flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0;
 	if (index_mailbox_want_full_sync(&mbox->box, flags)) {
-		T_BEGIN {
-			ctx = maildir_sync_context_new(mbox, flags);
-			ret = maildir_sync_context(ctx, force_resync, NULL,
-						   &lost_files);
-			maildir_sync_deinit(ctx);
-		} T_END;
-
+		ret = maildir_sync_run(mbox, flags, force_resync,
+				       NULL, &lost_files);
 		i_assert(!maildir_uidlist_is_locked(mbox->uidlist) ||
 			 (box->flags & MAILBOX_FLAG_KEEP_LOCKED) != 0);
 
diff -r 7389ff729d2e -r 4c05b9447a10 src/lib-storage/index/maildir/maildir-sync.h
--- a/src/lib-storage/index/maildir/maildir-sync.h	Wed May 15 15:26:47 2013 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.h	Mon May 20 01:52:25 2013 +0300
@@ -39,6 +39,7 @@
 
 struct maildir_keywords_sync_ctx *
 maildir_sync_get_keywords_sync_ctx(struct maildir_index_sync_context *ctx);
+void maildir_sync_set_racing(struct maildir_sync_context *ctx);
 void maildir_sync_notify(struct maildir_sync_context *ctx);
 void maildir_sync_set_new_msgs_count(struct maildir_index_sync_context *ctx,
 				     unsigned int count);


More information about the dovecot-cvs mailing list