Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/clone.c
+++ new/usr/src/uts/common/io/clone.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 22 /* All Rights Reserved */
23 23
24 24
25 25 /*
26 26 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 30
31 31 /*
32 32 * Clone Driver.
33 33 */
34 34
35 35 #include <sys/types.h>
36 36 #include <sys/param.h>
37 37 #include <sys/errno.h>
38 38 #include <sys/signal.h>
39 39 #include <sys/vfs.h>
40 40 #include <sys/vnode.h>
41 41 #include <sys/pcb.h>
42 42 #include <sys/user.h>
43 43 #include <sys/stropts.h>
44 44 #include <sys/stream.h>
45 45 #include <sys/errno.h>
46 46 #include <sys/sysinfo.h>
47 47 #include <sys/systm.h>
48 48 #include <sys/conf.h>
49 49 #include <sys/debug.h>
50 50 #include <sys/cred.h>
51 51 #include <sys/mkdev.h>
52 52 #include <sys/open.h>
53 53 #include <sys/strsubr.h>
54 54 #include <sys/ddi.h>
55 55 #include <sys/sunddi.h>
56 56 #include <sys/modctl.h>
57 57 #include <sys/policy.h>
58 58
59 59 int clnopen(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *crp);
60 60
61 61 static struct module_info clnm_info = { 0, "CLONE", 0, 0, 0, 0 };
62 62 static struct qinit clnrinit = { NULL, NULL, clnopen, NULL, NULL, &clnm_info,
63 63 NULL };
64 64 static struct qinit clnwinit = { NULL, NULL, NULL, NULL, NULL, &clnm_info,
65 65 NULL };
66 66 struct streamtab clninfo = { &clnrinit, &clnwinit };
67 67
68 68 static int cln_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
69 69 static int cln_attach(dev_info_t *, ddi_attach_cmd_t);
70 70 static dev_info_t *cln_dip; /* private copy of devinfo pointer */
71 71
72 72 #define CLONE_CONF_FLAG (D_NEW|D_MP)
73 73
74 74 DDI_DEFINE_STREAM_OPS(clone_ops, nulldev, nulldev, cln_attach, nodev, nodev, \
75 75 cln_info, CLONE_CONF_FLAG, &clninfo, ddi_quiesce_not_needed);
76 76
77 77 /*
78 78 * Module linkage information for the kernel.
↓ open down ↓ |
78 lines elided |
↑ open up ↑ |
79 79 */
80 80
81 81 static struct modldrv modldrv = {
82 82 &mod_driverops, /* Type of module. This one is a pseudo driver */
83 83 "Clone Pseudodriver 'clone'",
84 84 &clone_ops, /* driver ops */
85 85 };
86 86
87 87 static struct modlinkage modlinkage = {
88 88 MODREV_1,
89 - (void *)&modldrv,
90 - NULL
89 + { (void *)&modldrv, NULL }
91 90 };
92 91
93 92
94 93 int
95 94 _init(void)
96 95 {
97 96 return (mod_install(&modlinkage));
98 97 }
99 98
100 99 int
101 100 _fini(void)
102 101 {
103 102 /*
104 103 * Since the clone driver's reference count is unreliable,
105 104 * make sure we are never unloaded.
106 105 */
107 106 return (EBUSY);
108 107 }
109 108
110 109 int
111 110 _info(struct modinfo *modinfop)
112 111 {
113 112 return (mod_info(&modlinkage, modinfop));
114 113 }
115 114
116 115 /* ARGSUSED */
117 116 static int
118 117 cln_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
119 118 {
120 119 cln_dip = devi;
121 120 return (DDI_SUCCESS);
122 121 }
123 122
124 123 /* ARGSUSED */
125 124 static int
126 125 cln_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
127 126 void **result)
128 127 {
129 128 int error;
130 129
131 130 switch (infocmd) {
132 131 case DDI_INFO_DEVT2DEVINFO:
133 132 if (cln_dip == NULL) {
134 133 error = DDI_FAILURE;
135 134 } else {
136 135 *result = (void *)cln_dip;
137 136 error = DDI_SUCCESS;
138 137 }
139 138 break;
140 139 case DDI_INFO_DEVT2INSTANCE:
141 140 *result = (void *)0;
142 141 error = DDI_SUCCESS;
143 142 break;
144 143 default:
145 144 error = DDI_FAILURE;
146 145 }
147 146 return (error);
148 147 }
149 148
150 149 /*
151 150 * Clone open. Maj is the major device number of the streams
152 151 * device to open. Look up the device in the cdevsw[]. Attach
153 152 * its qinit structures to the read and write queues and call its
154 153 * open with the sflag set to CLONEOPEN. Swap in a new vnode with
155 154 * the real device number constructed from either
156 155 * a) for old-style drivers:
157 156 * maj and the minor returned by the device open, or
158 157 * b) for new-style drivers:
159 158 * the whole dev passed back as a reference parameter
160 159 * from the device open.
161 160 */
162 161 int
163 162 clnopen(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *crp)
164 163 {
165 164 struct streamtab *str;
166 165 dev_t newdev;
167 166 int error = 0;
168 167 major_t maj;
169 168 minor_t emaj;
170 169 struct qinit *rinit, *winit;
171 170 cdevsw_impl_t *dp;
172 171 uint32_t qflag;
173 172 uint32_t sqtype;
174 173 perdm_t *dmp;
175 174 vnode_t *vp;
176 175
177 176 if (sflag)
178 177 return (ENXIO);
179 178
180 179 /*
181 180 * Get the device to open.
182 181 */
183 182 emaj = getminor(*devp); /* minor is major for a cloned driver */
184 183 maj = etoimajor(emaj); /* get internal major of cloned driver */
185 184
186 185 if (maj >= devcnt)
187 186 return (ENXIO);
188 187
189 188 /*
190 189 * NOTE We call ddi_hold_installed_driver() here to attach
191 190 * all instances of the driver, since we do not know
192 191 * a priori which instance the Stream is associated with.
193 192 *
194 193 * For Style-2 network drivers, we know that the association
195 194 * happens at DL_ATTACH time. For other types of drivers,
196 195 * open probably requires attaching instance 0 (pseudo dip).
197 196 *
198 197 * To eliminate ddi_hold_installed_driver(), the following
199 198 * should happen:
200 199 *
201 200 * - GLD be modified to include gld_init(). The driver will
202 201 * register information for gld_open() to succeed. It will
203 202 * also inform framework if driver assigns instance=PPA.
204 203 * - ddi_hold_devi_by_instance() be modified to actively
205 204 * attach the instance via top-down enumeration.
206 205 */
207 206 if (ddi_hold_installed_driver(maj) == NULL)
208 207 return (ENXIO);
209 208
210 209 if ((str = STREAMSTAB(maj)) == NULL) {
211 210 ddi_rele_driver(maj);
212 211 return (ENXIO);
213 212 }
214 213
215 214 newdev = makedevice(emaj, 0); /* create new style device number */
216 215
217 216 /*
218 217 * Check for security here. For DLPI style 2 network
219 218 * drivers, we need to apply the default network policy.
220 219 * Clone is weird in that the network driver isn't loaded
221 220 * and attached at spec_open() time, we need to load the
222 221 * driver to see if it is a network driver. Hence, we
223 222 * check security here (after ddi_hold_installed_driver
224 223 * call above).
225 224 */
226 225 vp = makespecvp(newdev, VCHR);
227 226 error = secpolicy_spec_open(crp, vp, flag);
228 227 VN_RELE(vp);
229 228 if (error) {
230 229 ddi_rele_driver(maj);
231 230 return (error);
232 231 }
233 232
234 233 /*
235 234 * Save so that we can restore the q on failure.
236 235 */
237 236 rinit = rq->q_qinfo;
238 237 winit = WR(rq)->q_qinfo;
239 238 ASSERT(rq->q_syncq->sq_type == (SQ_CI|SQ_CO));
240 239 ASSERT((rq->q_flag & QMT_TYPEMASK) == QMTSAFE);
241 240
242 241 dp = &devimpl[maj];
243 242 ASSERT(str == dp->d_str);
244 243
245 244 qflag = dp->d_qflag;
246 245 sqtype = dp->d_sqtype;
247 246
248 247 /* create perdm_t if needed */
249 248 if (NEED_DM(dp->d_dmp, qflag))
250 249 dp->d_dmp = hold_dm(str, qflag, sqtype);
251 250
252 251 dmp = dp->d_dmp;
253 252
254 253 /*
255 254 * Set the syncq state what qattach started off with. This is safe
256 255 * since no other thread can access this queue at this point
257 256 * (stream open, close, push, and pop are single threaded
258 257 * by the framework.)
259 258 */
260 259 leavesq(rq->q_syncq, SQ_OPENCLOSE);
261 260
262 261 /*
263 262 * Substitute the real qinit values for the current ones.
264 263 */
265 264 /* setq might sleep in kmem_alloc - avoid holding locks. */
266 265 setq(rq, str->st_rdinit, str->st_wrinit, dmp, qflag, sqtype, B_FALSE);
267 266
268 267 /*
269 268 * Open the attached module or driver.
270 269 *
271 270 * If there is an outer perimeter get exclusive access during
272 271 * the open procedure.
273 272 * Bump up the reference count on the queue.
274 273 */
275 274 entersq(rq->q_syncq, SQ_OPENCLOSE);
276 275
277 276 /*
278 277 * Call the device open with the stream flag CLONEOPEN. The device
279 278 * will either fail this or return the device number.
280 279 */
281 280 error = (*rq->q_qinfo->qi_qopen)(rq, &newdev, flag, CLONEOPEN, crp);
282 281 if (error != 0)
283 282 goto failed;
284 283
285 284 *devp = newdev;
286 285 if (getmajor(newdev) != emaj)
287 286 goto bad_major;
288 287
289 288 return (0);
290 289
291 290 bad_major:
292 291 /*
293 292 * Close the device
294 293 */
295 294 (*rq->q_qinfo->qi_qclose)(rq, flag, crp);
296 295
297 296 #ifdef DEBUG
298 297 cmn_err(CE_NOTE, "cannot clone major number %d(%s)->%d", emaj,
299 298 ddi_major_to_name(emaj), getmajor(newdev));
300 299 #endif
301 300 error = ENXIO;
302 301
303 302 failed:
304 303 /*
305 304 * open failed; pretty up to look like original
306 305 * queue.
307 306 */
308 307 if (backq(WR(rq)) && backq(WR(rq))->q_next == WR(rq))
309 308 qprocsoff(rq);
310 309 leavesq(rq->q_syncq, SQ_OPENCLOSE);
311 310 rq->q_next = WR(rq)->q_next = NULL;
312 311 ASSERT(flush_syncq(rq->q_syncq, rq) == 0);
313 312 ASSERT(flush_syncq(WR(rq)->q_syncq, WR(rq)) == 0);
314 313 rq->q_ptr = WR(rq)->q_ptr = NULL;
315 314 /* setq might sleep in kmem_alloc - avoid holding locks. */
316 315 setq(rq, rinit, winit, NULL, QMTSAFE, SQ_CI|SQ_CO,
317 316 B_FALSE);
318 317
319 318 /* Restore back to what qattach will expect */
320 319 entersq(rq->q_syncq, SQ_OPENCLOSE);
321 320
322 321 ddi_rele_driver(maj);
323 322 return (error);
324 323 }
↓ open down ↓ |
224 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX