]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Rebuild index after it's been fsck'd
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 24 Nov 2016 16:12:18 +0000 (18:12 +0200)
committerGitLab <gitlab@git.dovecot.net>
Fri, 25 Nov 2016 13:25:14 +0000 (15:25 +0200)
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-map.h
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-sync.c

index cf993efbbdebde28f869e35fa0613bc94c85b51e..6c602c32901388756f52e7416a6224bdba3c5503 100644 (file)
@@ -238,6 +238,19 @@ int mdbox_map_refresh(struct mdbox_map *map)
        return ret;
 }
 
+bool mdbox_map_is_fscked(struct mdbox_map *map)
+{
+       const struct mail_index_header *hdr;
+
+       if (map->view == NULL) {
+               /* map isn't opened yet. don't bother. */
+               return FALSE;
+       }
+
+       hdr = mail_index_get_header(map->view);
+       return (hdr->flags & MAIL_INDEX_HDR_FLAG_FSCKD) != 0;
+}
+
 static void
 mdbox_map_get_ext_hdr(struct mdbox_map *map, struct mail_index_view *view,
                      struct mdbox_map_mail_index_header *hdr_r)
@@ -533,6 +546,11 @@ void mdbox_map_atomic_set_success(struct mdbox_map_atomic_context *atomic)
                atomic->success = TRUE;
 }
 
+void mdbox_map_atomic_unset_fscked(struct mdbox_map_atomic_context *atomic)
+{
+       mail_index_unset_fscked(atomic->sync_trans);
+}
+
 int mdbox_map_atomic_finish(struct mdbox_map_atomic_context **_atomic)
 {
        struct mdbox_map_atomic_context *atomic = *_atomic;
index b89ae812ae491731b90c5911bbdd000aeed57c2b..9571f0e9ec494b6167152e9f2eff1e8997d7f480 100644 (file)
@@ -41,6 +41,8 @@ int mdbox_map_open(struct mdbox_map *map);
 int mdbox_map_open_or_create(struct mdbox_map *map);
 /* Refresh the map. Returns 0 if ok, -1 if error. */
 int mdbox_map_refresh(struct mdbox_map *map);
+/* Returns TRUE if map has been fsck'd. */
+bool mdbox_map_is_fscked(struct mdbox_map *map);
 
 /* Return the current rebuild counter */
 uint32_t mdbox_map_get_rebuild_count(struct mdbox_map *map);
@@ -81,6 +83,8 @@ void mdbox_map_atomic_set_failed(struct mdbox_map_atomic_context *atomic);
    transaction or append is committed within this atomic, but not when the
    atomic is used standalone. */
 void mdbox_map_atomic_set_success(struct mdbox_map_atomic_context *atomic);
+/* Remove fsck'd flag. */
+void mdbox_map_atomic_unset_fscked(struct mdbox_map_atomic_context *atomic);
 /* Commit/rollback changes within this atomic context. */
 int mdbox_map_atomic_finish(struct mdbox_map_atomic_context **atomic);
 
index 4eece4f9338777e5b5f00de9a60c3f673649d4b3..9b3e1224257f4e31dd95382f91c433b1ca89ff8a 100644 (file)
@@ -581,6 +581,7 @@ rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx,
        mdbox_header_update(ctx, rebuild_ctx, mbox);
        rebuild_mailbox_multi(ctx, rebuild_ctx, mbox, view, trans);
        index_index_rebuild_deinit(&rebuild_ctx, dbox_get_uidvalidity_next);
+       mail_index_unset_fscked(trans);
 
        mail_index_sync_set_reason(sync_ctx, "mdbox storage rebuild");
        if (mail_index_sync_commit(&sync_ctx) < 0) {
@@ -982,6 +983,7 @@ int mdbox_storage_rebuild(struct mdbox_storage *storage)
        atomic = mdbox_map_atomic_begin(storage->map);
        ret = mdbox_storage_rebuild_in_context(storage, atomic);
        mdbox_map_atomic_set_success(atomic);
+       mdbox_map_atomic_unset_fscked(atomic);
        if (mdbox_map_atomic_finish(&atomic) < 0)
                ret = -1;
        return ret;
index fd59e8592c0307522146b4d7744b4d3411ba5efa..29b1e72a4aa1a39ddc7035bf78056391ac18b976 100644 (file)
@@ -226,6 +226,8 @@ int mdbox_sync_begin(struct mdbox_mailbox *mbox, enum mdbox_sync_flags flags,
                     struct mdbox_sync_context **ctx_r)
 {
        struct mail_storage *storage = mbox->box.storage;
+       const struct mail_index_header *hdr =
+               mail_index_get_header(mbox->box.view);
        struct mdbox_sync_context *ctx;
        const char *reason;
        enum mail_index_sync_flags sync_flags;
@@ -237,6 +239,8 @@ int mdbox_sync_begin(struct mdbox_mailbox *mbox, enum mdbox_sync_flags flags,
        /* avoid race conditions with mailbox creation, don't check for dbox
           headers until syncing has locked the mailbox */
        rebuild = mbox->storage->corrupted ||
+               (hdr->flags & MAIL_INDEX_HDR_FLAG_FSCKD) != 0 ||
+               mdbox_map_is_fscked(mbox->storage->map) ||
                (flags & MDBOX_SYNC_FLAG_FORCE_REBUILD) != 0;
        if (rebuild && (flags & MDBOX_SYNC_FLAG_NO_REBUILD) == 0) {
                if (mdbox_storage_rebuild_in_context(mbox->storage, atomic) < 0)