]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: mdbox_storage_set_corrupted() - Add reason parameter
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 3 Jul 2023 10:57:59 +0000 (13:57 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 31 Jan 2024 11:45:51 +0000 (13:45 +0200)
src/lib-storage/index/dbox-multi/mdbox-file.c
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage.h

index 65138bd42175d02509191a3176a3675c464d2cd2..1cc9521a1fa330fe04e284a4023b83193a8dae26 100644 (file)
@@ -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) {
index f9bac0b9705bb3ca1e5531fa99c231ac4a0bc6c3..c5d1e5955c3850cd431eb7bbc621c4af6716c457 100644 (file)
@@ -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),
index bf6f336a7fff03c54e2ad4f53dc002c1cfb9c5c8..10749ff761d39aab761080d6a149e5933cb09e7f 100644 (file)
@@ -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
index 21e19cb3196097c3009e87557a3679b850a29094..ce39d53860341245628a4f1dda5608929023ba05 100644 (file)
@@ -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);