dovecot: dotlocks: Flush NFS attribute cache only if nfs_flush s...

dovecot at dovecot.org dovecot at dovecot.org
Sun Oct 21 16:39:12 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/b6631550cf84
changeset: 6592:b6631550cf84
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 21 16:39:08 2007 +0300
description:
dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.

diffstat:

15 files changed, 35 insertions(+), 27 deletions(-)
src/deliver/duplicate.c                          |    2 ++
src/lib-index/mail-cache.c                       |    1 +
src/lib-index/mail-hash.c                        |    8 ++------
src/lib-index/mail-transaction-log.c             |    1 +
src/lib-index/mailbox-list-index.c               |    8 ++------
src/lib-storage/index/maildir/maildir-keywords.c |    3 +++
src/lib-storage/index/maildir/maildir-uidlist.c  |    3 +++
src/lib-storage/index/mbox/mbox-lock.c           |    2 ++
src/lib-storage/list/subscription-file.c         |    2 ++
src/lib-storage/mail-storage.c                   |    2 ++
src/lib-storage/mailbox-list.h                   |    4 +++-
src/lib/file-dotlock.c                           |    6 ++++--
src/lib/file-dotlock.h                           |    2 ++
src/plugins/convert/convert-storage.c            |   10 ++++------
src/plugins/quota/quota-maildir.c                |    8 ++------

diffs (247 lines):

diff -r f74e84fd11fc -r b6631550cf84 src/deliver/duplicate.c
--- a/src/deliver/duplicate.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/deliver/duplicate.c	Sun Oct 21 16:39:08 2007 +0300
@@ -308,6 +308,8 @@ void duplicate_init(void)
 {
 	duplicate_dotlock_set.use_excl_lock =
 		getenv("DOTLOCK_USE_EXCL") != NULL;
+	duplicate_dotlock_set.nfs_flush =
+		getenv("MAIL_NFS_STORAGE") != NULL;
 }
 
 void duplicate_deinit(void)
diff -r f74e84fd11fc -r b6631550cf84 src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-index/mail-cache.c	Sun Oct 21 16:39:08 2007 +0300
@@ -328,6 +328,7 @@ static struct mail_cache *mail_cache_all
 			    strcase_hash, (hash_cmp_callback_t *)strcasecmp);
 
 	cache->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
+	cache->dotlock_settings.nfs_flush = index->nfs_flush;
 	cache->dotlock_settings.timeout = MAIL_CACHE_LOCK_TIMEOUT;
 	cache->dotlock_settings.stale_timeout = MAIL_CACHE_LOCK_CHANGE_TIMEOUT;
 
diff -r f74e84fd11fc -r b6631550cf84 src/lib-index/mail-hash.c
--- a/src/lib-index/mail-hash.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-index/mail-hash.c	Sun Oct 21 16:39:08 2007 +0300
@@ -78,12 +78,7 @@ const struct dotlock_settings default_do
 	MEMBER(lock_suffix) NULL,
 
 	MEMBER(timeout) 10,
-	MEMBER(stale_timeout) 30,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
+	MEMBER(stale_timeout) 30
 };
 
 static void mail_hash_set_syscall_error(struct mail_hash *hash,
@@ -570,6 +565,7 @@ mail_hash_open(struct mail_index *index,
 	hash->fd = -1;
 	hash->dotlock_settings = default_dotlock_settings;
 	hash->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
+	hash->dotlock_settings.nfs_flush = index->nfs_flush;
 
 	hash->key_hash_cb = key_hash_cb;
 	hash->rec_hash_cb = rec_hash_cb;
diff -r f74e84fd11fc -r b6631550cf84 src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-index/mail-transaction-log.c	Sun Oct 21 16:39:08 2007 +0300
@@ -39,6 +39,7 @@ mail_transaction_log_alloc(struct mail_i
 	log->index = index;
 
 	log->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
+	log->dotlock_settings.nfs_flush = index->nfs_flush;
 	log->dotlock_settings.timeout = MAIL_TRANSCATION_LOG_LOCK_TIMEOUT;
 	log->dotlock_settings.stale_timeout =
 		MAIL_TRANSCATION_LOG_LOCK_CHANGE_TIMEOUT;
diff -r f74e84fd11fc -r b6631550cf84 src/lib-index/mailbox-list-index.c
--- a/src/lib-index/mailbox-list-index.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-index/mailbox-list-index.c	Sun Oct 21 16:39:08 2007 +0300
@@ -46,12 +46,7 @@ const struct dotlock_settings default_do
 	MEMBER(lock_suffix) NULL,
 
 	MEMBER(timeout) 60,
-	MEMBER(stale_timeout) 30,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
+	MEMBER(stale_timeout) 30
 };
 
 int mailbox_list_index_set_syscall_error(struct mailbox_list_index *index,
@@ -363,6 +358,7 @@ mailbox_list_index_alloc(const char *pat
 	index->mmap_disable = mail_index->mmap_disable;
 	index->dotlock_set = default_dotlock_set;
 	index->dotlock_set.use_excl_lock = mail_index->use_excl_dotlocks;
+	index->dotlock_set.nfs_flush = mail_index->nfs_flush;
 	return index;
 }
 
diff -r f74e84fd11fc -r b6631550cf84 src/lib-storage/index/maildir/maildir-keywords.c
--- a/src/lib-storage/index/maildir/maildir-keywords.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-keywords.c	Sun Oct 21 16:39:08 2007 +0300
@@ -76,6 +76,9 @@ maildir_keywords_init_readonly(struct ma
 
 	mk->dotlock_settings.use_excl_lock =
 		(box->storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
+	mk->dotlock_settings.nfs_flush =
+		(box->storage->flags &
+		 MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0;
 	mk->dotlock_settings.timeout = KEYWORDS_LOCK_STALE_TIMEOUT + 2;
 	mk->dotlock_settings.stale_timeout = KEYWORDS_LOCK_STALE_TIMEOUT;
 	mk->dotlock_settings.temp_prefix =
diff -r f74e84fd11fc -r b6631550cf84 src/lib-storage/index/maildir/maildir-uidlist.c
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Sun Oct 21 16:39:08 2007 +0300
@@ -212,6 +212,9 @@ struct maildir_uidlist *maildir_uidlist_
 	uidlist->dotlock_settings.use_excl_lock =
 		(mbox->storage->storage.flags &
 		 MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
+	uidlist->dotlock_settings.nfs_flush =
+		(mbox->storage->storage.flags &
+		 MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0;
 	uidlist->dotlock_settings.timeout = UIDLIST_LOCK_STALE_TIMEOUT + 2;
 	uidlist->dotlock_settings.stale_timeout = UIDLIST_LOCK_STALE_TIMEOUT;
 	uidlist->dotlock_settings.temp_prefix = mbox->storage->temp_prefix;
diff -r f74e84fd11fc -r b6631550cf84 src/lib-storage/index/mbox/mbox-lock.c
--- a/src/lib-storage/index/mbox/mbox-lock.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Sun Oct 21 16:39:08 2007 +0300
@@ -260,6 +260,8 @@ mbox_lock_dotlock_int(struct mbox_lock_c
 	memset(&set, 0, sizeof(set));
 	set.use_excl_lock = (mbox->storage->storage.flags &
 			     MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
+	set.nfs_flush = (mbox->storage->storage.flags &
+			 MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0;
 	set.timeout = lock_timeout;
 	set.stale_timeout = dotlock_change_timeout;
 	set.callback = dotlock_callback;
diff -r f74e84fd11fc -r b6631550cf84 src/lib-storage/list/subscription-file.c
--- a/src/lib-storage/list/subscription-file.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-storage/list/subscription-file.c	Sun Oct 21 16:39:08 2007 +0300
@@ -89,6 +89,8 @@ int subsfile_set_subscribed(struct mailb
 	memset(&dotlock_set, 0, sizeof(dotlock_set));
 	dotlock_set.use_excl_lock =
 		(list->flags & MAILBOX_LIST_FLAG_DOTLOCK_USE_EXCL) != 0;
+	dotlock_set.nfs_flush =
+		(list->flags & MAILBOX_LIST_FLAG_NFS_FLUSH) != 0;
 	dotlock_set.temp_prefix = temp_prefix;
 	dotlock_set.timeout = SUBSCRIPTION_FILE_LOCK_TIMEOUT;
 	dotlock_set.stale_timeout = SUBSCRIPTION_FILE_CHANGE_TIMEOUT;
diff -r f74e84fd11fc -r b6631550cf84 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-storage/mail-storage.c	Sun Oct 21 16:39:08 2007 +0300
@@ -421,6 +421,8 @@ mail_storage_get_list_flags(enum mail_st
 		list_flags |= MAILBOX_LIST_FLAG_FULL_FS_ACCESS;
 	if ((storage_flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0)
 		list_flags |= MAILBOX_LIST_FLAG_DOTLOCK_USE_EXCL;
+	if ((storage_flags & MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0)
+		list_flags |= MAILBOX_LIST_FLAG_NFS_FLUSH;
 	return list_flags;
 }
 
diff -r f74e84fd11fc -r b6631550cf84 src/lib-storage/mailbox-list.h
--- a/src/lib-storage/mailbox-list.h	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib-storage/mailbox-list.h	Sun Oct 21 16:39:08 2007 +0300
@@ -15,7 +15,9 @@ enum mailbox_list_flags {
 	/* Rely on O_EXCL when creating dotlocks */
 	MAILBOX_LIST_FLAG_DOTLOCK_USE_EXCL	= 0x08,
 	/* Mailboxes are files, not directories. */
-	MAILBOX_LIST_FLAG_MAILBOX_FILES		= 0x10
+	MAILBOX_LIST_FLAG_MAILBOX_FILES		= 0x10,
+	/* Flush NFS attribute cache when needed */
+	MAILBOX_LIST_FLAG_NFS_FLUSH		= 0x20
 };
 
 enum mailbox_info_flags {
diff -r f74e84fd11fc -r b6631550cf84 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib/file-dotlock.c	Sun Oct 21 16:39:08 2007 +0300
@@ -147,7 +147,8 @@ static int update_lock_info(time_t now, 
 {
 	struct stat st;
 
-	nfs_flush_attr_cache(lock_info->lock_path);
+	if (lock_info->set->nfs_flush)
+		nfs_flush_attr_cache(lock_info->lock_path);
 	if (nfs_safe_lstat(lock_info->lock_path, &st) < 0) {
 		if (errno != ENOENT) {
 			i_error("lstat(%s) failed: %m", lock_info->lock_path);
@@ -232,7 +233,8 @@ static int check_lock(time_t now, struct
 
 		/* possibly stale lock file. check also the timestamp of the
 		   file we're protecting. */
-		nfs_flush_attr_cache(lock_info->path);
+		if (lock_info->set->nfs_flush)
+			nfs_flush_attr_cache(lock_info->path);
 		if (nfs_safe_stat(lock_info->path, &st) < 0) {
 			if (errno == ENOENT) {
 				/* file doesn't exist. treat it as if
diff -r f74e84fd11fc -r b6631550cf84 src/lib/file-dotlock.h
--- a/src/lib/file-dotlock.h	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/lib/file-dotlock.h	Sun Oct 21 16:39:08 2007 +0300
@@ -30,6 +30,8 @@ struct dotlock_settings {
 	/* Rely on O_EXCL locking to work instead of using hardlinks.
 	   It's faster, but doesn't work with all NFS implementations. */
 	unsigned int use_excl_lock:1;
+	/* Flush NFS attribute cache before stating files. */
+	unsigned int nfs_flush:1;
 	/* Use io_add_notify() to speed up finding out when an existing
 	   dotlock is deleted */
 	unsigned int use_io_notify:1;
diff -r f74e84fd11fc -r b6631550cf84 src/plugins/convert/convert-storage.c
--- a/src/plugins/convert/convert-storage.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/plugins/convert/convert-storage.c	Sun Oct 21 16:39:08 2007 +0300
@@ -17,12 +17,7 @@ struct dotlock_settings dotlock_settings
 	MEMBER(lock_suffix) NULL,
 
 	MEMBER(timeout) 60*5,
-	MEMBER(stale_timeout) 60*5,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
+	MEMBER(stale_timeout) 60*5
 };
 
 static int mailbox_copy_mails(struct mailbox *srcbox, struct mailbox *destbox,
@@ -287,6 +282,9 @@ int convert_storage(const char *source_d
 	dotlock_settings.use_excl_lock =
 		(source_ns->storage->flags &
 		 MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
+	dotlock_settings.nfs_flush =
+		(source_ns->storage->flags &
+		 MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0;
 	ret = file_dotlock_create(&dotlock_settings, path, 0, &dotlock);
 	if (ret <= 0) {
 		if (ret == 0)
diff -r f74e84fd11fc -r b6631550cf84 src/plugins/quota/quota-maildir.c
--- a/src/plugins/quota/quota-maildir.c	Sun Oct 21 16:28:12 2007 +0300
+++ b/src/plugins/quota/quota-maildir.c	Sun Oct 21 16:39:08 2007 +0300
@@ -52,12 +52,7 @@ struct dotlock_settings dotlock_settings
 	MEMBER(lock_suffix) NULL,
 
 	MEMBER(timeout) 0,
-	MEMBER(stale_timeout) 30,
-
-	MEMBER(callback) NULL,
-	MEMBER(context) NULL,
-
-	MEMBER(use_excl_lock) FALSE
+	MEMBER(stale_timeout) 30
 };
 
 static int maildir_sum_dir(const char *dir, uint64_t *total_bytes,
@@ -217,6 +212,7 @@ static int maildirsize_write(struct mail
 	i_assert(root->fd == -1);
 
 	dotlock_settings.use_excl_lock = getenv("DOTLOCK_USE_EXCL") != NULL;
+	dotlock_settings.nfs_flush = getenv("MAIL_NFS_STORAGE") != NULL;
 	fd = file_dotlock_open(&dotlock_settings, path,
 			       DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
 	if (fd == -1) {


More information about the dovecot-cvs mailing list