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;
/* ignore */
break;
default:
- i_error("file_preallocate(%s) failed: %m",
+ e_error(event, "file_preallocate(%s) failed: %m",
_file->cur_path);
break;
}
struct mdbox_map {
struct mdbox_storage *storage;
+ struct event *event;
const struct mdbox_settings *set;
char *path, *index_path;
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;
}
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);
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;
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)) ;
{
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;
*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.
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;
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) {
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;
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;
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;
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;
}
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);
}
} 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;
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;
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;
}
}
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;
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)
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);
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;
}
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;
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;
}