changeset 5974:b88278b5d8d3 HEAD

Flush NFS caches when needed.
author Timo Sirainen <tss@iki.fi>
date Fri, 13 Jul 2007 00:05:44 +0300
parents fe9da9c92cf4
children 78fe45cdc192
files src/lib-storage/index/maildir/maildir-keywords.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/mbox/mbox-lock.c src/lib-storage/index/mbox/mbox-sync.c
diffstat 4 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-keywords.c	Thu Jul 12 23:56:13 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-keywords.c	Fri Jul 13 00:05:44 2007 +0300
@@ -12,6 +12,7 @@
 #include "istream.h"
 #include "file-dotlock.h"
 #include "write-full.h"
+#include "nfs-workarounds.h"
 #include "maildir-storage.h"
 #include "maildir-uidlist.h"
 #include "maildir-keywords.h"
@@ -97,7 +98,11 @@
            we rely on stat()'s timestamp and don't bother handling ESTALE
            errors. */
 
-	if (stat(mk->path, &st) < 0) {
+	if ((mk->mbox->storage->storage.flags &
+	     MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0)
+		nfs_flush_attr_cache(mk->path);
+
+	if (nfs_safe_stat(mk->path, &st) < 0) {
 		if (errno == ENOENT) {
 			maildir_keywords_clear(mk);
 			mk->synced = TRUE;
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Thu Jul 12 23:56:13 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Fri Jul 13 00:05:44 2007 +0300
@@ -575,7 +575,9 @@
 
 	*recreated_r = FALSE;
 
-	/* FIXME: nfs attribute cache flush */
+	if ((storage->flags & MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0)
+		nfs_flush_attr_cache(uidlist->path);
+
 	if (nfs_safe_stat(uidlist->path, &st) < 0) {
 		if (errno != ENOENT) {
 			mail_storage_set_critical(storage,
--- a/src/lib-storage/index/mbox/mbox-lock.c	Thu Jul 12 23:56:13 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Fri Jul 13 00:05:44 2007 +0300
@@ -1,6 +1,7 @@
-/* Copyright (C) 2002 Timo Sirainen */
+/* Copyright (C) 2002-2007 Timo Sirainen */
 
 #include "lib.h"
+#include "nfs-workarounds.h"
 #include "mail-index-private.h"
 #include "mbox-storage.h"
 #include "mbox-file.h"
@@ -43,6 +44,7 @@
 
 	int lock_type;
 	bool dotlock_last_stale;
+	bool fcntl_locked;
 };
 
 struct mbox_lock_data {
@@ -165,7 +167,10 @@
 		return 0;
 
 	if (mbox->mbox_fd != -1) {
-		if (stat(mbox->path, &st) < 0) {
+		if ((mbox->storage->storage.flags &
+		     MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0)
+			nfs_flush_attr_cache(mbox->path);
+		if (nfs_safe_stat(mbox->path, &st) < 0) {
 			mbox_set_syscall_error(mbox, "stat()");
 			return -1;
 		}
@@ -421,6 +426,7 @@
 	}
 
 	alarm(0);
+	ctx->fcntl_locked = TRUE;
 	return 1;
 }
 
@@ -451,13 +457,16 @@
 	return ret;
 }
 
-static int mbox_update_locking(struct mbox_mailbox *mbox, int lock_type)
+static int mbox_update_locking(struct mbox_mailbox *mbox, int lock_type,
+			       bool *fcntl_locked_r)
 {
 	struct mbox_lock_context ctx;
 	time_t max_wait_time;
 	int ret, i;
 	bool drop_locks;
 
+	*fcntl_locked_r = FALSE;
+
         index_storage_lock_notify_reset(&mbox->ibox);
 
 	if (!lock_settings_initialized)
@@ -513,12 +522,14 @@
 		mbox->mbox_lock_type = F_RDLCK;
 	}
 
+	*fcntl_locked_r = ctx.fcntl_locked;
 	return 1;
 }
 
 int mbox_lock(struct mbox_mailbox *mbox, int lock_type,
 	      unsigned int *lock_id_r)
 {
+	bool fcntl_locked;
 	int ret;
 
 	/* allow only unlock -> shared/exclusive or exclusive -> shared */
@@ -529,10 +540,17 @@
 	i_assert(mbox->ibox.index->lock_type != F_WRLCK);
 
 	if (mbox->mbox_lock_type == F_UNLCK) {
-		ret = mbox_update_locking(mbox, lock_type);
+		ret = mbox_update_locking(mbox, lock_type, &fcntl_locked);
 		if (ret <= 0)
 			return ret;
 
+		if ((mbox->storage->storage.flags &
+		     MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0) {
+			nfs_flush_read_cache(mbox->path, mbox->mbox_fd,
+					     fcntl_locked ? lock_type : F_UNLCK,
+					     fcntl_locked);
+		}
+
 		mbox->mbox_lock_id += 2;
 	}
 
@@ -561,6 +579,7 @@
 int mbox_unlock(struct mbox_mailbox *mbox, unsigned int lock_id)
 {
 	struct mbox_lock_context ctx;
+	bool fcntl_locked;
 	int i;
 
 	i_assert(mbox->mbox_lock_id == (lock_id & ~1));
@@ -572,7 +591,8 @@
 			return 0;
 		if (mbox->mbox_shared_locks > 0) {
 			/* drop to shared lock */
-			if (mbox_update_locking(mbox, F_RDLCK) < 0)
+			if (mbox_update_locking(mbox, F_RDLCK,
+						&fcntl_locked) < 0)
 				return -1;
 			return 0;
 		}
--- a/src/lib-storage/index/mbox/mbox-sync.c	Thu Jul 12 23:56:13 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Fri Jul 13 00:05:44 2007 +0300
@@ -1781,6 +1781,14 @@
 
 	i_assert(lock_id != 0);
 
+	if ((mbox->storage->storage.flags &
+	     MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0 && mbox->mbox_fd != -1) {
+		if (fdatasync(mbox->mbox_fd) < 0) {
+			mbox_set_syscall_error(mbox, "fdatasync()");
+			ret = -1;
+		}
+	}
+
 	if (mbox->mbox_lock_type != F_RDLCK) {
 		/* drop to read lock */
 		unsigned int read_lock_id = 0;