Skip to content

Commit

Permalink
lib-storage: Add mail_storage.event and use it wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and cmouse committed Aug 7, 2018
1 parent b689d71 commit da5f06d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib-storage/index/dbox-multi/mdbox-map.c
Expand Up @@ -59,7 +59,7 @@ 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(storage->storage.storage.user->event,
map->index = mail_index_alloc(storage->storage.storage.event,
map->index_path,
MDBOX_GLOBAL_INDEX_PREFIX);
mail_index_set_fsync_mode(map->index,
Expand Down
2 changes: 1 addition & 1 deletion src/lib-storage/index/index-rebuild.c
Expand Up @@ -214,7 +214,7 @@ 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(box->storage->user->event,
ctx->backup_index = mail_index_alloc(box->storage->event,
index_dir, backup_path);

#ifndef MMAP_CONFLICTS_WRITE
Expand Down
4 changes: 2 additions & 2 deletions src/lib-storage/index/index-storage.c
Expand Up @@ -161,7 +161,7 @@ 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(box->storage->user->event,
*index_r = mail_index_alloc_cache_get(box->storage->event,
mailbox_path, index_dir,
box->index_prefix);
return 0;
Expand Down Expand Up @@ -379,7 +379,7 @@ void index_storage_mailbox_alloc(struct mailbox *box, const char *vname,
mailbox_list_get_storage_name(box->list, vname));
box->flags = flags;
box->index_prefix = p_strdup(box->pool, index_prefix);
box->event = event_create(box->storage->user->event);
box->event = event_create(box->storage->event);
event_add_category(box->event, &event_category_mailbox);
event_add_str(box->event, "name", box->vname);
event_set_append_log_prefix(box->event,
Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/mail-storage-private.h
Expand Up @@ -160,6 +160,7 @@ struct mail_storage {
char *error_string;
enum mail_error error;
ARRAY(struct mail_storage_error) error_stack;
struct event *event;

const struct mail_storage *storage_class;
struct mail_user *user;
Expand Down
6 changes: 4 additions & 2 deletions src/lib-storage/mail-storage.c
Expand Up @@ -421,6 +421,7 @@ int mail_storage_create_full(struct mail_namespace *ns, const char *driver,
storage->user = ns->user;
storage->set = ns->mail_set;
storage->flags = flags;
storage->event = event_create(ns->user->event);
p_array_init(&storage->module_contexts, storage->pool, 5);

if (storage->v.create != NULL &&
Expand Down Expand Up @@ -480,6 +481,7 @@ void mail_storage_unref(struct mail_storage **_storage)
i_assert(array_count(&storage->error_stack) == 0);
array_free(&storage->error_stack);
}
event_unref(&storage->event);

*_storage = NULL;
pool_unref(&storage->pool);
Expand Down Expand Up @@ -559,7 +561,7 @@ void mail_storage_set_critical(struct mail_storage *storage,
storage->last_internal_error = i_strdup_vprintf(fmt, va);
va_end(va);
storage->last_error_is_internal = TRUE;
e_error(storage->user->event, "%s", storage->last_internal_error);
e_error(storage->event, "%s", storage->last_internal_error);

/* free the old_error and old_internal_error only after the new error
is generated, because they may be one of the parameters. */
Expand Down Expand Up @@ -1378,7 +1380,7 @@ 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(box->storage->user->event,
box->index_pvt = mail_index_alloc_cache_get(box->storage->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);
Expand Down
2 changes: 2 additions & 0 deletions src/lib-storage/test-mail-storage.c
Expand Up @@ -9,6 +9,7 @@ static void test_init_storage(struct mail_storage *storage_r)
i_zero(storage_r);
storage_r->user = t_new(struct mail_user, 1);
storage_r->user->event = event_create(NULL);
storage_r->event = event_create(storage_r->user->event);
}

static void test_deinit_storage(struct mail_storage *storage)
Expand All @@ -19,6 +20,7 @@ static void test_deinit_storage(struct mail_storage *storage)
i_assert(array_count(&storage->error_stack) == 0);
array_free(&storage->error_stack);
}
event_unref(&storage->event);
event_unref(&storage->user->event);
}

Expand Down

0 comments on commit da5f06d

Please sign in to comment.