Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jan 2013 20:19:28 -0500 (EST)
From:      Rick Macklem <rmacklem@uoguelph.ca>
To:        Jason Keltz <jas@cse.yorku.ca>
Cc:        FreeBSD Filesystems <freebsd-fs@freebsd.org>
Subject:   Re: Problems Re-Starting mountd
Message-ID:  <2094136156.1801692.1357694368838.JavaMail.root@erie.cs.uoguelph.ca>
In-Reply-To: <1855706034.1801685.1357694364311.JavaMail.root@erie.cs.uoguelph.ca>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
You could test the attached patch, which I think makes mountd
load new export entries from a file called /etc/exports.new
without deleting the exports already in place, when sent a
USR1 signal.

After applying the patch to mountd.c, rebuilding and replacing
it, you would:
- put new entries for file systems not yet exported in both
  /etc/exports and /etc/exports.new
# kill -USR1 <mountd's pid>
- delete /etc/exports.new
Don't send HUP to mountd for this case.

Very lightly tested, rick
ps: Sometimes it's faster to just code this stuff instead of
    discussing if/how it can be done;-)
pss: This patch isn't ready for head. If it is useful, it might
    make sense to add a new mountd option that specifies the
    name of the file (/etc/exports.new or ...), so that this
    capability isn't enabled by default.

[-- Attachment #2 --]
--- usr.sbin/mountd/mountd.c.savnew	2013-01-08 19:32:46.000000000 -0500
+++ usr.sbin/mountd/mountd.c	2013-01-08 19:54:51.000000000 -0500
@@ -190,6 +190,7 @@ void	free_exp(struct exportlist *);
 void	free_grp(struct grouplist *);
 void	free_host(struct hostlist *);
 void	get_exportlist(void);
+void	get_new_exportlist(void);
 int	get_host(char *, struct grouplist *, struct grouplist *);
 struct hostlist *get_ht(void);
 int	get_line(void);
@@ -200,6 +201,7 @@ struct grouplist *get_grp(void);
 void	hang_dirp(struct dirlist *, struct grouplist *,
 				struct exportlist *, int);
 void	huphandler(int sig);
+void	usr1handler(int sig);
 int	makemask(struct sockaddr_storage *ssp, int bitlen);
 void	mntsrv(struct svc_req *, SVCXPRT *);
 void	nextfield(char **, char **);
@@ -225,6 +227,7 @@ struct mountlist *mlhead;
 struct grouplist *grphead;
 char *exnames_default[2] = { _PATH_EXPORTS, NULL };
 char **exnames;
+char *new_exname = "/etc/exports.new";
 char **hosts = NULL;
 struct xucred def_anon = {
 	XUCRED_VERSION,
@@ -239,6 +242,7 @@ int nhosts = 0;
 int dir_only = 1;
 int dolog = 0;
 int got_sighup = 0;
+int got_sigusr1 = 0;
 int xcreated = 0;
 
 char *svcport_str = NULL;
@@ -411,6 +415,7 @@ main(int argc, char **argv)
 		signal(SIGQUIT, SIG_IGN);
 	}
 	signal(SIGHUP, huphandler);
+	signal(SIGUSR1, usr1handler);
 	signal(SIGTERM, terminate);
 	signal(SIGPIPE, SIG_IGN);
 
@@ -573,6 +578,10 @@ main(int argc, char **argv)
 			get_exportlist();
 			got_sighup = 0;
 		}
+		if (got_sigusr1) {
+			get_new_exportlist();
+			got_sigusr1 = 0;
+		}
 		readfds = svc_fdset;
 		switch (select(svc_maxfd + 1, &readfds, NULL, NULL, NULL)) {
 		case -1:
@@ -951,6 +960,7 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *t
 
 	sigemptyset(&sighup_mask);
 	sigaddset(&sighup_mask, SIGHUP);
+	sigaddset(&sighup_mask, SIGUSR1);
 	saddr = svc_getrpccaller(transp)->buf;
 	switch (saddr->sa_family) {
 	case AF_INET6:
@@ -1227,6 +1237,7 @@ xdr_explist_common(XDR *xdrsp, caddr_t c
 
 	sigemptyset(&sighup_mask);
 	sigaddset(&sighup_mask, SIGHUP);
+	sigaddset(&sighup_mask, SIGUSR1);
 	sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
 	ep = exphead;
 	while (ep) {
@@ -1799,6 +1810,32 @@ get_exportlist(void)
 }
 
 /*
+ * Get the export list for all new entries.
+ */
+void
+get_new_exportlist(void)
+{
+
+	if (suspend_nfsd != 0)
+		(void)nfssvc(NFSSVC_SUSPENDNFSD, NULL);
+
+	/*
+	 * Read in the new exports file and add to the list, calling
+	 * nmount() as we go along to push the export rules into the kernel.
+	 */
+	if (debug)
+		warnx("reading new exports from %s", new_exname);
+	if ((exp_file = fopen(new_exname, "r")) != NULL) {
+		get_exportlist_one();
+		fclose(exp_file);
+	} else
+		syslog(LOG_WARNING, "can't open %s", new_exname);
+
+	/* Resume the nfsd. If they weren't suspended, this is harmless. */
+	(void)nfssvc(NFSSVC_RESUMENFSD, NULL);
+}
+
+/*
  * Allocate an export list element
  */
 struct exportlist *
@@ -3212,6 +3249,12 @@ huphandler(int sig __unused)
 	got_sighup = 1;
 }
 
+void
+usr1handler(int sig __unused)
+{
+	got_sigusr1 = 1;
+}
+
 void terminate(int sig __unused)
 {
 	pidfile_remove(pfh);

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2094136156.1801692.1357694368838.JavaMail.root>