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]
23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
24 /* All Rights Reserved */
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5.3.3 */
40 #include <sys/stream.h>
41 #define _SUN_TPI_VERSION 2
42 #include <sys/tihdr.h>
43 #include <sys/timod.h>
54 * If _tx_open is called for transport that doesn't understand T_CAPABILITY_REQ
55 * TPI message, call to _t_create may fail the first time it is called with
56 * given transport (in the rare case when transport shuts down the stream with
57 * M_ERROR in reply to unknown T_CAPABILITY_REQ). In this case we may reopen the
58 * stream again since timod will emulate T_CAPABILITY_REQ behaviour.
60 * _t_create sends T_CAPABILITY_REQ through TI_CAPABILITY ioctl.
64 _tx_open(const char *path
, int flags
, struct t_info
*info
, int api_semantics
)
66 int retval
, fd
, sv_errno
;
69 struct _ti_user
*tiptr
;
71 int t_create_first_attempt
= 1;
72 int ticap_ioctl_failed
= 0;
74 if (!(flags
& O_RDWR
)) {
79 sv_errno_global
= errno
;
83 if ((fd
= open(path
, flags
)) < 0) {
85 if (_T_IS_XTI(api_semantics
) && errno
== ENOENT
)
91 * is module already pushed
94 retval
= ioctl(fd
, I_FIND
, "timod");
95 } while (retval
< 0 && errno
== EINTR
);
108 * "timod" not already on stream, then push it
112 * Assumes (correctly) that I_PUSH is
113 * atomic w.r.t signals (EINTR error)
115 retval
= ioctl(fd
, I_PUSH
, "timod");
116 } while (retval
< 0 && errno
== EINTR
);
119 int sv_errno
= errno
;
129 * _t_create() requires that all signals be blocked.
130 * Note that sig_mutex_lock() only defers signals, it does not
131 * block them, so interruptible syscalls could still get EINTR.
133 (void) thr_sigsetmask(SIG_SETMASK
, &fillset
, &mask
);
134 sig_mutex_lock(&_ti_userlock
);
136 * Call to _t_create may fail either because transport doesn't
137 * understand T_CAPABILITY_REQ or for some other reason. It is nearly
138 * impossible to distinguish between these cases so it is implicitly
139 * assumed that it is always save to close and reopen the same stream
140 * and that open/close doesn't have side effects. _t_create may fail
141 * only once if its' failure is caused by unimplemented
144 tiptr
= _t_create(fd
, info
, api_semantics
, &ticap_ioctl_failed
);
147 * If _t_create failed due to fail of ti_capability_req we may
148 * try to reopen the stream in the hope that timod will emulate
149 * TI_CAPABILITY and it will succeed when called again.
151 if (t_create_first_attempt
== 1 && ticap_ioctl_failed
== 1) {
152 t_create_first_attempt
= 0;
154 errno
= sv_errno_global
;
156 sig_mutex_unlock(&_ti_userlock
);
157 (void) thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
160 int sv_errno
= errno
;
162 sig_mutex_unlock(&_ti_userlock
);
163 (void) thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
170 * _t_create synchronizes state witk kernel timod and
171 * already sets it to T_UNBND - what it needs to be
172 * be on T_OPEN event. No _T_TX_NEXTSTATE needed here.
174 sig_mutex_unlock(&_ti_userlock
);
175 (void) thr_sigsetmask(SIG_SETMASK
, &mask
, NULL
);
178 retval
= ioctl(fd
, I_FLUSH
, FLUSHRW
);
179 } while (retval
< 0 && errno
== EINTR
);
182 * We ignore other error cases (retval < 0) - assumption is
183 * that I_FLUSH failures is temporary (e.g. ENOSR) or
184 * otherwise benign failure on a this newly opened file
185 * descriptor and not a critical failure.