[Dovecot] Bug? 1.0.0-test28 NFS locking problems

Tim Southerwood ts at doc.ic.ac.uk
Tue Jul 20 19:24:00 EEST 2004


Hi

Slight problem - linux 2.4 running dovecot, Solaris 2.8 home directory
server. Full lockd support etc.

I had to make the following code patches (at end of mail for clarity) to
get dovecot to read the users mbox files at all.

1) fcntl with F_SETLKW will not work against a Solaris 2.8 server as
proved with a small test program. Other forms of fcntl (ie F_SETLK) are
OK.


I noticed there are some code witches, but setting mbox_lock_timeout=0
only seems to knock one of the fcntl's over to F_SETLK

2) O_CREAT | O_EXCL are documented not to work over NFS properly (see
man open(2) on linux). So I knocked out the O_EXCL and combined with (1)
dovecot will talk over NFS to remote mbox files.

THESE ARE NOT VIABLE CODE PATCHES

They illustrate a problem I found - they are hackish and totally wrong.
I'm not sure of the best way to correct this problem cleanly, so I am
just submitting it as a potential bug.

Cheers

Tim Southerwood


**************************************************
--- dovecot-1.0-test28/src/lib/file-lock.c.orig	2004-07-20 14:29:47.000000000 +0100
+++ dovecot-1.0-test28/src/lib/file-lock.c	2004-07-20 14:30:15.000000000 +0100
@@ -38,7 +38,7 @@
 	fl.l_start = 0;
 	fl.l_len = 0;
 
-	while (fcntl(fd, timeout != 0 ? F_SETLKW : F_SETLK, &fl) < 0) {
+	while (fcntl(fd, timeout != 0 ? F_SETLK : F_SETLK, &fl) < 0) {
 		if (timeout == 0 && (errno == EACCES || errno == EAGAIN))
 			return 0;
 
--- dovecot-1.0-test28/src/lib-storage/index/mbox/mbox-lock.c.orig	2004-07-20 14:29:54.000000000 +0100
+++ dovecot-1.0-test28/src/lib-storage/index/mbox/mbox-lock.c	2004-07-20 14:30:35.000000000 +0100
@@ -361,7 +361,7 @@
 	fl.l_start = 0;
 	fl.l_len = 0;
 
-        wait_type = max_wait_time == 0 ? F_SETLK : F_SETLKW;
+        wait_type = max_wait_time == 0 ? F_SETLK : F_SETLK;
 	while (fcntl(ctx->ibox->mbox_fd, wait_type, &fl) < 0) {
 		if (errno != EINTR) {
 			if (errno != EAGAIN && errno != EACCES)
**************************************************
and
**************************************************
diff -NaurbB dovecot-1.0-test28.orig/src/lib/file-dotlock.c
dovecot-1.0-test28/src/lib/file-dotlock.c---
dovecot-1.0-test28.orig/src/lib/file-dotlock.c	2004-06-28
18:28:01.000000000 +0100+++ dovecot-1.0-test28/src/lib/file-dotlock.c	2004-07-20 14:50:33.000000000 +0100
@@ -192,7 +192,7 @@
 			return -1;
 		}
 
-		fd = open(*path_r, O_RDWR | O_EXCL | O_CREAT, 0666);
+		fd = open(*path_r, O_RDWR | O_CREAT, 0666);
 		if (fd != -1)
 			return fd;
 
diff -NaurbB
dovecot-1.0-test28.orig/src/lib-storage/index/maildir/maildir-util.c
dovecot-1.0-test28/src/lib-storage/index/maildir/maildir-util.c---
dovecot-1.0-test28.orig/src/lib-storage/index/maildir/maildir-util.c
2004-06-16 01:50:41.000000000 +0100+++
dovecot-1.0-test28/src/lib-storage/index/maildir/maildir-util.c
2004-07-20 14:51:25.000000000 +0100@@ -241,7 +241,7 @@
 		if (stat(path, &st) < 0 && errno == ENOENT) {
 			/* doesn't exist */
 			mode_t old_mask = umask(0);
-			fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
+			fd = open(path, O_WRONLY | O_CREAT, mode);
 			umask(old_mask);
 			if (fd != -1 || errno != EEXIST)
 				break;
diff -NaurbB
dovecot-1.0-test28.orig/src/lib-storage/index/mbox/mbox-storage.c
dovecot-1.0-test28/src/lib-storage/index/mbox/mbox-storage.c---
dovecot-1.0-test28.orig/src/lib-storage/index/mbox/mbox-storage.c
2004-07-20 14:45:55.000000000 +0100+++
dovecot-1.0-test28/src/lib-storage/index/mbox/mbox-storage.c	2004-07-20
14:49:56.000000000 +0100@@ -386,7 +386,7 @@
 	int fd;
 
 	/* make sure inbox file itself exists */
-	fd = open(storage->inbox_path, O_RDWR | O_CREAT | O_EXCL, 0660);
+	fd = open(storage->inbox_path, O_RDWR | O_CREAT, 0660);
 	if (fd != -1)
 		(void)close(fd);
 
@@ -579,7 +579,7 @@
 	}
 
 	/* create the mailbox file */
-	fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0660);
+	fd = open(path, O_RDWR | O_CREAT, 0660);
 	if (fd != -1) {
 		(void)close(fd);
 		return 0;
diff -NaurbB
dovecot-1.0-test28.orig/src/lib-storage/index/mbox/mbox-storage.c.mbox
dovecot-1.0-test28/src/lib-storage/index/mbox/mbox-storage.c.mbox---
dovecot-1.0-test28.orig/src/lib-storage/index/mbox/mbox-storage.c.mbox
2004-07-11 22:03:09.000000000 +0100+++
dovecot-1.0-test28/src/lib-storage/index/mbox/mbox-storage.c.mbox
2004-07-20 14:50:58.000000000 +0100@@ -386,7 +386,7 @@
 	int fd;
 
 	/* make sure inbox file itself exists */
-	fd = open(storage->inbox_path, O_RDWR | O_CREAT | O_EXCL, 0660);
+	fd = open(storage->inbox_path, O_RDWR | O_CREAT, 0660);
 	if (fd != -1)
 		(void)close(fd);
 
@@ -579,7 +579,7 @@
 	}
 
 	/* create the mailbox file */
-	fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0660);
+	fd = open(path, O_RDWR | O_CREAT, 0660);
 	if (fd != -1) {
 		(void)close(fd);
 		return 0;
**************************************************


-- 
Tim J Southerwood
Senior Programmer
CSG, Dept of Computing, Imperial College, London



More information about the dovecot mailing list