]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
file_dotlock: Don't warn about changed mtime when it's 1 second.
authorTimo Sirainen <tss@iki.fi>
Fri, 23 Sep 2011 12:01:23 +0000 (15:01 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 23 Sep 2011 12:01:23 +0000 (15:01 +0300)
This is mainly to avoid bogus warnings with NFS and its caching.

src/lib/file-dotlock.c

index 314ebbf5c0b9eff1bffeb04f28dcd23a1f1ac62c..916c314073abde9711428f5c7c664fbb9b80d0f8 100644 (file)
 /* 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,