]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: index/dbox-multi - Replace i_<log>() with e_<log>()
authorMarco Bettini <marco.bettini@open-xchange.com>
Thu, 7 Jul 2022 08:01:09 +0000 (08:01 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Thu, 4 Aug 2022 12:05:27 +0000 (12:05 +0000)
src/lib-storage/index/dbox-multi/mdbox-file.c
src/lib-storage/index/dbox-multi/mdbox-map-private.h
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-purge.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-storage.c

index 65138bd42175d02509191a3176a3675c464d2cd2..6411dd4dea2635e54f410c7a71a67b62c455b037 100644 (file)
@@ -102,6 +102,7 @@ mdbox_file_init_paths(struct mdbox_file *file, const char *fname, bool alt)
 static int mdbox_file_create(struct mdbox_file *file)
 {
        struct dbox_file *_file = &file->file;
+       struct event *event = _file->storage->storage.event;
        bool create_parents;
        int ret;
 
@@ -121,7 +122,7 @@ static int mdbox_file_create(struct mdbox_file *file)
                                /* ignore */
                                break;
                        default:
-                               i_error("file_preallocate(%s) failed: %m",
+                               e_error(event, "file_preallocate(%s) failed: %m",
                                        _file->cur_path);
                                break;
                        }
index 259d85484461dc0e1fd071f6003275a595d886fe..bca38d5af752e88ceb41edf40b84fde6ded034bf 100644 (file)
@@ -11,6 +11,7 @@ struct dbox_mail_lookup_rec {
 
 struct mdbox_map {
        struct mdbox_storage *storage;
+       struct event *event;
        const struct mdbox_settings *set;
        char *path, *index_path;
 
index 67d20831a81cd5171fbfe9ed815a871ec53e12c0..978223e64d45cd8de71869b6da0330d7edbb6ae9 100644 (file)
@@ -71,6 +71,12 @@ mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list)
                                sizeof(uint32_t));
        map->ref_ext_id = mail_index_ext_register(map->index, "ref", 0,
                                sizeof(uint16_t), sizeof(uint16_t));
+
+       map->event = event_create(storage->storage.storage.event);
+       event_drop_parent_log_prefixes(map->event, 1);
+       event_set_append_log_prefix(map->event, t_strdup_printf(
+               "mdbox(%s): ", map->path));
+
        return map;
 }
 
@@ -85,6 +91,7 @@ void mdbox_map_deinit(struct mdbox_map **_map)
                mail_index_close(map->index);
        }
        mail_index_free(&map->index);
+       event_unref(&map->event);
        i_free(map->index_path);
        i_free(map->path);
        i_free(map);
@@ -477,6 +484,7 @@ 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;
@@ -484,9 +492,9 @@ 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 "
+               e_warning(event, "Inconsistency in map index "
                          "(%u,%"PRIuUOFF_T" != %u,%"PRIuUOFF_T")",
-                         map->path, seq1, offset1, seq2, offset2);
+                         seq1, offset1, seq2, offset2);
                mdbox_storage_set_corrupted(map->storage);
        }
        while (mail_index_sync_next(sync_ctx, &sync_rec)) ;
@@ -844,6 +852,7 @@ mdbox_map_file_try_append(struct mdbox_map_append_context *ctx,
 {
        struct mdbox_map *map = ctx->map;
        struct mdbox_storage *storage = map->storage;
+       struct event *event = map->event;
        struct dbox_file *file;
        struct dbox_file_append_context *file_append;
        struct stat st;
@@ -867,7 +876,7 @@ mdbox_map_file_try_append(struct mdbox_map_append_context *ctx,
                *retry_later_r = ret == 0;
        } else if (stat(file->cur_path, &st) < 0) {
                if (errno != ENOENT)
-                       i_error("stat(%s) failed: %m", file->cur_path);
+                       e_error(event, "stat(%s) failed: %m", file->cur_path);
                /* the file was unlinked between opening and locking it. */
        } else if (st.st_size != rec->offset + rec->size &&
                   /* check if there's any garbage at the end of file.
@@ -1187,6 +1196,7 @@ void mdbox_map_append_abort(struct mdbox_map_append_context *ctx)
 static int
 mdbox_find_highest_file_id(struct mdbox_map *map, uint32_t *file_id_r)
 {
+       struct event *event = map->event;
        const size_t prefix_len = strlen(MDBOX_MAIL_FILE_PREFIX);
        DIR *dir;
        struct dirent *d;
@@ -1194,7 +1204,7 @@ mdbox_find_highest_file_id(struct mdbox_map *map, uint32_t *file_id_r)
 
        dir = opendir(map->path);
        if (dir == NULL) {
-               i_error("opendir(%s) failed: %m", map->path);
+               e_error(event, "opendir(%s) failed: %m", map->path);
                return -1;
        }
        while ((d = readdir(dir)) != NULL) {
index 60508e315ac912618b195dbb8e39149fc9fbe35b..1eca969677717283ea09ba00a8128e0b01a175aa 100644 (file)
@@ -130,6 +130,7 @@ static int
 mdbox_metadata_get_extrefs(struct dbox_file *file, pool_t ext_refs_pool,
                           ARRAY_TYPE(mail_attachment_extref) *extrefs)
 {
+       struct event *event = file->storage->storage.event;
        struct dbox_metadata_header meta_hdr;
        const char *line;
        size_t buf_size;
@@ -150,7 +151,7 @@ mdbox_metadata_get_extrefs(struct dbox_file *file, pool_t ext_refs_pool,
                if (*line == DBOX_METADATA_EXT_REF) T_BEGIN {
                        if (!index_attachment_parse_extrefs(line+1, ext_refs_pool,
                                                            extrefs)) {
-                               i_warning("%s: Ignoring corrupted extref: %s",
+                               e_warning(event, "%s: Ignoring corrupted extref: %s",
                                          file->cur_path, line);
                        }
                } T_END;
index b4ebbdd77b5a9b2c5c35e06ad3423ad1d09b0c85..3db6be2ff7ce53438f0baa4500d9811ba40fe663 100644 (file)
@@ -142,6 +142,7 @@ static void rebuild_scan_metadata(struct mdbox_storage_rebuild_context *ctx,
 static int rebuild_file_mails(struct mdbox_storage_rebuild_context *ctx,
                              struct dbox_file *file, uint32_t file_id)
 {
+       struct event *event = file->storage->storage.event;
        const char *guid;
        uint8_t *guid_p;
        struct mdbox_rebuild_msg *rec, *old_rec;
@@ -217,12 +218,12 @@ static int rebuild_file_mails(struct mdbox_storage_rebuild_context *ctx,
                        rec->seen_zero_ref_in_map = TRUE;
                } else {
                        /* duplicate GUID, but not a duplicate message. */
-                       i_error("mdbox %s: Duplicate GUID %s in "
+                       e_error(event, "Duplicate GUID %s in "
                                "m.%u:%u (size=%"PRIuUOFF_T") and m.%u:%u "
                                "(size=%"PRIuUOFF_T")",
-                               ctx->storage->storage_dir, guid,
-                               old_rec->file_id, old_rec->offset, old_rec->mail_size,
-                               rec->file_id, rec->offset, rec->mail_size);
+                               guid, old_rec->file_id, old_rec->offset,
+                               old_rec->mail_size, rec->file_id, rec->offset,
+                               rec->mail_size);
                        rec->guid_hash_next = old_rec->guid_hash_next;
                        old_rec->guid_hash_next = rec;
                }
@@ -239,6 +240,7 @@ static int
 rebuild_rename_file(struct mdbox_storage_rebuild_context *ctx,
                    const char *dir, const char **fname_p, uint32_t *file_id_r)
 {
+       struct event *event = ctx->storage->storage.storage.event;
        const char *old_path, *new_path, *fname = *fname_p;
 
        old_path = t_strconcat(dir, "/", fname, NULL);
@@ -255,13 +257,14 @@ rebuild_rename_file(struct mdbox_storage_rebuild_context *ctx,
                }
        } while (errno == EEXIST);
 
-       i_error("link(%s, %s) failed: %m", old_path, new_path);
+       e_error(event, "link(%s, %s) failed: %m", old_path, new_path);
        return -1;
 }
 
 static int rebuild_add_file(struct mdbox_storage_rebuild_context *ctx,
                            const char *dir, const char *fname)
 {
+       struct event *event = ctx->storage->storage.storage.event;
        struct dbox_file *file;
        uint32_t file_id;
        const char *id_str, *ext;
@@ -275,8 +278,8 @@ static int rebuild_add_file(struct mdbox_storage_rebuild_context *ctx,
                ext = strrchr(id_str, '.');
                if (ext == NULL || (strcmp(ext, ".broken") != 0 &&
                                    strcmp(ext, ".lock") != 0)) {
-                       i_warning("mdbox rebuild: "
-                                 "Skipping file with missing ID: %s/%s",
+                       e_warning(event,
+                                 "rebuild: Skipping file with missing ID: %s/%s",
                                  dir, fname);
                }
                return 0;
@@ -298,7 +301,7 @@ static int rebuild_add_file(struct mdbox_storage_rebuild_context *ctx,
        if ((ret = dbox_file_open(file, &deleted)) > 0 && !deleted)
                ret = rebuild_file_mails(ctx, file, file_id);
        if (ret == 0)
-               i_error("mdbox rebuild: Failed to fix file %s/%s", dir, fname);
+               e_error(event, "rebuild: Failed to fix file %s/%s", dir, fname);
        dbox_file_unref(&file);
        return ret < 0 ? -1 : 0;
 }
@@ -563,8 +566,8 @@ rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx,
        }
        if (mailbox_open(box) < 0) {
                error = mailbox_get_last_mail_error(box);
-               i_error("Couldn't open mailbox '%s': %s",
-                       vname, mailbox_get_last_internal_error(box, NULL));
+               e_error(box->event, "Couldn't open mailbox: %s",
+                       mailbox_get_last_internal_error(box, NULL));
                mailbox_free(&box);
                if (error == MAIL_ERROR_TEMP)
                        return -1;
@@ -941,7 +944,8 @@ mdbox_storage_rebuild_scan_prepare(struct mdbox_storage_rebuild_context *ctx)
 
 static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx)
 {
-       i_warning("mdbox %s: rebuilding indexes", ctx->storage->storage_dir);
+       struct event *event = ctx->storage->storage.storage.event;
+       e_warning(event, "rebuilding indexes");
 
        if (mdbox_storage_rebuild_scan_dir(ctx, ctx->storage->storage_dir,
                                           FALSE) < 0)
index 02bca0cca5fbf5666d6fbc4ad0472fc276352681..b7fc6b3c17d64bd918a9737a6dec70497d9903be 100644 (file)
@@ -64,6 +64,10 @@ int mdbox_storage_create(struct mail_storage *_storage,
                                                        ns->list->set.alt_dir,
                                                        "/"MDBOX_GLOBAL_DIR_NAME, NULL);
        }
+
+       event_set_append_log_prefix(_storage->event, t_strdup_printf(
+               "mdbox(%s): ", storage->storage_dir));
+
        i_array_init(&storage->open_files, 64);
 
        storage->map = mdbox_map_init(storage, ns->list);
@@ -89,19 +93,19 @@ void mdbox_storage_destroy(struct mail_storage *_storage)
 static const char *
 mdbox_storage_find_root_dir(const struct mail_namespace *ns)
 {
-       bool debug = ns->mail_set->mail_debug;
+       struct event *event = ns->user->event;
        const char *home, *path;
 
        if (ns->owner != NULL &&
            mail_user_get_home(ns->owner, &home) > 0) {
                path = t_strconcat(home, "/mdbox", NULL);
                if (access(path, R_OK|W_OK|X_OK) == 0) {
-                       if (debug)
-                               i_debug("mdbox: root exists (%s)", path);
+                       e_debug(event,
+                               "mdbox autodetect: root exists (%s)", path);
                        return path;
                }
-               if (debug)
-                       i_debug("mdbox: access(%s, rwx): failed: %m", path);
+               e_debug(event,
+                       "mdbox autodetect: access(%s, rwx): failed: %m", path);
        }
        return NULL;
 }
@@ -109,7 +113,7 @@ mdbox_storage_find_root_dir(const struct mail_namespace *ns)
 static bool mdbox_storage_autodetect(const struct mail_namespace *ns,
                                     struct mailbox_list_settings *set)
 {
-       bool debug = ns->mail_set->mail_debug;
+       struct event *event = ns->user->event;
        struct stat st;
        const char *path, *root_dir;
 
@@ -118,22 +122,20 @@ static bool mdbox_storage_autodetect(const struct mail_namespace *ns,
        else {
                root_dir = mdbox_storage_find_root_dir(ns);
                if (root_dir == NULL) {
-                       if (debug)
-                               i_debug("mdbox: couldn't find root dir");
+                       e_debug(event,
+                               "mdbox autodetect: couldn't find root dir");
                        return FALSE;
                }
        }
 
        path = t_strconcat(root_dir, "/"MDBOX_GLOBAL_DIR_NAME, NULL);
        if (stat(path, &st) < 0) {
-               if (debug)
-                       i_debug("mdbox autodetect: stat(%s) failed: %m", path);
+               e_debug(event, "mdbox autodetect: stat(%s) failed: %m", path);
                return FALSE;
        }
 
        if (!S_ISDIR(st.st_mode)) {
-               if (debug)
-                       i_debug("mdbox autodetect: %s not a directory", path);
+               e_debug(event, "mdbox autodetect: %s not a directory", path);
                return FALSE;
        }