nfsd.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/* LINTLIBRARY */
/* PROTOLIB1 */
#pragma ident "%Z%%M% %I% %E% SMI"
/* NFS server */
#include <syslog.h>
#include <tiuser.h>
#include <errno.h>
#include <thread.h>
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <netconfig.h>
#include <netdir.h>
#include <string.h>
#include <unistd.h>
#include <stropts.h>
#include <poll.h>
#include <priv_utils.h>
#include <deflt.h>
#include <rpcsvc/daemon_utils.h>
#include <rpcsvc/nfs4_prot.h>
#include "nfs_tbind.h"
#include "thrpool.h"
/* quiesce requests will be ignored if nfs_server_vers_max < QUIESCE_VERSMIN */
#define QUIESCE_VERSMIN 4
static int nfssvcpool(int maxservers);
static void usage(void);
extern int _nfssys(int, void *);
/* signal handlers */
static void sigflush(int);
static void quiesce(int);
static char *MyName;
/* static NETSELDECL(defaultprotos)[] = { NC_UDP, NC_TCP, NULL }; */
/*
* The following are all globals used by routines in nfs_tbind.c.
*/
int num_servers; /* used by cots_listen_event() */
/* used by cots_listen_event() */
/*
* Start with the defaults (min == 2, max == 3). We have the
* capability of starting vers=4 but only if the user requests it.
*/
/*
* Set the default for server delegation enablement and set per
*/
{
char *dir = "/";
int allflag = 0;
int df_allflag = 0;
int opt_cnt = 0;
int maxservers_set = 0;
int logmaxservers = 0;
int pid;
int i;
char *df_provider = (char *)NULL;
char *defval;
/*
* Initializations that require more privileges than we need to run.
*/
svcsetprio();
" sufficient privileges\n", av[0]);
exit(1);
}
/*
* Read in the values from config file first before we check
* commandline options so the options override the file.
*/
errno = 0;
if (errno != 0) {
max_conns_allowed = -1;
}
}
errno = 0;
if (errno != 0) {
listen_backlog = 32;
}
}
opt_cnt++;
df_allflag = 1;
}
}
opt_cnt++;
}
errno = 0;
if (errno != 0) {
maxservers = 1;
} else {
maxservers_set = 1;
}
}
errno = 0;
if (errno != 0) {
}
}
errno = 0;
if (errno != 0) {
}
}
}
}
/* close defaults file */
}
/*
* Conflict options error messages.
*/
if (opt_cnt > 1) {
"the following options can be specified\n"
"\tNFSD_PROTOCOL=ALL\n"
"\tNFSD_PROTOCOL=protocol\n"
"\tNFSD_DEVICE=device\n\n");
usage();
}
opt_cnt = 0;
switch (i) {
case 'a':
df_provider = NULL;
allflag = 1;
opt_cnt++;
break;
case 'c':
break;
case 'p':
df_allflag = 0;
opt_cnt++;
break;
case 't':
df_allflag = 0;
opt_cnt++;
break;
case 'l':
break;
case '?':
usage();
/* NOTREACHED */
}
}
/*
* Conflict options error messages.
*/
if (opt_cnt > 1) {
"the following options can be specified\n"
"on the command line:\n"
"\t-a\n"
"\t-p protocol\n"
"\t-t transport\n\n");
usage();
}
if (nfs_server_vers_max == NFS_V4) {
if (nfs_server_vers_min == NFS_V4) {
"NFS version 4 is not supported "
"with the UDP protocol. Exiting\n");
"NFS version 4 is not supported "
"with the UDP protocol. Exiting\n");
exit(3);
} else {
"NFS version 4 is not supported "
"with the UDP protocol.\n");
}
}
}
/*
* If there is exactly one more argument, it is the number of
* servers.
*/
maxservers_set = 1;
}
/*
* If there are two or more arguments, then this is a usage error.
*/
usage();
/*
*/
else if ((nfs_server_vers_min > nfs_server_vers_max) ||
(nfs_server_vers_min < NFS_VERSMIN) ||
usage();
/*
* There are no additional arguments, and we haven't set maxservers
* explicitly via the config file, we use a default number of
* servers. We will log this.
*/
else if (maxservers_set == 0)
logmaxservers = 1;
/*
* Basic Sanity checks on options
*
* max_conns_allowed must be positive, except for the special
* value of -1 which is used internally to mean unlimited, -1 isn't
* documented but we allow it anyway.
*
* maxservers must be positive
* listen_backlog must be positive or zero
*/
(listen_backlog < 0) || (maxservers <= 0)) {
usage();
}
/*
* Set current dir to server root
*/
exit(1);
}
#ifndef DEBUG
/*
* Background
*/
if (pid < 0) {
perror("nfsd: fork");
exit(1);
}
if (pid != 0)
exit(0);
/*
* standard input, output, and error, and detach from
* controlling terminal.
*/
closefrom(0);
(void) dup(1);
(void) setsid();
#endif
/*
* establish our lock on the lock file and write our pid to it.
* exit if some other process holds the lock, or if there's any
*/
switch (pid) {
case 0:
break;
case -1:
exit(2);
default:
/* daemon was already running */
exit(0);
}
if (logmaxservers) {
"Number of servers not specified. Using default of %d.",
}
/*
* Make sure to unregister any previous versions in case the
* user is reconfiguring the server in interesting ways.
*/
/*
* Set up kernel RPC thread pool for the NFS server.
*/
if (nfssvcpool(maxservers)) {
"Can't set up kernel NFS service: %m. Exiting");
exit(1);
}
/*
* Set up blocked thread to do LWP creation on behalf of the kernel.
*/
if (svcwait(NFS_SVCPOOL_ID)) {
"Can't set up NFS pool creator: %m, Exiting");
exit(1);
}
/*
* RDMA start and stop thread.
* Per pool RDMA listener creation and
* destructor thread.
*
* start rdma services and block in the kernel.
*/
"Can't set up RDMA creator thread : %m.");
}
/*
* Build a protocol block list for registration.
*/
/* XXX - this needs work to get the version just right */
if (allflag) {
exit(1);
} else if (proto) {
/* there's more than one match for the same protocol */
goto done;
}
protoFound = TRUE;
}
}
(void) endnetconfig(nc);
if (protoFound == FALSE)
for protocol %s", proto);
} else if (provider)
else {
for (providerp = defaultproviders;
}
}
done:
if (num_fds == 0) {
"Could not start NFS service for any protocol. Exiting.");
exit(1);
}
/*
* Get rid of unneeded privileges.
*/
/*
* Poll for non-data control events on the transport descriptors.
*/
/*
* If we get here, something failed in poll_for_action().
*/
return (1);
}
static int
nfssvcpool(int maxservers)
{
struct svcpool_args npa;
npa.max_same_xprt = 0;
}
/*
* Establish NFS service thread.
*/
static int
{
struct nfs_svc_args nsa;
/*
* If no version left, silently do nothing, previous
* checks will have assured at least TCP is available.
*/
return (0);
} else {
}
}
static void
usage(void)
{
"usage: %s [ -a ] [ -c max_conns ] [ -p protocol ] [ -t transport ] ", MyName);
"\twhere -a causes <nservers> to be started on each appropriate transport,\n");
"\tmax_conns is the maximum number of concurrent connections allowed,\n");
"\ttransport is a transport provider name (i.e. device),\n");
"\tlisten_backlog is the TCP listen backlog,\n");
"\tand <nservers> must be a decimal number > zero.\n");
exit(1);
}
/*
* Issue nfssys system call to flush all logging buffers asynchronously.
*
* NOTICE: It is extremely important to flush NFS logging buffers when
* nfsd exits. When the system is halted or rebooted nfslogd
* may not have an opportunity to flush the buffers.
*/
static void
{
struct nfsl_flush_args nfa;
}
/*
* SIGTERM handler.
* Flush logging buffers and exit.
*/
static void
{
nfsl_flush();
exit(0);
}
/*
* SIGUSR1 handler.
* Request server quiesce, then exit. For subsequent warm start.
* Equivalent to SIGTERM handler if nfs_server_vers_max < QUIESCE_VERSMIN.
*/
static void
{
int error;
int id = NFS_SVCPOOL_ID;
if (nfs_server_vers_max >= QUIESCE_VERSMIN) {
/* Request server quiesce at next shutdown */
if (error) {
"_nfssys(NFS_SVC_REQUEST_QUIESCE) failed: %s\n",
return;
}
}
/* Flush logging buffers */
nfsl_flush();
exit(0);
}