8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / nsctl / nsctl.c
blobe9a360deb60083ca832a5d304d3770a8104d12ad
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/ksynch.h>
28 #include <sys/kmem.h>
29 #include <sys/errno.h>
30 #include <sys/ddi.h>
32 #include <sys/mdb_modapi.h>
34 #define __NSC_GEN__
35 #include <sys/nsc_thread.h>
36 #include <sys/nsctl/nsc_dev.h>
37 #include <sys/nsctl/nsc_gen.h>
38 #include <sys/nsctl/nsc_mem.h>
39 #include <sys/nsctl/nsctl.h>
40 #include <sys/nsctl/nsc_disk.h>
44 * Data struct for the complex walks.
47 struct complex_args {
48 int argc;
49 mdb_arg_t *argv;
54 * Bit definitions
57 #define NSC_RW_BITS \
58 { "NSC_READ", NSC_READ, NSC_READ }, \
59 { "NSC_WRITE", NSC_WRITE, NSC_WRITE }
62 static const mdb_bitmask_t nsc_bhflag_bits[] = {
63 NSC_RW_BITS,
64 { "NSC_PINNABLE", NSC_PINNABLE, NSC_PINNABLE },
65 { "NSC_NOBLOCK", NSC_NOBLOCK, NSC_NOBLOCK },
66 { "NSC_HALLOCATED", NSC_HALLOCATED, NSC_HALLOCATED },
67 { "NSC_HACTIVE", NSC_HACTIVE, NSC_HACTIVE },
68 { "NSC_BCOPY", NSC_BCOPY, NSC_BCOPY },
69 { "NSC_PAGEIO", NSC_PAGEIO, NSC_PAGEIO },
70 { "NSC_ABUF", NSC_ABUF, NSC_ABUF },
71 { "NSC_MIXED", NSC_MIXED, NSC_MIXED },
72 { "NSC_WRTHRU", NSC_WRTHRU, NSC_WRTHRU },
73 { "NSC_FORCED_WRTHRU", NSC_FORCED_WRTHRU, NSC_FORCED_WRTHRU },
74 { "NSC_NOCACHE", NSC_NOCACHE, NSC_NOCACHE },
75 { "NSC_QUEUE", NSC_QUEUE, NSC_QUEUE },
76 { "NSC_RDAHEAD", NSC_RDAHEAD, NSC_RDAHEAD },
77 { "NSC_NO_FORCED_WRTHRU", NSC_NO_FORCED_WRTHRU, NSC_NO_FORCED_WRTHRU },
78 { "NSC_METADATA", NSC_METADATA, NSC_METADATA },
79 { "NSC_SEQ_IO", NSC_SEQ_IO, NSC_SEQ_IO },
80 { NULL, 0, 0 }
84 static const mdb_bitmask_t nsc_fdflag_bits[] = {
85 NSC_RW_BITS,
86 { NULL, 0, 0 }
90 static const mdb_bitmask_t nsc_fdmode_bits[] = {
91 { "NSC_MULTI", NSC_MULTI, NSC_MULTI },
92 { NULL, 0, 0 }
96 static const mdb_bitmask_t nsc_type_bits[] = {
97 /* types */
98 { "NSC_NULL", NSC_NULL, NSC_NULL },
99 { "NSC_DEVICE", NSC_DEVICE, NSC_DEVICE },
100 { "NSC_FILE", NSC_FILE, NSC_FILE },
101 { "NSC_CACHE", NSC_CACHE, NSC_CACHE },
102 { "NSC_VCHR", NSC_VCHR, NSC_VCHR },
103 { "NSC_NCALL", NSC_NCALL, NSC_NCALL },
105 /* type flags */
106 { "NSC_ANON", NSC_ANON, NSC_ANON },
108 /* ids */
109 { "NSC_RAW_ID", NSC_RAW_ID, NSC_RAW_ID },
110 { "NSC_FILE_ID", NSC_FILE_ID, NSC_FILE_ID },
111 { "NSC_FREEZE_ID", NSC_FREEZE_ID, NSC_FREEZE_ID },
112 { "NSC_VCHR_ID", NSC_VCHR_ID, NSC_VCHR_ID },
113 { "NSC_NCALL_ID", NSC_NCALL_ID, NSC_NCALL_ID },
114 { "NSC_SDBC_ID", NSC_SDBC_ID, NSC_SDBC_ID },
115 { "NSC_RDCLR_ID", NSC_RDCLR_ID, NSC_RDCLR_ID },
116 { "NSC_RDCL_ID", NSC_RDCL_ID, NSC_RDCL_ID },
117 { "NSC_IIR_ID", NSC_IIR_ID, NSC_IIR_ID },
118 { "NSC_II_ID", NSC_II_ID, NSC_II_ID },
119 { "NSC_RDCHR_ID", NSC_RDCHR_ID, NSC_RDCHR_ID },
120 { "NSC_RDCH_ID", NSC_RDCH_ID, NSC_RDCH_ID },
121 { NULL, 0, 0 }
125 static const mdb_bitmask_t nsc_availpend_bits[] = {
126 NSC_RW_BITS,
127 { "_NSC_OPEN", _NSC_OPEN, _NSC_OPEN },
128 { "_NSC_CLOSE", _NSC_CLOSE, _NSC_CLOSE },
129 { "_NSC_PINNED", _NSC_PINNED, _NSC_PINNED },
130 { "_NSC_ATTACH", _NSC_ATTACH, _NSC_ATTACH },
131 { "_NSC_DETACH", _NSC_DETACH, _NSC_DETACH },
132 { "_NSC_OWNER", _NSC_OWNER, _NSC_OWNER },
133 { NULL, 0, 0 }
137 static const mdb_bitmask_t nsc_ioflag_bits[] = {
138 { "NSC_REFCNT", NSC_REFCNT, NSC_REFCNT },
139 { "NSC_FILTER", NSC_FILTER, NSC_FILTER },
140 { NULL, 0, 0 }
144 static const mdb_bitmask_t nstset_flag_bits[] = {
145 { "NST_SF_KILL", NST_SF_KILL, NST_SF_KILL },
146 { NULL, 0, 0 }
150 static const mdb_bitmask_t nst_flag_bits[] = {
151 { "NST_TF_INUSE", NST_TF_INUSE, NST_TF_INUSE },
152 { "NST_TF_ACTIVE", NST_TF_ACTIVE, NST_TF_ACTIVE },
153 { "NST_TF_PENDING", NST_TF_PENDING, NST_TF_PENDING },
154 { "NST_TF_DESTROY", NST_TF_DESTROY, NST_TF_DESTROY },
155 { "NST_TF_KILL", NST_TF_KILL, NST_TF_KILL },
156 { NULL, 0, 0 }
161 * Global data.
164 static nsc_mem_t type_mem[20];
165 static int complex_walk;
166 static int complex_hdr;
169 /* ---------------------------------------------------------------------- */
172 * Walker for an nsc_io chain.
173 * A global walk is assumed to start at _nsc_io_top.
176 static int
177 nsc_io_winit(mdb_walk_state_t *wsp)
179 if (wsp->walk_addr == NULL &&
180 mdb_readvar(&wsp->walk_addr, "_nsc_io_top") == -1) {
181 mdb_warn("unable to read '_nsc_io_top'");
182 return (WALK_ERR);
185 return (WALK_NEXT);
189 static int
190 nsc_io_wstep(mdb_walk_state_t *wsp)
192 uintptr_t next;
193 int status;
195 if (wsp->walk_addr == NULL)
196 return (WALK_DONE);
198 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
199 wsp->walk_cbdata);
201 next = wsp->walk_addr + OFFSETOF(nsc_io_t, next);
203 if (mdb_vread(&wsp->walk_addr, sizeof (uintptr_t), next) == -1) {
204 mdb_warn("failed to read nsc_io_t.next at %p", next);
205 return (WALK_DONE);
208 return (status);
212 /* ---------------------------------------------------------------------- */
215 * Walker for an nsc_dev chain.
216 * A global walk is assumed to start at _nsc_dev_top.
219 static int
220 nsc_dev_winit(mdb_walk_state_t *wsp)
222 if (wsp->walk_addr == NULL &&
223 mdb_readvar(&wsp->walk_addr, "_nsc_dev_top") == -1) {
224 mdb_warn("unable to read '_nsc_dev_top'");
225 return (WALK_ERR);
228 return (WALK_NEXT);
232 static int
233 nsc_dev_wstep(mdb_walk_state_t *wsp)
235 uintptr_t next;
236 int status;
238 if (wsp->walk_addr == NULL)
239 return (WALK_DONE);
241 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
242 wsp->walk_cbdata);
244 next = wsp->walk_addr + OFFSETOF(nsc_dev_t, nsc_next);
246 if (mdb_vread(&wsp->walk_addr, sizeof (uintptr_t), next) == -1) {
247 mdb_warn("failed to read nsc_dev_t.nsc_next at %p", next);
248 return (WALK_DONE);
251 return (status);
255 /* ARGSUSED */
257 static void
258 nsc_dev_wfini(mdb_walk_state_t *wsp)
260 complex_walk = 0;
264 /* ---------------------------------------------------------------------- */
267 * Walker for a chain of nsc_devval_t structures.
268 * Global walks start from _nsc_devval_top;
271 static int
272 nsc_devval_winit(mdb_walk_state_t *wsp)
274 if (wsp->walk_addr == NULL &&
275 mdb_readvar(&wsp->walk_addr, "_nsc_devval_top") == -1) {
276 mdb_warn("unable to read '_nsc_devval_top'");
277 return (WALK_ERR);
280 return (WALK_NEXT);
284 static int
285 nsc_devval_wstep(mdb_walk_state_t *wsp)
287 uintptr_t devval = wsp->walk_addr;
288 int status;
290 if (!devval)
291 return (WALK_DONE);
293 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
294 wsp->walk_cbdata);
296 /* move on to next devval */
298 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
299 devval + OFFSETOF(nsc_devval_t, dv_next)) == -1) {
300 mdb_warn("failed to read nsc_devval_t.dv_next");
301 return (WALK_ERR);
304 return (status);
308 /* ---------------------------------------------------------------------- */
311 * Walker for a chain of nsc_fd_t structures.
312 * No global walks.
315 static int
316 nsc_fd_winit(mdb_walk_state_t *wsp)
318 if (wsp->walk_addr == NULL) {
319 mdb_warn("nsc_fd doesn't support global walks");
320 return (WALK_ERR);
323 return (WALK_NEXT);
327 static int
328 nsc_fd_wstep(mdb_walk_state_t *wsp)
330 uintptr_t fd = wsp->walk_addr;
331 int status;
333 if (!fd)
334 return (WALK_DONE);
336 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
337 wsp->walk_cbdata);
339 /* move on to next fd */
341 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
342 fd + OFFSETOF(nsc_fd_t, sf_next)) == -1) {
343 mdb_warn("failed to read nsc_fd_t.sf_next");
344 return (WALK_ERR);
347 return (status);
351 /* ---------------------------------------------------------------------- */
354 * Walker for a chain of nsc_iodev_t structures.
355 * No global walks.
358 static int
359 nsc_iodev_winit(mdb_walk_state_t *wsp)
361 if (wsp->walk_addr == NULL) {
362 mdb_warn("nsc_iodev doesn't support global walks");
363 return (WALK_ERR);
366 return (WALK_NEXT);
370 static int
371 nsc_iodev_wstep(mdb_walk_state_t *wsp)
373 uintptr_t iodev = wsp->walk_addr;
374 int status;
376 if (!iodev)
377 return (WALK_DONE);
379 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
380 wsp->walk_cbdata);
382 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
383 iodev + OFFSETOF(nsc_iodev_t, si_next)) == -1) {
384 mdb_warn("failed to read nsc_iodev_t.si_next");
385 return (WALK_ERR);
388 return (status);
392 /* ---------------------------------------------------------------------- */
395 * Walker for a chain of nsc_service_t structures.
396 * Global walks start at _nsc_services.
399 static int
400 nsc_service_winit(mdb_walk_state_t *wsp)
402 if (wsp->walk_addr == NULL &&
403 mdb_readvar(&wsp->walk_addr, "_nsc_services") == -1) {
404 mdb_warn("unable to read '_nsc_services'");
405 return (WALK_ERR);
408 return (WALK_NEXT);
412 static int
413 nsc_service_wstep(mdb_walk_state_t *wsp)
415 uintptr_t service = wsp->walk_addr;
416 int status;
418 if (!service)
419 return (WALK_DONE);
421 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
422 wsp->walk_cbdata);
424 /* move on to next service */
426 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
427 service + OFFSETOF(nsc_service_t, s_next)) == -1) {
428 mdb_warn("failed to read nsc_service_t.s_next");
429 return (WALK_ERR);
432 return (status);
436 /* ---------------------------------------------------------------------- */
439 * Walker for a chain of nsc_svc_t structures.
440 * No global walks.
443 static int
444 nsc_svc_winit(mdb_walk_state_t *wsp)
446 if (wsp->walk_addr == NULL) {
447 mdb_warn("nsc_svc does not support global walks");
448 return (WALK_ERR);
451 return (WALK_NEXT);
455 static int
456 nsc_svc_wstep(mdb_walk_state_t *wsp)
458 uintptr_t svc = wsp->walk_addr;
459 int status;
461 if (!svc)
462 return (WALK_DONE);
464 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
465 wsp->walk_cbdata);
467 /* move on to next svc */
469 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
470 svc + OFFSETOF(nsc_svc_t, svc_next)) == -1) {
471 mdb_warn("failed to read nsc_svc_t.svc_next");
472 return (WALK_ERR);
475 return (status);
479 /* ---------------------------------------------------------------------- */
482 * Walker for a chain of nsc_val_t structures.
483 * No global walks.
486 static int
487 nsc_val_winit(mdb_walk_state_t *wsp)
489 if (wsp->walk_addr == NULL) {
490 mdb_warn("nsc_val doesn't support global walks");
491 return (WALK_ERR);
494 return (WALK_NEXT);
498 static int
499 nsc_val_wstep(mdb_walk_state_t *wsp)
501 uintptr_t val = wsp->walk_addr;
502 int status;
504 if (!val)
505 return (WALK_DONE);
507 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
508 wsp->walk_cbdata);
510 /* move on to next val */
512 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
513 val + OFFSETOF(nsc_val_t, sv_next)) == -1) {
514 mdb_warn("failed to read nsc_val_t.sv_next");
515 return (WALK_ERR);
518 return (status);
522 /* ---------------------------------------------------------------------- */
525 * Walker for a chain of nstset_t structures.
526 * Global walks start at _nst_sets.
529 static int
530 nstset_winit(mdb_walk_state_t *wsp)
532 if (wsp->walk_addr == NULL &&
533 mdb_readvar(&wsp->walk_addr, "nst_sets") == -1) {
534 mdb_warn("unable to read 'nst_sets'");
535 return (WALK_ERR);
538 return (WALK_NEXT);
542 static int
543 nstset_wstep(mdb_walk_state_t *wsp)
545 uintptr_t set = wsp->walk_addr;
546 int status;
548 if (!set)
549 return (WALK_DONE);
551 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
552 wsp->walk_cbdata);
554 /* move on to next set */
556 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
557 set + OFFSETOF(nstset_t, set_next)) == -1) {
558 mdb_warn("failed to read nstset_t.set_next");
559 return (WALK_ERR);
562 return (status);
566 /* ---------------------------------------------------------------------- */
569 * Walker for a chain of nsthread_t structures.
570 * No global walks.
573 static int
574 nsthread_winit(mdb_walk_state_t *wsp)
576 if (wsp->walk_addr == NULL) {
577 mdb_warn("nsthread does not support global walks");
578 return (WALK_ERR);
581 return (WALK_NEXT);
585 static int
586 nsthread_wstep(mdb_walk_state_t *wsp)
588 uintptr_t thread = wsp->walk_addr;
589 int status;
591 if (!thread)
592 return (WALK_DONE);
594 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
595 wsp->walk_cbdata);
597 /* move on to next iodev */
599 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
600 thread + OFFSETOF(nsthread_t, tp_chain)) == -1) {
601 mdb_warn("failed to read nsthread_t.tp_chain");
602 return (WALK_ERR);
605 return (status);
609 /* ---------------------------------------------------------------------- */
612 * Walker for nsthread_t free/reuse chain.
613 * No global walks.
616 static int
617 nst_free_winit(mdb_walk_state_t *wsp)
619 if (wsp->walk_addr == NULL) {
620 mdb_warn("nst_free does not support global walks");
621 return (WALK_ERR);
624 /* store starting address */
626 wsp->walk_data = (void *)wsp->walk_addr;
628 /* move on to next thread */
630 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
631 wsp->walk_addr + OFFSETOF(nsthread_t, tp_link.q_forw)) == -1) {
632 mdb_warn("failed to read nsthread_t.tp_link.q_forw");
633 return (WALK_ERR);
636 return (WALK_NEXT);
640 static int
641 nst_free_wstep(mdb_walk_state_t *wsp)
643 uintptr_t thread = wsp->walk_addr;
644 int status;
646 if (!thread)
647 return (WALK_DONE);
649 if (thread == (uintptr_t)wsp->walk_data)
650 return (WALK_DONE);
652 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
653 wsp->walk_cbdata);
655 /* move on to next thread */
657 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
658 thread + OFFSETOF(nsthread_t, tp_link.q_forw)) == -1) {
659 mdb_warn("failed to read nsthread_t.tp_link.q_forw");
660 return (WALK_ERR);
663 return (status);
667 /* ---------------------------------------------------------------------- */
670 * Walker for a chain of nsc_mem_t structures.
671 * Global walks start at _nsc_mem_top.
674 static int
675 nsc_mem_winit(mdb_walk_state_t *wsp)
677 if (wsp->walk_addr == NULL &&
678 mdb_readvar(&wsp->walk_addr, "_nsc_mem_top") == -1) {
679 mdb_warn("unable to read '_nsc_mem_top'");
680 return (WALK_ERR);
683 return (WALK_NEXT);
687 static int
688 nsc_mem_wstep(mdb_walk_state_t *wsp)
690 uintptr_t mem = wsp->walk_addr;
691 int status;
693 if (!mem)
694 return (WALK_DONE);
696 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
697 wsp->walk_cbdata);
699 /* move on to next mem */
701 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr),
702 mem + OFFSETOF(nsc_mem_t, next)) == -1) {
703 mdb_warn("failed to read nsc_mem_t.next");
704 return (WALK_ERR);
707 return (status);
711 /* ---------------------------------------------------------------------- */
713 struct {
714 char *name;
715 int id;
716 } io_ids[] = {
717 { "NSC_RAW_ID", NSC_RAW_ID },
718 { "NSC_FILE_ID", NSC_FILE_ID },
719 { "NSC_FREEZE_ID", NSC_FREEZE_ID },
720 { "NSC_SDBC_ID", NSC_SDBC_ID },
721 { "NSC_RDCLR_ID", NSC_RDCLR_ID },
722 { "NSC_RDCL_ID", NSC_RDCL_ID },
723 { "NSC_IIR_ID", NSC_IIR_ID },
724 { "NSC_II_ID", NSC_II_ID },
725 { "NSC_RDCHR_ID", NSC_RDCHR_ID },
726 { "NSC_RDCH_ID", NSC_RDCH_ID },
727 { NULL, 0 }
731 static char *
732 nsc_io_id(const int id)
734 int i;
736 for (i = 0; io_ids[i].name != NULL; i++) {
737 if (io_ids[i].id == id) {
738 return (io_ids[i].name);
742 return ("unknown");
747 * Display a single nsc_io_t structure.
748 * If called with no address, performs a global walk of all nsc_ios.
750 static int
751 nsc_io(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
753 char io_name[128];
754 nsc_io_t *io;
755 int v_opt;
757 v_opt = 0;
759 if (mdb_getopts(argc, argv,
760 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
761 return (DCMD_USAGE);
763 if (!(flags & DCMD_ADDRSPEC)) {
764 if (mdb_walk_dcmd("nsctl`nsc_io",
765 "nsctl`nsc_io", argc, argv) == -1) {
766 mdb_warn("failed to walk 'nsc_io'");
767 return (DCMD_ERR);
770 return (DCMD_OK);
773 io = mdb_zalloc(sizeof (*io), UM_SLEEP | UM_GC);
774 memset(io_name, 0, sizeof (io_name));
776 if (mdb_vread(io, sizeof (*io), addr) != sizeof (*io)) {
777 mdb_warn("failed to read nsc_io at %p", addr);
778 return (DCMD_ERR);
781 if (io->name) {
782 if (mdb_readstr(io_name, sizeof (io_name),
783 (uintptr_t)io->name) == -1) {
784 mdb_warn("failed to read nsc_io_t.name");
785 return (DCMD_ERR);
789 if (DCMD_HDRSPEC(flags)) {
790 mdb_printf("%-?s %8Tid fl ref abuf name\n", "io");
793 mdb_printf("%0?p %8T%08x %2x %4d %4d %s\n",
794 addr, io->id, io->flag, io->refcnt, io->abufcnt, io_name);
796 if (!v_opt)
797 return (DCMD_OK);
799 mdb_inc_indent(4);
801 mdb_printf("id: %08x <%s>\n", io->id, nsc_io_id(io->id));
803 mdb_printf("provide: %08x <%b>\n", io->provide,
804 io->provide, nsc_type_bits);
806 mdb_printf("flag: %08x <%b>\n", io->flag, io->flag, nsc_ioflag_bits);
808 mdb_printf("pend: %d\n", io->pend);
810 mdb_dec_indent(4);
812 return (DCMD_OK);
816 /* ---------------------------------------------------------------------- */
819 * Display a single nsc_dev_t structure.
820 * If called with no address, performs a global walk of all nsc_devs.
822 static int
823 nsc_dev(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
825 char path[NSC_MAXPATH+1];
826 nsc_devval_t *dv;
827 nsc_dev_t *dev;
828 uintptr_t dev_pend;
829 int a_opt, v_opt;
831 a_opt = v_opt = 0;
833 if (mdb_getopts(argc, argv,
834 'a', MDB_OPT_SETBITS, TRUE, &a_opt,
835 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
836 return (DCMD_USAGE);
838 if (!(flags & DCMD_ADDRSPEC)) {
839 mdb_printf("Active device structures:\n");
841 if (mdb_walk_dcmd("nsctl`nsc_dev",
842 "nsctl`nsc_dev", argc, argv) == -1) {
843 mdb_warn("failed to walk 'nsc_dev'");
844 return (DCMD_ERR);
847 if (a_opt) {
848 if (mdb_readvar(&dev_pend, "_nsc_dev_pend") == -1) {
849 mdb_warn("failed to read _nsc_dev_pend");
850 return (DCMD_ERR);
853 mdb_printf("\nPending device structures:");
855 if (dev_pend) {
856 mdb_printf("\n");
858 if (mdb_pwalk_dcmd("nsctl`nsc_dev",
859 "nsctl`nsc_dev", argc, argv,
860 dev_pend) == -1) {
861 mdb_warn("failed to walk "
862 "pending dev structs");
863 return (DCMD_ERR);
865 } else {
866 mdb_printf(" none\n");
870 return (DCMD_OK);
873 memset(path, 0, sizeof (path));
874 dev = mdb_zalloc(sizeof (*dev), UM_SLEEP | UM_GC);
876 if (mdb_vread(dev, sizeof (*dev), addr) != sizeof (*dev)) {
877 mdb_warn("failed to read nsc_dev at %p", addr);
878 return (DCMD_ERR);
881 if (mdb_readstr(path, sizeof (path), (uintptr_t)dev->nsc_path) == -1) {
882 mdb_warn("failed to read nsc_path at %p", dev->nsc_path);
883 return (DCMD_ERR);
886 if (DCMD_HDRSPEC(flags)) {
887 mdb_printf("%-?s %8Tref pend rpnd wait path\n", "dev");
890 mdb_printf("%0?p %8T%3d %4d %4d %4d %s\n",
891 addr, dev->nsc_refcnt, dev->nsc_pend, dev->nsc_rpend,
892 dev->nsc_wait, path);
894 if (!v_opt)
895 return (DCMD_OK);
897 mdb_inc_indent(4);
899 mdb_printf("next: %0?p %8Tclose: %0?p\n",
900 dev->nsc_next, dev->nsc_close);
902 mdb_printf("list: %0?p %8Tlock: %0?p\n",
903 dev->nsc_list, addr + OFFSETOF(nsc_dev_t, nsc_lock));
905 mdb_printf("cv: %0?p %8Tpath: %0?p %8Tphash: %016llx\n",
906 addr + OFFSETOF(nsc_dev_t, nsc_cv),
907 dev->nsc_path, dev->nsc_phash);
909 mdb_printf("drop: %d %8Treopen: %d\n",
910 dev->nsc_drop, dev->nsc_reopen);
912 if (dev->nsc_values) {
913 dv = mdb_zalloc(sizeof (*dv), UM_SLEEP | UM_GC);
914 if (mdb_vread(dv, sizeof (*dv), (uintptr_t)dev->nsc_values) !=
915 sizeof (*dv)) {
916 mdb_warn("unable to read nsc_dev_t.nsc_values");
917 mdb_dec_indent(4);
918 return (DCMD_ERR);
921 if (dv->dv_values) {
922 mdb_printf("device/values: (nsc_devval: %0?p)\n",
923 dev->nsc_values);
925 mdb_inc_indent(4);
927 if (mdb_pwalk_dcmd("nsctl`nsc_val", "nsctl`nsc_val",
928 0, NULL, (uintptr_t)dv->dv_values) == -1) {
929 mdb_dec_indent(8);
930 return (DCMD_ERR);
933 mdb_dec_indent(4);
937 mdb_dec_indent(4);
939 return (DCMD_OK);
943 /* ---------------------------------------------------------------------- */
946 * Display a single nsc_devval_t structure.
947 * If called with no address, performs a global walk of all nsc_devs.
949 static int
950 nsc_devval(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
952 nsc_devval_t *dv;
953 int a_opt;
955 a_opt = 0;
957 if (mdb_getopts(argc, argv,
958 'a', MDB_OPT_SETBITS, TRUE, &a_opt) != argc)
959 return (DCMD_USAGE);
961 if (!(flags & DCMD_ADDRSPEC)) {
962 if (mdb_walk_dcmd("nsctl`nsc_devval",
963 "nsctl`nsc_devval", argc, argv) == -1) {
964 mdb_warn("failed to walk 'nsc_devval'");
965 return (DCMD_ERR);
968 return (DCMD_OK);
971 dv = mdb_zalloc(sizeof (*dv), UM_SLEEP | UM_GC);
973 if (mdb_vread(dv, sizeof (*dv), addr) != sizeof (*dv)) {
974 mdb_warn("failed to read nsc_devval at %p", addr);
975 return (DCMD_ERR);
978 if (!a_opt && !dv->dv_values) {
979 return (DCMD_OK);
982 if (DCMD_HDRSPEC(flags)) {
983 mdb_printf("%-?s %8T%?-s %8Tpath\n", "devval", "phash");
986 mdb_printf("%0?p %8T%016llx %8T%s\n", addr,
987 dv->dv_phash, dv->dv_path);
989 mdb_inc_indent(4);
991 if (dv->dv_values) {
992 if (mdb_pwalk_dcmd("nsctl`nsc_val", "nsctl`nsc_val",
993 0, NULL, (uintptr_t)dv->dv_values) == -1) {
994 return (DCMD_ERR);
996 } else {
997 mdb_printf("No values\n");
1000 mdb_dec_indent(4);
1002 return (DCMD_OK);
1006 /* ---------------------------------------------------------------------- */
1009 * Part 2 callback for the all devices and fds walk. Called per iodev.
1011 /* ARGSUSED */
1012 static int
1013 nsc_fd_iodev(uintptr_t addr, const void *data, void *cbdata)
1015 struct complex_args *fdall = cbdata;
1016 struct nsc_fd_t *fd;
1018 if (mdb_vread(&fd, sizeof (fd),
1019 addr + OFFSETOF(nsc_iodev_t, si_open)) == -1) {
1020 mdb_warn("unable to read nsc_iodev_t.si_open");
1021 return (WALK_ERR);
1024 if (fd != NULL) {
1025 if (mdb_pwalk_dcmd("nsctl`nsc_fd", "nsctl`nsc_fd",
1026 fdall->argc, fdall->argv, (uintptr_t)fd) == -1)
1027 return (WALK_ERR);
1030 return (WALK_NEXT);
1035 * Part 1 callback for the all devices and fds walk. Called per device.
1037 /* ARGSUSED */
1038 static int
1039 nsc_fd_dev(uintptr_t addr, const void *data, void *cbdata)
1041 struct complex_args *fdall = cbdata;
1042 nsc_iodev_t *iodev;
1043 nsc_fd_t *fd;
1045 if (mdb_vread(&iodev, sizeof (iodev),
1046 addr + OFFSETOF(nsc_dev_t, nsc_list)) == -1) {
1047 mdb_warn("unable to read nsc_dev_t.nsc_list at %p", addr);
1048 return (WALK_ERR);
1051 /* walk iodev chains */
1053 if (iodev != NULL) {
1054 if (mdb_pwalk("nsctl`nsc_iodev",
1055 nsc_fd_iodev, fdall, (uintptr_t)iodev) == -1)
1056 return (WALK_ERR);
1059 /* walk nsc_close (closing fds) chains */
1061 if (mdb_vread(&fd, sizeof (fd),
1062 addr + OFFSETOF(nsc_dev_t, nsc_close)) == -1) {
1063 mdb_warn("unable to read nsc_dev_t.nsc_close at %p", addr);
1064 return (WALK_ERR);
1067 if (fd != NULL) {
1068 if (mdb_pwalk_dcmd("nsctl`nsc_fd", "nsctl`nsc_fd",
1069 fdall->argc, fdall->argv, (uintptr_t)fd) == -1)
1070 return (WALK_ERR);
1073 return (WALK_NEXT);
1078 * Walk all devices and fds in the system.
1080 static int
1081 nsc_fd_all(int argc, const mdb_arg_t *argv)
1083 struct complex_args fdall;
1085 fdall.argc = argc;
1086 fdall.argv = (mdb_arg_t *)argv;
1088 complex_walk = 1;
1089 complex_hdr = 0;
1091 if (mdb_walk("nsctl`nsc_dev", nsc_fd_dev, &fdall) == -1) {
1092 return (DCMD_ERR);
1095 return (DCMD_OK);
1101 * Display an nsd_fd_t structure, or walk all devices and fds in the system.
1103 static int
1104 nsc_fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1106 char io_name[128], *io_namep;
1107 char path[NSC_MAXPATH+1];
1108 uintptr_t pathp;
1109 nsc_fd_t *fd;
1110 nsc_io_t *io;
1111 int v_opt;
1112 int hdr;
1114 v_opt = 0;
1116 if (mdb_getopts(argc, argv,
1117 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
1118 return (DCMD_USAGE);
1120 if (!(flags & DCMD_ADDRSPEC)) {
1121 return (nsc_fd_all(argc, argv));
1124 memset(path, 0, sizeof (path));
1125 fd = mdb_zalloc(sizeof (*fd), UM_SLEEP | UM_GC);
1126 memset(io_name, 0, sizeof (io_name));
1128 if (mdb_vread(fd, sizeof (*fd), addr) != sizeof (*fd)) {
1129 mdb_warn("failed to read nsc_fd at %p", addr);
1130 return (DCMD_ERR);
1133 if (mdb_vread(&pathp, sizeof (pathp),
1134 (uintptr_t)fd->sf_dev + OFFSETOF(nsc_dev_t, nsc_path)) !=
1135 sizeof (pathp)) {
1136 mdb_warn("failed to read nsc_dev.nsc_path");
1137 return (DCMD_ERR);
1140 if (mdb_readstr(path, sizeof (path), pathp) == -1) {
1141 mdb_warn("failed to read nsc_path");
1142 return (DCMD_ERR);
1145 if (fd->sf_iodev) {
1146 if (mdb_vread(&io, sizeof (io),
1147 (uintptr_t)fd->sf_iodev + OFFSETOF(nsc_iodev_t, si_io)) !=
1148 sizeof (io)) {
1149 mdb_warn("failed to read nsc_iodev.si_io");
1150 return (DCMD_ERR);
1153 if (mdb_vread(&io_namep, sizeof (io_namep),
1154 (uintptr_t)io + OFFSETOF(nsc_io_t, name)) !=
1155 sizeof (io_namep)) {
1156 mdb_warn("failed to read nsc_io_t.name");
1157 return (DCMD_ERR);
1160 if (mdb_readstr(io_name, sizeof (io_name),
1161 (uintptr_t)io_namep) == -1) {
1162 mdb_warn("failed to read nsc_io_t.name string");
1163 return (DCMD_ERR);
1167 hdr = 0;
1168 if (complex_walk) {
1169 if (!complex_hdr) {
1170 complex_hdr = 1;
1171 hdr = 1;
1173 } else if (DCMD_HDRSPEC(flags)) {
1174 hdr = 1;
1177 if (hdr) {
1178 mdb_printf("%-?s %8T%-?s %8T%-8s %-?s\n",
1179 "fd", "dev", "io", "cd");
1180 mdb_printf(" %-?s %8Trv pend av path\n", "arg");
1183 mdb_printf("%0?p %8T%0?p %8T%-8s %p\n",
1184 addr, fd->sf_dev, io_name, fd->sf_cd);
1185 mdb_printf(" %0?p %8T%2d %4x %2x %s\n",
1186 fd->sf_arg, fd->sf_reserve, fd->sf_pend,
1187 fd->sf_avail, path);
1189 if (!v_opt)
1190 return (DCMD_OK);
1192 mdb_inc_indent(4);
1194 mdb_printf("open type: %08x <%b>\n", fd->sf_type,
1195 fd->sf_type, nsc_type_bits);
1197 mdb_printf("avail: %08x <%b>\n", fd->sf_avail,
1198 fd->sf_avail, nsc_availpend_bits);
1200 mdb_printf("flag: %08x <%b>\n", fd->sf_flag,
1201 fd->sf_flag, nsc_fdflag_bits);
1203 mdb_printf("rsrv mode: %08x <%b>\n", fd->sf_mode,
1204 fd->sf_mode, nsc_fdmode_bits);
1206 mdb_printf("open lbolt: %?x %8Treopen: %d\n", fd->sf_lbolt,
1207 fd->sf_reopen);
1209 mdb_dec_indent(4);
1211 return (DCMD_OK);
1215 /* ---------------------------------------------------------------------- */
1218 * Callback for the all devices and iodevs walk. Called per device.
1220 /* ARGSUSED */
1221 static int
1222 nsc_iodev_dev(uintptr_t addr, const void *data, void *cbdata)
1224 struct complex_args *iodevall = cbdata;
1225 uintptr_t iodev;
1227 if (mdb_vread(&iodev, sizeof (iodev),
1228 addr + OFFSETOF(nsc_dev_t, nsc_list)) == -1) {
1229 mdb_warn("unable to read nsc_dev_t.nsc_list at %p", addr);
1230 return (WALK_ERR);
1233 /* walk iodev chains */
1235 if (iodev != NULL) {
1236 if (mdb_pwalk_dcmd("nsctl`nsc_iodev", "nsctl`nsc_iodev",
1237 iodevall->argc, iodevall->argv, iodev) == -1)
1238 return (WALK_ERR);
1241 return (WALK_NEXT);
1246 * Walk all devices and iodevs in the system.
1248 static int
1249 nsc_iodev_all(int argc, const mdb_arg_t *argv)
1251 struct complex_args iodevall;
1253 iodevall.argc = argc;
1254 iodevall.argv = (mdb_arg_t *)argv;
1256 complex_walk = 1;
1257 complex_hdr = 0;
1259 if (mdb_walk("nsctl`nsc_dev", nsc_iodev_dev, &iodevall) == -1) {
1260 return (DCMD_ERR);
1263 return (DCMD_OK);
1268 * Display an nsc_iodev_t structure, or walk all devices and
1269 * iodevs in the system.
1271 static int
1272 nsc_iodev(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1274 char io_name[128], *io_namep;
1275 char path[NSC_MAXPATH+1];
1276 nsc_iodev_t *iodev;
1277 uintptr_t pathp;
1278 int v_opt;
1279 int hdr;
1281 v_opt = 0;
1283 if (mdb_getopts(argc, argv,
1284 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
1285 return (DCMD_USAGE);
1287 if (!(flags & DCMD_ADDRSPEC)) {
1288 return (nsc_iodev_all(argc, argv));
1291 memset(path, 0, sizeof (path));
1292 iodev = mdb_zalloc(sizeof (*iodev), UM_SLEEP | UM_GC);
1293 memset(io_name, 0, sizeof (io_name));
1295 if (mdb_vread(iodev, sizeof (*iodev), addr) != sizeof (*iodev)) {
1296 mdb_warn("failed to read nsc_iodev at %p", addr);
1297 return (DCMD_ERR);
1300 if (mdb_vread(&pathp, sizeof (pathp),
1301 (uintptr_t)iodev->si_dev + OFFSETOF(nsc_dev_t, nsc_path)) !=
1302 sizeof (pathp)) {
1303 mdb_warn("failed to read nsc_dev.nsc_path");
1304 return (DCMD_ERR);
1307 if (mdb_readstr(path, sizeof (path), pathp) == -1) {
1308 mdb_warn("failed to read nsc_path");
1309 return (DCMD_ERR);
1312 if (mdb_vread(&io_namep, sizeof (io_namep),
1313 (uintptr_t)iodev->si_io + OFFSETOF(nsc_io_t, name)) !=
1314 sizeof (io_namep)) {
1315 mdb_warn("failed to read nsc_io_t.name");
1316 return (DCMD_ERR);
1319 if (mdb_readstr(io_name, sizeof (io_name),
1320 (uintptr_t)io_namep) == -1) {
1321 mdb_warn("failed to read nsc_io_t.name string");
1322 return (DCMD_ERR);
1325 hdr = 0;
1326 if (complex_walk) {
1327 if (!complex_hdr) {
1328 complex_hdr = 1;
1329 hdr = 1;
1331 } else if (DCMD_HDRSPEC(flags)) {
1332 hdr = 1;
1335 if (hdr) {
1336 mdb_printf("%-?s %8T%-?s ref %-8s path\n",
1337 "iodev", "dev", "io");
1340 mdb_printf("%0?p %8T%0?p %3d %-8s %s\n",
1341 addr, iodev->si_dev, iodev->si_refcnt, io_name, path);
1343 if (!v_opt)
1344 return (DCMD_OK);
1346 mdb_inc_indent(4);
1348 mdb_printf("open fds: %?p %8Tactive ios: %?p\n",
1349 iodev->si_open, iodev->si_active);
1351 mdb_printf("busy: %d %8Trsrv pend: %d\n",
1352 iodev->si_busy, iodev->si_rpend);
1354 mdb_printf("pend: %08x <%b>\n", iodev->si_pend,
1355 iodev->si_pend, nsc_availpend_bits);
1357 mdb_printf("avail: %08x <%b>\n", iodev->si_avail,
1358 iodev->si_avail, nsc_availpend_bits);
1360 mdb_dec_indent(4);
1362 return (DCMD_OK);
1366 /* ---------------------------------------------------------------------- */
1369 * Display an nsc_service_t structure, or walk all services.
1371 static int
1372 nsc_service(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1374 nsc_service_t *service;
1375 char s_name[32];
1376 int v_opt;
1378 v_opt = 0;
1380 if (mdb_getopts(argc, argv,
1381 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
1382 return (DCMD_USAGE);
1384 if (!(flags & DCMD_ADDRSPEC)) {
1385 if (mdb_walk_dcmd("nsctl`nsc_service",
1386 "nsctl`nsc_service", argc, argv) == -1) {
1387 mdb_warn("failed to walk 'nsc_service'");
1388 return (DCMD_ERR);
1391 return (DCMD_OK);
1394 service = mdb_zalloc(sizeof (*service), UM_SLEEP | UM_GC);
1396 if (mdb_vread(service, sizeof (*service), addr) != sizeof (*service)) {
1397 mdb_warn("failed to read nsc_service at %p", addr);
1398 return (DCMD_ERR);
1401 if (DCMD_HDRSPEC(flags)) {
1402 mdb_printf("%-?s %8Tname\n", "service");
1405 memset(s_name, 0, sizeof (s_name));
1406 if (service->s_name) {
1407 if (mdb_readstr(s_name, sizeof (s_name),
1408 (uintptr_t)service->s_name) == -1) {
1409 mdb_warn("failed to read nsc_io_t.name");
1410 return (DCMD_ERR);
1414 mdb_printf("%0?p %8T%s\n", addr, s_name);
1416 if (!v_opt)
1417 return (DCMD_OK);
1419 mdb_inc_indent(4);
1421 mdb_printf("servers:\n");
1422 if (service->s_servers == NULL) {
1423 mdb_printf("<none>\n");
1424 } else {
1425 mdb_inc_indent(4);
1426 if (mdb_pwalk_dcmd("nsctl`nsc_svc", "nsctl`nsc_svc",
1427 argc, argv, (uintptr_t)service->s_servers) == -1) {
1428 mdb_dec_indent(8);
1429 return (DCMD_ERR);
1431 mdb_dec_indent(4);
1434 mdb_printf("clients:\n");
1435 if (service->s_clients == NULL) {
1436 mdb_printf("<none>\n");
1437 } else {
1438 mdb_inc_indent(4);
1439 if (mdb_pwalk_dcmd("nsctl`nsc_svc", "nsctl`nsc_svc",
1440 argc, argv, (uintptr_t)service->s_clients) == -1) {
1441 mdb_dec_indent(8);
1442 return (DCMD_ERR);
1444 mdb_dec_indent(4);
1447 mdb_dec_indent(4);
1449 return (DCMD_OK);
1453 /* ---------------------------------------------------------------------- */
1456 * Display an nsc_svc_t structure.
1458 /*ARGSUSED*/
1459 static int
1460 nsc_svc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1462 nsc_svc_t *svc;
1464 if (!(flags & DCMD_ADDRSPEC))
1465 return (DCMD_USAGE);
1467 svc = mdb_zalloc(sizeof (*svc), UM_SLEEP | UM_GC);
1469 if (mdb_vread(svc, sizeof (*svc), addr) != sizeof (*svc)) {
1470 mdb_warn("failed to read nsc_svc at %p", addr);
1471 return (DCMD_ERR);
1474 if (DCMD_HDRSPEC(flags)) {
1475 mdb_printf("%-?s %8T%-?s %8Tfunc\n", "svc", "service");
1478 mdb_printf("%0?p %8T%0?p %8T%a\n", addr, svc->svc_svc, svc->svc_fn);
1479 return (DCMD_OK);
1483 /* ---------------------------------------------------------------------- */
1486 * Display a single nsc_val_t structure.
1487 * If called with no address, performs a global walk of all nsc_devs.
1489 /* ARGSUSED3 */
1490 static int
1491 nsc_val(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1493 nsc_val_t *vp;
1495 if (argc != 0)
1496 return (DCMD_USAGE);
1498 if (!(flags & DCMD_ADDRSPEC)) {
1499 mdb_warn("nsc_val requires an address");
1500 return (DCMD_ERR);
1503 vp = mdb_zalloc(sizeof (*vp), UM_SLEEP | UM_GC);
1505 if (mdb_vread(vp, sizeof (*vp), addr) != sizeof (*vp)) {
1506 mdb_warn("failed to read nsc_val at %p", addr);
1507 return (DCMD_ERR);
1510 if (DCMD_HDRSPEC(flags)) {
1511 mdb_printf("%-?s %8T%8-s %8Tname\n", "val", "value");
1514 mdb_printf("%0?p %8T%08x %8T%s\n", addr, vp->sv_value, vp->sv_name);
1516 return (DCMD_OK);
1520 /* ---------------------------------------------------------------------- */
1523 * Display an nstset_t structure, or walk all sets.
1526 static int
1527 nstset(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1529 nstset_t *set;
1530 int f_opt, r_opt, t_opt, v_opt;
1532 f_opt = r_opt = t_opt = v_opt = 0;
1534 if (mdb_getopts(argc, argv,
1535 'f', MDB_OPT_SETBITS, TRUE, &f_opt, /* free list */
1536 'r', MDB_OPT_SETBITS, TRUE, &r_opt, /* reuse list */
1537 't', MDB_OPT_SETBITS, TRUE, &t_opt, /* all threads */
1538 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
1539 return (DCMD_USAGE);
1541 /* displaying threads implies verbose */
1542 if (f_opt || r_opt || t_opt)
1543 v_opt = 1;
1545 if (!(flags & DCMD_ADDRSPEC)) {
1546 if (mdb_walk_dcmd("nsctl`nstset",
1547 "nsctl`nstset", argc, argv) == -1) {
1548 mdb_warn("failed to walk 'nstset'");
1549 return (DCMD_ERR);
1552 return (DCMD_OK);
1555 set = mdb_zalloc(sizeof (*set), UM_SLEEP | UM_GC);
1557 if (mdb_vread(set, sizeof (*set), addr) != sizeof (*set)) {
1558 mdb_warn("failed to read nstset at %p", addr);
1559 return (DCMD_ERR);
1562 if (DCMD_HDRSPEC(flags)) {
1563 mdb_printf("%-?s %8T live nthr flag name\n", "set");
1566 mdb_printf("%0?p %8T%6d %6d %4x %s\n", addr,
1567 set->set_nlive, set->set_nthread, set->set_flag, set->set_name);
1569 if (!v_opt)
1570 return (DCMD_OK);
1572 mdb_inc_indent(4);
1574 mdb_printf("chain: %0?p %8Tpending: %4d res_cnt: %4d\n",
1575 set->set_chain, set->set_pending, set->set_res_cnt);
1577 if (set->set_reuse.q_forw == set->set_reuse.q_back &&
1578 (uintptr_t)set->set_reuse.q_forw ==
1579 (addr + OFFSETOF(nstset_t, set_reuse))) {
1580 mdb_printf("reuse.forw: %-?s %8Treuse.back: %s\n",
1581 "empty", "empty");
1582 } else {
1583 mdb_printf("reuse.forw: %0?p %8Treuse.back: %0?p\n",
1584 set->set_reuse.q_forw, set->set_reuse.q_back);
1586 /* display all threads in reuse list */
1587 if (r_opt &&
1588 mdb_pwalk_dcmd("nsctl`nst_free", "nsctl`nsthread",
1589 0, (const mdb_arg_t *)NULL,
1590 (addr + OFFSETOF(nstset_t, set_reuse))) == -1) {
1591 mdb_dec_indent(4);
1592 return (DCMD_ERR);
1596 if (set->set_free.q_forw == set->set_free.q_back &&
1597 (uintptr_t)set->set_free.q_forw ==
1598 (addr + OFFSETOF(nstset_t, set_free))) {
1599 mdb_printf("free.forw: %-?s %8Tfree.back: %s\n",
1600 "empty", "empty");
1601 } else {
1602 mdb_printf("free.forw: %0?p %8Tfree.back: %0?p\n",
1603 set->set_free.q_forw, set->set_free.q_back);
1605 /* display all threads in free list */
1606 if (f_opt &&
1607 mdb_pwalk_dcmd("nsctl`nst_free", "nsctl`nsthread",
1608 0, (const mdb_arg_t *)NULL,
1609 (addr + OFFSETOF(nstset_t, set_free))) == -1) {
1610 mdb_dec_indent(4);
1611 return (DCMD_ERR);
1615 mdb_printf("flag: %08x <%b>\n",
1616 set->set_flag, set->set_flag, nstset_flag_bits);
1618 /* display all threads in set */
1619 if (t_opt) {
1620 mdb_printf("all threads in set:\n");
1621 if (mdb_pwalk_dcmd("nsctl`nsthread", "nsctl`nsthread",
1622 0, (const mdb_arg_t *)NULL,
1623 (uintptr_t)set->set_chain) == -1) {
1624 mdb_dec_indent(4);
1625 return (DCMD_ERR);
1629 mdb_dec_indent(4);
1631 return (DCMD_OK);
1635 /* ---------------------------------------------------------------------- */
1638 * Callback for the all nstsets and threads walk. Called per set.
1640 /* ARGSUSED */
1641 static int
1642 nst_thr_set(uintptr_t addr, const void *data, void *cbdata)
1644 struct complex_args *thrall = cbdata;
1645 char set_name[48];
1646 uintptr_t tp;
1648 if (mdb_vread(&tp, sizeof (tp),
1649 addr + OFFSETOF(nstset_t, set_chain)) == -1) {
1650 mdb_warn("unable to read nstset_t.set_chain at %p", addr);
1651 return (WALK_ERR);
1654 memset(set_name, 0, sizeof (set_name));
1656 if (mdb_readstr(set_name, sizeof (set_name),
1657 addr + OFFSETOF(nstset_t, set_name)) == -1) {
1658 mdb_warn("unable to read nstset_t.set_name at %p", addr);
1661 mdb_printf("nstset: %0?p (%s)\n", addr, set_name);
1663 /* walk thread chains */
1665 if (tp != NULL) {
1666 if (mdb_pwalk_dcmd("nsctl`nsthread", "nsctl`nsthread",
1667 thrall->argc, thrall->argv, tp) == -1)
1668 return (WALK_ERR);
1669 } else
1670 mdb_printf(" no threads\n");
1672 mdb_printf("\n");
1674 return (WALK_NEXT);
1679 * Walk all nstsets and threads in the system.
1681 static int
1682 nst_thr_all(int argc, const mdb_arg_t *argv)
1684 struct complex_args thrall;
1686 thrall.argc = argc;
1687 thrall.argv = (mdb_arg_t *)argv;
1689 if (mdb_walk("nsctl`nstset", nst_thr_set, &thrall) == -1)
1690 return (DCMD_ERR);
1692 return (DCMD_OK);
1697 * Display an nsthread_t structure, or walk all threads.
1700 static int
1701 nsthread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1703 uintptr_t thrpend;
1704 nsthread_t *tp;
1705 int a_opt, v_opt;
1706 int rc;
1708 a_opt = v_opt = 0;
1710 if (mdb_getopts(argc, argv,
1711 'a', MDB_OPT_SETBITS, TRUE, &a_opt,
1712 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
1713 return (DCMD_USAGE);
1715 if (!(flags & DCMD_ADDRSPEC)) {
1716 if ((rc = nst_thr_all(argc, argv)) != DCMD_OK)
1717 return (rc);
1719 if (a_opt) {
1720 if (mdb_readvar(&thrpend, "nst_pending") == -1) {
1721 mdb_warn("unable to read 'nst_pending'");
1722 return (DCMD_ERR);
1725 if (thrpend) {
1726 mdb_printf("\nPending threads:\n");
1728 if (mdb_pwalk_dcmd("nsctl`nsthread",
1729 "nsctl`nsthread", argc, argv,
1730 thrpend) == -1) {
1731 mdb_warn("failed to walk 'nsthread'");
1732 return (DCMD_ERR);
1737 return (DCMD_OK);
1740 tp = mdb_zalloc(sizeof (*tp), UM_SLEEP | UM_GC);
1742 if (mdb_vread(tp, sizeof (*tp), addr) != sizeof (*tp)) {
1743 mdb_warn("failed to read nsthread at %p", addr);
1744 return (DCMD_ERR);
1747 if (DCMD_HDRSPEC(flags)) {
1748 mdb_printf("%-?s %8Tflag %-?s %8Tfunc\n", "thread", "arg");
1751 mdb_printf("%0?p %8T%4x %0?p %8T%a\n",
1752 addr, tp->tp_flag, tp->tp_arg, tp->tp_func);
1754 if (!v_opt)
1755 return (DCMD_OK);
1757 mdb_inc_indent(4);
1759 mdb_printf("set: %0?p %8Tchain: %0?p\n",
1760 tp->tp_set, tp->tp_chain);
1762 mdb_printf("link.forw: %0?p %8Tlink.back: %0?p\n",
1763 tp->tp_link.q_forw, tp->tp_link.q_back);
1765 mdb_printf("flag: %08x <%b>\n",
1766 tp->tp_flag, tp->tp_flag, nst_flag_bits);
1768 mdb_dec_indent(4);
1770 return (DCMD_OK);
1774 /* ---------------------------------------------------------------------- */
1776 static void
1777 nsc_rmap(char *name)
1779 nsc_rmmap_t slot;
1780 uintptr_t addr;
1781 int nslot;
1782 char *cp;
1784 if (mdb_readvar(&addr, name) == -1) {
1785 mdb_warn("unable to read rmap '%s'", name);
1786 return;
1789 if (mdb_vread(&slot, sizeof (slot), addr) != sizeof (slot)) {
1790 mdb_warn("unable to read rmap '%s' slot 0", name);
1791 return;
1794 mdb_printf("\nmap name offset size nslot\n");
1795 mdb_printf("%16s %9d %9d %5d\n",
1796 slot.name, slot.offset, slot.size, slot.inuse);
1798 nslot = slot.inuse;
1799 mdb_printf("\nslot name offset size inuse\n");
1801 while (--nslot) {
1802 addr += sizeof (slot);
1804 if (mdb_vread(&slot, sizeof (slot), addr) != sizeof (slot)) {
1805 mdb_warn("unable to read rmap '%s' slot @ %p",
1806 name, addr);
1807 return;
1810 if (!slot.inuse || !slot.size)
1811 continue;
1813 for (cp = slot.name; *cp; cp++)
1814 if (*cp == ':')
1815 *cp = ' ';
1817 mdb_printf("%16s %9d %9d %08x\n",
1818 slot.name, slot.offset, slot.size, slot.inuse);
1823 static void
1824 nsc_rmhdr(void)
1826 nsc_rmhdr_t *rmhdr = mdb_zalloc(sizeof (*rmhdr), UM_SLEEP | UM_GC);
1827 uintptr_t addr;
1829 if (mdb_readvar(&addr, "_nsc_rmhdr_ptr") == -1) {
1830 mdb_warn("unable to read _nsc_rmhdr_ptr");
1831 return;
1834 if (!addr) {
1835 mdb_printf("\n\nGlobal header not initialised\n");
1836 return;
1839 if (mdb_vread(rmhdr, sizeof (*rmhdr), addr) != sizeof (*rmhdr)) {
1840 mdb_warn("unable to read global header at %p", addr);
1841 return;
1844 mdb_printf("\n\nglobal header (magic %08x, version %d, size %d)\n",
1845 rmhdr->magic, rmhdr->ver, rmhdr->size);
1847 nsc_rmap("_nsc_global_map");
1851 static nsc_mem_t *
1852 memptr(int type, int flag)
1854 int i;
1856 type &= NSC_MEM_GLOBAL;
1858 if (type)
1859 flag = 0;
1861 if (!type && !flag)
1862 return (&type_mem[0]);
1864 for (i = 1; i < (sizeof (type_mem) / sizeof (nsc_mem_t)); i++) {
1865 if (!type_mem[i].flag && !type_mem[i].type) {
1866 type_mem[i].flag = flag;
1867 type_mem[i].type = type;
1868 return (&type_mem[i]);
1871 if (type_mem[i].flag == flag && type_mem[i].type == type)
1872 return (&type_mem[i]);
1875 return (&type_mem[i]);
1879 #define typename(t) \
1880 (((t) & NSC_MEM_GLOBAL) ? "gbl" : " - ")
1882 #define memname(t) \
1883 (((t) & NSC_MEM_GLOBAL) ? "nsc_global" : "system kmem")
1885 static void
1886 nsc_mem_type(const int first, nsc_mem_t *mp)
1888 char *type, *name;
1890 if (first) {
1891 mdb_printf("\nregion typ f ");
1892 mdb_printf("used hwm pgs alloc free\n");
1895 type = typename(mp->type);
1896 name = memname(mp->type);
1898 mdb_printf("%16s %s %2x %9d %9d %6d %5d %5d\n",
1899 name, type, mp->flag, mp->used, mp->hwm, mp->pagehwm,
1900 mp->nalloc, mp->nfree);
1904 static int
1905 nsc_mem_all(int argc, const mdb_arg_t *argv, int v_opt)
1907 int first;
1908 int i;
1910 memset(type_mem, 0, sizeof (type_mem));
1912 if (mdb_walk_dcmd("nsctl`nsc_mem",
1913 "nsctl`nsc_mem", argc, argv) == -1) {
1914 mdb_warn("unable to walk 'nsc_mem'");
1915 return (DCMD_ERR);
1918 for (first = 1, i = 0;
1919 i < (sizeof (type_mem) / sizeof (nsc_mem_t)); first = 0, i++) {
1920 if (type_mem[i].nalloc || type_mem[i].hwm) {
1921 nsc_mem_type(first, &type_mem[i]);
1925 if (v_opt)
1926 nsc_rmhdr();
1928 return (DCMD_OK);
1932 static int
1933 nsc_mem(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1935 char name[16], *type, *cp;
1936 nsc_mem_t mem, *mp;
1937 int v_opt;
1939 v_opt = 0;
1941 if (mdb_getopts(argc, argv,
1942 'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
1943 return (DCMD_USAGE);
1945 if (!(flags & DCMD_ADDRSPEC)) {
1946 return (nsc_mem_all(argc, argv, v_opt));
1949 if (mdb_vread(&mem, sizeof (mem), addr) != sizeof (mem)) {
1950 mdb_warn("failed to read nsc_mem_t at %p", addr);
1951 return (DCMD_ERR);
1954 if (mdb_readstr(name, sizeof (name), (uintptr_t)mem.name) == -1) {
1955 mdb_warn("failed to read nsc_mem_t.name at %p", addr);
1956 return (DCMD_ERR);
1959 if (!mem.nalloc && !mem.hwm && !v_opt)
1960 return (DCMD_OK);
1962 if (DCMD_HDRSPEC(flags)) {
1963 mdb_printf("name typ f ");
1964 mdb_printf("used hwm pgs alloc free base\n");
1967 type = typename(mem.type);
1968 mp = memptr(mem.type, mem.flag);
1970 for (cp = name; *cp; cp++)
1971 if (*cp == ':')
1972 *cp = ' ';
1974 mdb_printf("%-16s %s %2x %9d %9d %5d %5d %5d %0?p\n",
1975 name, type, mem.flag, mem.used, mem.hwm, mem.pagehwm,
1976 mem.nalloc, mem.nfree, mem.base);
1978 mp->used += mem.used;
1979 mp->hwm += mem.hwm;
1980 mp->pagehwm += mem.pagehwm;
1981 mp->nalloc += mem.nalloc;
1982 mp->nfree += mem.nfree;
1984 return (DCMD_OK);
1987 /*ARGSUSED*/
1988 static int
1989 nsc_vec(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1991 nsc_vec_t *vec;
1993 vec = mdb_zalloc(sizeof (*vec), UM_SLEEP | UM_GC);
1994 if (mdb_vread(vec, sizeof (*vec), addr) != sizeof (*vec)) {
1995 mdb_warn("failed to read nsc_vec at %p", addr);
1996 return (DCMD_ERR);
1998 mdb_printf("nsc_vec_t @ 0x%p = {\n", addr);
1999 mdb_inc_indent(4);
2000 mdb_printf("sv_addr: %p\n", vec->sv_addr);
2001 mdb_printf("sv_vme: %lu\n", vec->sv_vme);
2002 mdb_printf("sv_len: %d\n", vec->sv_len);
2003 mdb_dec_indent(4);
2004 mdb_printf("};\n");
2005 if (vec->sv_addr)
2006 return (DCMD_OK);
2007 else
2008 return (DCMD_ERR);
2011 /* ---------------------------------------------------------------------- */
2013 * Display an nsc_buf_t structure.
2016 #ifdef NSC_MULTI_TERABYTE
2017 #define STRCONV "ll"
2018 #else
2019 #define STRCONV ""
2020 #endif
2022 /* ARGSUSED */
2023 static int
2024 nsc_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2026 nsc_buf_t *bh;
2027 nsc_vec_t *v;
2029 if (!(flags & DCMD_ADDRSPEC))
2030 return (DCMD_USAGE);
2032 bh = mdb_zalloc(sizeof (*bh), UM_SLEEP | UM_GC);
2034 if (mdb_vread(bh, sizeof (*bh), addr) != sizeof (*bh)) {
2035 mdb_warn("failed to read nsc_buf at %p", addr);
2036 return (DCMD_ERR);
2039 mdb_printf("nsc_buf_t @ 0x%p = {\n", addr);
2040 mdb_inc_indent(4);
2041 mdb_printf("sb_fd: 0x%p\n", bh->sb_fd);
2042 mdb_printf("sb_pos: 0x%" STRCONV "x\n", bh->sb_pos);
2043 mdb_printf("sb_len: 0x%" STRCONV "x\n", bh->sb_len);
2044 mdb_printf("sb_flag: 0x%08x <%b>\n", bh->sb_flag,
2045 bh->sb_flag, nsc_bhflag_bits);
2046 mdb_printf("sb_error: %d\n", bh->sb_error);
2047 #ifdef NSC_MULTI_TERABYTE
2048 mdb_printf("sb_user: 0x%p\n", bh->sb_user);
2049 #else
2050 mdb_printf("sb_user: 0x%x\n", bh->sb_user);
2051 #endif
2052 mdb_printf("sb_vec: 0x%p\n", bh->sb_vec);
2053 v = bh->sb_vec++;
2054 while (nsc_vec((uintptr_t)v, flags, argc, argv) == DCMD_OK)
2055 v++;
2057 mdb_dec_indent(4);
2058 mdb_printf("};\n");
2060 return (DCMD_OK);
2063 /* ---------------------------------------------------------------------- */
2065 /* ARGSUSED */
2066 static int
2067 nsc_dbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2069 nsc_dbuf_t *bh;
2071 if (!(flags & DCMD_ADDRSPEC))
2072 return (DCMD_USAGE);
2074 bh = mdb_zalloc(sizeof (*bh), UM_SLEEP | UM_GC);
2076 if (mdb_vread(bh, sizeof (*bh), addr) != sizeof (*bh)) {
2077 mdb_warn("failed to read nsc_dbuf at %p", addr);
2078 return (DCMD_ERR);
2081 mdb_printf("nsc_dbuf_t @ 0x%p = {\n", addr);
2082 mdb_inc_indent(4);
2083 mdb_printf("db_disc: 0x%p\n", bh->db_disc);
2084 mdb_printf("db_addr: 0x%p\n", bh->db_addr);
2085 mdb_printf("db_next: 0x%p\n", bh->db_next);
2086 mdb_printf("db_maxfbas: 0x%d\n", bh->db_maxfbas);
2089 mdb_dec_indent(4);
2090 mdb_printf("};\n");
2092 return (DCMD_OK);
2094 /* ---------------------------------------------------------------------- */
2097 * MDB module linkage information:
2100 static const mdb_dcmd_t dcmds[] = {
2101 #if 0
2102 { "nsctl", NULL, "display nsctl module info", nsctl },
2103 #endif
2104 { "nsc_buf", ":", "list nsc_buf structure", nsc_buf },
2105 { "nsc_dbuf", ":", "list nsc_dbuf structure", nsc_dbuf },
2106 { "nsc_dev", "?[-av]", "list nsc_dev structure", nsc_dev },
2107 { "nsc_devval", "?[-a]", "list nsc_devval structure", nsc_devval },
2108 { "nsc_fd", "?[-v]", "list nsc_fd structure", nsc_fd },
2109 { "nsc_iodev", "?[-v]", "list nsc_iodev structure", nsc_iodev },
2110 { "nsc_io", "?[-v]", "list nsc_io structure", nsc_io },
2111 { "nsc_mem", "?[-v]", "list nsc_mem structure", nsc_mem },
2112 { "nsc_svc", ":", "list nsc_svc structure", nsc_svc },
2113 { "nsc_service", "?[-v]", "list nsc_service structure", nsc_service },
2114 { "nsc_val", ":", "list nsc_val structure", nsc_val },
2115 { "nstset", "?[-frtv]", "list nstset structure", nstset },
2116 { "nsthread", "?[-av]", "list nsthread structure", nsthread },
2117 { NULL }
2121 static const mdb_walker_t walkers[] = {
2122 { "nsc_dev", "walk nsc_dev chain",
2123 nsc_dev_winit, nsc_dev_wstep, nsc_dev_wfini, NULL },
2124 { "nsc_devval", "walk nsc_devval chain",
2125 nsc_devval_winit, nsc_devval_wstep, NULL, NULL },
2126 { "nsc_fd", "walk nsc_fd chain",
2127 nsc_fd_winit, nsc_fd_wstep, NULL, NULL },
2128 { "nsc_io", "walk nsc_io chain",
2129 nsc_io_winit, nsc_io_wstep, NULL, NULL },
2130 { "nsc_iodev", "walk nsc_iodev chain",
2131 nsc_iodev_winit, nsc_iodev_wstep, NULL, NULL },
2132 { "nsc_mem", "walk nsc_mem chain",
2133 nsc_mem_winit, nsc_mem_wstep, NULL, NULL },
2134 { "nsc_service", "walk nsc_service chain",
2135 nsc_service_winit, nsc_service_wstep, NULL, NULL },
2136 { "nsc_svc", "walk nsc_svc chain",
2137 nsc_svc_winit, nsc_svc_wstep, NULL, NULL },
2138 { "nsc_val", "walk nsc_val chain",
2139 nsc_val_winit, nsc_val_wstep, NULL, NULL },
2140 { "nstset", "walk nstset chain",
2141 nstset_winit, nstset_wstep, NULL, NULL },
2142 { "nsthread", "walk nsthread chain",
2143 nsthread_winit, nsthread_wstep, NULL, NULL },
2144 { "nst_free", "walk nsthread free/reuse list",
2145 nst_free_winit, nst_free_wstep, NULL, NULL },
2146 { NULL }
2150 static const mdb_modinfo_t modinfo = {
2151 MDB_API_VERSION, dcmds, walkers
2155 const mdb_modinfo_t *
2156 _mdb_init(void)
2158 return (&modinfo);