]> 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)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 30 Oct 2023 08:40:13 +0000 (08:40 +0000)
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 17b68b3d65d149be64d8b8eaa0c0eaaf01c792fb..193dca61b32a62c0a3304c3860273170ed316a19 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 62aaf6af17d58b709ef63f8b1443dc39f2cb5a2a..85cab8cf13024accb7a20dc043112626043c59bc 100644 (file)
@@ -682,7 +682,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 c4930537f4bf050f86d4e8b92a72c303d0456a64..cc188a65ea466950f9f611b92ed0aae533dd133a 100644 (file)
@@ -922,9 +922,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(
@@ -954,7 +957,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;
        }
@@ -1014,7 +1017,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 ff0591d8bafcd77ab3c105733d7ce2e6df089e28..d5a54a7a8cc2ce9c4826a2ea271435725a0b41a4 100644 (file)
@@ -89,6 +89,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);
 }
 
@@ -201,7 +202,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);
        }
@@ -354,12 +356,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 88a8b6f5d1b5b97d7d8728f86a7a668f77c42fc7..b9304febc1ac824d28631e82bf965c1639de5f64 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);