]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Change mdbox_storage.corrupted boolean to reason string
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 3 Jul 2023 10:23:52 +0000 (13:23 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 31 Jan 2024 11:38:54 +0000 (13:38 +0200)
src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c
src/lib-storage/index/dbox-multi/mdbox-purge.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage.h
src/lib-storage/index/dbox-multi/mdbox-sync.c

index 4fdf1ab2cf3b71c6407a7a6002d571f48bbfcd07..91b59003c793b11d69909c055ae2354f9ea95f4a 100644 (file)
@@ -231,7 +231,7 @@ mdbox_deleted_storage_sync_init(struct mailbox *box,
        int ret = 0;
 
        if (index_mailbox_want_full_sync(&mbox->box, flags) ||
-           mbox->storage->corrupted)
+           mbox->storage->corrupted_reason != NULL)
                ret = mdbox_deleted_sync(mbox, mdbox_sync_flags);
 
        return index_mailbox_sync_init(box, flags, ret < 0);
index 195eeec8977c8b8945b2a488c90d7a3cd6d2a6a6..a9e89b5023b0a8197d9f7567d734b39f78836b74 100644 (file)
@@ -681,7 +681,7 @@ int mdbox_purge(struct mail_storage *_storage)
        } T_END;
        mdbox_purge_free(&ctx);
 
-       if (storage->corrupted) {
+       if (storage->corrupted_reason != NULL) {
                /* purging found corrupted files */
                (void)mdbox_storage_rebuild(storage, NULL,
                                            MDBOX_REBUILD_REASON_CORRUPTED);
index 824e85d7543f357b14f5781eed0f6af77d483363..96379287a9a7c63dccd2dbb7accc8287a03b8fcb 100644 (file)
@@ -918,9 +918,12 @@ mdbox_storage_rebuild_scan_prepare(struct mdbox_storage_rebuild_context *ctx,
 
        if ((reason & MDBOX_REBUILD_REASON_FORCED) != 0)
                *reason_string_r = "Rebuild forced";
-       else if ((reason & MDBOX_REBUILD_REASON_CORRUPTED) != 0)
-               *reason_string_r = "Storage was marked corrupted";
-       else if ((reason & MDBOX_REBUILD_REASON_MAP_FSCKD) != 0)
+       else if ((reason & MDBOX_REBUILD_REASON_CORRUPTED) != 0) {
+               i_assert(ctx->storage->corrupted_reason != NULL);
+               *reason_string_r = t_strdup_printf(
+                       "Storage was marked corrupted: %s",
+                       ctx->storage->corrupted_reason);
+       } else if ((reason & MDBOX_REBUILD_REASON_MAP_FSCKD) != 0)
                *reason_string_r = "dovecot.index.map was fsck'd";
        else if ((reason & MDBOX_REBUILD_REASON_MAILBOX_FSCKD) != 0) {
                *reason_string_r = t_strdup_printf(
@@ -948,7 +951,7 @@ mdbox_storage_rebuild_scan_prepare(struct mdbox_storage_rebuild_context *ctx,
        /* get storage rebuild counter after locking */
        ctx->rebuild_count = mdbox_map_get_rebuild_count(ctx->storage->map);
        if (ctx->rebuild_count != ctx->storage->corrupted_rebuild_count &&
-           ctx->storage->corrupted) {
+           ctx->storage->corrupted_reason != NULL) {
                /* storage was already rebuilt by someone else */
                return 0;
        }
@@ -1008,7 +1011,7 @@ mdbox_storage_rebuild_in_context(struct mdbox_storage *storage,
        mdbox_storage_rebuild_deinit(ctx);
 
        if (ret == 0) {
-               storage->corrupted = FALSE;
+               i_free(storage->corrupted_reason);
                storage->corrupted_rebuild_count = 0;
        }
        return ret;
index a0501430db959439e1b208e67fbb396b47055cb1..c2250398eb1b5718c78adb00acb0e8cbfbb17309 100644 (file)
@@ -83,6 +83,7 @@ void mdbox_storage_destroy(struct mail_storage *_storage)
        if (array_is_created(&storage->move_to_alt_map_uids))
                array_free(&storage->move_to_alt_map_uids);
        array_free(&storage->open_files);
+       i_free(storage->corrupted_reason);
        dbox_storage_destroy(_storage);
 }
 
@@ -197,7 +198,8 @@ static void mdbox_mailbox_close(struct mailbox *box)
 {
        struct mdbox_storage *mstorage = MDBOX_STORAGE(box->storage);
 
-       if (mstorage->corrupted && !mstorage->rebuilding_storage) {
+       if (mstorage->corrupted_reason != NULL &&
+           !mstorage->rebuilding_storage) {
                (void)mdbox_storage_rebuild(mstorage, box,
                                            MDBOX_REBUILD_REASON_CORRUPTED);
        }
@@ -350,12 +352,12 @@ int mdbox_mailbox_create_indexes(struct mailbox *box,
 
 void mdbox_storage_set_corrupted(struct mdbox_storage *storage)
 {
-       if (storage->corrupted) {
+       if (storage->corrupted_reason != NULL) {
                /* already set it corrupted (possibly recursing back here) */
                return;
        }
 
-       storage->corrupted = TRUE;
+       storage->corrupted_reason = i_strdup("Storage marked corrupted");
        storage->corrupted_rebuild_count = (uint32_t)-1;
 
        if (mdbox_map_open(storage->map) > 0 &&
index ea995328033ebb53111faa7d1d4f6c80fb02392c..dbb6cfa7b05018bad4b696662b329011e771bf47 100644 (file)
@@ -39,8 +39,8 @@ struct mdbox_storage {
        /* if non-zero, storage should be rebuilt (except if rebuild_count
           has changed from this value) */
        uint32_t corrupted_rebuild_count;
+       char *corrupted_reason;
 
-       bool corrupted:1;
        bool rebuilding_storage:1;
        bool preallocate_space:1;
 };
index 3bb522f7453766456a98ea9fc7eb497d8c89f75c..0b7baba1484420e9bd26194c67c296928dad73ae 100644 (file)
@@ -193,7 +193,7 @@ static int mdbox_sync_index(struct mdbox_sync_context *ctx)
        mailbox_sync_notify(box, 0, 0);
 
        return ret == 0 ? 1 :
-               (ctx->mbox->storage->corrupted ? 0 : -1);
+               (ctx->mbox->storage->corrupted_reason != NULL ? 0 : -1);
 }
 
 static int mdbox_sync_try_begin(struct mdbox_sync_context *ctx,
@@ -322,7 +322,7 @@ int mdbox_sync(struct mdbox_mailbox *mbox, enum mdbox_sync_flags flags)
        bool corrupted, storage_rebuilt = FALSE;
        int ret;
 
-       if (mbox->storage->corrupted)
+       if (mbox->storage->corrupted_reason != NULL)
                rebuild_reason |= MDBOX_REBUILD_REASON_CORRUPTED;
        if ((hdr->flags & MAIL_INDEX_HDR_FLAG_FSCKD) != 0)
                rebuild_reason |= MDBOX_REBUILD_REASON_MAILBOX_FSCKD;
@@ -373,7 +373,7 @@ mdbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
        if (mail_index_reset_fscked(box->index))
                mdbox_storage_set_corrupted(mbox->storage);
        if (index_mailbox_want_full_sync(&mbox->box, flags) ||
-           mbox->storage->corrupted) {
+           mbox->storage->corrupted_reason != NULL) {
                if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0)
                        mdbox_sync_flags |= MDBOX_SYNC_FLAG_FORCE_REBUILD;
                ret = mdbox_sync(mbox, mdbox_sync_flags);