Print this page
10132 smatch fixes for MDB
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/modules/fcp/fcp.c
+++ new/usr/src/cmd/mdb/common/modules/fcp/fcp.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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 *
25 - * FCP mdb module
25 + * Copyright (c) 2018, Joyent, Inc.
26 26 */
27 27
28 28
29 29 #include <sys/mdb_modapi.h>
30 30 #include <sys/mutex.h>
31 31 #include <sys/modctl.h>
32 32 #include <sys/scsi/scsi.h>
33 33 #include <sys/sunndi.h>
34 34 #include <sys/fibre-channel/fc.h>
35 35 #include <sys/fibre-channel/ulp/fcpvar.h>
36 36
37 37 static struct fcp_port port;
38 38 static struct fcp_tgt tgt;
39 39 static struct fcp_lun lun;
40 40 static uint32_t tgt_hash_index;
41 41
42 42
43 43 /*
44 44 * Leadville fcp walker/dcmd code
45 45 */
46 46
47 47 static int
48 48 fcp_walk_i(mdb_walk_state_t *wsp)
49 49 {
50 50 if (wsp->walk_addr == NULL &&
51 51 mdb_readvar(&wsp->walk_addr, "fcp_port_head") == -1) {
52 52 mdb_warn("failed to read 'fcp_port_head'");
53 53 return (WALK_ERR);
54 54 }
55 55
56 56 wsp->walk_data = mdb_alloc(sizeof (struct fcp_port), UM_SLEEP);
57 57 return (WALK_NEXT);
58 58 }
59 59
60 60 static int
61 61 fcp_walk_s(mdb_walk_state_t *wsp)
62 62 {
63 63 int status;
64 64
65 65 if (wsp->walk_addr == NULL)
66 66 return (WALK_DONE);
67 67
68 68 if (mdb_vread(wsp->walk_data, sizeof (struct fcp_port),
69 69 wsp->walk_addr) == -1) {
70 70 mdb_warn("failed to read fcp_port at %p", wsp->walk_addr);
71 71 return (WALK_DONE);
72 72 }
73 73
74 74 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
75 75 wsp->walk_cbdata);
76 76
77 77 wsp->walk_addr =
78 78 (uintptr_t)(((struct fcp_port *)wsp->walk_data)->port_next);
79 79
80 80 return (status);
81 81 }
82 82
83 83 /*
84 84 * The walker's fini function is invoked at the end of each walk.
85 85 */
86 86 static void
87 87 fcp_walk_f(mdb_walk_state_t *wsp)
88 88 {
89 89 mdb_free(wsp->walk_data, sizeof (struct fcp_port));
90 90 }
91 91
92 92
93 93 static int
94 94 fcp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
95 95 {
96 96 struct fcp_port pinfo;
97 97
98 98 if (argc != 0) {
99 99 return (DCMD_USAGE);
100 100 }
101 101
102 102 if (!(flags & DCMD_ADDRSPEC)) {
103 103 if (mdb_walk_dcmd("fcp", "fcp",
104 104 argc, argv) == -1) {
105 105 mdb_warn("failed to walk 'fcp_port_head'");
106 106 return (DCMD_ERR);
107 107 }
108 108 return (DCMD_OK);
109 109 }
110 110
111 111 mdb_printf("FCP structure at %p\n", addr);
112 112
113 113 /*
114 114 * For each port, we just need to read the fc_fca_port_t struct, read
115 115 * the port_handle
116 116 */
117 117 if (mdb_vread(&pinfo, sizeof (struct fcp_port), addr) !=
118 118 sizeof (struct fcp_port)) {
119 119 mdb_warn("failed to read fcp_port at %p", addr);
120 120 return (DCMD_OK);
121 121 }
122 122
123 123 mdb_printf(" mutex : 0x%-08x\n", pinfo.port_mutex);
124 124 mdb_printf(" ipkt_list : 0x%p\n", pinfo.port_ipkt_list);
125 125 mdb_printf(" state : 0x%-08x\n", pinfo.port_state);
126 126 mdb_printf(" phys_state : 0x%-08x\n", pinfo.port_phys_state);
127 127 mdb_printf(" top : %u\n", pinfo.port_topology);
128 128 mdb_printf(" sid : 0x%-06x\n", pinfo.port_id);
129 129 mdb_printf(" reset_list : 0x%p\n", pinfo.port_reset_list);
130 130 mdb_printf(" link_cnt : %u\n", pinfo.port_link_cnt);
131 131 mdb_printf(" deadline : %d\n", pinfo.port_deadline);
132 132 mdb_printf(" port wwn : "
133 133 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
134 134 pinfo.port_pwwn.raw_wwn[0], pinfo.port_pwwn.raw_wwn[1],
135 135 pinfo.port_pwwn.raw_wwn[2], pinfo.port_pwwn.raw_wwn[3],
136 136 pinfo.port_pwwn.raw_wwn[4], pinfo.port_pwwn.raw_wwn[5],
137 137 pinfo.port_pwwn.raw_wwn[6], pinfo.port_pwwn.raw_wwn[7]);
138 138 mdb_printf(" node wwn : "
139 139 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
140 140 pinfo.port_nwwn.raw_wwn[0], pinfo.port_nwwn.raw_wwn[1],
141 141 pinfo.port_nwwn.raw_wwn[2], pinfo.port_nwwn.raw_wwn[3],
142 142 pinfo.port_nwwn.raw_wwn[4], pinfo.port_nwwn.raw_wwn[5],
143 143 pinfo.port_nwwn.raw_wwn[6], pinfo.port_nwwn.raw_wwn[7]);
144 144 mdb_printf(" handle : 0x%p\n", pinfo.port_fp_handle);
145 145 mdb_printf(" cmd_mutex : 0x%-08x\n", pinfo.port_pkt_mutex);
146 146 mdb_printf(" ncmds : %u\n", pinfo.port_npkts);
147 147 mdb_printf(" pkt_head : 0x%p\n", pinfo.port_pkt_head);
148 148 mdb_printf(" pkt_tail : 0x%p\n", pinfo.port_pkt_tail);
149 149 mdb_printf(" ipkt_cnt : %d\n", pinfo.port_ipkt_cnt);
150 150 mdb_printf(" instance : %u\n", pinfo.port_instance);
151 151 mdb_printf(" max_exch : %u\n", pinfo.port_max_exch);
152 152 mdb_printf(" cmds_aborted : 0x%-08x\n",
153 153 pinfo.port_reset_action);
154 154 mdb_printf(" cmds_dma_flags : 0x%-08x\n",
155 155 pinfo.port_cmds_dma_flags);
156 156 mdb_printf(" fcp_dma : 0x%-08x\n", pinfo.port_fcp_dma);
157 157 mdb_printf(" priv_pkt_len : %u\n", pinfo.port_priv_pkt_len);
158 158 mdb_printf(" data_dma_attr : 0x%-08x\n",
159 159 pinfo.port_data_dma_attr);
160 160 mdb_printf(" cmd_dma_attr : 0x%-08x\n",
161 161 pinfo.port_cmd_dma_attr);
162 162 mdb_printf(" resp_dma_attr : 0x%-08x\n",
163 163 pinfo.port_resp_dma_attr);
164 164 mdb_printf(" dma_acc_attr : 0x%-08x\n",
165 165 pinfo.port_dma_acc_attr);
166 166 mdb_printf(" tran : 0x%p\n", pinfo.port_tran);
167 167 mdb_printf(" dip : 0x%p\n", pinfo.port_dip);
168 168 mdb_printf(" reset_notify_listf: 0x%p\n",
169 169 pinfo.port_reset_notify_listf);
170 170 mdb_printf(" event_defs : 0x%p\n", pinfo.port_ndi_event_defs);
171 171 mdb_printf(" event_hdl : 0x%p\n", pinfo.port_ndi_event_hdl);
172 172 mdb_printf(" events : 0x%p\n", pinfo.port_ndi_events);
173 173 mdb_printf(" tgt_hash_table : 0x%p\n", pinfo.port_tgt_hash_table);
174 174 mdb_printf(" mpxio : %d\n", pinfo.port_mpxio);
175 175
176 176 mdb_printf("\n");
177 177
178 178 return (DCMD_OK);
179 179 }
180 180
181 181
182 182 /*
183 183 * Leadville cmds walker/dcmd code
184 184 */
185 185
186 186 static int
187 187 cmds_walk_i(mdb_walk_state_t *wsp)
188 188 {
189 189 if (wsp->walk_addr == NULL) {
190 190 mdb_warn("Can not perform global walk");
191 191 return (WALK_ERR);
192 192 }
193 193
194 194 /*
195 195 * Input should be a fcp_lun, so read it to get the fcp_pkt
196 196 * lists's head
197 197 */
198 198
199 199 if (mdb_vread(&lun, sizeof (struct fcp_lun), wsp->walk_addr) !=
200 200 sizeof (struct fcp_lun)) {
201 201 mdb_warn("Unable to read in the fcp_lun structure address\n");
202 202 return (WALK_ERR);
203 203 }
204 204
205 205 wsp->walk_addr = (uintptr_t)(lun.lun_pkt_head);
206 206 wsp->walk_data = mdb_alloc(sizeof (struct fcp_pkt), UM_SLEEP);
207 207
208 208 return (WALK_NEXT);
209 209 }
210 210
211 211 static int
212 212 cmds_walk_s(mdb_walk_state_t *wsp)
213 213 {
214 214 int status;
215 215
216 216 if (wsp->walk_addr == NULL)
217 217 return (WALK_DONE);
218 218
219 219 if (mdb_vread(wsp->walk_data, sizeof (struct fcp_pkt),
220 220 wsp->walk_addr) == -1) {
221 221 mdb_warn("failed to read fcp_pkt at %p", wsp->walk_addr);
222 222 return (WALK_DONE);
223 223 }
224 224
225 225 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
226 226 wsp->walk_cbdata);
227 227
228 228 wsp->walk_addr =
229 229 (uintptr_t)(((struct fcp_pkt *)wsp->walk_data)->cmd_forw);
230 230
231 231 return (status);
232 232 }
233 233
234 234 /*
235 235 * The walker's fini function is invoked at the end of each walk.
236 236 */
237 237 static void
238 238 cmds_walk_f(mdb_walk_state_t *wsp)
239 239 {
240 240 mdb_free(wsp->walk_data, sizeof (struct fcp_pkt));
241 241 }
242 242
243 243
244 244 /*
245 245 * Leadville luns walker/dcmd code
246 246 */
247 247
248 248 static int
249 249 luns_walk_i(mdb_walk_state_t *wsp)
250 250 {
251 251 if (wsp->walk_addr == NULL) {
252 252 mdb_warn("Can not perform global walk");
253 253 return (WALK_ERR);
254 254 }
255 255
256 256 /*
257 257 * Input should be a fcp_tgt, so read it to get the fcp_lun
258 258 * lists's head
259 259 */
260 260
261 261 if (mdb_vread(&tgt, sizeof (struct fcp_tgt), wsp->walk_addr) !=
262 262 sizeof (struct fcp_tgt)) {
263 263 mdb_warn("Unable to read in the fcp_tgt structure address\n");
264 264 return (WALK_ERR);
265 265 }
266 266
267 267 wsp->walk_addr = (uintptr_t)(tgt.tgt_lun);
268 268 wsp->walk_data = mdb_alloc(sizeof (struct fcp_lun), UM_SLEEP);
269 269
270 270 return (WALK_NEXT);
271 271 }
272 272
273 273 static int
274 274 luns_walk_s(mdb_walk_state_t *wsp)
275 275 {
276 276 int status;
277 277
278 278 if (wsp->walk_addr == NULL)
279 279 return (WALK_DONE);
280 280
281 281 if (mdb_vread(wsp->walk_data, sizeof (struct fcp_lun),
282 282 wsp->walk_addr) == -1) {
283 283 mdb_warn("failed to read fcp_pkt at %p", wsp->walk_addr);
284 284 return (WALK_DONE);
285 285 }
286 286
287 287 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
288 288 wsp->walk_cbdata);
289 289
290 290 wsp->walk_addr =
291 291 (uintptr_t)(((struct fcp_lun *)wsp->walk_data)->lun_next);
292 292
293 293 return (status);
294 294 }
295 295
296 296 /*
297 297 * The walker's fini function is invoked at the end of each walk.
298 298 */
299 299 static void
300 300 luns_walk_f(mdb_walk_state_t *wsp)
301 301 {
302 302 mdb_free(wsp->walk_data, sizeof (struct fcp_lun));
303 303 }
304 304
305 305
306 306 /*
307 307 * Leadville targets walker/dcmd code
308 308 */
309 309
310 310 static int
311 311 targets_walk_i(mdb_walk_state_t *wsp)
312 312 {
313 313 if (wsp->walk_addr == NULL) {
314 314 mdb_warn("Can not perform global walk\n");
315 315 return (WALK_ERR);
316 316 }
317 317
318 318 /*
319 319 * Input should be a fcp_port, so read it to get the port_tgt
320 320 * table's head
↓ open down ↓ |
285 lines elided |
↑ open up ↑ |
321 321 */
322 322
323 323 if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) !=
324 324 sizeof (struct fcp_port)) {
325 325 mdb_warn("Unable to read in the port structure address\n");
326 326 return (WALK_ERR);
327 327 }
328 328
329 329 tgt_hash_index = 0;
330 330
331 - while ((port.port_tgt_hash_table[tgt_hash_index] == NULL) &&
332 - (tgt_hash_index < FCP_NUM_HASH)) {
331 + while (tgt_hash_index < FCP_NUM_HASH &&
332 + port.port_tgt_hash_table[tgt_hash_index] == NULL) {
333 333 tgt_hash_index++;
334 334 }
335 335
336 336 wsp->walk_addr = (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]);
337 337
338 338 wsp->walk_data = mdb_alloc(sizeof (struct fcp_tgt), UM_SLEEP);
339 339
340 340 return (WALK_NEXT);
341 341 }
342 342
343 343 static int
344 344 targets_walk_s(mdb_walk_state_t *wsp)
345 345 {
346 346 int status;
347 347
348 348 if ((wsp->walk_addr == NULL) &&
349 349 (tgt_hash_index >= (FCP_NUM_HASH - 1))) {
350 350 return (WALK_DONE);
351 351 }
352 352
353 353 if (mdb_vread(wsp->walk_data, sizeof (struct fcp_tgt),
354 354 wsp->walk_addr) == -1) {
355 355 mdb_warn("failed to read fcp_tgt at %p", wsp->walk_addr);
356 356 return (WALK_DONE);
357 357 }
358 358
359 359 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
360 360 wsp->walk_cbdata);
361 361
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
362 362 wsp->walk_addr =
363 363 (uintptr_t)(((struct fcp_tgt *)wsp->walk_data)->tgt_next);
364 364
365 365 if (wsp->walk_addr == NULL) {
366 366 /*
367 367 * locate the next hash list
368 368 */
369 369
370 370 tgt_hash_index++;
371 371
372 - while ((port.port_tgt_hash_table[tgt_hash_index] == NULL) &&
373 - (tgt_hash_index < FCP_NUM_HASH)) {
372 + while (tgt_hash_index < FCP_NUM_HASH &&
373 + port.port_tgt_hash_table[tgt_hash_index] == NULL)
374 374 tgt_hash_index++;
375 - }
376 375
377 376 if (tgt_hash_index == FCP_NUM_HASH) {
378 377 /* You're done */
379 378 return (status);
380 379 }
381 380
382 381 wsp->walk_addr =
383 382 (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]);
384 383 }
385 384
386 385 return (status);
387 386 }
388 387
389 388 /*
390 389 * The walker's fini function is invoked at the end of each walk.
391 390 */
392 391 static void
393 392 targets_walk_f(mdb_walk_state_t *wsp)
394 393 {
395 394 mdb_free(wsp->walk_data, sizeof (struct fcp_tgt));
396 395 }
397 396
398 397
399 398 /*
400 399 * Leadville fcp_ipkt walker/dcmd code
401 400 */
402 401
403 402 static int
404 403 ipkt_walk_i(mdb_walk_state_t *wsp)
405 404 {
406 405 if (wsp->walk_addr == NULL) {
407 406 mdb_warn("The address of a fcp_port"
408 407 " structure must be given\n");
409 408 return (WALK_ERR);
410 409 }
411 410
412 411 /*
413 412 * Input should be a fcp_port, so read it to get the ipkt
414 413 * list's head
415 414 */
416 415
417 416 if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) !=
418 417 sizeof (struct fcp_port)) {
419 418 mdb_warn("Failed to read in the fcp_port"
420 419 " at 0x%p\n", wsp->walk_addr);
421 420 return (WALK_ERR);
422 421 }
423 422
424 423 wsp->walk_addr = (uintptr_t)(port.port_ipkt_list);
425 424 wsp->walk_data = mdb_alloc(sizeof (struct fcp_ipkt), UM_SLEEP);
426 425
427 426 return (WALK_NEXT);
428 427 }
429 428
430 429 static int
431 430 ipkt_walk_s(mdb_walk_state_t *wsp)
432 431 {
433 432 int status;
434 433
435 434 if (wsp->walk_addr == NULL)
436 435 return (WALK_DONE);
437 436
438 437 if (mdb_vread(wsp->walk_data, sizeof (struct fcp_ipkt),
439 438 wsp->walk_addr) == -1) {
440 439 mdb_warn("Failed to read in the fcp_ipkt"
441 440 " at 0x%p\n", wsp->walk_addr);
442 441 return (WALK_DONE);
443 442 }
444 443
445 444 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
446 445 wsp->walk_cbdata);
447 446
448 447 wsp->walk_addr =
449 448 (uintptr_t)(((struct fcp_ipkt *)wsp->walk_data)->ipkt_next);
450 449
451 450 return (status);
452 451 }
453 452
454 453 /*
455 454 * The walker's fini function is invoked at the end of each walk.
456 455 */
457 456 static void
458 457 ipkt_walk_f(mdb_walk_state_t *wsp)
459 458 {
460 459 mdb_free(wsp->walk_data, sizeof (struct fcp_ipkt));
461 460 }
462 461
463 462 /*
464 463 * Leadville fcp_pkt walker/dcmd code
465 464 */
466 465
467 466 static int
468 467 pkt_walk_i(mdb_walk_state_t *wsp)
469 468 {
470 469 if (wsp->walk_addr == NULL) {
471 470 mdb_warn("The address of a fcp_port"
472 471 " structure must be given\n");
473 472 return (WALK_ERR);
474 473 }
475 474
476 475 /*
477 476 * Input should be an fcp_port, so read it to get the pkt
478 477 * list's head
479 478 */
480 479
481 480 if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) !=
482 481 sizeof (struct fcp_port)) {
483 482 mdb_warn("Failed to read in the fcp_port"
484 483 " at 0x%p\n", wsp->walk_addr);
485 484 return (WALK_ERR);
486 485 }
487 486
488 487 wsp->walk_addr = (uintptr_t)(port.port_pkt_head);
489 488 wsp->walk_data = mdb_alloc(sizeof (struct fcp_pkt), UM_SLEEP);
490 489
491 490 return (WALK_NEXT);
492 491 }
493 492
494 493 static int
495 494 pkt_walk_s(mdb_walk_state_t *wsp)
496 495 {
497 496 int status;
498 497
499 498 if (wsp->walk_addr == NULL)
500 499 return (WALK_DONE);
501 500
502 501 if (mdb_vread(wsp->walk_data, sizeof (struct fcp_pkt),
503 502 wsp->walk_addr) == -1) {
504 503 mdb_warn("Failed to read in the fcp_pkt"
505 504 " at 0x%p\n", wsp->walk_addr);
506 505 return (WALK_DONE);
507 506 }
508 507
509 508 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
510 509 wsp->walk_cbdata);
511 510
512 511 wsp->walk_addr =
513 512 (uintptr_t)(((struct fcp_pkt *)wsp->walk_data)->cmd_next);
514 513
515 514 return (status);
516 515 }
517 516
518 517 /*
519 518 * The walker's fini function is invoked at the end of each walk.
520 519 */
521 520 static void
522 521 pkt_walk_f(mdb_walk_state_t *wsp)
523 522 {
524 523 mdb_free(wsp->walk_data, sizeof (struct fcp_pkt));
525 524 }
526 525
527 526 /*
528 527 * MDB module linkage information:
529 528 *
530 529 * We declare a list of structures describing our dcmds, a list of structures
531 530 * describing our walkers, and a function named _mdb_init to return a pointer
532 531 * to our module information.
533 532 */
534 533
535 534 static const mdb_dcmd_t dcmds[] = {
536 535 { "fcp", NULL, "Leadville fcp instances", fcp },
537 536 { NULL }
538 537 };
539 538
540 539 static const mdb_walker_t walkers[] = {
541 540 { "fcp", "Walk list of Leadville fcp instances",
542 541 fcp_walk_i, fcp_walk_s, fcp_walk_f },
543 542 { "cmds", "Walk list of SCSI commands in fcp's per-lun queue",
544 543 cmds_walk_i, cmds_walk_s, cmds_walk_f },
545 544 { "luns", "Walk list of LUNs in an fcp target",
546 545 luns_walk_i, luns_walk_s, luns_walk_f },
547 546 { "targets", "Walk list of fcp targets attached to the local port",
548 547 targets_walk_i, targets_walk_s, targets_walk_f },
549 548 { "fcp_ipkt", "Walk list of internal packets queued on a local port",
550 549 ipkt_walk_i, ipkt_walk_s, ipkt_walk_f},
551 550 { "fcp_pkt", "Walk list of packets queued on a local port",
552 551 pkt_walk_i, pkt_walk_s, pkt_walk_f},
553 552 { NULL }
554 553 };
555 554
556 555 static const mdb_modinfo_t modinfo = {
557 556 MDB_API_VERSION, dcmds, walkers
558 557 };
559 558
560 559 const mdb_modinfo_t *
561 560 _mdb_init(void)
562 561 {
563 562 return (&modinfo);
564 563 }
↓ open down ↓ |
179 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX