From: Timo Sirainen Date: Mon, 3 Jul 2023 10:57:59 +0000 (+0300) Subject: mdbox: mdbox_storage_set_corrupted() - Add reason parameter X-Git-Tag: 2.4.0~2466 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b151dc7c234880005dbe6e81383e61e5eec2756e;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 6411dd4dea..a620717b79 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-file.c +++ b/src/lib-storage/index/dbox-multi/mdbox-file.c @@ -201,9 +201,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 ded89bd686..b161970a14 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -32,13 +32,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 * @@ -227,8 +224,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; } @@ -475,7 +474,6 @@ static void mdbox_map_sync_handle(struct mdbox_map *map, struct mail_index_sync_ctx *sync_ctx) { - struct event *event = map->event; struct mail_index_sync_rec sync_rec; uint32_t seq1, seq2; uoff_t offset1, offset2; @@ -483,10 +481,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. */ - e_warning(event, "Inconsistency in map index " - "(%u,%"PRIuUOFF_T" != %u,%"PRIuUOFF_T")", - 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)) ; } @@ -507,8 +505,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 90f184bb16..5e945cadf1 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -352,14 +352,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 && @@ -379,16 +388,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 a04cc145b9..67c2d86490 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.h +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h @@ -112,7 +112,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);