From: Timo Sirainen Date: Thu, 29 Apr 2010 15:53:07 +0000 (+0300) Subject: mdbox: Renamed dbox_map* to mdbox_map*. X-Git-Tag: 2.0.beta5~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c18ff860dc22960fd37c272d929f889c7939a2c8;p=thirdparty%2Fdovecot%2Fcore.git mdbox: Renamed dbox_map* to mdbox_map*. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-file.c b/src/lib-storage/index/dbox-multi/mdbox-file.c index 769f60c6e5..84bee99705 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-file.c +++ b/src/lib-storage/index/dbox-multi/mdbox-file.c @@ -264,7 +264,7 @@ void mdbox_file_unrefed(struct dbox_file *file) int mdbox_file_create_fd(struct dbox_file *file, const char *path, bool parents) { struct mdbox_file *mfile = (struct mdbox_file *)file; - struct dbox_map *map = mfile->storage->map; + struct mdbox_map *map = mfile->storage->map; mode_t old_mask; const char *p, *dir; int fd; diff --git a/src/lib-storage/index/dbox-multi/mdbox-mail.c b/src/lib-storage/index/dbox-multi/mdbox-mail.c index 9048c79cb0..ab37d82332 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-mail.c +++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c @@ -41,10 +41,10 @@ int mdbox_mail_lookup(struct mdbox_mailbox *mbox, struct mail_index_view *view, } mbox->map_uid_validity = hdr.map_uid_validity; } - if (dbox_map_open_or_create(mbox->storage->map) < 0) + if (mdbox_map_open_or_create(mbox->storage->map) < 0) return -1; - cur_map_uid_validity = dbox_map_get_uid_validity(mbox->storage->map); + cur_map_uid_validity = mdbox_map_get_uid_validity(mbox->storage->map); if (cur_map_uid_validity != mbox->map_uid_validity) { mail_storage_set_critical(&mbox->storage->storage.storage, "mdbox %s: map uidvalidity mismatch (%u vs %u)", @@ -68,10 +68,10 @@ static void dbox_mail_set_expunged(struct dbox_mail *mail, uint32_t map_uid) return; } - dbox_map_set_corrupted(mbox->storage->map, - "Unexpectedly lost %s uid=%u map_uid=%u", - mailbox_get_vname(_mail->box), - _mail->uid, map_uid); + mdbox_map_set_corrupted(mbox->storage->map, + "Unexpectedly lost %s uid=%u map_uid=%u", + mailbox_get_vname(_mail->box), + _mail->uid, map_uid); } static int dbox_mail_open_init(struct dbox_mail *mail, uint32_t map_uid) @@ -81,8 +81,8 @@ static int dbox_mail_open_init(struct dbox_mail *mail, uint32_t map_uid) uint32_t file_id; int ret; - if ((ret = dbox_map_lookup(mbox->storage->map, map_uid, - &file_id, &mail->offset)) <= 0) { + if ((ret = mdbox_map_lookup(mbox->storage->map, map_uid, + &file_id, &mail->offset)) <= 0) { if (ret < 0) return -1; @@ -141,7 +141,7 @@ int mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r, return -1; } prev_file_id = mfile->file_id; - if (dbox_map_refresh(mbox->storage->map) < 0) + if (mdbox_map_refresh(mbox->storage->map) < 0) return -1; dbox_file_unref(&mail->open_file); } diff --git a/src/lib-storage/index/dbox-multi/mdbox-map-private.h b/src/lib-storage/index/dbox-multi/mdbox-map-private.h index 7aaf712fce..8bbeb78305 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map-private.h +++ b/src/lib-storage/index/dbox-multi/mdbox-map-private.h @@ -6,10 +6,10 @@ struct dbox_mail_lookup_rec { uint32_t map_uid; uint16_t refcount; - struct dbox_map_mail_index_record rec; + struct mdbox_map_mail_index_record rec; }; -struct dbox_map { +struct mdbox_map { struct mdbox_storage *storage; const struct mdbox_settings *set; char *path; @@ -25,13 +25,13 @@ struct dbox_map { const char *create_gid_origin; }; -struct dbox_map_append { +struct mdbox_map_append { struct dbox_file_append_context *file_append; uoff_t offset, size; }; -struct dbox_map_append_context { - struct dbox_map *map; +struct mdbox_map_append_context { + struct mdbox_map *map; struct mail_index_sync_ctx *sync_ctx; struct mail_index_view *sync_view; @@ -39,7 +39,7 @@ struct dbox_map_append_context { ARRAY_DEFINE(file_appends, struct dbox_file_append_context *); ARRAY_DEFINE(files, struct dbox_file *); - ARRAY_DEFINE(appends, struct dbox_map_append); + ARRAY_DEFINE(appends, struct mdbox_map_append); uint32_t first_new_file_id; @@ -49,7 +49,8 @@ struct dbox_map_append_context { unsigned int committed:1; }; -int dbox_map_view_lookup_rec(struct dbox_map *map, struct mail_index_view *view, - uint32_t seq, struct dbox_mail_lookup_rec *rec_r); +int mdbox_map_view_lookup_rec(struct mdbox_map *map, + struct mail_index_view *view, uint32_t seq, + struct dbox_mail_lookup_rec *rec_r); #endif diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.c b/src/lib-storage/index/dbox-multi/mdbox-map.c index bcf9b754b9..9811d5c5d2 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -20,8 +20,8 @@ #define MAP_STORAGE(map) (&(map)->storage->storage.storage) -struct dbox_map_transaction_context { - struct dbox_map *map; +struct mdbox_map_transaction_context { + struct mdbox_map *map; struct mail_index_transaction *trans; struct mail_index_sync_ctx *sync_ctx; @@ -29,7 +29,7 @@ struct dbox_map_transaction_context { unsigned int success:1; }; -void dbox_map_set_corrupted(struct dbox_map *map, const char *format, ...) +void mdbox_map_set_corrupted(struct mdbox_map *map, const char *format, ...) { va_list args; @@ -43,22 +43,22 @@ void dbox_map_set_corrupted(struct dbox_map *map, const char *format, ...) mdbox_storage_set_corrupted(map->storage); } -struct dbox_map * -dbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list, - const char *path) +struct mdbox_map * +mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list, + const char *path) { - struct dbox_map *map; + struct mdbox_map *map; gid_t tmp_gid; const char *tmp_origin; - map = i_new(struct dbox_map, 1); + map = i_new(struct mdbox_map, 1); map->storage = storage; map->set = storage->set; map->path = i_strdup(path); map->index = mail_index_alloc(path, MDBOX_GLOBAL_INDEX_PREFIX); map->map_ext_id = mail_index_ext_register(map->index, "map", - sizeof(struct dbox_map_mail_index_header), - sizeof(struct dbox_map_mail_index_record), + sizeof(struct mdbox_map_mail_index_header), + sizeof(struct mdbox_map_mail_index_record), sizeof(uint32_t)); map->ref_ext_id = mail_index_ext_register(map->index, "ref", 0, sizeof(uint16_t), sizeof(uint16_t)); @@ -73,9 +73,9 @@ dbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list, return map; } -void dbox_map_deinit(struct dbox_map **_map) +void mdbox_map_deinit(struct mdbox_map **_map) { - struct dbox_map *map = *_map; + struct mdbox_map *map = *_map; *_map = NULL; @@ -88,7 +88,7 @@ void dbox_map_deinit(struct dbox_map **_map) i_free(map); } -static int dbox_map_mkdir_storage(struct dbox_map *map) +static int mdbox_map_mkdir_storage(struct mdbox_map *map) { if (mkdir_parents_chgrp(map->path, map->create_dir_mode, map->create_gid, map->create_gid_origin) < 0 && @@ -100,7 +100,7 @@ static int dbox_map_mkdir_storage(struct dbox_map *map) return 0; } -static void dbox_map_cleanup(struct dbox_map *map) +static void mdbox_map_cleanup(struct mdbox_map *map) { struct stat st; @@ -118,7 +118,7 @@ static void dbox_map_cleanup(struct dbox_map *map) } } -static int dbox_map_open_internal(struct dbox_map *map, bool create_missing) +static int mdbox_map_open_internal(struct mdbox_map *map, bool create_missing) { enum mail_index_open_flags open_flags; int ret; @@ -132,7 +132,7 @@ static int dbox_map_open_internal(struct dbox_map *map, bool create_missing) mail_storage_settings_to_index_flags(MAP_STORAGE(map)->set); if (create_missing) { open_flags |= MAIL_INDEX_OPEN_FLAG_CREATE; - if (dbox_map_mkdir_storage(map) < 0) + if (mdbox_map_mkdir_storage(map) < 0) return -1; } ret = mail_index_open(map->index, open_flags, @@ -149,21 +149,21 @@ static int dbox_map_open_internal(struct dbox_map *map, bool create_missing) } map->view = mail_index_view_open(map->index); - dbox_map_cleanup(map); + mdbox_map_cleanup(map); return 1; } -int dbox_map_open(struct dbox_map *map) +int mdbox_map_open(struct mdbox_map *map) { - return dbox_map_open_internal(map, FALSE); + return mdbox_map_open_internal(map, FALSE); } -int dbox_map_open_or_create(struct dbox_map *map) +int mdbox_map_open_or_create(struct mdbox_map *map) { - return dbox_map_open_internal(map, TRUE) <= 0 ? -1 : 0; + return mdbox_map_open_internal(map, TRUE) <= 0 ? -1 : 0; } -int dbox_map_refresh(struct dbox_map *map) +int mdbox_map_refresh(struct mdbox_map *map) { struct mail_index_view_sync_ctx *ctx; bool delayed_expunges; @@ -189,8 +189,8 @@ int dbox_map_refresh(struct dbox_map *map) } static void -mdbox_map_get_ext_hdr(struct dbox_map *map, struct mail_index_view *view, - struct dbox_map_mail_index_header *hdr_r) +mdbox_map_get_ext_hdr(struct mdbox_map *map, struct mail_index_view *view, + struct mdbox_map_mail_index_header *hdr_r) { const void *data; size_t data_size; @@ -200,18 +200,19 @@ mdbox_map_get_ext_hdr(struct dbox_map *map, struct mail_index_view *view, memcpy(hdr_r, data, I_MIN(data_size, sizeof(*hdr_r))); } -uint32_t mdbox_map_get_rebuild_count(struct dbox_map *map) +uint32_t mdbox_map_get_rebuild_count(struct mdbox_map *map) { - struct dbox_map_mail_index_header hdr; + struct mdbox_map_mail_index_header hdr; mdbox_map_get_ext_hdr(map, map->view, &hdr); return hdr.rebuild_count; } -static int dbox_map_lookup_seq(struct dbox_map *map, uint32_t seq, - const struct dbox_map_mail_index_record **rec_r) +static int +mdbox_map_lookup_seq(struct mdbox_map *map, uint32_t seq, + const struct mdbox_map_mail_index_record **rec_r) { - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; const void *data; uint32_t uid; bool expunged; @@ -222,7 +223,7 @@ static int dbox_map_lookup_seq(struct dbox_map *map, uint32_t seq, if (rec == NULL || rec->file_id == 0) { mail_index_lookup_uid(map->view, seq, &uid); - dbox_map_set_corrupted(map, "file_id=0 for map_uid=%u", uid); + mdbox_map_set_corrupted(map, "file_id=0 for map_uid=%u", uid); return -1; } *rec_r = rec; @@ -230,11 +231,11 @@ static int dbox_map_lookup_seq(struct dbox_map *map, uint32_t seq, } static int -dbox_map_get_seq(struct dbox_map *map, uint32_t map_uid, uint32_t *seq_r) +mdbox_map_get_seq(struct mdbox_map *map, uint32_t map_uid, uint32_t *seq_r) { if (!mail_index_lookup_seq(map->view, map_uid, seq_r)) { /* not found - try again after a refresh */ - if (dbox_map_refresh(map) < 0) + if (mdbox_map_refresh(map) < 0) return -1; if (!mail_index_lookup_seq(map->view, map_uid, seq_r)) return 0; @@ -242,51 +243,51 @@ dbox_map_get_seq(struct dbox_map *map, uint32_t map_uid, uint32_t *seq_r) return 1; } -int dbox_map_lookup(struct dbox_map *map, uint32_t map_uid, - uint32_t *file_id_r, uoff_t *offset_r) +int mdbox_map_lookup(struct mdbox_map *map, uint32_t map_uid, + uint32_t *file_id_r, uoff_t *offset_r) { - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; uint32_t seq; int ret; - if (dbox_map_open_or_create(map) < 0) + if (mdbox_map_open_or_create(map) < 0) return -1; - if ((ret = dbox_map_get_seq(map, map_uid, &seq)) <= 0) + if ((ret = mdbox_map_get_seq(map, map_uid, &seq)) <= 0) return ret; - if (dbox_map_lookup_seq(map, seq, &rec) < 0) + if (mdbox_map_lookup_seq(map, seq, &rec) < 0) return -1; *file_id_r = rec->file_id; *offset_r = rec->offset; return 1; } -int dbox_map_lookup_full(struct dbox_map *map, uint32_t map_uid, - struct dbox_map_mail_index_record *rec_r, - uint16_t *refcount_r) +int mdbox_map_lookup_full(struct mdbox_map *map, uint32_t map_uid, + struct mdbox_map_mail_index_record *rec_r, + uint16_t *refcount_r) { - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; const uint16_t *ref16_p; const void *data; uint32_t seq; bool expunged; int ret; - if (dbox_map_open_or_create(map) < 0) + if (mdbox_map_open_or_create(map) < 0) return -1; - if ((ret = dbox_map_get_seq(map, map_uid, &seq)) <= 0) + if ((ret = mdbox_map_get_seq(map, map_uid, &seq)) <= 0) return ret; - if (dbox_map_lookup_seq(map, seq, &rec) < 0) + if (mdbox_map_lookup_seq(map, seq, &rec) < 0) return -1; *rec_r = *rec; mail_index_lookup_ext(map->view, seq, map->ref_ext_id, &data, &expunged); if (data == NULL) { - dbox_map_set_corrupted(map, "missing ref extension"); + mdbox_map_set_corrupted(map, "missing ref extension"); return -1; } ref16_p = data; @@ -294,8 +295,9 @@ int dbox_map_lookup_full(struct dbox_map *map, uint32_t map_uid, return 1; } -int dbox_map_view_lookup_rec(struct dbox_map *map, struct mail_index_view *view, - uint32_t seq, struct dbox_mail_lookup_rec *rec_r) +int mdbox_map_view_lookup_rec(struct mdbox_map *map, + struct mail_index_view *view, uint32_t seq, + struct dbox_mail_lookup_rec *rec_r) { const uint16_t *ref16_p; const void *data; @@ -306,14 +308,14 @@ int dbox_map_view_lookup_rec(struct dbox_map *map, struct mail_index_view *view, mail_index_lookup_ext(view, seq, map->map_ext_id, &data, &expunged); if (data == NULL) { - dbox_map_set_corrupted(map, "missing map extension"); + mdbox_map_set_corrupted(map, "missing map extension"); return -1; } memcpy(&rec_r->rec, data, sizeof(rec_r->rec)); mail_index_lookup_ext(view, seq, map->ref_ext_id, &data, &expunged); if (data == NULL) { - dbox_map_set_corrupted(map, "missing ref extension"); + mdbox_map_set_corrupted(map, "missing ref extension"); return -1; } ref16_p = data; @@ -321,21 +323,21 @@ int dbox_map_view_lookup_rec(struct dbox_map *map, struct mail_index_view *view, return 0; } -int dbox_map_get_file_msgs(struct dbox_map *map, uint32_t file_id, - ARRAY_TYPE(dbox_map_file_msg) *recs) +int mdbox_map_get_file_msgs(struct mdbox_map *map, uint32_t file_id, + ARRAY_TYPE(mdbox_map_file_msg) *recs) { const struct mail_index_header *hdr; struct dbox_mail_lookup_rec rec; - struct dbox_map_file_msg msg; + struct mdbox_map_file_msg msg; uint32_t seq; - if (dbox_map_refresh(map) < 0) + if (mdbox_map_refresh(map) < 0) return -1; hdr = mail_index_get_header(map->view); memset(&msg, 0, sizeof(msg)); for (seq = 1; seq <= hdr->messages_count; seq++) { - if (dbox_map_view_lookup_rec(map, map->view, seq, &rec) < 0) + if (mdbox_map_view_lookup_rec(map, map->view, seq, &rec) < 0) return -1; if (rec.rec.file_id == file_id) { @@ -348,22 +350,22 @@ int dbox_map_get_file_msgs(struct dbox_map *map, uint32_t file_id, return 0; } -int dbox_map_get_zero_ref_files(struct dbox_map *map, - ARRAY_TYPE(seq_range) *file_ids_r) +int mdbox_map_get_zero_ref_files(struct mdbox_map *map, + ARRAY_TYPE(seq_range) *file_ids_r) { const struct mail_index_header *hdr; - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; const uint16_t *ref16_p; const void *data; uint32_t seq; bool expunged; int ret; - if ((ret = dbox_map_open(map)) <= 0) { + if ((ret = mdbox_map_open(map)) <= 0) { /* no map / internal error */ return ret; } - if (dbox_map_refresh(map) < 0) + if (mdbox_map_refresh(map) < 0) return -1; hdr = mail_index_get_header(map->view); @@ -386,26 +388,27 @@ int dbox_map_get_zero_ref_files(struct dbox_map *map, return 0; } -struct dbox_map_transaction_context * -dbox_map_transaction_begin(struct dbox_map *map, bool external) +struct mdbox_map_transaction_context * +mdbox_map_transaction_begin(struct mdbox_map *map, bool external) { - struct dbox_map_transaction_context *ctx; + struct mdbox_map_transaction_context *ctx; enum mail_index_transaction_flags flags = MAIL_INDEX_TRANSACTION_FLAG_FSYNC; if (external) flags |= MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL; - ctx = i_new(struct dbox_map_transaction_context, 1); + ctx = i_new(struct mdbox_map_transaction_context, 1); ctx->map = map; - if (dbox_map_open(map) > 0 && - dbox_map_refresh(map) == 0) + if (mdbox_map_open(map) > 0 && + mdbox_map_refresh(map) == 0) ctx->trans = mail_index_transaction_begin(map->view, flags); return ctx; } static void -dbox_map_sync_handle(struct dbox_map *map, struct mail_index_sync_ctx *sync_ctx) +mdbox_map_sync_handle(struct mdbox_map *map, + struct mail_index_sync_ctx *sync_ctx) { struct mail_index_sync_rec sync_rec; uint32_t seq1, seq2; @@ -423,9 +426,9 @@ dbox_map_sync_handle(struct dbox_map *map, struct mail_index_sync_ctx *sync_ctx) } } -int dbox_map_transaction_commit(struct dbox_map_transaction_context *ctx) +int mdbox_map_transaction_commit(struct mdbox_map_transaction_context *ctx) { - struct dbox_map *map = ctx->map; + struct mdbox_map *map = ctx->map; struct mail_index_view *view; struct mail_index_transaction *sync_trans; int ret; @@ -444,7 +447,7 @@ int dbox_map_transaction_commit(struct dbox_map_transaction_context *ctx) mail_index_transaction_rollback(&ctx->trans); return -1; } - dbox_map_sync_handle(map, ctx->sync_ctx); + mdbox_map_sync_handle(map, ctx->sync_ctx); if (mail_index_transaction_commit(&ctx->trans) < 0) { mail_storage_set_internal_error(MAP_STORAGE(map)); @@ -455,15 +458,15 @@ int dbox_map_transaction_commit(struct dbox_map_transaction_context *ctx) return 0; } -void dbox_map_transaction_set_failed(struct dbox_map_transaction_context *ctx) +void mdbox_map_transaction_set_failed(struct mdbox_map_transaction_context *ctx) { ctx->success = FALSE; } -void dbox_map_transaction_free(struct dbox_map_transaction_context **_ctx) +void mdbox_map_transaction_free(struct mdbox_map_transaction_context **_ctx) { - struct dbox_map_transaction_context *ctx = *_ctx; - struct dbox_map *map = ctx->map; + struct mdbox_map_transaction_context *ctx = *_ctx; + struct mdbox_map *map = ctx->map; *_ctx = NULL; if (ctx->success) { @@ -479,10 +482,10 @@ void dbox_map_transaction_free(struct dbox_map_transaction_context **_ctx) i_free(ctx); } -int dbox_map_update_refcount(struct dbox_map_transaction_context *ctx, - uint32_t map_uid, int diff) +int mdbox_map_update_refcount(struct mdbox_map_transaction_context *ctx, + uint32_t map_uid, int diff) { - struct dbox_map *map = ctx->map; + struct mdbox_map *map = ctx->map; const void *data; uint32_t seq; bool expunged; @@ -494,8 +497,8 @@ int dbox_map_update_refcount(struct dbox_map_transaction_context *ctx, if (!mail_index_lookup_seq(map->view, map_uid, &seq)) { /* we can't refresh map here since view has a transaction open. */ - dbox_map_set_corrupted(map, "refcount update lost map_uid=%u", - map_uid); + mdbox_map_set_corrupted(map, "refcount update lost map_uid=%u", + map_uid); return -1; } mail_index_lookup_ext(map->view, seq, map->ref_ext_id, @@ -505,8 +508,8 @@ int dbox_map_update_refcount(struct dbox_map_transaction_context *ctx, new_diff = mail_index_atomic_inc_ext(ctx->trans, seq, map->ref_ext_id, diff); if (old_diff + new_diff < 0) { - dbox_map_set_corrupted(map, "map_uid=%u refcount too low", - map_uid); + mdbox_map_set_corrupted(map, "map_uid=%u refcount too low", + map_uid); return -1; } if (old_diff + new_diff >= 32768) { @@ -521,8 +524,8 @@ int dbox_map_update_refcount(struct dbox_map_transaction_context *ctx, return 0; } -int dbox_map_update_refcounts(struct dbox_map_transaction_context *ctx, - const ARRAY_TYPE(uint32_t) *map_uids, int diff) +int mdbox_map_update_refcounts(struct mdbox_map_transaction_context *ctx, + const ARRAY_TYPE(uint32_t) *map_uids, int diff) { const uint32_t *uidp; unsigned int i, count; @@ -533,17 +536,17 @@ int dbox_map_update_refcounts(struct dbox_map_transaction_context *ctx, count = array_count(map_uids); for (i = 0; i < count; i++) { uidp = array_idx(map_uids, i); - if (dbox_map_update_refcount(ctx, *uidp, diff) < 0) + if (mdbox_map_update_refcount(ctx, *uidp, diff) < 0) return -1; } return 0; } -int dbox_map_remove_file_id(struct dbox_map *map, uint32_t file_id) +int mdbox_map_remove_file_id(struct mdbox_map *map, uint32_t file_id) { - struct dbox_map_transaction_context *map_trans; + struct mdbox_map_transaction_context *map_trans; const struct mail_index_header *hdr; - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; const void *data; bool expunged; uint32_t seq; @@ -553,14 +556,14 @@ int dbox_map_remove_file_id(struct dbox_map *map, uint32_t file_id) messages that have already been moved to other files. */ /* we need a per-file transaction, otherwise we can't refresh the map */ - map_trans = dbox_map_transaction_begin(map, TRUE); + map_trans = mdbox_map_transaction_begin(map, TRUE); hdr = mail_index_get_header(map->view); for (seq = 1; seq <= hdr->messages_count; seq++) { mail_index_lookup_ext(map->view, seq, map->map_ext_id, &data, &expunged); if (data == NULL) { - dbox_map_set_corrupted(map, "missing map extension"); + mdbox_map_set_corrupted(map, "missing map extension"); ret = -1; break; } @@ -572,29 +575,29 @@ int dbox_map_remove_file_id(struct dbox_map *map, uint32_t file_id) } } if (ret == 0) - (void)dbox_map_transaction_commit(map_trans); - dbox_map_transaction_free(&map_trans); + (void)mdbox_map_transaction_commit(map_trans); + mdbox_map_transaction_free(&map_trans); return ret; } -struct dbox_map_append_context * -dbox_map_append_begin(struct dbox_map *map) +struct mdbox_map_append_context * +mdbox_map_append_begin(struct mdbox_map *map) { - struct dbox_map_append_context *ctx; + struct mdbox_map_append_context *ctx; - ctx = i_new(struct dbox_map_append_context, 1); + ctx = i_new(struct mdbox_map_append_context, 1); ctx->map = map; ctx->first_new_file_id = (uint32_t)-1; i_array_init(&ctx->file_appends, 64); i_array_init(&ctx->files, 64); i_array_init(&ctx->appends, 128); - if (dbox_map_open_or_create(map) < 0) + if (mdbox_map_open_or_create(map) < 0) ctx->failed = TRUE; else { /* refresh the map so we can try appending to the latest files */ - (void)dbox_map_refresh(ctx->map); + (void)mdbox_map_refresh(ctx->map); } return ctx; } @@ -657,12 +660,13 @@ static bool dbox_try_open(struct dbox_file *file, bool want_altpath) } static bool -dbox_map_file_try_append(struct dbox_map_append_context *ctx, bool want_altpath, - uint32_t file_id, time_t stamp, uoff_t mail_size, - struct dbox_file_append_context **file_append_r, - struct ostream **output_r, bool *retry_later_r) +mdbox_map_file_try_append(struct mdbox_map_append_context *ctx, + bool want_altpath, + uint32_t file_id, time_t stamp, uoff_t mail_size, + struct dbox_file_append_context **file_append_r, + struct ostream **output_r, bool *retry_later_r) { - struct dbox_map *map = ctx->map; + struct mdbox_map *map = ctx->map; struct mdbox_storage *storage = map->storage; struct dbox_file *file; struct dbox_file_append_context *file_append; @@ -710,7 +714,7 @@ dbox_map_file_try_append(struct dbox_map_append_context *ctx, bool want_altpath, } static bool -dbox_map_is_appending(struct dbox_map_append_context *ctx, uint32_t file_id) +mdbox_map_is_appending(struct mdbox_map_append_context *ctx, uint32_t file_id) { struct dbox_file_append_context *const *file_appends; unsigned int i, count; @@ -729,11 +733,11 @@ dbox_map_is_appending(struct dbox_map_append_context *ctx, uint32_t file_id) } static struct dbox_file_append_context * -dbox_map_find_existing_append(struct dbox_map_append_context *ctx, - uoff_t mail_size, bool want_altpath, - struct ostream **output_r) +mdbox_map_find_existing_append(struct mdbox_map_append_context *ctx, + uoff_t mail_size, bool want_altpath, + struct ostream **output_r) { - struct dbox_map *map = ctx->map; + struct mdbox_map *map = ctx->map; struct dbox_file_append_context *const *file_appends, *append; struct mdbox_file *mfile; unsigned int i, count; @@ -767,15 +771,15 @@ dbox_map_find_existing_append(struct dbox_map_append_context *ctx, } static int -dbox_map_find_first_alt(struct dbox_map_append_context *ctx, - uint32_t *min_file_id_r, uint32_t *seq_r) +mdbox_map_find_first_alt(struct mdbox_map_append_context *ctx, + uint32_t *min_file_id_r, uint32_t *seq_r) { struct mdbox_storage *dstorage = ctx->map->storage; struct mail_storage *storage = &dstorage->storage.storage; DIR *dir; struct dirent *d; const struct mail_index_header *hdr; - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; uint32_t seq, file_id, min_file_id = -1U; int ret = 0; @@ -817,7 +821,7 @@ dbox_map_find_first_alt(struct dbox_map_append_context *ctx, /* find the newest message in alt storage from map view */ hdr = mail_index_get_header(ctx->map->view); for (seq = hdr->messages_count; seq > 0; seq--) { - if (dbox_map_lookup_seq(ctx->map, seq, &rec) < 0) + if (mdbox_map_lookup_seq(ctx->map, seq, &rec) < 0) return -1; if (rec->file_id < min_file_id) @@ -830,15 +834,15 @@ dbox_map_find_first_alt(struct dbox_map_append_context *ctx, } static int -dbox_map_find_appendable_file(struct dbox_map_append_context *ctx, - uoff_t mail_size, bool want_altpath, - struct dbox_file_append_context **file_append_r, - struct ostream **output_r) +mdbox_map_find_appendable_file(struct mdbox_map_append_context *ctx, + uoff_t mail_size, bool want_altpath, + struct dbox_file_append_context **file_append_r, + struct ostream **output_r) { - struct dbox_map *map = ctx->map; + struct mdbox_map *map = ctx->map; ARRAY_TYPE(seq_range) checked_file_ids; const struct mail_index_header *hdr; - const struct dbox_map_mail_index_record *rec; + const struct mdbox_map_mail_index_record *rec; unsigned int backwards_lookup_count; uint32_t seq, seq1, uid, min_file_id; time_t stamp; @@ -858,14 +862,14 @@ dbox_map_find_appendable_file(struct dbox_map_append_context *ctx, seq = hdr->messages_count; else { /* we want to save to alt storage. */ - if (dbox_map_find_first_alt(ctx, &min_file_id, &seq) < 0) + if (mdbox_map_find_first_alt(ctx, &min_file_id, &seq) < 0) return -1; seq_range_array_add_range(&checked_file_ids, min_file_id, (uint32_t)-1); } for (; seq > 0; seq--) { - if (dbox_map_lookup_seq(map, seq, &rec) < 0) + if (mdbox_map_lookup_seq(map, seq, &rec) < 0) return -1; if (seq_range_exists(&checked_file_ids, rec->file_id)) @@ -884,15 +888,15 @@ dbox_map_find_appendable_file(struct dbox_map_append_context *ctx, map->set->mdbox_rotate_size) continue; - if (dbox_map_is_appending(ctx, rec->file_id)) { + if (mdbox_map_is_appending(ctx, rec->file_id)) { /* already checked this */ continue; } mail_index_lookup_uid(map->view, seq, &uid); - if (!dbox_map_file_try_append(ctx, want_altpath, rec->file_id, - stamp, mail_size, file_append_r, - output_r, &retry_later)) { + if (!mdbox_map_file_try_append(ctx, want_altpath, rec->file_id, + stamp, mail_size, file_append_r, + output_r, &retry_later)) { /* file is too old. the rest of the files are too. */ break; } @@ -910,13 +914,13 @@ dbox_map_find_appendable_file(struct dbox_map_append_context *ctx, return 0; } -int dbox_map_append_next(struct dbox_map_append_context *ctx, uoff_t mail_size, - enum dbox_map_append_flags flags, - struct dbox_file_append_context **file_append_ctx_r, - struct ostream **output_r) +int mdbox_map_append_next(struct mdbox_map_append_context *ctx, + uoff_t mail_size, enum mdbox_map_append_flags flags, + struct dbox_file_append_context **file_append_ctx_r, + struct ostream **output_r) { struct dbox_file *file; - struct dbox_map_append *append; + struct mdbox_map_append *append; struct dbox_file_append_context *file_append; bool existing, want_altpath; int ret; @@ -925,14 +929,14 @@ int dbox_map_append_next(struct dbox_map_append_context *ctx, uoff_t mail_size, return -1; want_altpath = (flags & DBOX_MAP_APPEND_FLAG_ALT) != 0; - file_append = dbox_map_find_existing_append(ctx, mail_size, - want_altpath, output_r); + file_append = mdbox_map_find_existing_append(ctx, mail_size, + want_altpath, output_r); if (file_append != NULL) { ret = 1; existing = TRUE; } else { - ret = dbox_map_find_appendable_file(ctx, mail_size, flags, - &file_append, output_r); + ret = mdbox_map_find_appendable_file(ctx, mail_size, flags, + &file_append, output_r); existing = FALSE; } if (ret > 0) @@ -969,9 +973,9 @@ int dbox_map_append_next(struct dbox_map_append_context *ctx, uoff_t mail_size, return 0; } -void dbox_map_append_finish(struct dbox_map_append_context *ctx) +void mdbox_map_append_finish(struct mdbox_map_append_context *ctx) { - struct dbox_map_append *appends; + struct mdbox_map_append *appends; unsigned int count; uoff_t cur_offset; @@ -982,12 +986,12 @@ void dbox_map_append_finish(struct dbox_map_append_context *ctx) appends[count-1].size = cur_offset - appends[count-1].offset; } -static int dbox_map_assign_file_ids(struct dbox_map_append_context *ctx, - bool separate_transaction) +static int mdbox_map_assign_file_ids(struct mdbox_map_append_context *ctx, + bool separate_transaction) { struct dbox_file_append_context *const *file_appends; unsigned int i, count; - struct dbox_map_mail_index_header hdr; + struct mdbox_map_mail_index_header hdr; uint32_t first_file_id, file_id; int ret; @@ -1001,7 +1005,7 @@ static int dbox_map_assign_file_ids(struct dbox_map_append_context *ctx, mail_index_reset_error(ctx->map->index); return -1; } - dbox_map_sync_handle(ctx->map, ctx->sync_ctx); + mdbox_map_sync_handle(ctx->map, ctx->sync_ctx); mdbox_map_get_ext_hdr(ctx->map, ctx->sync_view, &hdr); file_id = hdr.highest_file_id + 1; @@ -1046,13 +1050,13 @@ static int dbox_map_assign_file_ids(struct dbox_map_append_context *ctx, return 0; } -int dbox_map_append_assign_map_uids(struct dbox_map_append_context *ctx, - uint32_t *first_map_uid_r, - uint32_t *last_map_uid_r) +int mdbox_map_append_assign_map_uids(struct mdbox_map_append_context *ctx, + uint32_t *first_map_uid_r, + uint32_t *last_map_uid_r) { - const struct dbox_map_append *appends; + const struct mdbox_map_append *appends; const struct mail_index_header *hdr; - struct dbox_map_mail_index_record rec; + struct mdbox_map_mail_index_record rec; unsigned int i, count; ARRAY_TYPE(seq_range) uids; const struct seq_range *range; @@ -1066,7 +1070,7 @@ int dbox_map_append_assign_map_uids(struct dbox_map_append_context *ctx, return 0; } - if (dbox_map_assign_file_ids(ctx, TRUE) < 0) + if (mdbox_map_assign_file_ids(ctx, TRUE) < 0) return -1; /* append map records to index */ @@ -1117,18 +1121,18 @@ int dbox_map_append_assign_map_uids(struct dbox_map_append_context *ctx, return ret; } -int dbox_map_append_move(struct dbox_map_append_context *ctx, - const ARRAY_TYPE(uint32_t) *map_uids, - const ARRAY_TYPE(seq_range) *expunge_map_uids) +int mdbox_map_append_move(struct mdbox_map_append_context *ctx, + const ARRAY_TYPE(uint32_t) *map_uids, + const ARRAY_TYPE(seq_range) *expunge_map_uids) { - const struct dbox_map_append *appends; - struct dbox_map_mail_index_record rec; + const struct mdbox_map_append *appends; + struct mdbox_map_mail_index_record rec; struct seq_range_iter iter; const uint32_t *uids; unsigned int i, j, map_uids_count, appends_count; uint32_t uid, seq; - if (dbox_map_assign_file_ids(ctx, FALSE) < 0) + if (mdbox_map_assign_file_ids(ctx, FALSE) < 0) return -1; memset(&rec, 0, sizeof(rec)); @@ -1160,9 +1164,9 @@ int dbox_map_append_move(struct dbox_map_append_context *ctx, return 0; } -int dbox_map_append_commit(struct dbox_map_append_context *ctx) +int mdbox_map_append_commit(struct mdbox_map_append_context *ctx) { - struct dbox_map *map = ctx->map; + struct mdbox_map *map = ctx->map; struct dbox_file_append_context **file_appends; unsigned int i, count; @@ -1186,9 +1190,9 @@ int dbox_map_append_commit(struct dbox_map_append_context *ctx) return 0; } -void dbox_map_append_free(struct dbox_map_append_context **_ctx) +void mdbox_map_append_free(struct mdbox_map_append_context **_ctx) { - struct dbox_map_append_context *ctx = *_ctx; + struct mdbox_map_append_context *ctx = *_ctx; struct dbox_file_append_context **file_appends; struct dbox_file **files; unsigned int i, count; @@ -1218,7 +1222,7 @@ void dbox_map_append_free(struct dbox_map_append_context **_ctx) i_free(ctx); } -uint32_t dbox_map_get_uid_validity(struct dbox_map *map) +uint32_t mdbox_map_get_uid_validity(struct mdbox_map *map) { const struct mail_index_header *hdr; @@ -1229,7 +1233,7 @@ uint32_t dbox_map_get_uid_validity(struct dbox_map *map) return hdr->uid_validity; /* refresh index in case it was just changed */ - (void)dbox_map_refresh(map); + (void)mdbox_map_refresh(map); hdr = mail_index_get_header(map->view); return hdr->uid_validity != 0 ? hdr->uid_validity : map->created_uid_validity; diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.h b/src/lib-storage/index/dbox-multi/mdbox-map.h index 71ceec6af8..b2892a8766 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.h +++ b/src/lib-storage/index/dbox-multi/mdbox-map.h @@ -3,109 +3,109 @@ #include "seq-range-array.h" -struct dbox_map_append_context; struct dbox_file_append_context; +struct mdbox_map_append_context; struct mdbox_storage; -enum dbox_map_append_flags { +enum mdbox_map_append_flags { DBOX_MAP_APPEND_FLAG_ALT = 0x01 }; -struct dbox_map_mail_index_header { +struct mdbox_map_mail_index_header { uint32_t highest_file_id; /* increased every time storage is rebuilt */ uint32_t rebuild_count; }; -struct dbox_map_mail_index_record { +struct mdbox_map_mail_index_record { uint32_t file_id; uint32_t offset; uint32_t size; /* including pre/post metadata */ }; -struct dbox_map_file_msg { +struct mdbox_map_file_msg { uint32_t map_uid; uint32_t offset; uint32_t refcount; }; -ARRAY_DEFINE_TYPE(dbox_map_file_msg, struct dbox_map_file_msg); +ARRAY_DEFINE_TYPE(mdbox_map_file_msg, struct mdbox_map_file_msg); -struct dbox_map * -dbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list, - const char *path); -void dbox_map_deinit(struct dbox_map **map); +struct mdbox_map * +mdbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list, + const char *path); +void mdbox_map_deinit(struct mdbox_map **map); /* Open the map. Returns 1 if ok, 0 if map doesn't exist, -1 if error. */ -int dbox_map_open(struct dbox_map *map); +int mdbox_map_open(struct mdbox_map *map); /* Open or create the map. This is done automatically for most operations. Returns 0 if ok, -1 if error. */ -int dbox_map_open_or_create(struct dbox_map *map); +int mdbox_map_open_or_create(struct mdbox_map *map); /* Refresh the map. Returns 0 if ok, -1 if error. */ -int dbox_map_refresh(struct dbox_map *map); +int mdbox_map_refresh(struct mdbox_map *map); /* Return the current rebuild counter */ -uint32_t mdbox_map_get_rebuild_count(struct dbox_map *map); +uint32_t mdbox_map_get_rebuild_count(struct mdbox_map *map); /* Look up file_id and offset for given map UID. Returns 1 if ok, 0 if UID is already expunged, -1 if error. */ -int dbox_map_lookup(struct dbox_map *map, uint32_t map_uid, - uint32_t *file_id_r, uoff_t *offset_r); -/* Like dbox_map_lookup(), but look up everything. */ -int dbox_map_lookup_full(struct dbox_map *map, uint32_t map_uid, - struct dbox_map_mail_index_record *rec_r, - uint16_t *refcount_r); +int mdbox_map_lookup(struct mdbox_map *map, uint32_t map_uid, + uint32_t *file_id_r, uoff_t *offset_r); +/* Like mdbox_map_lookup(), but look up everything. */ +int mdbox_map_lookup_full(struct mdbox_map *map, uint32_t map_uid, + struct mdbox_map_mail_index_record *rec_r, + uint16_t *refcount_r); /* Get all messages from file */ -int dbox_map_get_file_msgs(struct dbox_map *map, uint32_t file_id, - ARRAY_TYPE(dbox_map_file_msg) *recs); +int mdbox_map_get_file_msgs(struct mdbox_map *map, uint32_t file_id, + ARRAY_TYPE(mdbox_map_file_msg) *recs); -struct dbox_map_transaction_context * -dbox_map_transaction_begin(struct dbox_map *map, bool external); +struct mdbox_map_transaction_context * +mdbox_map_transaction_begin(struct mdbox_map *map, bool external); /* Write transaction to map and leave it locked. Call _free() to update tail offset and unlock. */ -int dbox_map_transaction_commit(struct dbox_map_transaction_context *ctx); -void dbox_map_transaction_set_failed(struct dbox_map_transaction_context *ctx); -void dbox_map_transaction_free(struct dbox_map_transaction_context **ctx); +int mdbox_map_transaction_commit(struct mdbox_map_transaction_context *ctx); +void mdbox_map_transaction_set_failed(struct mdbox_map_transaction_context *ctx); +void mdbox_map_transaction_free(struct mdbox_map_transaction_context **ctx); -int dbox_map_update_refcount(struct dbox_map_transaction_context *ctx, - uint32_t map_uid, int diff); -int dbox_map_update_refcounts(struct dbox_map_transaction_context *ctx, - const ARRAY_TYPE(uint32_t) *map_uids, int diff); -int dbox_map_remove_file_id(struct dbox_map *map, uint32_t file_id); +int mdbox_map_update_refcount(struct mdbox_map_transaction_context *ctx, + uint32_t map_uid, int diff); +int mdbox_map_update_refcounts(struct mdbox_map_transaction_context *ctx, + const ARRAY_TYPE(uint32_t) *map_uids, int diff); +int mdbox_map_remove_file_id(struct mdbox_map *map, uint32_t file_id); /* Return all files containing messages with zero refcount. */ -int dbox_map_get_zero_ref_files(struct dbox_map *map, - ARRAY_TYPE(seq_range) *file_ids_r); +int mdbox_map_get_zero_ref_files(struct mdbox_map *map, + ARRAY_TYPE(seq_range) *file_ids_r); -struct dbox_map_append_context * -dbox_map_append_begin(struct dbox_map *map); +struct mdbox_map_append_context * +mdbox_map_append_begin(struct mdbox_map *map); /* Request file for saving a new message with given size (if available). If an existing file can be used, the record is locked and updated in index. Returns 0 if ok, -1 if error. */ -int dbox_map_append_next(struct dbox_map_append_context *ctx, uoff_t mail_size, - enum dbox_map_append_flags flags, - struct dbox_file_append_context **file_append_ctx_r, - struct ostream **output_r); +int mdbox_map_append_next(struct mdbox_map_append_context *ctx, uoff_t mail_size, + enum mdbox_map_append_flags flags, + struct dbox_file_append_context **file_append_ctx_r, + struct ostream **output_r); /* Finished saving the last mail. Saves the message size. */ -void dbox_map_append_finish(struct dbox_map_append_context *ctx); +void mdbox_map_append_finish(struct mdbox_map_append_context *ctx); /* Assign map UIDs to all appended msgs to multi-files. */ -int dbox_map_append_assign_map_uids(struct dbox_map_append_context *ctx, - uint32_t *first_map_uid_r, - uint32_t *last_map_uid_r); +int mdbox_map_append_assign_map_uids(struct mdbox_map_append_context *ctx, + uint32_t *first_map_uid_r, + uint32_t *last_map_uid_r); /* The appends are existing messages that were simply moved to a new file. map_uids contains the moved messages' map UIDs. */ -int dbox_map_append_move(struct dbox_map_append_context *ctx, - const ARRAY_TYPE(uint32_t) *map_uids, - const ARRAY_TYPE(seq_range) *expunge_map_uids); +int mdbox_map_append_move(struct mdbox_map_append_context *ctx, + const ARRAY_TYPE(uint32_t) *map_uids, + const ARRAY_TYPE(seq_range) *expunge_map_uids); /* Returns 0 if ok, -1 if error. */ -int dbox_map_append_commit(struct dbox_map_append_context *ctx); -void dbox_map_append_free(struct dbox_map_append_context **ctx); +int mdbox_map_append_commit(struct mdbox_map_append_context *ctx); +void mdbox_map_append_free(struct mdbox_map_append_context **ctx); /* Get either existing uidvalidity or create a new one if map was just created. */ -uint32_t dbox_map_get_uid_validity(struct dbox_map *map); +uint32_t mdbox_map_get_uid_validity(struct mdbox_map *map); -void dbox_map_set_corrupted(struct dbox_map *map, const char *format, ...) +void mdbox_map_set_corrupted(struct mdbox_map *map, const char *format, ...) ATTR_FORMAT(2, 3); #endif diff --git a/src/lib-storage/index/dbox-multi/mdbox-purge.c b/src/lib-storage/index/dbox-multi/mdbox-purge.c index 90535b436e..a760890774 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-purge.c +++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c @@ -46,12 +46,12 @@ struct mdbox_purge_context { struct hash_table *altmoves; bool have_altmoves; - struct dbox_map_append_context *append_ctx; + struct mdbox_map_append_context *append_ctx; }; static int mdbox_map_file_msg_offset_cmp(const void *p1, const void *p2) { - const struct dbox_map_file_msg *m1 = p1, *m2 = p2; + const struct mdbox_map_file_msg *m1 = p1, *m2 = p2; if (m1->offset < m2->offset) return -1; @@ -130,24 +130,24 @@ mdbox_purge_want_altpath(struct mdbox_purge_context *ctx, uint32_t map_uid) static int mdbox_purge_save_msg(struct mdbox_purge_context *ctx, struct dbox_file *file, - const struct dbox_map_file_msg *msg) + const struct mdbox_map_file_msg *msg) { struct dbox_file_append_context *out_file_append; struct istream *input; struct ostream *output; - enum dbox_map_append_flags append_flags; + enum mdbox_map_append_flags append_flags; uoff_t msg_size; off_t ret; int read_errno; if (ctx->append_ctx == NULL) - ctx->append_ctx = dbox_map_append_begin(ctx->storage->map); + ctx->append_ctx = mdbox_map_append_begin(ctx->storage->map); append_flags = !mdbox_purge_want_altpath(ctx, msg->map_uid) ? 0 : DBOX_MAP_APPEND_FLAG_ALT; msg_size = file->msg_header_size + file->cur_physical_size; - if (dbox_map_append_next(ctx->append_ctx, file->cur_physical_size, - append_flags, &out_file_append, &output) < 0) + if (mdbox_map_append_next(ctx->append_ctx, file->cur_physical_size, + append_flags, &out_file_append, &output) < 0) return -1; i_assert(file != out_file_append->file); @@ -176,7 +176,7 @@ mdbox_purge_save_msg(struct mdbox_purge_context *ctx, struct dbox_file *file, if ((ret = mdbox_file_copy_metadata(file, output)) <= 0) return ret; - dbox_map_append_finish(ctx->append_ctx); + mdbox_map_append_finish(ctx->append_ctx); return 1; } @@ -185,8 +185,8 @@ mdbox_file_purge(struct mdbox_purge_context *ctx, struct dbox_file *file) { struct mdbox_storage *dstorage = (struct mdbox_storage *)file->storage; struct stat st; - ARRAY_TYPE(dbox_map_file_msg) msgs_arr; - const struct dbox_map_file_msg *msgs; + ARRAY_TYPE(mdbox_map_file_msg) msgs_arr; + const struct mdbox_map_file_msg *msgs; ARRAY_TYPE(seq_range) expunged_map_uids; ARRAY_TYPE(uint32_t) copied_map_uids; unsigned int i, count; @@ -211,9 +211,9 @@ mdbox_file_purge(struct mdbox_purge_context *ctx, struct dbox_file *file) /* get list of map UIDs that exist in this file (again has to be done after locking) */ i_array_init(&msgs_arr, 128); - if (dbox_map_get_file_msgs(dstorage->map, - ((struct mdbox_file *)file)->file_id, - &msgs_arr) < 0) { + if (mdbox_map_get_file_msgs(dstorage->map, + ((struct mdbox_file *)file)->file_id, + &msgs_arr) < 0) { array_free(&msgs_arr); dbox_file_unlock(file); return -1; @@ -276,9 +276,9 @@ mdbox_file_purge(struct mdbox_purge_context *ctx, struct dbox_file *file) ret = 1; } else { /* assign new file_id + offset to moved messages */ - if (dbox_map_append_move(ctx->append_ctx, &copied_map_uids, - &expunged_map_uids) < 0 || - dbox_map_append_commit(ctx->append_ctx) < 0) + if (mdbox_map_append_move(ctx->append_ctx, &copied_map_uids, + &expunged_map_uids) < 0 || + mdbox_map_append_commit(ctx->append_ctx) < 0) ret = -1; else ret = 1; @@ -286,7 +286,7 @@ mdbox_file_purge(struct mdbox_purge_context *ctx, struct dbox_file *file) if (ret > 0) (void)dbox_file_unlink(file); if (ctx->append_ctx != NULL) - dbox_map_append_free(&ctx->append_ctx); + mdbox_map_append_free(&ctx->append_ctx); if (ret < 0) dbox_file_unlock(file); array_free(&copied_map_uids); @@ -425,7 +425,7 @@ static int mdbox_altmove_add_files(struct mdbox_purge_context *ctx) struct mdbox_storage *dstorage = ctx->storage; const uint32_t *map_uids; unsigned int i, count, alt_refcount = 0; - struct dbox_map_mail_index_record cur_rec; + struct mdbox_map_mail_index_record cur_rec; uint32_t cur_map_uid; uint16_t cur_refcount = 0; uoff_t offset; @@ -443,8 +443,8 @@ static int mdbox_altmove_add_files(struct mdbox_purge_context *ctx) for (i = 0; i < count; i++) { if (cur_map_uid != map_uids[i]) { cur_map_uid = map_uids[i]; - if (dbox_map_lookup_full(dstorage->map, cur_map_uid, - &cur_rec, &cur_refcount) < 0) { + if (mdbox_map_lookup_full(dstorage->map, cur_map_uid, + &cur_rec, &cur_refcount) < 0) { cur_refcount = (uint16_t)-1; ret = -1; } @@ -479,8 +479,8 @@ static int mdbox_altmove_add_files(struct mdbox_purge_context *ctx) continue; cur_map_uid = map_uids[i]; - if (dbox_map_lookup(dstorage->map, cur_map_uid, - &cur_rec.file_id, &offset) < 0) { + if (mdbox_map_lookup(dstorage->map, cur_map_uid, + &cur_rec.file_id, &offset) < 0) { ret = -1; continue; } @@ -509,7 +509,7 @@ int mdbox_purge(struct mail_storage *_storage) int ret; ctx = mdbox_purge_alloc(storage); - ret = dbox_map_get_zero_ref_files(storage->map, &ctx->purge_file_ids); + ret = mdbox_map_get_zero_ref_files(storage->map, &ctx->purge_file_ids); if (storage->alt_storage_dir != NULL) { if (mdbox_purge_get_primary_files(ctx) < 0) ret = -1; @@ -527,7 +527,7 @@ int mdbox_purge(struct mail_storage *_storage) if (mdbox_file_purge(ctx, file) < 0) ret = -1; } else { - dbox_map_remove_file_id(storage->map, file_id); + mdbox_map_remove_file_id(storage->map, file_id); } dbox_file_unref(&file); } T_END; diff --git a/src/lib-storage/index/dbox-multi/mdbox-save.c b/src/lib-storage/index/dbox-multi/mdbox-save.c index 0958d1c264..807312ac5d 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-save.c +++ b/src/lib-storage/index/dbox-multi/mdbox-save.c @@ -33,10 +33,10 @@ struct mdbox_save_context { struct mdbox_sync_context *sync_ctx; struct dbox_file_append_context *cur_file_append; - struct dbox_map_append_context *append_ctx; + struct mdbox_map_append_context *append_ctx; ARRAY_TYPE(uint32_t) copy_map_uids; - struct dbox_map_transaction_context *map_trans; + struct mdbox_map_transaction_context *map_trans; ARRAY_DEFINE(mails, struct dbox_save_mail); }; @@ -56,8 +56,8 @@ mdbox_copy_file_get_file(struct mailbox_transaction_context *t, &data, &expunged); rec = data; - if (dbox_map_lookup(ctx->mbox->storage->map, rec->map_uid, - &file_id, offset_r) <= 0) + if (mdbox_map_lookup(ctx->mbox->storage->map, rec->map_uid, + &file_id, offset_r) <= 0) i_unreached(); return mdbox_file_init(ctx->mbox->storage, file_id); @@ -112,7 +112,7 @@ mdbox_save_alloc(struct mailbox_transaction_context *t) ctx->ctx.ctx.transaction = t; ctx->ctx.trans = t->itrans; ctx->mbox = mbox; - ctx->append_ctx = dbox_map_append_begin(mbox->storage->map); + ctx->append_ctx = mdbox_map_append_begin(mbox->storage->map); i_array_init(&ctx->mails, 32); t->save_ctx = &ctx->ctx.ctx; return t->save_ctx; @@ -135,9 +135,9 @@ int mdbox_save_begin(struct mail_save_context *_ctx, struct istream *input) st = i_stream_stat(input, FALSE); mail_size = st->st_size > 0 ? st->st_size : 0; } - if (dbox_map_append_next(ctx->append_ctx, mail_size, 0, - &ctx->cur_file_append, - &ctx->ctx.dbox_output) < 0) { + if (mdbox_map_append_next(ctx->append_ctx, mail_size, 0, + &ctx->cur_file_append, + &ctx->ctx.dbox_output) < 0) { ctx->ctx.failed = TRUE; return -1; } @@ -201,7 +201,7 @@ static int mdbox_save_finish_write(struct mail_save_context *_ctx) if (mdbox_save_mail_write_metadata(ctx, mails) < 0) ctx->ctx.failed = TRUE; else - dbox_map_append_finish(ctx->append_ctx); + mdbox_map_append_finish(ctx->append_ctx); } T_END; i_stream_unref(&ctx->ctx.input); @@ -251,8 +251,8 @@ int mdbox_transaction_save_commit_pre(struct mail_save_context *_ctx) /* assign map UIDs for newly saved messages. they're written to transaction log immediately within this function, but the map is left locked. */ - if (dbox_map_append_assign_map_uids(ctx->append_ctx, &first_map_uid, - &last_map_uid) < 0) { + if (mdbox_map_append_assign_map_uids(ctx->append_ctx, &first_map_uid, + &last_map_uid) < 0) { mdbox_transaction_save_rollback(_ctx); return -1; } @@ -285,9 +285,9 @@ int mdbox_transaction_save_commit_pre(struct mail_save_context *_ctx) /* increase map's refcount for copied mails */ if (array_is_created(&ctx->copy_map_uids)) { ctx->map_trans = - dbox_map_transaction_begin(mbox->storage->map, FALSE); - if (dbox_map_update_refcounts(ctx->map_trans, - &ctx->copy_map_uids, 1) < 0) { + mdbox_map_transaction_begin(mbox->storage->map, FALSE); + if (mdbox_map_update_refcounts(ctx->map_trans, + &ctx->copy_map_uids, 1) < 0) { mdbox_transaction_save_rollback(_ctx); return -1; } @@ -313,12 +313,12 @@ void mdbox_transaction_save_commit_post(struct mail_save_context *_ctx, /* finish writing the mailbox APPENDs */ if (mdbox_sync_finish(&ctx->sync_ctx, TRUE) == 0) { if (ctx->map_trans != NULL) - (void)dbox_map_transaction_commit(ctx->map_trans); + (void)mdbox_map_transaction_commit(ctx->map_trans); /* commit only updates the sync tail offset, everything else was already written at this point. */ - (void)dbox_map_append_commit(ctx->append_ctx); + (void)mdbox_map_append_commit(ctx->append_ctx); } - dbox_map_append_free(&ctx->append_ctx); + mdbox_map_append_free(&ctx->append_ctx); if (!ctx->mbox->storage->storage.storage.set->fsync_disable) { if (fdatasync_path(ctx->mbox->box.path) < 0) { @@ -336,9 +336,9 @@ void mdbox_transaction_save_rollback(struct mail_save_context *_ctx) if (!ctx->ctx.finished) mdbox_save_cancel(&ctx->ctx.ctx); if (ctx->append_ctx != NULL) - dbox_map_append_free(&ctx->append_ctx); + mdbox_map_append_free(&ctx->append_ctx); if (ctx->map_trans != NULL) - dbox_map_transaction_free(&ctx->map_trans); + mdbox_map_transaction_free(&ctx->map_trans); if (array_is_created(&ctx->copy_map_uids)) array_free(&ctx->copy_map_uids); diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index c9499d79ee..d37df55d5c 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -255,7 +255,7 @@ rebuild_add_missing_map_uids(struct mdbox_storage_rebuild_context *ctx, uint32_t next_uid) { struct mdbox_rebuild_msg **msgs; - struct dbox_map_mail_index_record rec; + struct mdbox_map_mail_index_record rec; unsigned int i, count; uint32_t seq; @@ -279,7 +279,7 @@ rebuild_add_missing_map_uids(struct mdbox_storage_rebuild_context *ctx, static int rebuild_apply_map(struct mdbox_storage_rebuild_context *ctx) { - struct dbox_map *map = ctx->storage->map; + struct mdbox_map *map = ctx->storage->map; const struct mail_index_header *hdr; struct mdbox_rebuild_msg *const *msgs, **pos; struct mdbox_rebuild_msg search_msg, *search_msgp = &search_msg; @@ -293,8 +293,8 @@ static int rebuild_apply_map(struct mdbox_storage_rebuild_context *ctx) msgs = array_get_modifiable(&ctx->msgs, &count); hdr = mail_index_get_header(ctx->sync_view); for (seq = 1; seq <= hdr->messages_count; seq++) { - if (dbox_map_view_lookup_rec(map, ctx->sync_view, - seq, &rec) < 0) + if (mdbox_map_view_lookup_rec(map, ctx->sync_view, + seq, &rec) < 0) return -1; /* look up the rebuild msg record for this message */ @@ -441,7 +441,7 @@ static void mdbox_header_update(struct dbox_sync_rebuild_context *rebuild_ctx, } /* update map's uid-validity */ - hdr.map_uid_validity = dbox_map_get_uid_validity(mbox->storage->map); + hdr.map_uid_validity = mdbox_map_get_uid_validity(mbox->storage->map); /* and write changes */ mail_index_update_header_ext(rebuild_ctx->trans, mbox->hdr_ext_id, 0, @@ -747,7 +747,7 @@ static int rebuild_finish(struct mdbox_storage_rebuild_context *ctx) ctx->rebuild_count++; mail_index_update_header_ext(ctx->trans, ctx->storage->map->map_ext_id, - offsetof(struct dbox_map_mail_index_header, rebuild_count), + offsetof(struct mdbox_map_mail_index_header, rebuild_count), &ctx->rebuild_count, sizeof(ctx->rebuild_count)); return 0; } @@ -809,7 +809,7 @@ static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx) uint32_t uid_validity; int ret = 0; - if (dbox_map_open_or_create(ctx->storage->map) < 0) + if (mdbox_map_open_or_create(ctx->storage->map) < 0) return -1; /* begin by locking the map, so that other processes can't try to @@ -833,7 +833,7 @@ static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx) i_warning("mdbox %s: rebuilding indexes", ctx->storage->storage_dir); - uid_validity = dbox_map_get_uid_validity(ctx->storage->map); + uid_validity = mdbox_map_get_uid_validity(ctx->storage->map); hdr = mail_index_get_header(ctx->sync_view); if (hdr->uid_validity != uid_validity) { mail_index_update_header(ctx->trans, diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index a36bb72e9b..7b8ffdddf5 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -58,7 +58,7 @@ mdbox_storage_create(struct mail_storage *_storage, struct mail_namespace *ns, "/"MDBOX_GLOBAL_DIR_NAME, NULL); i_array_init(&storage->open_files, 64); - storage->map = dbox_map_init(storage, ns->list, storage->storage_dir); + storage->map = mdbox_map_init(storage, ns->list, storage->storage_dir); return 0; } @@ -67,7 +67,7 @@ static void mdbox_storage_destroy(struct mail_storage *_storage) struct mdbox_storage *storage = (struct mdbox_storage *)_storage; mdbox_files_free(storage); - dbox_map_deinit(&storage->map); + mdbox_map_deinit(&storage->map); if (storage->to_close_unused_files != NULL) timeout_remove(&storage->to_close_unused_files); @@ -173,7 +173,7 @@ void mdbox_update_header(struct mdbox_mailbox *mbox, } new_hdr.map_uid_validity = - dbox_map_get_uid_validity(mbox->storage->map); + mdbox_map_get_uid_validity(mbox->storage->map); if (memcmp(&hdr, &new_hdr, sizeof(hdr)) != 0) { mail_index_update_header_ext(trans, mbox->hdr_ext_id, 0, &new_hdr, sizeof(new_hdr)); @@ -188,7 +188,7 @@ static int mdbox_write_index_header(struct mailbox *box, const struct mail_index_header *hdr; uint32_t uid_validity, uid_next; - if (dbox_map_open_or_create(mbox->storage->map) < 0) + if (mdbox_map_open_or_create(mbox->storage->map) < 0) return -1; hdr = mail_index_get_header(box->view); @@ -254,8 +254,8 @@ void mdbox_storage_set_corrupted(struct mdbox_storage *storage) storage->corrupted = TRUE; storage->corrupted_rebuild_count = (uint32_t)-1; - if (dbox_map_open(storage->map) > 0 && - dbox_map_refresh(storage->map) == 0) { + if (mdbox_map_open(storage->map) > 0 && + mdbox_map_refresh(storage->map) == 0) { storage->corrupted_rebuild_count = mdbox_map_get_rebuild_count(storage->map); } @@ -301,12 +301,12 @@ mdbox_mailbox_update(struct mailbox *box, const struct mailbox_update *update) static int mdbox_mailbox_unref_mails(struct mdbox_mailbox *mbox) { - struct dbox_map_transaction_context *map_trans; + struct mdbox_map_transaction_context *map_trans; const struct mail_index_header *hdr; uint32_t seq, map_uid; int ret = 0; - map_trans = dbox_map_transaction_begin(mbox->storage->map, FALSE); + map_trans = mdbox_map_transaction_begin(mbox->storage->map, FALSE); hdr = mail_index_get_header(mbox->box.view); for (seq = 1; seq <= hdr->messages_count; seq++) { if (mdbox_mail_lookup(mbox, mbox->box.view, seq, @@ -315,15 +315,15 @@ static int mdbox_mailbox_unref_mails(struct mdbox_mailbox *mbox) break; } - if (dbox_map_update_refcount(map_trans, map_uid, -1) < 0) { + if (mdbox_map_update_refcount(map_trans, map_uid, -1) < 0) { ret = -1; break; } } if (ret == 0) - ret = dbox_map_transaction_commit(map_trans); - dbox_map_transaction_free(&map_trans); + ret = mdbox_map_transaction_commit(map_trans); + mdbox_map_transaction_free(&map_trans); return ret; } diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.h b/src/lib-storage/index/dbox-multi/mdbox-storage.h index e08bc469f8..be39e69fe5 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.h +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h @@ -27,7 +27,7 @@ struct mdbox_storage { /* paths for storage directories */ const char *storage_dir, *alt_storage_dir; - struct dbox_map *map; + struct mdbox_map *map; ARRAY_DEFINE(open_files, struct mdbox_file *); struct timeout *to_close_unused_files; diff --git a/src/lib-storage/index/dbox-multi/mdbox-sync.c b/src/lib-storage/index/dbox-multi/mdbox-sync.c index 69463eda52..c23d0ffa62 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-sync.c +++ b/src/lib-storage/index/dbox-multi/mdbox-sync.c @@ -62,7 +62,7 @@ static int mdbox_sync_expunge(struct mdbox_sync_context *ctx, uint32_t seq, return -1; if (mdbox_mail_lookup(ctx->mbox, ctx->sync_view, seq, &map_uid) < 0) return -1; - if (dbox_map_update_refcount(ctx->map_trans, map_uid, -1) < 0) + if (mdbox_map_update_refcount(ctx->map_trans, map_uid, -1) < 0) return -1; return 0; } @@ -149,7 +149,7 @@ static int mdbox_sync_index(struct mdbox_sync_context *ctx) /* handle syncing records without map being locked. */ ctx->map_trans = - dbox_map_transaction_begin(ctx->mbox->storage->map, FALSE); + mdbox_map_transaction_begin(ctx->mbox->storage->map, FALSE); i_array_init(&ctx->expunged_seqs, 64); while (mail_index_sync_next(ctx->index_sync_ctx, &sync_rec)) { if ((ret = mdbox_sync_rec(ctx, &sync_rec)) < 0) @@ -159,7 +159,7 @@ static int mdbox_sync_index(struct mdbox_sync_context *ctx) /* write refcount changes to map index. map index is locked by the commit() and log head is updated, while tail is left behind. */ if (ret == 0) - ret = dbox_map_transaction_commit(ctx->map_trans); + ret = mdbox_map_transaction_commit(ctx->map_trans); /* write changes to mailbox index */ if (ret == 0) ret = dbox_sync_mark_expunges(ctx); @@ -167,8 +167,8 @@ static int mdbox_sync_index(struct mdbox_sync_context *ctx) /* finish the map changes and unlock the map. this also updates map's tail -> head. */ if (ret < 0) - dbox_map_transaction_set_failed(ctx->map_trans); - dbox_map_transaction_free(&ctx->map_trans); + mdbox_map_transaction_set_failed(ctx->map_trans); + mdbox_map_transaction_free(&ctx->map_trans); if (box->v.sync_notify != NULL) box->v.sync_notify(box, 0, 0); diff --git a/src/lib-storage/index/dbox-multi/mdbox-sync.h b/src/lib-storage/index/dbox-multi/mdbox-sync.h index 630303d41f..4a79896b75 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-sync.h +++ b/src/lib-storage/index/dbox-multi/mdbox-sync.h @@ -16,7 +16,7 @@ struct mdbox_sync_context { struct mail_index_sync_ctx *index_sync_ctx; struct mail_index_view *sync_view; struct mail_index_transaction *trans; - struct dbox_map_transaction_context *map_trans; + struct mdbox_map_transaction_context *map_trans; enum mdbox_sync_flags flags; ARRAY_TYPE(seq_range) expunged_seqs;