From: Timo Sirainen Date: Fri, 23 Sep 2011 12:01:23 +0000 (+0300) Subject: file_dotlock: Don't warn about changed mtime when it's 1 second. X-Git-Tag: 2.1.beta1~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbebb157d18f7b98b323260bdff96d0defa4d2ef;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib/file-dotlock.c b/src/lib/file-dotlock.c index 314ebbf5c0..916c314073 100644 --- a/src/lib/file-dotlock.c +++ b/src/lib/file-dotlock.c @@ -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 void dotlock_replaced_warning(struct dotlock *dotlock, bool deleted) } } +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 @@ int file_dotlock_delete(struct dotlock **dotlock_p) 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,