]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index.event
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Nov 2017 12:13:40 +0000 (13:13 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 13 Dec 2017 11:22:17 +0000 (13:22 +0200)
14 files changed:
src/doveadm/doveadm-dump-index.c
src/lib-index/mail-index-alloc-cache.c
src/lib-index/mail-index-alloc-cache.h
src/lib-index/mail-index-private.h
src/lib-index/mail-index.c
src/lib-index/mail-index.h
src/lib-index/test-mail-index-modseq.c
src/lib-index/test-mail-transaction-log-file.c
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/index-rebuild.c
src/lib-storage/index/index-storage.c
src/lib-storage/list/mailbox-list-index.c
src/lib-storage/mail-storage.c
src/lib-storage/test-mail-search-args-simplify.c

index 4a1833aa933187f7a70d0d7ecc41c8da4ec4752e..d42f9f585153de14a03c33ac5fc024977873e7f1 100644 (file)
@@ -727,15 +727,15 @@ static struct mail_index *path_open_index(const char *path)
 
        if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
                if (dir_has_index(path, "dovecot.index"))
-                       return mail_index_alloc(path, "dovecot.index");
+                       return mail_index_alloc(NULL, path, "dovecot.index");
                else if (dir_has_index(path, "dovecot.map.index"))
-                       return mail_index_alloc(path, "dovecot.map.index");
+                       return mail_index_alloc(NULL, path, "dovecot.map.index");
                else
                        return NULL;
        } else if ((p = strrchr(path, '/')) != NULL)
-               return mail_index_alloc(t_strdup_until(path, p), p + 1);
+               return mail_index_alloc(NULL, t_strdup_until(path, p), p + 1);
        else
-               return mail_index_alloc(".", path);
+               return mail_index_alloc(NULL, ".", path);
 }
 
 static void cmd_dump_index(int argc ATTR_UNUSED, char *argv[])
index 3b75801ac77eceb73bfa25472269e8b1ffc08065..c97e8a95fc920ddd114d88569f0210b8b8485d0d 100644 (file)
@@ -134,7 +134,7 @@ mail_index_alloc_cache_find(const char *mailbox_path, const char *index_dir,
 }
 
 struct mail_index *
-mail_index_alloc_cache_get(const char *mailbox_path,
+mail_index_alloc_cache_get(struct event *parent_event, const char *mailbox_path,
                           const char *index_dir, const char *prefix)
 {
        struct mail_index_alloc_cache_list *match;
@@ -158,7 +158,8 @@ mail_index_alloc_cache_get(const char *mailbox_path,
 
        match = mail_index_alloc_cache_find(mailbox_path, index_dir, &st);
        if (match == NULL) {
-               struct mail_index *index = mail_index_alloc(index_dir, prefix);
+               struct mail_index *index =
+                       mail_index_alloc(parent_event, index_dir, prefix);
                match = mail_index_alloc_cache_add(index, mailbox_path, &st);
        } else {
                match->refcount++;
index 888b3096f80b06466a27fdebf5eec9e401a00611..eadfc30f03d82b2bc7781edea6bfa25e7c325a3e 100644 (file)
@@ -3,7 +3,7 @@
 
 /* If using in-memory indexes, give index_dir=NULL. */
 struct mail_index * ATTR_NULL(1, 2)
-mail_index_alloc_cache_get(const char *mailbox_path,
+mail_index_alloc_cache_get(struct event *parent_event, const char *mailbox_path,
                           const char *index_dir, const char *prefix);
 void mail_index_alloc_cache_unref(struct mail_index **index);
 
index 63ed2a8e35ec29be707840e25280f88b3a76abf4..b1a94a82c5bea52cc7317cd308f8137dffea091d 100644 (file)
@@ -155,6 +155,7 @@ union mail_index_module_context {
 struct mail_index {
        char *dir, *prefix;
        char *cache_dir;
+       struct event *event;
 
        struct mail_cache *cache;
        struct mail_transaction_log *log;
@@ -235,6 +236,7 @@ struct mail_index {
 };
 
 extern struct mail_index_module_register mail_index_module_register;
+extern struct event_category event_category_index;
 
 /* Add/replace sync handler for specified extra record. */
 void mail_index_register_expunge_handler(struct mail_index *index,
index 468f7087f1fec415e11642a9a84401a0ac8d38b3..55821f4d97500ba67ba98cc2582a063c70649abb 100644 (file)
 
 struct mail_index_module_register mail_index_module_register = { 0 };
 
+struct event_category event_category_index = {
+       .name = "index",
+};
+
 static void mail_index_close_nonopened(struct mail_index *index);
 
 static const struct mail_index_optimization_settings default_optimization_set = {
@@ -50,7 +54,8 @@ static const struct mail_index_optimization_settings default_optimization_set =
        },
 };
 
-struct mail_index *mail_index_alloc(const char *dir, const char *prefix)
+struct mail_index *mail_index_alloc(struct event *parent_event,
+                                   const char *dir, const char *prefix)
 {
        struct mail_index *index;
 
@@ -58,6 +63,8 @@ struct mail_index *mail_index_alloc(const char *dir, const char *prefix)
        index->dir = i_strdup(dir);
        index->prefix = i_strdup(prefix);
        index->fd = -1;
+       index->event = event_create(parent_event);
+       event_add_category(index->event, &event_category_index);
 
        index->extension_pool =
                pool_alloconly_create(MEMPOOL_GROWING"index extension", 1024);
@@ -101,6 +108,7 @@ void mail_index_free(struct mail_index **_index)
        array_free(&index->keywords);
        array_free(&index->module_contexts);
 
+       event_unref(&index->event);
        i_free(index->cache_dir);
        i_free(index->ext_hdr_init_data);
        i_free(index->gid_origin);
index e8348b0197ef3ea0d881447d022e55efd286bceb..6ced7e7ced69b3c7114bd59b8d0bf37cb46e808b 100644 (file)
@@ -288,7 +288,8 @@ struct mail_index_transaction;
 struct mail_index_sync_ctx;
 struct mail_index_view_sync_ctx;
 
-struct mail_index *mail_index_alloc(const char *dir, const char *prefix);
+struct mail_index *mail_index_alloc(struct event *parent_event,
+                                   const char *dir, const char *prefix);
 void mail_index_free(struct mail_index **index);
 
 /* Change .cache file's directory. */
index 5c1f7d2e139212a385ccec7aaf26118f971136d8..a140c3778f569fffda646d8da6f60878a9c8f9a1 100644 (file)
@@ -38,7 +38,7 @@ static void test_mail_index_modseq_get_next_log_offset(void)
        ioloop_time = 1;
 
        test_begin("mail_transaction_log_file_get_modseq_next_offset()");
-       index = mail_index_alloc(TESTDIR_NAME, "test.dovecot.index");
+       index = mail_index_alloc(NULL, TESTDIR_NAME, "test.dovecot.index");
        test_assert(mail_index_open_or_create(index, MAIL_INDEX_OPEN_FLAG_CREATE) == 0);
        view = mail_index_view_open(index);
        mail_index_modseq_enable(index);
index 89d4f19c87061370586b1a171d890634e14df070..a215129b6a2e968e7acb7f1fc0d7099d44e7536c 100644 (file)
@@ -243,7 +243,7 @@ static void test_mail_transaction_update_modseq(void)
 
 static struct mail_index *test_mail_index_open(void)
 {
-       struct mail_index *index = mail_index_alloc(NULL, "test.dovecot.index");
+       struct mail_index *index = mail_index_alloc(NULL, NULL, "test.dovecot.index");
        test_assert(mail_index_open_or_create(index, MAIL_INDEX_OPEN_FLAG_CREATE) == 0);
        struct mail_index_view *view = mail_index_view_open(index);
 
index 34b92740b26cf9cae07c5915fc7eb592dc12504e..ee6b293875a7a9f48cb4962d6aa897db749a917f 100644 (file)
@@ -59,7 +59,8 @@ mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list)
        map->path = i_strconcat(root, "/"MDBOX_GLOBAL_DIR_NAME, NULL);
        map->index_path =
                i_strconcat(index_root, "/"MDBOX_GLOBAL_DIR_NAME, NULL);
-       map->index = mail_index_alloc(map->index_path,
+       map->index = mail_index_alloc(storage->storage.storage.user->event,
+                                     map->index_path,
                                      MDBOX_GLOBAL_INDEX_PREFIX);
        mail_index_set_fsync_mode(map->index,
                MAP_STORAGE(map)->set->parsed_fsync_mode, 0);
index ef234eab20bf25149caa97d6fd7670b5b6e6c267..da5ffa428a0cbbe934a598c3723ceece11c80831 100644 (file)
@@ -214,7 +214,8 @@ index_index_rebuild_init(struct mailbox *box, struct mail_index_view *view,
        /* if backup index file exists, try to use it */
        index_dir = mailbox_get_index_path(box);
        backup_path = t_strconcat(box->index_prefix, ".backup", NULL);
-       ctx->backup_index = mail_index_alloc(index_dir, backup_path);
+       ctx->backup_index = mail_index_alloc(box->storage->user->event,
+                                            index_dir, backup_path);
 
 #ifndef MMAP_CONFLICTS_WRITE
        if (box->storage->set->mmap_disable)
index 89cd54dae2d3eba49703d17f2bbfcf430563494f..b4b3c8341933fb2848717314afe49ce0af9aef5b 100644 (file)
@@ -161,7 +161,8 @@ index_mailbox_alloc_index(struct mailbox *box, struct mail_index **index_r)
            mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
                                &index_dir) <= 0)
                index_dir = NULL;
-       *index_r = mail_index_alloc_cache_get(mailbox_path, index_dir,
+       *index_r = mail_index_alloc_cache_get(box->storage->user->event,
+                                             mailbox_path, index_dir,
                                              box->index_prefix);
        return 0;
 }
index 4d9314ea61673fc029adeb61f85131d2b52a5b2c..9b8f4f2c1b04f82081cc16a39423d69ae5f75bf8 100644 (file)
@@ -908,7 +908,8 @@ static void mailbox_list_index_init_finish(struct mailbox_list *list)
        i_assert(list->set.list_index_fname != NULL);
        ilist->path = dir == NULL ? "(in-memory mailbox list index)" :
                p_strdup_printf(list->pool, "%s/%s", dir, list->set.list_index_fname);
-       ilist->index = mail_index_alloc(dir, list->set.list_index_fname);
+       ilist->index = mail_index_alloc(list->ns->user->event,
+                                       dir, list->set.list_index_fname);
        ilist->rebuild_on_missing_inbox =
                (list->ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0;
 
index 2530bb01425c2de65432fc67732b268d1e3dd218..dd399f6aaf501410db7a1dcc614cbce3d3f52d46 100644 (file)
@@ -1384,8 +1384,8 @@ static int mailbox_alloc_index_pvt(struct mailbox *box)
        if (mailbox_create_missing_dir(box, MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE) < 0)
                return -1;
 
-       box->index_pvt = mail_index_alloc_cache_get(NULL, index_dir,
-               t_strconcat(box->index_prefix, ".pvt", NULL));
+       box->index_pvt = mail_index_alloc_cache_get(box->storage->user->event,
+               NULL, index_dir, t_strconcat(box->index_prefix, ".pvt", NULL));
        mail_index_set_fsync_mode(box->index_pvt,
                                  box->storage->set->parsed_fsync_mode, 0);
        mail_index_set_lock_method(box->index_pvt,
index 1b6a3e033d4a41f5bbdc7aac5d906fd7874ae39d..81e05690d548538d07d6cc4135dd4f0dea63d6d5 100644 (file)
@@ -276,7 +276,7 @@ static void test_mail_search_args_simplify(void)
        unsigned int i;
 
        test_begin("mail search args simplify");
-       box.index = mail_index_alloc(NULL, "dovecot.index.");
+       box.index = mail_index_alloc(NULL, NULL, "dovecot.index.");
        for (i = 0; i < N_ELEMENTS(tests); i++) {
                args = test_build_search_args(tests[i].input);
                /* delay simplification until after init. that way we can test