dovecot-2.1: sdbox: Use mail_index_set_ext_init_data() to simpli...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Feb 9 00:41:49 EET 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/1e2e69ea3095
changeset: 14080:1e2e69ea3095
user: Timo Sirainen <tss at iki.fi>
date: Thu Feb 09 00:41:25 2012 +0200
description:
sdbox: Use mail_index_set_ext_init_data() to simplify opening mailboxes.
Now the initial mailbox index can be created with the necessary sdbox
header. If the header doesn't exist when opening a mailbox, it's guaranteed
to be corrupted.
diffstat:
src/lib-storage/index/dbox-single/sdbox-storage.c | 61 ++++++++++-------
src/lib-storage/index/dbox-single/sdbox-storage.h | 3 -
src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c | 3 +-
src/lib-storage/index/index-storage.c | 2 +-
src/lib-storage/index/index-storage.h | 1 +
5 files changed, 41 insertions(+), 29 deletions(-)
diffs (146 lines):
diff -r 2ab26bb55346 -r 1e2e69ea3095 src/lib-storage/index/dbox-single/sdbox-storage.c
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c Thu Feb 09 00:39:52 2012 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c Thu Feb 09 00:41:25 2012 +0200
@@ -138,15 +138,23 @@
} else {
memset(hdr, 0, sizeof(*hdr));
memcpy(hdr, data, I_MIN(data_size, sizeof(*hdr)));
- ret = 0;
+ if (guid_128_is_empty(hdr->mailbox_guid))
+ ret = -1;
+ else {
+ /* data is valid. remember it in case mailbox
+ is being reset */
+ mail_index_set_ext_init_data(mbox->box.index,
+ mbox->hdr_ext_id,
+ hdr, sizeof(*hdr));
+ }
}
mail_index_view_close(&view);
return ret;
}
-void sdbox_update_header(struct sdbox_mailbox *mbox,
- struct mail_index_transaction *trans,
- const struct mailbox_update *update)
+static void sdbox_update_header(struct sdbox_mailbox *mbox,
+ struct mail_index_transaction *trans,
+ const struct mailbox_update *update)
{
struct sdbox_index_header hdr, new_hdr;
@@ -263,16 +271,34 @@
sdbox_set_mailbox_corrupted(&file->mbox->box);
}
+static int sdbox_mailbox_alloc_index(struct sdbox_mailbox *mbox)
+{
+ struct sdbox_index_header hdr;
+
+ if (index_storage_mailbox_alloc_index(&mbox->box) < 0)
+ return -1;
+
+ mbox->hdr_ext_id =
+ mail_index_ext_register(mbox->box.index, "dbox-hdr",
+ sizeof(struct sdbox_index_header), 0, 0);
+ /* set the initialization data in case the mailbox is created */
+ memset(&hdr, 0, sizeof(hdr));
+ guid_128_generate(hdr.mailbox_guid);
+ mail_index_set_ext_init_data(mbox->box.index, mbox->hdr_ext_id,
+ &hdr, sizeof(hdr));
+ return 0;
+}
+
static int sdbox_mailbox_open(struct mailbox *box)
{
struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
struct sdbox_index_header hdr;
+ if (sdbox_mailbox_alloc_index(mbox) < 0)
+ return -1;
+
if (dbox_mailbox_open(box) < 0)
return -1;
- mbox->hdr_ext_id =
- mail_index_ext_register(box->index, "dbox-hdr",
- sizeof(struct sdbox_index_header), 0, 0);
if (box->creating) {
/* wait for mailbox creation to initialize the index */
@@ -286,23 +312,10 @@
/* get/generate mailbox guid */
if (sdbox_read_header(mbox, &hdr, FALSE) < 0) {
- /* it's possible that this mailbox is just now being created
- by another process. lock it first and see if the header is
- available then. */
- struct mail_index_sync_ctx *sync_ctx;
- struct mail_index_view *view;
- struct mail_index_transaction *trans;
-
- if (mail_index_sync_begin(box->index, &sync_ctx,
- &view, &trans, 0) > 0)
- (void)mail_index_sync_commit(&sync_ctx);
-
- if (sdbox_read_header(mbox, &hdr, TRUE) < 0) {
- /* looks like the mailbox is corrupted */
- (void)sdbox_sync(mbox, SDBOX_SYNC_FLAG_FORCE);
- if (sdbox_read_header(mbox, &hdr, TRUE) < 0)
- memset(&hdr, 0, sizeof(hdr));
- }
+ /* looks like the mailbox is corrupted */
+ (void)sdbox_sync(mbox, SDBOX_SYNC_FLAG_FORCE);
+ if (sdbox_read_header(mbox, &hdr, TRUE) < 0)
+ memset(&hdr, 0, sizeof(hdr));
}
if (guid_128_is_empty(hdr.mailbox_guid)) {
diff -r 2ab26bb55346 -r 1e2e69ea3095 src/lib-storage/index/dbox-single/sdbox-storage.h
--- a/src/lib-storage/index/dbox-single/sdbox-storage.h Thu Feb 09 00:39:52 2012 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.h Thu Feb 09 00:41:25 2012 +0200
@@ -39,9 +39,6 @@
uint32_t dbox_get_uidvalidity_next(struct mailbox_list *list);
int sdbox_read_header(struct sdbox_mailbox *mbox,
struct sdbox_index_header *hdr, bool log_error);
-void sdbox_update_header(struct sdbox_mailbox *mbox,
- struct mail_index_transaction *trans,
- const struct mailbox_update *update);
void sdbox_set_mailbox_corrupted(struct mailbox *box);
struct mail_save_context *
diff -r 2ab26bb55346 -r 1e2e69ea3095 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c Thu Feb 09 00:39:52 2012 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c Thu Feb 09 00:41:25 2012 +0200
@@ -139,7 +139,8 @@
guid_128_generate(hdr.mailbox_guid);
if (++hdr.rebuild_count == 0)
hdr.rebuild_count = 1;
- mail_index_update_header_ext(ctx->trans, mbox->hdr_ext_id, 0,
+ /* mailbox is being reset. this gets written directly there */
+ mail_index_set_ext_init_data(ctx->box->index, mbox->hdr_ext_id,
&hdr, sizeof(hdr));
}
diff -r 2ab26bb55346 -r 1e2e69ea3095 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c Thu Feb 09 00:39:52 2012 +0200
+++ b/src/lib-storage/index/index-storage.c Thu Feb 09 00:41:25 2012 +0200
@@ -191,7 +191,7 @@
return 0;
}
-static int index_storage_mailbox_alloc_index(struct mailbox *box)
+int index_storage_mailbox_alloc_index(struct mailbox *box)
{
if (box->index != NULL)
return 0;
diff -r 2ab26bb55346 -r 1e2e69ea3095 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h Thu Feb 09 00:39:52 2012 +0200
+++ b/src/lib-storage/index/index-storage.h Thu Feb 09 00:41:25 2012 +0200
@@ -55,6 +55,7 @@
unsigned int secs_left);
void index_storage_lock_notify_reset(struct mailbox *box);
+int index_storage_mailbox_alloc_index(struct mailbox *box);
void index_storage_mailbox_alloc(struct mailbox *box, const char *vname,
enum mailbox_flags flags,
const char *index_prefix);
More information about the dovecot-cvs
mailing list