FreeBSD-10.1-mountd.patch 30.7 KB
Newer Older
1 2
diff -Nu mountd.orig/Makefile mountd/Makefile
--- mountd.orig/Makefile	2014-11-11 13:02:20.000000000 -0700
3
+++ mountd/Makefile	2015-06-08 14:01:18.000000000 -0600
4 5 6 7 8
@@ -9,6 +9,9 @@
 CFLAGS+= -I${MOUNT}
 WARNS?= 2
 
+# Emulab-specific CFLAGS
9
+CFLAGS+= -DSPLIT_MOUNT -DMOUNTD_STATS -DCACHE_ROOT_CRED # -g # -pg -O0 # -DDEBUG
10 11 12 13 14 15
+
 .PATH: ${MOUNT}
 
 DPADD=	${LIBUTIL}
diff -Nu mountd.orig/mountd.c mountd/mountd.c
--- mountd.orig/mountd.c	2014-11-11 13:02:20.000000000 -0700
16
+++ mountd/mountd.c	2015-06-08 13:57:05.000000000 -0600
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
@@ -87,6 +87,31 @@
 #include <stdarg.h>
 #endif
 
+#ifdef MOUNTD_STATS
+#include <sys/time.h>
+#define TS_DEF(s)	struct timeval s = {0, 0}
+#define TS_GET(s)	{ gettimeofday(&s, NULL); }
+#define TS_DIFF(o,n,r)	{ timersub(&n, &o, &r); }
+#define TS_SUM(o,n,r)	{ timeradd(&n, &o, &r); }
+#define TS_ZERO(s)	{ s.tv_sec = s.tv_usec = 0; }
+#define TS_PRINT(s)	{ fprintf(stderr, "%ld.%06ld", s.tv_sec, s.tv_usec); }
+#define TSC_DEF(c)	int c = 0
+#define TSC_INC(c)	{ c++; }
+#define TSC_ZERO(c)	{ c = 0; }
+#define TSC_PRINT(c)	{ fprintf(stderr, "%d", c); }
+#else
+#define TS_DEF(s)
+#define TS_GET(s)
+#define TS_DIFF(n,o,r)
+#define TS_SUM(o,n,r)
+#define TS_ZERO(s)
+#define TS_PRINT(s)
+#define TSC_DEF(c)
+#define TSC_INC(c)
+#define TSC_ZERO(c)
+#define TSC_PRINT(c)
+#endif
+
 /*
  * Structures for keeping the mount list and export list
  */
@@ -107,21 +132,33 @@
 #define	DP_DEFSET	0x1
 #define DP_HOSTSET	0x2
 
+/*
+ * One for each filesystem exported.
+ * Global list (exphead) is sorted by ex_fsdir, but ex_fs is the unique ID.
+ */
 struct exportlist {
 	struct exportlist *ex_next;
-	struct dirlist	*ex_dirl;
-	struct dirlist	*ex_defdir;
-	int		ex_flag;
-	fsid_t		ex_fs;
-	char		*ex_fsdir;
+	struct dirlist	*ex_dirl;	/* !alldirs: list of exported dirs */
+	struct dirlist	*ex_defdir;	/* alldirs: mount point */
+	int		ex_flag;	/* local state flags */
+	fsid_t		ex_fs;		/* unique FS id */
+	char		*ex_fsdir;	/* mount point of FS */
 	char		*ex_indexfile;
 	int		ex_numsecflavors;
 	int		ex_secflavors[MAXSECFLAVORS];
 	int		ex_defnumsecflavors;
 	int		ex_defsecflavors[MAXSECFLAVORS];
+#ifdef SPLIT_MOUNT
+	int		ex_mflags;	/* mount flags */
+	struct xucred	ex_anon;	/* anon credential */
+	struct statfs	ex_fsinfo;	/* statfs(2) info */
+#endif
 };
 /* ex_flag bits */
 #define	EX_LINKED	0x1
+#define EX_FOUND	0x2
+#define EX_MUSTADD	0x4
+#define EX_MUSTRM	0x8
 
 struct netmsk {
 	struct sockaddr_storage nt_net;
@@ -134,12 +171,21 @@
 	struct netmsk	gt_net;
 };
 
+/*
+ * Group of hosts/networks to which a mount point is exported.
+ * Global list of all groups (grphead) is unordered.
+ */
 struct grouplist {
 	int gr_type;
 	union grouptypes gr_ptr;
 	struct grouplist *gr_next;
-	int gr_numsecflavors;
-	int gr_secflavors[MAXSECFLAVORS];
+	int		 gr_numsecflavors;
+	int		 gr_secflavors[MAXSECFLAVORS];
+#ifdef SPLIT_MOUNT
+	int		 gr_mark;	/* mark for scanning */
+	int		 gr_mflags;	/* mount flags */
+	struct xucred	 gr_anon;	/* anon credential */
+#endif
 };
 /* Group types */
 #define	GT_NULL		0x0
@@ -180,7 +226,7 @@
 void	del_mlist(char *hostp, char *dirp);
 struct dirlist *dirp_search(struct dirlist *, char *);
 int	do_mount(struct exportlist *, struct grouplist *, int,
-		struct xucred *, char *, int, struct statfs *);
+		struct xucred *, char *, int, struct statfs *, int);
 int	do_opt(char **, char **, struct exportlist *, struct grouplist *,
 				int *, int *, struct xucred *);
 struct	exportlist *ex_search(fsid_t *);
@@ -189,7 +235,7 @@
 void	free_exp(struct exportlist *);
 void	free_grp(struct grouplist *);
 void	free_host(struct hostlist *);
-void	get_exportlist(void);
+void	get_exportlist(int);
 int	get_host(char *, struct grouplist *, struct grouplist *);
 struct hostlist *get_ht(void);
 int	get_line(void);
@@ -219,6 +265,7 @@
 int	xdr_fhs(XDR *, caddr_t);
 int	xdr_mlist(XDR *, caddr_t);
 void	terminate(int);
+void	clear_exports(struct exportlist *);
 
 struct exportlist *exphead;
 struct mountlist *mlhead;
138
@@ -240,6 +287,10 @@
139 140 141 142 143
 int dolog = 0;
 int got_sighup = 0;
 int xcreated = 0;
+#ifdef SPLIT_MOUNT
+int got_sigusr1 = 0;
144
+char *tsfile = "/var/run/mountd.ts";
145 146 147 148
+#endif
 
 char *svcport_str = NULL;
 static int	mallocd_svcport = 0;
149
@@ -399,7 +450,7 @@
150 151 152 153 154 155 156 157
 	openlog("mountd", LOG_PID, LOG_DAEMON);
 	if (debug)
 		warnx("getting export list");
-	get_exportlist();
+	get_exportlist(0);
 	if (debug)
 		warnx("getting mount list");
 	get_mountlist();
158
@@ -411,6 +462,9 @@
159 160 161 162 163 164 165 166 167
 		signal(SIGQUIT, SIG_IGN);
 	}
 	signal(SIGHUP, huphandler);
+#ifdef SPLIT_MOUNT
+	signal(SIGUSR1, huphandler);
+#endif
 	signal(SIGTERM, terminate);
 	signal(SIGPIPE, SIG_IGN);
 
168
@@ -570,9 +624,15 @@
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
 	/* Expand svc_run() here so that we can call get_exportlist(). */
 	for (;;) {
 		if (got_sighup) {
-			get_exportlist();
+			get_exportlist(0);
 			got_sighup = 0;
 		}
+#ifdef SPLIT_MOUNT
+		else if (got_sigusr1) {
+			get_exportlist(1);
+			got_sigusr1 = 0;
+		}
+#endif
 		readfds = svc_fdset;
 		switch (select(svc_maxfd + 1, &readfds, NULL, NULL, NULL)) {
 		case -1:
185
@@ -951,6 +1011,9 @@
186 187 188 189 190 191 192 193 194
 
 	sigemptyset(&sighup_mask);
 	sigaddset(&sighup_mask, SIGHUP);
+#ifdef SPLIT_MOUNT
+	sigaddset(&sighup_mask, SIGUSR1);
+#endif
 	saddr = svc_getrpccaller(transp)->buf;
 	switch (saddr->sa_family) {
 	case AF_INET6:
195
@@ -1227,6 +1290,9 @@
196 197 198 199 200 201 202 203 204
 
 	sigemptyset(&sighup_mask);
 	sigaddset(&sighup_mask, SIGHUP);
+#ifdef SPLIT_MOUNT
+	sigaddset(&sighup_mask, SIGUSR1);
+#endif
 	sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
 	ep = exphead;
 	while (ep) {
205
@@ -1335,11 +1401,152 @@
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
 int linesize;
 FILE *exp_file;
 
+TS_DEF(suspend);	/* time spent with NFS service suspended */
+TS_DEF(tsexport);	/* total time spend in the export function */
+TS_DEF(parse);		/* time spend parsing exports files */
+TSC_DEF(plines);	/* total lines parsed */
+TS_DEF(tsremove);	/* time spent removing kernel export entries */
+TSC_DEF(rcalls);	/* export entries removed */
+TS_DEF(tsinsert);	/* time spent inserting kernel export entries */
+TSC_DEF(icalls);	/* export entries inserted */
+TS_DEF(tscompare);	/* time spent comparing lists */
+TS_DEF(tss);
+TS_DEF(tse);
+TS_DEF(ps);
+TS_DEF(pe);
+TS_DEF(cs);
+TS_DEF(ce);
+
+/* micro */
+TS_DEF(lsearch);	/* time spent in ex_search */
+TSC_DEF(lscalls);	/* ex_search calls */
+TS_DEF(linsert);	/* time spent inserting entries in export list */
+TSC_DEF(licalls);	/* insert operations */
+TS_DEF(phost);		/* time spent parsing host/netgroup strings */
+TSC_DEF(phcalls);	/* number of such parses */
+TS_DEF(hangdir);	/* time spend in hang_dirp */
+TSC_DEF(hdcalls);	/* number of such calls */
234 235
+TS_DEF(doopt);		/* time spend in doopt */
+TSC_DEF(docalls);	/* number of such calls */
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
+TS_DEF(ls);
+TS_DEF(le);
+
+
+#ifdef SPLIT_MOUNT
+/*
+ * Install export info into the kernel.
+ * Mimics xdr_explist_common and put_exlist.
+ */
+static int
+export_dirlist(struct exportlist *ep, struct dirlist *dp,
+	       struct dirlist *ddp, int *putdefp)
+{
+	struct grouplist *grp;
+	struct hostlist *hp;
+	int gotalldir = 0;
+
+	if (dp) {
+		if (export_dirlist(ep, dp->dp_left, ddp, putdefp))
+			return (1);
+
+		if (ddp && !strcmp(ddp->dp_dirp, dp->dp_dirp)) {
+			gotalldir = 1;
+			*putdefp = 1;
+		}
+		if ((dp->dp_flag & DP_DEFSET) == 0 &&
+		    (gotalldir == 0 || (ddp->dp_flag & DP_DEFSET) == 0)) {
+			hp = dp->dp_hosts;
+			while (hp) {
+				grp = hp->ht_grp;
+				/* only put out each group once */
+				if (!grp->gr_mark) {
+					grp->gr_mark = 1;
+					do_mount(ep, grp, grp->gr_mflags,
+						 &grp->gr_anon, dp->dp_dirp,
+						 strlen(dp->dp_dirp),
+						 &ep->ex_fsinfo, 1);
+				}
+				hp = hp->ht_next;
+				if (gotalldir &&
+				    hp == (struct hostlist *)NULL) {
+					hp = ddp->dp_hosts;
+					gotalldir = 0;
+				}
+			}
+		} else if ((ep->ex_flag & EX_FOUND) == 0) {
+			struct grouplist tgrp;
+
+			ep->ex_flag |= EX_FOUND;
+			if (grp) {
+				fprintf(stderr, "oops, got a grp!\n");
+			} else {
+				grp = &tgrp;
+				grp->gr_type = GT_DEFAULT;
+				grp->gr_mflags = ep->ex_mflags;
+				grp->gr_anon = ep->ex_anon;
+			}
+			do_mount(ep, grp,
+				 grp->gr_mflags, &grp->gr_anon,
+				 dp->dp_dirp, strlen(dp->dp_dirp),
+				 &ep->ex_fsinfo, 1);
+		}
+		if (export_dirlist(ep, dp->dp_right, ddp, putdefp))
+			return (1);
+	}
+
+	return (0);
+}
+
+static int
+load_exports(void)
+{
+	struct exportlist *ep, **prevep;
+	int putdef;
+	int fail, errors = 0;
+
+	for (ep = exphead; ep; ep = ep->ex_next)
+		ep->ex_flag &= ~EX_FOUND;
+
+	prevep = &exphead;
+	ep = exphead;
+	while (ep) {
+		if (ep->ex_flag & EX_MUSTADD) {
+			putdef = fail = 0;
+			if (export_dirlist(ep, ep->ex_dirl, ep->ex_defdir,
+					   &putdef))
+				fail++;
+			if (!fail && ep->ex_defdir && putdef == 0) {
+				if (export_dirlist(ep, ep->ex_defdir, NULL,
+						   &putdef))
+					fail++;
+			}
+			if (fail) {
+				struct exportlist *epnext;
+
+				warnx("WARNING: some exports for %s failed! Removing all",
+				      ep->ex_fsdir);
+				*prevep = epnext = ep->ex_next;
+				ep->ex_next = 0;
+				ep->ex_flag |= EX_MUSTRM;
+				clear_exports(ep);
+				free_exp(ep);
+				ep = epnext;
+				errors++;
+				continue;
+			}
+		}
+		prevep = &ep->ex_next;
+		ep = ep->ex_next;
+	}
+	return (errors);
+}
+#endif
+
 /*
  * Get the export list from one, currently open file
  */
 static void
-get_exportlist_one(void)
+get_exportlist_one(int doexport)
 {
 	struct exportlist *ep, *ep2;
 	struct grouplist *grp, *tgrp;
359
@@ -1352,9 +1559,11 @@
360 361 362 363 364 365 366 367 368 369 370
 
 	v4root_phase = 0;
 	dirhead = (struct dirlist *)NULL;
+	TS_GET(ps);
 	while (get_line()) {
 		if (debug)
 			warnx("got line %s", line);
+		TSC_INC(plines);
 		cp = line;
 		nextfield(&cp, &endcp);
 		if (*cp == '#')
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
@@ -1394,6 +1603,7 @@
 		len = endcp-cp;
 		tgrp = grp = get_grp();
 		while (len > 0) {
+			int _err;
 			if (len > MNTNAMLEN) {
 			    getexp_err(ep, tgrp);
 			    goto nextline;
@@ -1406,8 +1616,14 @@
 			    if (debug)
 				warnx("doing opt %s", cp);
 			    got_nondir = 1;
-			    if (do_opt(&cp, &endcp, ep, grp, &has_host,
-				&exflags, &anon)) {
+			    TS_GET(ls);
+			    _err = do_opt(&cp, &endcp, ep, grp, &has_host,
+					  &exflags, &anon);
+			    TS_GET(le);
+			    TS_DIFF(ls, le, le);
+			    TS_SUM(le, doopt, doopt);
+			    TSC_INC(docalls);
+			    if (_err) {
 				getexp_err(ep, tgrp);
 				goto nextline;
 			    }
@@ -1462,7 +1678,12 @@
397 398 399 400 401 402 403 404 405 406 407 408
 					 * See if this directory is already
 					 * in the list.
 					 */
+					TS_GET(ls);
 					ep = ex_search(&fsb.f_fsid);
+					TS_GET(le);
+					TS_DIFF(ls, le, le);
+					TS_SUM(le, lsearch, lsearch);
+					TSC_INC(lscalls);
 					if (ep == (struct exportlist *)NULL) {
 					    ep = get_exp();
 					    ep->ex_fs = fsb.f_fsid;
409
@@ -1504,6 +1725,7 @@
410 411 412 413 414 415 416
 				goto nextline;
 			    }
 
+			    TS_GET(ls);
 			    /*
 			     * Get the host or netgroup.
 			     */
417
@@ -1532,6 +1754,10 @@
418 419 420 421 422 423 424 425 426 427
 			    } while (netgrp && getnetgrent(&hst, &usr, &dom));
 			    endnetgrent();
 			    *endcp = savedc;
+			    TS_GET(le);
+			    TS_DIFF(ls, le, le);
+			    TS_SUM(le, phost, phost);
+			    TSC_INC(phcalls);
 			}
 			cp = endcp;
 			nextfield(&cp, &endcp);
428
@@ -1582,11 +1808,17 @@
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
 		 */
 		grp = tgrp;
 		do {
-			if (do_mount(ep, grp, exflags, &anon, dirp, dirplen,
-			    &fsb)) {
+			if (doexport &&
+			    do_mount(ep, grp, exflags, &anon, dirp, dirplen,
+			    &fsb, doexport)) {
 				getexp_err(ep, tgrp);
 				goto nextline;
 			}
+#ifdef SPLIT_MOUNT
+			grp->gr_mflags = exflags;
+			grp->gr_anon = anon;
+			grp->gr_mark = 0;
+#endif
 		} while (grp->gr_next && (grp = grp->gr_next));
 
 		/*
448
@@ -1610,6 +1842,7 @@
449 450 451 452 453 454 455
 		/*
 		 * Success. Update the data structures.
 		 */
+		TS_GET(ls);
 		if (has_host) {
 			hang_dirp(dirhead, tgrp, ep, opt_flags);
 			grp->gr_next = grphead;
456
@@ -1617,13 +1850,22 @@
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
 		} else {
 			hang_dirp(dirhead, (struct grouplist *)NULL, ep,
 				opt_flags);
+#ifdef SPLIT_MOUNT
+			ep->ex_mflags = exflags;
+			ep->ex_anon = anon;
+#endif
 			free_grp(grp);
 		}
+		TS_GET(le);
+		TS_DIFF(ls, le, le);
+		TS_SUM(le, hangdir, hangdir);
+		TSC_INC(hdcalls);
 		dirhead = (struct dirlist *)NULL;
 		if ((ep->ex_flag & EX_LINKED) == 0) {
 			ep2 = exphead;
 			epp = &exphead;
 
+			TS_GET(ls);
 			/*
 			 * Insert in the list in alphabetical order.
 			 */
479
@@ -1634,8 +1876,15 @@
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
 			if (ep2)
 				ep->ex_next = ep2;
 			*epp = ep;
+			TS_GET(le);
+			TS_DIFF(ls, le, le);
+			TS_SUM(le, linsert, linsert);
+			TSC_INC(licalls);
 			ep->ex_flag |= EX_LINKED;
 		}
+#ifdef SPLIT_MOUNT
+		ep->ex_fsinfo = fsb;
+#endif
 nextline:
 		v4root_phase = 0;
 		if (dirhead) {
495
@@ -1643,75 +1892,63 @@
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
 			dirhead = (struct dirlist *)NULL;
 		}
 	}
+	TS_GET(pe);
+	TS_DIFF(ps, pe, pe);
+	TS_SUM(pe, parse, parse);
 }
 
 /*
- * Get the export list from all specified files
+ * And delete exports that are in the kernel for all local
+ * filesystems.
+ * XXX: Should know how to handle all local exportable filesystems.
  */
 void
-get_exportlist(void)
+clear_exports(struct exportlist *list)
 {
-	struct exportlist *ep, *ep2;
-	struct grouplist *grp, *tgrp;
 	struct export_args export;
 	struct iovec *iov;
-	struct statfs *fsp, *mntbufp;
+	struct statfs *fsp, *mntbufp, **mntbufpp;
 	struct xvfsconf vfc;
 	char errmsg[255];
 	int num, i;
 	int iovlen;
-	int done;
-	struct nfsex_args eargs;
 
-	if (suspend_nfsd != 0)
-		(void)nfssvc(NFSSVC_SUSPENDNFSD, NULL);
-	v4root_dirpath[0] = '\0';
+	if (debug)
+		warnx("clearing %s exports", list ? "selective" : "all");
+
+	TS_GET(tss);
 	bzero(&export, sizeof(export));
 	export.ex_flags = MNT_DELEXPORT;
 	iov = NULL;
 	iovlen = 0;
 	bzero(errmsg, sizeof(errmsg));
 
-	/*
-	 * First, get rid of the old list
-	 */
-	ep = exphead;
-	while (ep) {
-		ep2 = ep;
-		ep = ep->ex_next;
-		free_exp(ep2);
-	}
-	exphead = (struct exportlist *)NULL;
-
-	grp = grphead;
-	while (grp) {
-		tgrp = grp;
-		grp = grp->gr_next;
-		free_grp(tgrp);
+	if (list) {
+#ifdef SPLIT_MOUNT
+		struct exportlist *exp;
+		num = 0;
+		for (exp = list; exp; exp = exp->ex_next)
+			if (exp->ex_flag & EX_MUSTRM)
+				num++;
+		if (debug)
+			fprintf(stderr, "clear_exports: found %d to remove\n",
+				num);
+		if (num) {
+			mntbufpp = malloc(num * sizeof(struct statfs *));
+			if (mntbufpp == NULL)
+				out_of_mem();
+			i = 0;
+			for (exp = list; exp; exp = exp->ex_next)
+				if (exp->ex_flag & EX_MUSTRM)
+					mntbufpp[i++] = &exp->ex_fsinfo;
+		}
+#else
+		warnx("clear_exports: partial clear not supported");
+		list = NULL;
+#endif
 	}
-	grphead = (struct grouplist *)NULL;
-
-	/*
-	 * and the old V4 root dir.
-	 */
-	bzero(&eargs, sizeof (eargs));
-	eargs.export.ex_flags = MNT_DELEXPORT;
-	if (run_v4server > 0 &&
-	    nfssvc(NFSSVC_V4ROOTEXPORT, (caddr_t)&eargs) < 0 &&
-	    errno != ENOENT)
-		syslog(LOG_ERR, "Can't delete exports for V4:");
-
-	/*
-	 * and clear flag that notes if a public fh has been exported.
-	 */
-	has_publicfh = 0;
-
-	/*
-	 * And delete exports that are in the kernel for all local
-	 * filesystems.
-	 * XXX: Should know how to handle all local exportable filesystems.
-	 */
-	num = getmntinfo(&mntbufp, MNT_NOWAIT);
+	if (!list)
+		num = getmntinfo(&mntbufp, MNT_NOWAIT);
 
 	if (num > 0) {
 		build_iovec(&iov, &iovlen, "fstype", NULL, 0);
608
@@ -1723,7 +1960,10 @@
609 610 611 612 613 614 615 616 617 618 619
 	}
 
 	for (i = 0; i < num; i++) {
-		fsp = &mntbufp[i];
+		if (list)
+			fsp = mntbufpp[i];
+		else
+			fsp = &mntbufp[i];
 		if (getvfsbyname(fsp->f_fstypename, &vfc) != 0) {
 			syslog(LOG_ERR, "getvfsbyname() failed for %s",
 			    fsp->f_fstypename);
620
@@ -1752,6 +1992,7 @@
621 622 623 624 625 626 627
 			    "can't delete exports for %s: %m %s",
 			    fsp->f_mntonname, errmsg);
 		}
+		TSC_INC(rcalls);
 	}
 
 	if (iov != NULL) {
628
@@ -1766,7 +2007,333 @@
629 630 631 632 633 634
 		/* free iov, allocated by realloc() */
 		free(iov);
 		iovlen = 0;
+
+		if (list)
+			free(mntbufpp);
635
+	}
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
+	TS_GET(tse);
+	TS_DIFF(tss, tse, tse);
+	TS_SUM(tsremove, tse, tsremove);
+}
+
+#ifdef SPLIT_MOUNT
+struct ihostlist {
+	int nhost;
+	int nnet;
+	int ndef;
+	int nign;
+	in_addr_t addr[2000];
+};
+
+static int
+intcmp(const void *p1, const void *p2)
+{
+	in_addr_t a1 = *(in_addr_t *)p1;
+	in_addr_t a2 = *(in_addr_t *)p2;
+	if (a1 < a2)
+		return -1;
+	if (a1 > a2)
+		return 1;
+	return 0;
+}
+
+/*
+ * Count up the number of different group types
+ * and create a sorted list of all hosts and networks
+ * (networks are represented by their broadcast addr).
+ */
+static int
+build_ihostlist(struct hostlist *list, struct ihostlist *ilist)
+{
+	struct hostlist *hp;
+	struct grouplist *grp;
+	int ix = 0;
+
+	memset(ilist, 0, sizeof(*ilist));
+	for (hp = list; hp; hp = hp->ht_next) {
+		grp = hp->ht_grp;
+		switch (grp->gr_type) {
+		case GT_HOST:
+		{
+			struct addrinfo *ai = grp->gr_ptr.gt_addrinfo;
+			struct sockaddr_in *sin;
+ 
+			if (ai->ai_addr->sa_family != AF_INET) {
+				warnx("compare: non-IPv4 host in list");
+				return 1;
+			}
+			sin = ((struct sockaddr_in *)ai->ai_addr);
+			ilist->addr[ix] = ntohl(sin->sin_addr.s_addr);
+			ilist->nhost++;
+			break;
+		}
+		case GT_NET:
+		{
+			struct sockaddr_in *sin;
+			in_addr_t addr, mask;
+
+			if (grp->gr_ptr.gt_net.nt_net.ss_family != AF_INET) {
+				warnx("compare: non-IPv4 net in list");
+				return 1;
+			}
+			sin = (struct sockaddr_in *)&grp->gr_ptr.gt_net.nt_net;
+			addr = ntohl(sin->sin_addr.s_addr);
+			sin = (struct sockaddr_in *)&grp->gr_ptr.gt_net.nt_mask;
+			mask = ntohl(sin->sin_addr.s_addr);
+			ilist->addr[ix] = (addr & mask) | (~0 & ~mask);
+			ilist->nnet++;
+			break;
+		}
+		case GT_DEFAULT:
+			ilist->ndef++;
+			continue;
+		case GT_IGNORE:
+			ilist->nign++;
+			continue;
+		default:
+			warnx("bad address type");
+			return(1);
+		}
+		if (++ix == 2000) {
+			warnx("too many addresses");
+			return 1;
+		}
+	}
+	if (ix > 1)
+		qsort(&ilist->addr[0], ix, sizeof(ilist->addr[0]), intcmp);
+#if 0
+{
+int sz = ix+4;
+fprintf(stderr, "ilist: ");
+for (ix = 0; ix < sz; ix++)
+fprintf(stderr, "%08x/", ((int *)ilist)[ix]);
+fprintf(stderr,"\n");
+}
+#endif
+	return(0);
+}
+
+static int
+compare_hostlist(struct hostlist *old, struct hostlist *new)
+{
+	struct ihostlist olist, nlist;
+
+	if (old == NULL && new == NULL)
+		return(0);
+	if (old == NULL || new == NULL)
+		return(1);
+
+	if (build_ihostlist(old, &olist) ||
+	    build_ihostlist(new, &nlist) ||
+	    memcmp(&olist, &nlist, sizeof(nlist)))
+		return(1);
+
+	return(0);
+}
+
+static int
+compare_dirlist(struct dirlist *old, struct dirlist *new)
+{
+	if (old == NULL && new == NULL)
+		return(0);
+	if (old == NULL || new == NULL)
+		return(1);
+
+	return (strcmp(old->dp_dirp, new->dp_dirp) != 0 ||
+		old->dp_flag != new->dp_flag ||
+		compare_hostlist(old->dp_hosts, new->dp_hosts) ||
+		compare_dirlist(old->dp_left, new->dp_left) ||
+		compare_dirlist(old->dp_right, new->dp_right));
+}
+
+static int
+same_exportlist(struct exportlist *old, struct exportlist *new)
+{
+	if (old->ex_numsecflavors || new->ex_numsecflavors ||
+	    old->ex_indexfile || new->ex_indexfile) {
+		warnx("%s: bad options, cannot do incremental update",
+		      old->ex_fsdir);
+		return 0;
+	}
+	if (old->ex_mflags != new->ex_mflags ||
+	    memcmp(&old->ex_anon, &new->ex_anon, sizeof(new->ex_anon)))
+		return 0;
+	return 1;
+}
+
+/*
+ * Compare two lists looking for differences.
+ * Returns non-zero if lists are different, with lists annotated:
+ *   old list entries that no longer exist will have EX_MUSTRM set
+ *   new list entries that need to be added will have EX_MUSTADD set
+ *   (note that a changed entry will have both EX_MUSTRM set in old
+ *   and EX_MUSTADD set in new)
+ * Returns zero if lists are the same.
+ */
+static int
+compare_exportlist(struct exportlist *old, struct exportlist *new)
+{
+	struct exportlist *nep, *oep;
+	int changed = 0;
+
+	TS_GET(tscompare);
+
+	/* pathological cases */
+	if (new == NULL) {
+		syslog(LOG_INFO, "compare: remove all");
+		for (oep = old; oep; oep = oep->ex_next)
+			oep->ex_flag |= EX_MUSTRM;
+		changed = (old ? 1 : 0);
+		goto done;
+	}
+	if (old == NULL) {
+		syslog(LOG_INFO, "compare: add all");
+		for (nep = new; nep; nep = nep->ex_next)
+			nep->ex_flag |= EX_MUSTADD;
+		changed = (new ? 1 : 0);
+		goto done;
+	}
+
+	/* loop over the new list matching up with old */
+	for (nep = new, oep = old; nep; nep = nep->ex_next) {
+		int rv;
+
+		/* anything from old before this new entry must be removed */
+		while (oep) {
+			if ((rv = strcmp(oep->ex_fsdir, nep->ex_fsdir)) >= 0)
+				break;
+			syslog(LOG_INFO, "compare: remove %s", oep->ex_fsdir);
+			oep->ex_flag |= EX_MUSTRM;
+			oep = oep->ex_next;
+			changed++;
+		}
+
+		/* else found matching entries: check dir and host lists */
+		if (oep && rv == 0) {
+			if (memcmp(&oep->ex_fs, &nep->ex_fs, sizeof(fsid_t))) {
+				warnx("compare: fsids do not match!");
+				goto bigfail;
+			}
+			if (!same_exportlist(oep, nep) ||
+			    compare_dirlist(oep->ex_defdir, nep->ex_defdir) ||
+			    compare_dirlist(oep->ex_dirl, nep->ex_dirl)) {
+				/* different, must change */
+				syslog(LOG_INFO, "compare: changing %s",
+				       oep->ex_fsdir);
+				oep->ex_flag |= EX_MUSTRM;
+				nep->ex_flag |= EX_MUSTADD;
+				changed++;
+			}
+			oep = oep->ex_next;
+			continue;
+		}
+
+		/* else old list is done or new entry not on old list, add it */
+		syslog(LOG_INFO, "compare: add %s", nep->ex_fsdir);
+		nep->ex_flag |= EX_MUSTADD;
+		changed++;
+		continue;
+	}
+
+	/* if there are old list entries left, they must be removed */
+	while (oep) {
+		syslog(LOG_INFO, "compare: remove %s", oep->ex_fsdir);
+		oep->ex_flag |= EX_MUSTRM;
+		oep = oep->ex_next;
+		changed++;
+	}
+
+ done:
+	TS_GET(ce);
+	TS_DIFF(tscompare, ce, tscompare);
+	return changed;
+
+ bigfail:
+	for (oep = old; oep; oep = oep->ex_next)
+		oep->ex_flag |= EX_MUSTRM;
+	for (nep = new; nep; nep = nep->ex_next)
+		nep->ex_flag |= EX_MUSTADD;
+	TS_GET(ce);
+	TS_DIFF(tscompare, ce, tscompare);
+	return -1;
+}
+#endif
+
+/*
+ * Get the export list from all specified files
+ */
+void
+get_exportlist(int incremental)
+{
+	struct exportlist *ep, *ep2;
+	struct grouplist *grp, *tgrp;
+	int i;
+	int done;
+	struct nfsex_args eargs;
+#ifdef SPLIT_MOUNT
+	struct exportlist *Oexphead = NULL;
+	struct grouplist *Ogrphead = NULL;
898
+	FILE *tsfd;
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
+
+	if (incremental) {
+		if (debug)
+			fprintf(stderr, "Doing incremental update, head=%p\n",
+				exphead);
+		Oexphead = exphead;
+		Ogrphead = grphead;
+	}
+#else
+	if (incremental) {
+		fprintf(stderr,
+			"Do not support incremental updates, ignored\n");
+		incremental = 0;
+	}
+#endif
+
+	TS_GET(tsexport);
+	if (!incremental && suspend_nfsd != 0) {
+		TS_GET(suspend);
+		(void)nfssvc(NFSSVC_SUSPENDNFSD, NULL);
919
 	}
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
+	v4root_dirpath[0] = '\0';
+
+	/*
+	 * First, get rid of the old list
+	 */
+	if (!incremental) {
+		ep = exphead;
+		while (ep) {
+			ep2 = ep;
+			ep = ep->ex_next;
+			free_exp(ep2);
+		}
+		grp = grphead;
+		while (grp) {
+			tgrp = grp;
+			grp = grp->gr_next;
+			free_grp(tgrp);
+		}
+	}
+	exphead = (struct exportlist *)NULL;
+	grphead = (struct grouplist *)NULL;
+
+	/*
+	 * and the old V4 root dir.
+	 */
+	bzero(&eargs, sizeof (eargs));
+	eargs.export.ex_flags = MNT_DELEXPORT;
+	if (run_v4server > 0 &&
+	    nfssvc(NFSSVC_V4ROOTEXPORT, (caddr_t)&eargs) < 0 &&
+	    errno != ENOENT)
+		syslog(LOG_ERR, "Can't delete exports for V4:");
+
+	/*
+	 * and clear flag that notes if a public fh has been exported.
+	 */
+	has_publicfh = 0;
+
+	if (!incremental)
+		clear_exports(NULL);
 
 	/*
 	 * Read in the exports file and build the list, calling
962
@@ -1780,7 +2347,7 @@
963 964 965 966 967 968 969 970
 			syslog(LOG_WARNING, "can't open %s", exnames[i]);
 			continue;
 		}
-		get_exportlist_one();
+		get_exportlist_one(incremental ? 0 : 1);
 		fclose(exp_file);
 		done++;
 	}
971
@@ -1789,6 +2356,28 @@
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
 		exit(2);
 	}
 
+#ifdef SPLIT_MOUNT
+	if (incremental) {
+		if (compare_exportlist(Oexphead, exphead) == 0) {
+			syslog(LOG_INFO, "compare: exports unchanged");
+			TS_GET(suspend);
+		} else {
+			if (suspend_nfsd != 0) {
+				TS_GET(suspend);
+				(void)nfssvc(NFSSVC_SUSPENDNFSD, NULL);
+			}
+
+			/* clear exports indicated in the old list */
+			if (Oexphead)
+				clear_exports(Oexphead);
+
+			/* export from the new list */
+			if (exphead && load_exports())
+				warnx("WARNING: not all exports done");
+		}
+	}
+#endif
+
 	/*
 	 * If there was no public fh, clear any previous one set.
 	 */
1000
@@ -1797,6 +2386,87 @@
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
 
 	/* Resume the nfsd. If they weren't suspended, this is harmless. */
 	(void)nfssvc(NFSSVC_RESUMENFSD, NULL);
+	TS_GET(tse);
+	TS_DIFF(suspend, tse, suspend);
+	TS_DIFF(tsexport, tse, tsexport);
+
+#ifdef SPLIT_MOUNT
+	/* whack the old lists */
+	if (incremental && Oexphead) {
+		ep = Oexphead;
+		while (ep) {
+			ep2 = ep;
+			ep = ep->ex_next;
+			free_exp(ep2);
+		}
+		grp = Ogrphead;
+		while (grp) {
+			tgrp = grp;
+			grp = grp->gr_next;
+			free_grp(tgrp);
+		}
+	}
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
+
+	/*
+	 * Update a timestamp file so that anyone signalling us can tell
+	 * when we have finished our work.
+	 */
+	unlink(tsfile);
+	tsfd = fopen(tsfile, "w");
+	if (tsfd != NULL) {
+		fprintf(tsfd, "%lu\n", (unsigned long)time(NULL));
+		fclose(tsfd);
+	}
1035 1036 1037 1038 1039 1040 1041 1042
+#endif
+
+#ifdef MOUNTD_STATS
+	syslog(LOG_INFO, "=== %s export: %ld.%06ld seconds",
+	       incremental ? "incremental" : "full",
+	       tsexport.tv_sec, tsexport.tv_usec);
+	syslog(LOG_INFO, "  %ld.%06ld seconds parsing %d lines",
+	       parse.tv_sec, parse.tv_usec, plines);
1043 1044
+	syslog(LOG_INFO, "    %ld.%06ld seconds parsing %d option strings",
+	       doopt.tv_sec, doopt.tv_usec, docalls);
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
+	syslog(LOG_INFO, "    %ld.%06ld seconds parsing %d host entries",
+	       phost.tv_sec, phost.tv_usec, phcalls);
+	syslog(LOG_INFO,
+	       "    %ld.%06ld seconds searching export list (%d calls)",
+	       lsearch.tv_sec, lsearch.tv_usec, lscalls);
+	syslog(LOG_INFO,
+	       "    %ld.%06ld seconds inserting in export list (%d calls)",
+	       linsert.tv_sec, linsert.tv_usec, licalls);
+	syslog(LOG_INFO,
+	       "    %ld.%06ld seconds hanging hosts on dirs (%d calls)",
+	       hangdir.tv_sec, hangdir.tv_usec, hdcalls);
+	syslog(LOG_INFO, "  %ld.%06ld seconds comparing",
+	       tscompare.tv_sec, tscompare.tv_usec);
+	syslog(LOG_INFO, "  %ld.%06ld seconds with nfsd suspended",
+	       suspend.tv_sec, suspend.tv_usec);
+	syslog(LOG_INFO, "    %ld.%06ld seconds in %d export remove calls",
+	       tsremove.tv_sec, tsremove.tv_usec, rcalls);
+	syslog(LOG_INFO, "    %ld.%06ld seconds in %d export insert calls",
+	       tsinsert.tv_sec, tsinsert.tv_usec, icalls);
+
+	TS_ZERO(tsexport);
+	TS_ZERO(parse);
+	TSC_ZERO(plines);
+	TS_ZERO(phost);
+	TSC_ZERO(phcalls);
+	TS_ZERO(lsearch);
+	TSC_ZERO(lscalls);
+	TS_ZERO(linsert);
+	TSC_ZERO(licalls);
+	TS_ZERO(hangdir);
+	TSC_ZERO(hdcalls);
1076 1077
+	TS_ZERO(doopt);
+	TSC_ZERO(docalls);
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
+	TS_ZERO(tscompare);
+	TS_ZERO(suspend);
+	TS_ZERO(tsremove);
+	TSC_ZERO(rcalls);
+	TS_ZERO(tsinsert);
+	TSC_ZERO(icalls);
+#endif
 }
 
 /*
1088
@@ -1872,6 +2542,8 @@
1089 1090 1091 1092 1093 1094 1095 1096
 {
 	struct dirlist *dp;
 
+	if (debug)
+		warnx("adding directory '%s' to %p", cp, dpp);
 	dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
 	if (dp == (struct dirlist *)NULL)
 		out_of_mem();
1097
@@ -2294,7 +2966,7 @@
1098 1099 1100 1101 1102 1103 1104 1105
 			ai->ai_flags |= AI_CANONNAME;
 		}
 		if (debug)
-			fprintf(stderr, "got host %s\n", ai->ai_canonname);
+			warnx("got host %s", ai->ai_canonname);
 		/*
 		 * Sanity check: make sure we don't already have an entry
 		 * for this host in the grouplist.
1106
@@ -2385,7 +3057,8 @@
1107 1108 1109 1110 1111 1112 1113 1114 1115
  */
 int
 do_mount(struct exportlist *ep, struct grouplist *grp, int exflags,
-    struct xucred *anoncrp, char *dirp, int dirplen, struct statfs *fsb)
+    struct xucred *anoncrp, char *dirp, int dirplen, struct statfs *fsb,
+    int doexport)
 {
 	struct statfs fsb1;
 	struct addrinfo *ai;
1116
@@ -2399,6 +3072,8 @@
1117 1118 1119 1120 1121 1122 1123 1124
 	int ret;
 	struct nfsex_args nfsea;
 
+	if (doexport)
+		TS_GET(tss);
 	if (run_v4server > 0)
 		eap = &nfsea.export;
 	else
1125
@@ -2504,7 +3179,34 @@
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
 			iov[5].iov_len = strlen(fsb->f_mntfromname) + 1;
 			errmsg[0] = '\0';
 	
-			while (nmount(iov, iovlen, fsb->f_flags) < 0) {
+#ifdef SPLIT_MOUNT
+			if (0) {
+				fprintf(stderr, "fspath='%s',", fsb->f_mntonname);
+				fprintf(stderr, "fsfrom='%s',", fsb->f_mntfromname);
+				fprintf(stderr, "fstype='%s',", fsb->f_fstypename);
+				fprintf(stderr, "addr=%08x,", eap->ex_addr ?
+					((struct sockaddr_in *)eap->ex_addr)->sin_addr.s_addr : 0);
+				fprintf(stderr, "flags=%x,", eap->ex_flags);
+				fprintf(stderr, "indexfile=%p,", eap->ex_indexfile);
+				fprintf(stderr, "numsec=%d,", eap->ex_numsecflavors);
+				fprintf(stderr, "sec[0]=%x,", eap->ex_secflavors[0]);
+				fprintf(stderr, "cred=%u/%d/%u/%d\n",
+					eap->ex_anon.cr_version,
+					(int)eap->ex_anon.cr_uid,
+					eap->ex_anon.cr_ngroups,
+					(int)eap->ex_anon.cr_groups[0]);
+			}
+#endif
+			if (!doexport)
+				goto skip;
+
+			while (1) {
+				int rv;
+
+				rv = nmount(iov, iovlen, fsb->f_flags);
+				if (rv >= 0)
+					break;
+
 				if (cp)
 					*cp-- = savedc;
 				else
1161
@@ -2610,6 +3312,12 @@
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
 		/* free iov, allocated by realloc() */
 		free(iov);
 	}
+	if (doexport) {
+		TS_GET(tse);
+		TS_DIFF(tss, tse, tse);
+		TS_SUM(tsinsert, tse, tsinsert);
+		TSC_INC(icalls);
+	}
 	return (ret);
 }
 
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
@@ -2824,6 +3532,15 @@
 	struct group *gr;
 	gid_t groups[XU_NGROUPS + 1];
 	int ngroups;
+#ifdef CACHE_ROOT_CRED
+	/*
+	 * Cache credential for -maproot=root, which is common and
+	 * typically does not change. This really matters when you have
+	 * thousands of export lines with -maproot=root. Otherwise you
+	 * burn up half your time stat()ing /etc/nsswitch.conf.
+	 */
+	static struct xucred rootcred;
+#endif
 
 	cr->cr_version = XUCRED_VERSION;
 	/*
@@ -2849,17 +3566,44 @@
 			syslog(LOG_ERR, "unknown user: %s", name);
 			return;
 		}
+#ifdef CACHE_ROOT_CRED
+		if (pw->pw_uid == 0 && rootcred.cr_ngroups > 0) {
+			*cr = rootcred;
+			return;
+		}
+#endif
+
 		cr->cr_uid = pw->pw_uid;
 		ngroups = XU_NGROUPS + 1;
 		if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups))
 			syslog(LOG_ERR, "too many groups");
 		/*
 		 * Compress out duplicate.
+		 * XXX there no longer is any duplication, so be careful.
 		 */
-		cr->cr_ngroups = ngroups - 1;
-		cr->cr_groups[0] = groups[0];
-		for (cnt = 2; cnt < ngroups; cnt++)
-			cr->cr_groups[cnt - 1] = groups[cnt];
+		if (ngroups > 1 && groups[0] == groups[1]) {
+			cr->cr_ngroups = ngroups - 1;
+			cr->cr_groups[0] = groups[0];
+			for (cnt = 2; cnt < ngroups; cnt++)
+				cr->cr_groups[cnt - 1] = groups[cnt];
+		} else {
+			cr->cr_ngroups = ngroups;
+			for (cnt = 0; cnt < ngroups; cnt++)
+				cr->cr_groups[cnt] = groups[cnt];
+		}
+#ifdef CACHE_ROOT_CRED
+		if (cr->cr_uid == 0) {
+			rootcred = *cr;
+			if (debug) {
+				fprintf(stderr, "caching root credentials: %d",
+					rootcred.cr_uid);
+				for (cnt = 0; cnt < rootcred.cr_ngroups; cnt++)
+					fprintf(stderr, "/%d",
+						rootcred.cr_groups[cnt]);
+				fprintf(stderr, "\n");
+			}
+		}
+#endif
 		return;
 	}
 	/*
@@ -3067,6 +3811,7 @@
1240 1241 1242 1243 1244 1245 1246
 
 /*
  * Check an absolute directory path for any symbolic links. Return true
+ * if complete path reflects a directory with no symlinks.
  */
 int
 check_dirpath(char *dirp)
1247
@@ -3085,7 +3830,7 @@
1248 1249 1250 1251 1252 1253 1254 1255
 		}
 		cp++;
 	}
-	if (lstat(dirp, &sb) < 0 || !S_ISDIR(sb.st_mode))
+	if (ret && (lstat(dirp, &sb) < 0 || !S_ISDIR(sb.st_mode)))
 		ret = 0;
 	return (ret);
 }
1256
@@ -3209,9 +3954,14 @@
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
 }
 
 void
-huphandler(int sig __unused)
+huphandler(int sig)
 {
-	got_sighup = 1;
+#ifdef SPLIT_MOUNT
+	if (sig == SIGUSR1)
+		got_sigusr1 = 1;
+	else
+#endif
+		got_sighup = 1;
 }
 
 void terminate(int sig __unused)
1273
@@ -3221,4 +3971,3 @@
1274 1275 1276 1277
 	rpcb_unset(MOUNTPROG, MOUNTVERS3, NULL);
 	exit (0);
 }
-