xref: /onnv-gate/usr/src/uts/common/avs/ns/rdc/rdcsrv.c (revision 9093:cd587b0bd19c)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM /*
22*9093SRamana.Srikanth@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237836SJohn.Forte@Sun.COM  * Use is subject to license terms.
247836SJohn.Forte@Sun.COM  */
257836SJohn.Forte@Sun.COM 
267836SJohn.Forte@Sun.COM #include <sys/types.h>
277836SJohn.Forte@Sun.COM #include <sys/ksynch.h>
287836SJohn.Forte@Sun.COM #include <sys/cmn_err.h>
297836SJohn.Forte@Sun.COM #include <sys/kmem.h>
307836SJohn.Forte@Sun.COM #include <sys/stat.h>
317836SJohn.Forte@Sun.COM #include <sys/file.h>
327836SJohn.Forte@Sun.COM #include <sys/cred.h>
337836SJohn.Forte@Sun.COM #include <sys/conf.h>
347836SJohn.Forte@Sun.COM #include <sys/modctl.h>
357836SJohn.Forte@Sun.COM #include <sys/errno.h>
367836SJohn.Forte@Sun.COM 
377836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s.h>
387836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s_k.h>
397836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_errors.h>
407836SJohn.Forte@Sun.COM 
417836SJohn.Forte@Sun.COM #ifdef _SunOS_2_6
427836SJohn.Forte@Sun.COM /*
437836SJohn.Forte@Sun.COM  * on 2.6 both dki_lock.h and rpc/types.h define bool_t so we
447836SJohn.Forte@Sun.COM  * define enum_t here as it is all we need from rpc/types.h
457836SJohn.Forte@Sun.COM  * anyway and make it look like we included it. Yuck.
467836SJohn.Forte@Sun.COM  */
477836SJohn.Forte@Sun.COM #define	_RPC_TYPES_H
487836SJohn.Forte@Sun.COM typedef int enum_t;
497836SJohn.Forte@Sun.COM #else
507836SJohn.Forte@Sun.COM #ifndef DS_DDICT
517836SJohn.Forte@Sun.COM #include <rpc/types.h>
527836SJohn.Forte@Sun.COM #endif
537836SJohn.Forte@Sun.COM #endif /* _SunOS_2_6 */
547836SJohn.Forte@Sun.COM 
557836SJohn.Forte@Sun.COM #ifndef DS_DDICT
567836SJohn.Forte@Sun.COM #include <rpc/auth.h>
577836SJohn.Forte@Sun.COM #include <rpc/svc.h>
587836SJohn.Forte@Sun.COM #include <rpc/xdr.h>
597836SJohn.Forte@Sun.COM #else
607836SJohn.Forte@Sun.COM #include "../contract.h"
617836SJohn.Forte@Sun.COM #endif
627836SJohn.Forte@Sun.COM 
637836SJohn.Forte@Sun.COM #include <sys/ddi.h>
647836SJohn.Forte@Sun.COM 
657836SJohn.Forte@Sun.COM #include <sys/nsc_thread.h>
667836SJohn.Forte@Sun.COM #include <sys/nsctl/nsctl.h>
677836SJohn.Forte@Sun.COM 
687836SJohn.Forte@Sun.COM #include <sys/nsctl/nsvers.h>
697836SJohn.Forte@Sun.COM 
707836SJohn.Forte@Sun.COM #include "rdc_io.h"
717836SJohn.Forte@Sun.COM #include "rdc_stub.h"
727836SJohn.Forte@Sun.COM #include "rdc_ioctl.h"
737836SJohn.Forte@Sun.COM #include "rdcsrv.h"
747836SJohn.Forte@Sun.COM 
757836SJohn.Forte@Sun.COM #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
767836SJohn.Forte@Sun.COM static void rdcsrv_xprtclose(const SVCXPRT *xprt);
777836SJohn.Forte@Sun.COM #else	/* SunOS 5.8 or later */
787836SJohn.Forte@Sun.COM /*
797836SJohn.Forte@Sun.COM  * SunOS 5.8 or later.
807836SJohn.Forte@Sun.COM  *
817836SJohn.Forte@Sun.COM  * RDC callout table
827836SJohn.Forte@Sun.COM  *
837836SJohn.Forte@Sun.COM  * This table is used by svc_getreq to dispatch a request with a given
847836SJohn.Forte@Sun.COM  * prog/vers pair to an approriate service provider.
857836SJohn.Forte@Sun.COM  */
867836SJohn.Forte@Sun.COM 
877836SJohn.Forte@Sun.COM static SVC_CALLOUT rdcsrv_sc[] = {
887836SJohn.Forte@Sun.COM 	{ RDC_PROGRAM, RDC_VERS_MIN, RDC_VERS_MAX, rdcstub_dispatch }
897836SJohn.Forte@Sun.COM };
907836SJohn.Forte@Sun.COM 
917836SJohn.Forte@Sun.COM static SVC_CALLOUT_TABLE rdcsrv_sct = {
927836SJohn.Forte@Sun.COM 	sizeof (rdcsrv_sc) / sizeof (rdcsrv_sc[0]), FALSE, rdcsrv_sc
937836SJohn.Forte@Sun.COM };
947836SJohn.Forte@Sun.COM #endif	/* SunOS 5.8 or later */
957836SJohn.Forte@Sun.COM 
967836SJohn.Forte@Sun.COM static kmutex_t rdcsrv_lock;
977836SJohn.Forte@Sun.COM 
987836SJohn.Forte@Sun.COM static int rdcsrv_dup_error;
997836SJohn.Forte@Sun.COM static int rdcsrv_registered;
1007836SJohn.Forte@Sun.COM static int rdcsrv_closing;
1017836SJohn.Forte@Sun.COM static int rdcsrv_refcnt;
1027836SJohn.Forte@Sun.COM long rdc_svc_count = 0;
1037836SJohn.Forte@Sun.COM static rdcsrv_t *rdcsrv_disptab;
1047836SJohn.Forte@Sun.COM 
1057836SJohn.Forte@Sun.COM /*
1067836SJohn.Forte@Sun.COM  * Solaris module setup.
1077836SJohn.Forte@Sun.COM  */
1087836SJohn.Forte@Sun.COM 
1097836SJohn.Forte@Sun.COM extern struct mod_ops mod_miscops;
1107836SJohn.Forte@Sun.COM 
1117836SJohn.Forte@Sun.COM static struct modlmisc modlmisc = {
1127836SJohn.Forte@Sun.COM 	&mod_miscops,   /* Type of module */
1137836SJohn.Forte@Sun.COM 	"nws:Remote Mirror kRPC:" ISS_VERSION_STR
1147836SJohn.Forte@Sun.COM };
1157836SJohn.Forte@Sun.COM 
1167836SJohn.Forte@Sun.COM static struct modlinkage modlinkage = {
1177836SJohn.Forte@Sun.COM 	MODREV_1,
1187836SJohn.Forte@Sun.COM 	&modlmisc,
1197836SJohn.Forte@Sun.COM 	NULL
1207836SJohn.Forte@Sun.COM };
1217836SJohn.Forte@Sun.COM 
1227836SJohn.Forte@Sun.COM 
1237836SJohn.Forte@Sun.COM int
_init(void)1247836SJohn.Forte@Sun.COM _init(void)
1257836SJohn.Forte@Sun.COM {
1267836SJohn.Forte@Sun.COM 	int rc;
1277836SJohn.Forte@Sun.COM 
1287836SJohn.Forte@Sun.COM 	mutex_init(&rdcsrv_lock, NULL, MUTEX_DRIVER, NULL);
1297836SJohn.Forte@Sun.COM 
1307836SJohn.Forte@Sun.COM 	if ((rc = mod_install(&modlinkage)) != DDI_SUCCESS)
1317836SJohn.Forte@Sun.COM 		mutex_destroy(&rdcsrv_lock);
1327836SJohn.Forte@Sun.COM 
1337836SJohn.Forte@Sun.COM 	return (rc);
1347836SJohn.Forte@Sun.COM }
1357836SJohn.Forte@Sun.COM 
1367836SJohn.Forte@Sun.COM 
1377836SJohn.Forte@Sun.COM int
_fini(void)1387836SJohn.Forte@Sun.COM _fini(void)
1397836SJohn.Forte@Sun.COM {
1407836SJohn.Forte@Sun.COM 	int rc;
1417836SJohn.Forte@Sun.COM 
1427836SJohn.Forte@Sun.COM 	if ((rc = mod_remove(&modlinkage)) == DDI_SUCCESS)
1437836SJohn.Forte@Sun.COM 		mutex_destroy(&rdcsrv_lock);
1447836SJohn.Forte@Sun.COM 
1457836SJohn.Forte@Sun.COM 	return (rc);
1467836SJohn.Forte@Sun.COM }
1477836SJohn.Forte@Sun.COM 
1487836SJohn.Forte@Sun.COM 
1497836SJohn.Forte@Sun.COM int
_info(struct modinfo * modinfop)1507836SJohn.Forte@Sun.COM _info(struct modinfo *modinfop)
1517836SJohn.Forte@Sun.COM {
1527836SJohn.Forte@Sun.COM 	return (mod_info(&modlinkage, modinfop));
1537836SJohn.Forte@Sun.COM }
1547836SJohn.Forte@Sun.COM 
1557836SJohn.Forte@Sun.COM 
1567836SJohn.Forte@Sun.COM /*
1577836SJohn.Forte@Sun.COM  * RDC kRPC server stub.
1587836SJohn.Forte@Sun.COM  */
1597836SJohn.Forte@Sun.COM 
1607836SJohn.Forte@Sun.COM void
rdcsrv_noproc(void)1617836SJohn.Forte@Sun.COM rdcsrv_noproc(void)
1627836SJohn.Forte@Sun.COM {
1637836SJohn.Forte@Sun.COM 	;
1647836SJohn.Forte@Sun.COM }
1657836SJohn.Forte@Sun.COM 
1667836SJohn.Forte@Sun.COM 
1677836SJohn.Forte@Sun.COM static int
rdcsrv_dispdup(struct svc_req * req,SVCXPRT * xprt)1687836SJohn.Forte@Sun.COM rdcsrv_dispdup(struct svc_req *req, SVCXPRT *xprt)
1697836SJohn.Forte@Sun.COM {
1707836SJohn.Forte@Sun.COM 	rdc_disptab_t *disp;
1717836SJohn.Forte@Sun.COM 	struct dupreq *dr;
1727836SJohn.Forte@Sun.COM 	rdcsrv_t *srvp;
1737836SJohn.Forte@Sun.COM 	void (*fn)();
1747836SJohn.Forte@Sun.COM 	int dupstat;
1757836SJohn.Forte@Sun.COM 
1767836SJohn.Forte@Sun.COM 	srvp = &rdcsrv_disptab[req->rq_vers - RDC_VERS_MIN];
1777836SJohn.Forte@Sun.COM 	disp = &srvp->disptab[req->rq_proc];
1787836SJohn.Forte@Sun.COM 	fn = disp->dispfn;
1797836SJohn.Forte@Sun.COM 
1807836SJohn.Forte@Sun.COM 	dupstat = SVC_DUP(xprt, req, 0, 0, &dr);
1817836SJohn.Forte@Sun.COM 
1827836SJohn.Forte@Sun.COM 	switch (dupstat) {
1837836SJohn.Forte@Sun.COM 	case DUP_ERROR:
1847836SJohn.Forte@Sun.COM 		/* svcerr_systemerr does a freeargs */
1857836SJohn.Forte@Sun.COM 		svcerr_systemerr(xprt);
1867836SJohn.Forte@Sun.COM 		rdcsrv_dup_error++;
1877836SJohn.Forte@Sun.COM 		break;
1887836SJohn.Forte@Sun.COM 
1897836SJohn.Forte@Sun.COM 	case DUP_INPROGRESS:
1907836SJohn.Forte@Sun.COM 		rdcsrv_dup_error++;
1917836SJohn.Forte@Sun.COM 		break;
1927836SJohn.Forte@Sun.COM 
1937836SJohn.Forte@Sun.COM 	case DUP_NEW:
1947836SJohn.Forte@Sun.COM 	case DUP_DROP:
1957836SJohn.Forte@Sun.COM 		(*fn)(xprt, req);
1967836SJohn.Forte@Sun.COM 		SVC_DUPDONE(xprt, dr, 0, 0, DUP_DONE);
1977836SJohn.Forte@Sun.COM 		break;
1987836SJohn.Forte@Sun.COM 
1997836SJohn.Forte@Sun.COM 	case DUP_DONE:
2007836SJohn.Forte@Sun.COM 		break;
2017836SJohn.Forte@Sun.COM 	}
2027836SJohn.Forte@Sun.COM 
2037836SJohn.Forte@Sun.COM 	return (dupstat);
2047836SJohn.Forte@Sun.COM }
2057836SJohn.Forte@Sun.COM 
2067836SJohn.Forte@Sun.COM 
2077836SJohn.Forte@Sun.COM /*
2087836SJohn.Forte@Sun.COM  * rdcsrv_dispatch is the dispatcher routine for the RDC RPC protocol
2097836SJohn.Forte@Sun.COM  */
2107836SJohn.Forte@Sun.COM void
rdcsrv_dispatch(struct svc_req * req,SVCXPRT * xprt)2117836SJohn.Forte@Sun.COM rdcsrv_dispatch(struct svc_req *req, SVCXPRT *xprt)
2127836SJohn.Forte@Sun.COM {
2137836SJohn.Forte@Sun.COM 	rdc_disptab_t *disp;
2147836SJohn.Forte@Sun.COM 	rdcsrv_t *srvp;
2157836SJohn.Forte@Sun.COM 
2167836SJohn.Forte@Sun.COM 	mutex_enter(&rdcsrv_lock);
2177836SJohn.Forte@Sun.COM 	rdcsrv_refcnt++;
2187836SJohn.Forte@Sun.COM 
2197836SJohn.Forte@Sun.COM 	if (!rdcsrv_registered || rdcsrv_closing || !rdcsrv_disptab) {
2207836SJohn.Forte@Sun.COM 		mutex_exit(&rdcsrv_lock);
2217836SJohn.Forte@Sun.COM 		goto outdisp;
2227836SJohn.Forte@Sun.COM 	}
2237836SJohn.Forte@Sun.COM 
2247836SJohn.Forte@Sun.COM 	mutex_exit(&rdcsrv_lock);
2257836SJohn.Forte@Sun.COM 
2267836SJohn.Forte@Sun.COM 	if ((req->rq_vers < RDC_VERS_MIN) || (req->rq_vers > RDC_VERS_MAX)) {
2277836SJohn.Forte@Sun.COM 		svcerr_noproc(xprt);
228*9093SRamana.Srikanth@Sun.COM 		cmn_err(CE_NOTE, "!rdcsrv_dispatch: unknown version %d",
229*9093SRamana.Srikanth@Sun.COM 		    req->rq_vers);
2307836SJohn.Forte@Sun.COM 		/* svcerr_noproc does a freeargs on xprt */
2317836SJohn.Forte@Sun.COM 		goto done;
2327836SJohn.Forte@Sun.COM 	}
2337836SJohn.Forte@Sun.COM 
2347836SJohn.Forte@Sun.COM 	srvp = &rdcsrv_disptab[req->rq_vers - RDC_VERS_MIN];
2357836SJohn.Forte@Sun.COM 	disp = &srvp->disptab[req->rq_proc];
2367836SJohn.Forte@Sun.COM 
2377836SJohn.Forte@Sun.COM 	if (req->rq_proc >= srvp->nprocs ||
2387836SJohn.Forte@Sun.COM 	    disp->dispfn == rdcsrv_noproc) {
2397836SJohn.Forte@Sun.COM 		svcerr_noproc(xprt);
240*9093SRamana.Srikanth@Sun.COM 		cmn_err(CE_NOTE, "!rdcsrv_dispatch: bad proc number %d",
241*9093SRamana.Srikanth@Sun.COM 		    req->rq_proc);
2427836SJohn.Forte@Sun.COM 		/* svcerr_noproc does a freeargs on xprt */
2437836SJohn.Forte@Sun.COM 		goto done;
2447836SJohn.Forte@Sun.COM 	} else if (disp->clone) {
2457836SJohn.Forte@Sun.COM 		switch (rdcsrv_dispdup(req, xprt)) {
2467836SJohn.Forte@Sun.COM 		case DUP_ERROR:
2477836SJohn.Forte@Sun.COM 			goto done;
2487836SJohn.Forte@Sun.COM 			/* NOTREACHED */
2497836SJohn.Forte@Sun.COM 		case DUP_INPROGRESS:
2507836SJohn.Forte@Sun.COM 			goto outdisp;
2517836SJohn.Forte@Sun.COM 			/* NOTREACHED */
2527836SJohn.Forte@Sun.COM 		default:
2537836SJohn.Forte@Sun.COM 			break;
2547836SJohn.Forte@Sun.COM 		}
2557836SJohn.Forte@Sun.COM 	} else {
2567836SJohn.Forte@Sun.COM 		(*disp->dispfn)(xprt, req);
2577836SJohn.Forte@Sun.COM 		rdc_svc_count++;
2587836SJohn.Forte@Sun.COM 	}
2597836SJohn.Forte@Sun.COM 
2607836SJohn.Forte@Sun.COM outdisp:
2617836SJohn.Forte@Sun.COM 	if (!SVC_FREEARGS(xprt, (xdrproc_t)0, (caddr_t)0))
262*9093SRamana.Srikanth@Sun.COM 		cmn_err(CE_NOTE, "!rdcsrv_dispatch: bad freeargs");
2637836SJohn.Forte@Sun.COM done:
2647836SJohn.Forte@Sun.COM 	mutex_enter(&rdcsrv_lock);
2657836SJohn.Forte@Sun.COM 	rdcsrv_refcnt--;
2667836SJohn.Forte@Sun.COM 	mutex_exit(&rdcsrv_lock);
2677836SJohn.Forte@Sun.COM }
2687836SJohn.Forte@Sun.COM 
2697836SJohn.Forte@Sun.COM 
2707836SJohn.Forte@Sun.COM static int
rdcsrv_create(file_t * fp,rdc_svc_args_t * args,int mode)2717836SJohn.Forte@Sun.COM rdcsrv_create(file_t *fp, rdc_svc_args_t *args, int mode)
2727836SJohn.Forte@Sun.COM {
2737836SJohn.Forte@Sun.COM 	/*LINTED*/
2747836SJohn.Forte@Sun.COM 	int rc, error = 0;
2757836SJohn.Forte@Sun.COM 	/*LINTED*/
2767836SJohn.Forte@Sun.COM 	rpcvers_t vers;
2777836SJohn.Forte@Sun.COM 	struct netbuf addrmask;
2787836SJohn.Forte@Sun.COM 
2797836SJohn.Forte@Sun.COM #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
2807836SJohn.Forte@Sun.COM 	SVCXPRT *xprt;
2817836SJohn.Forte@Sun.COM #else
2827836SJohn.Forte@Sun.COM 	SVCMASTERXPRT *xprt;
2837836SJohn.Forte@Sun.COM #endif
2847836SJohn.Forte@Sun.COM 	STRUCT_HANDLE(rdc_svc_args, uap);
2857836SJohn.Forte@Sun.COM 
2867836SJohn.Forte@Sun.COM 	STRUCT_SET_HANDLE(uap, mode, args);
2877836SJohn.Forte@Sun.COM 
2887836SJohn.Forte@Sun.COM 	addrmask.len = STRUCT_FGET(uap, addrmask.len);
2897836SJohn.Forte@Sun.COM 	addrmask.maxlen = STRUCT_FGET(uap, addrmask.maxlen);
2907836SJohn.Forte@Sun.COM 	addrmask.buf = kmem_alloc(addrmask.maxlen, KM_SLEEP);
2917836SJohn.Forte@Sun.COM 	error = ddi_copyin(STRUCT_FGETP(uap, addrmask.buf), addrmask.buf,
292*9093SRamana.Srikanth@Sun.COM 	    addrmask.len, mode);
2937836SJohn.Forte@Sun.COM 	if (error) {
2947836SJohn.Forte@Sun.COM 		kmem_free(addrmask.buf, addrmask.maxlen);
2957836SJohn.Forte@Sun.COM #ifdef DEBUG
296*9093SRamana.Srikanth@Sun.COM 		cmn_err(CE_WARN, "!addrmask copyin failed %p", (void *) args);
2977836SJohn.Forte@Sun.COM #endif
2987836SJohn.Forte@Sun.COM 		return (error);
2997836SJohn.Forte@Sun.COM 	}
3007836SJohn.Forte@Sun.COM 
3017836SJohn.Forte@Sun.COM 	/*
3027836SJohn.Forte@Sun.COM 	 * Set rdcstub's dispatch handle to rdcsrv_dispatch
3037836SJohn.Forte@Sun.COM 	 */
3047836SJohn.Forte@Sun.COM 	rdcstub_set_dispatch(rdcsrv_dispatch);
3057836SJohn.Forte@Sun.COM 
3067836SJohn.Forte@Sun.COM 	/*
3077836SJohn.Forte@Sun.COM 	 * Create a transport endpoint and create one kernel thread to run the
3087836SJohn.Forte@Sun.COM 	 * rdc service loop
3097836SJohn.Forte@Sun.COM 	 */
3107836SJohn.Forte@Sun.COM #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
3117836SJohn.Forte@Sun.COM 	error = svc_tli_kcreate(fp, RDC_RPC_MAX,
312*9093SRamana.Srikanth@Sun.COM 	    STRUCT_FGETP(uap, netid), &addrmask, STRUCT_FGET(uap, nthr), &xprt);
3137836SJohn.Forte@Sun.COM #else
3147836SJohn.Forte@Sun.COM 	{
3157836SJohn.Forte@Sun.COM #if defined(_SunOS_5_8)
3167836SJohn.Forte@Sun.COM 		struct svcpool_args p;
3177836SJohn.Forte@Sun.COM 		p.id = RDC_SVCPOOL_ID;
3187836SJohn.Forte@Sun.COM 		p.maxthreads = STRUCT_FGET(uap, nthr);
3197836SJohn.Forte@Sun.COM 		p.redline = 0;
3207836SJohn.Forte@Sun.COM 		p.qsize =  0;
3217836SJohn.Forte@Sun.COM 		p.timeout = 0;
3227836SJohn.Forte@Sun.COM 		p.stksize = 0;
3237836SJohn.Forte@Sun.COM 		p.max_same_xprt = 0;
3247836SJohn.Forte@Sun.COM 
3257836SJohn.Forte@Sun.COM 		error = svc_pool_create(&p);
3267836SJohn.Forte@Sun.COM 		if (error) {
3277836SJohn.Forte@Sun.COM 			cmn_err(CE_NOTE,
328*9093SRamana.Srikanth@Sun.COM 			    "!rdcsrv_create: svc_pool_create failed %d", error);
3297836SJohn.Forte@Sun.COM 			return (error);
3307836SJohn.Forte@Sun.COM 		}
3317836SJohn.Forte@Sun.COM #endif
3327836SJohn.Forte@Sun.COM 		error = svc_tli_kcreate(fp, RDC_RPC_MAX,
333*9093SRamana.Srikanth@Sun.COM 		    STRUCT_FGETP(uap, netid), &addrmask,
334*9093SRamana.Srikanth@Sun.COM 		    &xprt, &rdcsrv_sct, NULL, RDC_SVCPOOL_ID, FALSE);
3357836SJohn.Forte@Sun.COM 	}
3367836SJohn.Forte@Sun.COM #endif
3377836SJohn.Forte@Sun.COM 
3387836SJohn.Forte@Sun.COM 	if (error) {
339*9093SRamana.Srikanth@Sun.COM 		cmn_err(CE_NOTE, "!rdcsrv_create: svc_tli_kcreate failed %d",
340*9093SRamana.Srikanth@Sun.COM 		    error);
3417836SJohn.Forte@Sun.COM 		return (error);
3427836SJohn.Forte@Sun.COM 	}
3437836SJohn.Forte@Sun.COM 
3447836SJohn.Forte@Sun.COM #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
3457836SJohn.Forte@Sun.COM 	if (xprt == NULL) {
346*9093SRamana.Srikanth@Sun.COM 		cmn_err(CE_NOTE, "!xprt in rdcsrv_create is NULL");
3477836SJohn.Forte@Sun.COM 	} else {
3487836SJohn.Forte@Sun.COM 		/*
3497836SJohn.Forte@Sun.COM 		 * Register a cleanup routine in case the transport gets
3507836SJohn.Forte@Sun.COM 		 * destroyed.  If the registration fails for some reason,
3517836SJohn.Forte@Sun.COM 		 * it means that the transport is already being destroyed.
3527836SJohn.Forte@Sun.COM 		 * This shouldn't happen, but it's probably not worth a
3537836SJohn.Forte@Sun.COM 		 * panic.
3547836SJohn.Forte@Sun.COM 		 */
3557836SJohn.Forte@Sun.COM 		if (!svc_control(xprt, SVCSET_CLOSEPROC,
356*9093SRamana.Srikanth@Sun.COM 		    (void *)rdcsrv_xprtclose)) {
3577836SJohn.Forte@Sun.COM 			cmn_err(
3587836SJohn.Forte@Sun.COM #ifdef DEBUG
359*9093SRamana.Srikanth@Sun.COM 			    CE_PANIC,
3607836SJohn.Forte@Sun.COM #else
361*9093SRamana.Srikanth@Sun.COM 			    CE_WARN,
3627836SJohn.Forte@Sun.COM #endif
363*9093SRamana.Srikanth@Sun.COM 			    "!rdcsrv_create: couldn't set xprt callback");
3647836SJohn.Forte@Sun.COM 
3657836SJohn.Forte@Sun.COM 			error = EBADF;
3667836SJohn.Forte@Sun.COM 			goto done;
3677836SJohn.Forte@Sun.COM 		}
3687836SJohn.Forte@Sun.COM 	}
3697836SJohn.Forte@Sun.COM 
3707836SJohn.Forte@Sun.COM 	for (vers = RDC_VERS_MIN; vers <= RDC_VERS_MAX; vers++) {
3717836SJohn.Forte@Sun.COM 		rc = svc_register(xprt, (ulong_t)RDC_PROGRAM, vers,
372*9093SRamana.Srikanth@Sun.COM 		    rdcstub_dispatch, 0);
3737836SJohn.Forte@Sun.COM 		if (!rc) {
3747836SJohn.Forte@Sun.COM 			cmn_err(CE_NOTE,
375*9093SRamana.Srikanth@Sun.COM 			    "!rdcsrv_create: svc_register(%d, %lu) failed",
376*9093SRamana.Srikanth@Sun.COM 			    RDC_PROGRAM, vers);
3777836SJohn.Forte@Sun.COM 
3787836SJohn.Forte@Sun.COM 			if (!error) {
3797836SJohn.Forte@Sun.COM 				error = EBADF;
3807836SJohn.Forte@Sun.COM 			}
3817836SJohn.Forte@Sun.COM 		}
3827836SJohn.Forte@Sun.COM 	}
3837836SJohn.Forte@Sun.COM #endif /* 5.6 or 5.7 */
3847836SJohn.Forte@Sun.COM 
3857836SJohn.Forte@Sun.COM 	if (!error) {
3867836SJohn.Forte@Sun.COM 		/* mark as registered with the kRPC subsystem */
3877836SJohn.Forte@Sun.COM 		rdcsrv_registered = 1;
3887836SJohn.Forte@Sun.COM 	}
3897836SJohn.Forte@Sun.COM 
3907836SJohn.Forte@Sun.COM done:
3917836SJohn.Forte@Sun.COM 	return (error);
3927836SJohn.Forte@Sun.COM }
3937836SJohn.Forte@Sun.COM 
3947836SJohn.Forte@Sun.COM 
3957836SJohn.Forte@Sun.COM #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
3967836SJohn.Forte@Sun.COM /*
3977836SJohn.Forte@Sun.COM  * Callback routine for when a transport is closed.
3987836SJohn.Forte@Sun.COM  */
3997836SJohn.Forte@Sun.COM static void
rdcsrv_xprtclose(const SVCXPRT * xprt)4007836SJohn.Forte@Sun.COM rdcsrv_xprtclose(const SVCXPRT *xprt)
4017836SJohn.Forte@Sun.COM {
4027836SJohn.Forte@Sun.COM }
4037836SJohn.Forte@Sun.COM #endif
4047836SJohn.Forte@Sun.COM 
4057836SJohn.Forte@Sun.COM 
4067836SJohn.Forte@Sun.COM /*
4077836SJohn.Forte@Sun.COM  * Private interface from the main RDC module.
4087836SJohn.Forte@Sun.COM  */
4097836SJohn.Forte@Sun.COM 
4107836SJohn.Forte@Sun.COM int
rdcsrv_load(file_t * fp,rdcsrv_t * disptab,rdc_svc_args_t * args,int mode)4117836SJohn.Forte@Sun.COM rdcsrv_load(file_t *fp, rdcsrv_t *disptab,  rdc_svc_args_t *args, int mode)
4127836SJohn.Forte@Sun.COM {
4137836SJohn.Forte@Sun.COM 	int rc = 0;
4147836SJohn.Forte@Sun.COM 
4157836SJohn.Forte@Sun.COM 	mutex_enter(&rdcsrv_lock);
4167836SJohn.Forte@Sun.COM 
4177836SJohn.Forte@Sun.COM 	rc = rdcsrv_create(fp, args, mode);
4187836SJohn.Forte@Sun.COM 	if (rc == 0) {
4197836SJohn.Forte@Sun.COM 		rdcsrv_disptab = disptab;
4207836SJohn.Forte@Sun.COM 	}
4217836SJohn.Forte@Sun.COM 
4227836SJohn.Forte@Sun.COM 	mutex_exit(&rdcsrv_lock);
4237836SJohn.Forte@Sun.COM 	return (rc);
4247836SJohn.Forte@Sun.COM }
4257836SJohn.Forte@Sun.COM 
4267836SJohn.Forte@Sun.COM 
4277836SJohn.Forte@Sun.COM void
rdcsrv_unload(void)4287836SJohn.Forte@Sun.COM rdcsrv_unload(void)
4297836SJohn.Forte@Sun.COM {
4307836SJohn.Forte@Sun.COM 	mutex_enter(&rdcsrv_lock);
4317836SJohn.Forte@Sun.COM 
4327836SJohn.Forte@Sun.COM 	/* Unset rdcstub's dispatch handle */
4337836SJohn.Forte@Sun.COM 	rdcstub_unset_dispatch();
4347836SJohn.Forte@Sun.COM 
4357836SJohn.Forte@Sun.COM 	rdcsrv_closing = 1;
4367836SJohn.Forte@Sun.COM 
4377836SJohn.Forte@Sun.COM 	while (rdcsrv_refcnt > 0) {
4387836SJohn.Forte@Sun.COM 		mutex_exit(&rdcsrv_lock);
4397836SJohn.Forte@Sun.COM 		delay(drv_usectohz(25));
4407836SJohn.Forte@Sun.COM 		mutex_enter(&rdcsrv_lock);
4417836SJohn.Forte@Sun.COM 	}
4427836SJohn.Forte@Sun.COM 
4437836SJohn.Forte@Sun.COM 	rdcsrv_closing = 0;
4447836SJohn.Forte@Sun.COM 	rdcsrv_disptab = 0;
4457836SJohn.Forte@Sun.COM 
4467836SJohn.Forte@Sun.COM 	mutex_exit(&rdcsrv_lock);
4477836SJohn.Forte@Sun.COM }
448