Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/modules/genunix/ldi.c
+++ new/usr/src/cmd/mdb/common/modules/genunix/ldi.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, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 +/*
28 + * Copyright (c) 2018, Joyent, Inc.
29 + */
30 +
27 31 #include <sys/types.h>
28 32 #include <sys/sysmacros.h>
29 33 #include <sys/dditypes.h>
30 34 #include <sys/ddi_impldefs.h>
31 35 #include <sys/ddipropdefs.h>
32 36 #include <sys/modctl.h>
33 37 #include <sys/file.h>
34 38 #include <sys/sunldi_impl.h>
35 39
36 40 #include <mdb/mdb_modapi.h>
37 41 #include <mdb/mdb_ks.h>
38 42
39 43 #include "ldi.h"
40 44
41 45 /*
42 46 * ldi handle walker structure
43 47 */
44 48 typedef struct lh_walk {
45 49 struct ldi_handle **hash; /* current bucket pointer */
46 50 struct ldi_handle *lhp; /* ldi handle pointer */
47 51 size_t index; /* hash table index */
48 52 struct ldi_handle buf; /* buffer used for handle reads */
49 53 } lh_walk_t;
50 54
51 55 /*
52 56 * ldi identifier walker structure
53 57 */
54 58 typedef struct li_walk {
55 59 struct ldi_ident **hash; /* current bucket pointer */
56 60 struct ldi_ident *lip; /* ldi handle pointer */
57 61 size_t index; /* hash table index */
58 62 struct ldi_ident buf; /* buffer used for ident reads */
59 63 } li_walk_t;
60 64
61 65 /*
62 66 * Options for ldi_handles dcmd
63 67 */
64 68 #define LH_IDENTINFO 0x1
65 69
66 70 /*
67 71 * LDI walkers
68 72 */
69 73 int
70 74 ldi_handle_walk_init(mdb_walk_state_t *wsp)
71 75 {
72 76 lh_walk_t *lhwp;
73 77 GElf_Sym sym;
74 78
75 79 /* get the address of the hash table */
76 80 if (mdb_lookup_by_name("ldi_handle_hash", &sym) == -1) {
77 81 mdb_warn("couldn't find ldi_handle_hash");
78 82 return (WALK_ERR);
79 83 }
80 84
81 85 lhwp = mdb_alloc(sizeof (lh_walk_t), UM_SLEEP|UM_GC);
82 86 lhwp->hash = (struct ldi_handle **)(uintptr_t)sym.st_value;
83 87 lhwp->index = 0;
84 88
85 89 /* get the address of the first element in the first hash bucket */
86 90 if ((mdb_vread(&lhwp->lhp, sizeof (struct ldi_handle *),
87 91 (uintptr_t)lhwp->hash)) == -1) {
88 92 mdb_warn("couldn't read ldi handle hash at %p", lhwp->hash);
89 93 return (WALK_ERR);
90 94 }
91 95
92 96 wsp->walk_addr = (uintptr_t)lhwp->lhp;
93 97 wsp->walk_data = lhwp;
94 98
95 99 return (WALK_NEXT);
96 100 }
97 101
98 102 int
99 103 ldi_handle_walk_step(mdb_walk_state_t *wsp)
100 104 {
101 105 lh_walk_t *lhwp = (lh_walk_t *)wsp->walk_data;
102 106 int status;
103 107
104 108 /* check if we need to go to the next hash bucket */
105 109 while (wsp->walk_addr == 0) {
106 110
107 111 /* advance to the next bucket */
108 112 if (++(lhwp->index) >= LH_HASH_SZ)
109 113 return (WALK_DONE);
110 114
111 115 /* get handle address from the hash bucket */
112 116 if ((mdb_vread(&lhwp->lhp, sizeof (struct ldi_handle *),
113 117 (uintptr_t)(lhwp->hash + lhwp->index))) == -1) {
114 118 mdb_warn("couldn't read ldi handle hash at %p",
115 119 (uintptr_t)lhwp->hash + lhwp->index);
116 120 return (WALK_ERR);
117 121 }
118 122
119 123 wsp->walk_addr = (uintptr_t)lhwp->lhp;
120 124 }
121 125
122 126 /* invoke the walker callback for this hash element */
123 127 status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
124 128 if (status != WALK_NEXT)
125 129 return (status);
126 130
127 131 /* get a pointer to the next hash element */
128 132 if (mdb_vread(&lhwp->buf, sizeof (struct ldi_handle),
129 133 wsp->walk_addr) == -1) {
130 134 mdb_warn("couldn't read ldi handle at %p", wsp->walk_addr);
131 135 return (WALK_ERR);
132 136 }
133 137 wsp->walk_addr = (uintptr_t)lhwp->buf.lh_next;
134 138 return (WALK_NEXT);
135 139 }
136 140
137 141 int
138 142 ldi_ident_walk_init(mdb_walk_state_t *wsp)
139 143 {
140 144 li_walk_t *liwp;
141 145 GElf_Sym sym;
142 146
143 147 /* get the address of the hash table */
144 148 if (mdb_lookup_by_name("ldi_ident_hash", &sym) == -1) {
145 149 mdb_warn("couldn't find ldi_ident_hash");
146 150 return (WALK_ERR);
147 151 }
148 152
149 153 liwp = mdb_alloc(sizeof (li_walk_t), UM_SLEEP|UM_GC);
150 154 liwp->hash = (struct ldi_ident **)(uintptr_t)sym.st_value;
151 155 liwp->index = 0;
152 156
153 157 /* get the address of the first element in the first hash bucket */
154 158 if ((mdb_vread(&liwp->lip, sizeof (struct ldi_ident *),
155 159 (uintptr_t)liwp->hash)) == -1) {
156 160 mdb_warn("couldn't read ldi ident hash at %p", liwp->hash);
157 161 return (WALK_ERR);
158 162 }
159 163
160 164 wsp->walk_addr = (uintptr_t)liwp->lip;
161 165 wsp->walk_data = liwp;
162 166
163 167 return (WALK_NEXT);
164 168 }
165 169
166 170 int
167 171 ldi_ident_walk_step(mdb_walk_state_t *wsp)
168 172 {
169 173 li_walk_t *liwp = (li_walk_t *)wsp->walk_data;
170 174 int status;
171 175
172 176 /* check if we need to go to the next hash bucket */
173 177 while (wsp->walk_addr == 0) {
174 178
175 179 /* advance to the next bucket */
176 180 if (++(liwp->index) >= LI_HASH_SZ)
177 181 return (WALK_DONE);
178 182
179 183 /* get handle address from the hash bucket */
180 184 if ((mdb_vread(&liwp->lip, sizeof (struct ldi_ident *),
181 185 (uintptr_t)(liwp->hash + liwp->index))) == -1) {
182 186 mdb_warn("couldn't read ldi ident hash at %p",
183 187 (uintptr_t)liwp->hash + liwp->index);
184 188 return (WALK_ERR);
185 189 }
186 190
187 191 wsp->walk_addr = (uintptr_t)liwp->lip;
188 192 }
189 193
190 194 /* invoke the walker callback for this hash element */
191 195 status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
192 196 if (status != WALK_NEXT)
193 197 return (status);
194 198
195 199 /* get a pointer to the next hash element */
196 200 if (mdb_vread(&liwp->buf, sizeof (struct ldi_ident),
197 201 wsp->walk_addr) == -1) {
198 202 mdb_warn("couldn't read ldi ident at %p", wsp->walk_addr);
199 203 return (WALK_ERR);
200 204 }
201 205 wsp->walk_addr = (uintptr_t)liwp->buf.li_next;
202 206 return (WALK_NEXT);
203 207 }
204 208
205 209 /*
206 210 * LDI dcmds
207 211 */
208 212 static void
209 213 ldi_ident_header(int start, int refs)
210 214 {
211 215 if (start) {
212 216 mdb_printf("%-?s ", "IDENT");
213 217 } else {
214 218 mdb_printf("%?s ", "IDENT");
215 219 }
216 220
217 221 if (refs)
218 222 mdb_printf("%4s ", "REFS");
219 223
220 224 mdb_printf("%?s %5s %5s %s\n", "DIP", "MINOR", "MODID", "MODULE NAME");
221 225 }
222 226
223 227 static int
224 228 ldi_ident_print(uintptr_t addr, int refs)
225 229 {
226 230 struct ldi_ident li;
227 231
228 232 /* read the ldi ident */
229 233 if (mdb_vread(&li, sizeof (struct ldi_ident), addr) == -1) {
230 234 mdb_warn("couldn't read ldi ident at %p", addr);
231 235 return (1);
232 236 }
233 237
234 238 /* display the ident address */
235 239 mdb_printf("%0?p ", addr);
236 240
237 241 /* display the ref count */
238 242 if (refs)
239 243 mdb_printf("%4u ", li.li_ref);
240 244
241 245 /* display the dip (if any) */
242 246 if (li.li_dip != NULL) {
243 247 mdb_printf("%0?p ", li.li_dip);
244 248 } else {
245 249 mdb_printf("%?s ", "-");
246 250 }
247 251
248 252 /* display the minor node (if any) */
249 253 if (li.li_dev != DDI_DEV_T_NONE) {
250 254 mdb_printf("%5u ", getminor(li.li_dev));
251 255 } else {
252 256 mdb_printf("%5s ", "-");
253 257 }
254 258
255 259 /* display the module info */
256 260 mdb_printf("%5d %s\n", li.li_modid, li.li_modname);
257 261
258 262 return (0);
259 263 }
260 264
261 265 int
262 266 ldi_ident(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
263 267 {
264 268 int start = 1;
265 269 int refs = 1;
266 270
267 271 /* Determine if there is an ldi identifier address */
268 272 if (!(flags & DCMD_ADDRSPEC)) {
269 273 if (mdb_walk_dcmd("ldi_ident", "ldi_ident",
270 274 argc, argv) == -1) {
271 275 mdb_warn("can't walk ldi idents");
272 276 return (DCMD_ERR);
273 277 }
274 278 return (DCMD_OK);
275 279 }
276 280
277 281 /* display the header line */
278 282 if (DCMD_HDRSPEC(flags))
279 283 ldi_ident_header(start, refs);
280 284
281 285 /* display the ldi ident */
282 286 if (ldi_ident_print(addr, refs))
283 287 return (DCMD_ERR);
284 288
285 289 return (DCMD_OK);
286 290 }
287 291
288 292 static void
289 293 ldi_handle_header(int refs, int ident) {
290 294 mdb_printf("%-?s ", "HANDLE");
291 295
292 296 if (refs)
293 297 mdb_printf("%4s ", "REFS");
294 298
295 299 mdb_printf("%?s %10s %5s %?s ", "VNODE", "DRV", "MINOR", "EVENTS");
296 300
297 301 if (!ident) {
298 302 mdb_printf("%?s\n", "IDENT");
299 303 } else {
300 304 ldi_ident_header(0, 0);
301 305 }
302 306 }
303 307
304 308 static int
305 309 ldi_handle_print(uintptr_t addr, int ident, int refs)
306 310 {
307 311 vnode_t vnode;
308 312 struct ldi_handle lh;
309 313 const char *name;
310 314
311 315 /* read in the ldi handle */
312 316 if (mdb_vread(&lh, sizeof (struct ldi_handle), addr) == -1) {
313 317 mdb_warn("couldn't read ldi handle at %p", addr);
314 318 return (DCMD_ERR);
315 319 }
316 320
317 321 /* display the handle address */
318 322 mdb_printf("%0?p ", addr);
319 323
320 324 /* display the ref count */
321 325 if (refs)
322 326 mdb_printf("%4u ", lh.lh_ref);
323 327
324 328 /* display the vnode */
325 329 mdb_printf("%0?p ", lh.lh_vp);
326 330
327 331 /* read in the vnode associated with the handle */
328 332 addr = (uintptr_t)lh.lh_vp;
329 333 if (mdb_vread(&vnode, sizeof (vnode_t), addr) == -1) {
330 334 mdb_warn("couldn't read vnode at %p", addr);
331 335 return (1);
332 336 }
333 337
334 338 /* display the driver name */
335 339 if ((name = mdb_major_to_name(getmajor(vnode.v_rdev))) == NULL) {
336 340 mdb_warn("failed to convert major number to name\n");
337 341 return (1);
338 342 }
339 343 mdb_printf("%10s ", name);
340 344
341 345 /* display the minor number */
342 346 mdb_printf("%5d ", getminor(vnode.v_rdev));
343 347
344 348 /* display the event pointer (if any) */
345 349 if (lh.lh_events != NULL) {
346 350 mdb_printf("%0?p ", lh.lh_events);
347 351 } else {
348 352 mdb_printf("%?s ", "-");
349 353 }
350 354
351 355 if (!ident) {
352 356 /* display the ident address */
353 357 mdb_printf("%0?p\n", lh.lh_ident);
354 358 return (0);
355 359 }
356 360
357 361 /* display the entire ident */
358 362 return (ldi_ident_print((uintptr_t)lh.lh_ident, refs));
359 363 }
360 364
361 365 int
362 366 ldi_handle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
363 367 {
364 368 int ident = 0;
365 369 int refs = 1;
366 370
367 371 if (mdb_getopts(argc, argv,
368 372 'i', MDB_OPT_SETBITS, TRUE, &ident) != argc)
369 373 return (DCMD_USAGE);
↓ open down ↓ |
333 lines elided |
↑ open up ↑ |
370 374
371 375 if (ident)
372 376 refs = 0;
373 377
374 378 /* Determine if there is an ldi handle address */
375 379 if (!(flags & DCMD_ADDRSPEC)) {
376 380 if (mdb_walk_dcmd("ldi_handle", "ldi_handle",
377 381 argc, argv) == -1) {
378 382 mdb_warn("can't walk ldi handles");
379 383 return (DCMD_ERR);
380 - } return (DCMD_OK);
384 + }
385 + return (DCMD_OK);
381 386 }
382 387
383 388 /* display the header line */
384 389 if (DCMD_HDRSPEC(flags))
385 390 ldi_handle_header(refs, ident);
386 391
387 392 /* display the ldi handle */
388 393 if (ldi_handle_print(addr, ident, refs))
389 394 return (DCMD_ERR);
390 395
391 396 return (DCMD_OK);
392 397 }
393 398
394 399 void
395 400 ldi_ident_help(void)
396 401 {
397 402 mdb_printf("Displays an ldi identifier.\n"
398 403 "Without the address of an \"ldi_ident_t\", "
399 404 "print all identifiers.\n"
400 405 "With an address, print the specified identifier.\n");
401 406 }
402 407
403 408 void
404 409 ldi_handle_help(void)
405 410 {
406 411 mdb_printf("Displays an ldi handle.\n"
407 412 "Without the address of an \"ldi_handle_t\", "
408 413 "print all handles.\n"
409 414 "With an address, print the specified handle.\n\n"
410 415 "Switches:\n"
411 416 " -i print the module identifier information\n");
412 417 }
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX