[dovecot-cvs] dovecot/src/lib Makefile.am, 1.60, 1.61 nfs-workarounds.c, NONE, 1.1 nfs-workarounds.h, NONE, 1.1 safe-open.c, 1.1, NONE safe-open.h, 1.1, NONE

cras at dovecot.org cras at dovecot.org
Sun Feb 26 12:15:42 EET 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv9314/lib

Modified Files:
	Makefile.am 
Added Files:
	nfs-workarounds.c nfs-workarounds.h 
Removed Files:
	safe-open.c safe-open.h 
Log Message:
Renamed safe-open.* to nfs-workarounds.*, safe_open() to nfs_safe_open() and
added a new global NFS_ESTALE_RETRY_COUNT which everyone uses instead of
defining their own.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- Makefile.am	16 Feb 2006 15:23:04 -0000	1.60
+++ Makefile.am	26 Feb 2006 10:15:39 -0000	1.61
@@ -53,6 +53,7 @@
 	mmap-util.c \
 	module-dir.c \
 	network.c \
+	nfs-workarounds.c \
 	ostream.c \
 	ostream-file.c \
 	ostream-crlf.c \
@@ -65,7 +66,6 @@
 	restrict-process-size.c \
 	safe-memset.c \
 	safe-mkdir.c \
-	safe-open.c \
 	sendfile-util.c \
 	seq-range-array.c \
 	sha1.c \
@@ -122,6 +122,7 @@
 	mmap-util.h \
 	module-dir.h \
 	network.h \
+	nfs-workarounds.h \
 	ostream.h \
 	ostream-crlf.h \
 	ostream-internal.h \
@@ -134,7 +135,6 @@
 	restrict-process-size.h \
 	safe-memset.h \
 	safe-mkdir.h \
-	safe-open.h \
 	sendfile-util.h \
 	seq-range-array.h \
 	sha1.h \

--- NEW FILE: nfs-workarounds.c ---
/* Copyright (c) 2006 Timo Sirainen */

#include "lib.h"
#include "nfs-workarounds.h"

#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

int nfs_safe_open(const char *path, int flags)
{
        const char *dir = NULL;
        struct stat st;
        unsigned int i;
        int fd;

        i_assert((flags & O_CREAT) == 0);

        t_push();
        for (i = 1;; i++) {
                fd = open(path, flags);
                if (fd != -1 || errno != ESTALE || i == NFS_ESTALE_RETRY_COUNT)
                        break;

                /* ESTALE: Some operating systems may fail with this if they
                   can't internally revalidating the NFS handle. It may also
                   happen if the parent directory has been deleted. If the
                   directory still exists, try reopening the file. */
                if (dir == NULL) {
                        dir = strrchr(path, '/');
                        if (dir == NULL)
                                break;
                        dir = t_strdup_until(path, dir);
                }
                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
                           with the original ESTALE error and let our caller
                           handle it. */
                        errno = ESTALE;
                        break;
                }

                /* directory still exists, try reopening */
        }
        t_pop();
        return fd;
}

--- NEW FILE: nfs-workarounds.h ---
#ifndef __NFS_WORKAROUNDS_H
#define __NFS_WORKAROUNDS_H

/* When syscall fails with ESTALE error, how many times to try reopening the
   file and retrying the operation. */
#define NFS_ESTALE_RETRY_COUNT 10

/* open() with some NFS workarounds */
int nfs_safe_open(const char *path, int flags);

#endif

--- safe-open.c DELETED ---

--- safe-open.h DELETED ---



More information about the dovecot-cvs mailing list