[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-private.h, 1.56.2.10, 1.56.2.11 mbox-sync-rewrite.c, 1.62.2.16, 1.62.2.17 mbox-sync.c, 1.181.2.18, 1.181.2.19

tss at dovecot.org tss at dovecot.org
Fri Apr 6 20:53:37 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv2181

Modified Files:
      Tag: branch_1_0
	mbox-sync-private.h mbox-sync-rewrite.c mbox-sync.c 
Log Message:
Give "mbox file was modified while we were syncing" error only if we detect
some problems in the mbox file. The check can't be trusted with NFS.



Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.56.2.10
retrieving revision 1.56.2.11
diff -u -d -r1.56.2.10 -r1.56.2.11
--- mbox-sync-private.h	21 Mar 2007 21:57:13 -0000	1.56.2.10
+++ mbox-sync-private.h	6 Apr 2007 17:53:35 -0000	1.56.2.11
@@ -139,6 +139,7 @@
 	unsigned int delay_writes:1;
 	unsigned int renumber_uids:1;
 	unsigned int moved_offsets:1;
+	unsigned int ext_modified:1;
 };
 
 int mbox_sync(struct mbox_mailbox *mbox, enum mbox_sync_flags flags);
@@ -162,8 +163,10 @@
 				 struct mbox_sync_mail *mail,
 				 bool *keywords_changed_r);
 int mbox_sync_seek(struct mbox_sync_context *sync_ctx, uoff_t from_offset);
-bool mbox_sync_file_is_ext_modified(struct mbox_sync_context *sync_ctx);
+bool mbox_sync_file_is_ext_modified(struct mbox_sync_context *sync_ctx,
+				    bool give_error);
 void mbox_sync_file_updated(struct mbox_sync_context *sync_ctx, bool dirty);
+void mbox_sync_ext_modify_warning(struct mbox_sync_context *sync_ctx);
 int mbox_move(struct mbox_sync_context *sync_ctx,
 	      uoff_t dest, uoff_t source, uoff_t size);
 void mbox_sync_move_buffer(struct mbox_sync_mail_context *ctx,

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.62.2.16
retrieving revision 1.62.2.17
diff -u -d -r1.62.2.16 -r1.62.2.17
--- mbox-sync-rewrite.c	21 Mar 2007 21:57:13 -0000	1.62.2.16
+++ mbox-sync-rewrite.c	6 Apr 2007 17:53:35 -0000	1.62.2.17
@@ -44,6 +44,7 @@
         if (ret == (off_t)size)
 		ret = 0;
 	else if (ret >= 0) {
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"mbox_move(%"PRIuUOFF_T", %"PRIuUOFF_T", %"PRIuUOFF_T
 			") moved only %"PRIuUOFF_T" bytes in mbox file %s",
@@ -415,7 +416,7 @@
 		if (need_space != (uoff_t)-mails[idx].space) {
 			/* this check works only if we're doing the first
 			   write, or if the file size was changed externally */
-			if (mbox_sync_file_is_ext_modified(sync_ctx))
+			if (mbox_sync_file_is_ext_modified(sync_ctx, TRUE))
 				return -1;
 
 			i_panic("mbox %s: seq=%u uid=%u uid_broken=%d "

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.181.2.18
retrieving revision 1.181.2.19
diff -u -d -r1.181.2.18 -r1.181.2.19
--- mbox-sync.c	23 Mar 2007 02:46:16 -0000	1.181.2.18
+++ mbox-sync.c	6 Apr 2007 17:53:35 -0000	1.181.2.19
@@ -65,6 +65,7 @@
 int mbox_sync_seek(struct mbox_sync_context *sync_ctx, uoff_t from_offset)
 {
 	if (istream_raw_mbox_seek(sync_ctx->input, from_offset) < 0) {
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"Unexpectedly lost From-line at offset %"PRIuUOFF_T
 			" from mbox file %s", from_offset,
@@ -74,7 +75,8 @@
 	return 0;
 }
 
-bool mbox_sync_file_is_ext_modified(struct mbox_sync_context *sync_ctx)
+bool mbox_sync_file_is_ext_modified(struct mbox_sync_context *sync_ctx,
+				    bool give_error)
 {
 	struct stat st;
 
@@ -92,9 +94,15 @@
 	      || st.st_mtim.tv_nsec != sync_ctx->last_stat.st_mtim.tv_nsec
 #endif
 	     ))) {
-		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
-			"mbox file %s was modified while we were syncing, "
-			"check your locking settings", sync_ctx->mbox->path);
+		sync_ctx->ext_modified = TRUE;
+		if (!give_error) {
+			/* This check can't be trusted with NFS, so don't give
+			   an error yet. Just mark the sync as possibly broken,
+			   and if we do see a problem later then tell about
+			   this. */
+			return FALSE;
+		}
+		mbox_sync_ext_modify_warning(sync_ctx);
 		return TRUE;
 	}
 
@@ -114,6 +122,16 @@
 	i_stream_sync(sync_ctx->input);
 }
 
+void mbox_sync_ext_modify_warning(struct mbox_sync_context *sync_ctx)
+{
+	if (!sync_ctx->ext_modified)
+		return;
+
+	mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
+		"mbox file %s was modified while we were syncing, "
+		"check your locking settings", sync_ctx->mbox->path);
+}
+
 static void mbox_sync_array_delete_to(array_t *syncs_arr, uint32_t last_uid)
 {
 	ARRAY_SET_TYPE(syncs_arr, struct mail_index_sync_rec);
@@ -339,6 +357,7 @@
 
 	if (rec == NULL && uid < sync_ctx->idx_next_uid) {
 		/* this UID was already in index and it was expunged */
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"mbox sync: Expunged message reappeared in mailbox %s "
 			"(UID %u < %u, seq=%u, idx_msgs=%u)",
@@ -347,6 +366,7 @@
 		ret = 0; rec = NULL;
 	} else if (rec != NULL && rec->uid != uid) {
 		/* new UID in the middle of the mailbox - shouldn't happen */
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"mbox sync: UID inserted in the middle of mailbox %s "
 			"(%u > %u, seq=%u, idx_msgs=%u)", sync_ctx->mbox->path,
@@ -636,6 +656,7 @@
 		return -1;
 	}
 	if (ret == 0) {
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"X-IMAPbase uid-last unexpectedly points outside "
 			"mbox file %s", sync_ctx->mbox->path);
@@ -651,6 +672,7 @@
 	}
 
 	if (uid_last != sync_ctx->base_uid_last) {
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"X-IMAPbase uid-last unexpectedly lost in mbox file %s",
 			sync_ctx->mbox->path);
@@ -892,7 +914,7 @@
 		extra_space = sync_ctx->space_diff;
 	}
 
-	if (mbox_sync_file_is_ext_modified(sync_ctx))
+	if (mbox_sync_file_is_ext_modified(sync_ctx, FALSE))
 		return -1;
 
 	if (mbox_sync_rewrite(sync_ctx,
@@ -940,6 +962,7 @@
 		if (ret == 0) {
 			if (istream_raw_mbox_seek(mbox->mbox_stream,
 						  old_offset) < 0) {
+				mbox_sync_ext_modify_warning(sync_ctx);
 				mail_storage_set_critical(
 					STORAGE(mbox->storage),
 					"Error seeking back to original "
@@ -998,6 +1021,7 @@
 
 		if (istream_raw_mbox_seek(sync_ctx->mbox->mbox_stream,
 					  st->st_size) < 0) {
+			mbox_sync_ext_modify_warning(sync_ctx);
 			mail_storage_set_critical(
 				STORAGE(sync_ctx->mbox->storage),
 				"Error seeking to end of mbox file %s",
@@ -1111,6 +1135,7 @@
 			if (sync_ctx->mbox->mbox_sync_dirty)
 				return 0;
 
+			mbox_sync_ext_modify_warning(sync_ctx);
 			mail_storage_set_critical(
 				STORAGE(sync_ctx->mbox->storage),
 				"UIDs broken with partial sync in mbox file %s",
@@ -1229,7 +1254,8 @@
 		} else if (sync_ctx->expunged_space > 0) {
 			if (!expunged) {
 				/* move the body */
-				if (mbox_sync_file_is_ext_modified(sync_ctx))
+				if (mbox_sync_file_is_ext_modified(sync_ctx,
+								   FALSE))
 					return -1;
 
 				if (mbox_move(sync_ctx,
@@ -1334,6 +1360,7 @@
 	}
 	file_size = st->st_size;
 	if (file_size < sync_ctx->file_input->v_offset) {
+		mbox_sync_ext_modify_warning(sync_ctx);
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"file size unexpectedly shrinked in mbox file %s "
 			"(%"PRIuUOFF_T" vs %"PRIuUOFF_T")",
@@ -1361,7 +1388,7 @@
 
 		i_assert(sync_ctx->space_diff < 0);
 
-		if (mbox_sync_file_is_ext_modified(sync_ctx))
+		if (mbox_sync_file_is_ext_modified(sync_ctx, FALSE))
 			return -1;
 
 		if (file_set_size(sync_ctx->write_fd,
@@ -1392,7 +1419,7 @@
 	if (sync_ctx->expunged_space > 0) {
 		i_assert(sync_ctx->write_fd != -1);
 
-		if (mbox_sync_file_is_ext_modified(sync_ctx))
+		if (mbox_sync_file_is_ext_modified(sync_ctx, FALSE))
 			return -1;
 
 		/* copy trailer, then truncate the file */
@@ -1544,6 +1571,7 @@
 	sync_ctx->space_diff = 0;
 
 	sync_ctx->dest_first_mail = TRUE;
+	sync_ctx->ext_modified = FALSE;
 }
 
 static int mbox_sync_do(struct mbox_sync_context *sync_ctx,



More information about the dovecot-cvs mailing list