Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/nfsd/nfsd.c
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | |||||
static void cleanup(int); | static void cleanup(int); | ||||
static void child_cleanup(int); | static void child_cleanup(int); | ||||
static void killchildren(void); | static void killchildren(void); | ||||
static void nfsd_exit(int); | static void nfsd_exit(int); | ||||
static void nonfs(int); | static void nonfs(int); | ||||
static void reapchild(int); | static void reapchild(int); | ||||
static int setbindhost(struct addrinfo **ia, const char *bindhost, | static int setbindhost(struct addrinfo **ia, const char *bindhost, | ||||
struct addrinfo hints); | struct addrinfo hints); | ||||
static void start_server(int, struct nfsd_nfsd_args *); | static void start_server(int, struct nfsd_nfsd_args *, const char *vhost); | ||||
static void unregistration(void); | static void unregistration(void); | ||||
static void usage(void); | static void usage(void); | ||||
static void open_stable(int *, int *); | static void open_stable(int *, int *); | ||||
static void copy_stable(int, int); | static void copy_stable(int, int); | ||||
static void backup_stable(int); | static void backup_stable(int); | ||||
static void set_nfsdcnt(int); | static void set_nfsdcnt(int); | ||||
static void parse_dsserver(const char *, struct nfsd_nfsd_args *); | static void parse_dsserver(const char *, struct nfsd_nfsd_args *); | ||||
Show All 37 Lines | main(int argc, char **argv) | ||||
int nfssvc_addsock; | int nfssvc_addsock; | ||||
int longindex = 0; | int longindex = 0; | ||||
int nfs_minvers = NFS_VER2; | int nfs_minvers = NFS_VER2; | ||||
size_t nfs_minvers_size; | size_t nfs_minvers_size; | ||||
const char *lopt; | const char *lopt; | ||||
char **bindhost = NULL; | char **bindhost = NULL; | ||||
pid_t pid; | pid_t pid; | ||||
struct nfsd_nfsd_args nfsdargs; | struct nfsd_nfsd_args nfsdargs; | ||||
const char *vhostname = NULL; | |||||
nfsdargs.mirrorcnt = 1; | nfsdargs.mirrorcnt = 1; | ||||
nfsdargs.addr = NULL; | nfsdargs.addr = NULL; | ||||
nfsdargs.addrlen = 0; | nfsdargs.addrlen = 0; | ||||
nfsdcnt = DEFNFSDCNT; | nfsdcnt = DEFNFSDCNT; | ||||
unregister = reregister = tcpflag = maxsock = 0; | unregister = reregister = tcpflag = maxsock = 0; | ||||
bindanyflag = udpflag = connect_type_cnt = bindhostc = 0; | bindanyflag = udpflag = connect_type_cnt = bindhostc = 0; | ||||
getopt_shortopts = "ah:n:rdtuep:m:"; | getopt_shortopts = "ah:n:rdtuep:m:V:"; | ||||
getopt_usage = | getopt_usage = | ||||
"usage:\n" | "usage:\n" | ||||
" nfsd [-ardtue] [-h bindip]\n" | " nfsd [-ardtue] [-h bindip]\n" | ||||
" [-n numservers] [--minthreads #] [--maxthreads #]\n" | " [-n numservers] [--minthreads #] [--maxthreads #]\n" | ||||
" [-p/--pnfs dsserver0:/dsserver0-mounted-on-dir,...," | " [-p/--pnfs dsserver0:/dsserver0-mounted-on-dir,...,\n" | ||||
" [-V virtual_hostname]\n" | |||||
"dsserverN:/dsserverN-mounted-on-dir] [-m mirrorlevel]\n"; | " dsserverN:/dsserverN-mounted-on-dir] [-m mirrorlevel]\n"; | ||||
while ((ch = getopt_long(argc, argv, getopt_shortopts, longopts, | while ((ch = getopt_long(argc, argv, getopt_shortopts, longopts, | ||||
&longindex)) != -1) | &longindex)) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case 'V': | |||||
vhostname = optarg; | |||||
break; | |||||
case 'a': | case 'a': | ||||
bindanyflag = 1; | bindanyflag = 1; | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
set_nfsdcnt(atoi(optarg)); | set_nfsdcnt(atoi(optarg)); | ||||
break; | break; | ||||
case 'h': | case 'h': | ||||
bindhostc++; | bindhostc++; | ||||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | if (pid == -1) { | ||||
syslog(LOG_ERR, "fork: %m"); | syslog(LOG_ERR, "fork: %m"); | ||||
nfsd_exit(1); | nfsd_exit(1); | ||||
} | } | ||||
if (pid) { | if (pid) { | ||||
children[0] = pid; | children[0] = pid; | ||||
} else { | } else { | ||||
(void)signal(SIGUSR1, child_cleanup); | (void)signal(SIGUSR1, child_cleanup); | ||||
setproctitle("server"); | setproctitle("server"); | ||||
start_server(0, &nfsdargs); | start_server(0, &nfsdargs, vhostname); | ||||
} | } | ||||
} | } | ||||
(void)signal(SIGUSR1, cleanup); | (void)signal(SIGUSR1, cleanup); | ||||
FD_ZERO(&sockbits); | FD_ZERO(&sockbits); | ||||
rpcbregcnt = 0; | rpcbregcnt = 0; | ||||
/* Set up the socket for udp and rpcb register it. */ | /* Set up the socket for udp and rpcb register it. */ | ||||
▲ Show 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | main(int argc, char **argv) | ||||
/* | /* | ||||
* We always want a master to have a clean way to shut nfsd down | * We always want a master to have a clean way to shut nfsd down | ||||
* (with unregistration): if the master is killed, it unregisters and | * (with unregistration): if the master is killed, it unregisters and | ||||
* kills all children. If we run for UDP only (and so do not have to | * kills all children. If we run for UDP only (and so do not have to | ||||
* loop waiting for accept), we instead make the parent | * loop waiting for accept), we instead make the parent | ||||
* a "server" too. start_server will not return. | * a "server" too. start_server will not return. | ||||
*/ | */ | ||||
if (!tcpflag) | if (!tcpflag) | ||||
start_server(1, &nfsdargs); | start_server(1, &nfsdargs, vhostname); | ||||
/* | /* | ||||
* Loop forever accepting connections and passing the sockets | * Loop forever accepting connections and passing the sockets | ||||
* into the kernel for the mounts. | * into the kernel for the mounts. | ||||
*/ | */ | ||||
for (;;) { | for (;;) { | ||||
ready = sockbits; | ready = sockbits; | ||||
if (connect_type_cnt > 1) { | if (connect_type_cnt > 1) { | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | if (error) { | ||||
tuned_nfsdcnt = DEFNFSDCNT; | tuned_nfsdcnt = DEFNFSDCNT; | ||||
} else { | } else { | ||||
tuned_nfsdcnt = ncpu * 8; | tuned_nfsdcnt = ncpu * 8; | ||||
} | } | ||||
return tuned_nfsdcnt; | return tuned_nfsdcnt; | ||||
} | } | ||||
static void | static void | ||||
start_server(int master, struct nfsd_nfsd_args *nfsdargp) | start_server(int master, struct nfsd_nfsd_args *nfsdargp, const char *vhost) | ||||
{ | { | ||||
char principal[MAXHOSTNAMELEN + 5]; | char principal[MAXHOSTNAMELEN + 5]; | ||||
int status, error; | int status, error; | ||||
char hostname[MAXHOSTNAMELEN + 1], *cp; | char hostname[MAXHOSTNAMELEN + 1], *cp; | ||||
struct addrinfo *aip, hints; | struct addrinfo *aip, hints; | ||||
status = 0; | status = 0; | ||||
if (vhost == NULL) | |||||
gethostname(hostname, sizeof (hostname)); | gethostname(hostname, sizeof (hostname)); | ||||
else | |||||
strlcpy(hostname, vhost, sizeof (hostname)); | |||||
snprintf(principal, sizeof (principal), "nfs@%s", hostname); | snprintf(principal, sizeof (principal), "nfs@%s", hostname); | ||||
if ((cp = strchr(hostname, '.')) == NULL || | if ((cp = strchr(hostname, '.')) == NULL || | ||||
*(cp + 1) == '\0') { | *(cp + 1) == '\0') { | ||||
/* If not fully qualified, try getaddrinfo() */ | /* If not fully qualified, try getaddrinfo() */ | ||||
memset((void *)&hints, 0, sizeof (hints)); | memset((void *)&hints, 0, sizeof (hints)); | ||||
hints.ai_flags = AI_CANONNAME; | hints.ai_flags = AI_CANONNAME; | ||||
error = getaddrinfo(hostname, NULL, &hints, &aip); | error = getaddrinfo(hostname, NULL, &hints, &aip); | ||||
if (error == 0) { | if (error == 0) { | ||||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |