]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Add reason parameter to dbox_storage_vfuncs.set_mailbox_corrupted()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 3 Jul 2023 10:45:28 +0000 (13:45 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 31 Jan 2024 11:45:08 +0000 (13:45 +0200)
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-common/dbox-storage.h
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage.h
src/lib-storage/index/dbox-single/sdbox-file.c
src/lib-storage/index/dbox-single/sdbox-mail.c
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.h
src/lib-storage/index/dbox-single/sdbox-sync.c

index 3087174b4725520cf40c91a19fb4526c35054ead..0ffccaaf1ecde01b6ecf57cae280c403c0431c19 100644 (file)
@@ -386,10 +386,9 @@ int dbox_mailbox_create(struct mailbox *box,
                if (ret < 0)
                        return -1;
                if (ret == 0) {
-                       mailbox_set_critical(box,
+                       storage->v.set_mailbox_corrupted(box,
                                "Existing files in alt path, "
                                "rebuilding storage to avoid losing messages");
-                       storage->v.set_mailbox_corrupted(box);
                        return -1;
                }
                /* dir is empty, ignore it */
index 4da88b566de51e1d519ecfcbddb0e870d117a229..88cfe32dc521dd7fce7c5e106820be8f7c94ed9b 100644 (file)
@@ -49,7 +49,7 @@ struct dbox_storage_vfuncs {
           "-<mailbox_guid>-<uid>" */
        const char *(*get_attachment_path_suffix)(struct dbox_file *file);
        /* mark the mailbox corrupted */
-       void (*set_mailbox_corrupted)(struct mailbox *box);
+       void (*set_mailbox_corrupted)(struct mailbox *box, const char *reason);
        /* mark the file corrupted */
        void (*set_file_corrupted)(struct dbox_file *file, const char *reason);
 };
index 283ef7a29a0137658e49ccfef996e9a7fc054bfa..ff332fd49480c22a488e2224cbc861b53a68d836 100644 (file)
@@ -373,10 +373,11 @@ mdbox_get_attachment_path_suffix(struct dbox_file *file ATTR_UNUSED)
        return "";
 }
 
-void mdbox_set_mailbox_corrupted(struct mailbox *box)
+void mdbox_set_mailbox_corrupted(struct mailbox *box, const char *reason)
 {
        struct mdbox_storage *mstorage = MDBOX_STORAGE(box->storage);
 
+       mailbox_set_critical(box, "%s", reason);
        mdbox_storage_set_corrupted(mstorage);
 }
 
index 86cf407fbd752ea652965f13ecc094dd7d0cb29e..21e19cb3196097c3009e87557a3679b850a29094 100644 (file)
@@ -112,7 +112,7 @@ void mdbox_storage_destroy(struct mail_storage *_storage);
 int mdbox_mailbox_open(struct mailbox *box);
 
 void mdbox_storage_set_corrupted(struct mdbox_storage *storage);
-void mdbox_set_mailbox_corrupted(struct mailbox *box);
+void mdbox_set_mailbox_corrupted(struct mailbox *box, const char *reason);
 void mdbox_set_file_corrupted(struct dbox_file *file, const char *reason);
 
 #endif
index fed111a77fee88e6e81ba987e4dfa363f177ca87..985e6d1dcc225636ff5a11cc9dab3c3e588ce25c 100644 (file)
@@ -163,9 +163,8 @@ int sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid)
        new_path = t_strdup_printf("%s/%s", dir, new_fname);
 
        if (stat(new_path, &st) == 0) {
-               mailbox_set_critical(&file->mbox->box,
-                       "sdbox: %s already exists, rebuilding index", new_path);
-               sdbox_set_mailbox_corrupted(&file->mbox->box);
+               sdbox_set_mailbox_corrupted(&file->mbox->box, t_strdup_printf(
+                       "%s already exists, rebuilding index", new_path));
                return -1;
        }
        if (rename(old_path, new_path) < 0) {
index 3b0352ca99b4d0e38ab5a6b0a2507f647c42e96d..cf6293df408d86d0a0191e7404c381060820d854 100644 (file)
@@ -21,8 +21,8 @@ static void sdbox_mail_set_expunged(struct dbox_mail *mail)
                return;
        }
 
-       mail_set_critical(_mail, "dbox: Unexpectedly lost uid");
-       sdbox_set_mailbox_corrupted(_mail->box);
+       sdbox_set_mailbox_corrupted(_mail->box, t_strdup_printf(
+               "Unexpectedly lost uid %u", _mail->uid));
 }
 
 static int sdbox_mail_file_set(struct dbox_mail *mail)
@@ -48,9 +48,8 @@ static int sdbox_mail_file_set(struct dbox_mail *mail)
                /* it doesn't have input stream yet */
                ret = dbox_file_open(mail->open_file, &deleted);
                if (ret <= 0) {
-                       mail_set_critical(_mail,
-                               "dbox: Unexpectedly lost mail being saved");
-                       sdbox_set_mailbox_corrupted(_mail->box);
+                       sdbox_set_mailbox_corrupted(_mail->box,
+                               "Unexpectedly lost mail being saved");
                        return -1;
                }
                return 1;
index f1663d7628d6441dc180581688ce645f413de4a3..ab07652e6c75d3d58a5ca2578231e3807c635823 100644 (file)
@@ -292,12 +292,13 @@ sdbox_get_attachment_path_suffix(struct dbox_file *_file)
                        file->uid);
 }
 
-void sdbox_set_mailbox_corrupted(struct mailbox *box)
+void sdbox_set_mailbox_corrupted(struct mailbox *box, const char *reason)
 {
        struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        struct sdbox_index_header hdr;
        bool need_resize;
 
+       mailbox_set_critical(box, "%s", reason);
        if (sdbox_read_header(mbox, &hdr, TRUE, &need_resize) < 0 ||
            hdr.rebuild_count == 0)
                mbox->corrupted_rebuild_count = 1;
@@ -310,8 +311,7 @@ static void sdbox_set_file_corrupted(struct dbox_file *_file,
 {
        struct sdbox_file *file = (struct sdbox_file *)_file;
 
-       mail_storage_set_critical(&_file->storage->storage, "%s", reason);
-       sdbox_set_mailbox_corrupted(&file->mbox->box);
+       sdbox_set_mailbox_corrupted(&file->mbox->box, reason);
 }
 
 static int sdbox_mailbox_alloc_index(struct sdbox_mailbox *mbox)
index 66d08daedc7e36b58ed55c100489326171b4b14a..385d33344995efbf7e8e9ed0de530d3cc3eff147 100644 (file)
@@ -47,7 +47,7 @@ int sdbox_read_header(struct sdbox_mailbox *mbox,
 int sdbox_mailbox_create_indexes(struct mailbox *box,
                                 const struct mailbox_update *update,
                                 struct mail_index_transaction *trans);
-void sdbox_set_mailbox_corrupted(struct mailbox *box);
+void sdbox_set_mailbox_corrupted(struct mailbox *box, const char *reason);
 
 struct mail_save_context *
 sdbox_save_alloc(struct mailbox_transaction_context *_t);
index 2698ea95465ba76f9291709b2168502231ffa0d3..32c1823fad67e54ac786e8e0f960cc2f79106797 100644 (file)
@@ -116,9 +116,8 @@ static int sdbox_sync_index(struct sdbox_sync_context *ctx)
                                return -1;
                        return 1;
                }
-               mailbox_set_critical(box,
+               sdbox_set_mailbox_corrupted(box,
                        "sdbox: Broken index: missing UIDVALIDITY");
-               sdbox_set_mailbox_corrupted(box);
                return 0;
        }
 
@@ -220,8 +219,10 @@ int sdbox_sync_begin(struct sdbox_mailbox *mbox, enum sdbox_sync_flags flags,
                ret = index_storage_expunged_sync_begin(&mbox->box,
                                &ctx->index_sync_ctx, &ctx->sync_view,
                                &ctx->trans, sync_flags);
-               if (mail_index_reset_fscked(mbox->box.index))
-                       sdbox_set_mailbox_corrupted(&mbox->box);
+               if (mail_index_reset_fscked(mbox->box.index)) {
+                       sdbox_set_mailbox_corrupted(&mbox->box,
+                               "Mailbox index was fsck'd");
+               }
                if (ret <= 0) {
                        array_free(&ctx->expunged_uids);
                        i_free(ctx);
@@ -314,7 +315,7 @@ sdbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
        int ret = 0;
 
        if (mail_index_reset_fscked(box->index))
-               sdbox_set_mailbox_corrupted(box);
+               sdbox_set_mailbox_corrupted(box, "Mailbox index was fsck'd");
        if (index_mailbox_want_full_sync(&mbox->box, flags) ||
            mbox->corrupted_rebuild_count != 0) {
                if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0)