diff options
author | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
commit | 97d8b9495668afa398ab17c8c5f7e223b5fd2e89 (patch) | |
tree | 54038c9ac32a45f8741dcc23fb9a8ffc0e15ff89 /usr.sbin/nfsd | |
parent | 5ee3bfdb338e7c80af29a67f4425c4be24c7b866 (diff) | |
parent | 086d73aef6d0ab7d21daa2076fdc8d25961f9b05 (diff) | |
download | FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.zip FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.tar.gz |
sync from head
Diffstat (limited to 'usr.sbin/nfsd')
-rw-r--r-- | usr.sbin/nfsd/nfsd.c | 123 |
1 files changed, 55 insertions, 68 deletions
diff --git a/usr.sbin/nfsd/nfsd.c b/usr.sbin/nfsd/nfsd.c index 0e39138..b114ba6 100644 --- a/usr.sbin/nfsd/nfsd.c +++ b/usr.sbin/nfsd/nfsd.c @@ -105,20 +105,21 @@ static struct option longopts[] = { { NULL, 0, NULL, 0} }; -void cleanup(int); -void child_cleanup(int); -void killchildren(void); -void nfsd_exit(int); -void nonfs(int); -void reapchild(int); -int setbindhost(struct addrinfo **ia, const char *bindhost, - struct addrinfo hints); -void start_server(int); -void unregistration(void); -void usage(void); -void open_stable(int *, int *); -void copy_stable(int, int); -void backup_stable(int); +static void cleanup(int); +static void child_cleanup(int); +static void killchildren(void); +static void nfsd_exit(int); +static void nonfs(int); +static void reapchild(int); +static int setbindhost(struct addrinfo **ia, const char *bindhost, + struct addrinfo hints); +static void start_server(int); +static void unregistration(void); +static void usage(void); +static void open_stable(int *, int *); +static void copy_stable(int, int); +static void backup_stable(int); +static void set_nfsdcnt(int); /* * Nfs server daemon mostly just a user context for nfssvc() @@ -178,8 +179,7 @@ main(int argc, char **argv) bindanyflag = 1; break; case 'n': - nfsdcnt_set = 1; - nfsdcnt = atoi(optarg); + set_nfsdcnt(atoi(optarg)); break; case 'h': bindhostc++; @@ -235,15 +235,8 @@ main(int argc, char **argv) */ if (argc > 1) usage(); - if (argc == 1) { - nfsdcnt_set = 1; - nfsdcnt = atoi(argv[0]); - if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) { - warnx("nfsd count %d; reset to %d", nfsdcnt, - DEFNFSDCNT); - nfsdcnt = DEFNFSDCNT; - } - } + if (argc == 1) + set_nfsdcnt(atoi(argv[0])); /* * Unless the "-o" option was specified, try and run "nfsd". @@ -429,16 +422,6 @@ main(int argc, char **argv) } if (!new_syscall) { - if (nfsdcnt < 1) { - warnx("nfsd count too low %d; reset to %d", nfsdcnt, - DEFNFSDCNT); - nfsdcnt = DEFNFSDCNT; - } - if (nfsdcnt > MAXNFSDCNT) { - warnx("nfsd count too high %d; reset to %d", nfsdcnt, - DEFNFSDCNT); - nfsdcnt = MAXNFSDCNT; - } /* If we use UDP only, we start the last server below. */ srvcnt = tcpflag ? nfsdcnt : nfsdcnt - 1; for (i = 0; i < srvcnt; i++) { @@ -844,7 +827,7 @@ main(int argc, char **argv) } } -int +static int setbindhost(struct addrinfo **ai, const char *bindhost, struct addrinfo hints) { int ecode; @@ -890,20 +873,37 @@ setbindhost(struct addrinfo **ai, const char *bindhost, struct addrinfo hints) return (0); } -void +static void +set_nfsdcnt(int proposed) +{ + + if (proposed < 1) { + warnx("nfsd count too low %d; reset to %d", proposed, + DEFNFSDCNT); + nfsdcnt = DEFNFSDCNT; + } else if (proposed > MAXNFSDCNT) { + warnx("nfsd count too high %d; truncated to %d", proposed, + MAXNFSDCNT); + nfsdcnt = MAXNFSDCNT; + } else + nfsdcnt = proposed; + nfsdcnt_set = 1; +} + +static void usage(void) { (void)fprintf(stderr, "%s", getopt_usage); exit(1); } -void +static void nonfs(__unused int signo) { syslog(LOG_ERR, "missing system call: NFS not available"); } -void +static void reapchild(__unused int signo) { pid_t pid; @@ -916,7 +916,7 @@ reapchild(__unused int signo) } } -void +static void unregistration(void) { if ((!rpcb_unset(NFS_PROGRAM, 2, NULL)) || @@ -924,7 +924,7 @@ unregistration(void) syslog(LOG_ERR, "rpcb_unset failed"); } -void +static void killchildren(void) { int i; @@ -938,7 +938,7 @@ killchildren(void) /* * Cleanup master after SIGUSR1. */ -void +static void cleanup(__unused int signo) { nfsd_exit(0); @@ -947,13 +947,13 @@ cleanup(__unused int signo) /* * Cleanup child after SIGUSR1. */ -void +static void child_cleanup(__unused int signo) { exit(0); } -void +static void nfsd_exit(int status) { killchildren(); @@ -984,7 +984,7 @@ get_tuned_nfsdcount(void) return tuned_nfsdcnt; } -void +static void start_server(int master) { char principal[MAXHOSTNAMELEN + 5]; @@ -1014,26 +1014,13 @@ start_server(int master) } nfsdargs.principal = principal; - if (minthreads_set) { - nfsdargs.minthreads = minthreads; - if (!maxthreads_set) - nfsdargs.maxthreads = minthreads; - } - if (maxthreads_set) { - nfsdargs.maxthreads = maxthreads; - if (!minthreads_set) - nfsdargs.minthreads = maxthreads; - } - if (nfsdcnt_set) { - nfsdargs.minthreads = nfsdcnt; - nfsdargs.maxthreads = nfsdcnt; - } - if (!minthreads_set && !maxthreads_set && !nfsdcnt_set) { - int tuned_nfsdcnt; - - tuned_nfsdcnt = get_tuned_nfsdcount(); - nfsdargs.minthreads = tuned_nfsdcnt; - nfsdargs.maxthreads = tuned_nfsdcnt; + if (nfsdcnt_set) + nfsdargs.minthreads = nfsdargs.maxthreads = nfsdcnt; + else { + nfsdargs.minthreads = minthreads_set ? minthreads : get_tuned_nfsdcount(); + nfsdargs.maxthreads = maxthreads_set ? maxthreads : nfsdargs.minthreads; + if (nfsdargs.maxthreads < nfsdargs.minthreads) + nfsdargs.maxthreads = nfsdargs.minthreads; } error = nfssvc(nfssvc_nfsd, &nfsdargs); if (error < 0 && errno == EAUTH) { @@ -1066,7 +1053,7 @@ start_server(int master) /* * Open the stable restart file and return the file descriptor for it. */ -void +static void open_stable(int *stable_fdp, int *backup_fdp) { int stable_fd, backup_fd = -1, ret; @@ -1118,7 +1105,7 @@ open_stable(int *stable_fdp, int *backup_fdp) /* * Copy the stable restart file to the backup or vice versa. */ -void +static void copy_stable(int from_fd, int to_fd) { int cnt, ret; @@ -1146,7 +1133,7 @@ copy_stable(int from_fd, int to_fd) /* * Back up the stable restart file when indicated by the kernel. */ -void +static void backup_stable(__unused int signo) { |