walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
c11fb47
commit ec08843916d07c28045398e5b17e7347a8fa0135
c11fb47
Author: Steve Dickson <steved@redhat.com>
c11fb47
Date:   Fri May 11 12:13:06 2007 -0400
c11fb47
c11fb47
    nfs-utils: have mountd hold open etab file to force inode number to change
c11fb47
    
c11fb47
    This patch changes mountd to hold the etab file open so that when it's
c11fb47
    changed by exportfs, the inode number should change. We then change
c11fb47
    auth_reload to reload the file based on whether st_ino is different
c11fb47
    from the last time it was checked. It also changes auth_reload to
c11fb47
    maintain a static counter value and return it instead of a timestamp
c11fb47
    and fixes up get_exportlist accordingly. Finally, it adds some
c11fb47
    comments to xtab_write to warn people about editing the etab in place.
c11fb47
    
c11fb47
    Signed-off-by: Jeff Layton <jlayton@redhat.com>
c11fb47
    
c11fb47
    Signed-off-by: Steve Dickson <steved@redhat.com>
c11fb47
c11fb47
diff --git a/support/export/xtab.c b/support/export/xtab.c
c11fb47
index 0ddb251..292087b 100644
c11fb47
--- a/support/export/xtab.c
c11fb47
+++ b/support/export/xtab.c
c11fb47
@@ -80,6 +80,12 @@ xtab_export_read(void)
c11fb47
 	return xtab_read(_PATH_ETAB, 1);
c11fb47
 }
c11fb47
 
c11fb47
+/*
c11fb47
+ * mountd now keeps an open fd for the etab at all times to make sure that the
c11fb47
+ * inode number changes when the xtab_export_write is done. If you change the
c11fb47
+ * routine below such that the files are edited in place, then you'll need to
c11fb47
+ * fix the auth_reload logic as well...
c11fb47
+ */
c11fb47
 static int
c11fb47
 xtab_write(char *xtab, char *xtabtmp, int is_export)
c11fb47
 {
c11fb47
diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
c11fb47
index 183c9ea..f7fe23d 100644
c11fb47
--- a/utils/mountd/auth.c
c11fb47
+++ b/utils/mountd/auth.c
c11fb47
@@ -14,6 +14,7 @@
c11fb47
 #include <netinet/in.h>
c11fb47
 #include <arpa/inet.h>
c11fb47
 #include <errno.h>
c11fb47
+#include <unistd.h>
c11fb47
 #include "misc.h"
c11fb47
 #include "nfslib.h"
c11fb47
 #include "exportfs.h"
c11fb47
@@ -46,24 +47,34 @@ auth_init(char *exports)
c11fb47
 	xtab_mount_write();
c11fb47
 }
c11fb47
 
c11fb47
-time_t
c11fb47
+unsigned int
c11fb47
 auth_reload()
c11fb47
 {
c11fb47
 	struct stat		stb;
c11fb47
-	static time_t		last_modified = 0;
c11fb47
-
c11fb47
-	if (stat(_PATH_ETAB, &stb) < 0)
c11fb47
+	static ino_t		last_inode;
c11fb47
+	static int		last_fd;
c11fb47
+	static unsigned int	counter;
c11fb47
+	int			fd;
c11fb47
+
c11fb47
+	if ((fd = open(_PATH_ETAB, O_RDONLY)) < 0) {
c11fb47
+		xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
c11fb47
+	} else if (fstat(fd, &stb) < 0) {
c11fb47
 		xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
c11fb47
-	if (stb.st_mtime == last_modified)
c11fb47
-		return last_modified;
c11fb47
-	last_modified = stb.st_mtime;
c11fb47
+	} else if (stb.st_ino == last_inode) {
c11fb47
+		close(fd);
c11fb47
+		return counter;
c11fb47
+	} else {
c11fb47
+		close(last_fd);
c11fb47
+		last_fd = fd;
c11fb47
+		last_inode = stb.st_ino;
c11fb47
+	}
c11fb47
 
c11fb47
 	export_freeall();
c11fb47
 	memset(&my_client, 0, sizeof(my_client));
c11fb47
-	// export_read(export_file);
c11fb47
 	xtab_export_read();
c11fb47
+	++counter;
c11fb47
 
c11fb47
-	return last_modified;
c11fb47
+	return counter;
c11fb47
 }
c11fb47
 
c11fb47
 static nfs_export *
c11fb47
diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
c11fb47
index fc9a73c..09cab84 100644
c11fb47
--- a/utils/mountd/mountd.c
c11fb47
+++ b/utils/mountd/mountd.c
c11fb47
@@ -465,18 +465,18 @@ static exports
c11fb47
 get_exportlist(void)
c11fb47
 {
c11fb47
 	static exports		elist = NULL;
c11fb47
-	static time_t		etime = 0;
c11fb47
-	time_t			atime;
c11fb47
 	struct exportnode	*e, *ne;
c11fb47
 	struct groupnode	*g, *ng, *c, **cp;
c11fb47
 	nfs_export		*exp;
c11fb47
 	int			i;
c11fb47
+	static unsigned int	ecounter;
c11fb47
+	unsigned int		acounter;
c11fb47
 
c11fb47
-	atime = auth_reload();
c11fb47
-	if (elist && atime == etime)
c11fb47
+	acounter = auth_reload();
c11fb47
+	if (elist && acounter == ecounter)
c11fb47
 		return elist;
c11fb47
 
c11fb47
-	etime = atime;
c11fb47
+	ecounter = acounter;
c11fb47
 
c11fb47
 	for (e = elist; e != NULL; e = ne) {
c11fb47
 		ne = e->ex_next;
c11fb47
diff --git a/utils/mountd/mountd.h b/utils/mountd/mountd.h
c11fb47
index b539278..31bacb5 100644
c11fb47
--- a/utils/mountd/mountd.h
c11fb47
+++ b/utils/mountd/mountd.h
c11fb47
@@ -40,7 +40,7 @@ bool_t		mount_mnt_3_svc(struct svc_req *, dirpath *, mountres3 *);
c11fb47
 
c11fb47
 void		mount_dispatch(struct svc_req *, SVCXPRT *);
c11fb47
 void		auth_init(char *export_file);
c11fb47
-time_t		auth_reload(void);
c11fb47
+unsigned int	auth_reload(void);
c11fb47
 nfs_export *	auth_authenticate(char *what, struct sockaddr_in *sin,
c11fb47
 					char *path);
c11fb47
 void		auth_export(nfs_export *exp);