From: Jeff Layton <jlayton@redhat.com>
To: Neil Brown <neilb@suse.de>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
nfs@lists.sourceforge.net, Jeff Layton <jlayton@redhat.com>
Subject: Re: [PATCH] nfs-utils: make auth_reload respect sub-second timestamps on etab
Date: Thu, 3 May 2007 07:58:15 -0400 [thread overview]
Message-ID: <20070503115814.GA4641@dantu.rdu.redhat.com> (raw)
In-Reply-To: <17977.13065.307535.484372@notabene.brown>
On Thu, May 03, 2007 at 10:55:37AM +1000, Neil Brown wrote:
> On Thursday April 26, jlayton@redhat.com wrote:
> >
> > This patch seems to fix the problem as well. mountd holds the etab open, but
> > doesn't actually do any I/O on that fd. This makes sure that the inode number
> > of the new etab file won't be the same as the current version that mountd is
> > aware of. I also added a comment to xtab_write to warn people who might
> > consider changing how the files are written.
> >
> > We might also consider adding back in some of the mtime logic to try and
> > catch programs that edit the file in place, but I'm not sure if that's
> > worthwhile.
>
> I agree.
>
> >
> > Neil, what do you think?
>
> I was about to say "fine", but then saw the problem.
> Because of the way get_exportlist uses the return value, that value
> needs to unique over all time (or close to it). So returning the
> inode number won't work (as we have seen that ext3 cycles between
> two).
>
> A simple event counter could be returned though, which would give
> something unique to get_exportlist.
>
> NeilBrown
Ahh, good catch. I wasn't considering that mountd might call into auth_reload
from other functions between get_exportlist calls. I'm not sure we even really
need a static counter here though. How about just having auth_reload return
true if the reload occurred?
Signed-off-by: Jeff Layton <jlayton@redhat.com>
diff --git a/support/export/xtab.c b/support/export/xtab.c
index 0ddb251..292087b 100644
--- a/support/export/xtab.c
+++ b/support/export/xtab.c
@@ -80,6 +80,12 @@ xtab_export_read(void)
return xtab_read(_PATH_ETAB, 1);
}
+/*
+ * mountd now keeps an open fd for the etab at all times to make sure that the
+ * inode number changes when the xtab_export_write is done. If you change the
+ * routine below such that the files are edited in place, then you'll need to
+ * fix the auth_reload logic as well...
+ */
static int
xtab_write(char *xtab, char *xtabtmp, int is_export)
{
diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
index 183c9ea..5638a05 100644
--- a/utils/mountd/auth.c
+++ b/utils/mountd/auth.c
@@ -14,6 +14,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
+#include <unistd.h>
#include "misc.h"
#include "nfslib.h"
#include "exportfs.h"
@@ -46,24 +47,33 @@ auth_init(char *exports)
xtab_mount_write();
}
-time_t
+/* Check the etab file. Reload it and return true if it changed */
+int
auth_reload()
{
struct stat stb;
- static time_t last_modified = 0;
+ static ino_t last_inode;
+ static int last_fd;
+ int fd;
- if (stat(_PATH_ETAB, &stb) < 0)
+ if ((fd = open(_PATH_ETAB, O_RDONLY)) < 0) {
+ xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
+ } else if (fstat(fd, &stb) < 0) {
xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
- if (stb.st_mtime == last_modified)
- return last_modified;
- last_modified = stb.st_mtime;
+ } else if (stb.st_ino == last_inode) {
+ close(fd);
+ return 0;
+ } else {
+ close(last_fd);
+ last_fd = fd;
+ last_inode = stb.st_ino;
+ }
export_freeall();
memset(&my_client, 0, sizeof(my_client));
- // export_read(export_file);
xtab_export_read();
- return last_modified;
+ return 1;
}
static nfs_export *
diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
index 04141d1..c3324cf 100644
--- a/utils/mountd/mountd.c
+++ b/utils/mountd/mountd.c
@@ -465,19 +465,14 @@ static exports
get_exportlist(void)
{
static exports elist = NULL;
- static time_t etime = 0;
- time_t atime;
struct exportnode *e, *ne;
struct groupnode *g, *ng, *c, **cp;
nfs_export *exp;
int i;
- atime = auth_reload();
- if (elist && atime == etime)
+ if (auth_reload() == 0)
return elist;
- etime = atime;
-
for (e = elist; e != NULL; e = ne) {
ne = e->ex_next;
for (g = e->ex_groups; g != NULL; g = ng) {
diff --git a/utils/mountd/mountd.h b/utils/mountd/mountd.h
index b539278..d64c171 100644
--- a/utils/mountd/mountd.h
+++ b/utils/mountd/mountd.h
@@ -40,7 +40,7 @@ bool_t mount_mnt_3_svc(struct svc_req *, dirpath *, mountres3 *);
void mount_dispatch(struct svc_req *, SVCXPRT *);
void auth_init(char *export_file);
-time_t auth_reload(void);
+int auth_reload(void);
nfs_export * auth_authenticate(char *what, struct sockaddr_in *sin,
char *path);
void auth_export(nfs_export *exp);
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs
next prev parent reply other threads:[~2007-05-03 11:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-25 17:39 [PATCH] nfs-utils: make auth_reload respect sub-second timestamps on etab Jeff Layton
2007-04-25 18:09 ` Jeff Layton
2007-04-25 20:13 ` Jeff Layton
2007-04-25 21:29 ` Chuck Lever
2007-04-26 4:56 ` Neil Brown
2007-04-26 12:05 ` Jeff Layton
2007-04-26 16:23 ` Jeff Layton
2007-04-26 16:58 ` J. Bruce Fields
2007-04-26 17:00 ` Jeff Layton
2007-04-26 17:24 ` J. Bruce Fields
2007-04-26 18:29 ` Jeff Layton
2007-05-03 0:55 ` Neil Brown
2007-05-03 11:58 ` Jeff Layton [this message]
2007-05-03 12:11 ` Jeff Layton
2007-04-26 17:33 ` Jeff Layton
2007-04-26 12:35 ` J. Bruce Fields
2007-04-26 4:50 ` Neil Brown
2007-04-26 11:50 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070503115814.GA4641@dantu.rdu.redhat.com \
--to=jlayton@redhat.com \
--cc=bfields@fieldses.org \
--cc=neilb@suse.de \
--cc=nfs@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox