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 5d624471bSelowe * Common Development and Distribution License (the "License"). 6d624471bSelowe * 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 */ 217c478bd9Sstevel@tonic-gate /* 22*8ffff9fdSgt29601 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * Define and initialize MT client/server data. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 387c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 397c478bd9Sstevel@tonic-gate #include <sys/systm.h> 407c478bd9Sstevel@tonic-gate #include <sys/zone.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <rpc/types.h> 437c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 447c478bd9Sstevel@tonic-gate #include <rpc/clnt.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate kmutex_t xid_lock; /* XID allocation */ 477c478bd9Sstevel@tonic-gate kmutex_t clnt_pending_lock; /* for list of pending calls awaiting replies */ 487c478bd9Sstevel@tonic-gate kmutex_t clnt_max_msg_lock; /* updating max message sanity check for cots */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate zone_key_t rpcstat_zone_key; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * rpcstat_zone_[init|fini]_common() ends up being nearly identical to 547c478bd9Sstevel@tonic-gate * nfsstat_zone_[init|fini]_common(). Due to them necessarily being in 557c478bd9Sstevel@tonic-gate * different modules, however, we end up needing to duplicate the code. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate kstat_named_t * 587c478bd9Sstevel@tonic-gate rpcstat_zone_init_common(zoneid_t zoneid, const char *module, const char *name, 597c478bd9Sstevel@tonic-gate const kstat_named_t *template, size_t template_size) 607c478bd9Sstevel@tonic-gate { 617c478bd9Sstevel@tonic-gate kstat_t *ksp; 627c478bd9Sstevel@tonic-gate kstat_named_t *ks_data; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * PSARC 2001/697 Contract Private Interface 677c478bd9Sstevel@tonic-gate * rpc_clts_client 687c478bd9Sstevel@tonic-gate * rpc_cots_client 697c478bd9Sstevel@tonic-gate * Changes must be reviewed by Solaris File Sharing 707c478bd9Sstevel@tonic-gate * Changes must be communicated to contract-2001-697@sun.com 717c478bd9Sstevel@tonic-gate * 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate ks_data = kmem_alloc(template_size, KM_SLEEP); 747c478bd9Sstevel@tonic-gate bcopy(template, ks_data, template_size); 75d624471bSelowe if ((ksp = kstat_create_zone(module, 0, name, "rpc", 767c478bd9Sstevel@tonic-gate KSTAT_TYPE_NAMED, template_size / sizeof (kstat_named_t), 777c478bd9Sstevel@tonic-gate KSTAT_FLAG_VIRTUAL | KSTAT_FLAG_WRITABLE, zoneid)) != NULL) { 787c478bd9Sstevel@tonic-gate ksp->ks_data = ks_data; 797c478bd9Sstevel@tonic-gate kstat_install(ksp); 807c478bd9Sstevel@tonic-gate } 817c478bd9Sstevel@tonic-gate return (ks_data); 827c478bd9Sstevel@tonic-gate } 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate void 857c478bd9Sstevel@tonic-gate rpcstat_zone_fini_common(zoneid_t zoneid, const char *module, const char *name) 867c478bd9Sstevel@tonic-gate { 87d624471bSelowe kstat_delete_byname_zone(module, 0, name, zoneid); 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate static void * 917c478bd9Sstevel@tonic-gate mt_kstat_zone_init(zoneid_t zoneid) 927c478bd9Sstevel@tonic-gate { 937c478bd9Sstevel@tonic-gate struct rpcstat *rpcstat; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate rpcstat = kmem_alloc(sizeof (*rpcstat), KM_SLEEP); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate clnt_clts_stats_init(zoneid, &rpcstat->rpc_clts_client); 987c478bd9Sstevel@tonic-gate svc_clts_stats_init(zoneid, &rpcstat->rpc_clts_server); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate clnt_cots_stats_init(zoneid, &rpcstat->rpc_cots_client); 1017c478bd9Sstevel@tonic-gate svc_cots_stats_init(zoneid, &rpcstat->rpc_cots_server); 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate return (rpcstat); 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Deletes the previously allocated "rpc" kstats 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate static void 1107c478bd9Sstevel@tonic-gate mt_kstat_zone_fini(zoneid_t zoneid, void *data) 1117c478bd9Sstevel@tonic-gate { 1127c478bd9Sstevel@tonic-gate struct rpcstat *rpcstat = data; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate clnt_cots_stats_fini(zoneid, &rpcstat->rpc_cots_client); 1157c478bd9Sstevel@tonic-gate svc_cots_stats_fini(zoneid, &rpcstat->rpc_cots_server); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate clnt_clts_stats_fini(zoneid, &rpcstat->rpc_clts_client); 1187c478bd9Sstevel@tonic-gate svc_clts_stats_fini(zoneid, &rpcstat->rpc_clts_server); 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate kmem_free(rpcstat, sizeof (*rpcstat)); 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate void 1247c478bd9Sstevel@tonic-gate mt_kstat_init(void) 1257c478bd9Sstevel@tonic-gate { 1267c478bd9Sstevel@tonic-gate zone_key_create(&rpcstat_zone_key, mt_kstat_zone_init, NULL, 1277c478bd9Sstevel@tonic-gate mt_kstat_zone_fini); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate void 1317c478bd9Sstevel@tonic-gate mt_kstat_fini(void) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate (void) zone_key_delete(rpcstat_zone_key); 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate static bool_t clnt_xid_initialized = FALSE; 1377c478bd9Sstevel@tonic-gate static uint32_t clnt_xid = 0; /* transaction id used by all clients */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate uint32_t 1407c478bd9Sstevel@tonic-gate alloc_xid(void) 1417c478bd9Sstevel@tonic-gate { 1427c478bd9Sstevel@tonic-gate uint32_t xid; 1437c478bd9Sstevel@tonic-gate timestruc_t now; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * Do a one time initialzation to better utilize the number 1477c478bd9Sstevel@tonic-gate * space. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate mutex_enter(&xid_lock); 1507c478bd9Sstevel@tonic-gate if (clnt_xid_initialized == FALSE) { 1517c478bd9Sstevel@tonic-gate clnt_xid_initialized = TRUE; 1527c478bd9Sstevel@tonic-gate gethrestime(&now); 1537c478bd9Sstevel@tonic-gate clnt_xid = (uint32_t)((now.tv_sec << 20) | 1547c478bd9Sstevel@tonic-gate (now.tv_nsec >> 10)); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate xid = clnt_xid++; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * Don't return a zero xid. This could happen if the initialization 1617c478bd9Sstevel@tonic-gate * happens to return zero or if clnt_xid wraps. 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate if (xid == 0) 1647c478bd9Sstevel@tonic-gate xid = clnt_xid++; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate mutex_exit(&xid_lock); 1677c478bd9Sstevel@tonic-gate return (xid); 1687c478bd9Sstevel@tonic-gate } 169108322fbScarlsonj 170108322fbScarlsonj /* 171108322fbScarlsonj * These functions are temporary and designed for the upgrade-workaround only. 172108322fbScarlsonj * They cannot be used for general zone-crossing RPC client support, and will 173108322fbScarlsonj * be removed shortly. 174*8ffff9fdSgt29601 * 175*8ffff9fdSgt29601 * Currently these functions route all nfs global clients to the global zone. 176*8ffff9fdSgt29601 * When this upgrade-workaround is removed these function should return the 177*8ffff9fdSgt29601 * correct zone or their calls should be changed (rpc_zone() to curproc->p_zone 178*8ffff9fdSgt29601 * and rpc_zoneid() to getzoneid()). 179108322fbScarlsonj */ 180108322fbScarlsonj struct zone * 181108322fbScarlsonj rpc_zone(void) 182108322fbScarlsonj { 183108322fbScarlsonj return (nfs_global_client_only != 0 ? global_zone : curproc->p_zone); 184108322fbScarlsonj } 185108322fbScarlsonj 186108322fbScarlsonj zoneid_t 187108322fbScarlsonj rpc_zoneid(void) 188108322fbScarlsonj { 189108322fbScarlsonj return (nfs_global_client_only != 0 ? GLOBAL_ZONEID : getzoneid()); 190108322fbScarlsonj } 191