lockd.c revision 42cdb25977ffa6ebef76064b66ad665992fadee5
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 (c) 2012 by Delphix. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/* 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 */
/*
* NLM server
*
* and then s:NFS:NLM: applied, etc.
*/
#include <syslog.h>
#include <tiuser.h>
#include <errno.h>
#include <thread.h>
#include <stdio.h>
#include <stdio_ext.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/nlm_prot.h>
#include <libintl.h>
#include <libscf.h>
#include <libshare.h>
#include "nfs_tbind.h"
#include "thrpool.h"
#include "smfcfg.h"
/* Option defaults. See nfssys.h */
struct lm_svc_args lmargs = {
/* fd, n_fmly, n_proto, n_rdev (below) */
.debug = 0,
.grace = 90,
.retransmittimeout = 5
};
int max_servers = 20;
#define RET_OK 0 /* return code for no error */
static int nlmsvcpool(int max_servers);
static void usage(void);
extern int _nfssys(int, void *);
static void sigterm_handler(void);
static void shutdown_lockd(void);
extern int daemonize_init(void);
extern void daemonize_fini(int fd);
static char *MyName;
/*
* We want to bind to these TLI providers, and in this order,
* because the kernel NLM needs the loopback first for its
* initialization. (It uses it to talk to statd.)
*/
static NETSELDECL(defaultproviders)[] = {
};
/*
* The following are all globals used by routines in nfs_tbind.c.
*/
/* used by cots_listen_event() */
int
{
char *dir = "/";
int pipe_fd = -1;
/*
* Initializations that require more privileges than we need to run.
*/
svcsetprio();
" sufficient privileges\n", av[0]);
exit(1);
}
/*
* Read in the values from SMF first before we check
* command line options so the options override SMF values.
*/
/* How long to wait for clients to re-establish locks. */
if (val <= 0)
"Invalid %s from SMF"), propname);
else
} else {
"value", propname);
}
if (val <= 0)
"Invalid %s from SMF"), propname);
else
} else {
"value", propname);
}
if (val <= 0)
"Invalid %s from SMF"), propname);
else
max_servers = val;
} else {
"value", propname);
}
if (val <= 0)
"Invalid %s from SMF"), propname);
else
} else {
"value", propname);
}
switch (c) {
case 'c': /* max_connections */
goto badval;
break;
case 'd': /* debug */
break;
case 'g': /* grace_period */
goto badval;
break;
case 'l': /* listen_backlog */
goto badval;
break;
case 't': /* retrans_timeout */
goto badval;
break;
"Invalid -%c option value"), c);
/* FALLTHROUGH */
default:
usage();
/* NOTREACHED */
}
/*
* If there is exactly one more argument, it is the number of
* servers.
*/
if (val <= 0) {
"Invalid max_servers argument"));
usage();
}
max_servers = val;
optind++;
}
/*
* If there are two or more arguments, then this is a usage error.
*/
usage();
printf("%s: debug= %d, conn_idle_timout= %d,"
" grace_period= %d, listen_backlog= %d,"
" max_connections= %d, max_servers= %d,"
" retrans_timeout= %d\n",
}
/*
* Set current dir to server root
*/
exit(1);
}
/* Daemonize, if not debug. */
pipe_fd = daemonize_init();
/*
* 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);
}
/*
* Block all signals till we spawn other
* threads.
*/
(void) sigfillset(&sgset);
/* Unregister any previous versions. */
}
/*
* Set up kernel RPC thread pool for the NLM server.
*/
if (nlmsvcpool(max_servers)) {
exit(1);
}
/*
* Set up blocked thread to do LWP creation on behalf of the kernel.
*/
if (svcwait(NLM_SVCPOOL_ID)) {
exit(1);
}
/*
* Install atexit and sigterm handlers
*/
(void) atexit(shutdown_lockd);
/*
* Now open up for signal delivery
*/
/*
* Build a protocol block list for registration.
*/
for (providerp = defaultproviders;
}
if (num_fds == 0) {
" Exiting");
exit(1);
}
/*
* lockd is up and running as far as we are concerned.
*/
/*
* 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
nlmsvcpool(int maxservers)
{
struct svcpool_args npa;
npa.max_same_xprt = 0;
}
static int
ncfmly_to_lmfmly(const char *ncfmly)
{
return (LM_INET);
return (LM_INET6);
return (LM_LOOPBACK);
return (-1);
}
static int
{
switch (semantics) {
case NC_TPI_CLTS:
return (LM_UDP);
case NC_TPI_COTS_ORD:
return (LM_TCP);
}
return (-1);
}
static dev_t
ncdev_to_rdev(const char *ncdev)
{
return (NODEV);
}
static void
sigterm_handler(void)
{
/* to call atexit handler */
exit(0);
}
static void
shutdown_lockd(void)
{
}
/*
* Establish NLM service thread.
*/
static int
{
struct lm_svc_args lma;
/*
* The kernel code needs to reconstruct a complete
* knetconfig from n_fmly, n_proto. We use these
* two fields to convey the family and semantics.
*/
}
static void
usage(void)
{
"usage: %s [options] [max_servers]\n"), MyName);
"options: (see SMF property descriptions)\n"));
/* Note: don't translate these */
exit(1);
}