dovecot: FreeBSD and Solaris supports flushing attribute cache w...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 16 10:41:38 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/6dfb3969baae
changeset: 6820:6dfb3969baae
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 16 10:41:34 2007 +0200
description:
FreeBSD and Solaris supports flushing attribute cache with chown(uid=-1,
gid=-1). Do it with them.

diffstat:

1 file changed, 23 insertions(+), 6 deletions(-)
src/lib/nfs-workarounds.c |   29 +++++++++++++++++++++++------

diffs (69 lines):

diff -r 256725979152 -r 6dfb3969baae src/lib/nfs-workarounds.c
--- a/src/lib/nfs-workarounds.c	Fri Nov 16 08:10:17 2007 +0200
+++ b/src/lib/nfs-workarounds.c	Fri Nov 16 10:41:34 2007 +0200
@@ -36,6 +36,10 @@
 
 #ifdef __linux__
 #  define READ_CACHE_FLUSH_FCNTL
+#endif
+
+#if defined(__FreeBSD__) || defined(__sun)
+#  define ATTRCACHE_FLUSH_CHOWN_UID_1
 #endif
 
 static int
@@ -162,6 +166,7 @@ static bool nfs_flush_fchown_uid(const c
 static bool nfs_flush_fchown_uid(const char *path, int fd)
 {
 	struct stat st;
+	uid_t uid;
 
 	if (fstat(fd, &st) < 0) {
 		if (errno == ESTALE) {
@@ -171,7 +176,12 @@ static bool nfs_flush_fchown_uid(const c
 		i_error("nfs_flush_fchown_uid: fstat(%s) failed: %m", path);
 		return TRUE;
 	}
-	if (fchown(fd, st.st_uid, (gid_t)-1) < 0) {
+#ifdef ATTRCACHE_FLUSH_CHOWN_UID_1
+	uid = (uid_t)-1;
+#else
+	uid = st.st_uid;
+#endif
+	if (fchown(fd, uid, (gid_t)-1) < 0) {
 		if (errno == ESTALE) {
 			return FALSE;
 		}
@@ -188,9 +198,16 @@ static bool nfs_flush_fchown_uid(const c
 #ifndef __FreeBSD__
 static void nfs_flush_chown_uid(const char *path)
 {
+	uid_t uid;
+
+#ifdef ATTRCACHE_FLUSH_CHOWN_UID_1
+	uid = (uid_t)-1;
+#else
 	struct stat st;
 
-	if (stat(path, &st) < 0) {
+	if (stat(path, &st) == 0)
+		uid = st.st_uid;
+	else {
 		if (errno == ESTALE) {
 			/* ESTALE causes the OS to flush the attr cache */
 			return;
@@ -205,10 +222,10 @@ static void nfs_flush_chown_uid(const ch
 		   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) {
+		uid = geteuid();
+	}
+#endif
+	if (chown(path, uid, (gid_t)-1) < 0) {
 		if (errno == ESTALE || errno == EACCES ||
 		    errno == EPERM || errno == ENOENT) {
 			/* attr cache is flushed */


More information about the dovecot-cvs mailing list