dovecot: nfs_flush_attr_cache() doesn't take flush_dir paramter ...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Nov 16 08:10:22 EET 2007
details: http://hg.dovecot.org/dovecot/rev/256725979152
changeset: 6819:256725979152
user: Timo Sirainen <tss at iki.fi>
date: Fri Nov 16 08:10:17 2007 +0200
description:
nfs_flush_attr_cache() doesn't take flush_dir paramter anymore. Instead the
directory is always flushed now.
diffstat:
12 files changed, 93 insertions(+), 102 deletions(-)
src/lib-index/mail-cache.c | 2
src/lib-index/mail-hash.c | 2
src/lib-index/mail-index.c | 4
src/lib-index/mail-transaction-log-file.c | 2
src/lib-index/mail-transaction-log.c | 2
src/lib-index/mailbox-list-index.c | 2
src/lib-storage/index/maildir/maildir-keywords.c | 2
src/lib-storage/index/maildir/maildir-uidlist.c | 4
src/lib-storage/index/mbox/mbox-lock.c | 2
src/lib/file-dotlock.c | 4
src/lib/nfs-workarounds.c | 162 ++++++++++------------
src/lib/nfs-workarounds.h | 7
diffs (truncated from 360 to 300 lines):
diff -r f637a8a1aae7 -r 256725979152 src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-index/mail-cache.c Fri Nov 16 08:10:17 2007 +0200
@@ -115,7 +115,7 @@ static bool mail_cache_need_reopen(struc
/* see if the file has changed */
if (cache->index->nfs_flush)
- nfs_flush_attr_cache(cache->filepath, TRUE);
+ nfs_flush_attr_cache(cache->filepath);
if (nfs_safe_stat(cache->filepath, &st) < 0) {
mail_cache_set_syscall_error(cache, "stat()");
return TRUE;
diff -r f637a8a1aae7 -r 256725979152 src/lib-index/mail-hash.c
--- a/src/lib-index/mail-hash.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-index/mail-hash.c Fri Nov 16 08:10:17 2007 +0200
@@ -653,7 +653,7 @@ static int mail_hash_reopen_if_needed(st
return mail_hash_reopen(hash);
if (hash->index->nfs_flush)
- nfs_flush_attr_cache(hash->filepath, TRUE);
+ nfs_flush_attr_cache(hash->filepath);
if (nfs_safe_stat(hash->filepath, &st) < 0) {
if (errno == ENOENT)
diff -r f637a8a1aae7 -r 256725979152 src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-index/mail-index.c Fri Nov 16 08:10:17 2007 +0200
@@ -249,7 +249,7 @@ int mail_index_try_open_only(struct mail
i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
if (index->nfs_flush)
- nfs_flush_attr_cache(index->filepath, TRUE);
+ nfs_flush_attr_cache(index->filepath);
/* Note that our caller must close index->fd by itself. */
if (index->readonly)
@@ -474,7 +474,7 @@ int mail_index_reopen_if_changed(struct
return mail_index_try_open_only(index);
if (index->nfs_flush)
- nfs_flush_attr_cache(index->filepath, TRUE);
+ nfs_flush_attr_cache(index->filepath);
if (nfs_safe_stat(index->filepath, &st2) < 0) {
if (errno == ENOENT)
return 0;
diff -r f637a8a1aae7 -r 256725979152 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-index/mail-transaction-log-file.c Fri Nov 16 08:10:17 2007 +0200
@@ -435,7 +435,7 @@ mail_transaction_log_file_create2(struct
bool rename_existing;
if (index->nfs_flush)
- nfs_flush_attr_cache(file->filepath, TRUE);
+ nfs_flush_attr_cache(file->filepath);
/* log creation is locked now - see if someone already created it.
note that if we're rotating, we need to keep the log locked until
diff -r f637a8a1aae7 -r 256725979152 src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-index/mail-transaction-log.c Fri Nov 16 08:10:17 2007 +0200
@@ -280,7 +280,7 @@ mail_transaction_log_refresh(struct mail
path = t_strconcat(log->index->filepath,
MAIL_TRANSACTION_LOG_SUFFIX, NULL);
if (log->index->nfs_flush && nfs_flush)
- nfs_flush_attr_cache(path, TRUE);
+ nfs_flush_attr_cache(path);
if (nfs_safe_stat(path, &st) < 0) {
if (errno != ENOENT) {
mail_index_file_set_syscall_error(log->index, path,
diff -r f637a8a1aae7 -r 256725979152 src/lib-index/mailbox-list-index.c
--- a/src/lib-index/mailbox-list-index.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-index/mailbox-list-index.c Fri Nov 16 08:10:17 2007 +0200
@@ -229,7 +229,7 @@ static int mailbox_list_index_is_recreat
return 1;
if (index->mail_index->nfs_flush)
- nfs_flush_attr_cache(index->filepath, TRUE);
+ nfs_flush_attr_cache(index->filepath);
if (nfs_safe_stat(index->filepath, &st1) < 0) {
if (errno == ENOENT)
diff -r f637a8a1aae7 -r 256725979152 src/lib-storage/index/maildir/maildir-keywords.c
--- a/src/lib-storage/index/maildir/maildir-keywords.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-storage/index/maildir/maildir-keywords.c Fri Nov 16 08:10:17 2007 +0200
@@ -118,7 +118,7 @@ static int maildir_keywords_sync(struct
errors. */
if ((mk->storage->flags & MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0)
- nfs_flush_attr_cache(mk->path, FALSE);
+ nfs_flush_attr_cache(mk->path);
if (nfs_safe_stat(mk->path, &st) < 0) {
if (errno == ENOENT) {
diff -r f637a8a1aae7 -r 256725979152 src/lib-storage/index/maildir/maildir-uidlist.c
--- a/src/lib-storage/index/maildir/maildir-uidlist.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c Fri Nov 16 08:10:17 2007 +0200
@@ -682,7 +682,7 @@ int maildir_uidlist_refresh(struct maild
if (!nfs_flush)
uidlist->nfs_dirty_refresh = TRUE;
else {
- nfs_flush_attr_cache(uidlist->path, TRUE);
+ nfs_flush_attr_cache(uidlist->path);
uidlist->nfs_dirty_refresh = FALSE;
}
}
@@ -704,7 +704,7 @@ int maildir_uidlist_refresh(struct maild
break;
/* ESTALE - try reopening and rereading */
maildir_uidlist_close(uidlist);
- nfs_flush_attr_cache(uidlist->path, TRUE);
+ nfs_flush_attr_cache(uidlist->path);
}
if (ret >= 0)
uidlist->initial_read = TRUE;
diff -r f637a8a1aae7 -r 256725979152 src/lib-storage/index/mbox/mbox-lock.c
--- a/src/lib-storage/index/mbox/mbox-lock.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-lock.c Fri Nov 16 08:10:17 2007 +0200
@@ -173,7 +173,7 @@ static int mbox_file_open_latest(struct
if (mbox->mbox_fd != -1) {
if ((mbox->storage->storage.flags &
MAIL_STORAGE_FLAG_NFS_FLUSH_STORAGE) != 0)
- nfs_flush_attr_cache(mbox->path, TRUE);
+ nfs_flush_attr_cache(mbox->path);
if (nfs_safe_stat(mbox->path, &st) < 0) {
mbox_set_syscall_error(mbox, "stat()");
return -1;
diff -r f637a8a1aae7 -r 256725979152 src/lib/file-dotlock.c
--- a/src/lib/file-dotlock.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib/file-dotlock.c Fri Nov 16 08:10:17 2007 +0200
@@ -159,7 +159,7 @@ static int update_lock_info(time_t now,
/* don't waste time flushing attribute cache the first time we're here.
if it's stale we'll get back here soon. */
if (lock_info->set->nfs_flush && lock_info->lock_stated)
- nfs_flush_attr_cache(lock_info->lock_path, TRUE);
+ nfs_flush_attr_cache(lock_info->lock_path);
lock_info->lock_stated = TRUE;
if (nfs_safe_lstat(lock_info->lock_path, &st) < 0) {
@@ -249,7 +249,7 @@ static int check_lock(time_t now, struct
/* possibly stale lock file. check also the timestamp of the
file we're protecting. */
if (lock_info->set->nfs_flush)
- nfs_flush_attr_cache(lock_info->path, TRUE);
+ 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 f637a8a1aae7 -r 256725979152 src/lib/nfs-workarounds.c
--- a/src/lib/nfs-workarounds.c Fri Nov 16 05:20:48 2007 +0200
+++ b/src/lib/nfs-workarounds.c Fri Nov 16 08:10:17 2007 +0200
@@ -37,8 +37,6 @@
#ifdef __linux__
# define READ_CACHE_FLUSH_FCNTL
#endif
-
-static void nfs_flush_chown_uid(const char *path);
static int
nfs_safe_do(const char *path, int (*callback)(const char *path, void *context),
@@ -65,7 +63,7 @@ nfs_safe_do(const char *path, int (*call
break;
dir = t_strdup_until(path, dir);
}
- nfs_flush_attr_cache(dir, FALSE);
+ nfs_flush_attr_cache(path);
if (stat(dir, &st) < 0) {
/* maybe it's gone or something else bad happened to
it. in any case we can't open the file, so fail
@@ -187,7 +185,72 @@ static bool nfs_flush_fchown_uid(const c
return TRUE;
}
-static void nfs_flush_dir(const char *path)
+#ifndef __FreeBSD__
+static void nfs_flush_chown_uid(const char *path)
+{
+ struct stat st;
+
+ if (stat(path, &st) < 0) {
+ if (errno == ESTALE) {
+ /* ESTALE causes the OS to flush the attr cache */
+ return;
+ }
+ if (errno != ENOENT) {
+ i_error("nfs_flush_chown_uid: stat(%s) failed: %m",
+ path);
+ return;
+ }
+
+ /* flush a negative cache entry. use effective UID to chown.
+ it probably doesn't really matter what UID is used, because
+ as long as we're not root we don't have permission to really
+ change it anyway */
+ st.st_uid = geteuid();
+ }
+
+ if (chown(path, st.st_uid, (gid_t)-1) < 0) {
+ if (errno == ESTALE || errno == EACCES ||
+ errno == EPERM || errno == ENOENT) {
+ /* attr cache is flushed */
+ return;
+ }
+ i_error("nfs_flush_chown_uid: chown(%s) failed: %m", path);
+ }
+}
+#endif
+
+#ifdef READ_CACHE_FLUSH_FCNTL
+static void nfs_flush_fcntl(const char *path, int fd, int old_lock_type)
+{
+ struct flock fl;
+ int ret;
+
+ /* If the file was already locked, we'll just get the same lock
+ again. It should succeed just fine. If was was unlocked, we'll
+ have to get a lock and then unlock it. Linux 2.6 flushes read cache
+ only when read/write locking succeeded. */
+ fl.l_type = old_lock_type != F_UNLCK ? old_lock_type : F_RDLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+
+ alarm(60);
+ ret = fcntl(fd, F_SETLKW, &fl);
+ alarm(0);
+
+ if (ret < 0) {
+ i_error("nfs_flush_fcntl: fcntl(%s, F_RDLCK) failed: %m", path);
+ return;
+ }
+
+ if (old_lock_type == F_UNLCK) {
+ fl.l_type = F_UNLCK;
+ (void)fcntl(fd, F_SETLKW, &fl);
+ }
+}
+#endif
+
+static void nfs_flush_attr_cache_dir(const char *path)
{
#ifdef __FreeBSD__
/* Unfortunately rmdir() seems to be the only way to flush a
@@ -210,91 +273,18 @@ static void nfs_flush_dir(const char *pa
#endif
}
-static void nfs_flush_chown_uid(const char *path)
-{
- struct stat st;
-
- if (stat(path, &st) < 0) {
- if (errno == ESTALE) {
- /* ESTALE causes the OS to flush the attr cache */
- return;
- }
- if (errno != ENOENT) {
- i_error("nfs_flush_chown_uid: stat(%s) failed: %m",
- path);
- return;
- }
-
- /* flush a negative cache entry. use effective UID to chown.
- it probably doesn't really matter what UID is used, because
- as long as we're not root we don't have permission to really
- change it anyway */
- st.st_uid = geteuid();
- }
-#ifdef __FreeBSD__
- if (S_ISDIR(st.st_mode)) {
- nfs_flush_dir(path);
- return;
- }
-#endif
-
-
- if (chown(path, st.st_uid, (gid_t)-1) < 0) {
- if (errno == ESTALE || errno == EACCES ||
- errno == EPERM || errno == ENOENT) {
- /* attr cache is flushed */
- return;
- }
- i_error("nfs_flush_chown_uid: chown(%s) failed: %m", path);
- }
-}
-
-#ifdef READ_CACHE_FLUSH_FCNTL
-static void nfs_flush_fcntl(const char *path, int fd, int old_lock_type)
-{
- struct flock fl;
- int ret;
-
- /* If the file was already locked, we'll just get the same lock
- again. It should succeed just fine. If was was unlocked, we'll
- have to get a lock and then unlock it. Linux 2.6 flushes read cache
- only when read/write locking succeeded. */
- fl.l_type = old_lock_type != F_UNLCK ? old_lock_type : F_RDLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
-
More information about the dovecot-cvs
mailing list