From: Timo Sirainen Date: Mon, 3 Jul 2023 10:45:28 +0000 (+0300) Subject: dbox: Add reason parameter to dbox_storage_vfuncs.set_mailbox_corrupted() X-Git-Tag: 2.4.0~2469 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebd2b7be612d3e7cf9ff6223909dc31b4f394f5b;p=thirdparty%2Fdovecot%2Fcore.git dbox: Add reason parameter to dbox_storage_vfuncs.set_mailbox_corrupted() --- diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index 3acaac46b5..dfb70df7f2 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -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 */ diff --git a/src/lib-storage/index/dbox-common/dbox-storage.h b/src/lib-storage/index/dbox-common/dbox-storage.h index dbdeff91c8..dc67dd25c5 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.h +++ b/src/lib-storage/index/dbox-common/dbox-storage.h @@ -50,7 +50,7 @@ struct dbox_storage_vfuncs { "--" */ 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); }; diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index 0864e14dd4..9d8ccf4b23 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -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); } diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.h b/src/lib-storage/index/dbox-multi/mdbox-storage.h index 383e61c14a..a04cc145b9 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.h +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h @@ -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 diff --git a/src/lib-storage/index/dbox-single/sdbox-file.c b/src/lib-storage/index/dbox-single/sdbox-file.c index 0237ae3df8..b436b47b2a 100644 --- a/src/lib-storage/index/dbox-single/sdbox-file.c +++ b/src/lib-storage/index/dbox-single/sdbox-file.c @@ -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) { diff --git a/src/lib-storage/index/dbox-single/sdbox-mail.c b/src/lib-storage/index/dbox-single/sdbox-mail.c index 82b4d493d0..835088a1f4 100644 --- a/src/lib-storage/index/dbox-single/sdbox-mail.c +++ b/src/lib-storage/index/dbox-single/sdbox-mail.c @@ -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; diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index b9db237647..9d70aa713d 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -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; diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.h b/src/lib-storage/index/dbox-single/sdbox-storage.h index 020d8a3ce0..3c25f620e9 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.h +++ b/src/lib-storage/index/dbox-single/sdbox-storage.h @@ -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); diff --git a/src/lib-storage/index/dbox-single/sdbox-sync.c b/src/lib-storage/index/dbox-single/sdbox-sync.c index 12df5261a2..70f0ca7cce 100644 --- a/src/lib-storage/index/dbox-single/sdbox-sync.c +++ b/src/lib-storage/index/dbox-single/sdbox-sync.c @@ -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)