]> 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)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 30 Oct 2023 08:40:13 +0000 (08:40 +0000)
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 6411dd4dea2635e54f410c7a71a67b62c455b037..a620717b79a309faef648429bbe792dad132e2ae 100644 (file)
@@ -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) {
index ded89bd6860a528fd915a10d2d7a686b2e298530..b161970a14071d07ad7fb01c9afb50ab6c20cb0c 100644 (file)
@@ -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),
index 90f184bb16eedebb0a93b190783a2ef43c0533d2..5e945cadf11c1651078f7b1f87ff21a72d864796 100644 (file)
@@ -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
index a04cc145b941570be5a5c5956172fc4798664539..67c2d864902446a9a988fc2aa84481a0ecce1f24 100644 (file)
@@ -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);