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[])
}
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;
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++;
/* 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);
struct mail_index {
char *dir, *prefix;
char *cache_dir;
+ struct event *event;
struct mail_cache *cache;
struct mail_transaction_log *log;
};
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,
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 = {
},
};
-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;
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);
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);
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. */
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);
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);
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);
/* 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)
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;
}
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;
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,
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