diff src/lib-index/mail-index.c @ 6797:a59deefc552f HEAD

NFS attribute cache flushing fixes. nfs_flush_attr_cache() takes now flush_dir parameter and nfs_flush_attr_cache_fd() returns FALSE if file handle is already stale.
author Timo Sirainen <tss@iki.fi>
date Wed, 14 Nov 2007 23:52:33 +0200
parents b3de2053937f
children 256725979152
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Wed Nov 14 23:43:42 2007 +0200
+++ b/src/lib-index/mail-index.c	Wed Nov 14 23:52:33 2007 +0200
@@ -248,6 +248,9 @@
 	i_assert(index->fd == -1);
 	i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
 
+	if (index->nfs_flush)
+		nfs_flush_attr_cache(index->filepath, TRUE);
+
         /* Note that our caller must close index->fd by itself. */
 	if (index->readonly)
 		errno = EACCES;
@@ -470,6 +473,22 @@
 	if (index->fd == -1)
 		return mail_index_try_open_only(index);
 
+	if (index->nfs_flush)
+		nfs_flush_attr_cache(index->filepath, TRUE);
+	if (nfs_safe_stat(index->filepath, &st2) < 0) {
+		if (errno == ENOENT)
+			return 0;
+
+		return mail_index_set_syscall_error(index, "stat()");
+	}
+
+	if (index->nfs_flush) {
+		if (!nfs_flush_attr_cache_fd(index->filepath, index->fd)) {
+			/* deleted/recreated, reopen */
+			mail_index_close_file(index);
+			return mail_index_try_open_only(index);
+		}
+	}
 	if (fstat(index->fd, &st1) < 0) {
 		if (errno != ESTALE)
 			return mail_index_set_syscall_error(index, "fstat()");
@@ -478,15 +497,6 @@
 		return mail_index_try_open_only(index);
 	}
 
-	if (index->nfs_flush)
-		nfs_flush_attr_cache(index->filepath);
-	if (nfs_safe_stat(index->filepath, &st2) < 0) {
-		if (errno == ENOENT)
-			return 0;
-
-		return mail_index_set_syscall_error(index, "stat()");
-	}
-
 	if (st1.st_ino == st2.st_ino && CMP_DEV_T(st1.st_dev, st2.st_dev)) {
 		/* the same file */
 		return 1;