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/fctl/fctl.c
+++ new/usr/src/cmd/mdb/common/modules/fctl/fctl.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
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
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 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 +/*
27 + * Copyright (c) 2018, Joyent, Inc.
28 + */
26 29
27 30 #include <sys/mdb_modapi.h>
28 31 #include <sys/mutex.h>
29 32 #include <sys/modctl.h>
30 33 #include <time.h>
31 34 #include <sys/fibre-channel/fc.h>
32 35 #include <sys/fibre-channel/impl/fctl_private.h>
33 36 #include <sys/fibre-channel/impl/fc_ulpif.h>
34 37 #include <sys/fibre-channel/impl/fc_portif.h>
35 38 #include <sys/fibre-channel/impl/fc_fcaif.h>
36 39
37 40
38 41 /*
39 42 * If we #include <string.h> then other definitions fail. This is
40 43 * the easiest way of getting access to the function
41 44 */
42 45 extern char *strtok(char *string, const char *sepset);
43 46
44 47 /* we need 26 bytes for the cftime() call */
45 48 #define TIMESTAMPSIZE 26 * sizeof (char)
46 49
47 50 /* for backward compatibility */
48 51 typedef struct fc_trace_dmsgv1 {
49 52 int id_size;
50 53 int id_flag;
51 54 time_t id_time;
52 55 caddr_t id_buf;
53 56 struct fc_trace_dmsgv1 *id_next;
54 57 } fc_trace_dmsgv1_t;
55 58
56 59 static struct pwwn_hash *fp_pwwn_table;
57 60 static struct d_id_hash *fp_did_table;
58 61 static uint32_t pd_hash_index;
59 62 struct fc_local_port port;
60 63
61 64 /*
62 65 * Leadville port walker/dcmd code
63 66 */
64 67
65 68 /*
66 69 * Initialize the fc_fca_port_t walker by either using the given starting
67 70 * address, or reading the value of the kernel's fctl_fca_portlist pointer.
68 71 * We also allocate a fc_fca_port_t for storage, and save this using the
69 72 * walk_data pointer.
70 73 */
71 74 static int
72 75 port_walk_i(mdb_walk_state_t *wsp)
73 76 {
74 77 if (wsp->walk_addr == NULL &&
75 78 mdb_readvar(&wsp->walk_addr, "fctl_fca_portlist") == -1) {
76 79 mdb_warn("failed to read 'fctl_fca_portlist'");
77 80 return (WALK_ERR);
78 81 }
79 82
80 83 wsp->walk_data = mdb_alloc(sizeof (fc_fca_port_t), UM_SLEEP);
81 84 return (WALK_NEXT);
82 85 }
83 86
84 87 /*
85 88 * At each step, read a fc_fca_port_t into our private storage, and then invoke
86 89 * the callback function. We terminate when we reach a NULL p_next pointer.
87 90 */
88 91 static int
89 92 port_walk_s(mdb_walk_state_t *wsp)
90 93 {
91 94 int status;
92 95
93 96 if (wsp->walk_addr == NULL)
94 97 return (WALK_DONE);
95 98
96 99 if (mdb_vread(wsp->walk_data, sizeof (fc_fca_port_t), wsp->walk_addr)
97 100 == -1) {
98 101 mdb_warn("failed to read fc_fca_port_t at %p", wsp->walk_addr);
99 102 return (WALK_DONE);
100 103 }
101 104
102 105 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
103 106 wsp->walk_cbdata);
104 107
105 108 wsp->walk_addr =
106 109 (uintptr_t)(((fc_fca_port_t *)wsp->walk_data)->port_next);
107 110
108 111 return (status);
109 112 }
110 113
111 114 /*
112 115 * The walker's fini function is invoked at the end of each walk. Since we
113 116 * dynamically allocated a fc_fca_port_t in port_walk_i, we must free it now.
114 117 */
115 118 static void
116 119 port_walk_f(mdb_walk_state_t *wsp)
117 120 {
118 121 mdb_free(wsp->walk_data, sizeof (fc_fca_port_t));
119 122 }
120 123
121 124
122 125 static int
123 126 ports(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
124 127 {
125 128 fc_fca_port_t portlist;
126 129 fc_local_port_t port;
127 130 int longlist = FALSE;
128 131
129 132 if (argc > 1) {
130 133 return (DCMD_USAGE);
131 134 }
132 135
133 136 if (mdb_getopts(argc, argv,
134 137 'l', MDB_OPT_SETBITS, TRUE, &longlist) != argc) {
135 138 return (DCMD_USAGE);
136 139 }
137 140
138 141
139 142 if (!(flags & DCMD_ADDRSPEC)) {
140 143 if (longlist == 0) {
141 144 if (mdb_walk_dcmd("ports", "ports",
142 145 argc, argv) == -1) {
143 146 mdb_warn("failed to walk 'fctl_fca_portlist'");
144 147 return (DCMD_ERR);
145 148 }
146 149 } else {
147 150 if (mdb_walk_dcmd("ports", "fcport",
148 151 argc, argv) == -1) {
149 152 mdb_warn("failed to walk 'fctl_fca_portlist'");
150 153 return (DCMD_ERR);
151 154 }
152 155 }
153 156
154 157 return (DCMD_OK);
155 158 }
156 159
157 160 /*
158 161 * If this is the first invocation of the command, print a nice
159 162 * header line for the output that will follow.
160 163 */
161 164 if (DCMD_HDRSPEC(flags))
162 165 mdb_printf("%16s %-2s %4s %-4s%16s %16s %16s\n",
163 166 "Port", "I#", "State", "Soft", "FCA Handle",
164 167 "Port DIP", "FCA Port DIP");
165 168
166 169 /*
167 170 * For each port, we just need to read the fc_fca_port_t struct, read
168 171 * the port_handle
169 172 */
170 173 if (mdb_vread(&portlist, sizeof (fc_fca_port_t), addr) ==
171 174 sizeof (fc_fca_port_t)) {
172 175 /*
173 176 * Now read that port in
174 177 */
175 178
176 179 if (mdb_vread(&port, sizeof (fc_local_port_t), (uintptr_t)
177 180 portlist.port_handle) == sizeof (fc_local_port_t)) {
178 181 mdb_printf("%16p %2d %4x %4x %16p %16p %16p\n",
179 182 portlist.port_handle, port.fp_instance,
180 183 port.fp_state, port.fp_soft_state,
181 184 port.fp_fca_handle, port.fp_port_dip,
182 185 port.fp_fca_dip);
183 186 } else
184 187 mdb_warn("failed to read port at %p",
185 188 portlist.port_handle);
186 189
187 190 } else
188 191 mdb_warn("failed to read port info at %p", addr);
189 192
190 193 return (DCMD_OK);
191 194 }
192 195
193 196
194 197 /*
195 198 * Leadville ULP walker/dcmd code
196 199 */
197 200
198 201 static int
199 202 ulp_walk_i(mdb_walk_state_t *wsp)
200 203 {
201 204 if (wsp->walk_addr == NULL &&
202 205 mdb_readvar(&wsp->walk_addr, "fctl_ulp_list") == -1) {
203 206 mdb_warn("failed to read 'fctl_ulp_list'");
204 207 return (WALK_ERR);
205 208 }
206 209
207 210 wsp->walk_data = mdb_alloc(sizeof (fc_ulp_list_t), UM_SLEEP);
208 211 return (WALK_NEXT);
209 212 }
210 213
211 214
212 215
213 216 static int
214 217 ulp_walk_s(mdb_walk_state_t *wsp)
215 218 {
216 219 int status;
217 220
218 221 if (wsp->walk_addr == NULL)
219 222 return (WALK_DONE);
220 223
221 224 if (mdb_vread(wsp->walk_data, sizeof (fc_ulp_list_t), wsp->walk_addr)
222 225 == -1) {
223 226 mdb_warn("failed to read fctl_ulp_list %p", wsp->walk_addr);
224 227 return (WALK_DONE);
225 228 }
226 229
227 230 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
228 231 wsp->walk_cbdata);
229 232
230 233 wsp->walk_addr =
231 234 (uintptr_t)(((fc_ulp_list_t *)wsp->walk_data)->ulp_next);
232 235
233 236 return (status);
234 237 }
235 238
236 239
237 240 static void
238 241 ulp_walk_f(mdb_walk_state_t *wsp)
239 242 {
240 243 mdb_free(wsp->walk_data, sizeof (fc_ulp_list_t));
241 244 }
242 245
243 246
244 247 static int
245 248 ulps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
246 249 {
247 250 fc_ulp_list_t ulplist;
248 251 fc_ulp_modinfo_t ulp;
249 252 char ulp_name[30];
250 253
251 254 if (argc != 0) {
252 255 return (DCMD_USAGE);
253 256 }
254 257
255 258 /*
256 259 * If no fc_ulp_list_t address was specified on the command line, we can
257 260 * print out all processes by invoking the walker, using this
258 261 * dcmd itself as the callback.
259 262 */
260 263 if (!(flags & DCMD_ADDRSPEC)) {
261 264 if (mdb_walk_dcmd("ulps", "ulps", argc, argv) == -1) {
262 265 mdb_warn("failed to walk 'fc_ulp_list_t'");
263 266 return (DCMD_ERR);
264 267 }
265 268 return (DCMD_OK);
266 269 }
267 270
268 271 /*
269 272 * If this is the first invocation of the command, print a nice
270 273 * header line for the output that will follow.
271 274 */
272 275 if (DCMD_HDRSPEC(flags))
273 276 mdb_printf("%30s %4s %8s\n", "ULP Name", "Type", "Revision");
274 277
275 278 /*
276 279 * For each port, we just need to read the fc_fca_port_t struct, read
277 280 * the port_handle
278 281 */
279 282 if (mdb_vread(&ulplist, sizeof (fc_ulp_list_t), addr) ==
280 283 sizeof (fc_ulp_list_t)) {
281 284 /*
282 285 * Now read that port in
283 286 */
284 287
285 288 if (mdb_vread(&ulp, sizeof (fc_ulp_modinfo_t),
286 289 (uintptr_t)ulplist.ulp_info) == sizeof (fc_ulp_modinfo_t)) {
287 290 if (mdb_vread(&ulp_name, 30,
288 291 (uintptr_t)ulp.ulp_name) > 0) {
289 292 mdb_printf("%30s %4x %8x\n",
290 293 ulp_name, ulp.ulp_type, ulp.ulp_rev);
291 294 }
292 295 } else
293 296 mdb_warn("failed to read ulp at %p",
294 297 ulplist.ulp_info);
295 298
296 299 } else
297 300 mdb_warn("failed to read ulplist at %p", addr);
298 301
299 302 return (DCMD_OK);
300 303 }
301 304
302 305
303 306
304 307 /*
305 308 * Leadville ULP module walker/dcmd code
306 309 */
307 310
308 311 static int
309 312 ulpmod_walk_i(mdb_walk_state_t *wsp)
310 313 {
311 314 if (wsp->walk_addr == NULL &&
312 315 mdb_readvar(&wsp->walk_addr, "fctl_ulp_modules") == -1) {
313 316 mdb_warn("failed to read 'fctl_ulp_modules'");
314 317 return (WALK_ERR);
315 318 }
316 319
317 320 wsp->walk_data = mdb_alloc(sizeof (fc_ulp_module_t), UM_SLEEP);
318 321 return (WALK_NEXT);
319 322 }
320 323
321 324
322 325
323 326 static int
324 327 ulpmod_walk_s(mdb_walk_state_t *wsp)
325 328 {
326 329 int status;
327 330
328 331 if (wsp->walk_addr == NULL)
329 332 return (WALK_DONE);
330 333
331 334 if (mdb_vread(wsp->walk_data, sizeof (fc_ulp_module_t), wsp->walk_addr)
332 335 == -1) {
333 336 mdb_warn("failed to read fctl_ulp_modules %p", wsp->walk_addr);
334 337 return (WALK_DONE);
335 338 }
336 339
337 340 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
338 341 wsp->walk_cbdata);
339 342
340 343 wsp->walk_addr =
341 344 (uintptr_t)(((fc_ulp_module_t *)wsp->walk_data)->mod_next);
342 345
343 346 return (status);
344 347 }
345 348
346 349
347 350 static void
348 351 ulpmod_walk_f(mdb_walk_state_t *wsp)
349 352 {
350 353 mdb_free(wsp->walk_data, sizeof (fc_ulp_module_t));
351 354 }
352 355
353 356
354 357 static int
355 358 ulpmods(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
356 359 {
357 360 fc_ulp_module_t modlist;
358 361 fc_ulp_modinfo_t modinfo;
359 362 fc_ulp_ports_t ulp_port;
360 363
361 364 if (argc != 0) {
362 365 return (DCMD_USAGE);
363 366 }
364 367
365 368 if (!(flags & DCMD_ADDRSPEC)) {
366 369 if (mdb_walk_dcmd("ulpmods", "ulpmods", argc, argv)
367 370 == -1) {
368 371 mdb_warn("failed to walk 'fc_ulp_module_t'");
369 372 return (DCMD_ERR);
370 373 }
371 374 return (DCMD_OK);
372 375 }
373 376
374 377 /*
375 378 * If this is the first invocation of the command, print a nice
376 379 * header line for the output that will follow.
377 380 */
378 381 if (DCMD_HDRSPEC(flags))
379 382 mdb_printf("%4s %16s %8s %8s\n",
380 383 "Type", "Port Handle", "dstate", "statec");
381 384
382 385 /*
383 386 * For each port, we just need to read the fc_fca_port_t struct, read
384 387 * the port_handle
385 388 */
386 389 if (mdb_vread(&modlist, sizeof (fc_ulp_module_t), addr) ==
387 390 sizeof (fc_ulp_module_t)) {
388 391 /*
389 392 * Now read that module info in
390 393 */
391 394
392 395 if (mdb_vread(&modinfo, sizeof (fc_ulp_modinfo_t),
393 396 (uintptr_t)modlist.mod_info) == sizeof (fc_ulp_modinfo_t)) {
394 397 /* Now read all the ports for this module */
395 398 if (mdb_vread(&ulp_port, sizeof (fc_ulp_ports_t),
396 399 (uintptr_t)modlist.mod_ports) ==
397 400 sizeof (fc_ulp_ports_t)) {
398 401 while (ulp_port.port_handle != NULL) {
399 402 mdb_printf("%4x %16p %8x %8x\n",
400 403 modinfo.ulp_type,
401 404 ulp_port.port_handle,
402 405 ulp_port.port_dstate,
403 406 ulp_port.port_statec);
404 407
405 408 if (ulp_port.port_next == NULL)
406 409 break;
407 410
408 411 mdb_vread(&ulp_port,
409 412 sizeof (fc_ulp_ports_t),
410 413 (uintptr_t)ulp_port.port_next);
411 414 }
412 415 }
413 416 } else
414 417 mdb_warn("failed to read modinfo at %p",
415 418 modlist.mod_info);
416 419
417 420 } else
418 421 mdb_warn("failed to read modlist at %p", addr);
419 422
420 423 return (DCMD_OK);
421 424 }
422 425
423 426
424 427 /*
425 428 * Display an fc_local_port_t struct
426 429 */
427 430 static int
428 431 fcport(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
429 432 {
430 433 fc_fca_port_t portlist;
431 434 fc_local_port_t port;
432 435 int idx;
433 436 int first = 1;
434 437 int walking_fc_fca_portlist = 0;
435 438
436 439 if (argc != 0) {
437 440 int result;
438 441
439 442 if (argc != 1)
440 443 return (DCMD_USAGE);
441 444
442 445 if (argv->a_type != MDB_TYPE_STRING)
443 446 return (DCMD_USAGE);
444 447
445 448 walking_fc_fca_portlist = 1;
446 449 }
447 450
448 451 if (!(flags & DCMD_ADDRSPEC)) {
449 452 mdb_printf("Sorry, you must provide an address\n");
450 453 return (DCMD_ERR);
451 454 }
452 455
453 456 if (walking_fc_fca_portlist) {
454 457 /*
455 458 * Must read the fc_fca_portlist to get the fc_local_port addr
456 459 */
457 460 if (mdb_vread(&portlist, sizeof (fc_fca_port_t), addr) ==
458 461 sizeof (fc_fca_port_t)) {
459 462 addr = (uintptr_t)portlist.port_handle;
460 463 }
461 464 }
462 465
463 466 mdb_printf("Reading fc_local_port_t at %p:\n", addr);
464 467
465 468 /*
466 469 * For each port, we just need to read the fc_local_port_t struct
467 470 */
468 471
469 472 if (mdb_vread(&port, sizeof (fc_local_port_t),
470 473 addr) == sizeof (fc_local_port_t)) {
471 474 mdb_printf(" fp_mutex : 0x%p\n", port.fp_mutex);
472 475 mdb_printf(" fp_state : 0x%-8x\n", port.fp_state);
473 476 mdb_printf(" fp_port_id : 0x%-06x\n",
474 477 port.fp_port_id.port_id);
475 478 mdb_printf(" fp_fca_handle : 0x%p\n", port.fp_fca_handle);
476 479 mdb_printf(" fp_fca_tran : 0x%p\n", port.fp_fca_tran);
477 480 mdb_printf(" fp_job_head : 0x%p\n", port.fp_job_head);
478 481 mdb_printf(" fp_job_tail : 0x%p\n", port.fp_job_tail);
479 482 mdb_printf(" fp_wait_head : 0x%p\n", port.fp_wait_head);
480 483 mdb_printf(" fp_wait_tail : 0x%p\n", port.fp_wait_tail);
481 484 mdb_printf(" fp_topology : %u\n", port.fp_topology);
482 485 mdb_printf(" fp_task : %d\n", port.fp_task);
483 486 mdb_printf(" fp_last_task : %d\n", port.fp_last_task);
484 487 mdb_printf(" fp_soft_state : 0x%-4x\n",
485 488 port.fp_soft_state);
486 489 mdb_printf(" fp_flag : 0x%-2x\n", port.fp_flag);
487 490 mdb_printf(" fp_statec_busy : 0x%-8x\n",
488 491 port.fp_statec_busy);
489 492 mdb_printf(" fp_port_num : %d\n", port.fp_port_num);
490 493 mdb_printf(" fp_instance : %d\n", port.fp_instance);
491 494 mdb_printf(" fp_ulp_attach : %d\n", port.fp_ulp_attach);
492 495 mdb_printf(" fp_dev_count : %d\n", port.fp_dev_count);
493 496 mdb_printf(" fp_total_devices : %d\n", port.fp_total_devices);
494 497 mdb_printf(" fp_bind_state : 0x%-8x\n",
495 498 port.fp_bind_state);
496 499 mdb_printf(" fp_options : 0x%-8x\n", port.fp_options);
497 500 mdb_printf(" fp_port_type : 0x%-2x\n",
498 501 port.fp_port_type.port_type);
499 502 mdb_printf(" fp_ub_count : %d\n", port.fp_ub_count);
500 503 mdb_printf(" fp_active_ubs : %d\n", port.fp_active_ubs);
501 504 mdb_printf(" fp_port_dip : 0x%p\n", port.fp_port_dip);
502 505 mdb_printf(" fp_fca_dip : 0x%p\n", port.fp_fca_dip);
503 506
504 507 for (idx = 0; idx < 16; idx++) {
505 508 if (port.fp_ip_addr[idx] != 0)
506 509 break;
507 510 }
508 511
509 512 if (idx != 16) {
510 513 mdb_printf(" fp_ip_addr : %-2x:%-2x:%-2x:%-2x:"
511 514 "%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x"
512 515 ":%-2x:%-2x\n",
513 516 port.fp_ip_addr[0], port.fp_ip_addr[1],
514 517 port.fp_ip_addr[2], port.fp_ip_addr[3],
515 518 port.fp_ip_addr[4], port.fp_ip_addr[5],
516 519 port.fp_ip_addr[6], port.fp_ip_addr[7],
517 520 port.fp_ip_addr[8], port.fp_ip_addr[9],
518 521 port.fp_ip_addr[10], port.fp_ip_addr[11],
519 522 port.fp_ip_addr[12], port.fp_ip_addr[13],
520 523 port.fp_ip_addr[14], port.fp_ip_addr[15]);
521 524 } else {
522 525 mdb_printf(" fp_ip_addr : N/A\n");
523 526 }
524 527
525 528 mdb_printf(" fp_fc4_types : ");
526 529
527 530 for (idx = 0; idx < 8; idx++) {
528 531 if (port.fp_fc4_types[idx] != 0) {
529 532 if (first) {
530 533 mdb_printf("%d",
531 534 port.fp_fc4_types[idx]);
532 535 first = 0;
533 536 } else {
534 537 mdb_printf(", %d",
535 538 port.fp_fc4_types[idx]);
536 539 }
537 540 }
538 541 }
539 542
540 543 if (first) {
541 544 mdb_printf("None\n");
542 545 } else {
543 546 mdb_printf("\n");
544 547 }
545 548
546 549 mdb_printf(" fp_pm_level : %d\n", port.fp_pm_level);
547 550 mdb_printf(" fp_pm_busy : %d\n", port.fp_pm_busy);
548 551 mdb_printf(" fp_pm_busy_nocomp : 0x%-8x\n",
549 552 port.fp_pm_busy_nocomp);
550 553 mdb_printf(" fp_hard_addr : 0x%-6x\n",
551 554 port.fp_hard_addr.hard_addr);
552 555 mdb_printf(" fp_sym_port_name : \"%s\"\n",
553 556 port.fp_sym_port_name);
554 557 mdb_printf(" fp_sym_node_name : \"%s\"\n",
555 558 port.fp_sym_node_name);
556 559 mdb_printf(" fp_rscn_count : %d\n", port.fp_rscn_count);
557 560 } else {
558 561 mdb_warn("failed to read fc_local_port_t at 0x%p", addr);
559 562 }
560 563
561 564 mdb_printf("\n");
562 565
563 566 return (DCMD_OK);
564 567 }
565 568
566 569
567 570 /*
568 571 * Leadville remote_port walker/dcmd code
569 572 */
570 573
571 574 /*
572 575 * We need to be given the address of a port structure in order to start
573 576 * walking. From that, we can read the pwwn table.
574 577 */
575 578 static int
576 579 pd_by_pwwn_walk_i(mdb_walk_state_t *wsp)
577 580 {
578 581 fc_local_port_t port;
579 582
580 583 if (wsp->walk_addr == NULL) {
581 584 mdb_warn("pd_by_pwwn walk doesn't support global walks\n");
582 585 return (WALK_ERR);
583 586 }
584 587
585 588 /*
586 589 * Allocate space for the pwwn_hash table
587 590 */
588 591
589 592 fp_pwwn_table = mdb_alloc(sizeof (struct pwwn_hash) *
590 593 PWWN_HASH_TABLE_SIZE, UM_SLEEP);
591 594
592 595 /*
593 596 * Input should be an fc_local_port_t, so read it to get the pwwn
594 597 * table's head
595 598 */
596 599
597 600 if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
598 601 sizeof (fc_local_port_t)) {
599 602 mdb_warn("Unable to read in the port structure address\n");
600 603 return (WALK_ERR);
601 604 }
602 605
603 606 if (mdb_vread(fp_pwwn_table, sizeof (struct pwwn_hash) *
604 607 PWWN_HASH_TABLE_SIZE, (uintptr_t)port.fp_pwwn_table) == -1) {
605 608 mdb_warn("Unable to read in the pwwn hash table\n");
606 609 return (WALK_ERR);
607 610 }
608 611
609 612 pd_hash_index = 0;
610 613
611 614 while ((fp_pwwn_table[pd_hash_index].pwwn_head == NULL) &&
612 615 (pd_hash_index < PWWN_HASH_TABLE_SIZE)) {
613 616 pd_hash_index++;
614 617 }
615 618
616 619 wsp->walk_addr = (uintptr_t)fp_pwwn_table[pd_hash_index].pwwn_head;
617 620
618 621 wsp->walk_data = mdb_alloc(sizeof (fc_remote_port_t), UM_SLEEP);
619 622 return (WALK_NEXT);
620 623 }
621 624
622 625 /*
623 626 * At each step, read a fc_remote_port_t into our private storage, and then
624 627 * invoke the callback function. We terminate when we reach a NULL p_next
625 628 * pointer.
626 629 */
627 630 static int
628 631 pd_by_pwwn_walk_s(mdb_walk_state_t *wsp)
629 632 {
630 633 int status;
631 634
632 635 if ((wsp->walk_addr == NULL) &&
633 636 (pd_hash_index >= (PWWN_HASH_TABLE_SIZE - 1))) {
634 637 return (WALK_DONE);
635 638 }
636 639
637 640 if (mdb_vread(wsp->walk_data, sizeof (fc_remote_port_t), wsp->walk_addr)
638 641 == -1) {
639 642 mdb_warn("failed to read fc_remote_port at %p", wsp->walk_addr);
640 643 return (WALK_DONE);
641 644 }
642 645
643 646 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
644 647 wsp->walk_cbdata);
645 648
646 649 wsp->walk_addr =
647 650 (uintptr_t)(((fc_remote_port_t *)wsp->walk_data)->pd_wwn_hnext);
648 651
649 652 if (wsp->walk_addr == NULL) {
650 653 /*
651 654 * Try the next hash list, if there is one.
652 655 */
653 656
654 657 pd_hash_index++;
655 658
656 659 while ((fp_pwwn_table[pd_hash_index].pwwn_head == NULL) &&
657 660 (pd_hash_index < PWWN_HASH_TABLE_SIZE)) {
658 661 pd_hash_index++;
659 662 }
660 663
661 664 if (pd_hash_index == PWWN_HASH_TABLE_SIZE) {
662 665 /* We're done */
663 666 return (status);
664 667 }
665 668
666 669 wsp->walk_addr =
667 670 (uintptr_t)fp_pwwn_table[pd_hash_index].pwwn_head;
668 671 }
669 672
670 673 return (status);
671 674 }
672 675
673 676 /*
674 677 * The walker's fini function is invoked at the end of each walk.
675 678 */
676 679 static void
677 680 pd_by_pwwn_walk_f(mdb_walk_state_t *wsp)
678 681 {
679 682 mdb_free(wsp->walk_data, sizeof (fc_remote_port_t));
680 683 mdb_free(fp_pwwn_table, sizeof (struct pwwn_hash) *
681 684 PWWN_HASH_TABLE_SIZE);
682 685 fp_pwwn_table = NULL;
683 686 }
684 687
685 688 /*
686 689 * This is the same walker as pd_by_pwwn, but we walk the D_ID hash table
687 690 */
688 691
689 692 static int
690 693 pd_by_did_walk_i(mdb_walk_state_t *wsp)
691 694 {
692 695 fc_local_port_t port;
693 696
694 697 if (wsp->walk_addr == NULL) {
695 698 mdb_warn("pd_by_did walk doesn't support global walks\n");
696 699 return (WALK_ERR);
697 700 }
698 701
699 702 /*
700 703 * Allocate space for the did_hash table
701 704 */
702 705
703 706 fp_did_table = mdb_alloc(sizeof (struct d_id_hash) *
704 707 D_ID_HASH_TABLE_SIZE, UM_SLEEP);
705 708
706 709 /*
707 710 * Input should be an fc_local_port_t, so read it to get the d_id
708 711 * table's head
709 712 */
710 713
711 714 if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
712 715 sizeof (fc_local_port_t)) {
713 716 mdb_warn("Unable to read in the port structure address\n");
714 717 return (WALK_ERR);
715 718 }
716 719
717 720 if (mdb_vread(fp_did_table, sizeof (struct d_id_hash) *
718 721 D_ID_HASH_TABLE_SIZE, (uintptr_t)port.fp_did_table) == -1) {
719 722 mdb_warn("Unable to read in the D_ID hash table\n");
720 723 return (WALK_ERR);
721 724 }
722 725 pd_hash_index = 0;
723 726
724 727 while ((fp_did_table[pd_hash_index].d_id_head == NULL) &&
725 728 (pd_hash_index < D_ID_HASH_TABLE_SIZE)) {
726 729 pd_hash_index++;
727 730 }
728 731
729 732 wsp->walk_addr = (uintptr_t)fp_did_table[pd_hash_index].d_id_head;
730 733
731 734 wsp->walk_data = mdb_alloc(sizeof (fc_remote_port_t), UM_SLEEP);
732 735 return (WALK_NEXT);
733 736 }
734 737
735 738 /*
736 739 * At each step, read a fc_remote_port_t into our private storage, and then
737 740 * invoke the callback function. We terminate when we reach a NULL p_next
738 741 * pointer.
739 742 */
740 743 static int
741 744 pd_by_did_walk_s(mdb_walk_state_t *wsp)
742 745 {
743 746 int status;
744 747
745 748 if ((wsp->walk_addr == NULL) &&
746 749 (pd_hash_index >= (D_ID_HASH_TABLE_SIZE - 1))) {
747 750 return (WALK_DONE);
748 751 }
749 752
750 753 if (mdb_vread(wsp->walk_data, sizeof (fc_remote_port_t), wsp->walk_addr)
751 754 == -1) {
752 755 mdb_warn("failed to read fc_remote_port at %p", wsp->walk_addr);
753 756 return (WALK_DONE);
754 757 }
755 758
756 759 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
757 760 wsp->walk_cbdata);
758 761
759 762 wsp->walk_addr =
760 763 (uintptr_t)(((fc_remote_port_t *)wsp->walk_data)->pd_did_hnext);
761 764
762 765 if (wsp->walk_addr == NULL) {
763 766 /*
764 767 * Try the next hash list, if there is one.
765 768 */
766 769
767 770 pd_hash_index++;
768 771
769 772 while ((fp_did_table[pd_hash_index].d_id_head == NULL) &&
770 773 (pd_hash_index < D_ID_HASH_TABLE_SIZE)) {
771 774 pd_hash_index++;
772 775 }
773 776
774 777 if (pd_hash_index == D_ID_HASH_TABLE_SIZE) {
775 778 /* We're done */
776 779 return (status);
777 780 }
778 781
779 782 wsp->walk_addr =
780 783 (uintptr_t)fp_did_table[pd_hash_index].d_id_head;
781 784 }
782 785
783 786 return (status);
784 787 }
785 788
786 789 /*
787 790 * The walker's fini function is invoked at the end of each walk.
788 791 */
789 792 static void
790 793 pd_by_did_walk_f(mdb_walk_state_t *wsp)
791 794 {
792 795 mdb_free(wsp->walk_data, sizeof (fc_remote_port_t));
793 796 mdb_free(fp_did_table, sizeof (struct d_id_hash) *
794 797 D_ID_HASH_TABLE_SIZE);
795 798 fp_did_table = NULL;
796 799 }
797 800
798 801
799 802 /*
800 803 * Display a remote_port structure
801 804 */
802 805 static int
803 806 remote_port(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
804 807 {
805 808 fc_remote_port_t pd;
806 809 int idx;
807 810 int first = 1;
808 811
809 812 if (argc > 0) {
810 813 return (DCMD_USAGE);
811 814 }
812 815
813 816 if (!(flags & DCMD_ADDRSPEC)) {
814 817 mdb_printf("Sorry, you must provide an address\n");
815 818 return (DCMD_ERR);
816 819 }
817 820
818 821 if (mdb_vread(&pd, sizeof (fc_remote_port_t), addr) !=
819 822 sizeof (fc_remote_port_t)) {
820 823 mdb_warn("Error reading pd at 0x%x\n", addr);
821 824 return (DCMD_ERR);
822 825 }
823 826
824 827 mdb_printf("Reading remote_port at 0x%p\n", addr);
825 828 mdb_printf(" mutex : 0x%p\n", pd.pd_mutex);
826 829 mdb_printf(" port_id : 0x%-8x\n", pd.pd_port_id);
827 830 mdb_printf(" port_name : 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
828 831 pd.pd_port_name.raw_wwn[0], pd.pd_port_name.raw_wwn[1],
829 832 pd.pd_port_name.raw_wwn[2], pd.pd_port_name.raw_wwn[3],
830 833 pd.pd_port_name.raw_wwn[4], pd.pd_port_name.raw_wwn[5],
831 834 pd.pd_port_name.raw_wwn[6], pd.pd_port_name.raw_wwn[7]);
832 835 mdb_printf(" login_count : %d\n", pd.pd_login_count);
833 836 mdb_printf(" state : 0x%x ", pd.pd_state);
834 837
835 838 switch (pd.pd_state) {
836 839 case PORT_DEVICE_INVALID:
837 840 mdb_printf("(invalid)\n");
838 841 break;
839 842 case PORT_DEVICE_VALID:
840 843 mdb_printf("(valid)\n");
841 844 break;
842 845 case PORT_DEVICE_LOGGED_IN:
843 846 mdb_printf("(logged in)\n");
844 847 break;
845 848 default:
846 849 mdb_printf("(Unknown state)\n");
847 850 }
848 851
849 852 mdb_printf(" remote node : 0x%p\n", pd.pd_remote_nodep);
850 853 mdb_printf(" hard_addr : 0x%x\n", pd.pd_hard_addr);
851 854 mdb_printf(" local port : 0x%p\n", pd.pd_port);
852 855 mdb_printf(" type : %d ", pd.pd_type);
853 856
854 857 switch (pd.pd_type) {
855 858 case PORT_DEVICE_NOCHANGE:
856 859 mdb_printf("(No change)\n");
857 860 break;
858 861 case PORT_DEVICE_NEW:
859 862 mdb_printf("(New)\n");
860 863 break;
861 864 case PORT_DEVICE_OLD:
862 865 mdb_printf("(Old)\n");
863 866 break;
864 867 case PORT_DEVICE_CHANGED:
865 868 mdb_printf("(Changed)\n");
866 869 break;
867 870 case PORT_DEVICE_DELETE:
868 871 mdb_printf("(Delete)\n");
869 872 break;
870 873 case PORT_DEVICE_USER_LOGIN:
871 874 mdb_printf("(User login)\n");
872 875 break;
873 876 case PORT_DEVICE_USER_LOGOUT:
874 877 mdb_printf("(User logout)\n");
875 878 break;
876 879 case PORT_DEVICE_USER_CREATE:
877 880 mdb_printf("(User create)\n");
878 881 break;
879 882 case PORT_DEVICE_USER_DELETE:
880 883 mdb_printf("(User delete)\n");
881 884 break;
882 885 default:
883 886 mdb_printf("(Unknown type)\n");
884 887 }
885 888
886 889 mdb_printf(" flags : 0x%x ", pd.pd_flags);
887 890
888 891 switch (pd.pd_flags) {
889 892 case PD_IDLE:
890 893 mdb_printf("(Idle)\n");
891 894 break;
892 895 case PD_ELS_IN_PROGRESS:
893 896 mdb_printf("(ELS in progress)\n");
894 897 break;
895 898 case PD_ELS_MARK:
896 899 mdb_printf("(Mark)\n");
897 900 break;
898 901 default:
899 902 mdb_printf("(Unknown flag value)\n");
900 903 }
901 904
902 905 mdb_printf(" login_class : 0x%x\n", pd.pd_login_class);
903 906 mdb_printf(" recipient : %d\n", pd.pd_recepient);
904 907 mdb_printf(" ref_count : %d\n", pd.pd_ref_count);
905 908 mdb_printf(" aux_flags : 0x%x ", pd.pd_aux_flags);
906 909
907 910 first = 1;
908 911 if (pd.pd_aux_flags & PD_IN_DID_QUEUE) {
909 912 mdb_printf("(IN_DID_QUEUE");
910 913 first = 0;
911 914 }
912 915
913 916 if (pd.pd_aux_flags & PD_DISABLE_RELOGIN) {
914 917 if (first) {
915 918 mdb_printf("(DISABLE_RELOGIN");
916 919 } else {
917 920 mdb_printf(", DISABLE_RELOGIN");
918 921 }
919 922 first = 0;
920 923 }
921 924
922 925 if (pd.pd_aux_flags & PD_NEEDS_REMOVAL) {
923 926 if (first) {
924 927 mdb_printf("(NEEDS_REMOVAL");
925 928 } else {
926 929 mdb_printf(", NEEDS_REMOVAL");
927 930 }
928 931 first = 0;
929 932 }
930 933
931 934 if (pd.pd_aux_flags & PD_LOGGED_OUT) {
932 935 if (first) {
933 936 mdb_printf("(LOGGED_OUT");
934 937 } else {
935 938 mdb_printf(", LOGGED_OUT");
936 939 }
937 940 first = 0;
938 941 }
939 942
940 943 if (pd.pd_aux_flags & PD_GIVEN_TO_ULPS) {
941 944 if (first) {
942 945 mdb_printf("(GIVEN_TO_ULPS");
943 946 } else {
944 947 mdb_printf(", GIVEN_TO_ULPS");
945 948 }
946 949 first = 0;
947 950 }
948 951
949 952 if (first == 0) {
950 953 mdb_printf(")\n");
951 954 } else {
952 955 mdb_printf("\n");
953 956 }
954 957
955 958 mdb_printf(" sig : %p\n", pd.pd_logo_tc.sig);
956 959 mdb_printf(" active : %d\n", pd.pd_logo_tc.active);
957 960 mdb_printf(" counter : %d\n", pd.pd_logo_tc.counter);
958 961 mdb_printf(" max_value : %d\n", pd.pd_logo_tc.max_value);
959 962 mdb_printf(" timer : %d\n", pd.pd_logo_tc.timer);
960 963 mdb_printf("\n");
961 964
962 965 return (DCMD_OK);
963 966 }
964 967
965 968 int
966 969 fc_dump_logmsg(fc_trace_dmsg_t *addr, uint_t pktstart, uint_t pktend,
967 970 uint_t *printed)
968 971 {
969 972 fc_trace_dmsg_t msg;
970 973 caddr_t buf;
971 974 char merge[1024];
972 975 caddr_t tmppkt;
973 976 char *tmpbuf; /* for tokenising the buffer */
974 977 uint_t pktnum = 0;
975 978
976 979 while (addr != NULL) {
977 980 if (mdb_vread(&msg, sizeof (msg), (uintptr_t)addr) !=
978 981 sizeof (msg)) {
979 982 mdb_warn("failed to read message pointer in kernel");
980 983 return (DCMD_ERR);
981 984 }
982 985
983 986 if (msg.id_size) {
984 987
985 988 buf = mdb_alloc(msg.id_size + 1, UM_SLEEP);
986 989 tmppkt = mdb_alloc(msg.id_size + 1, UM_SLEEP);
987 990
988 991 if (mdb_vread(buf, msg.id_size,
989 992 (uintptr_t)msg.id_buf) != msg.id_size) {
990 993 mdb_warn("failed to read buffer contents"
991 994 " in kernel");
992 995 mdb_free(buf, msg.id_size + 1);
993 996 return (DCMD_ERR);
994 997 }
995 998
996 999 if (buf[0] == '\n') {
997 1000 mdb_printf("There is a problem in"
998 1001 "the buffer\n");
999 1002 }
1000 1003 /* funky packet processing stuff */
1001 1004 bcopy(buf, tmppkt, msg.id_size + 1);
1002 1005
1003 1006 /* find the equals sign, and put a null there */
1004 1007 tmpbuf = strchr(tmppkt, '=');
1005 1008 *tmpbuf = 0;
1006 1009 pktnum = (uint_t)mdb_strtoull(tmppkt);
1007 1010
1008 1011 if ((pktnum >= pktstart) && (pktnum <= pktend)) {
1009 1012 (void) mdb_snprintf(merge, sizeof (merge),
1010 1013 "[%Y:%03d:%03d:%03d] %s",
1011 1014 msg.id_time.tv_sec,
1012 1015 (int)msg.id_time.tv_nsec/1000000,
1013 1016 (int)(msg.id_time.tv_nsec/1000)%1000,
1014 1017 (int)msg.id_time.tv_nsec%1000, buf);
1015 1018 mdb_printf("%s", merge);
1016 1019 if (printed != NULL)
1017 1020 (*printed) ++;
1018 1021 }
1019 1022 mdb_free(buf, msg.id_size + 1);
1020 1023 mdb_free(tmppkt, msg.id_size + 1);
1021 1024 }
1022 1025 addr = msg.id_next;
1023 1026 }
1024 1027
1025 1028 return (DCMD_OK);
1026 1029 }
1027 1030
1028 1031 int
1029 1032 fc_dump_old_logmsg(fc_trace_dmsgv1_t *addr, uint_t pktstart, uint_t pktend,
1030 1033 uint_t *printed)
1031 1034 {
1032 1035 fc_trace_dmsgv1_t msg;
1033 1036 caddr_t buf;
1034 1037 char merge[1024];
1035 1038 caddr_t tmppkt;
1036 1039 char *tmpbuf; /* for tokenising the buffer */
1037 1040 uint_t pktnum = 0;
1038 1041
1039 1042 while (addr != NULL) {
1040 1043 if (mdb_vread(&msg, sizeof (msg), (uintptr_t)addr) !=
1041 1044 sizeof (msg)) {
1042 1045 mdb_warn("failed to read message pointer in kernel");
1043 1046 return (DCMD_ERR);
1044 1047 }
1045 1048
1046 1049 if (msg.id_size) {
1047 1050
1048 1051 buf = mdb_alloc(msg.id_size + 1, UM_SLEEP);
1049 1052 tmppkt = mdb_alloc(msg.id_size + 1, UM_SLEEP);
1050 1053
1051 1054 if (mdb_vread(buf, msg.id_size,
1052 1055 (uintptr_t)msg.id_buf) != msg.id_size) {
1053 1056 mdb_warn("failed to read buffer contents"
1054 1057 " in kernel");
1055 1058 mdb_free(buf, msg.id_size + 1);
1056 1059 return (DCMD_ERR);
1057 1060 }
1058 1061
1059 1062 if (buf[0] == '\n') {
1060 1063 mdb_printf("There is a problem in"
1061 1064 "the buffer\n");
1062 1065 }
1063 1066 /* funky packet processing stuff */
1064 1067 bcopy(buf, tmppkt, msg.id_size + 1);
1065 1068
1066 1069 tmpbuf = strchr(tmppkt, '=');
1067 1070 *tmpbuf = 0;
1068 1071 pktnum = (uint_t)mdb_strtoull(tmppkt);
1069 1072
1070 1073 if ((pktnum >= pktstart) && (pktnum <= pktend)) {
1071 1074 (void) mdb_snprintf(merge, sizeof (merge),
1072 1075 "[%Y] %s", msg.id_time, buf);
1073 1076 mdb_printf("%s", merge);
1074 1077 if (printed != NULL)
1075 1078 (*printed) ++;
1076 1079 }
1077 1080 mdb_free(buf, msg.id_size + 1);
1078 1081 mdb_free(tmppkt, msg.id_size + 1);
1079 1082 }
1080 1083 addr = msg.id_next;
1081 1084 }
1082 1085
1083 1086 return (DCMD_OK);
1084 1087 }
1085 1088
1086 1089 int
1087 1090 fc_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1088 1091 {
1089 1092 fc_trace_logq_t logq;
1090 1093 uint_t pktnum = 0;
1091 1094 uint_t printed = 0; /* have we printed anything? */
1092 1095
1093 1096 uintptr_t pktstart = 0;
1094 1097 uintptr_t pktend = UINT_MAX;
1095 1098 int rval = DCMD_OK;
1096 1099
1097 1100 if (mdb_vread(&logq, sizeof (logq), addr) != sizeof (logq)) {
1098 1101 mdb_warn("Failed to read log queue in kernel");
1099 1102 return (DCMD_ERR);
1100 1103 }
1101 1104
↓ open down ↓ |
1066 lines elided |
↑ open up ↑ |
1102 1105 if (mdb_getopts(argc, argv,
1103 1106 's', MDB_OPT_UINTPTR, &pktstart,
1104 1107 'e', MDB_OPT_UINTPTR, &pktend) != argc) {
1105 1108 return (DCMD_USAGE);
1106 1109 }
1107 1110
1108 1111 if (pktstart > pktend) {
1109 1112 return (DCMD_USAGE);
1110 1113 }
1111 1114
1112 - if (logq.il_flags & FC_TRACE_LOGQ_V2 != 0) {
1115 + if ((logq.il_flags & FC_TRACE_LOGQ_V2) != 0) {
1113 1116 rval = fc_dump_logmsg((fc_trace_dmsg_t *)logq.il_msgh, pktstart,
1114 1117 pktend, &printed);
1115 1118 } else {
1116 1119 rval = fc_dump_old_logmsg((fc_trace_dmsgv1_t *)logq.il_msgh,
1117 1120 pktstart, pktend, &printed);
1118 1121 }
1119 1122
1120 1123 if (rval != DCMD_OK) {
1121 1124 return (rval);
1122 1125 }
1123 1126
1124 1127 if (printed == 0) {
1125 1128 mdb_printf("No packets in the buffer match the"
1126 1129 " criteria given");
1127 1130 }
1128 1131
1129 1132 return (rval);
1130 1133 }
1131 1134
1132 1135 int
1133 1136 fp_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1134 1137 {
1135 1138 if (mdb_readvar(&addr, "fp_logq") == -1) {
1136 1139 mdb_warn("failed to read fp_logq");
1137 1140 return (DCMD_ERR);
1138 1141 }
1139 1142
1140 1143 if (DCMD_HDRSPEC(flags)) {
1141 1144 mdb_printf("fp trace buffer contents\n");
1142 1145 }
1143 1146
1144 1147 return (fc_trace_dump(addr, flags, argc, argv));
1145 1148 }
1146 1149
1147 1150
1148 1151 int
1149 1152 fcp_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1150 1153 {
1151 1154 if (mdb_readvar(&addr, "fcp_logq") == -1) {
1152 1155 mdb_warn("failed to read fcp_logq");
1153 1156 return (DCMD_ERR);
1154 1157 }
1155 1158
1156 1159 if (DCMD_HDRSPEC(flags)) {
1157 1160 mdb_printf("fcp trace buffer contents\n");
1158 1161 }
1159 1162
1160 1163 return (fc_trace_dump(addr, flags, argc, argv));
1161 1164 }
1162 1165
1163 1166 /*
1164 1167 * Leadville job_request walker/dcmd code
1165 1168 */
1166 1169
1167 1170 /*
1168 1171 * We need to be given the address of a local port structure in order to start
1169 1172 * walking. From that, we can read the job_request list.
1170 1173 */
1171 1174
1172 1175 static int
1173 1176 job_request_walk_i(mdb_walk_state_t *wsp)
1174 1177 {
1175 1178 if (wsp->walk_addr == NULL) {
1176 1179 mdb_warn("The address of a fc_local_port"
1177 1180 " structure must be given\n");
1178 1181 return (WALK_ERR);
1179 1182 }
1180 1183
1181 1184 /*
1182 1185 * Input should be a fc_local_port_t, so read it to get the job_request
1183 1186 * lists's head
1184 1187 */
1185 1188
1186 1189 if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
1187 1190 sizeof (fc_local_port_t)) {
1188 1191 mdb_warn("Failed to read in the fc_local_port"
1189 1192 " at 0x%p\n", wsp->walk_addr);
1190 1193 return (WALK_ERR);
1191 1194 }
1192 1195
1193 1196 wsp->walk_addr = (uintptr_t)(port.fp_job_head);
1194 1197 wsp->walk_data = mdb_alloc(sizeof (struct job_request), UM_SLEEP);
1195 1198
1196 1199 return (WALK_NEXT);
1197 1200 }
1198 1201
1199 1202 static int
1200 1203 job_request_walk_s(mdb_walk_state_t *wsp)
1201 1204 {
1202 1205 int status;
1203 1206
1204 1207 if (wsp->walk_addr == NULL)
1205 1208 return (WALK_DONE);
1206 1209
1207 1210 if (mdb_vread(wsp->walk_data, sizeof (struct job_request),
1208 1211 wsp->walk_addr) == -1) {
1209 1212 mdb_warn("Failed to read in the job_request at 0x%p\n",
1210 1213 wsp->walk_addr);
1211 1214 return (WALK_DONE);
1212 1215 }
1213 1216
1214 1217 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
1215 1218 wsp->walk_cbdata);
1216 1219
1217 1220 wsp->walk_addr =
1218 1221 (uintptr_t)(((struct job_request *)wsp->walk_data)->job_next);
1219 1222
1220 1223 return (status);
1221 1224 }
1222 1225
1223 1226 /*
1224 1227 * The walker's fini function is invoked at the end of each walk.
1225 1228 */
1226 1229 static void
1227 1230 job_request_walk_f(mdb_walk_state_t *wsp)
1228 1231 {
1229 1232 mdb_free(wsp->walk_data, sizeof (struct job_request));
1230 1233 }
1231 1234
1232 1235
1233 1236 /*
1234 1237 * Leadville fc_orphan walker/dcmd code
1235 1238 */
1236 1239
1237 1240 /*
1238 1241 * We need to be given the address of a port structure in order to start
1239 1242 * walking. From that, we can read the orphan list.
1240 1243 */
1241 1244
1242 1245 static int
1243 1246 orphan_walk_i(mdb_walk_state_t *wsp)
1244 1247 {
1245 1248 if (wsp->walk_addr == NULL) {
1246 1249 mdb_warn("The address of a fc_local_port"
1247 1250 " structure must be given\n");
1248 1251 return (WALK_ERR);
1249 1252 }
1250 1253
1251 1254 /*
1252 1255 * Input should be a fc_local_port_t, so read it to get the orphan
1253 1256 * lists's head
1254 1257 */
1255 1258
1256 1259 if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
1257 1260 sizeof (fc_local_port_t)) {
1258 1261 mdb_warn("Failed to read in the fc_local_port"
1259 1262 " at 0x%p\n", wsp->walk_addr);
1260 1263 return (WALK_ERR);
1261 1264 }
1262 1265
1263 1266 wsp->walk_addr = (uintptr_t)(port.fp_orphan_list);
1264 1267 wsp->walk_data = mdb_alloc(sizeof (struct fc_orphan), UM_SLEEP);
1265 1268
1266 1269 return (WALK_NEXT);
1267 1270 }
1268 1271
1269 1272 static int
1270 1273 orphan_walk_s(mdb_walk_state_t *wsp)
1271 1274 {
1272 1275 int status;
1273 1276
1274 1277 if (wsp->walk_addr == NULL)
1275 1278 return (WALK_DONE);
1276 1279
1277 1280 if (mdb_vread(wsp->walk_data, sizeof (struct fc_orphan),
1278 1281 wsp->walk_addr) == -1) {
1279 1282 mdb_warn("Failed to read in the fc_orphan at 0x%p\n",
1280 1283 wsp->walk_addr);
1281 1284 return (WALK_DONE);
1282 1285 }
1283 1286
1284 1287 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
1285 1288 wsp->walk_cbdata);
1286 1289
1287 1290 wsp->walk_addr =
1288 1291 (uintptr_t)(((struct fc_orphan *)wsp->walk_data)->orp_next);
1289 1292
1290 1293 return (status);
1291 1294 }
1292 1295
1293 1296 /*
1294 1297 * The walker's fini function is invoked at the end of each walk.
1295 1298 */
1296 1299 static void
1297 1300 orphan_walk_f(mdb_walk_state_t *wsp)
1298 1301 {
1299 1302 mdb_free(wsp->walk_data, sizeof (struct fc_orphan));
1300 1303 }
1301 1304
1302 1305
1303 1306 /*
1304 1307 * MDB module linkage information:
1305 1308 *
1306 1309 * We declare a list of structures describing our dcmds, a list of structures
1307 1310 * describing our walkers, and a function named _mdb_init to return a pointer
1308 1311 * to our module information.
1309 1312 */
1310 1313
1311 1314 static const mdb_dcmd_t dcmds[] = {
1312 1315 { "ports", "[-l]", "Leadville port list", ports },
1313 1316 { "ulps", NULL, "Leadville ULP list", ulps },
1314 1317 { "ulpmods", NULL, "Leadville ULP module list", ulpmods },
1315 1318 { "fcport", NULL, "Display a Leadville fc_local_port structure",
1316 1319 fcport },
1317 1320 { "remote_port", NULL, "Display fc_remote_port structures",
1318 1321 remote_port },
1319 1322 { "fcptrace", "[-s m][-e n] (m < n)", "Dump the fcp trace buffer, "
1320 1323 "optionally supplying starting and ending packet numbers.",
1321 1324 fcp_trace_dump, NULL },
1322 1325 { "fptrace", "[-s m][-e n] (m < n)", "Dump the fp trace buffer, "
1323 1326 "optionally supplying starting and ending packet numbers.",
1324 1327 fp_trace_dump, NULL },
1325 1328 { NULL }
1326 1329 };
1327 1330
1328 1331 static const mdb_walker_t walkers[] = {
1329 1332 { "ports", "walk list of Leadville port structures",
1330 1333 port_walk_i, port_walk_s, port_walk_f },
1331 1334 { "ulps", "walk list of Leadville ULP structures",
1332 1335 ulp_walk_i, ulp_walk_s, ulp_walk_f },
1333 1336 { "ulpmods", "walk list of Leadville ULP module structures",
1334 1337 ulpmod_walk_i, ulpmod_walk_s, ulpmod_walk_f },
1335 1338 { "pd_by_pwwn", "walk list of fc_remote_port structures hashed by PWWN",
1336 1339 pd_by_pwwn_walk_i, pd_by_pwwn_walk_s, pd_by_pwwn_walk_f },
1337 1340 { "pd_by_did", "walk list of fc_remote_port structures hashed by D_ID",
1338 1341 pd_by_did_walk_i, pd_by_did_walk_s, pd_by_did_walk_f },
1339 1342 { "job_request", "walk list of job_request structures for a local port",
1340 1343 job_request_walk_i, job_request_walk_s, job_request_walk_f },
1341 1344 { "orphan", "walk list of orphan structures for a local port",
1342 1345 orphan_walk_i, orphan_walk_s, orphan_walk_f },
1343 1346 { NULL }
1344 1347 };
1345 1348
1346 1349 static const mdb_modinfo_t modinfo = {
1347 1350 MDB_API_VERSION, dcmds, walkers
1348 1351 };
1349 1352
1350 1353 const mdb_modinfo_t *
1351 1354 _mdb_init(void)
1352 1355 {
1353 1356 return (&modinfo);
1354 1357 }
↓ open down ↓ |
232 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX