From: Timo Sirainen Date: Mon, 3 Jul 2023 10:57:59 +0000 (+0300) Subject: mdbox: mdbox_storage_set_corrupted() - Add reason parameter X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23b69f05885e0351ffcd9f0ef9188d23803e2719;p=thirdparty%2Fdovecot%2Fcore.git mdbox: mdbox_storage_set_corrupted() - Add reason parameter --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-file.c b/src/lib-storage/index/dbox-multi/mdbox-file.c index 65138bd421..1cc9521a1f 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-file.c +++ b/src/lib-storage/index/dbox-multi/mdbox-file.c @@ -200,9 +200,8 @@ int mdbox_file_assign_file_id(struct mdbox_file *file, uint32_t file_id) new_path = t_strdup_printf("%s/%s", new_dir, new_fname); if (stat(new_path, &st) == 0) { - mail_storage_set_critical(&file->file.storage->storage, - "mdbox: %s already exists, rebuilding index", new_path); - mdbox_storage_set_corrupted(file->storage); + mdbox_storage_set_corrupted(file->storage, + "%s already exists, rebuilding index", new_path); return -1; } if (rename(old_path, new_path) < 0) { diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.c b/src/lib-storage/index/dbox-multi/mdbox-map.c index f9bac0b970..c5d1e5955c 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -35,13 +35,10 @@ void mdbox_map_set_corrupted(struct mdbox_map *map, const char *format, ...) va_list args; va_start(args, format); - mail_storage_set_critical(MAP_STORAGE(map), - "mdbox map %s corrupted: %s", - map->index->filepath, - t_strdup_vprintf(format, args)); + mdbox_storage_set_corrupted(map->storage, "map %s corrupted: %s", + map->index->filepath, + t_strdup_vprintf(format, args)); va_end(args); - - mdbox_storage_set_corrupted(map->storage); } struct mdbox_map * @@ -223,8 +220,10 @@ int mdbox_map_refresh(struct mdbox_map *map) mail_storage_set_index_error(MAP_STORAGE(map), map->index); ret = -1; } - if (fscked) - mdbox_storage_set_corrupted(map->storage); + if (fscked) { + mdbox_storage_set_corrupted(map->storage, + "dovecot.index.map was fsck'd (refresh)"); + } return ret; } @@ -477,10 +476,10 @@ mdbox_map_sync_handle(struct mdbox_map *map, mail_index_sync_get_offsets(sync_ctx, &seq1, &offset1, &seq2, &offset2); if (offset1 != offset2 || seq1 != seq2) { /* something had crashed. need a full resync. */ - i_warning("mdbox %s: Inconsistency in map index " - "(%u,%"PRIuUOFF_T" != %u,%"PRIuUOFF_T")", - map->path, seq1, offset1, seq2, offset2); - mdbox_storage_set_corrupted(map->storage); + mdbox_storage_set_corrupted(map->storage, + "Inconsistency in map index " + "(%u,%"PRIuUOFF_T" != %u,%"PRIuUOFF_T")", + seq1, offset1, seq2, offset2); } while (mail_index_sync_next(sync_ctx, &sync_rec)) ; } @@ -501,8 +500,10 @@ int mdbox_map_atomic_lock(struct mdbox_map_atomic_context *atomic, ret = mail_index_sync_begin(atomic->map->index, &atomic->sync_ctx, &atomic->sync_view, &atomic->sync_trans, MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET); - if (mail_index_reset_fscked(atomic->map->index)) - mdbox_storage_set_corrupted(atomic->map->storage); + if (mail_index_reset_fscked(atomic->map->index)) { + mdbox_storage_set_corrupted(atomic->map->storage, + "dovecot.index.map was fsck'd (atomic lock)"); + } if (ret <= 0) { i_assert(ret != 0); mail_storage_set_index_error(MAP_STORAGE(atomic->map), diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index bf6f336a7f..10749ff761 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -348,14 +348,23 @@ int mdbox_mailbox_create_indexes(struct mailbox *box, return ret; } -void mdbox_storage_set_corrupted(struct mdbox_storage *storage) +void mdbox_storage_set_corrupted(struct mdbox_storage *storage, + const char *reason, ...) { + const char *reason_str; + va_list args; + + va_start(args, reason); + reason_str = t_strdup_vprintf(reason, args); + va_end(args); + + mail_storage_set_critical(&storage->storage.storage, "%s", reason_str); if (storage->corrupted_reason != NULL) { /* already set it corrupted (possibly recursing back here) */ return; } - storage->corrupted_reason = i_strdup("Storage marked corrupted"); + storage->corrupted_reason = i_strdup(reason_str); storage->corrupted_rebuild_count = (uint32_t)-1; if (mdbox_map_open(storage->map) > 0 && @@ -375,16 +384,15 @@ 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); + mdbox_storage_set_corrupted(mstorage, "Mailbox %s: %s", + box->vname, reason); } void mdbox_set_file_corrupted(struct dbox_file *file, const char *reason) { struct mdbox_storage *mstorage = MDBOX_DBOX_STORAGE(file->storage); - mail_storage_set_critical(&mstorage->storage.storage, "%s", reason); - mdbox_storage_set_corrupted(mstorage); + mdbox_storage_set_corrupted(mstorage, "%s", reason); } static int diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.h b/src/lib-storage/index/dbox-multi/mdbox-storage.h index 21e19cb319..ce39d53860 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.h +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h @@ -111,7 +111,8 @@ int mdbox_storage_create(struct mail_storage *_storage, 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_storage_set_corrupted(struct mdbox_storage *storage, + const char *reason, ...) ATTR_FORMAT(2, 3); void mdbox_set_mailbox_corrupted(struct mailbox *box, const char *reason); void mdbox_set_file_corrupted(struct dbox_file *file, const char *reason);