dovecot-2.2: maildir: If we notice an unexpectedly inserted file...
dovecot at dovecot.org
dovecot at dovecot.org
Mon May 20 01:53:52 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/096054ae8584
changeset: 16375:096054ae8584
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 422d165d4b8e -r 096054ae8584 src/lib-storage/index/maildir/maildir-sync-index.c
--- a/src/lib-storage/index/maildir/maildir-sync-index.c Mon May 20 01:39:52 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 422d165d4b8e -r 096054ae8584 src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c Mon May 20 01:39:52 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;
@@ -981,26 +987,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;
}
@@ -1037,7 +1060,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;
@@ -1048,13 +1070,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 422d165d4b8e -r 096054ae8584 src/lib-storage/index/maildir/maildir-sync.h
--- a/src/lib-storage/index/maildir/maildir-sync.h Mon May 20 01:39:52 2013 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.h Mon May 20 01:52:25 2013 +0300
@@ -38,6 +38,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