dovecot-2.0: dbox: If alt path is lost, fail with an error rathe...

dovecot at dovecot.org dovecot at dovecot.org
Thu Oct 21 18:33:32 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/099925543768
changeset: 12327:099925543768
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Oct 21 16:33:28 2010 +0100
description:
dbox: If alt path is lost, fail with an error rather than rebuilding indexes.
This could be simply because alt storage is unmounted at the time and
rebuilding would just lose messages. If this error happens unintentionally,
it's still possible to fix it with "doveadm force-resync".

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-file.c            |  26 +++++++++++++
 src/lib-storage/index/dbox-multi/mdbox-file.h            |   2 +
 src/lib-storage/index/dbox-multi/mdbox-mail.c            |   2 +-
 src/lib-storage/index/dbox-multi/mdbox-purge.c           |   2 +-
 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c |   4 +-
 src/lib-storage/index/dbox-single/sdbox-file.c           |  31 ++++++++++++++-
 src/lib-storage/index/dbox-single/sdbox-file.h           |   2 +
 src/lib-storage/index/dbox-single/sdbox-mail.c           |   4 +-
 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c   |   2 +-
 src/lib-storage/index/dbox-single/sdbox-sync.c           |   2 +-
 10 files changed, 67 insertions(+), 10 deletions(-)

diffs (205 lines):

diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-multi/mdbox-file.c
--- a/src/lib-storage/index/dbox-multi/mdbox-file.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-file.c	Thu Oct 21 16:33:28 2010 +0100
@@ -183,6 +183,32 @@
 	return mdbox_file_init_full(storage, 0, TRUE);
 }
 
+int mdbox_file_open(struct dbox_file *file, bool *deleted_r)
+{
+	struct mdbox_file *mfile = (struct mdbox_file *)file;
+	struct stat st;
+	int ret;
+
+	if ((ret = dbox_file_open(file, deleted_r)) <= 0 || !*deleted_r)
+		return ret;
+
+	/* file appears to be deleted. check if the alt path root even exists
+	   to avoid reindexing errors if alt path isn't mounted currently */
+	if (stat(mfile->storage->alt_storage_dir, &st) == 0)
+		return 1;
+	else if (errno == ENOENT) {
+		mail_storage_set_critical(&file->storage->storage,
+			"mdbox: User's alt path lost: %s",
+			mfile->storage->alt_storage_dir);
+		return -1;
+	} else {
+		mail_storage_set_critical(&file->storage->storage,
+			"stat(%s) failed: %m", mfile->storage->alt_storage_dir);
+		return -1;
+	}
+}
+
+
 int mdbox_file_assign_file_id(struct mdbox_file *file, uint32_t file_id)
 {
 	const char *old_path;
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-multi/mdbox-file.h
--- a/src/lib-storage/index/dbox-multi/mdbox-file.h	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-file.h	Thu Oct 21 16:33:28 2010 +0100
@@ -16,6 +16,8 @@
 struct dbox_file *
 mdbox_file_init_new_alt(struct mdbox_storage *storage);
 
+int mdbox_file_open(struct dbox_file *file, bool *deleted_r);
+
 /* Assign file ID for a newly created file. */
 int mdbox_file_assign_file_id(struct mdbox_file *file, uint32_t file_id);
 
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-multi/mdbox-mail.c
--- a/src/lib-storage/index/dbox-multi/mdbox-mail.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c	Thu Oct 21 16:33:28 2010 +0100
@@ -129,7 +129,7 @@
 
 		if (!dbox_file_is_open(mail->open_file))
 			mail->imail.mail.stats_open_lookup_count++;
-		if (dbox_file_open(mail->open_file, &deleted) <= 0)
+		if (mdbox_file_open(mail->open_file, &deleted) <= 0)
 			return -1;
 		if (deleted) {
 			/* either it's expunged now or moved to another file. */
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-multi/mdbox-purge.c
--- a/src/lib-storage/index/dbox-multi/mdbox-purge.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c	Thu Oct 21 16:33:28 2010 +0100
@@ -658,7 +658,7 @@
 	while (ret == 0 &&
 	       seq_range_array_iter_nth(&iter, i++, &file_id)) T_BEGIN {
 		file = mdbox_file_init(storage, file_id);
-		if (dbox_file_open(file, &deleted) > 0 && !deleted) {
+		if (mdbox_file_open(file, &deleted) > 0 && !deleted) {
 			if (mdbox_file_purge(ctx, file) < 0)
 				ret = -1;
 		} else {
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Oct 21 16:33:28 2010 +0100
@@ -277,7 +277,7 @@
 	seq_range_array_add(&ctx->seen_file_ids, 0, file_id);
 
 	file = mdbox_file_init(ctx->storage, file_id);
-	if ((ret = dbox_file_open(file, &deleted)) > 0 && !deleted)
+	if ((ret = mdbox_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);
@@ -614,7 +614,7 @@
 	/* first see if message contains the mailbox it was originally
 	   saved to */
 	file = mdbox_file_init(ctx->storage, msg->file_id);
-	ret = dbox_file_open(file, &deleted);
+	ret = mdbox_file_open(file, &deleted);
 	if (ret > 0 && !deleted)
 		ret = dbox_file_seek(file, msg->offset);
 	if (ret > 0 && !deleted && dbox_file_metadata_read(file) > 0) {
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-single/sdbox-file.c
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Thu Oct 21 16:33:28 2010 +0100
@@ -73,6 +73,33 @@
 	dbox_file_free(file);
 }
 
+int sdbox_file_open(struct dbox_file *file, bool *deleted_r)
+{
+	struct sdbox_file *sfile = (struct sdbox_file *)file;
+	struct stat st;
+	const char *alt_root;
+	int ret;
+
+	if ((ret = dbox_file_open(file, deleted_r)) <= 0 || !*deleted_r)
+		return ret;
+
+	/* file appears to be deleted. check if the alt path root even exists
+	   to avoid reindexing errors if alt path isn't mounted currently */
+	alt_root = mailbox_list_get_path(sfile->mbox->box.list, NULL,
+					 MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
+	if (stat(alt_root, &st) == 0)
+		return 1;
+	else if (errno == ENOENT) {
+		mail_storage_set_critical(&file->storage->storage,
+			"sdbox: User's alt path lost: %s", alt_root);
+		return -1;
+	} else {
+		mail_storage_set_critical(&file->storage->storage,
+			"stat(%s) failed: %m", alt_root);
+		return -1;
+	}
+}
+
 int sdbox_file_get_attachments(struct dbox_file *file, const char **extrefs_r)
 {
 	const char *line;
@@ -82,7 +109,7 @@
 	*extrefs_r = NULL;
 
 	/* read the metadata */
-	ret = dbox_file_open(file, &deleted);
+	ret = sdbox_file_open(file, &deleted);
 	if (ret > 0) {
 		if (deleted)
 			return 0;
@@ -365,7 +392,7 @@
 
 	/* file was successfully moved - reopen it */
 	dbox_file_close(file);
-	if (dbox_file_open(file, &deleted) <= 0) {
+	if (sdbox_file_open(file, &deleted) <= 0) {
 		mail_storage_set_critical(storage,
 			"dbox_file_move(%s): reopening file failed", dest_path);
 		return -1;
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-single/sdbox-file.h
--- a/src/lib-storage/index/dbox-single/sdbox-file.h	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-file.h	Thu Oct 21 16:33:28 2010 +0100
@@ -19,6 +19,8 @@
 struct dbox_file *sdbox_file_create(struct sdbox_mailbox *mbox);
 void sdbox_file_free(struct dbox_file *file);
 
+int sdbox_file_open(struct dbox_file *file, bool *deleted_r);
+
 /* Get file's extrefs metadata. */
 int sdbox_file_get_attachments(struct dbox_file *file, const char **extrefs_r);
 /* Returns attachment path for this file, given the source path. The result is
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-single/sdbox-mail.c
--- a/src/lib-storage/index/dbox-single/sdbox-mail.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-mail.c	Thu Oct 21 16:33:28 2010 +0100
@@ -43,7 +43,7 @@
 		mail->open_file->refcount++;
 
 		/* it doesn't have input stream yet */
-		ret = dbox_file_open(mail->open_file, &deleted);
+		ret = sdbox_file_open(mail->open_file, &deleted);
 		i_assert(ret > 0);
 		return TRUE;
 	}
@@ -63,7 +63,7 @@
 	if (!sdbox_mail_file_set(mail)) {
 		if (!dbox_file_is_open(mail->open_file))
 			mail->imail.mail.stats_open_lookup_count++;
-		if (dbox_file_open(mail->open_file, &deleted) <= 0)
+		if (sdbox_file_open(mail->open_file, &deleted) <= 0)
 			return -1;
 		if (deleted) {
 			sdbox_mail_set_expunged(mail);
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Thu Oct 21 16:33:28 2010 +0100
@@ -32,7 +32,7 @@
 	bool deleted;
 	int ret;
 
-	if ((ret = dbox_file_open(file, &deleted)) > 0) {
+	if ((ret = sdbox_file_open(file, &deleted)) > 0) {
 		if (deleted)
 			return 0;
 		ret = dbox_file_seek(file, 0);
diff -r 760d84e274ad -r 099925543768 src/lib-storage/index/dbox-single/sdbox-sync.c
--- a/src/lib-storage/index/dbox-single/sdbox-sync.c	Thu Oct 21 16:12:13 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-sync.c	Thu Oct 21 16:33:28 2010 +0100
@@ -18,7 +18,7 @@
 	if (move_to_alt != dbox_file_is_in_alt(file)) {
 		/* move the file. if it fails, nothing broke so
 		   don't worry about it. */
-		if (dbox_file_open(file, &deleted) > 0 && !deleted)
+		if (sdbox_file_open(file, &deleted) > 0 && !deleted)
 			(void)sdbox_file_move(file, move_to_alt);
 	}
 }


More information about the dovecot-cvs mailing list