]> 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)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 30 Oct 2023 08:40:13 +0000 (08:40 +0000)
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 3acaac46b5af86267f46789c0000714aa98429a5..dfb70df7f294a4ab18d602bca3100a29d095b67a 100644 (file)
@@ -398,10 +398,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 dbdeff91c82524ebdeba60381f770fed722ff497..dc67dd25c52bb9105fc64ddc4367e7107e812c7a 100644 (file)
@@ -50,7 +50,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 0864e14dd477b18d990f11ce677de960a5647fed..9d8ccf4b23aa4f4c2091102beeb069aaefdbab80 100644 (file)
@@ -377,10 +377,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 383e61c14ad48e9d3aed4723ecc2e59555f9a658..a04cc145b941570be5a5c5956172fc4798664539 100644 (file)
@@ -113,7 +113,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 0237ae3df8d69dc4589ebcd588cb46c7cb60f325..b436b47b2a2a90dd658ee5c5d3f84be9dff24208 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) {
@@ -267,9 +266,12 @@ int sdbox_file_create_fd(struct dbox_file *file, const char *path, bool parents)
                umask(old_mask);
        }
        if (fd == -1) {
-               mailbox_set_critical(box, "open(%s, O_CREAT) failed: %m", path);
-               if (errno == ENOENT)
-                       sdbox_set_mailbox_corrupted(box);
+               if (errno == ENOENT) {
+                       sdbox_set_mailbox_corrupted(box, t_strdup_printf(
+                               "open(%s, O_CREAT) failed: %m", path));
+               } else {
+                       mailbox_set_critical(box, "open(%s, O_CREAT) failed: %m", path);
+               }
        } else if (perm->file_create_gid == (gid_t)-1) {
                /* no group change */
        } else if (fchown(fd, (uid_t)-1, perm->file_create_gid) < 0) {
index 82b4d493d04163bfc250f6b633df49e57d5e8f7a..835088a1f4fc67b385e5adc143a370e357c4e43b 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));
 }
 
 int sdbox_mail_file_set(struct dbox_mail *mail)
@@ -48,9 +48,8 @@ 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 b9db23764764336509476d3f28ca8b745dc81f0a..9d70aa713d344e74f5bb64f3303c3e7cc1f0b341 100644 (file)
@@ -291,12 +291,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;
index 020d8a3ce0cf3d89abf511ca02579c31d66e3430..3c25f620e9c38404c75157b52ea23ca9d571412e 100644 (file)
@@ -48,7 +48,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 12df5261a28441347af1931e94fe21f4cf36724b..70f0ca7cceb3be59fc9306c662b8368cca228d00 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)