17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5e810a982Svv149972 * Common Development and Distribution License (the "License").
6e810a982Svv149972 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*cf98b944SMarcel Telka
227c478bd9Sstevel@tonic-gate /*
23*cf98b944SMarcel Telka * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
240a4b0810SKaren Rochford * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD
327c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California.
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * svc_cots.c
377c478bd9Sstevel@tonic-gate * Server side for connection-oriented RPC in the kernel.
387c478bd9Sstevel@tonic-gate *
397c478bd9Sstevel@tonic-gate */
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
447c478bd9Sstevel@tonic-gate #include <sys/file.h>
457c478bd9Sstevel@tonic-gate #include <sys/stream.h>
467c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
477c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
487c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
497c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
507c478bd9Sstevel@tonic-gate #include <sys/timod.h>
517c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
527c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
537c478bd9Sstevel@tonic-gate #include <sys/errno.h>
547c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
557c478bd9Sstevel@tonic-gate #include <sys/systm.h>
567c478bd9Sstevel@tonic-gate #include <sys/debug.h>
577c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
587c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
597c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate #include <rpc/types.h>
627c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
637c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
647c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
657c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
66e810a982Svv149972 #include <inet/ip.h>
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate #define COTS_MAX_ALLOCSIZE 2048
697c478bd9Sstevel@tonic-gate #define MSG_OFFSET 128 /* offset of call into the mblk */
707c478bd9Sstevel@tonic-gate #define RM_HDR_SIZE 4 /* record mark header size */
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate * Routines exported through ops vector.
747c478bd9Sstevel@tonic-gate */
757c478bd9Sstevel@tonic-gate static bool_t svc_cots_krecv(SVCXPRT *, mblk_t *, struct rpc_msg *);
767c478bd9Sstevel@tonic-gate static bool_t svc_cots_ksend(SVCXPRT *, struct rpc_msg *);
777c478bd9Sstevel@tonic-gate static bool_t svc_cots_kgetargs(SVCXPRT *, xdrproc_t, caddr_t);
787c478bd9Sstevel@tonic-gate static bool_t svc_cots_kfreeargs(SVCXPRT *, xdrproc_t, caddr_t);
797c478bd9Sstevel@tonic-gate static void svc_cots_kdestroy(SVCMASTERXPRT *);
807c478bd9Sstevel@tonic-gate static int svc_cots_kdup(struct svc_req *, caddr_t, int,
817c478bd9Sstevel@tonic-gate struct dupreq **, bool_t *);
827c478bd9Sstevel@tonic-gate static void svc_cots_kdupdone(struct dupreq *, caddr_t,
837c478bd9Sstevel@tonic-gate void (*)(), int, int);
847c478bd9Sstevel@tonic-gate static int32_t *svc_cots_kgetres(SVCXPRT *, int);
857c478bd9Sstevel@tonic-gate static void svc_cots_kfreeres(SVCXPRT *);
867c478bd9Sstevel@tonic-gate static void svc_cots_kclone_destroy(SVCXPRT *);
877c478bd9Sstevel@tonic-gate static void svc_cots_kstart(SVCMASTERXPRT *);
880a4b0810SKaren Rochford static void svc_cots_ktattrs(SVCXPRT *, int, void **);
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate * Server transport operations vector.
927c478bd9Sstevel@tonic-gate */
937c478bd9Sstevel@tonic-gate struct svc_ops svc_cots_op = {
947c478bd9Sstevel@tonic-gate svc_cots_krecv, /* Get requests */
957c478bd9Sstevel@tonic-gate svc_cots_kgetargs, /* Deserialize arguments */
967c478bd9Sstevel@tonic-gate svc_cots_ksend, /* Send reply */
977c478bd9Sstevel@tonic-gate svc_cots_kfreeargs, /* Free argument data space */
987c478bd9Sstevel@tonic-gate svc_cots_kdestroy, /* Destroy transport handle */
997c478bd9Sstevel@tonic-gate svc_cots_kdup, /* Check entry in dup req cache */
1007c478bd9Sstevel@tonic-gate svc_cots_kdupdone, /* Mark entry in dup req cache as done */
1017c478bd9Sstevel@tonic-gate svc_cots_kgetres, /* Get pointer to response buffer */
1027c478bd9Sstevel@tonic-gate svc_cots_kfreeres, /* Destroy pre-serialized response header */
1037c478bd9Sstevel@tonic-gate svc_cots_kclone_destroy, /* Destroy a clone xprt */
10460536ef9SKaren Rochford svc_cots_kstart, /* Tell `ready-to-receive' to rpcmod */
1050a4b0810SKaren Rochford NULL, /* Transport specific clone xprt */
1060a4b0810SKaren Rochford svc_cots_ktattrs /* Transport Attributes */
1077c478bd9Sstevel@tonic-gate };
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate * Master transport private data.
1117c478bd9Sstevel@tonic-gate * Kept in xprt->xp_p2.
1127c478bd9Sstevel@tonic-gate */
1137c478bd9Sstevel@tonic-gate struct cots_master_data {
1147c478bd9Sstevel@tonic-gate char *cmd_src_addr; /* client's address */
1157c478bd9Sstevel@tonic-gate int cmd_xprt_started; /* flag for clone routine to call */
1167c478bd9Sstevel@tonic-gate /* rpcmod's start routine. */
1177c478bd9Sstevel@tonic-gate struct rpc_cots_server *cmd_stats; /* stats for zone */
1187c478bd9Sstevel@tonic-gate };
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate * Transport private data.
1227c478bd9Sstevel@tonic-gate * Kept in clone_xprt->xp_p2buf.
1237c478bd9Sstevel@tonic-gate */
1247c478bd9Sstevel@tonic-gate typedef struct cots_data {
1257c478bd9Sstevel@tonic-gate mblk_t *cd_mp; /* pre-allocated reply message */
1267c478bd9Sstevel@tonic-gate mblk_t *cd_req_mp; /* request message */
1277c478bd9Sstevel@tonic-gate } cots_data_t;
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * Server statistics
1317c478bd9Sstevel@tonic-gate * NOTE: This structure type is duplicated in the NFS fast path.
1327c478bd9Sstevel@tonic-gate */
1337c478bd9Sstevel@tonic-gate static const struct rpc_cots_server {
1347c478bd9Sstevel@tonic-gate kstat_named_t rscalls;
1357c478bd9Sstevel@tonic-gate kstat_named_t rsbadcalls;
1367c478bd9Sstevel@tonic-gate kstat_named_t rsnullrecv;
1377c478bd9Sstevel@tonic-gate kstat_named_t rsbadlen;
1387c478bd9Sstevel@tonic-gate kstat_named_t rsxdrcall;
1397c478bd9Sstevel@tonic-gate kstat_named_t rsdupchecks;
1407c478bd9Sstevel@tonic-gate kstat_named_t rsdupreqs;
1417c478bd9Sstevel@tonic-gate } cots_rsstat_tmpl = {
1427c478bd9Sstevel@tonic-gate { "calls", KSTAT_DATA_UINT64 },
1437c478bd9Sstevel@tonic-gate { "badcalls", KSTAT_DATA_UINT64 },
1447c478bd9Sstevel@tonic-gate { "nullrecv", KSTAT_DATA_UINT64 },
1457c478bd9Sstevel@tonic-gate { "badlen", KSTAT_DATA_UINT64 },
1467c478bd9Sstevel@tonic-gate { "xdrcall", KSTAT_DATA_UINT64 },
1477c478bd9Sstevel@tonic-gate { "dupchecks", KSTAT_DATA_UINT64 },
1487c478bd9Sstevel@tonic-gate { "dupreqs", KSTAT_DATA_UINT64 }
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate #define CLONE2STATS(clone_xprt) \
1527c478bd9Sstevel@tonic-gate ((struct cots_master_data *)(clone_xprt)->xp_master->xp_p2)->cmd_stats
1537c478bd9Sstevel@tonic-gate #define RSSTAT_INCR(s, x) \
1541a5e258fSJosef 'Jeff' Sipek atomic_inc_64(&(s)->x.value.ui64)
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate * Pointer to a transport specific `ready to receive' function in rpcmod
1587c478bd9Sstevel@tonic-gate * (set from rpcmod).
1597c478bd9Sstevel@tonic-gate */
1607c478bd9Sstevel@tonic-gate void (*mir_start)(queue_t *);
1617c478bd9Sstevel@tonic-gate uint_t *svc_max_msg_sizep;
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate * the address size of the underlying transport can sometimes be
1657c478bd9Sstevel@tonic-gate * unknown (tinfo->ADDR_size == -1). For this case, it is
1667c478bd9Sstevel@tonic-gate * necessary to figure out what the size is so the correct amount
1677c478bd9Sstevel@tonic-gate * of data is allocated. This is an itterative process:
1687c478bd9Sstevel@tonic-gate * 1. take a good guess (use T_MINADDRSIZE)
1697c478bd9Sstevel@tonic-gate * 2. try it.
1707c478bd9Sstevel@tonic-gate * 3. if it works then everything is ok
1717c478bd9Sstevel@tonic-gate * 4. if the error is ENAMETOLONG, double the guess
1727c478bd9Sstevel@tonic-gate * 5. go back to step 2.
1737c478bd9Sstevel@tonic-gate */
1747c478bd9Sstevel@tonic-gate #define T_UNKNOWNADDRSIZE (-1)
1757c478bd9Sstevel@tonic-gate #define T_MINADDRSIZE 32
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * Create a transport record.
1797c478bd9Sstevel@tonic-gate * The transport record, output buffer, and private data structure
1807c478bd9Sstevel@tonic-gate * are allocated. The output buffer is serialized into using xdrmem.
1817c478bd9Sstevel@tonic-gate * There is one transport record per user process which implements a
1827c478bd9Sstevel@tonic-gate * set of services.
1837c478bd9Sstevel@tonic-gate */
1847c478bd9Sstevel@tonic-gate static kmutex_t cots_kcreate_lock;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate int
svc_cots_kcreate(file_t * fp,uint_t max_msgsize,struct T_info_ack * tinfo,SVCMASTERXPRT ** nxprt)1877c478bd9Sstevel@tonic-gate svc_cots_kcreate(file_t *fp, uint_t max_msgsize, struct T_info_ack *tinfo,
1887c478bd9Sstevel@tonic-gate SVCMASTERXPRT **nxprt)
1897c478bd9Sstevel@tonic-gate {
1907c478bd9Sstevel@tonic-gate struct cots_master_data *cmd;
191e810a982Svv149972 int err, retval;
1927c478bd9Sstevel@tonic-gate SVCMASTERXPRT *xprt;
1937c478bd9Sstevel@tonic-gate struct rpcstat *rpcstat;
194e810a982Svv149972 struct T_addr_ack *ack_p;
195e810a982Svv149972 struct strioctl getaddr;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate if (nxprt == NULL)
1987c478bd9Sstevel@tonic-gate return (EINVAL);
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate rpcstat = zone_getspecific(rpcstat_zone_key, curproc->p_zone);
2017c478bd9Sstevel@tonic-gate ASSERT(rpcstat != NULL);
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate xprt = kmem_zalloc(sizeof (SVCMASTERXPRT), KM_SLEEP);
2047c478bd9Sstevel@tonic-gate
205e810a982Svv149972 cmd = kmem_zalloc(sizeof (*cmd) + sizeof (*ack_p)
206e810a982Svv149972 + (2 * sizeof (sin6_t)), KM_SLEEP);
207e810a982Svv149972
208e810a982Svv149972 ack_p = (struct T_addr_ack *)&cmd[1];
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate if ((tinfo->TIDU_size > COTS_MAX_ALLOCSIZE) ||
2117c478bd9Sstevel@tonic-gate (tinfo->TIDU_size <= 0))
2127c478bd9Sstevel@tonic-gate xprt->xp_msg_size = COTS_MAX_ALLOCSIZE;
2137c478bd9Sstevel@tonic-gate else {
2147c478bd9Sstevel@tonic-gate xprt->xp_msg_size = tinfo->TIDU_size -
2157c478bd9Sstevel@tonic-gate (tinfo->TIDU_size % BYTES_PER_XDR_UNIT);
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate xprt->xp_ops = &svc_cots_op;
2197c478bd9Sstevel@tonic-gate xprt->xp_p2 = (caddr_t)cmd;
2207c478bd9Sstevel@tonic-gate cmd->cmd_xprt_started = 0;
2217c478bd9Sstevel@tonic-gate cmd->cmd_stats = rpcstat->rpc_cots_server;
2227c478bd9Sstevel@tonic-gate
223e810a982Svv149972 getaddr.ic_cmd = TI_GETINFO;
224e810a982Svv149972 getaddr.ic_timout = -1;
225e810a982Svv149972 getaddr.ic_len = sizeof (*ack_p) + (2 * sizeof (sin6_t));
226e810a982Svv149972 getaddr.ic_dp = (char *)ack_p;
227e810a982Svv149972 ack_p->PRIM_type = T_ADDR_REQ;
2287c478bd9Sstevel@tonic-gate
229e810a982Svv149972 err = strioctl(fp->f_vnode, I_STR, (intptr_t)&getaddr,
230e810a982Svv149972 0, K_TO_K, CRED(), &retval);
2317c478bd9Sstevel@tonic-gate if (err) {
232e810a982Svv149972 kmem_free(cmd, sizeof (*cmd) + sizeof (*ack_p) +
233e810a982Svv149972 (2 * sizeof (sin6_t)));
2347c478bd9Sstevel@tonic-gate kmem_free(xprt, sizeof (SVCMASTERXPRT));
2357c478bd9Sstevel@tonic-gate return (err);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
238e810a982Svv149972 xprt->xp_rtaddr.maxlen = ack_p->REMADDR_length;
239e810a982Svv149972 xprt->xp_rtaddr.len = ack_p->REMADDR_length;
240e810a982Svv149972 cmd->cmd_src_addr = xprt->xp_rtaddr.buf =
241e810a982Svv149972 (char *)ack_p + ack_p->REMADDR_offset;
242e810a982Svv149972
243e810a982Svv149972 xprt->xp_lcladdr.maxlen = ack_p->LOCADDR_length;
244e810a982Svv149972 xprt->xp_lcladdr.len = ack_p->LOCADDR_length;
245e810a982Svv149972 xprt->xp_lcladdr.buf = (char *)ack_p + ack_p->LOCADDR_offset;
246e810a982Svv149972
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate * If the current sanity check size in rpcmod is smaller
2497c478bd9Sstevel@tonic-gate * than the size needed for this xprt, then increase
2507c478bd9Sstevel@tonic-gate * the sanity check.
2517c478bd9Sstevel@tonic-gate */
2527c478bd9Sstevel@tonic-gate if (max_msgsize != 0 && svc_max_msg_sizep &&
2537c478bd9Sstevel@tonic-gate max_msgsize > *svc_max_msg_sizep) {
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate /* This check needs a lock */
2567c478bd9Sstevel@tonic-gate mutex_enter(&cots_kcreate_lock);
2577c478bd9Sstevel@tonic-gate if (svc_max_msg_sizep && max_msgsize > *svc_max_msg_sizep)
2587c478bd9Sstevel@tonic-gate *svc_max_msg_sizep = max_msgsize;
2597c478bd9Sstevel@tonic-gate mutex_exit(&cots_kcreate_lock);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate *nxprt = xprt;
263e810a982Svv149972
2647c478bd9Sstevel@tonic-gate return (0);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate /*
2687c478bd9Sstevel@tonic-gate * Destroy a master transport record.
2697c478bd9Sstevel@tonic-gate * Frees the space allocated for a transport record.
2707c478bd9Sstevel@tonic-gate */
2717c478bd9Sstevel@tonic-gate static void
svc_cots_kdestroy(SVCMASTERXPRT * xprt)2727c478bd9Sstevel@tonic-gate svc_cots_kdestroy(SVCMASTERXPRT *xprt)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate struct cots_master_data *cmd = (struct cots_master_data *)xprt->xp_p2;
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate ASSERT(cmd);
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate if (xprt->xp_netid)
2797c478bd9Sstevel@tonic-gate kmem_free(xprt->xp_netid, strlen(xprt->xp_netid) + 1);
2807c478bd9Sstevel@tonic-gate if (xprt->xp_addrmask.maxlen)
2817c478bd9Sstevel@tonic-gate kmem_free(xprt->xp_addrmask.buf, xprt->xp_addrmask.maxlen);
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate mutex_destroy(&xprt->xp_req_lock);
2847c478bd9Sstevel@tonic-gate mutex_destroy(&xprt->xp_thread_lock);
2857c478bd9Sstevel@tonic-gate
286e810a982Svv149972 kmem_free(cmd, sizeof (*cmd) + sizeof (struct T_addr_ack) +
287e810a982Svv149972 (2 * sizeof (sin6_t)));
288e810a982Svv149972
2897c478bd9Sstevel@tonic-gate kmem_free(xprt, sizeof (SVCMASTERXPRT));
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate /*
2937c478bd9Sstevel@tonic-gate * svc_tli_kcreate() calls this function at the end to tell
2947c478bd9Sstevel@tonic-gate * rpcmod that the transport is ready to receive requests.
2957c478bd9Sstevel@tonic-gate */
2967c478bd9Sstevel@tonic-gate static void
svc_cots_kstart(SVCMASTERXPRT * xprt)2977c478bd9Sstevel@tonic-gate svc_cots_kstart(SVCMASTERXPRT *xprt)
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate struct cots_master_data *cmd = (struct cots_master_data *)xprt->xp_p2;
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate if (cmd->cmd_xprt_started == 0) {
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate * Acquire the xp_req_lock in order to use xp_wq
3047c478bd9Sstevel@tonic-gate * safely (we don't want to qenable a queue that has
3057c478bd9Sstevel@tonic-gate * already been closed).
3067c478bd9Sstevel@tonic-gate */
3077c478bd9Sstevel@tonic-gate mutex_enter(&xprt->xp_req_lock);
3087c478bd9Sstevel@tonic-gate if (cmd->cmd_xprt_started == 0 &&
3097c478bd9Sstevel@tonic-gate xprt->xp_wq != NULL) {
3107c478bd9Sstevel@tonic-gate (*mir_start)(xprt->xp_wq);
3117c478bd9Sstevel@tonic-gate cmd->cmd_xprt_started = 1;
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate mutex_exit(&xprt->xp_req_lock);
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate /*
3187c478bd9Sstevel@tonic-gate * Transport-type specific part of svc_xprt_cleanup().
3197c478bd9Sstevel@tonic-gate */
3207c478bd9Sstevel@tonic-gate static void
svc_cots_kclone_destroy(SVCXPRT * clone_xprt)3217c478bd9Sstevel@tonic-gate svc_cots_kclone_destroy(SVCXPRT *clone_xprt)
3227c478bd9Sstevel@tonic-gate {
3237c478bd9Sstevel@tonic-gate cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate if (cd->cd_req_mp) {
3267c478bd9Sstevel@tonic-gate freemsg(cd->cd_req_mp);
3277c478bd9Sstevel@tonic-gate cd->cd_req_mp = (mblk_t *)0;
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate ASSERT(cd->cd_mp == NULL);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate /*
3330a4b0810SKaren Rochford * Transport Attributes.
3340a4b0810SKaren Rochford */
3350a4b0810SKaren Rochford static void
svc_cots_ktattrs(SVCXPRT * clone_xprt,int attrflag,void ** tattr)3360a4b0810SKaren Rochford svc_cots_ktattrs(SVCXPRT *clone_xprt, int attrflag, void **tattr)
3370a4b0810SKaren Rochford {
3380a4b0810SKaren Rochford *tattr = NULL;
3390a4b0810SKaren Rochford
3400a4b0810SKaren Rochford switch (attrflag) {
3410a4b0810SKaren Rochford case SVC_TATTR_ADDRMASK:
3420a4b0810SKaren Rochford *tattr = (void *)&clone_xprt->xp_master->xp_addrmask;
3430a4b0810SKaren Rochford }
3440a4b0810SKaren Rochford }
3450a4b0810SKaren Rochford
3460a4b0810SKaren Rochford /*
3477c478bd9Sstevel@tonic-gate * Receive rpc requests.
3487c478bd9Sstevel@tonic-gate * Checks if the message is intact, and deserializes the call packet.
3497c478bd9Sstevel@tonic-gate */
3507c478bd9Sstevel@tonic-gate static bool_t
svc_cots_krecv(SVCXPRT * clone_xprt,mblk_t * mp,struct rpc_msg * msg)3517c478bd9Sstevel@tonic-gate svc_cots_krecv(SVCXPRT *clone_xprt, mblk_t *mp, struct rpc_msg *msg)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
3547c478bd9Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrin;
3557c478bd9Sstevel@tonic-gate struct rpc_cots_server *stats = CLONE2STATS(clone_xprt);
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_SVC_COTS_KRECV_START,
3587c478bd9Sstevel@tonic-gate "svc_cots_krecv_start:");
3597c478bd9Sstevel@tonic-gate RPCLOG(4, "svc_cots_krecv_start clone_xprt = %p:\n",
3607c478bd9Sstevel@tonic-gate (void *)clone_xprt);
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rscalls);
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate if (mp->b_datap->db_type != M_DATA) {
3657c478bd9Sstevel@tonic-gate RPCLOG(16, "svc_cots_krecv bad db_type %d\n",
3667c478bd9Sstevel@tonic-gate mp->b_datap->db_type);
3677c478bd9Sstevel@tonic-gate goto bad;
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate xdrmblk_init(xdrs, mp, XDR_DECODE, 0);
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_XDR_CALLMSG_START,
3737c478bd9Sstevel@tonic-gate "xdr_callmsg_start:");
3747c478bd9Sstevel@tonic-gate RPCLOG0(4, "xdr_callmsg_start:\n");
3757c478bd9Sstevel@tonic-gate if (!xdr_callmsg(xdrs, msg)) {
376*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
3777c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
3787c478bd9Sstevel@tonic-gate "xdr_callmsg_end:(%S)", "bad");
3797c478bd9Sstevel@tonic-gate RPCLOG0(1, "svc_cots_krecv xdr_callmsg failure\n");
3807c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsxdrcall);
3817c478bd9Sstevel@tonic-gate goto bad;
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_CALLMSG_END,
3847c478bd9Sstevel@tonic-gate "xdr_callmsg_end:(%S)", "good");
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate clone_xprt->xp_xid = msg->rm_xid;
3877c478bd9Sstevel@tonic-gate cd->cd_req_mp = mp;
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KRECV_END,
3907c478bd9Sstevel@tonic-gate "svc_cots_krecv_end:(%S)", "good");
3917c478bd9Sstevel@tonic-gate RPCLOG0(4, "svc_cots_krecv_end:good\n");
3927c478bd9Sstevel@tonic-gate return (TRUE);
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate bad:
3957c478bd9Sstevel@tonic-gate if (mp)
3967c478bd9Sstevel@tonic-gate freemsg(mp);
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsbadcalls);
3997c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KRECV_END,
4007c478bd9Sstevel@tonic-gate "svc_cots_krecv_end:(%S)", "bad");
4017c478bd9Sstevel@tonic-gate return (FALSE);
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate /*
4057c478bd9Sstevel@tonic-gate * Send rpc reply.
4067c478bd9Sstevel@tonic-gate */
4077c478bd9Sstevel@tonic-gate static bool_t
svc_cots_ksend(SVCXPRT * clone_xprt,struct rpc_msg * msg)4087c478bd9Sstevel@tonic-gate svc_cots_ksend(SVCXPRT *clone_xprt, struct rpc_msg *msg)
4097c478bd9Sstevel@tonic-gate {
4107c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
4117c478bd9Sstevel@tonic-gate cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
4127c478bd9Sstevel@tonic-gate XDR *xdrs = &(clone_xprt->xp_xdrout);
4137c478bd9Sstevel@tonic-gate int retval = FALSE;
4147c478bd9Sstevel@tonic-gate mblk_t *mp;
4157c478bd9Sstevel@tonic-gate xdrproc_t xdr_results;
4167c478bd9Sstevel@tonic-gate caddr_t xdr_location;
4177c478bd9Sstevel@tonic-gate bool_t has_args;
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_SVC_COTS_KSEND_START,
4207c478bd9Sstevel@tonic-gate "svc_cots_ksend_start:");
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate /*
4237c478bd9Sstevel@tonic-gate * If there is a result procedure specified in the reply message,
4247c478bd9Sstevel@tonic-gate * it will be processed in the xdr_replymsg and SVCAUTH_WRAP.
4257c478bd9Sstevel@tonic-gate * We need to make sure it won't be processed twice, so we null
4267c478bd9Sstevel@tonic-gate * it for xdr_replymsg here.
4277c478bd9Sstevel@tonic-gate */
4287c478bd9Sstevel@tonic-gate has_args = FALSE;
4297c478bd9Sstevel@tonic-gate if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
4307c478bd9Sstevel@tonic-gate msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
4317c478bd9Sstevel@tonic-gate if ((xdr_results = msg->acpted_rply.ar_results.proc) != NULL) {
4327c478bd9Sstevel@tonic-gate has_args = TRUE;
4337c478bd9Sstevel@tonic-gate xdr_location = msg->acpted_rply.ar_results.where;
4347c478bd9Sstevel@tonic-gate msg->acpted_rply.ar_results.proc = xdr_void;
4357c478bd9Sstevel@tonic-gate msg->acpted_rply.ar_results.where = NULL;
4367c478bd9Sstevel@tonic-gate }
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate mp = cd->cd_mp;
4407c478bd9Sstevel@tonic-gate if (mp) {
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate * The program above pre-allocated an mblk and put
4437c478bd9Sstevel@tonic-gate * the data in place.
4447c478bd9Sstevel@tonic-gate */
4457c478bd9Sstevel@tonic-gate cd->cd_mp = (mblk_t *)NULL;
4467c478bd9Sstevel@tonic-gate if (!(xdr_replymsg_body(xdrs, msg) &&
4477c478bd9Sstevel@tonic-gate (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
4487c478bd9Sstevel@tonic-gate xdr_results, xdr_location)))) {
449*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
4507c478bd9Sstevel@tonic-gate RPCLOG0(1, "svc_cots_ksend: "
4517c478bd9Sstevel@tonic-gate "xdr_replymsg_body/SVCAUTH_WRAP failed\n");
4527c478bd9Sstevel@tonic-gate freemsg(mp);
4537c478bd9Sstevel@tonic-gate goto out;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate } else {
4567c478bd9Sstevel@tonic-gate int len;
4577c478bd9Sstevel@tonic-gate int mpsize;
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate /*
4607c478bd9Sstevel@tonic-gate * Leave space for protocol headers.
4617c478bd9Sstevel@tonic-gate */
4627c478bd9Sstevel@tonic-gate len = MSG_OFFSET + clone_xprt->xp_msg_size;
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate /*
4657c478bd9Sstevel@tonic-gate * Allocate an initial mblk for the response data.
4667c478bd9Sstevel@tonic-gate */
4677c478bd9Sstevel@tonic-gate while (!(mp = allocb(len, BPRI_LO))) {
4687c478bd9Sstevel@tonic-gate RPCLOG0(16, "svc_cots_ksend: allocb failed failed\n");
4697c478bd9Sstevel@tonic-gate if (strwaitbuf(len, BPRI_LO)) {
4707c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KSEND_END,
4717c478bd9Sstevel@tonic-gate "svc_cots_ksend_end:(%S)", "strwaitbuf");
4727c478bd9Sstevel@tonic-gate RPCLOG0(1,
4737c478bd9Sstevel@tonic-gate "svc_cots_ksend: strwaitbuf failed\n");
4747c478bd9Sstevel@tonic-gate goto out;
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate /*
479*cf98b944SMarcel Telka * Initialize the XDR encode stream. Additional mblks
4807c478bd9Sstevel@tonic-gate * will be allocated if necessary. They will be TIDU
4817c478bd9Sstevel@tonic-gate * sized.
4827c478bd9Sstevel@tonic-gate */
4837c478bd9Sstevel@tonic-gate xdrmblk_init(xdrs, mp, XDR_ENCODE, clone_xprt->xp_msg_size);
4847c478bd9Sstevel@tonic-gate mpsize = MBLKSIZE(mp);
4857c478bd9Sstevel@tonic-gate ASSERT(mpsize >= len);
4867c478bd9Sstevel@tonic-gate ASSERT(mp->b_rptr == mp->b_datap->db_base);
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate /*
4897c478bd9Sstevel@tonic-gate * If the size of mblk is not appreciably larger than what we
4907c478bd9Sstevel@tonic-gate * asked, then resize the mblk to exactly len bytes. Reason for
4917c478bd9Sstevel@tonic-gate * this: suppose len is 1600 bytes, the tidu is 1460 bytes
4927c478bd9Sstevel@tonic-gate * (from TCP over ethernet), and the arguments to RPC require
4937c478bd9Sstevel@tonic-gate * 2800 bytes. Ideally we want the protocol to render two
4947c478bd9Sstevel@tonic-gate * ~1400 byte segments over the wire. If allocb() gives us a 2k
4957c478bd9Sstevel@tonic-gate * mblk, and we allocate a second mblk for the rest, the
4967c478bd9Sstevel@tonic-gate * protocol module may generate 3 segments over the wire:
4977c478bd9Sstevel@tonic-gate * 1460 bytes for the first, 448 (2048 - 1600) for the 2nd, and
4987c478bd9Sstevel@tonic-gate * 892 for the 3rd. If we "waste" 448 bytes in the first mblk,
4997c478bd9Sstevel@tonic-gate * the XDR encoding will generate two ~1400 byte mblks, and the
5007c478bd9Sstevel@tonic-gate * protocol module is more likely to produce properly sized
5017c478bd9Sstevel@tonic-gate * segments.
5027c478bd9Sstevel@tonic-gate */
5037c478bd9Sstevel@tonic-gate if ((mpsize >> 1) <= len) {
5047c478bd9Sstevel@tonic-gate mp->b_rptr += (mpsize - len);
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate * Adjust b_rptr to reserve space for the non-data protocol
5097c478bd9Sstevel@tonic-gate * headers that any downstream modules might like to add, and
5107c478bd9Sstevel@tonic-gate * for the record marking header.
5117c478bd9Sstevel@tonic-gate */
5127c478bd9Sstevel@tonic-gate mp->b_rptr += (MSG_OFFSET + RM_HDR_SIZE);
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate XDR_SETPOS(xdrs, (uint_t)(mp->b_rptr - mp->b_datap->db_base));
5157c478bd9Sstevel@tonic-gate ASSERT(mp->b_wptr == mp->b_rptr);
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate msg->rm_xid = clone_xprt->xp_xid;
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_XDR_REPLYMSG_START,
5207c478bd9Sstevel@tonic-gate "xdr_replymsg_start:");
5217c478bd9Sstevel@tonic-gate if (!(xdr_replymsg(xdrs, msg) &&
5227c478bd9Sstevel@tonic-gate (!has_args || SVCAUTH_WRAP(&clone_xprt->xp_auth, xdrs,
5237c478bd9Sstevel@tonic-gate xdr_results, xdr_location)))) {
524*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
5257c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
5267c478bd9Sstevel@tonic-gate "xdr_replymsg_end:(%S)", "bad");
5277c478bd9Sstevel@tonic-gate freemsg(mp);
5287c478bd9Sstevel@tonic-gate RPCLOG0(1, "svc_cots_ksend: xdr_replymsg/SVCAUTH_WRAP "
5297c478bd9Sstevel@tonic-gate "failed\n");
5307c478bd9Sstevel@tonic-gate goto out;
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_XDR_REPLYMSG_END,
5337c478bd9Sstevel@tonic-gate "xdr_replymsg_end:(%S)", "good");
5347c478bd9Sstevel@tonic-gate }
5357c478bd9Sstevel@tonic-gate
536*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
537*cf98b944SMarcel Telka
5387c478bd9Sstevel@tonic-gate put(clone_xprt->xp_wq, mp);
5397c478bd9Sstevel@tonic-gate retval = TRUE;
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate out:
5427c478bd9Sstevel@tonic-gate /*
5437c478bd9Sstevel@tonic-gate * This is completely disgusting. If public is set it is
5447c478bd9Sstevel@tonic-gate * a pointer to a structure whose first field is the address
5457c478bd9Sstevel@tonic-gate * of the function to free that structure and any related
5467c478bd9Sstevel@tonic-gate * stuff. (see rrokfree in nfs_xdr.c).
5477c478bd9Sstevel@tonic-gate */
5487c478bd9Sstevel@tonic-gate if (xdrs->x_public) {
5497c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
5507c478bd9Sstevel@tonic-gate (**((int (**)())xdrs->x_public))(xdrs->x_public);
5517c478bd9Sstevel@tonic-gate }
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate TRACE_1(TR_FAC_KRPC, TR_SVC_COTS_KSEND_END,
5547c478bd9Sstevel@tonic-gate "svc_cots_ksend_end:(%S)", "done");
5557c478bd9Sstevel@tonic-gate return (retval);
5567c478bd9Sstevel@tonic-gate }
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate /*
5597c478bd9Sstevel@tonic-gate * Deserialize arguments.
5607c478bd9Sstevel@tonic-gate */
5617c478bd9Sstevel@tonic-gate static bool_t
svc_cots_kgetargs(SVCXPRT * clone_xprt,xdrproc_t xdr_args,caddr_t args_ptr)5627c478bd9Sstevel@tonic-gate svc_cots_kgetargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
5637c478bd9Sstevel@tonic-gate caddr_t args_ptr)
5647c478bd9Sstevel@tonic-gate {
5657c478bd9Sstevel@tonic-gate return (SVCAUTH_UNWRAP(&clone_xprt->xp_auth, &clone_xprt->xp_xdrin,
5667c478bd9Sstevel@tonic-gate xdr_args, args_ptr));
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate static bool_t
svc_cots_kfreeargs(SVCXPRT * clone_xprt,xdrproc_t xdr_args,caddr_t args_ptr)5707c478bd9Sstevel@tonic-gate svc_cots_kfreeargs(SVCXPRT *clone_xprt, xdrproc_t xdr_args,
5717c478bd9Sstevel@tonic-gate caddr_t args_ptr)
5727c478bd9Sstevel@tonic-gate {
5737c478bd9Sstevel@tonic-gate cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
574*cf98b944SMarcel Telka /* LINTED pointer alignment */
575*cf98b944SMarcel Telka XDR *xdrs = &clone_xprt->xp_xdrin;
5767c478bd9Sstevel@tonic-gate mblk_t *mp;
5777c478bd9Sstevel@tonic-gate bool_t retval;
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate /*
5807c478bd9Sstevel@tonic-gate * It is important to call the XDR routine before
5817c478bd9Sstevel@tonic-gate * freeing the request mblk. Structures in the
5827c478bd9Sstevel@tonic-gate * XDR data may point into the mblk and require that
5837c478bd9Sstevel@tonic-gate * the memory be intact during the free routine.
5847c478bd9Sstevel@tonic-gate */
5857c478bd9Sstevel@tonic-gate if (args_ptr) {
5867c478bd9Sstevel@tonic-gate xdrs->x_op = XDR_FREE;
5877c478bd9Sstevel@tonic-gate retval = (*xdr_args)(xdrs, args_ptr);
5887c478bd9Sstevel@tonic-gate } else
5897c478bd9Sstevel@tonic-gate retval = TRUE;
5907c478bd9Sstevel@tonic-gate
591*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
592*cf98b944SMarcel Telka
5937c478bd9Sstevel@tonic-gate if ((mp = cd->cd_req_mp) != NULL) {
5947c478bd9Sstevel@tonic-gate cd->cd_req_mp = (mblk_t *)0;
5957c478bd9Sstevel@tonic-gate freemsg(mp);
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate return (retval);
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate static int32_t *
svc_cots_kgetres(SVCXPRT * clone_xprt,int size)6027c478bd9Sstevel@tonic-gate svc_cots_kgetres(SVCXPRT *clone_xprt, int size)
6037c478bd9Sstevel@tonic-gate {
6047c478bd9Sstevel@tonic-gate /* LINTED pointer alignment */
6057c478bd9Sstevel@tonic-gate cots_data_t *cd = (cots_data_t *)clone_xprt->xp_p2buf;
6067c478bd9Sstevel@tonic-gate XDR *xdrs = &clone_xprt->xp_xdrout;
6077c478bd9Sstevel@tonic-gate mblk_t *mp;
6087c478bd9Sstevel@tonic-gate int32_t *buf;
6097c478bd9Sstevel@tonic-gate struct rpc_msg rply;
6107c478bd9Sstevel@tonic-gate int len;
6117c478bd9Sstevel@tonic-gate int mpsize;
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate * Leave space for protocol headers.
6157c478bd9Sstevel@tonic-gate */
6167c478bd9Sstevel@tonic-gate len = MSG_OFFSET + clone_xprt->xp_msg_size;
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate /*
6197c478bd9Sstevel@tonic-gate * Allocate an initial mblk for the response data.
6207c478bd9Sstevel@tonic-gate */
6217c478bd9Sstevel@tonic-gate while ((mp = allocb(len, BPRI_LO)) == NULL) {
6227c478bd9Sstevel@tonic-gate if (strwaitbuf(len, BPRI_LO))
623*cf98b944SMarcel Telka return (NULL);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate /*
627*cf98b944SMarcel Telka * Initialize the XDR encode stream. Additional mblks
6287c478bd9Sstevel@tonic-gate * will be allocated if necessary. They will be TIDU
6297c478bd9Sstevel@tonic-gate * sized.
6307c478bd9Sstevel@tonic-gate */
6317c478bd9Sstevel@tonic-gate xdrmblk_init(xdrs, mp, XDR_ENCODE, clone_xprt->xp_msg_size);
6327c478bd9Sstevel@tonic-gate mpsize = MBLKSIZE(mp);
6337c478bd9Sstevel@tonic-gate ASSERT(mpsize >= len);
6347c478bd9Sstevel@tonic-gate ASSERT(mp->b_rptr == mp->b_datap->db_base);
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate /*
6377c478bd9Sstevel@tonic-gate * If the size of mblk is not appreciably larger than what we
6387c478bd9Sstevel@tonic-gate * asked, then resize the mblk to exactly len bytes. Reason for
6397c478bd9Sstevel@tonic-gate * this: suppose len is 1600 bytes, the tidu is 1460 bytes
6407c478bd9Sstevel@tonic-gate * (from TCP over ethernet), and the arguments to RPC require
6417c478bd9Sstevel@tonic-gate * 2800 bytes. Ideally we want the protocol to render two
6427c478bd9Sstevel@tonic-gate * ~1400 byte segments over the wire. If allocb() gives us a 2k
6437c478bd9Sstevel@tonic-gate * mblk, and we allocate a second mblk for the rest, the
6447c478bd9Sstevel@tonic-gate * protocol module may generate 3 segments over the wire:
6457c478bd9Sstevel@tonic-gate * 1460 bytes for the first, 448 (2048 - 1600) for the 2nd, and
6467c478bd9Sstevel@tonic-gate * 892 for the 3rd. If we "waste" 448 bytes in the first mblk,
6477c478bd9Sstevel@tonic-gate * the XDR encoding will generate two ~1400 byte mblks, and the
6487c478bd9Sstevel@tonic-gate * protocol module is more likely to produce properly sized
6497c478bd9Sstevel@tonic-gate * segments.
6507c478bd9Sstevel@tonic-gate */
6517c478bd9Sstevel@tonic-gate if ((mpsize >> 1) <= len) {
6527c478bd9Sstevel@tonic-gate mp->b_rptr += (mpsize - len);
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate /*
6567c478bd9Sstevel@tonic-gate * Adjust b_rptr to reserve space for the non-data protocol
6577c478bd9Sstevel@tonic-gate * headers that any downstream modules might like to add, and
6587c478bd9Sstevel@tonic-gate * for the record marking header.
6597c478bd9Sstevel@tonic-gate */
6607c478bd9Sstevel@tonic-gate mp->b_rptr += (MSG_OFFSET + RM_HDR_SIZE);
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate XDR_SETPOS(xdrs, (uint_t)(mp->b_rptr - mp->b_datap->db_base));
6637c478bd9Sstevel@tonic-gate ASSERT(mp->b_wptr == mp->b_rptr);
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate /*
6667c478bd9Sstevel@tonic-gate * Assume a successful RPC since most of them are.
6677c478bd9Sstevel@tonic-gate */
6687c478bd9Sstevel@tonic-gate rply.rm_xid = clone_xprt->xp_xid;
6697c478bd9Sstevel@tonic-gate rply.rm_direction = REPLY;
6707c478bd9Sstevel@tonic-gate rply.rm_reply.rp_stat = MSG_ACCEPTED;
6717c478bd9Sstevel@tonic-gate rply.acpted_rply.ar_verf = clone_xprt->xp_verf;
6727c478bd9Sstevel@tonic-gate rply.acpted_rply.ar_stat = SUCCESS;
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate if (!xdr_replymsg_hdr(xdrs, &rply)) {
675*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
6767c478bd9Sstevel@tonic-gate freeb(mp);
6777c478bd9Sstevel@tonic-gate return (NULL);
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate
6807c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, size);
6817c478bd9Sstevel@tonic-gate if (buf == NULL) {
682*cf98b944SMarcel Telka XDR_DESTROY(xdrs);
6837c478bd9Sstevel@tonic-gate ASSERT(cd->cd_mp == NULL);
6847c478bd9Sstevel@tonic-gate freemsg(mp);
6857c478bd9Sstevel@tonic-gate } else {
6867c478bd9Sstevel@tonic-gate cd->cd_mp = mp;
6877c478bd9Sstevel@tonic-gate }
6887c478bd9Sstevel@tonic-gate return (buf);
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate static void
svc_cots_kfreeres(SVCXPRT * clone_xprt)6927c478bd9Sstevel@tonic-gate svc_cots_kfreeres(SVCXPRT *clone_xprt)
6937c478bd9Sstevel@tonic-gate {
6947c478bd9Sstevel@tonic-gate cots_data_t *cd;
6957c478bd9Sstevel@tonic-gate mblk_t *mp;
6967c478bd9Sstevel@tonic-gate
6977c478bd9Sstevel@tonic-gate cd = (cots_data_t *)clone_xprt->xp_p2buf;
6987c478bd9Sstevel@tonic-gate if ((mp = cd->cd_mp) != NULL) {
699*cf98b944SMarcel Telka XDR_DESTROY(&clone_xprt->xp_xdrout);
7007c478bd9Sstevel@tonic-gate cd->cd_mp = (mblk_t *)NULL;
7017c478bd9Sstevel@tonic-gate freemsg(mp);
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate /*
7067c478bd9Sstevel@tonic-gate * the dup cacheing routines below provide a cache of non-failure
7077c478bd9Sstevel@tonic-gate * transaction id's. rpc service routines can use this to detect
7087c478bd9Sstevel@tonic-gate * retransmissions and re-send a non-failure response.
7097c478bd9Sstevel@tonic-gate */
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate /*
7127c478bd9Sstevel@tonic-gate * MAXDUPREQS is the number of cached items. It should be adjusted
7137c478bd9Sstevel@tonic-gate * to the service load so that there is likely to be a response entry
7147c478bd9Sstevel@tonic-gate * when the first retransmission comes in.
7157c478bd9Sstevel@tonic-gate */
7167c478bd9Sstevel@tonic-gate #define MAXDUPREQS 1024
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate /*
7197c478bd9Sstevel@tonic-gate * This should be appropriately scaled to MAXDUPREQS.
7207c478bd9Sstevel@tonic-gate */
7217c478bd9Sstevel@tonic-gate #define DRHASHSZ 257
7227c478bd9Sstevel@tonic-gate
7237c478bd9Sstevel@tonic-gate #if ((DRHASHSZ & (DRHASHSZ - 1)) == 0)
7247c478bd9Sstevel@tonic-gate #define XIDHASH(xid) ((xid) & (DRHASHSZ - 1))
7257c478bd9Sstevel@tonic-gate #else
7267c478bd9Sstevel@tonic-gate #define XIDHASH(xid) ((xid) % DRHASHSZ)
7277c478bd9Sstevel@tonic-gate #endif
7287c478bd9Sstevel@tonic-gate #define DRHASH(dr) XIDHASH((dr)->dr_xid)
7297c478bd9Sstevel@tonic-gate #define REQTOXID(req) ((req)->rq_xprt->xp_xid)
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate static int cotsndupreqs = 0;
73259418bdeSgt29601@anthrax int cotsmaxdupreqs = MAXDUPREQS;
7337c478bd9Sstevel@tonic-gate static kmutex_t cotsdupreq_lock;
7347c478bd9Sstevel@tonic-gate static struct dupreq *cotsdrhashtbl[DRHASHSZ];
7357c478bd9Sstevel@tonic-gate static int cotsdrhashstat[DRHASHSZ];
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate static void unhash(struct dupreq *);
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate /*
7407c478bd9Sstevel@tonic-gate * cotsdrmru points to the head of a circular linked list in lru order.
7417c478bd9Sstevel@tonic-gate * cotsdrmru->dr_next == drlru
7427c478bd9Sstevel@tonic-gate */
7437c478bd9Sstevel@tonic-gate struct dupreq *cotsdrmru;
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate /*
7467c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface
7477c478bd9Sstevel@tonic-gate * svc_cots_kdup
7487c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing
7497c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com
7507c478bd9Sstevel@tonic-gate *
7517c478bd9Sstevel@tonic-gate * svc_cots_kdup searches the request cache and returns 0 if the
7527c478bd9Sstevel@tonic-gate * request is not found in the cache. If it is found, then it
7537c478bd9Sstevel@tonic-gate * returns the state of the request (in progress or done) and
7547c478bd9Sstevel@tonic-gate * the status or attributes that were part of the original reply.
7557c478bd9Sstevel@tonic-gate *
7567c478bd9Sstevel@tonic-gate * If DUP_DONE (there is a duplicate) svc_cots_kdup copies over the
7577c478bd9Sstevel@tonic-gate * value of the response. In that case, also return in *dupcachedp
7587c478bd9Sstevel@tonic-gate * whether the response free routine is cached in the dupreq - in which case
7597c478bd9Sstevel@tonic-gate * the caller should not be freeing it, because it will be done later
7607c478bd9Sstevel@tonic-gate * in the svc_cots_kdup code when the dupreq is reused.
7617c478bd9Sstevel@tonic-gate */
7627c478bd9Sstevel@tonic-gate static int
svc_cots_kdup(struct svc_req * req,caddr_t res,int size,struct dupreq ** drpp,bool_t * dupcachedp)7637c478bd9Sstevel@tonic-gate svc_cots_kdup(struct svc_req *req, caddr_t res, int size, struct dupreq **drpp,
7647c478bd9Sstevel@tonic-gate bool_t *dupcachedp)
7657c478bd9Sstevel@tonic-gate {
7667c478bd9Sstevel@tonic-gate struct rpc_cots_server *stats = CLONE2STATS(req->rq_xprt);
7677c478bd9Sstevel@tonic-gate struct dupreq *dr;
7687c478bd9Sstevel@tonic-gate uint32_t xid;
7697c478bd9Sstevel@tonic-gate uint32_t drhash;
7707c478bd9Sstevel@tonic-gate int status;
7717c478bd9Sstevel@tonic-gate
7727c478bd9Sstevel@tonic-gate xid = REQTOXID(req);
7737c478bd9Sstevel@tonic-gate mutex_enter(&cotsdupreq_lock);
7747c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsdupchecks);
7757c478bd9Sstevel@tonic-gate /*
7767c478bd9Sstevel@tonic-gate * Check to see whether an entry already exists in the cache.
7777c478bd9Sstevel@tonic-gate */
7787c478bd9Sstevel@tonic-gate dr = cotsdrhashtbl[XIDHASH(xid)];
7797c478bd9Sstevel@tonic-gate while (dr != NULL) {
7807c478bd9Sstevel@tonic-gate if (dr->dr_xid == xid &&
7817c478bd9Sstevel@tonic-gate dr->dr_proc == req->rq_proc &&
7827c478bd9Sstevel@tonic-gate dr->dr_prog == req->rq_prog &&
7837c478bd9Sstevel@tonic-gate dr->dr_vers == req->rq_vers &&
7847c478bd9Sstevel@tonic-gate dr->dr_addr.len == req->rq_xprt->xp_rtaddr.len &&
7857c478bd9Sstevel@tonic-gate bcmp((caddr_t)dr->dr_addr.buf,
7867c478bd9Sstevel@tonic-gate (caddr_t)req->rq_xprt->xp_rtaddr.buf,
7877c478bd9Sstevel@tonic-gate dr->dr_addr.len) == 0) {
7887c478bd9Sstevel@tonic-gate status = dr->dr_status;
7897c478bd9Sstevel@tonic-gate if (status == DUP_DONE) {
7907c478bd9Sstevel@tonic-gate bcopy(dr->dr_resp.buf, res, size);
7917c478bd9Sstevel@tonic-gate if (dupcachedp != NULL)
7927c478bd9Sstevel@tonic-gate *dupcachedp = (dr->dr_resfree != NULL);
7937c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC, TR_SVC_COTS_KDUP_DONE,
7947c478bd9Sstevel@tonic-gate "svc_cots_kdup: DUP_DONE");
7957c478bd9Sstevel@tonic-gate } else {
7967c478bd9Sstevel@tonic-gate dr->dr_status = DUP_INPROGRESS;
7977c478bd9Sstevel@tonic-gate *drpp = dr;
7987c478bd9Sstevel@tonic-gate TRACE_0(TR_FAC_KRPC,
7997c478bd9Sstevel@tonic-gate TR_SVC_COTS_KDUP_INPROGRESS,
8007c478bd9Sstevel@tonic-gate "svc_cots_kdup: DUP_INPROGRESS");
8017c478bd9Sstevel@tonic-gate }
8027c478bd9Sstevel@tonic-gate RSSTAT_INCR(stats, rsdupreqs);
8037c478bd9Sstevel@tonic-gate mutex_exit(&cotsdupreq_lock);
8047c478bd9Sstevel@tonic-gate return (status);
8057c478bd9Sstevel@tonic-gate }
8067c478bd9Sstevel@tonic-gate dr = dr->dr_chain;
8077c478bd9Sstevel@tonic-gate }
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate /*
8107c478bd9Sstevel@tonic-gate * There wasn't an entry, either allocate a new one or recycle
8117c478bd9Sstevel@tonic-gate * an old one.
8127c478bd9Sstevel@tonic-gate */
8137c478bd9Sstevel@tonic-gate if (cotsndupreqs < cotsmaxdupreqs) {
8147c478bd9Sstevel@tonic-gate dr = kmem_alloc(sizeof (*dr), KM_NOSLEEP);
8157c478bd9Sstevel@tonic-gate if (dr == NULL) {
8167c478bd9Sstevel@tonic-gate mutex_exit(&cotsdupreq_lock);
8177c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8187c478bd9Sstevel@tonic-gate }
8197c478bd9Sstevel@tonic-gate dr->dr_resp.buf = NULL;
8207c478bd9Sstevel@tonic-gate dr->dr_resp.maxlen = 0;
8217c478bd9Sstevel@tonic-gate dr->dr_addr.buf = NULL;
8227c478bd9Sstevel@tonic-gate dr->dr_addr.maxlen = 0;
8237c478bd9Sstevel@tonic-gate if (cotsdrmru) {
8247c478bd9Sstevel@tonic-gate dr->dr_next = cotsdrmru->dr_next;
8257c478bd9Sstevel@tonic-gate cotsdrmru->dr_next = dr;
8267c478bd9Sstevel@tonic-gate } else {
8277c478bd9Sstevel@tonic-gate dr->dr_next = dr;
8287c478bd9Sstevel@tonic-gate }
8297c478bd9Sstevel@tonic-gate cotsndupreqs++;
8307c478bd9Sstevel@tonic-gate } else {
8317c478bd9Sstevel@tonic-gate dr = cotsdrmru->dr_next;
8327c478bd9Sstevel@tonic-gate while (dr->dr_status == DUP_INPROGRESS) {
8337c478bd9Sstevel@tonic-gate dr = dr->dr_next;
8347c478bd9Sstevel@tonic-gate if (dr == cotsdrmru->dr_next) {
8357c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "svc_cots_kdup no slots free");
8367c478bd9Sstevel@tonic-gate mutex_exit(&cotsdupreq_lock);
8377c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8387c478bd9Sstevel@tonic-gate }
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate unhash(dr);
8417c478bd9Sstevel@tonic-gate if (dr->dr_resfree) {
8427c478bd9Sstevel@tonic-gate (*dr->dr_resfree)(dr->dr_resp.buf);
8437c478bd9Sstevel@tonic-gate }
8447c478bd9Sstevel@tonic-gate }
8457c478bd9Sstevel@tonic-gate dr->dr_resfree = NULL;
8467c478bd9Sstevel@tonic-gate cotsdrmru = dr;
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate dr->dr_xid = REQTOXID(req);
8497c478bd9Sstevel@tonic-gate dr->dr_prog = req->rq_prog;
8507c478bd9Sstevel@tonic-gate dr->dr_vers = req->rq_vers;
8517c478bd9Sstevel@tonic-gate dr->dr_proc = req->rq_proc;
8527c478bd9Sstevel@tonic-gate if (dr->dr_addr.maxlen < req->rq_xprt->xp_rtaddr.len) {
8537c478bd9Sstevel@tonic-gate if (dr->dr_addr.buf != NULL)
8547c478bd9Sstevel@tonic-gate kmem_free(dr->dr_addr.buf, dr->dr_addr.maxlen);
8557c478bd9Sstevel@tonic-gate dr->dr_addr.maxlen = req->rq_xprt->xp_rtaddr.len;
8567c478bd9Sstevel@tonic-gate dr->dr_addr.buf = kmem_alloc(dr->dr_addr.maxlen, KM_NOSLEEP);
8577c478bd9Sstevel@tonic-gate if (dr->dr_addr.buf == NULL) {
8587c478bd9Sstevel@tonic-gate dr->dr_addr.maxlen = 0;
8597c478bd9Sstevel@tonic-gate dr->dr_status = DUP_DROP;
8607c478bd9Sstevel@tonic-gate mutex_exit(&cotsdupreq_lock);
8617c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8627c478bd9Sstevel@tonic-gate }
8637c478bd9Sstevel@tonic-gate }
8647c478bd9Sstevel@tonic-gate dr->dr_addr.len = req->rq_xprt->xp_rtaddr.len;
8657c478bd9Sstevel@tonic-gate bcopy(req->rq_xprt->xp_rtaddr.buf, dr->dr_addr.buf, dr->dr_addr.len);
8667c478bd9Sstevel@tonic-gate if (dr->dr_resp.maxlen < size) {
8677c478bd9Sstevel@tonic-gate if (dr->dr_resp.buf != NULL)
8687c478bd9Sstevel@tonic-gate kmem_free(dr->dr_resp.buf, dr->dr_resp.maxlen);
8697c478bd9Sstevel@tonic-gate dr->dr_resp.maxlen = (unsigned int)size;
8707c478bd9Sstevel@tonic-gate dr->dr_resp.buf = kmem_alloc(size, KM_NOSLEEP);
8717c478bd9Sstevel@tonic-gate if (dr->dr_resp.buf == NULL) {
8727c478bd9Sstevel@tonic-gate dr->dr_resp.maxlen = 0;
8737c478bd9Sstevel@tonic-gate dr->dr_status = DUP_DROP;
8747c478bd9Sstevel@tonic-gate mutex_exit(&cotsdupreq_lock);
8757c478bd9Sstevel@tonic-gate return (DUP_ERROR);
8767c478bd9Sstevel@tonic-gate }
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate dr->dr_status = DUP_INPROGRESS;
8797c478bd9Sstevel@tonic-gate
8807c478bd9Sstevel@tonic-gate drhash = (uint32_t)DRHASH(dr);
8817c478bd9Sstevel@tonic-gate dr->dr_chain = cotsdrhashtbl[drhash];
8827c478bd9Sstevel@tonic-gate cotsdrhashtbl[drhash] = dr;
8837c478bd9Sstevel@tonic-gate cotsdrhashstat[drhash]++;
8847c478bd9Sstevel@tonic-gate mutex_exit(&cotsdupreq_lock);
8857c478bd9Sstevel@tonic-gate *drpp = dr;
8867c478bd9Sstevel@tonic-gate return (DUP_NEW);
8877c478bd9Sstevel@tonic-gate }
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate /*
8907c478bd9Sstevel@tonic-gate * PSARC 2003/523 Contract Private Interface
8917c478bd9Sstevel@tonic-gate * svc_cots_kdupdone
8927c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing
8937c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2003-523@sun.com
8947c478bd9Sstevel@tonic-gate *
8957c478bd9Sstevel@tonic-gate * svc_cots_kdupdone marks the request done (DUP_DONE or DUP_DROP)
8967c478bd9Sstevel@tonic-gate * and stores the response.
8977c478bd9Sstevel@tonic-gate */
8987c478bd9Sstevel@tonic-gate static void
svc_cots_kdupdone(struct dupreq * dr,caddr_t res,void (* dis_resfree)(),int size,int status)8997c478bd9Sstevel@tonic-gate svc_cots_kdupdone(struct dupreq *dr, caddr_t res, void (*dis_resfree)(),
9007c478bd9Sstevel@tonic-gate int size, int status)
9017c478bd9Sstevel@tonic-gate {
9027c478bd9Sstevel@tonic-gate ASSERT(dr->dr_resfree == NULL);
9037c478bd9Sstevel@tonic-gate if (status == DUP_DONE) {
9047c478bd9Sstevel@tonic-gate bcopy(res, dr->dr_resp.buf, size);
9057c478bd9Sstevel@tonic-gate dr->dr_resfree = dis_resfree;
9067c478bd9Sstevel@tonic-gate }
9077c478bd9Sstevel@tonic-gate dr->dr_status = status;
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate
9107c478bd9Sstevel@tonic-gate /*
9117c478bd9Sstevel@tonic-gate * This routine expects that the mutex, cotsdupreq_lock, is already held.
9127c478bd9Sstevel@tonic-gate */
9137c478bd9Sstevel@tonic-gate static void
unhash(struct dupreq * dr)9147c478bd9Sstevel@tonic-gate unhash(struct dupreq *dr)
9157c478bd9Sstevel@tonic-gate {
9167c478bd9Sstevel@tonic-gate struct dupreq *drt;
9177c478bd9Sstevel@tonic-gate struct dupreq *drtprev = NULL;
9187c478bd9Sstevel@tonic-gate uint32_t drhash;
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cotsdupreq_lock));
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate drhash = (uint32_t)DRHASH(dr);
9237c478bd9Sstevel@tonic-gate drt = cotsdrhashtbl[drhash];
9247c478bd9Sstevel@tonic-gate while (drt != NULL) {
9257c478bd9Sstevel@tonic-gate if (drt == dr) {
9267c478bd9Sstevel@tonic-gate cotsdrhashstat[drhash]--;
9277c478bd9Sstevel@tonic-gate if (drtprev == NULL) {
9287c478bd9Sstevel@tonic-gate cotsdrhashtbl[drhash] = drt->dr_chain;
9297c478bd9Sstevel@tonic-gate } else {
9307c478bd9Sstevel@tonic-gate drtprev->dr_chain = drt->dr_chain;
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate return;
9337c478bd9Sstevel@tonic-gate }
9347c478bd9Sstevel@tonic-gate drtprev = drt;
9357c478bd9Sstevel@tonic-gate drt = drt->dr_chain;
9367c478bd9Sstevel@tonic-gate }
9377c478bd9Sstevel@tonic-gate }
9387c478bd9Sstevel@tonic-gate
9397c478bd9Sstevel@tonic-gate void
svc_cots_stats_init(zoneid_t zoneid,struct rpc_cots_server ** statsp)9407c478bd9Sstevel@tonic-gate svc_cots_stats_init(zoneid_t zoneid, struct rpc_cots_server **statsp)
9417c478bd9Sstevel@tonic-gate {
9427c478bd9Sstevel@tonic-gate *statsp = (struct rpc_cots_server *)rpcstat_zone_init_common(zoneid,
9437c478bd9Sstevel@tonic-gate "unix", "rpc_cots_server", (const kstat_named_t *)&cots_rsstat_tmpl,
9447c478bd9Sstevel@tonic-gate sizeof (cots_rsstat_tmpl));
9457c478bd9Sstevel@tonic-gate }
9467c478bd9Sstevel@tonic-gate
9477c478bd9Sstevel@tonic-gate void
svc_cots_stats_fini(zoneid_t zoneid,struct rpc_cots_server ** statsp)9487c478bd9Sstevel@tonic-gate svc_cots_stats_fini(zoneid_t zoneid, struct rpc_cots_server **statsp)
9497c478bd9Sstevel@tonic-gate {
9507c478bd9Sstevel@tonic-gate rpcstat_zone_fini_common(zoneid, "unix", "rpc_cots_server");
9517c478bd9Sstevel@tonic-gate kmem_free(*statsp, sizeof (cots_rsstat_tmpl));
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate void
svc_cots_init(void)9557c478bd9Sstevel@tonic-gate svc_cots_init(void)
9567c478bd9Sstevel@tonic-gate {
9577c478bd9Sstevel@tonic-gate /*
9587c478bd9Sstevel@tonic-gate * Check to make sure that the cots private data will fit into
9597c478bd9Sstevel@tonic-gate * the stack buffer allocated by svc_run. The ASSERT is a safety
9607c478bd9Sstevel@tonic-gate * net if the cots_data_t structure ever changes.
9617c478bd9Sstevel@tonic-gate */
9627c478bd9Sstevel@tonic-gate /*CONSTANTCONDITION*/
9637c478bd9Sstevel@tonic-gate ASSERT(sizeof (cots_data_t) <= SVC_P2LEN);
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gate mutex_init(&cots_kcreate_lock, NULL, MUTEX_DEFAULT, NULL);
9667c478bd9Sstevel@tonic-gate mutex_init(&cotsdupreq_lock, NULL, MUTEX_DEFAULT, NULL);
9677c478bd9Sstevel@tonic-gate }
968