Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6819:256725979152 HEAD
nfs_flush_attr_cache() doesn't take flush_dir paramter anymore. Instead the
directory is always flushed now.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 16 Nov 2007 08:10:17 +0200 |
parents | f637a8a1aae7 |
children | 6dfb3969baae |
files | src/lib-index/mail-cache.c src/lib-index/mail-hash.c src/lib-index/mail-index.c src/lib-index/mail-transaction-log-file.c src/lib-index/mail-transaction-log.c src/lib-index/mailbox-list-index.c 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/file-dotlock.c src/lib/nfs-workarounds.c src/lib/nfs-workarounds.h |
diffstat | 12 files changed, 51 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ /* 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;
--- 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 @@ 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)
--- 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 @@ 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 @@ 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;
--- 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 @@ 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
--- 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 @@ 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,
--- 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 @@ 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)
--- 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 @@ 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) {
--- 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 @@ 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 @@ 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;
--- 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 @@ 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;
--- 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 @@ /* 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 @@ /* 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
--- 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 @@ -38,8 +38,6 @@ # 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), void *context) @@ -65,7 +63,7 @@ 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,29 +185,7 @@ return TRUE; } -static void nfs_flush_dir(const char *path) -{ -#ifdef __FreeBSD__ - /* Unfortunately rmdir() seems to be the only way to flush a - directory's attribute cache. */ - if (rmdir(path) == 0) { - if (mkdir(path, 0600) == 0) { - i_warning("nfs_flush_dir: rmdir(%s) unexpectedly " - "removed the dir. recreated.", path); - } else { - i_error("nfs_flush_dir: rmdir(%s) unexpectedly " - "removed the dir. mkdir() failed: %m", path); - } - } else if (errno == ESTALE || errno == ENOENT || errno == ENOTEMPTY) { - /* expected failures */ - } else { - i_error("nfs_flush_dir: rmdir(%s) failed: %m", path); - } -#else - nfs_flush_chown_uid(path); -#endif -} - +#ifndef __FreeBSD__ static void nfs_flush_chown_uid(const char *path) { struct stat st; @@ -231,13 +207,6 @@ 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 || @@ -248,6 +217,7 @@ 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) @@ -280,21 +250,41 @@ } #endif -void nfs_flush_attr_cache(const char *path, bool flush_dir) +static void nfs_flush_attr_cache_dir(const char *path) +{ +#ifdef __FreeBSD__ + /* Unfortunately rmdir() seems to be the only way to flush a + directory's attribute cache. */ + if (rmdir(path) == 0) { + if (mkdir(path, 0600) == 0) { + i_warning("nfs_flush_dir: rmdir(%s) unexpectedly " + "removed the dir. recreated.", path); + } else { + i_error("nfs_flush_dir: rmdir(%s) unexpectedly " + "removed the dir. mkdir() failed: %m", path); + } + } else if (errno == ESTALE || errno == ENOENT || errno == ENOTEMPTY) { + /* expected failures */ + } else { + i_error("nfs_flush_dir: rmdir(%s) failed: %m", path); + } +#else + nfs_flush_chown_uid(path); +#endif +} + +void nfs_flush_attr_cache(const char *path) { const char *p; - if (flush_dir) { - p = strrchr(path, '/'); - if (p == NULL) - nfs_flush_dir("."); - else { - t_push(); - nfs_flush_dir(t_strdup_until(path, p)); - t_pop(); - } + p = strrchr(path, '/'); + if (p == NULL) + nfs_flush_attr_cache_dir("."); + else { + t_push(); + nfs_flush_attr_cache_dir(t_strdup_until(path, p)); + t_pop(); } - nfs_flush_chown_uid(path); } bool nfs_flush_attr_cache_fd(const char *path, int fd)
--- a/src/lib/nfs-workarounds.h Fri Nov 16 05:20:48 2007 +0200 +++ b/src/lib/nfs-workarounds.h Fri Nov 16 08:10:17 2007 +0200 @@ -19,9 +19,10 @@ is 1, otherwise stat() first to find it out. */ int nfs_safe_link(const char *oldpath, const char *newpath, bool links1); -/* Flush attribute cache for given path. If flush_dir is TRUE, also the - directory's cache is flushed. */ -void nfs_flush_attr_cache(const char *path, bool flush_dir); +/* Flush attribute cache for given path. This actually flushes the parent + directory's attribute cache to make sure that the file handle also gets + refreshed. */ +void nfs_flush_attr_cache(const char *path); /* Flush attribute cache for given file descriptor. The given path is used only for logging. */ bool nfs_flush_attr_cache_fd(const char *path, int fd);