]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 25 Nov 2016 13:31:25 +0000 (15:31 +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 fec4115c155e171b1c3c755473401a8c23bd9003..6f031c080d66fe9db253e60db9deef48275786cf 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 5cf75e719dcba6f1b638b338885dc8a47af3fc29..9d26bc296828c7e96247106d5d7f2fbb3631b9e7 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 59e9c559067273c377d4da2dbe29512d93a0b226..133d884c7f5dc4e23d5ba46fa1878082ea817073 100644 (file)
@@ -225,6 +225,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;
@@ -236,6 +238,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)