Print this page
7651 default maximum nfs server threads is insufficient
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/rpc/svc_cots.c
+++ new/usr/src/uts/common/rpc/svc_cots.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.
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 /*
23 23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 24 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
25 + * Copyright (c) 2012 by Delphix. All rights reserved.
25 26 */
26 27
27 28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 29 /* All Rights Reserved */
29 30
30 31 /*
31 32 * Portions of this source code were derived from Berkeley 4.3 BSD
32 33 * under license from the Regents of the University of California.
33 34 */
34 35
35 36 /*
36 37 * svc_cots.c
37 38 * Server side for connection-oriented RPC in the kernel.
38 39 *
39 40 */
40 41
41 42 #include <sys/param.h>
42 43 #include <sys/types.h>
43 44 #include <sys/sysmacros.h>
44 45 #include <sys/file.h>
45 46 #include <sys/stream.h>
46 47 #include <sys/strsubr.h>
47 48 #include <sys/strsun.h>
48 49 #include <sys/stropts.h>
49 50 #include <sys/tiuser.h>
50 51 #include <sys/timod.h>
51 52 #include <sys/tihdr.h>
52 53 #include <sys/fcntl.h>
53 54 #include <sys/errno.h>
54 55 #include <sys/kmem.h>
55 56 #include <sys/systm.h>
56 57 #include <sys/debug.h>
57 58 #include <sys/cmn_err.h>
58 59 #include <sys/kstat.h>
59 60 #include <sys/vtrace.h>
60 61
61 62 #include <rpc/types.h>
62 63 #include <rpc/xdr.h>
63 64 #include <rpc/auth.h>
64 65 #include <rpc/rpc_msg.h>
65 66 #include <rpc/svc.h>
66 67 #include <inet/ip.h>
67 68
68 69 #define COTS_MAX_ALLOCSIZE 2048
69 70 #define MSG_OFFSET 128 /* offset of call into the mblk */
70 71 #define RM_HDR_SIZE 4 /* record mark header size */
71 72
72 73 /*
73 74 * Routines exported through ops vector.
74 75 */
75 76 static bool_t svc_cots_krecv(SVCXPRT *, mblk_t *, struct rpc_msg *);
76 77 static bool_t svc_cots_ksend(SVCXPRT *, struct rpc_msg *);
77 78 static bool_t svc_cots_kgetargs(SVCXPRT *, xdrproc_t, caddr_t);
78 79 static bool_t svc_cots_kfreeargs(SVCXPRT *, xdrproc_t, caddr_t);
79 80 static void svc_cots_kdestroy(SVCMASTERXPRT *);
80 81 static int svc_cots_kdup(struct svc_req *, caddr_t, int,
81 82 struct dupreq **, bool_t *);
82 83 static void svc_cots_kdupdone(struct dupreq *, caddr_t,
83 84 void (*)(), int, int);
84 85 static int32_t *svc_cots_kgetres(SVCXPRT *, int);
85 86 static void svc_cots_kfreeres(SVCXPRT *);
86 87 static void svc_cots_kclone_destroy(SVCXPRT *);
87 88 static void svc_cots_kstart(SVCMASTERXPRT *);
88 89 static void svc_cots_ktattrs(SVCXPRT *, int, void **);
89 90
90 91 /*
91 92 * Server transport operations vector.
92 93 */
93 94 struct svc_ops svc_cots_op = {
94 95 svc_cots_krecv, /* Get requests */
95 96 svc_cots_kgetargs, /* Deserialize arguments */
96 97 svc_cots_ksend, /* Send reply */
97 98 svc_cots_kfreeargs, /* Free argument data space */
98 99 svc_cots_kdestroy, /* Destroy transport handle */
99 100 svc_cots_kdup, /* Check entry in dup req cache */
100 101 svc_cots_kdupdone, /* Mark entry in dup req cache as done */
101 102 svc_cots_kgetres, /* Get pointer to response buffer */
102 103 svc_cots_kfreeres, /* Destroy pre-serialized response header */
103 104 svc_cots_kclone_destroy, /* Destroy a clone xprt */
104 105 svc_cots_kstart, /* Tell `ready-to-receive' to rpcmod */
105 106 NULL, /* Transport specific clone xprt */
106 107 svc_cots_ktattrs /* Transport Attributes */
107 108 };
108 109
109 110 /*
110 111 * Master transport private data.
111 112 * Kept in xprt->xp_p2.
112 113 */
113 114 struct cots_master_data {
114 115 char *cmd_src_addr; /* client's address */
115 116 int cmd_xprt_started; /* flag for clone routine to call */
116 117 /* rpcmod's start routine. */
117 118 struct rpc_cots_server *cmd_stats; /* stats for zone */
118 119 };
119 120
120 121 /*
121 122 * Transport private data.
122 123 * Kept in clone_xprt->xp_p2buf.
123 124 */
124 125 typedef struct cots_data {
125 126 mblk_t *cd_mp; /* pre-allocated reply message */
126 127 mblk_t *cd_req_mp; /* request message */
127 128 } cots_data_t;
128 129
129 130 /*
130 131 * Server statistics
131 132 * NOTE: This structure type is duplicated in the NFS fast path.
132 133 */
133 134 static const struct rpc_cots_server {
134 135 kstat_named_t rscalls;
135 136 kstat_named_t rsbadcalls;
136 137 kstat_named_t rsnullrecv;
137 138 kstat_named_t rsbadlen;
138 139 kstat_named_t rsxdrcall;
139 140 kstat_named_t rsdupchecks;
140 141 kstat_named_t rsdupreqs;
141 142 } cots_rsstat_tmpl = {
142 143 { "calls", KSTAT_DATA_UINT64 },
143 144 { "badcalls", KSTAT_DATA_UINT64 },
144 145 { "nullrecv", KSTAT_DATA_UINT64 },
145 146 { "badlen", KSTAT_DATA_UINT64 },
146 147 { "xdrcall", KSTAT_DATA_UINT64 },
147 148 { "dupchecks", KSTAT_DATA_UINT64 },
148 149 { "dupreqs", KSTAT_DATA_UINT64 }
149 150 };
150 151
151 152 #define CLONE2STATS(clone_xprt) \
152 153 ((struct cots_master_data *)(clone_xprt)->xp_master->xp_p2)->cmd_stats
153 154 #define RSSTAT_INCR(s, x) \
154 155 atomic_inc_64(&(s)->x.value.ui64)
155 156
156 157 /*
157 158 * Pointer to a transport specific `ready to receive' function in rpcmod
158 159 * (set from rpcmod).
159 160 */
160 161 void (*mir_start)(queue_t *);
161 162 uint_t *svc_max_msg_sizep;
162 163
163 164 /*
164 165 * the address size of the underlying transport can sometimes be
165 166 * unknown (tinfo->ADDR_size == -1). For this case, it is
166 167 * necessary to figure out what the size is so the correct amount
167 168 * of data is allocated. This is an itterative process:
168 169 * 1. take a good guess (use T_MINADDRSIZE)
169 170 * 2. try it.
170 171 * 3. if it works then everything is ok
171 172 * 4. if the error is ENAMETOLONG, double the guess
172 173 * 5. go back to step 2.
173 174 */
174 175 #define T_UNKNOWNADDRSIZE (-1)
175 176 #define T_MINADDRSIZE 32
176 177
177 178 /*
178 179 * Create a transport record.
179 180 * The transport record, output buffer, and private data structure
180 181 * are allocated. The output buffer is serialized into using xdrmem.
181 182 * There is one transport record per user process which implements a
182 183 * set of services.
183 184 */
184 185 static kmutex_t cots_kcreate_lock;
185 186
186 187 int
187 188 svc_cots_kcreate(file_t *fp, uint_t max_msgsize, struct T_info_ack *tinfo,
188 189 SVCMASTERXPRT **nxprt)
189 190 {
190 191 struct cots_master_data *cmd;
191 192 int err, retval;
192 193 SVCMASTERXPRT *xprt;
193 194 struct rpcstat *rpcstat;
194 195 struct T_addr_ack *ack_p;
195 196 struct strioctl getaddr;
196 197
197 198 if (nxprt == NULL)
198 199 return (EINVAL);
199 200
200 201 rpcstat = zone_getspecific(rpcstat_zone_key, curproc->p_zone);
201 202 ASSERT(rpcstat != NULL);
202 203
203 204 xprt = kmem_zalloc(sizeof (SVCMASTERXPRT), KM_SLEEP);
204 205
205 206 cmd = kmem_zalloc(sizeof (*cmd) + sizeof (*ack_p)
206 207 + (2 * sizeof (sin6_t)), KM_SLEEP);
207 208
208 209 ack_p = (struct T_addr_ack *)&cmd[1];
209 210
210 211 if ((tinfo->TIDU_size > COTS_MAX_ALLOCSIZE) ||
211 212 (tinfo->TIDU_size <= 0))
212 213 xprt->xp_msg_size = COTS_MAX_ALLOCSIZE;
213 214 else {
214 215 xprt->xp_msg_size = tinfo->TIDU_size -
215 216 (tinfo->TIDU_size % BYTES_PER_XDR_UNIT);
216 217 }
217 218
218 219 xprt->xp_ops = &svc_cots_op;
219 220 xprt->xp_p2 = (caddr_t)cmd;
220 221 cmd->cmd_xprt_started = 0;
221 222 cmd->cmd_stats = rpcstat->rpc_cots_server;
222 223
223 224 getaddr.ic_cmd = TI_GETINFO;
224 225 getaddr.ic_timout = -1;
225 226 getaddr.ic_len = sizeof (*ack_p) + (2 * sizeof (sin6_t));
226 227 getaddr.ic_dp = (char *)ack_p;
227 228 ack_p->PRIM_type = T_ADDR_REQ;
228 229
229 230 err = strioctl(fp->f_vnode, I_STR, (intptr_t)&getaddr,
230 231 0, K_TO_K, CRED(), &retval);
231 232 if (err) {
232 233 kmem_free(cmd, sizeof (*cmd) + sizeof (*ack_p) +
233 234 (2 * sizeof (sin6_t)));
234 235 kmem_free(xprt, sizeof (SVCMASTERXPRT));
235 236 return (err);
236 237 }
237 238
238 239 xprt->xp_rtaddr.maxlen = ack_p->REMADDR_length;
239 240 xprt->xp_rtaddr.len = ack_p->REMADDR_length;
240 241 cmd->cmd_src_addr = xprt->xp_rtaddr.buf =
241 242 (char *)ack_p + ack_p->REMADDR_offset;
242 243
243 244 xprt->xp_lcladdr.maxlen = ack_p->LOCADDR_length;
244 245 xprt->xp_lcladdr.len = ack_p->LOCADDR_length;
245 246 xprt->xp_lcladdr.buf = (char *)ack_p + ack_p->LOCADDR_offset;
246 247
247 248 /*
248 249 * If the current sanity check size in rpcmod is smaller
249 250 * than the size needed for this xprt, then increase
250 251 * the sanity check.
251 252 */
252 253 if (max_msgsize != 0 && svc_max_msg_sizep &&
253 254 max_msgsize > *svc_max_msg_sizep) {
254 255
255 256 /* This check needs a lock */
256 257 mutex_enter(&cots_kcreate_lock);
257 258 if (svc_max_msg_sizep && max_msgsize > *svc_max_msg_sizep)
258 259 *svc_max_msg_sizep = max_msgsize;
259 260 mutex_exit(&cots_kcreate_lock);
260 261 }
261 262
262 263 *nxprt = xprt;
263 264
264 265 return (0);
265 266 }
266 267
267 268 /*
268 269 * Destroy a master transport record.
269 270 * Frees the space allocated for a transport record.
270 271 */
271 272 static void
272 273 svc_cots_kdestroy(SVCMASTERXPRT *xprt)
273 274 {
274 275 struct cots_master_data *cmd = (struct cots_master_data *)xprt->xp_p2;
275 276
276 277 ASSERT(cmd);
277 278
278 279 if (xprt->xp_netid)
279 280 kmem_free(xprt->xp_netid, strlen(xprt->xp_netid) + 1);
280 281 if (xprt->xp_addrmask.maxlen)
281 282 kmem_free(xprt->xp_addrmask.buf, xprt->xp_addrmask.maxlen);
282 283
283 284 mutex_destroy(&xprt->xp_req_lock);
284 285 mutex_destroy(&xprt->xp_thread_lock);
285 286
286 287 kmem_free(cmd, sizeof (*cmd) + sizeof (struct T_addr_ack) +
287 288 (2 * sizeof (sin6_t)));
288 289
289 290 kmem_free(xprt, sizeof (SVCMASTERXPRT));
290 291 }
291 292
292 293 /*
293 294 * svc_tli_kcreate() calls this function at the end to tell
294 295 * rpcmod that the transport is ready to receive requests.
295 296 */
296 297 static void
297 298 svc_cots_kstart(SVCMASTERXPRT *xprt)
298 299 {
299 300 struct cots_master_data *cmd = (struct cots_master_data *)xprt->xp_p2;
300 301
301 302 if (cmd->cmd_xprt_started == 0) {
302 303 /*
303 304 * Acquire the xp_req_lock in order to use xp_wq
304 305 * safely (we don't want to qenable a queue that has
305 306 * already been closed).
306 307 */
307 308 mutex_enter(&xprt->xp_req_lock);
308 309 if (cmd->cmd_xprt_started == 0 &&
309 310 xprt->xp_wq != NULL) {
310 311 (*mir_start)(xprt->xp_wq);
311 312 cmd->cmd_xprt_started = 1;
312 313 }
313 314 mutex_exit(&xprt->xp_req_lock);
314 315 }
315 316 }
316 317
317 318 /*
318 319 * Transport-type specific part of svc_xprt_cleanup().
319 320 */
320 321 static void
321 322 svc_cots_kclone_destroy(SVCXPRT *clone_xprt)
322 323 {
323 324 cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
324 325
325 326 if (cd->cd_req_mp) {
326 327 freemsg(cd->cd_req_mp);
327 328 cd->cd_req_mp = (mblk_t *)0;
328 329 }
329 330 ASSERT(cd->cd_mp == NULL);
330 331 }
331 332
332 333 /*
333 334 * Transport Attributes.
334 335 */
335 336 static void
336 337 svc_cots_ktattrs(SVCXPRT *clone_xprt, int attrflag, void **tattr)
337 338 {
338 339 *tattr = NULL;
339 340
340 341 switch (attrflag) {
341 342 case SVC_TATTR_ADDRMASK:
342 343 *tattr = (void *)&clone_xprt->xp_master->xp_addrmask;
343 344 }
344 345 }
345 346
346 347 /*
347 348 * Receive rpc requests.
348 349 * Checks if the message is intact, and deserializes the call packet.
349 350 */
350 351 static bool_t
351 352 svc_cots_krecv(SVCXPRT *clone_xprt, mblk_t *mp, struct rpc_msg *msg)
352 353 {
353 354 cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
354 355 XDR *xdrs = &clone_xprt->xp_xdrin;
355 356 struct rpc_cots_server *stats = CLONE2STATS(clone_xprt);
356 357
357 358 TRACE_0(TR_FAC_KRPC, TR_SVC_COTS_KRECV_START,
358 359 "svc_cots_krecv_start:");
359 360 RPCLOG(4, "svc_cots_krecv_start clone_xprt = %p:\n",
360 361 (void *)clone_xprt);
361 362
362 363 RSSTAT_INCR(stats, rscalls);
363 364
364 365 if (mp->b_datap->db_type != M_DATA) {
365 366 RPCLOG(16, "svc_cots_krecv bad db_type %d\n",
366 367 mp->b_datap->db_type);
367 368 goto bad;
368 369 }
369 370
370 371 xdrmblk_init(xdrs, mp, XDR_DECODE, 0);
371 372
372 373 TRACE_0(TR_FAC_KRPC, TR_XDR_CALLMSG_START,
373 374 "xdr_callmsg_start:");
374 375 RPCLOG0(4, "xdr_callmsg_start:\n");
375 376 if (!xdr_callmsg(xdrs, msg)) {
376 377 XDR_DESTROY(xdrs);
377 378 TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
378 379 "xdr_callmsg_end:(%S)", "bad");
379 380 RPCLOG0(1, "svc_cots_krecv xdr_callmsg failure\n");
380 381 RSSTAT_INCR(stats, rsxdrcall);
381 382 goto bad;
382 383 }
383 384 TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
384 385 "xdr_callmsg_end:(%S)", "good");
385 386
386 387 clone_xprt->xp_xid = msg->rm_xid;
387 388 cd->cd_req_mp = mp;
388 389
389 390 TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KRECV_END,
390 391 "svc_cots_krecv_end:(%S)", "good");
391 392 RPCLOG0(4, "svc_cots_krecv_end:good\n");
392 393 return (TRUE);
393 394
394 395 bad:
395 396 if (mp)
396 397 freemsg(mp);
397 398
398 399 RSSTAT_INCR(stats, rsbadcalls);
399 400 TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KRECV_END,
400 401 "svc_cots_krecv_end:(%S)", "bad");
401 402 return (FALSE);
402 403 }
403 404
404 405 /*
405 406 * Send rpc reply.
406 407 */
407 408 static bool_t
408 409 svc_cots_ksend(SVCXPRT *clone_xprt, struct rpc_msg *msg)
409 410 {
410 411 /* LINTED pointer alignment */
411 412 cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
412 413 XDR *xdrs = &(clone_xprt->xp_xdrout);
413 414 int retval = FALSE;
414 415 mblk_t *mp;
415 416 xdrproc_t xdr_results;
416 417 caddr_t xdr_location;
417 418 bool_t has_args;
418 419
419 420 TRACE_0(TR_FAC_KRPC, TR_SVC_COTS_KSEND_START,
420 421 "svc_cots_ksend_start:");
421 422
422 423 /*
423 424 * If there is a result procedure specified in the reply message,
424 425 * it will be processed in the xdr_replymsg and SVCAUTH_WRAP.
425 426 * We need to make sure it won't be processed twice, so we null
426 427 * it for xdr_replymsg here.
427 428 */
428 429 has_args = FALSE;
429 430 if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
430 431 msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
431 432 if ((xdr_results = msg->acpted_rply.ar_results.proc) != NULL) {
432 433 has_args = TRUE;
433 434 xdr_location = msg->acpted_rply.ar_results.where;
434 435 msg->acpted_rply.ar_results.proc = xdr_void;
435 436 msg->acpted_rply.ar_results.where = NULL;
436 437 }
437 438 }
438 439
439 440 mp = cd->cd_mp;
440 441 if (mp) {
441 442 /*
442 443 * The program above pre-allocated an mblk and put
443 444 * the data in place.
444 445 */
445 446 cd->cd_mp = (mblk_t *)NULL;
446 447 if (!(xdr_replymsg_body(xdrs, msg) &&
447 448 (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
448 449 xdr_results, xdr_location)))) {
449 450 XDR_DESTROY(xdrs);
450 451 RPCLOG0(1, "svc_cots_ksend: "
451 452 "xdr_replymsg_body/SVCAUTH_WRAP failed\n");
452 453 freemsg(mp);
453 454 goto out;
454 455 }
455 456 } else {
456 457 int len;
457 458 int mpsize;
458 459
459 460 /*
460 461 * Leave space for protocol headers.
461 462 */
462 463 len = MSG_OFFSET + clone_xprt->xp_msg_size;
463 464
464 465 /*
465 466 * Allocate an initial mblk for the response data.
466 467 */
467 468 while (!(mp = allocb(len, BPRI_LO))) {
468 469 RPCLOG0(16, "svc_cots_ksend: allocb failed failed\n");
469 470 if (strwaitbuf(len, BPRI_LO)) {
470 471 TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KSEND_END,
471 472 "svc_cots_ksend_end:(%S)", "strwaitbuf");
472 473 RPCLOG0(1,
473 474 "svc_cots_ksend: strwaitbuf failed\n");
474 475 goto out;
475 476 }
476 477 }
477 478
478 479 /*
479 480 * Initialize the XDR encode stream. Additional mblks
480 481 * will be allocated if necessary. They will be TIDU
481 482 * sized.
482 483 */
483 484 xdrmblk_init(xdrs, mp, XDR_ENCODE, clone_xprt->xp_msg_size);
484 485 mpsize = MBLKSIZE(mp);
485 486 ASSERT(mpsize >= len);
486 487 ASSERT(mp->b_rptr == mp->b_datap->db_base);
487 488
488 489 /*
489 490 * If the size of mblk is not appreciably larger than what we
490 491 * asked, then resize the mblk to exactly len bytes. Reason for
491 492 * this: suppose len is 1600 bytes, the tidu is 1460 bytes
492 493 * (from TCP over ethernet), and the arguments to RPC require
493 494 * 2800 bytes. Ideally we want the protocol to render two
494 495 * ~1400 byte segments over the wire. If allocb() gives us a 2k
495 496 * mblk, and we allocate a second mblk for the rest, the
496 497 * protocol module may generate 3 segments over the wire:
497 498 * 1460 bytes for the first, 448 (2048 - 1600) for the 2nd, and
498 499 * 892 for the 3rd. If we "waste" 448 bytes in the first mblk,
499 500 * the XDR encoding will generate two ~1400 byte mblks, and the
500 501 * protocol module is more likely to produce properly sized
501 502 * segments.
502 503 */
503 504 if ((mpsize >> 1) <= len) {
504 505 mp->b_rptr += (mpsize - len);
505 506 }
506 507
507 508 /*
508 509 * Adjust b_rptr to reserve space for the non-data protocol
509 510 * headers that any downstream modules might like to add, and
510 511 * for the record marking header.
511 512 */
512 513 mp->b_rptr += (MSG_OFFSET + RM_HDR_SIZE);
513 514
514 515 XDR_SETPOS(xdrs, (uint_t)(mp->b_rptr - mp->b_datap->db_base));
515 516 ASSERT(mp->b_wptr == mp->b_rptr);
516 517
517 518 msg->rm_xid = clone_xprt->xp_xid;
518 519
519 520 TRACE_0(TR_FAC_KRPC, TR_XDR_REPLYMSG_START,
520 521 "xdr_replymsg_start:");
521 522 if (!(xdr_replymsg(xdrs, msg) &&
522 523 (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
523 524 xdr_results, xdr_location)))) {
524 525 XDR_DESTROY(xdrs);
525 526 TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
526 527 "xdr_replymsg_end:(%S)", "bad");
527 528 freemsg(mp);
528 529 RPCLOG0(1, "svc_cots_ksend: xdr_replymsg/SVCAUTH_WRAP "
529 530 "failed\n");
530 531 goto out;
531 532 }
532 533 TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
533 534 "xdr_replymsg_end:(%S)", "good");
534 535 }
535 536
536 537 XDR_DESTROY(xdrs);
537 538
538 539 put(clone_xprt->xp_wq, mp);
539 540 retval = TRUE;
540 541
541 542 out:
542 543 /*
543 544 * This is completely disgusting. If public is set it is
544 545 * a pointer to a structure whose first field is the address
545 546 * of the function to free that structure and any related
546 547 * stuff. (see rrokfree in nfs_xdr.c).
547 548 */
548 549 if (xdrs->x_public) {
549 550 /* LINTED pointer alignment */
550 551 (**((int (**)())xdrs->x_public))(xdrs->x_public);
551 552 }
552 553
553 554 TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KSEND_END,
554 555 "svc_cots_ksend_end:(%S)", "done");
555 556 return (retval);
556 557 }
557 558
558 559 /*
559 560 * Deserialize arguments.
560 561 */
561 562 static bool_t
562 563 svc_cots_kgetargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
563 564 caddr_t args_ptr)
564 565 {
565 566 return (SVCAUTH_UNWRAP(&clone_xprt->xp_auth, &clone_xprt->xp_xdrin,
566 567 xdr_args, args_ptr));
567 568 }
568 569
569 570 static bool_t
570 571 svc_cots_kfreeargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
571 572 caddr_t args_ptr)
572 573 {
573 574 cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
574 575 /* LINTED pointer alignment */
575 576 XDR *xdrs = &clone_xprt->xp_xdrin;
576 577 mblk_t *mp;
577 578 bool_t retval;
578 579
579 580 /*
580 581 * It is important to call the XDR routine before
581 582 * freeing the request mblk. Structures in the
582 583 * XDR data may point into the mblk and require that
583 584 * the memory be intact during the free routine.
584 585 */
585 586 if (args_ptr) {
586 587 xdrs->x_op = XDR_FREE;
587 588 retval = (*xdr_args)(xdrs, args_ptr);
588 589 } else
589 590 retval = TRUE;
590 591
591 592 XDR_DESTROY(xdrs);
592 593
593 594 if ((mp = cd->cd_req_mp) != NULL) {
594 595 cd->cd_req_mp = (mblk_t *)0;
595 596 freemsg(mp);
596 597 }
597 598
598 599 return (retval);
599 600 }
600 601
601 602 static int32_t *
602 603 svc_cots_kgetres(SVCXPRT *clone_xprt, int size)
603 604 {
604 605 /* LINTED pointer alignment */
605 606 cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
606 607 XDR *xdrs = &clone_xprt->xp_xdrout;
607 608 mblk_t *mp;
608 609 int32_t *buf;
609 610 struct rpc_msg rply;
610 611 int len;
611 612 int mpsize;
612 613
613 614 /*
614 615 * Leave space for protocol headers.
615 616 */
616 617 len = MSG_OFFSET + clone_xprt->xp_msg_size;
617 618
618 619 /*
619 620 * Allocate an initial mblk for the response data.
620 621 */
621 622 while ((mp = allocb(len, BPRI_LO)) == NULL) {
622 623 if (strwaitbuf(len, BPRI_LO))
623 624 return (NULL);
624 625 }
625 626
626 627 /*
627 628 * Initialize the XDR encode stream. Additional mblks
628 629 * will be allocated if necessary. They will be TIDU
629 630 * sized.
630 631 */
631 632 xdrmblk_init(xdrs, mp, XDR_ENCODE, clone_xprt->xp_msg_size);
632 633 mpsize = MBLKSIZE(mp);
633 634 ASSERT(mpsize >= len);
634 635 ASSERT(mp->b_rptr == mp->b_datap->db_base);
635 636
636 637 /*
637 638 * If the size of mblk is not appreciably larger than what we
638 639 * asked, then resize the mblk to exactly len bytes. Reason for
639 640 * this: suppose len is 1600 bytes, the tidu is 1460 bytes
640 641 * (from TCP over ethernet), and the arguments to RPC require
641 642 * 2800 bytes. Ideally we want the protocol to render two
642 643 * ~1400 byte segments over the wire. If allocb() gives us a 2k
643 644 * mblk, and we allocate a second mblk for the rest, the
644 645 * protocol module may generate 3 segments over the wire:
645 646 * 1460 bytes for the first, 448 (2048 - 1600) for the 2nd, and
646 647 * 892 for the 3rd. If we "waste" 448 bytes in the first mblk,
647 648 * the XDR encoding will generate two ~1400 byte mblks, and the
648 649 * protocol module is more likely to produce properly sized
649 650 * segments.
650 651 */
651 652 if ((mpsize >> 1) <= len) {
652 653 mp->b_rptr += (mpsize - len);
653 654 }
654 655
655 656 /*
656 657 * Adjust b_rptr to reserve space for the non-data protocol
657 658 * headers that any downstream modules might like to add, and
658 659 * for the record marking header.
659 660 */
660 661 mp->b_rptr += (MSG_OFFSET + RM_HDR_SIZE);
661 662
662 663 XDR_SETPOS(xdrs, (uint_t)(mp->b_rptr - mp->b_datap->db_base));
663 664 ASSERT(mp->b_wptr == mp->b_rptr);
664 665
665 666 /*
666 667 * Assume a successful RPC since most of them are.
667 668 */
668 669 rply.rm_xid = clone_xprt->xp_xid;
669 670 rply.rm_direction = REPLY;
670 671 rply.rm_reply.rp_stat = MSG_ACCEPTED;
671 672 rply.acpted_rply.ar_verf = clone_xprt->xp_verf;
672 673 rply.acpted_rply.ar_stat = SUCCESS;
673 674
674 675 if (!xdr_replymsg_hdr(xdrs, &rply)) {
675 676 XDR_DESTROY(xdrs);
676 677 freeb(mp);
677 678 return (NULL);
678 679 }
679 680
680 681 buf = XDR_INLINE(xdrs, size);
681 682 if (buf == NULL) {
682 683 XDR_DESTROY(xdrs);
683 684 ASSERT(cd->cd_mp == NULL);
684 685 freemsg(mp);
685 686 } else {
686 687 cd->cd_mp = mp;
687 688 }
688 689 return (buf);
689 690 }
690 691
691 692 static void
692 693 svc_cots_kfreeres(SVCXPRT *clone_xprt)
693 694 {
694 695 cots_data_t *cd;
695 696 mblk_t *mp;
696 697
697 698 cd = (cots_data_t *)clone_xprt->xp_p2buf;
698 699 if ((mp = cd->cd_mp) != NULL) {
699 700 XDR_DESTROY(&clone_xprt->xp_xdrout);
700 701 cd->cd_mp = (mblk_t *)NULL;
701 702 freemsg(mp);
702 703 }
703 704 }
704 705
705 706 /*
|
↓ open down ↓ |
671 lines elided |
↑ open up ↑ |
706 707 * the dup cacheing routines below provide a cache of non-failure
707 708 * transaction id's. rpc service routines can use this to detect
708 709 * retransmissions and re-send a non-failure response.
709 710 */
710 711
711 712 /*
712 713 * MAXDUPREQS is the number of cached items. It should be adjusted
713 714 * to the service load so that there is likely to be a response entry
714 715 * when the first retransmission comes in.
715 716 */
716 -#define MAXDUPREQS 1024
717 +#define MAXDUPREQS 8192
717 718
718 719 /*
719 720 * This should be appropriately scaled to MAXDUPREQS.
720 721 */
721 -#define DRHASHSZ 257
722 +#define DRHASHSZ 2053
722 723
723 724 #if ((DRHASHSZ & (DRHASHSZ - 1)) == 0)
724 725 #define XIDHASH(xid) ((xid) & (DRHASHSZ - 1))
725 726 #else
726 727 #define XIDHASH(xid) ((xid) % DRHASHSZ)
727 728 #endif
728 729 #define DRHASH(dr) XIDHASH((dr)->dr_xid)
729 730 #define REQTOXID(req) ((req)->rq_xprt->xp_xid)
730 731
731 732 static int cotsndupreqs = 0;
732 733 int cotsmaxdupreqs = MAXDUPREQS;
733 734 static kmutex_t cotsdupreq_lock;
734 735 static struct dupreq *cotsdrhashtbl[DRHASHSZ];
735 736 static int cotsdrhashstat[DRHASHSZ];
736 737
737 738 static void unhash(struct dupreq *);
738 739
739 740 /*
740 741 * cotsdrmru points to the head of a circular linked list in lru order.
741 742 * cotsdrmru->dr_next == drlru
742 743 */
743 744 struct dupreq *cotsdrmru;
744 745
745 746 /*
746 747 * PSARC 2003/523 Contract Private Interface
747 748 * svc_cots_kdup
748 749 * Changes must be reviewed by Solaris File Sharing
749 750 * Changes must be communicated to contract-2003-523@sun.com
750 751 *
751 752 * svc_cots_kdup searches the request cache and returns 0 if the
752 753 * request is not found in the cache. If it is found, then it
753 754 * returns the state of the request (in progress or done) and
754 755 * the status or attributes that were part of the original reply.
755 756 *
756 757 * If DUP_DONE (there is a duplicate) svc_cots_kdup copies over the
757 758 * value of the response. In that case, also return in *dupcachedp
758 759 * whether the response free routine is cached in the dupreq - in which case
759 760 * the caller should not be freeing it, because it will be done later
760 761 * in the svc_cots_kdup code when the dupreq is reused.
761 762 */
762 763 static int
763 764 svc_cots_kdup(struct svc_req *req, caddr_t res, int size, struct dupreq **drpp,
764 765 bool_t *dupcachedp)
765 766 {
766 767 struct rpc_cots_server *stats = CLONE2STATS(req->rq_xprt);
767 768 struct dupreq *dr;
768 769 uint32_t xid;
769 770 uint32_t drhash;
770 771 int status;
771 772
772 773 xid = REQTOXID(req);
773 774 mutex_enter(&cotsdupreq_lock);
774 775 RSSTAT_INCR(stats, rsdupchecks);
775 776 /*
776 777 * Check to see whether an entry already exists in the cache.
777 778 */
778 779 dr = cotsdrhashtbl[XIDHASH(xid)];
779 780 while (dr != NULL) {
780 781 if (dr->dr_xid == xid &&
781 782 dr->dr_proc == req->rq_proc &&
782 783 dr->dr_prog == req->rq_prog &&
783 784 dr->dr_vers == req->rq_vers &&
784 785 dr->dr_addr.len == req->rq_xprt->xp_rtaddr.len &&
785 786 bcmp((caddr_t)dr->dr_addr.buf,
786 787 (caddr_t)req->rq_xprt->xp_rtaddr.buf,
787 788 dr->dr_addr.len) == 0) {
788 789 status = dr->dr_status;
789 790 if (status == DUP_DONE) {
790 791 bcopy(dr->dr_resp.buf, res, size);
791 792 if (dupcachedp != NULL)
792 793 *dupcachedp = (dr->dr_resfree != NULL);
793 794 TRACE_0(TR_FAC_KRPC, TR_SVC_COTS_KDUP_DONE,
794 795 "svc_cots_kdup: DUP_DONE");
795 796 } else {
796 797 dr->dr_status = DUP_INPROGRESS;
797 798 *drpp = dr;
798 799 TRACE_0(TR_FAC_KRPC,
799 800 TR_SVC_COTS_KDUP_INPROGRESS,
800 801 "svc_cots_kdup: DUP_INPROGRESS");
801 802 }
802 803 RSSTAT_INCR(stats, rsdupreqs);
803 804 mutex_exit(&cotsdupreq_lock);
804 805 return (status);
805 806 }
806 807 dr = dr->dr_chain;
807 808 }
808 809
809 810 /*
810 811 * There wasn't an entry, either allocate a new one or recycle
811 812 * an old one.
812 813 */
813 814 if (cotsndupreqs < cotsmaxdupreqs) {
814 815 dr = kmem_alloc(sizeof (*dr), KM_NOSLEEP);
815 816 if (dr == NULL) {
816 817 mutex_exit(&cotsdupreq_lock);
817 818 return (DUP_ERROR);
818 819 }
819 820 dr->dr_resp.buf = NULL;
820 821 dr->dr_resp.maxlen = 0;
821 822 dr->dr_addr.buf = NULL;
822 823 dr->dr_addr.maxlen = 0;
823 824 if (cotsdrmru) {
824 825 dr->dr_next = cotsdrmru->dr_next;
825 826 cotsdrmru->dr_next = dr;
826 827 } else {
827 828 dr->dr_next = dr;
828 829 }
829 830 cotsndupreqs++;
830 831 } else {
831 832 dr = cotsdrmru->dr_next;
832 833 while (dr->dr_status == DUP_INPROGRESS) {
833 834 dr = dr->dr_next;
834 835 if (dr == cotsdrmru->dr_next) {
835 836 cmn_err(CE_WARN, "svc_cots_kdup no slots free");
836 837 mutex_exit(&cotsdupreq_lock);
837 838 return (DUP_ERROR);
838 839 }
839 840 }
840 841 unhash(dr);
841 842 if (dr->dr_resfree) {
842 843 (*dr->dr_resfree)(dr->dr_resp.buf);
843 844 }
844 845 }
845 846 dr->dr_resfree = NULL;
846 847 cotsdrmru = dr;
847 848
848 849 dr->dr_xid = REQTOXID(req);
849 850 dr->dr_prog = req->rq_prog;
850 851 dr->dr_vers = req->rq_vers;
851 852 dr->dr_proc = req->rq_proc;
852 853 if (dr->dr_addr.maxlen < req->rq_xprt->xp_rtaddr.len) {
853 854 if (dr->dr_addr.buf != NULL)
854 855 kmem_free(dr->dr_addr.buf, dr->dr_addr.maxlen);
855 856 dr->dr_addr.maxlen = req->rq_xprt->xp_rtaddr.len;
856 857 dr->dr_addr.buf = kmem_alloc(dr->dr_addr.maxlen, KM_NOSLEEP);
857 858 if (dr->dr_addr.buf == NULL) {
858 859 dr->dr_addr.maxlen = 0;
859 860 dr->dr_status = DUP_DROP;
860 861 mutex_exit(&cotsdupreq_lock);
861 862 return (DUP_ERROR);
862 863 }
863 864 }
864 865 dr->dr_addr.len = req->rq_xprt->xp_rtaddr.len;
865 866 bcopy(req->rq_xprt->xp_rtaddr.buf, dr->dr_addr.buf, dr->dr_addr.len);
866 867 if (dr->dr_resp.maxlen < size) {
867 868 if (dr->dr_resp.buf != NULL)
868 869 kmem_free(dr->dr_resp.buf, dr->dr_resp.maxlen);
869 870 dr->dr_resp.maxlen = (unsigned int)size;
870 871 dr->dr_resp.buf = kmem_alloc(size, KM_NOSLEEP);
871 872 if (dr->dr_resp.buf == NULL) {
872 873 dr->dr_resp.maxlen = 0;
873 874 dr->dr_status = DUP_DROP;
874 875 mutex_exit(&cotsdupreq_lock);
875 876 return (DUP_ERROR);
876 877 }
877 878 }
878 879 dr->dr_status = DUP_INPROGRESS;
879 880
880 881 drhash = (uint32_t)DRHASH(dr);
881 882 dr->dr_chain = cotsdrhashtbl[drhash];
882 883 cotsdrhashtbl[drhash] = dr;
883 884 cotsdrhashstat[drhash]++;
884 885 mutex_exit(&cotsdupreq_lock);
885 886 *drpp = dr;
886 887 return (DUP_NEW);
887 888 }
888 889
889 890 /*
890 891 * PSARC 2003/523 Contract Private Interface
891 892 * svc_cots_kdupdone
892 893 * Changes must be reviewed by Solaris File Sharing
893 894 * Changes must be communicated to contract-2003-523@sun.com
894 895 *
895 896 * svc_cots_kdupdone marks the request done (DUP_DONE or DUP_DROP)
896 897 * and stores the response.
897 898 */
898 899 static void
899 900 svc_cots_kdupdone(struct dupreq *dr, caddr_t res, void (*dis_resfree)(),
900 901 int size, int status)
901 902 {
902 903 ASSERT(dr->dr_resfree == NULL);
903 904 if (status == DUP_DONE) {
904 905 bcopy(res, dr->dr_resp.buf, size);
905 906 dr->dr_resfree = dis_resfree;
906 907 }
907 908 dr->dr_status = status;
908 909 }
909 910
910 911 /*
911 912 * This routine expects that the mutex, cotsdupreq_lock, is already held.
912 913 */
913 914 static void
914 915 unhash(struct dupreq *dr)
915 916 {
916 917 struct dupreq *drt;
917 918 struct dupreq *drtprev = NULL;
918 919 uint32_t drhash;
919 920
920 921 ASSERT(MUTEX_HELD(&cotsdupreq_lock));
921 922
922 923 drhash = (uint32_t)DRHASH(dr);
923 924 drt = cotsdrhashtbl[drhash];
924 925 while (drt != NULL) {
925 926 if (drt == dr) {
926 927 cotsdrhashstat[drhash]--;
927 928 if (drtprev == NULL) {
928 929 cotsdrhashtbl[drhash] = drt->dr_chain;
929 930 } else {
930 931 drtprev->dr_chain = drt->dr_chain;
931 932 }
932 933 return;
933 934 }
934 935 drtprev = drt;
935 936 drt = drt->dr_chain;
936 937 }
937 938 }
938 939
939 940 void
940 941 svc_cots_stats_init(zoneid_t zoneid, struct rpc_cots_server **statsp)
941 942 {
942 943 *statsp = (struct rpc_cots_server *)rpcstat_zone_init_common(zoneid,
943 944 "unix", "rpc_cots_server", (const kstat_named_t *)&cots_rsstat_tmpl,
944 945 sizeof (cots_rsstat_tmpl));
945 946 }
946 947
947 948 void
948 949 svc_cots_stats_fini(zoneid_t zoneid, struct rpc_cots_server **statsp)
949 950 {
950 951 rpcstat_zone_fini_common(zoneid, "unix", "rpc_cots_server");
951 952 kmem_free(*statsp, sizeof (cots_rsstat_tmpl));
952 953 }
953 954
954 955 void
955 956 svc_cots_init(void)
956 957 {
957 958 /*
958 959 * Check to make sure that the cots private data will fit into
959 960 * the stack buffer allocated by svc_run. The ASSERT is a safety
960 961 * net if the cots_data_t structure ever changes.
961 962 */
962 963 /*CONSTANTCONDITION*/
963 964 ASSERT(sizeof (cots_data_t) <= SVC_P2LEN);
964 965
965 966 mutex_init(&cots_kcreate_lock, NULL, MUTEX_DEFAULT, NULL);
966 967 mutex_init(&cotsdupreq_lock, NULL, MUTEX_DEFAULT, NULL);
967 968 }
|
↓ open down ↓ |
236 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX