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