dovecot: Flush NFS caches when needed.

dovecot at dovecot.org dovecot at dovecot.org
Fri Jul 13 00:18:32 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/b88278b5d8d3
changeset: 5974:b88278b5d8d3
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jul 13 00:05:44 2007 +0300
description:
Flush NFS caches when needed.

diffstat:

4 files changed, 42 insertions(+), 7 deletions(-)
src/lib-storage/index/maildir/maildir-keywords.c |    7 ++++-
src/lib-storage/index/maildir/maildir-uidlist.c  |    4 ++
src/lib-storage/index/mbox/mbox-lock.c           |   30 ++++++++++++++++++----
src/lib-storage/index/mbox/mbox-sync.c           |    8 +++++

diffs (164 lines):

diff -r fe9da9c92cf4 -r b88278b5d8d3 src/lib-storage/index/maildir/maildir-keywords.c
--- 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 @@ static int maildir_keywords_sync(struct 
            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;
diff -r fe9da9c92cf4 -r b88278b5d8d3 src/lib-storage/index/maildir/maildir-uidlist.c
--- 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 @@ maildir_uidlist_has_changed(struct maild
 
 	*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,
diff -r fe9da9c92cf4 -r b88278b5d8d3 src/lib-storage/index/mbox/mbox-lock.c
--- 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 @@ struct mbox_lock_context {
 
 	int lock_type;
 	bool dotlock_last_stale;
+	bool fcntl_locked;
 };
 
 struct mbox_lock_data {
@@ -165,7 +167,10 @@ static int mbox_file_open_latest(struct 
 		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 @@ static int mbox_lock_fcntl(struct mbox_l
 	}
 
 	alarm(0);
+	ctx->fcntl_locked = TRUE;
 	return 1;
 }
 
@@ -451,12 +457,15 @@ static int mbox_lock_list(struct mbox_lo
 	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);
 
@@ -513,12 +522,14 @@ static int mbox_update_locking(struct mb
 		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,9 +540,16 @@ int mbox_lock(struct mbox_mailbox *mbox,
 	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 *mbo
 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 @@ int mbox_unlock(struct mbox_mailbox *mbo
 			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;
 		}
diff -r fe9da9c92cf4 -r b88278b5d8d3 src/lib-storage/index/mbox/mbox-sync.c
--- 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 @@ __again:
 
 	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;


More information about the dovecot-cvs mailing list