4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
32 * t_sndudata.c and t_sndvudata.c are very similar and contain common code.
33 * Any changes to either of them should be reviewed to see whether they
34 * are applicable to the other file.
40 #include <sys/stream.h>
41 #define _SUN_TPI_VERSION 2
42 #include <sys/tihdr.h>
43 #include <sys/timod.h>
50 _tx_sndvudata(int fd
, const struct t_unitdata
*unitdata
, struct t_iovec
*tiov
,
51 unsigned int tiovcount
, int api_semantics
)
53 struct T_unitdata_req
*udreq
;
55 struct strbuf databuf
;
57 struct _ti_user
*tiptr
;
63 assert(api_semantics
== TX_XTI_XNS5_API
);
64 if ((tiptr
= _t_checkfd(fd
, 0, api_semantics
)) == NULL
)
66 sig_mutex_lock(&tiptr
->ti_lock
);
68 if (tiptr
->ti_servtype
!= T_CLTS
) {
69 t_errno
= TNOTSUPPORT
;
70 sig_mutex_unlock(&tiptr
->ti_lock
);
74 if (tiovcount
== 0 || tiovcount
> T_IOV_MAX
) {
76 sig_mutex_unlock(&tiptr
->ti_lock
);
80 if (tiptr
->ti_state
!= T_IDLE
) {
82 sig_mutex_unlock(&tiptr
->ti_lock
);
86 nbytes
= _t_bytecount_upto_intmax(tiov
, tiovcount
);
89 !(tiptr
->ti_prov_flag
& (SENDZERO
|OLD_SENDZERO
))) {
91 sig_mutex_unlock(&tiptr
->ti_lock
);
95 if ((tiptr
->ti_maxpsz
> 0) && (nbytes
> (uint32_t)tiptr
->ti_maxpsz
)) {
98 sig_mutex_unlock(&tiptr
->ti_lock
);
104 * Acquire ctlbuf for use in sending/receiving control part
107 if (_t_acquire_ctlbuf(tiptr
, &ctlbuf
, &didalloc
) < 0) {
109 sig_mutex_unlock(&tiptr
->ti_lock
);
114 /* LINTED pointer cast */
115 udreq
= (struct T_unitdata_req
*)ctlbuf
.buf
;
117 udreq
->PRIM_type
= T_UNITDATA_REQ
;
118 udreq
->DEST_length
= unitdata
->addr
.len
;
119 udreq
->DEST_offset
= 0;
120 udreq
->OPT_length
= unitdata
->opt
.len
;
121 udreq
->OPT_offset
= 0;
122 size
= (int)sizeof (struct T_unitdata_req
);
124 if (unitdata
->addr
.len
) {
125 if (_t_aligned_copy(&ctlbuf
, unitdata
->addr
.len
, size
,
126 unitdata
->addr
.buf
, &udreq
->DEST_offset
) < 0) {
128 * Aligned copy based will overflow buffer
129 * allocated based on maximum transport address
136 size
= udreq
->DEST_offset
+ udreq
->DEST_length
;
138 if (unitdata
->opt
.len
) {
139 if (_t_aligned_copy(&ctlbuf
, unitdata
->opt
.len
, size
,
140 unitdata
->opt
.buf
, &udreq
->OPT_offset
) < 0) {
142 * Aligned copy based will overflow buffer
143 * allocated based on maximum transport option
150 size
= udreq
->OPT_offset
+ udreq
->OPT_length
;
153 if (size
> (int)ctlbuf
.maxlen
) {
162 if ((dataptr
= malloc((size_t)nbytes
)) == NULL
) {
166 _t_gather(dataptr
, tiov
, tiovcount
);
168 databuf
.buf
= dataptr
;
169 databuf
.len
= nbytes
;
170 databuf
.maxlen
= nbytes
;
172 * Calls to send data (write or putmsg) can potentially
173 * block, for MT case, we drop the lock and enable signals here
174 * and acquire it back
176 sig_mutex_unlock(&tiptr
->ti_lock
);
177 if (putmsg(fd
, &ctlbuf
, &databuf
, 0) < 0) {
183 sig_mutex_lock(&tiptr
->ti_lock
);
187 sig_mutex_lock(&tiptr
->ti_lock
);
189 _T_TX_NEXTSTATE(T_SNDUDATA
, tiptr
,
190 "t_sndvudata: invalid state event T_SNDUDATA");
194 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
196 sig_mutex_unlock(&tiptr
->ti_lock
);
203 tiptr
->ti_ctlbuf
= ctlbuf
.buf
;
205 sig_mutex_unlock(&tiptr
->ti_lock
);