dovecot-2.1: file_dotlock: Don't warn about changed mtime when i...

dovecot at dovecot.org dovecot at dovecot.org
Fri Sep 23 15:01:33 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/fecd095394b6
changeset: 13550:fecd095394b6
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Sep 23 15:01:23 2011 +0300
description:
file_dotlock: Don't warn about changed mtime when it's 1 second.
This is mainly to avoid bogus warnings with NFS and its caching.

diffstat:

 src/lib/file-dotlock.c |  20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diffs (44 lines):

diff -r b3111bbbaf22 -r fecd095394b6 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c	Fri Sep 23 14:52:46 2011 +0300
+++ b/src/lib/file-dotlock.c	Fri Sep 23 15:01:23 2011 +0300
@@ -33,6 +33,10 @@
 /* Maximum difference between current time and create file's ctime before
    logging a warning. Should be less than a second in normal operation. */
 #define MAX_TIME_DIFF 30
+/* NFS may return a cached mtime in stat(). A later non-cached stat() may
+   return a slightly different mtime. Allow the difference to be this much
+   and still consider it to be the same mtime. */
+#define FILE_DOTLOCK_MAX_STAT_MTIME_DIFF 1
 
 struct dotlock {
 	struct dotlock_settings settings;
@@ -699,6 +703,19 @@
 	}
 }
 
+static bool file_dotlock_has_mtime_changed(time_t t1, time_t t2)
+{
+	time_t diff;
+
+	if (t1 == t2)
+		return FALSE;
+
+	/* with NFS t1 may have been looked up from local cache.
+	   allow it to be a little bit different. */
+	diff = t1 > t2 ? t1-t2 : t2-t1;
+	return diff <= FILE_DOTLOCK_MAX_STAT_MTIME_DIFF;
+}
+
 int file_dotlock_delete(struct dotlock **dotlock_p)
 {
 	struct dotlock *dotlock;
@@ -729,7 +746,8 @@
 		return 0;
 	}
 
-	if (dotlock->mtime != st.st_mtime && dotlock->fd == -1) {
+	if (file_dotlock_has_mtime_changed(dotlock->mtime, st.st_mtime) &&
+	    dotlock->fd == -1) {
 		i_warning("Our dotlock file %s was modified (%s vs %s), "
 			  "assuming it wasn't overridden (kept it %d secs)",
 			  lock_path,


More information about the dovecot-cvs mailing list