xref: /titanic_41/usr/src/uts/common/avs/ns/rdc/rdcsrv.c (revision 3270659f55e0928d6edec3d26217cc29398a8149)
1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte /*
22*3270659fSSrikanth, Ramana  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fcf3ce44SJohn Forte  * Use is subject to license terms.
24fcf3ce44SJohn Forte  */
25fcf3ce44SJohn Forte 
26fcf3ce44SJohn Forte #include <sys/types.h>
27fcf3ce44SJohn Forte #include <sys/ksynch.h>
28fcf3ce44SJohn Forte #include <sys/cmn_err.h>
29fcf3ce44SJohn Forte #include <sys/kmem.h>
30fcf3ce44SJohn Forte #include <sys/stat.h>
31fcf3ce44SJohn Forte #include <sys/file.h>
32fcf3ce44SJohn Forte #include <sys/cred.h>
33fcf3ce44SJohn Forte #include <sys/conf.h>
34fcf3ce44SJohn Forte #include <sys/modctl.h>
35fcf3ce44SJohn Forte #include <sys/errno.h>
36fcf3ce44SJohn Forte 
37fcf3ce44SJohn Forte #include <sys/unistat/spcs_s.h>
38fcf3ce44SJohn Forte #include <sys/unistat/spcs_s_k.h>
39fcf3ce44SJohn Forte #include <sys/unistat/spcs_errors.h>
40fcf3ce44SJohn Forte 
41fcf3ce44SJohn Forte #ifdef _SunOS_2_6
42fcf3ce44SJohn Forte /*
43fcf3ce44SJohn Forte  * on 2.6 both dki_lock.h and rpc/types.h define bool_t so we
44fcf3ce44SJohn Forte  * define enum_t here as it is all we need from rpc/types.h
45fcf3ce44SJohn Forte  * anyway and make it look like we included it. Yuck.
46fcf3ce44SJohn Forte  */
47fcf3ce44SJohn Forte #define	_RPC_TYPES_H
48fcf3ce44SJohn Forte typedef int enum_t;
49fcf3ce44SJohn Forte #else
50fcf3ce44SJohn Forte #ifndef DS_DDICT
51fcf3ce44SJohn Forte #include <rpc/types.h>
52fcf3ce44SJohn Forte #endif
53fcf3ce44SJohn Forte #endif /* _SunOS_2_6 */
54fcf3ce44SJohn Forte 
55fcf3ce44SJohn Forte #ifndef DS_DDICT
56fcf3ce44SJohn Forte #include <rpc/auth.h>
57fcf3ce44SJohn Forte #include <rpc/svc.h>
58fcf3ce44SJohn Forte #include <rpc/xdr.h>
59fcf3ce44SJohn Forte #else
60fcf3ce44SJohn Forte #include "../contract.h"
61fcf3ce44SJohn Forte #endif
62fcf3ce44SJohn Forte 
63fcf3ce44SJohn Forte #include <sys/ddi.h>
64fcf3ce44SJohn Forte 
65fcf3ce44SJohn Forte #include <sys/nsc_thread.h>
66fcf3ce44SJohn Forte #include <sys/nsctl/nsctl.h>
67fcf3ce44SJohn Forte 
68fcf3ce44SJohn Forte #include <sys/nsctl/nsvers.h>
69fcf3ce44SJohn Forte 
70fcf3ce44SJohn Forte #include "rdc_io.h"
71fcf3ce44SJohn Forte #include "rdc_stub.h"
72fcf3ce44SJohn Forte #include "rdc_ioctl.h"
73fcf3ce44SJohn Forte #include "rdcsrv.h"
74fcf3ce44SJohn Forte 
75fcf3ce44SJohn Forte #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
76fcf3ce44SJohn Forte static void rdcsrv_xprtclose(const SVCXPRT *xprt);
77fcf3ce44SJohn Forte #else	/* SunOS 5.8 or later */
78fcf3ce44SJohn Forte /*
79fcf3ce44SJohn Forte  * SunOS 5.8 or later.
80fcf3ce44SJohn Forte  *
81fcf3ce44SJohn Forte  * RDC callout table
82fcf3ce44SJohn Forte  *
83fcf3ce44SJohn Forte  * This table is used by svc_getreq to dispatch a request with a given
84fcf3ce44SJohn Forte  * prog/vers pair to an approriate service provider.
85fcf3ce44SJohn Forte  */
86fcf3ce44SJohn Forte 
87fcf3ce44SJohn Forte static SVC_CALLOUT rdcsrv_sc[] = {
88fcf3ce44SJohn Forte 	{ RDC_PROGRAM, RDC_VERS_MIN, RDC_VERS_MAX, rdcstub_dispatch }
89fcf3ce44SJohn Forte };
90fcf3ce44SJohn Forte 
91fcf3ce44SJohn Forte static SVC_CALLOUT_TABLE rdcsrv_sct = {
92fcf3ce44SJohn Forte 	sizeof (rdcsrv_sc) / sizeof (rdcsrv_sc[0]), FALSE, rdcsrv_sc
93fcf3ce44SJohn Forte };
94fcf3ce44SJohn Forte #endif	/* SunOS 5.8 or later */
95fcf3ce44SJohn Forte 
96fcf3ce44SJohn Forte static kmutex_t rdcsrv_lock;
97fcf3ce44SJohn Forte 
98fcf3ce44SJohn Forte static int rdcsrv_dup_error;
99fcf3ce44SJohn Forte static int rdcsrv_registered;
100fcf3ce44SJohn Forte static int rdcsrv_closing;
101fcf3ce44SJohn Forte static int rdcsrv_refcnt;
102fcf3ce44SJohn Forte long rdc_svc_count = 0;
103fcf3ce44SJohn Forte static rdcsrv_t *rdcsrv_disptab;
104fcf3ce44SJohn Forte 
105fcf3ce44SJohn Forte /*
106fcf3ce44SJohn Forte  * Solaris module setup.
107fcf3ce44SJohn Forte  */
108fcf3ce44SJohn Forte 
109fcf3ce44SJohn Forte extern struct mod_ops mod_miscops;
110fcf3ce44SJohn Forte 
111fcf3ce44SJohn Forte static struct modlmisc modlmisc = {
112fcf3ce44SJohn Forte 	&mod_miscops,   /* Type of module */
113fcf3ce44SJohn Forte 	"nws:Remote Mirror kRPC:" ISS_VERSION_STR
114fcf3ce44SJohn Forte };
115fcf3ce44SJohn Forte 
116fcf3ce44SJohn Forte static struct modlinkage modlinkage = {
117fcf3ce44SJohn Forte 	MODREV_1,
118fcf3ce44SJohn Forte 	&modlmisc,
119fcf3ce44SJohn Forte 	NULL
120fcf3ce44SJohn Forte };
121fcf3ce44SJohn Forte 
122fcf3ce44SJohn Forte 
123fcf3ce44SJohn Forte int
_init(void)124fcf3ce44SJohn Forte _init(void)
125fcf3ce44SJohn Forte {
126fcf3ce44SJohn Forte 	int rc;
127fcf3ce44SJohn Forte 
128fcf3ce44SJohn Forte 	mutex_init(&rdcsrv_lock, NULL, MUTEX_DRIVER, NULL);
129fcf3ce44SJohn Forte 
130fcf3ce44SJohn Forte 	if ((rc = mod_install(&modlinkage)) != DDI_SUCCESS)
131fcf3ce44SJohn Forte 		mutex_destroy(&rdcsrv_lock);
132fcf3ce44SJohn Forte 
133fcf3ce44SJohn Forte 	return (rc);
134fcf3ce44SJohn Forte }
135fcf3ce44SJohn Forte 
136fcf3ce44SJohn Forte 
137fcf3ce44SJohn Forte int
_fini(void)138fcf3ce44SJohn Forte _fini(void)
139fcf3ce44SJohn Forte {
140fcf3ce44SJohn Forte 	int rc;
141fcf3ce44SJohn Forte 
142fcf3ce44SJohn Forte 	if ((rc = mod_remove(&modlinkage)) == DDI_SUCCESS)
143fcf3ce44SJohn Forte 		mutex_destroy(&rdcsrv_lock);
144fcf3ce44SJohn Forte 
145fcf3ce44SJohn Forte 	return (rc);
146fcf3ce44SJohn Forte }
147fcf3ce44SJohn Forte 
148fcf3ce44SJohn Forte 
149fcf3ce44SJohn Forte int
_info(struct modinfo * modinfop)150fcf3ce44SJohn Forte _info(struct modinfo *modinfop)
151fcf3ce44SJohn Forte {
152fcf3ce44SJohn Forte 	return (mod_info(&modlinkage, modinfop));
153fcf3ce44SJohn Forte }
154fcf3ce44SJohn Forte 
155fcf3ce44SJohn Forte 
156fcf3ce44SJohn Forte /*
157fcf3ce44SJohn Forte  * RDC kRPC server stub.
158fcf3ce44SJohn Forte  */
159fcf3ce44SJohn Forte 
160fcf3ce44SJohn Forte void
rdcsrv_noproc(void)161fcf3ce44SJohn Forte rdcsrv_noproc(void)
162fcf3ce44SJohn Forte {
163fcf3ce44SJohn Forte 	;
164fcf3ce44SJohn Forte }
165fcf3ce44SJohn Forte 
166fcf3ce44SJohn Forte 
167fcf3ce44SJohn Forte static int
rdcsrv_dispdup(struct svc_req * req,SVCXPRT * xprt)168fcf3ce44SJohn Forte rdcsrv_dispdup(struct svc_req *req, SVCXPRT *xprt)
169fcf3ce44SJohn Forte {
170fcf3ce44SJohn Forte 	rdc_disptab_t *disp;
171fcf3ce44SJohn Forte 	struct dupreq *dr;
172fcf3ce44SJohn Forte 	rdcsrv_t *srvp;
173fcf3ce44SJohn Forte 	void (*fn)();
174fcf3ce44SJohn Forte 	int dupstat;
175fcf3ce44SJohn Forte 
176fcf3ce44SJohn Forte 	srvp = &rdcsrv_disptab[req->rq_vers - RDC_VERS_MIN];
177fcf3ce44SJohn Forte 	disp = &srvp->disptab[req->rq_proc];
178fcf3ce44SJohn Forte 	fn = disp->dispfn;
179fcf3ce44SJohn Forte 
180fcf3ce44SJohn Forte 	dupstat = SVC_DUP(xprt, req, 0, 0, &dr);
181fcf3ce44SJohn Forte 
182fcf3ce44SJohn Forte 	switch (dupstat) {
183fcf3ce44SJohn Forte 	case DUP_ERROR:
184fcf3ce44SJohn Forte 		/* svcerr_systemerr does a freeargs */
185fcf3ce44SJohn Forte 		svcerr_systemerr(xprt);
186fcf3ce44SJohn Forte 		rdcsrv_dup_error++;
187fcf3ce44SJohn Forte 		break;
188fcf3ce44SJohn Forte 
189fcf3ce44SJohn Forte 	case DUP_INPROGRESS:
190fcf3ce44SJohn Forte 		rdcsrv_dup_error++;
191fcf3ce44SJohn Forte 		break;
192fcf3ce44SJohn Forte 
193fcf3ce44SJohn Forte 	case DUP_NEW:
194fcf3ce44SJohn Forte 	case DUP_DROP:
195fcf3ce44SJohn Forte 		(*fn)(xprt, req);
196fcf3ce44SJohn Forte 		SVC_DUPDONE(xprt, dr, 0, 0, DUP_DONE);
197fcf3ce44SJohn Forte 		break;
198fcf3ce44SJohn Forte 
199fcf3ce44SJohn Forte 	case DUP_DONE:
200fcf3ce44SJohn Forte 		break;
201fcf3ce44SJohn Forte 	}
202fcf3ce44SJohn Forte 
203fcf3ce44SJohn Forte 	return (dupstat);
204fcf3ce44SJohn Forte }
205fcf3ce44SJohn Forte 
206fcf3ce44SJohn Forte 
207fcf3ce44SJohn Forte /*
208fcf3ce44SJohn Forte  * rdcsrv_dispatch is the dispatcher routine for the RDC RPC protocol
209fcf3ce44SJohn Forte  */
210fcf3ce44SJohn Forte void
rdcsrv_dispatch(struct svc_req * req,SVCXPRT * xprt)211fcf3ce44SJohn Forte rdcsrv_dispatch(struct svc_req *req, SVCXPRT *xprt)
212fcf3ce44SJohn Forte {
213fcf3ce44SJohn Forte 	rdc_disptab_t *disp;
214fcf3ce44SJohn Forte 	rdcsrv_t *srvp;
215fcf3ce44SJohn Forte 
216fcf3ce44SJohn Forte 	mutex_enter(&rdcsrv_lock);
217fcf3ce44SJohn Forte 	rdcsrv_refcnt++;
218fcf3ce44SJohn Forte 
219fcf3ce44SJohn Forte 	if (!rdcsrv_registered || rdcsrv_closing || !rdcsrv_disptab) {
220fcf3ce44SJohn Forte 		mutex_exit(&rdcsrv_lock);
221fcf3ce44SJohn Forte 		goto outdisp;
222fcf3ce44SJohn Forte 	}
223fcf3ce44SJohn Forte 
224fcf3ce44SJohn Forte 	mutex_exit(&rdcsrv_lock);
225fcf3ce44SJohn Forte 
226fcf3ce44SJohn Forte 	if ((req->rq_vers < RDC_VERS_MIN) || (req->rq_vers > RDC_VERS_MAX)) {
227fcf3ce44SJohn Forte 		svcerr_noproc(xprt);
228*3270659fSSrikanth, Ramana 		cmn_err(CE_NOTE, "!rdcsrv_dispatch: unknown version %d",
229fcf3ce44SJohn Forte 		    req->rq_vers);
230fcf3ce44SJohn Forte 		/* svcerr_noproc does a freeargs on xprt */
231fcf3ce44SJohn Forte 		goto done;
232fcf3ce44SJohn Forte 	}
233fcf3ce44SJohn Forte 
234fcf3ce44SJohn Forte 	srvp = &rdcsrv_disptab[req->rq_vers - RDC_VERS_MIN];
235fcf3ce44SJohn Forte 	disp = &srvp->disptab[req->rq_proc];
236fcf3ce44SJohn Forte 
237fcf3ce44SJohn Forte 	if (req->rq_proc >= srvp->nprocs ||
238fcf3ce44SJohn Forte 	    disp->dispfn == rdcsrv_noproc) {
239fcf3ce44SJohn Forte 		svcerr_noproc(xprt);
240*3270659fSSrikanth, Ramana 		cmn_err(CE_NOTE, "!rdcsrv_dispatch: bad proc number %d",
241fcf3ce44SJohn Forte 		    req->rq_proc);
242fcf3ce44SJohn Forte 		/* svcerr_noproc does a freeargs on xprt */
243fcf3ce44SJohn Forte 		goto done;
244fcf3ce44SJohn Forte 	} else if (disp->clone) {
245fcf3ce44SJohn Forte 		switch (rdcsrv_dispdup(req, xprt)) {
246fcf3ce44SJohn Forte 		case DUP_ERROR:
247fcf3ce44SJohn Forte 			goto done;
248fcf3ce44SJohn Forte 			/* NOTREACHED */
249fcf3ce44SJohn Forte 		case DUP_INPROGRESS:
250fcf3ce44SJohn Forte 			goto outdisp;
251fcf3ce44SJohn Forte 			/* NOTREACHED */
252fcf3ce44SJohn Forte 		default:
253fcf3ce44SJohn Forte 			break;
254fcf3ce44SJohn Forte 		}
255fcf3ce44SJohn Forte 	} else {
256fcf3ce44SJohn Forte 		(*disp->dispfn)(xprt, req);
257fcf3ce44SJohn Forte 		rdc_svc_count++;
258fcf3ce44SJohn Forte 	}
259fcf3ce44SJohn Forte 
260fcf3ce44SJohn Forte outdisp:
261fcf3ce44SJohn Forte 	if (!SVC_FREEARGS(xprt, (xdrproc_t)0, (caddr_t)0))
262*3270659fSSrikanth, Ramana 		cmn_err(CE_NOTE, "!rdcsrv_dispatch: bad freeargs");
263fcf3ce44SJohn Forte done:
264fcf3ce44SJohn Forte 	mutex_enter(&rdcsrv_lock);
265fcf3ce44SJohn Forte 	rdcsrv_refcnt--;
266fcf3ce44SJohn Forte 	mutex_exit(&rdcsrv_lock);
267fcf3ce44SJohn Forte }
268fcf3ce44SJohn Forte 
269fcf3ce44SJohn Forte 
270fcf3ce44SJohn Forte static int
rdcsrv_create(file_t * fp,rdc_svc_args_t * args,int mode)271fcf3ce44SJohn Forte rdcsrv_create(file_t *fp, rdc_svc_args_t *args, int mode)
272fcf3ce44SJohn Forte {
273fcf3ce44SJohn Forte 	/*LINTED*/
274fcf3ce44SJohn Forte 	int rc, error = 0;
275fcf3ce44SJohn Forte 	/*LINTED*/
276fcf3ce44SJohn Forte 	rpcvers_t vers;
277fcf3ce44SJohn Forte 	struct netbuf addrmask;
278fcf3ce44SJohn Forte 
279fcf3ce44SJohn Forte #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
280fcf3ce44SJohn Forte 	SVCXPRT *xprt;
281fcf3ce44SJohn Forte #else
282fcf3ce44SJohn Forte 	SVCMASTERXPRT *xprt;
283fcf3ce44SJohn Forte #endif
284fcf3ce44SJohn Forte 	STRUCT_HANDLE(rdc_svc_args, uap);
285fcf3ce44SJohn Forte 
286fcf3ce44SJohn Forte 	STRUCT_SET_HANDLE(uap, mode, args);
287fcf3ce44SJohn Forte 
288fcf3ce44SJohn Forte 	addrmask.len = STRUCT_FGET(uap, addrmask.len);
289fcf3ce44SJohn Forte 	addrmask.maxlen = STRUCT_FGET(uap, addrmask.maxlen);
290fcf3ce44SJohn Forte 	addrmask.buf = kmem_alloc(addrmask.maxlen, KM_SLEEP);
291fcf3ce44SJohn Forte 	error = ddi_copyin(STRUCT_FGETP(uap, addrmask.buf), addrmask.buf,
292fcf3ce44SJohn Forte 	    addrmask.len, mode);
293fcf3ce44SJohn Forte 	if (error) {
294fcf3ce44SJohn Forte 		kmem_free(addrmask.buf, addrmask.maxlen);
295fcf3ce44SJohn Forte #ifdef DEBUG
296*3270659fSSrikanth, Ramana 		cmn_err(CE_WARN, "!addrmask copyin failed %p", (void *) args);
297fcf3ce44SJohn Forte #endif
298fcf3ce44SJohn Forte 		return (error);
299fcf3ce44SJohn Forte 	}
300fcf3ce44SJohn Forte 
301fcf3ce44SJohn Forte 	/*
302fcf3ce44SJohn Forte 	 * Set rdcstub's dispatch handle to rdcsrv_dispatch
303fcf3ce44SJohn Forte 	 */
304fcf3ce44SJohn Forte 	rdcstub_set_dispatch(rdcsrv_dispatch);
305fcf3ce44SJohn Forte 
306fcf3ce44SJohn Forte 	/*
307fcf3ce44SJohn Forte 	 * Create a transport endpoint and create one kernel thread to run the
308fcf3ce44SJohn Forte 	 * rdc service loop
309fcf3ce44SJohn Forte 	 */
310fcf3ce44SJohn Forte #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
311fcf3ce44SJohn Forte 	error = svc_tli_kcreate(fp, RDC_RPC_MAX,
312*3270659fSSrikanth, Ramana 	    STRUCT_FGETP(uap, netid), &addrmask, STRUCT_FGET(uap, nthr), &xprt);
313fcf3ce44SJohn Forte #else
314fcf3ce44SJohn Forte 	{
315fcf3ce44SJohn Forte #if defined(_SunOS_5_8)
316fcf3ce44SJohn Forte 		struct svcpool_args p;
317fcf3ce44SJohn Forte 		p.id = RDC_SVCPOOL_ID;
318fcf3ce44SJohn Forte 		p.maxthreads = STRUCT_FGET(uap, nthr);
319fcf3ce44SJohn Forte 		p.redline = 0;
320fcf3ce44SJohn Forte 		p.qsize =  0;
321fcf3ce44SJohn Forte 		p.timeout = 0;
322fcf3ce44SJohn Forte 		p.stksize = 0;
323fcf3ce44SJohn Forte 		p.max_same_xprt = 0;
324fcf3ce44SJohn Forte 
325fcf3ce44SJohn Forte 		error = svc_pool_create(&p);
326fcf3ce44SJohn Forte 		if (error) {
327fcf3ce44SJohn Forte 			cmn_err(CE_NOTE,
328*3270659fSSrikanth, Ramana 			    "!rdcsrv_create: svc_pool_create failed %d", error);
329fcf3ce44SJohn Forte 			return (error);
330fcf3ce44SJohn Forte 		}
331fcf3ce44SJohn Forte #endif
332fcf3ce44SJohn Forte 		error = svc_tli_kcreate(fp, RDC_RPC_MAX,
333fcf3ce44SJohn Forte 		    STRUCT_FGETP(uap, netid), &addrmask,
334*3270659fSSrikanth, Ramana 		    &xprt, &rdcsrv_sct, NULL, RDC_SVCPOOL_ID, FALSE);
335fcf3ce44SJohn Forte 	}
336fcf3ce44SJohn Forte #endif
337fcf3ce44SJohn Forte 
338fcf3ce44SJohn Forte 	if (error) {
339*3270659fSSrikanth, Ramana 		cmn_err(CE_NOTE, "!rdcsrv_create: svc_tli_kcreate failed %d",
340fcf3ce44SJohn Forte 		    error);
341fcf3ce44SJohn Forte 		return (error);
342fcf3ce44SJohn Forte 	}
343fcf3ce44SJohn Forte 
344fcf3ce44SJohn Forte #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
345fcf3ce44SJohn Forte 	if (xprt == NULL) {
346*3270659fSSrikanth, Ramana 		cmn_err(CE_NOTE, "!xprt in rdcsrv_create is NULL");
347fcf3ce44SJohn Forte 	} else {
348fcf3ce44SJohn Forte 		/*
349fcf3ce44SJohn Forte 		 * Register a cleanup routine in case the transport gets
350fcf3ce44SJohn Forte 		 * destroyed.  If the registration fails for some reason,
351fcf3ce44SJohn Forte 		 * it means that the transport is already being destroyed.
352fcf3ce44SJohn Forte 		 * This shouldn't happen, but it's probably not worth a
353fcf3ce44SJohn Forte 		 * panic.
354fcf3ce44SJohn Forte 		 */
355fcf3ce44SJohn Forte 		if (!svc_control(xprt, SVCSET_CLOSEPROC,
356fcf3ce44SJohn Forte 		    (void *)rdcsrv_xprtclose)) {
357fcf3ce44SJohn Forte 			cmn_err(
358fcf3ce44SJohn Forte #ifdef DEBUG
359fcf3ce44SJohn Forte 			    CE_PANIC,
360fcf3ce44SJohn Forte #else
361fcf3ce44SJohn Forte 			    CE_WARN,
362fcf3ce44SJohn Forte #endif
363*3270659fSSrikanth, Ramana 			    "!rdcsrv_create: couldn't set xprt callback");
364fcf3ce44SJohn Forte 
365fcf3ce44SJohn Forte 			error = EBADF;
366fcf3ce44SJohn Forte 			goto done;
367fcf3ce44SJohn Forte 		}
368fcf3ce44SJohn Forte 	}
369fcf3ce44SJohn Forte 
370fcf3ce44SJohn Forte 	for (vers = RDC_VERS_MIN; vers <= RDC_VERS_MAX; vers++) {
371fcf3ce44SJohn Forte 		rc = svc_register(xprt, (ulong_t)RDC_PROGRAM, vers,
372fcf3ce44SJohn Forte 		    rdcstub_dispatch, 0);
373fcf3ce44SJohn Forte 		if (!rc) {
374fcf3ce44SJohn Forte 			cmn_err(CE_NOTE,
375*3270659fSSrikanth, Ramana 			    "!rdcsrv_create: svc_register(%d, %lu) failed",
376fcf3ce44SJohn Forte 			    RDC_PROGRAM, vers);
377fcf3ce44SJohn Forte 
378fcf3ce44SJohn Forte 			if (!error) {
379fcf3ce44SJohn Forte 				error = EBADF;
380fcf3ce44SJohn Forte 			}
381fcf3ce44SJohn Forte 		}
382fcf3ce44SJohn Forte 	}
383fcf3ce44SJohn Forte #endif /* 5.6 or 5.7 */
384fcf3ce44SJohn Forte 
385fcf3ce44SJohn Forte 	if (!error) {
386fcf3ce44SJohn Forte 		/* mark as registered with the kRPC subsystem */
387fcf3ce44SJohn Forte 		rdcsrv_registered = 1;
388fcf3ce44SJohn Forte 	}
389fcf3ce44SJohn Forte 
390fcf3ce44SJohn Forte done:
391fcf3ce44SJohn Forte 	return (error);
392fcf3ce44SJohn Forte }
393fcf3ce44SJohn Forte 
394fcf3ce44SJohn Forte 
395fcf3ce44SJohn Forte #if defined(_SunOS_5_6) || defined(_SunOS_5_7)
396fcf3ce44SJohn Forte /*
397fcf3ce44SJohn Forte  * Callback routine for when a transport is closed.
398fcf3ce44SJohn Forte  */
399fcf3ce44SJohn Forte static void
rdcsrv_xprtclose(const SVCXPRT * xprt)400fcf3ce44SJohn Forte rdcsrv_xprtclose(const SVCXPRT *xprt)
401fcf3ce44SJohn Forte {
402fcf3ce44SJohn Forte }
403fcf3ce44SJohn Forte #endif
404fcf3ce44SJohn Forte 
405fcf3ce44SJohn Forte 
406fcf3ce44SJohn Forte /*
407fcf3ce44SJohn Forte  * Private interface from the main RDC module.
408fcf3ce44SJohn Forte  */
409fcf3ce44SJohn Forte 
410fcf3ce44SJohn Forte int
rdcsrv_load(file_t * fp,rdcsrv_t * disptab,rdc_svc_args_t * args,int mode)411fcf3ce44SJohn Forte rdcsrv_load(file_t *fp, rdcsrv_t *disptab,  rdc_svc_args_t *args, int mode)
412fcf3ce44SJohn Forte {
413fcf3ce44SJohn Forte 	int rc = 0;
414fcf3ce44SJohn Forte 
415fcf3ce44SJohn Forte 	mutex_enter(&rdcsrv_lock);
416fcf3ce44SJohn Forte 
417fcf3ce44SJohn Forte 	rc = rdcsrv_create(fp, args, mode);
418fcf3ce44SJohn Forte 	if (rc == 0) {
419fcf3ce44SJohn Forte 		rdcsrv_disptab = disptab;
420fcf3ce44SJohn Forte 	}
421fcf3ce44SJohn Forte 
422fcf3ce44SJohn Forte 	mutex_exit(&rdcsrv_lock);
423fcf3ce44SJohn Forte 	return (rc);
424fcf3ce44SJohn Forte }
425fcf3ce44SJohn Forte 
426fcf3ce44SJohn Forte 
427fcf3ce44SJohn Forte void
rdcsrv_unload(void)428fcf3ce44SJohn Forte rdcsrv_unload(void)
429fcf3ce44SJohn Forte {
430fcf3ce44SJohn Forte 	mutex_enter(&rdcsrv_lock);
431fcf3ce44SJohn Forte 
432fcf3ce44SJohn Forte 	/* Unset rdcstub's dispatch handle */
433fcf3ce44SJohn Forte 	rdcstub_unset_dispatch();
434fcf3ce44SJohn Forte 
435fcf3ce44SJohn Forte 	rdcsrv_closing = 1;
436fcf3ce44SJohn Forte 
437fcf3ce44SJohn Forte 	while (rdcsrv_refcnt > 0) {
438fcf3ce44SJohn Forte 		mutex_exit(&rdcsrv_lock);
439fcf3ce44SJohn Forte 		delay(drv_usectohz(25));
440fcf3ce44SJohn Forte 		mutex_enter(&rdcsrv_lock);
441fcf3ce44SJohn Forte 	}
442fcf3ce44SJohn Forte 
443fcf3ce44SJohn Forte 	rdcsrv_closing = 0;
444fcf3ce44SJohn Forte 	rdcsrv_disptab = 0;
445fcf3ce44SJohn Forte 
446fcf3ce44SJohn Forte 	mutex_exit(&rdcsrv_lock);
447fcf3ce44SJohn Forte }
448