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 527e6fb21Sdp * Common Development and Distribution License (the "License"). 627e6fb21Sdp * 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 /* 2227e6fb21Sdp * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Zone Console Driver. 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * This driver, derived from the pts/ptm drivers, is the pseudo console driver 327c478bd9Sstevel@tonic-gate * for system zones. Its implementation is straightforward. Each instance 337c478bd9Sstevel@tonic-gate * of the driver represents a global-zone/local-zone pair (this maps in a 347c478bd9Sstevel@tonic-gate * straightforward way to the commonly used terminal notion of "master side" 357c478bd9Sstevel@tonic-gate * and "slave side", and we use that terminology throughout). 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * Instances of zcons are onlined as children of /pseudo/zconsnex@1/ 387c478bd9Sstevel@tonic-gate * by zoneadmd in userland, using the devctl framework; thus the driver 397c478bd9Sstevel@tonic-gate * does not need to maintain any sort of "admin" node. 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * The driver shuttles I/O from master side to slave side and back. In a break 427c478bd9Sstevel@tonic-gate * from the pts/ptm semantics, if one side is not open, I/O directed towards 437c478bd9Sstevel@tonic-gate * it will simply be discarded. This is so that if zoneadmd is not holding 447c478bd9Sstevel@tonic-gate * the master side console open (i.e. it has died somehow), processes in 457c478bd9Sstevel@tonic-gate * the zone do not experience any errors and I/O to the console does not 467c478bd9Sstevel@tonic-gate * hang. 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * TODO: we may want to revisit the other direction; i.e. we may want 497c478bd9Sstevel@tonic-gate * zoneadmd to be able to detect whether no zone processes are holding the 507c478bd9Sstevel@tonic-gate * console open, an unusual situation. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #include <sys/types.h> 547c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 557c478bd9Sstevel@tonic-gate #include <sys/conf.h> 567c478bd9Sstevel@tonic-gate #include <sys/cred.h> 577c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 587c478bd9Sstevel@tonic-gate #include <sys/debug.h> 597c478bd9Sstevel@tonic-gate #include <sys/devops.h> 607c478bd9Sstevel@tonic-gate #include <sys/errno.h> 617c478bd9Sstevel@tonic-gate #include <sys/file.h> 627c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 637c478bd9Sstevel@tonic-gate #include <sys/param.h> 647c478bd9Sstevel@tonic-gate #include <sys/stat.h> 657c478bd9Sstevel@tonic-gate #include <sys/stream.h> 667c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 677c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 687c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 697c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 707c478bd9Sstevel@tonic-gate #include <sys/systm.h> 717c478bd9Sstevel@tonic-gate #include <sys/types.h> 727c478bd9Sstevel@tonic-gate #include <sys/zcons.h> 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate static int zc_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 757c478bd9Sstevel@tonic-gate static int zc_attach(dev_info_t *, ddi_attach_cmd_t); 767c478bd9Sstevel@tonic-gate static int zc_detach(dev_info_t *, ddi_detach_cmd_t); 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate static int zc_open(queue_t *, dev_t *, int, int, cred_t *); 797c478bd9Sstevel@tonic-gate static int zc_close(queue_t *, int, cred_t *); 807c478bd9Sstevel@tonic-gate static void zc_wput(queue_t *, mblk_t *); 817c478bd9Sstevel@tonic-gate static void zc_rsrv(queue_t *); 827c478bd9Sstevel@tonic-gate static void zc_wsrv(queue_t *); 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * The instance number is encoded in the dev_t in the minor number; the lowest 867c478bd9Sstevel@tonic-gate * bit of the minor number is used to track the master vs. slave side of the 877c478bd9Sstevel@tonic-gate * virtual console. The rest of the bits in the minor number are the instance. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate #define ZC_MASTER_MINOR 0 907c478bd9Sstevel@tonic-gate #define ZC_SLAVE_MINOR 1 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define ZC_INSTANCE(x) (getminor((x)) >> 1) 937c478bd9Sstevel@tonic-gate #define ZC_NODE(x) (getminor((x)) & 0x01) 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate int zcons_debug = 0; 967c478bd9Sstevel@tonic-gate #define DBG(a) if (zcons_debug) cmn_err(CE_NOTE, a) 977c478bd9Sstevel@tonic-gate #define DBG1(a, b) if (zcons_debug) cmn_err(CE_NOTE, a, b) 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * Zone Console Pseudo Terminal Module: stream data structure definitions 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate static struct module_info zc_info = { 1047c478bd9Sstevel@tonic-gate 31337, /* c0z we r hAx0rs */ 1057c478bd9Sstevel@tonic-gate "zcons", 1067c478bd9Sstevel@tonic-gate 0, 1077c478bd9Sstevel@tonic-gate INFPSZ, 1087c478bd9Sstevel@tonic-gate 2048, 1097c478bd9Sstevel@tonic-gate 128 1107c478bd9Sstevel@tonic-gate }; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate static struct qinit zc_rinit = { 1137c478bd9Sstevel@tonic-gate NULL, 1147c478bd9Sstevel@tonic-gate (int (*)()) zc_rsrv, 1157c478bd9Sstevel@tonic-gate zc_open, 1167c478bd9Sstevel@tonic-gate zc_close, 1177c478bd9Sstevel@tonic-gate NULL, 1187c478bd9Sstevel@tonic-gate &zc_info, 1197c478bd9Sstevel@tonic-gate NULL 1207c478bd9Sstevel@tonic-gate }; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate static struct qinit zc_winit = { 1237c478bd9Sstevel@tonic-gate (int (*)()) zc_wput, 1247c478bd9Sstevel@tonic-gate (int (*)()) zc_wsrv, 1257c478bd9Sstevel@tonic-gate NULL, 1267c478bd9Sstevel@tonic-gate NULL, 1277c478bd9Sstevel@tonic-gate NULL, 1287c478bd9Sstevel@tonic-gate &zc_info, 1297c478bd9Sstevel@tonic-gate NULL 1307c478bd9Sstevel@tonic-gate }; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate static struct streamtab zc_tab_info = { 1337c478bd9Sstevel@tonic-gate &zc_rinit, 1347c478bd9Sstevel@tonic-gate &zc_winit, 1357c478bd9Sstevel@tonic-gate NULL, 1367c478bd9Sstevel@tonic-gate NULL 1377c478bd9Sstevel@tonic-gate }; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate #define ZC_CONF_FLAG (D_MP | D_MTQPAIR | D_MTOUTPERIM | D_MTOCEXCL) 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * this will define (struct cb_ops cb_zc_ops) and (struct dev_ops zc_ops) 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(zc_ops, nulldev, nulldev, zc_attach, zc_detach, nodev, \ 1457c478bd9Sstevel@tonic-gate zc_getinfo, ZC_CONF_FLAG, &zc_tab_info); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 1497c478bd9Sstevel@tonic-gate */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 152*c6f42f0eSedp &mod_driverops, /* Type of module (this is a pseudo driver) */ 153*c6f42f0eSedp "Zone console driver", /* description of module */ 1547c478bd9Sstevel@tonic-gate &zc_ops /* driver ops */ 1557c478bd9Sstevel@tonic-gate }; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1587c478bd9Sstevel@tonic-gate MODREV_1, 1597c478bd9Sstevel@tonic-gate &modldrv, 1607c478bd9Sstevel@tonic-gate NULL 1617c478bd9Sstevel@tonic-gate }; 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate typedef struct zc_state { 1647c478bd9Sstevel@tonic-gate dev_info_t *zc_devinfo; 1657c478bd9Sstevel@tonic-gate queue_t *zc_master_rdq; 1667c478bd9Sstevel@tonic-gate queue_t *zc_slave_rdq; 1677c478bd9Sstevel@tonic-gate int zc_state; 1687c478bd9Sstevel@tonic-gate } zc_state_t; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #define ZC_STATE_MOPEN 0x01 1717c478bd9Sstevel@tonic-gate #define ZC_STATE_SOPEN 0x02 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate static void *zc_soft_state; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate int 1767c478bd9Sstevel@tonic-gate _init(void) 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate int err; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate if ((err = ddi_soft_state_init(&zc_soft_state, 1817c478bd9Sstevel@tonic-gate sizeof (zc_state_t), 0)) != 0) { 1827c478bd9Sstevel@tonic-gate return (err); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if ((err = mod_install(&modlinkage)) != 0) 1867c478bd9Sstevel@tonic-gate ddi_soft_state_fini(zc_soft_state); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate return (err); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate int 1937c478bd9Sstevel@tonic-gate _fini(void) 1947c478bd9Sstevel@tonic-gate { 1957c478bd9Sstevel@tonic-gate int err; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate if ((err = mod_remove(&modlinkage)) != 0) { 1987c478bd9Sstevel@tonic-gate return (err); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&zc_soft_state); 2027c478bd9Sstevel@tonic-gate return (0); 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate int 2067c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 2077c478bd9Sstevel@tonic-gate { 2087c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate static int 2127c478bd9Sstevel@tonic-gate zc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2137c478bd9Sstevel@tonic-gate { 2147c478bd9Sstevel@tonic-gate zc_state_t *zcs; 2157c478bd9Sstevel@tonic-gate int instance; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate if (cmd != DDI_ATTACH) 2187c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 2217c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(zc_soft_state, instance) != DDI_SUCCESS) 2227c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate if ((ddi_create_minor_node(dip, ZCONS_SLAVE_NAME, S_IFCHR, 2257c478bd9Sstevel@tonic-gate instance << 1 | ZC_SLAVE_MINOR, DDI_PSEUDO, 0) == DDI_FAILURE) || 2267c478bd9Sstevel@tonic-gate (ddi_create_minor_node(dip, ZCONS_MASTER_NAME, S_IFCHR, 2277c478bd9Sstevel@tonic-gate instance << 1 | ZC_MASTER_MINOR, DDI_PSEUDO, 0) == DDI_FAILURE)) { 2287c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 2297c478bd9Sstevel@tonic-gate ddi_soft_state_free(zc_soft_state, instance); 2307c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate if ((zcs = ddi_get_soft_state(zc_soft_state, instance)) == NULL) { 2347c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 2357c478bd9Sstevel@tonic-gate ddi_soft_state_free(zc_soft_state, instance); 2367c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate zcs->zc_devinfo = dip; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate static int 2447c478bd9Sstevel@tonic-gate zc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 2457c478bd9Sstevel@tonic-gate { 2467c478bd9Sstevel@tonic-gate zc_state_t *zcs; 2477c478bd9Sstevel@tonic-gate int instance; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate if (cmd != DDI_DETACH) 2507c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 2537c478bd9Sstevel@tonic-gate if ((zcs = ddi_get_soft_state(zc_soft_state, instance)) == NULL) 2547c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate if ((zcs->zc_state & ZC_STATE_MOPEN) || 2577c478bd9Sstevel@tonic-gate (zcs->zc_state & ZC_STATE_SOPEN)) { 2587c478bd9Sstevel@tonic-gate DBG1("zc_detach: device (dip=%p) still open\n", (void *)dip); 2597c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 2637c478bd9Sstevel@tonic-gate ddi_soft_state_free(zc_soft_state, instance); 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* 2697c478bd9Sstevel@tonic-gate * zc_getinfo() 2707c478bd9Sstevel@tonic-gate * getinfo(9e) entrypoint. 2717c478bd9Sstevel@tonic-gate */ 2727c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2737c478bd9Sstevel@tonic-gate static int 2747c478bd9Sstevel@tonic-gate zc_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 2757c478bd9Sstevel@tonic-gate { 2767c478bd9Sstevel@tonic-gate zc_state_t *zcs; 2777c478bd9Sstevel@tonic-gate int instance = ZC_INSTANCE((dev_t)arg); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate switch (infocmd) { 2807c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 2817c478bd9Sstevel@tonic-gate if ((zcs = ddi_get_soft_state(zc_soft_state, instance)) == NULL) 2827c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2837c478bd9Sstevel@tonic-gate *result = zcs->zc_devinfo; 2847c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2857c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 2867c478bd9Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 2877c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate /* 2937c478bd9Sstevel@tonic-gate * Return the equivalent queue from the other side of the relationship. 2947c478bd9Sstevel@tonic-gate * e.g.: given the slave's write queue, return the master's write queue. 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate static queue_t * 2977c478bd9Sstevel@tonic-gate zc_switch(queue_t *qp) 2987c478bd9Sstevel@tonic-gate { 2997c478bd9Sstevel@tonic-gate zc_state_t *zcs = qp->q_ptr; 3007c478bd9Sstevel@tonic-gate ASSERT(zcs != NULL); 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate if (qp == zcs->zc_master_rdq) 3037c478bd9Sstevel@tonic-gate return (zcs->zc_slave_rdq); 3047c478bd9Sstevel@tonic-gate else if (OTHERQ(qp) == zcs->zc_master_rdq && zcs->zc_slave_rdq != NULL) 3057c478bd9Sstevel@tonic-gate return (OTHERQ(zcs->zc_slave_rdq)); 3067c478bd9Sstevel@tonic-gate else if (qp == zcs->zc_slave_rdq) 3077c478bd9Sstevel@tonic-gate return (zcs->zc_master_rdq); 3087c478bd9Sstevel@tonic-gate else if (OTHERQ(qp) == zcs->zc_slave_rdq && zcs->zc_master_rdq != NULL) 3097c478bd9Sstevel@tonic-gate return (OTHERQ(zcs->zc_master_rdq)); 3107c478bd9Sstevel@tonic-gate else 3117c478bd9Sstevel@tonic-gate return (NULL); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate /* 3157c478bd9Sstevel@tonic-gate * For debugging and outputting messages. Returns the name of the side of 3167c478bd9Sstevel@tonic-gate * the relationship associated with this queue. 3177c478bd9Sstevel@tonic-gate */ 3187c478bd9Sstevel@tonic-gate static const char * 3197c478bd9Sstevel@tonic-gate zc_side(queue_t *qp) 3207c478bd9Sstevel@tonic-gate { 3217c478bd9Sstevel@tonic-gate zc_state_t *zcs = qp->q_ptr; 3227c478bd9Sstevel@tonic-gate ASSERT(zcs != NULL); 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate if (qp == zcs->zc_master_rdq || 3257c478bd9Sstevel@tonic-gate OTHERQ(qp) == zcs->zc_master_rdq) { 3267c478bd9Sstevel@tonic-gate return ("master"); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate ASSERT(qp == zcs->zc_slave_rdq || OTHERQ(qp) == zcs->zc_slave_rdq); 3297c478bd9Sstevel@tonic-gate return ("slave"); 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3337c478bd9Sstevel@tonic-gate static int 3347c478bd9Sstevel@tonic-gate zc_master_open(zc_state_t *zcs, 3357c478bd9Sstevel@tonic-gate queue_t *rqp, /* pointer to the read side queue */ 3367c478bd9Sstevel@tonic-gate dev_t *devp, /* pointer to stream tail's dev */ 3377c478bd9Sstevel@tonic-gate int oflag, /* the user open(2) supplied flags */ 3387c478bd9Sstevel@tonic-gate int sflag, /* open state flag */ 3397c478bd9Sstevel@tonic-gate cred_t *credp) /* credentials */ 3407c478bd9Sstevel@tonic-gate { 3417c478bd9Sstevel@tonic-gate mblk_t *mop; 3427c478bd9Sstevel@tonic-gate struct stroptions *sop; 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate * Enforce exclusivity on the master side; the only consumer should 3467c478bd9Sstevel@tonic-gate * be the zoneadmd for the zone. 3477c478bd9Sstevel@tonic-gate */ 3487c478bd9Sstevel@tonic-gate if ((zcs->zc_state & ZC_STATE_MOPEN) != 0) 3497c478bd9Sstevel@tonic-gate return (EBUSY); 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate if ((mop = allocb(sizeof (struct stroptions), BPRI_MED)) == NULL) { 3527c478bd9Sstevel@tonic-gate DBG("zc_master_open(): mop allocation failed\n"); 3537c478bd9Sstevel@tonic-gate return (ENOMEM); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate zcs->zc_state |= ZC_STATE_MOPEN; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate /* 3597c478bd9Sstevel@tonic-gate * q_ptr stores driver private data; stash the soft state data on both 3607c478bd9Sstevel@tonic-gate * read and write sides of the queue. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate WR(rqp)->q_ptr = rqp->q_ptr = zcs; 3637c478bd9Sstevel@tonic-gate qprocson(rqp); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * Following qprocson(), the master side is fully plumbed into the 3677c478bd9Sstevel@tonic-gate * STREAM and may send/receive messages. Setting zcs->zc_master_rdq 3687c478bd9Sstevel@tonic-gate * will allow the slave to send messages to us (the master). 3697c478bd9Sstevel@tonic-gate * This cannot occur before qprocson() because the master is not 3707c478bd9Sstevel@tonic-gate * ready to process them until that point. 3717c478bd9Sstevel@tonic-gate */ 3727c478bd9Sstevel@tonic-gate zcs->zc_master_rdq = rqp; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /* 3757c478bd9Sstevel@tonic-gate * set up hi/lo water marks on stream head read queue and add 3767c478bd9Sstevel@tonic-gate * controlling tty as needed. 3777c478bd9Sstevel@tonic-gate */ 3787c478bd9Sstevel@tonic-gate mop->b_datap->db_type = M_SETOPTS; 3797c478bd9Sstevel@tonic-gate mop->b_wptr += sizeof (struct stroptions); 38027e6fb21Sdp sop = (struct stroptions *)(void *)mop->b_rptr; 3817c478bd9Sstevel@tonic-gate if (oflag & FNOCTTY) 3827c478bd9Sstevel@tonic-gate sop->so_flags = SO_HIWAT | SO_LOWAT; 3837c478bd9Sstevel@tonic-gate else 3847c478bd9Sstevel@tonic-gate sop->so_flags = SO_HIWAT | SO_LOWAT | SO_ISTTY; 3857c478bd9Sstevel@tonic-gate sop->so_hiwat = 512; 3867c478bd9Sstevel@tonic-gate sop->so_lowat = 256; 3877c478bd9Sstevel@tonic-gate putnext(rqp, mop); 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate return (0); 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3937c478bd9Sstevel@tonic-gate static int 3947c478bd9Sstevel@tonic-gate zc_slave_open(zc_state_t *zcs, 3957c478bd9Sstevel@tonic-gate queue_t *rqp, /* pointer to the read side queue */ 3967c478bd9Sstevel@tonic-gate dev_t *devp, /* pointer to stream tail's dev */ 3977c478bd9Sstevel@tonic-gate int oflag, /* the user open(2) supplied flags */ 3987c478bd9Sstevel@tonic-gate int sflag, /* open state flag */ 3997c478bd9Sstevel@tonic-gate cred_t *credp) /* credentials */ 4007c478bd9Sstevel@tonic-gate { 4017c478bd9Sstevel@tonic-gate mblk_t *mop; 4027c478bd9Sstevel@tonic-gate struct stroptions *sop; 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate /* 4057c478bd9Sstevel@tonic-gate * The slave side can be opened as many times as needed. 4067c478bd9Sstevel@tonic-gate */ 4077c478bd9Sstevel@tonic-gate if ((zcs->zc_state & ZC_STATE_SOPEN) != 0) { 4087c478bd9Sstevel@tonic-gate ASSERT((rqp != NULL) && (WR(rqp)->q_ptr == zcs)); 4097c478bd9Sstevel@tonic-gate return (0); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate if ((mop = allocb(sizeof (struct stroptions), BPRI_MED)) == NULL) { 4137c478bd9Sstevel@tonic-gate DBG("zc_slave_open(): mop allocation failed\n"); 4147c478bd9Sstevel@tonic-gate return (ENOMEM); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate zcs->zc_state |= ZC_STATE_SOPEN; 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate /* 4207c478bd9Sstevel@tonic-gate * q_ptr stores driver private data; stash the soft state data on both 4217c478bd9Sstevel@tonic-gate * read and write sides of the queue. 4227c478bd9Sstevel@tonic-gate */ 4237c478bd9Sstevel@tonic-gate WR(rqp)->q_ptr = rqp->q_ptr = zcs; 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate qprocson(rqp); 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate /* 4287c478bd9Sstevel@tonic-gate * Must follow qprocson(), since we aren't ready to process until then. 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate zcs->zc_slave_rdq = rqp; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate /* 4337c478bd9Sstevel@tonic-gate * set up hi/lo water marks on stream head read queue and add 4347c478bd9Sstevel@tonic-gate * controlling tty as needed. 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate mop->b_datap->db_type = M_SETOPTS; 4377c478bd9Sstevel@tonic-gate mop->b_wptr += sizeof (struct stroptions); 43827e6fb21Sdp sop = (struct stroptions *)(void *)mop->b_rptr; 4397c478bd9Sstevel@tonic-gate sop->so_flags = SO_HIWAT | SO_LOWAT | SO_ISTTY; 4407c478bd9Sstevel@tonic-gate sop->so_hiwat = 512; 4417c478bd9Sstevel@tonic-gate sop->so_lowat = 256; 4427c478bd9Sstevel@tonic-gate putnext(rqp, mop); 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate return (0); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate /* 4487c478bd9Sstevel@tonic-gate * open(9e) entrypoint; checks sflag, and rejects anything unordinary. 4497c478bd9Sstevel@tonic-gate */ 4507c478bd9Sstevel@tonic-gate static int 4517c478bd9Sstevel@tonic-gate zc_open(queue_t *rqp, /* pointer to the read side queue */ 4527c478bd9Sstevel@tonic-gate dev_t *devp, /* pointer to stream tail's dev */ 4537c478bd9Sstevel@tonic-gate int oflag, /* the user open(2) supplied flags */ 4547c478bd9Sstevel@tonic-gate int sflag, /* open state flag */ 4557c478bd9Sstevel@tonic-gate cred_t *credp) /* credentials */ 4567c478bd9Sstevel@tonic-gate { 4577c478bd9Sstevel@tonic-gate int instance = ZC_INSTANCE(*devp); 4587c478bd9Sstevel@tonic-gate int ret; 4597c478bd9Sstevel@tonic-gate zc_state_t *zcs; 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate if (sflag != 0) 4627c478bd9Sstevel@tonic-gate return (EINVAL); 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate if ((zcs = ddi_get_soft_state(zc_soft_state, instance)) == NULL) 4657c478bd9Sstevel@tonic-gate return (ENXIO); 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate switch (ZC_NODE(*devp)) { 4687c478bd9Sstevel@tonic-gate case ZC_MASTER_MINOR: 4697c478bd9Sstevel@tonic-gate ret = zc_master_open(zcs, rqp, devp, oflag, sflag, credp); 4707c478bd9Sstevel@tonic-gate break; 4717c478bd9Sstevel@tonic-gate case ZC_SLAVE_MINOR: 4727c478bd9Sstevel@tonic-gate ret = zc_slave_open(zcs, rqp, devp, oflag, sflag, credp); 4737c478bd9Sstevel@tonic-gate break; 4747c478bd9Sstevel@tonic-gate default: 4757c478bd9Sstevel@tonic-gate ret = ENXIO; 4767c478bd9Sstevel@tonic-gate break; 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate return (ret); 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate /* 4837c478bd9Sstevel@tonic-gate * close(9e) entrypoint. 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate /*ARGSUSED1*/ 4867c478bd9Sstevel@tonic-gate static int 4877c478bd9Sstevel@tonic-gate zc_close(queue_t *rqp, int flag, cred_t *credp) 4887c478bd9Sstevel@tonic-gate { 4897c478bd9Sstevel@tonic-gate queue_t *wqp; 4907c478bd9Sstevel@tonic-gate mblk_t *bp; 4917c478bd9Sstevel@tonic-gate zc_state_t *zcs; 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate zcs = (zc_state_t *)rqp->q_ptr; 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate if (rqp == zcs->zc_master_rdq) { 4967c478bd9Sstevel@tonic-gate DBG("Closing master side"); 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate zcs->zc_master_rdq = NULL; 4997c478bd9Sstevel@tonic-gate zcs->zc_state &= ~ZC_STATE_MOPEN; 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5027c478bd9Sstevel@tonic-gate * qenable slave side write queue so that it can flush 5037c478bd9Sstevel@tonic-gate * its messages as master's read queue is going away 5047c478bd9Sstevel@tonic-gate */ 5057c478bd9Sstevel@tonic-gate if (zcs->zc_slave_rdq != NULL) { 5067c478bd9Sstevel@tonic-gate qenable(WR(zcs->zc_slave_rdq)); 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate qprocsoff(rqp); 5107c478bd9Sstevel@tonic-gate WR(rqp)->q_ptr = rqp->q_ptr = NULL; 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate } else if (rqp == zcs->zc_slave_rdq) { 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate DBG("Closing slave side"); 5157c478bd9Sstevel@tonic-gate zcs->zc_state &= ~ZC_STATE_SOPEN; 5167c478bd9Sstevel@tonic-gate zcs->zc_slave_rdq = NULL; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate wqp = WR(rqp); 5197c478bd9Sstevel@tonic-gate while ((bp = getq(wqp)) != NULL) { 5207c478bd9Sstevel@tonic-gate if (zcs->zc_master_rdq != NULL) 5217c478bd9Sstevel@tonic-gate putnext(zcs->zc_master_rdq, bp); 5227c478bd9Sstevel@tonic-gate else if (bp->b_datap->db_type == M_IOCTL) 5237c478bd9Sstevel@tonic-gate miocnak(wqp, bp, 0, 0); 5247c478bd9Sstevel@tonic-gate else 5257c478bd9Sstevel@tonic-gate freemsg(bp); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate /* 5297c478bd9Sstevel@tonic-gate * Qenable master side write queue so that it can flush its 5307c478bd9Sstevel@tonic-gate * messages as slaves's read queue is going away. 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate if (zcs->zc_master_rdq != NULL) 5337c478bd9Sstevel@tonic-gate qenable(WR(zcs->zc_master_rdq)); 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate qprocsoff(rqp); 5367c478bd9Sstevel@tonic-gate WR(rqp)->q_ptr = rqp->q_ptr = NULL; 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate return (0); 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate static void 5437c478bd9Sstevel@tonic-gate handle_mflush(queue_t *qp, mblk_t *mp) 5447c478bd9Sstevel@tonic-gate { 5457c478bd9Sstevel@tonic-gate mblk_t *nmp; 5467c478bd9Sstevel@tonic-gate DBG1("M_FLUSH on %s side", zc_side(qp)); 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 5497c478bd9Sstevel@tonic-gate DBG1("M_FLUSH, FLUSHW, %s side", zc_side(qp)); 5507c478bd9Sstevel@tonic-gate flushq(qp, FLUSHDATA); 5517c478bd9Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; 5527c478bd9Sstevel@tonic-gate if ((*mp->b_rptr & FLUSHR) == 0) { 5537c478bd9Sstevel@tonic-gate /* 5547c478bd9Sstevel@tonic-gate * FLUSHW only. Change to FLUSHR and putnext other side, 5557c478bd9Sstevel@tonic-gate * then we are done. 5567c478bd9Sstevel@tonic-gate */ 5577c478bd9Sstevel@tonic-gate *mp->b_rptr |= FLUSHR; 5587c478bd9Sstevel@tonic-gate if (zc_switch(RD(qp)) != NULL) { 5597c478bd9Sstevel@tonic-gate putnext(zc_switch(RD(qp)), mp); 5607c478bd9Sstevel@tonic-gate return; 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate } else if ((zc_switch(RD(qp)) != NULL) && 5637c478bd9Sstevel@tonic-gate (nmp = copyb(mp)) != NULL) { 5647c478bd9Sstevel@tonic-gate /* 5657c478bd9Sstevel@tonic-gate * It is a FLUSHRW; we copy the mblk and send 5667c478bd9Sstevel@tonic-gate * it to the other side, since we still need to use 5677c478bd9Sstevel@tonic-gate * the mblk in FLUSHR processing, below. 5687c478bd9Sstevel@tonic-gate */ 5697c478bd9Sstevel@tonic-gate putnext(zc_switch(RD(qp)), nmp); 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate } 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 5747c478bd9Sstevel@tonic-gate DBG("qreply(qp) turning FLUSHR around\n"); 5757c478bd9Sstevel@tonic-gate qreply(qp, mp); 5767c478bd9Sstevel@tonic-gate return; 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate freemsg(mp); 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * wput(9E) is symmetric for master and slave sides, so this handles both 5837c478bd9Sstevel@tonic-gate * without splitting the codepath. 5847c478bd9Sstevel@tonic-gate * 5857c478bd9Sstevel@tonic-gate * zc_wput() looks at the other side; if there is no process holding that 5867c478bd9Sstevel@tonic-gate * side open, it frees the message. This prevents processes from hanging 5877c478bd9Sstevel@tonic-gate * if no one is holding open the console. Otherwise, it putnext's high 5887c478bd9Sstevel@tonic-gate * priority messages, putnext's normal messages if possible, and otherwise 5897c478bd9Sstevel@tonic-gate * enqueues the messages; in the case that something is enqueued, wsrv(9E) 5907c478bd9Sstevel@tonic-gate * will take care of eventually shuttling I/O to the other side. 5917c478bd9Sstevel@tonic-gate */ 5927c478bd9Sstevel@tonic-gate static void 5937c478bd9Sstevel@tonic-gate zc_wput(queue_t *qp, mblk_t *mp) 5947c478bd9Sstevel@tonic-gate { 5957c478bd9Sstevel@tonic-gate unsigned char type = mp->b_datap->db_type; 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate ASSERT(qp->q_ptr); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate DBG1("entering zc_wput, %s side", zc_side(qp)); 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate if (zc_switch(RD(qp)) == NULL) { 6027c478bd9Sstevel@tonic-gate DBG1("wput to %s side (no one listening)", zc_side(qp)); 6037c478bd9Sstevel@tonic-gate switch (type) { 6047c478bd9Sstevel@tonic-gate case M_FLUSH: 6057c478bd9Sstevel@tonic-gate handle_mflush(qp, mp); 6067c478bd9Sstevel@tonic-gate break; 6077c478bd9Sstevel@tonic-gate case M_IOCTL: 6087c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, 0); 6097c478bd9Sstevel@tonic-gate break; 6107c478bd9Sstevel@tonic-gate default: 6117c478bd9Sstevel@tonic-gate freemsg(mp); 6127c478bd9Sstevel@tonic-gate break; 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate return; 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate if (type >= QPCTL) { 6187c478bd9Sstevel@tonic-gate DBG1("(hipri) wput, %s side", zc_side(qp)); 6197c478bd9Sstevel@tonic-gate switch (type) { 6207c478bd9Sstevel@tonic-gate case M_READ: /* supposedly from ldterm? */ 6217c478bd9Sstevel@tonic-gate DBG("zc_wput: tossing M_READ\n"); 6227c478bd9Sstevel@tonic-gate freemsg(mp); 6237c478bd9Sstevel@tonic-gate break; 6247c478bd9Sstevel@tonic-gate case M_FLUSH: 6257c478bd9Sstevel@tonic-gate handle_mflush(qp, mp); 6267c478bd9Sstevel@tonic-gate break; 6277c478bd9Sstevel@tonic-gate default: 6287c478bd9Sstevel@tonic-gate /* 6297c478bd9Sstevel@tonic-gate * Put this to the other side. 6307c478bd9Sstevel@tonic-gate */ 6317c478bd9Sstevel@tonic-gate ASSERT(zc_switch(RD(qp)) != NULL); 6327c478bd9Sstevel@tonic-gate putnext(zc_switch(RD(qp)), mp); 6337c478bd9Sstevel@tonic-gate break; 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate DBG1("done (hipri) wput, %s side", zc_side(qp)); 6367c478bd9Sstevel@tonic-gate return; 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate /* 6407c478bd9Sstevel@tonic-gate * Only putnext if there isn't already something in the queue. 6417c478bd9Sstevel@tonic-gate * otherwise things would wind up out of order. 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate if (qp->q_first == NULL && bcanputnext(RD(zc_switch(qp)), mp->b_band)) { 6447c478bd9Sstevel@tonic-gate DBG("wput: putting message to other side\n"); 6457c478bd9Sstevel@tonic-gate putnext(RD(zc_switch(qp)), mp); 6467c478bd9Sstevel@tonic-gate } else { 6477c478bd9Sstevel@tonic-gate DBG("wput: putting msg onto queue\n"); 6487c478bd9Sstevel@tonic-gate (void) putq(qp, mp); 6497c478bd9Sstevel@tonic-gate } 6507c478bd9Sstevel@tonic-gate DBG1("done wput, %s side", zc_side(qp)); 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate /* 6547c478bd9Sstevel@tonic-gate * rsrv(9E) is symmetric for master and slave, so zc_rsrv() handles both 6557c478bd9Sstevel@tonic-gate * without splitting up the codepath. 6567c478bd9Sstevel@tonic-gate * 6577c478bd9Sstevel@tonic-gate * Enable the write side of the partner. This triggers the partner to send 6587c478bd9Sstevel@tonic-gate * messages queued on its write side to this queue's read side. 6597c478bd9Sstevel@tonic-gate */ 6607c478bd9Sstevel@tonic-gate static void 6617c478bd9Sstevel@tonic-gate zc_rsrv(queue_t *qp) 6627c478bd9Sstevel@tonic-gate { 6637c478bd9Sstevel@tonic-gate zc_state_t *zcs; 6647c478bd9Sstevel@tonic-gate zcs = (zc_state_t *)qp->q_ptr; 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate /* 6677c478bd9Sstevel@tonic-gate * Care must be taken here, as either of the master or slave side 6687c478bd9Sstevel@tonic-gate * qptr could be NULL. 6697c478bd9Sstevel@tonic-gate */ 6707c478bd9Sstevel@tonic-gate ASSERT(qp == zcs->zc_master_rdq || qp == zcs->zc_slave_rdq); 6717c478bd9Sstevel@tonic-gate if (zc_switch(qp) == NULL) { 6727c478bd9Sstevel@tonic-gate DBG("zc_rsrv: other side isn't listening\n"); 6737c478bd9Sstevel@tonic-gate return; 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate qenable(WR(zc_switch(qp))); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate /* 6797c478bd9Sstevel@tonic-gate * This routine is symmetric for master and slave, so it handles both without 6807c478bd9Sstevel@tonic-gate * splitting up the codepath. 6817c478bd9Sstevel@tonic-gate * 6827c478bd9Sstevel@tonic-gate * If there are messages on this queue that can be sent to the other, send 6837c478bd9Sstevel@tonic-gate * them via putnext(). Else, if queued messages cannot be sent, leave them 6847c478bd9Sstevel@tonic-gate * on this queue. 6857c478bd9Sstevel@tonic-gate */ 6867c478bd9Sstevel@tonic-gate static void 6877c478bd9Sstevel@tonic-gate zc_wsrv(queue_t *qp) 6887c478bd9Sstevel@tonic-gate { 6897c478bd9Sstevel@tonic-gate mblk_t *mp; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate DBG1("zc_wsrv master (%s) side", zc_side(qp)); 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate /* 6947c478bd9Sstevel@tonic-gate * Partner has no read queue, so take the data, and throw it away. 6957c478bd9Sstevel@tonic-gate */ 6967c478bd9Sstevel@tonic-gate if (zc_switch(RD(qp)) == NULL) { 6977c478bd9Sstevel@tonic-gate DBG("zc_wsrv: other side isn't listening"); 6987c478bd9Sstevel@tonic-gate while ((mp = getq(qp)) != NULL) { 6997c478bd9Sstevel@tonic-gate if (mp->b_datap->db_type == M_IOCTL) 7007c478bd9Sstevel@tonic-gate miocnak(qp, mp, 0, 0); 7017c478bd9Sstevel@tonic-gate else 7027c478bd9Sstevel@tonic-gate freemsg(mp); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate flushq(qp, FLUSHALL); 7057c478bd9Sstevel@tonic-gate return; 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate /* 7097c478bd9Sstevel@tonic-gate * while there are messages on this write queue... 7107c478bd9Sstevel@tonic-gate */ 7117c478bd9Sstevel@tonic-gate while ((mp = getq(qp)) != NULL) { 7127c478bd9Sstevel@tonic-gate /* 7137c478bd9Sstevel@tonic-gate * Due to the way zc_wput is implemented, we should never 7147c478bd9Sstevel@tonic-gate * see a control message here. 7157c478bd9Sstevel@tonic-gate */ 7167c478bd9Sstevel@tonic-gate ASSERT(mp->b_datap->db_type < QPCTL); 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate if (bcanputnext(RD(zc_switch(qp)), mp->b_band)) { 7197c478bd9Sstevel@tonic-gate DBG("wsrv: send message to other side\n"); 7207c478bd9Sstevel@tonic-gate putnext(RD(zc_switch(qp)), mp); 7217c478bd9Sstevel@tonic-gate } else { 7227c478bd9Sstevel@tonic-gate DBG("wsrv: putting msg back on queue\n"); 7237c478bd9Sstevel@tonic-gate (void) putbq(qp, mp); 7247c478bd9Sstevel@tonic-gate break; 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate } 728