1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 22 /* All Rights Reserved */ 23 24 /* 25 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 * 28 * Copyright (c) 2016 by Delphix. All rights reserved. 29 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 30 */ 31 32 #include <sys/types.h> 33 #include <sys/param.h> 34 35 #include <sys/atomic.h> 36 #include <sys/stream.h> 37 #include <sys/strsubr.h> 38 #include <sys/cmn_err.h> 39 40 #include <sys/strft.h> 41 42 int str_ftnever = 0; 43 44 static void mblk_free(mblk_t *); 45 static void esballoc_mblk_free(mblk_t *); 46 47 /* 48 * A few things from os/strsubr.c 49 */ 50 51 int 52 strwaitbuf(size_t size, int pri) 53 { 54 return (0); 55 } 56 57 /* 58 * Return size of message of block type (bp->b_datap->db_type) 59 */ 60 size_t 61 xmsgsize(mblk_t *bp) 62 { 63 unsigned char type; 64 size_t count = 0; 65 66 type = bp->b_datap->db_type; 67 68 for (; bp; bp = bp->b_cont) { 69 if (type != bp->b_datap->db_type) 70 break; 71 ASSERT(bp->b_wptr >= bp->b_rptr); 72 count += bp->b_wptr - bp->b_rptr; 73 } 74 return (count); 75 } 76 77 /* ARGSUSED */ 78 bufcall_id_t 79 bufcall(size_t size, uint_t pri, void (*func)(void *), void *arg) 80 { 81 cmn_err(CE_NOTE, "bufcall() called!"); 82 return ("fake bufcall id"); 83 } 84 85 /* ARGSUSED */ 86 void 87 unbufcall(bufcall_id_t id) 88 { 89 } 90 91 /* ARGSUSED */ 92 void 93 freebs_enqueue(mblk_t *mp, dblk_t *dbp) 94 { 95 /* 96 * Won't bother with esb_queue_t async free here. 97 * Rather just free this mblk directly. 98 */ 99 esballoc_mblk_free(mp); 100 } 101 102 static void 103 esballoc_mblk_free(mblk_t *mp) 104 { 105 mblk_t *nextmp; 106 107 for (; mp != NULL; mp = nextmp) { 108 nextmp = mp->b_next; 109 mp->b_next = NULL; 110 mblk_free(mp); 111 } 112 } 113 114 static void 115 mblk_free(mblk_t *mp) 116 { 117 dblk_t *dbp = mp->b_datap; 118 frtn_t *frp = dbp->db_frtnp; 119 120 mp->b_next = NULL; 121 if (dbp->db_fthdr != NULL) 122 str_ftfree(dbp); 123 124 ASSERT(dbp->db_fthdr == NULL); 125 frp->free_func(frp->free_arg); 126 ASSERT(dbp->db_mblk == mp); 127 128 if (dbp->db_credp != NULL) { 129 crfree(dbp->db_credp); 130 dbp->db_credp = NULL; 131 } 132 dbp->db_cpid = -1; 133 dbp->db_struioflag = 0; 134 dbp->db_struioun.cksum.flags = 0; 135 136 kmem_cache_free(dbp->db_cache, dbp); 137 } 138 139 /* ARGSUSED */ 140 mblk_t * 141 mmd_copy(mblk_t *bp, int flags) 142 { 143 return (NULL); 144 } 145 146 /* 147 * A little bit from os/streamio.c 148 */ 149 150 static volatile uint32_t ioc_id; 151 152 int 153 getiocseqno(void) 154 { 155 uint32_t i; 156 157 i = atomic_inc_32_nv(&ioc_id); 158 159 return ((int)i); 160 } 161