xref: /titanic_41/usr/src/cmd/mdb/common/modules/smbsrv/smbsrv.c (revision 1816cb7076d3ec8a78ef9ac9f895574e13c43645)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/mdb_modapi.h>
27 #include <sys/thread.h>
28 #include <sys/taskq_impl.h>
29 #include <smbsrv/smb_vops.h>
30 #include <smbsrv/smb.h>
31 #include <smbsrv/smb_ktypes.h>
32 
33 #define	SMB_DCMD_INDENT		2
34 #define	ACE_TYPE_TABLEN		(ACE_ALL_TYPES + 1)
35 #define	ACE_TYPE_ENTRY(_v_)	{_v_, #_v_}
36 #define	SMB_COM_ENTRY(_v_, _x_)	{#_v_, _x_}
37 
38 #define	SMB_MDB_MAX_OPTS	10
39 
40 #define	SMB_OPT_SERVER		0x00000001
41 #define	SMB_OPT_VFS		0x00000002
42 #define	SMB_OPT_SESSION		0x00000004
43 #define	SMB_OPT_REQUEST		0x00000008
44 #define	SMB_OPT_USER		0x00000010
45 #define	SMB_OPT_TREE		0x00000020
46 #define	SMB_OPT_OFILE		0x00000040
47 #define	SMB_OPT_ODIR		0x00000080
48 #define	SMB_OPT_WALK		0x00000100
49 #define	SMB_OPT_VERBOSE		0x00000200
50 #define	SMB_OPT_ALL_OBJ		0x000000FF
51 
52 /*
53  * Structure associating an ACE type to a string.
54  */
55 typedef struct {
56 	uint8_t		ace_type_value;
57 	const char	*ace_type_sting;
58 } ace_type_entry_t;
59 
60 /*
61  * Structure containing strings describing an SMB command.
62  */
63 typedef struct {
64 	const char	*smb_com;
65 	const char	*smb_andx;
66 } smb_com_entry_t;
67 
68 /*
69  * Structure describing an object to be expanded (displayed).
70  */
71 typedef struct {
72 	uint_t		ex_mask;
73 	size_t		ex_offset;
74 	const char	*ex_dcmd;
75 	const char	*ex_name;
76 } smb_exp_t;
77 
78 /*
79  * List of supported options. Ther order has the match the bits SMB_OPT_xxx.
80  */
81 static const char *smb_opts[SMB_MDB_MAX_OPTS] =
82 {
83 	"-s", "-m", "-e", "-r", "-u", "-t", "-f", "-d", "-w", "-v"
84 };
85 
86 static smb_com_entry_t	smb_com[256] =
87 {
88 	SMB_COM_ENTRY(SMB_COM_CREATE_DIRECTORY, "No"),
89 	SMB_COM_ENTRY(SMB_COM_DELETE_DIRECTORY, "No"),
90 	SMB_COM_ENTRY(SMB_COM_OPEN, "No"),
91 	SMB_COM_ENTRY(SMB_COM_CREATE, "No"),
92 	SMB_COM_ENTRY(SMB_COM_CLOSE, "No"),
93 	SMB_COM_ENTRY(SMB_COM_FLUSH, "No"),
94 	SMB_COM_ENTRY(SMB_COM_DELETE, "No"),
95 	SMB_COM_ENTRY(SMB_COM_RENAME, "No"),
96 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION, "No"),
97 	SMB_COM_ENTRY(SMB_COM_SET_INFORMATION, "No"),
98 	SMB_COM_ENTRY(SMB_COM_READ, "No"),
99 	SMB_COM_ENTRY(SMB_COM_WRITE, "No"),
100 	SMB_COM_ENTRY(SMB_COM_LOCK_BYTE_RANGE, "No"),
101 	SMB_COM_ENTRY(SMB_COM_UNLOCK_BYTE_RANGE, "No"),
102 	SMB_COM_ENTRY(SMB_COM_CREATE_TEMPORARY, "No"),
103 	SMB_COM_ENTRY(SMB_COM_CREATE_NEW, "No"),
104 	SMB_COM_ENTRY(SMB_COM_CHECK_DIRECTORY, "No"),
105 	SMB_COM_ENTRY(SMB_COM_PROCESS_EXIT, "No"),
106 	SMB_COM_ENTRY(SMB_COM_SEEK, "No"),
107 	SMB_COM_ENTRY(SMB_COM_LOCK_AND_READ, "No"),
108 	SMB_COM_ENTRY(SMB_COM_WRITE_AND_UNLOCK, "No"),
109 	SMB_COM_ENTRY(0x15, "?"),
110 	SMB_COM_ENTRY(0x16, "?"),
111 	SMB_COM_ENTRY(0x17, "?"),
112 	SMB_COM_ENTRY(0x18, "?"),
113 	SMB_COM_ENTRY(0x19, "?"),
114 	SMB_COM_ENTRY(SMB_COM_READ_RAW, "No"),
115 	SMB_COM_ENTRY(SMB_COM_READ_MPX, "No"),
116 	SMB_COM_ENTRY(SMB_COM_READ_MPX_SECONDARY, "No"),
117 	SMB_COM_ENTRY(SMB_COM_WRITE_RAW, "No"),
118 	SMB_COM_ENTRY(SMB_COM_WRITE_MPX, "No"),
119 	SMB_COM_ENTRY(SMB_COM_WRITE_MPX_SECONDARY, "No"),
120 	SMB_COM_ENTRY(SMB_COM_WRITE_COMPLETE, "No"),
121 	SMB_COM_ENTRY(SMB_COM_QUERY_SERVER, "No"),
122 	SMB_COM_ENTRY(SMB_COM_SET_INFORMATION2, "No"),
123 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION2, "No"),
124 	SMB_COM_ENTRY(SMB_COM_LOCKING_ANDX, "No"),
125 	SMB_COM_ENTRY(SMB_COM_TRANSACTION, "No"),
126 	SMB_COM_ENTRY(SMB_COM_TRANSACTION_SECONDARY, "No"),
127 	SMB_COM_ENTRY(SMB_COM_IOCTL, "No"),
128 	SMB_COM_ENTRY(SMB_COM_IOCTL_SECONDARY, "No"),
129 	SMB_COM_ENTRY(SMB_COM_COPY, "No"),
130 	SMB_COM_ENTRY(SMB_COM_MOVE, "No"),
131 	SMB_COM_ENTRY(SMB_COM_ECHO, "No"),
132 	SMB_COM_ENTRY(SMB_COM_WRITE_AND_CLOSE, "No"),
133 	SMB_COM_ENTRY(SMB_COM_OPEN_ANDX, "No"),
134 	SMB_COM_ENTRY(SMB_COM_READ_ANDX, "No"),
135 	SMB_COM_ENTRY(SMB_COM_WRITE_ANDX, "No"),
136 	SMB_COM_ENTRY(SMB_COM_NEW_FILE_SIZE, "No"),
137 	SMB_COM_ENTRY(SMB_COM_CLOSE_AND_TREE_DISC, "No"),
138 	SMB_COM_ENTRY(SMB_COM_TRANSACTION2, "No"),
139 	SMB_COM_ENTRY(SMB_COM_TRANSACTION2_SECONDARY, "No"),
140 	SMB_COM_ENTRY(SMB_COM_FIND_CLOSE2, "No"),
141 	SMB_COM_ENTRY(SMB_COM_FIND_NOTIFY_CLOSE, "No"),
142 	SMB_COM_ENTRY(0x36, "?"),
143 	SMB_COM_ENTRY(0x37, "?"),
144 	SMB_COM_ENTRY(0x38, "?"),
145 	SMB_COM_ENTRY(0x39, "?"),
146 	SMB_COM_ENTRY(0x3A, "?"),
147 	SMB_COM_ENTRY(0x3B, "?"),
148 	SMB_COM_ENTRY(0x3C, "?"),
149 	SMB_COM_ENTRY(0x3D, "?"),
150 	SMB_COM_ENTRY(0x3E, "?"),
151 	SMB_COM_ENTRY(0x3F, "?"),
152 	SMB_COM_ENTRY(0x40, "?"),
153 	SMB_COM_ENTRY(0x41, "?"),
154 	SMB_COM_ENTRY(0x42, "?"),
155 	SMB_COM_ENTRY(0x43, "?"),
156 	SMB_COM_ENTRY(0x44, "?"),
157 	SMB_COM_ENTRY(0x45, "?"),
158 	SMB_COM_ENTRY(0x46, "?"),
159 	SMB_COM_ENTRY(0x47, "?"),
160 	SMB_COM_ENTRY(0x48, "?"),
161 	SMB_COM_ENTRY(0x49, "?"),
162 	SMB_COM_ENTRY(0x4A, "?"),
163 	SMB_COM_ENTRY(0x4B, "?"),
164 	SMB_COM_ENTRY(0x4C, "?"),
165 	SMB_COM_ENTRY(0x4D, "?"),
166 	SMB_COM_ENTRY(0x4E, "?"),
167 	SMB_COM_ENTRY(0x4F, "?"),
168 	SMB_COM_ENTRY(0x50, "?"),
169 	SMB_COM_ENTRY(0x51, "?"),
170 	SMB_COM_ENTRY(0x52, "?"),
171 	SMB_COM_ENTRY(0x53, "?"),
172 	SMB_COM_ENTRY(0x54, "?"),
173 	SMB_COM_ENTRY(0x55, "?"),
174 	SMB_COM_ENTRY(0x56, "?"),
175 	SMB_COM_ENTRY(0x57, "?"),
176 	SMB_COM_ENTRY(0x58, "?"),
177 	SMB_COM_ENTRY(0x59, "?"),
178 	SMB_COM_ENTRY(0x5A, "?"),
179 	SMB_COM_ENTRY(0x5B, "?"),
180 	SMB_COM_ENTRY(0x5C, "?"),
181 	SMB_COM_ENTRY(0x5D, "?"),
182 	SMB_COM_ENTRY(0x5E, "?"),
183 	SMB_COM_ENTRY(0x5F, "?"),
184 	SMB_COM_ENTRY(0x60, "?"),
185 	SMB_COM_ENTRY(0x61, "?"),
186 	SMB_COM_ENTRY(0x62, "?"),
187 	SMB_COM_ENTRY(0x63, "?"),
188 	SMB_COM_ENTRY(0x64, "?"),
189 	SMB_COM_ENTRY(0x65, "?"),
190 	SMB_COM_ENTRY(0x66, "?"),
191 	SMB_COM_ENTRY(0x67, "?"),
192 	SMB_COM_ENTRY(0x68, "?"),
193 	SMB_COM_ENTRY(0x69, "?"),
194 	SMB_COM_ENTRY(0x6A, "?"),
195 	SMB_COM_ENTRY(0x6B, "?"),
196 	SMB_COM_ENTRY(0x6C, "?"),
197 	SMB_COM_ENTRY(0x6D, "?"),
198 	SMB_COM_ENTRY(0x6E, "?"),
199 	SMB_COM_ENTRY(0x6F, "?"),
200 	SMB_COM_ENTRY(SMB_COM_TREE_CONNECT, "No"),
201 	SMB_COM_ENTRY(SMB_COM_TREE_DISCONNECT, "No"),
202 	SMB_COM_ENTRY(SMB_COM_NEGOTIATE, "No"),
203 	SMB_COM_ENTRY(SMB_COM_SESSION_SETUP_ANDX, "No"),
204 	SMB_COM_ENTRY(SMB_COM_LOGOFF_ANDX, "No"),
205 	SMB_COM_ENTRY(SMB_COM_TREE_CONNECT_ANDX, "No"),
206 	SMB_COM_ENTRY(0x76, "?"),
207 	SMB_COM_ENTRY(0x77, "?"),
208 	SMB_COM_ENTRY(0x78, "?"),
209 	SMB_COM_ENTRY(0x79, "?"),
210 	SMB_COM_ENTRY(0x7A, "?"),
211 	SMB_COM_ENTRY(0x7B, "?"),
212 	SMB_COM_ENTRY(0x7C, "?"),
213 	SMB_COM_ENTRY(0x7D, "?"),
214 	SMB_COM_ENTRY(0x7E, "?"),
215 	SMB_COM_ENTRY(0x7F, "?"),
216 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION_DISK, "No"),
217 	SMB_COM_ENTRY(SMB_COM_SEARCH, "No"),
218 	SMB_COM_ENTRY(SMB_COM_FIND, "No"),
219 	SMB_COM_ENTRY(SMB_COM_FIND_UNIQUE, "No"),
220 	SMB_COM_ENTRY(SMB_COM_FIND_CLOSE, "No"),
221 	SMB_COM_ENTRY(0x85, "?"),
222 	SMB_COM_ENTRY(0x86, "?"),
223 	SMB_COM_ENTRY(0x87, "?"),
224 	SMB_COM_ENTRY(0x88, "?"),
225 	SMB_COM_ENTRY(0x89, "?"),
226 	SMB_COM_ENTRY(0x8A, "?"),
227 	SMB_COM_ENTRY(0x8B, "?"),
228 	SMB_COM_ENTRY(0x8C, "?"),
229 	SMB_COM_ENTRY(0x8D, "?"),
230 	SMB_COM_ENTRY(0x8E, "?"),
231 	SMB_COM_ENTRY(0x8F, "?"),
232 	SMB_COM_ENTRY(0x90, "?"),
233 	SMB_COM_ENTRY(0x91, "?"),
234 	SMB_COM_ENTRY(0x92, "?"),
235 	SMB_COM_ENTRY(0x93, "?"),
236 	SMB_COM_ENTRY(0x94, "?"),
237 	SMB_COM_ENTRY(0x95, "?"),
238 	SMB_COM_ENTRY(0x96, "?"),
239 	SMB_COM_ENTRY(0x97, "?"),
240 	SMB_COM_ENTRY(0x98, "?"),
241 	SMB_COM_ENTRY(0x99, "?"),
242 	SMB_COM_ENTRY(0x9A, "?"),
243 	SMB_COM_ENTRY(0x9B, "?"),
244 	SMB_COM_ENTRY(0x9C, "?"),
245 	SMB_COM_ENTRY(0x9D, "?"),
246 	SMB_COM_ENTRY(0x9E, "?"),
247 	SMB_COM_ENTRY(0x9F, "?"),
248 	SMB_COM_ENTRY(SMB_COM_NT_TRANSACT, "No"),
249 	SMB_COM_ENTRY(SMB_COM_NT_TRANSACT_SECONDARY, "No"),
250 	SMB_COM_ENTRY(SMB_COM_NT_CREATE_ANDX, "No"),
251 	SMB_COM_ENTRY(0xA3, "?"),
252 	SMB_COM_ENTRY(SMB_COM_NT_CANCEL, "No"),
253 	SMB_COM_ENTRY(SMB_COM_NT_RENAME, "No"),
254 	SMB_COM_ENTRY(0xA6, "?"),
255 	SMB_COM_ENTRY(0xA7, "?"),
256 	SMB_COM_ENTRY(0xA8, "?"),
257 	SMB_COM_ENTRY(0xA9, "?"),
258 	SMB_COM_ENTRY(0xAA, "?"),
259 	SMB_COM_ENTRY(0xAB, "?"),
260 	SMB_COM_ENTRY(0xAC, "?"),
261 	SMB_COM_ENTRY(0xAD, "?"),
262 	SMB_COM_ENTRY(0xAE, "?"),
263 	SMB_COM_ENTRY(0xAF, "?"),
264 	SMB_COM_ENTRY(0xB0, "?"),
265 	SMB_COM_ENTRY(0xB1, "?"),
266 	SMB_COM_ENTRY(0xB2, "?"),
267 	SMB_COM_ENTRY(0xB3, "?"),
268 	SMB_COM_ENTRY(0xB4, "?"),
269 	SMB_COM_ENTRY(0xB5, "?"),
270 	SMB_COM_ENTRY(0xB6, "?"),
271 	SMB_COM_ENTRY(0xB7, "?"),
272 	SMB_COM_ENTRY(0xB8, "?"),
273 	SMB_COM_ENTRY(0xB9, "?"),
274 	SMB_COM_ENTRY(0xBA, "?"),
275 	SMB_COM_ENTRY(0xBB, "?"),
276 	SMB_COM_ENTRY(0xBC, "?"),
277 	SMB_COM_ENTRY(0xBD, "?"),
278 	SMB_COM_ENTRY(0xBE, "?"),
279 	SMB_COM_ENTRY(0xBF, "?"),
280 	SMB_COM_ENTRY(SMB_COM_OPEN_PRINT_FILE, "No"),
281 	SMB_COM_ENTRY(SMB_COM_WRITE_PRINT_FILE, "No"),
282 	SMB_COM_ENTRY(SMB_COM_CLOSE_PRINT_FILE, "No"),
283 	SMB_COM_ENTRY(SMB_COM_GET_PRINT_QUEUE, "No"),
284 	SMB_COM_ENTRY(0xC4, "?"),
285 	SMB_COM_ENTRY(0xC5, "?"),
286 	SMB_COM_ENTRY(0xC6, "?"),
287 	SMB_COM_ENTRY(0xC7, "?"),
288 	SMB_COM_ENTRY(0xC8, "?"),
289 	SMB_COM_ENTRY(0xC9, "?"),
290 	SMB_COM_ENTRY(0xCA, "?"),
291 	SMB_COM_ENTRY(0xCB, "?"),
292 	SMB_COM_ENTRY(0xCC, "?"),
293 	SMB_COM_ENTRY(0xCD, "?"),
294 	SMB_COM_ENTRY(0xCE, "?"),
295 	SMB_COM_ENTRY(0xCF, "?"),
296 	SMB_COM_ENTRY(0xD0, "?"),
297 	SMB_COM_ENTRY(0xD1, "?"),
298 	SMB_COM_ENTRY(0xD2, "?"),
299 	SMB_COM_ENTRY(0xD3, "?"),
300 	SMB_COM_ENTRY(0xD4, "?"),
301 	SMB_COM_ENTRY(0xD5, "?"),
302 	SMB_COM_ENTRY(0xD6, "?"),
303 	SMB_COM_ENTRY(0xD7, "?"),
304 	SMB_COM_ENTRY(SMB_COM_READ_BULK, "No"),
305 	SMB_COM_ENTRY(SMB_COM_WRITE_BULK, "No"),
306 	SMB_COM_ENTRY(SMB_COM_WRITE_BULK_DATA, "No"),
307 	SMB_COM_ENTRY(0xDB, "?"),
308 	SMB_COM_ENTRY(0xDC, "?"),
309 	SMB_COM_ENTRY(0xDD, "?"),
310 	SMB_COM_ENTRY(0xDE, "?"),
311 	SMB_COM_ENTRY(0xDF, "?"),
312 	SMB_COM_ENTRY(0xE0, "?"),
313 	SMB_COM_ENTRY(0xE1, "?"),
314 	SMB_COM_ENTRY(0xE2, "?"),
315 	SMB_COM_ENTRY(0xE3, "?"),
316 	SMB_COM_ENTRY(0xE4, "?"),
317 	SMB_COM_ENTRY(0xE5, "?"),
318 	SMB_COM_ENTRY(0xE6, "?"),
319 	SMB_COM_ENTRY(0xE7, "?"),
320 	SMB_COM_ENTRY(0xE8, "?"),
321 	SMB_COM_ENTRY(0xE9, "?"),
322 	SMB_COM_ENTRY(0xEA, "?"),
323 	SMB_COM_ENTRY(0xEB, "?"),
324 	SMB_COM_ENTRY(0xEC, "?"),
325 	SMB_COM_ENTRY(0xED, "?"),
326 	SMB_COM_ENTRY(0xEE, "?"),
327 	SMB_COM_ENTRY(0xEF, "?"),
328 	SMB_COM_ENTRY(0xF0, "?"),
329 	SMB_COM_ENTRY(0xF1, "?"),
330 	SMB_COM_ENTRY(0xF2, "?"),
331 	SMB_COM_ENTRY(0xF3, "?"),
332 	SMB_COM_ENTRY(0xF4, "?"),
333 	SMB_COM_ENTRY(0xF5, "?"),
334 	SMB_COM_ENTRY(0xF6, "?"),
335 	SMB_COM_ENTRY(0xF7, "?"),
336 	SMB_COM_ENTRY(0xF8, "?"),
337 	SMB_COM_ENTRY(0xF9, "?"),
338 	SMB_COM_ENTRY(0xFA, "?"),
339 	SMB_COM_ENTRY(0xFB, "?"),
340 	SMB_COM_ENTRY(0xFC, "?"),
341 	SMB_COM_ENTRY(0xFD, "?"),
342 	SMB_COM_ENTRY(0xFE, "?"),
343 	SMB_COM_ENTRY(0xFF, "?")
344 };
345 
346 static int smb_dcmd_list(uintptr_t, uint_t, int, const mdb_arg_t *);
347 static void smb_dcmd_list_help(void);
348 static int smb_dcmd_server(uintptr_t, uint_t, int, const mdb_arg_t *);
349 static int smb_dcmd_vfs(uintptr_t, uint_t, int, const mdb_arg_t *);
350 static void smb_dcmd_session_help(void);
351 static int smb_dcmd_session(uintptr_t, uint_t, int, const mdb_arg_t *);
352 static int smb_dcmd_request(uintptr_t, uint_t, int, const mdb_arg_t *);
353 static void smb_dcmd_user_help(void);
354 static int smb_dcmd_user(uintptr_t, uint_t, int, const mdb_arg_t *);
355 static void smb_dcmd_tree_help(void);
356 static int smb_dcmd_tree(uintptr_t, uint_t, int, const mdb_arg_t *);
357 static int smb_dcmd_odir(uintptr_t, uint_t, int, const mdb_arg_t *);
358 static int smb_dcmd_ofile(uintptr_t, uint_t, int, const mdb_arg_t *);
359 static void smb_node_help(void);
360 static int smb_node(uintptr_t, uint_t, int, const mdb_arg_t *);
361 static int smb_node_walk_init(mdb_walk_state_t *);
362 static int smb_node_walk_step(mdb_walk_state_t *);
363 static int smb_lock(uintptr_t, uint_t, int, const mdb_arg_t *);
364 static int smb_stats(uintptr_t, uint_t, int, const mdb_arg_t *);
365 static int smb_ace(uintptr_t, uint_t, int, const mdb_arg_t *);
366 static int smb_ace_walk_init(mdb_walk_state_t *);
367 static int smb_ace_walk_step(mdb_walk_state_t *);
368 static int smb_acl(uintptr_t, uint_t, int, const mdb_arg_t *);
369 static int smb_sd(uintptr_t, uint_t, int, const mdb_arg_t *);
370 static int smb_sid(uintptr_t, uint_t, int, const mdb_arg_t *);
371 static int smb_sid_print(uintptr_t);
372 static int smb_fssd(uintptr_t, uint_t, int, const mdb_arg_t *);
373 static int smb_dcmd_getopt(uint_t *, int, const mdb_arg_t *);
374 static int smb_dcmd_setopt(uint_t, int, mdb_arg_t *);
375 static int smb_obj_expand(uintptr_t, uint_t, const smb_exp_t *, ulong_t);
376 static int smb_obj_list(const char *, uint_t, uint_t);
377 static int smb_worker_findstack(uintptr_t);
378 
379 /*
380  * MDB module linkage information:
381  *
382  * We declare a list of structures describing our dcmds, a list of structures
383  * describing our walkers and a function named _mdb_init to return a pointer
384  * to our module information.
385  */
386 static const mdb_dcmd_t dcmds[] = {
387 	{   "smblist",
388 	    "[-seutfdwv]",
389 	    "print tree of SMB objects",
390 	    smb_dcmd_list,
391 	    smb_dcmd_list_help },
392 	{   "smbsrv",
393 	    "[-seutfdwv]",
394 	    "print smb_server information",
395 	    smb_dcmd_server },
396 	{   "smbvfs",
397 	    "[-v]",
398 	    "print smb_vfs information",
399 	    smb_dcmd_vfs },
400 	{   "smbnode",
401 	    "?[-vps]",
402 	    "print smb_node_t information",
403 	    smb_node,
404 	    smb_node_help },
405 	{   "smbsess",
406 	    "[-utfdwv]",
407 	    "print smb_session_t information",
408 	    smb_dcmd_session,
409 	    smb_dcmd_session_help},
410 	{   "smbreq",
411 	    ":[-v]",
412 	    "print smb_request_t information",
413 	    smb_dcmd_request },
414 	{   "smblock", ":[-v]",
415 	    "print smb_lock_t information", smb_lock },
416 	{   "smbuser",
417 	    ":[-vdftq]",
418 	    "print smb_user_t information",
419 	    smb_dcmd_user,
420 	    smb_dcmd_user_help },
421 	{   "smbtree",
422 	    ":[-vdf]",
423 	    "print smb_tree_t information",
424 	    smb_dcmd_tree,
425 	    smb_dcmd_tree_help },
426 	{   "smbodir",
427 	    ":[-v]",
428 	    "print smb_odir_t information",
429 	    smb_dcmd_odir },
430 	{   "smbofile",
431 	    "[-v]",
432 	    "print smb_odir_t information",
433 	    smb_dcmd_ofile },
434 	{   "smbstats", NULL,
435 	    "print all smb dispatched requests statistics", smb_stats },
436 	{   "smbace", "[-v]",
437 	    "print smb_ace_t information", smb_ace },
438 	{   "smbacl", "[-v]",
439 	    "print smb_acl_t information", smb_acl },
440 	{   "smbsid", "[-v]",
441 	    "print smb_sid_t information", smb_sid },
442 	{   "smbsd", "[-v]",
443 	    "print smb_sd_t information", smb_sd },
444 	{   "smbfssd", "[-v]",
445 	    "print smb_fssd_t information", smb_fssd },
446 	{ NULL }
447 };
448 
449 static const mdb_walker_t walkers[] = {
450 	{   "smbnode_walker",
451 	    "walk list of smb_node_t structures",
452 	    smb_node_walk_init,
453 	    smb_node_walk_step,
454 	    NULL,
455 	    NULL },
456 	{   "smbace_walker",
457 	    "walk list of smb_ace_t structures",
458 	    smb_ace_walk_init,
459 	    smb_ace_walk_step,
460 	    NULL,
461 	    NULL },
462 	{ NULL }
463 };
464 
465 static const mdb_modinfo_t modinfo = {
466 	MDB_API_VERSION, dcmds, walkers
467 };
468 
469 const mdb_modinfo_t *
470 _mdb_init(void)
471 {
472 	return (&modinfo);
473 }
474 
475 /*
476  * *****************************************************************************
477  * ****************************** Top level DCMD *******************************
478  * *****************************************************************************
479  */
480 
481 static void
482 smb_dcmd_list_help(void)
483 {
484 	mdb_printf(
485 	    "Displays the list of objects using an indented tree format.\n"
486 	    "If no option is specified the entire tree is displayed\n\n");
487 	(void) mdb_dec_indent(2);
488 	mdb_printf("%<b>OPTIONS%</b>\n");
489 	(void) mdb_inc_indent(2);
490 	mdb_printf(
491 	    "-v\tDisplay verbose information\n"
492 	    "-s\tDisplay the list of servers\n"
493 	    "-m\tDisplay the list of shared file systems\n"
494 	    "-e\tDisplay the list of sessions\n"
495 	    "-r\tDisplay the list of smb requests\n"
496 	    "-u\tDisplay the list of users\n"
497 	    "-t\tDisplay the list of trees\n"
498 	    "-f\tDisplay the list of open files\n"
499 	    "-d\tDisplay the list of open searches\n");
500 }
501 
502 /*
503  * ::smblist
504  *
505  * This function lists the objects specified on the command line. If no object
506  * is specified the entire tree (server through ofile and odir) is displayed.
507  *
508  */
509 /*ARGSUSED*/
510 static int
511 smb_dcmd_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
512 {
513 	GElf_Sym	sym;
514 	uint_t		opts = 0;
515 	int		new_argc;
516 	mdb_arg_t	new_argv[SMB_MDB_MAX_OPTS];
517 
518 	if (smb_dcmd_getopt(&opts, argc, argv))
519 		return (DCMD_USAGE);
520 
521 	if (!(opts & ~(SMB_OPT_WALK | SMB_OPT_VERBOSE)))
522 		opts |= SMB_OPT_ALL_OBJ;
523 
524 	opts |= SMB_OPT_WALK;
525 
526 	new_argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, new_argv);
527 
528 	if (mdb_lookup_by_name("smb_servers", &sym) == -1) {
529 		mdb_warn("failed to find symbol smb_servers");
530 		return (DCMD_ERR);
531 	}
532 
533 	addr = (uintptr_t)sym.st_value + offsetof(smb_llist_t, ll_list);
534 
535 	if (mdb_pwalk_dcmd("list", "smbsrv", new_argc, new_argv, addr))
536 		return (DCMD_ERR);
537 	return (DCMD_OK);
538 }
539 
540 /*
541  * *****************************************************************************
542  * ***************************** smb_server_t **********************************
543  * *****************************************************************************
544  */
545 
546 static const char *smb_server_state[SMB_SERVER_STATE_SENTINEL] =
547 {
548 	"CREATED",
549 	"CONFIGURED",
550 	"RUNNING",
551 	"DELETING"
552 };
553 
554 /*
555  * List of objects that can be expanded under a server structure.
556  */
557 static const smb_exp_t smb_server_exp[] =
558 {
559 	{ SMB_OPT_ALL_OBJ,
560 	    offsetof(smb_server_t, sv_nbt_daemon.ld_session_list.se_rdy.lst),
561 	    "smbsess", "smb_session"},
562 	{ SMB_OPT_ALL_OBJ,
563 	    offsetof(smb_server_t, sv_nbt_daemon.ld_session_list.se_act.lst),
564 	    "smbsess", "smb_session"},
565 	{ SMB_OPT_ALL_OBJ,
566 	    offsetof(smb_server_t, sv_tcp_daemon.ld_session_list.se_rdy.lst),
567 	    "smbsess", "smb_session"},
568 	{ SMB_OPT_ALL_OBJ,
569 	    offsetof(smb_server_t, sv_tcp_daemon.ld_session_list.se_act.lst),
570 	    "smbsess", "smb_session"},
571 	{ SMB_OPT_ALL_OBJ,
572 	    offsetof(smb_server_t, sv_vfs_list.ll_list),
573 	    "smbvfs", "smb_vfs"},
574 	{ 0, 0, NULL, NULL }
575 };
576 
577 /*
578  * ::smbsrv
579  *
580  * smbsrv dcmd - Print out smb_server structures.
581  */
582 /*ARGSUSED*/
583 static int
584 smb_dcmd_server(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
585 {
586 	uint_t		opts;
587 	ulong_t		indent = 0;
588 
589 	if (smb_dcmd_getopt(&opts, argc, argv))
590 		return (DCMD_USAGE);
591 
592 	if (!(flags & DCMD_ADDRSPEC))
593 		return (smb_obj_list("smb_server", opts | SMB_OPT_SERVER,
594 		    flags));
595 
596 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SERVER)) ||
597 	    !(opts & SMB_OPT_WALK)) {
598 		smb_server_t	*sv;
599 		const char	*state;
600 
601 		sv = mdb_alloc(sizeof (smb_server_t), UM_SLEEP | UM_GC);
602 		if (mdb_vread(sv, sizeof (smb_server_t), addr) == -1) {
603 			mdb_warn("failed to read smb_server at %p", addr);
604 			return (DCMD_ERR);
605 		}
606 
607 		indent = SMB_DCMD_INDENT;
608 
609 		if (opts & SMB_OPT_VERBOSE) {
610 			mdb_arg_t	argv;
611 
612 			argv.a_type = MDB_TYPE_STRING;
613 			argv.a_un.a_str = "smb_server_t";
614 			if (mdb_call_dcmd("print", addr, flags, 1, &argv))
615 				return (DCMD_ERR);
616 		} else {
617 			if (DCMD_HDRSPEC(flags))
618 				mdb_printf(
619 				    "%<b>%<u>%-?s% "
620 				    "%-4s% "
621 				    "%-32s% "
622 				    "%-6s% "
623 				    "%-6s% "
624 				    "%-6s%</u>%</b>\n",
625 				    "SERVER", "ZONE", "STATE", "USERS",
626 				    "TREES", "FILES");
627 
628 			if (sv->sv_state >= SMB_SERVER_STATE_SENTINEL)
629 				state = "UNKNOWN";
630 			else
631 				state = smb_server_state[sv->sv_state];
632 
633 			mdb_printf("%-?p %-4d %-32s %-6d %-6d %-6d \n",
634 			    addr, sv->sv_zid, state, sv->sv_open_users,
635 			    sv->sv_open_trees, sv->sv_open_files);
636 		}
637 	}
638 	if (smb_obj_expand(addr, opts, smb_server_exp, indent))
639 		return (DCMD_ERR);
640 	return (DCMD_OK);
641 }
642 
643 /*
644  * *****************************************************************************
645  * ******************************** smb_vfs_t **********************************
646  * *****************************************************************************
647  */
648 
649 /*
650  * ::smbvfs
651  *
652  * smbvfs dcmd - Prints out smb_vfs structures.
653  */
654 /*ARGSUSED*/
655 static int
656 smb_dcmd_vfs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
657 {
658 
659 	uint_t		opts;
660 
661 	if (smb_dcmd_getopt(&opts, argc, argv))
662 		return (DCMD_USAGE);
663 
664 	if (!(flags & DCMD_ADDRSPEC)) {
665 		return (smb_obj_list("smb_vfs", SMB_OPT_VFS, flags));
666 	}
667 
668 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_VFS)) ||
669 	    !(opts & SMB_OPT_WALK)) {
670 		smb_vfs_t	*sf;
671 		vnode_t		*vn;
672 		char		*path;
673 
674 		sf = mdb_alloc(sizeof (*sf), UM_SLEEP | UM_GC);
675 		if (mdb_vread(sf, sizeof (*sf), addr) == -1) {
676 			mdb_warn("failed to read smb_vfs at %p", addr);
677 			return (DCMD_ERR);
678 		}
679 		vn = mdb_alloc(sizeof (*vn), UM_SLEEP | UM_GC);
680 		if (mdb_vread(vn, sizeof (*vn),
681 		    (uintptr_t)sf->sv_rootvp) == -1) {
682 			mdb_warn("failed to read vnode at %p", sf->sv_rootvp);
683 			return (DCMD_ERR);
684 		}
685 		path = mdb_zalloc(MAXPATHLEN, UM_SLEEP | UM_GC);
686 		(void) mdb_vread(path, MAXPATHLEN, (uintptr_t)vn->v_path);
687 
688 		if (DCMD_HDRSPEC(flags))
689 			mdb_printf(
690 			    "%<b>%<u>"
691 			    "%-?s "
692 			    "%-10s "
693 			    "%-16s "
694 			    "%-16s"
695 			    "%-s"
696 			    "%</u>%</b>\n",
697 			    "SMB_VFS", "REFCNT", "VFS", "VNODE", "ROOT");
698 		mdb_printf(
699 		    "%-?p %-10d %-?p %-?p %-s\n", addr, sf->sv_refcnt,
700 		    sf->sv_vfsp, sf->sv_rootvp, path);
701 	}
702 	return (DCMD_OK);
703 }
704 
705 /*
706  * *****************************************************************************
707  * ***************************** smb_session_t *********************************
708  * *****************************************************************************
709  */
710 
711 static const char *smb_session_state[SMB_SESSION_STATE_SENTINEL] =
712 {
713 	"INITIALIZED",
714 	"DISCONNECTED",
715 	"CONNECTED",
716 	"ESTABLISHED",
717 	"NEGOTIATED",
718 	"OPLOCK_BREAKING",
719 	"WRITE_RAW_ACTIVE",
720 	"TERMINATED"
721 };
722 
723 /*
724  * List of objects that can be expanded under a session structure.
725  */
726 static const smb_exp_t smb_session_exp[] =
727 {
728 	{ SMB_OPT_REQUEST,
729 	    offsetof(smb_session_t, s_req_list.sl_list),
730 	    "smbreq", "smb_request"},
731 	{ SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_OFILE | SMB_OPT_ODIR,
732 	    offsetof(smb_session_t, s_user_list.ll_list),
733 	    "smbuser", "smb_user"},
734 	{ 0, 0, NULL, NULL}
735 };
736 
737 static void
738 smb_dcmd_session_help(void)
739 {
740 	mdb_printf(
741 	    "Display the contents of smb_session_t, with optional"
742 	    " filtering.\n\n");
743 	(void) mdb_dec_indent(2);
744 	mdb_printf("%<b>OPTIONS%</b>\n");
745 	(void) mdb_inc_indent(2);
746 	mdb_printf(
747 	    "-v\tDisplay verbose smb_session information\n"
748 	    "-r\tDisplay the list of smb requests attached\n"
749 	    "-u\tDisplay the list of users attached\n");
750 }
751 
752 /*
753  * ::smbsess
754  *
755  * smbsess dcmd - Print out the smb_session structure.
756  */
757 /*ARGSUSED*/
758 static int
759 smb_dcmd_session(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
760 {
761 	uint_t		opts;
762 	ulong_t		indent = 0;
763 
764 	if (smb_dcmd_getopt(&opts, argc, argv))
765 		return (DCMD_USAGE);
766 
767 	if (!(flags & DCMD_ADDRSPEC)) {
768 		opts |= SMB_OPT_SESSION;
769 		opts &= ~SMB_OPT_SERVER;
770 		return (smb_obj_list("smb_session", opts, flags));
771 	}
772 
773 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SESSION)) ||
774 	    !(opts & SMB_OPT_WALK)) {
775 		smb_session_t	*se;
776 		const char	*state;
777 
778 		indent = SMB_DCMD_INDENT;
779 
780 		se = mdb_alloc(sizeof (*se), UM_SLEEP | UM_GC);
781 		if (mdb_vread(se, sizeof (*se), addr) == -1) {
782 			mdb_warn("failed to read smb_session at %p", addr);
783 			return (DCMD_ERR);
784 		}
785 
786 		if (se->s_state >= SMB_SESSION_STATE_SENTINEL)
787 			state = "INVALID";
788 		else
789 			state = smb_session_state[se->s_state];
790 
791 		if (opts & SMB_OPT_VERBOSE) {
792 			mdb_printf("%<b>%<u>SMB session information "
793 			    "(%p): %</u>%</b>\n", addr);
794 			mdb_printf("Client IP address: %I\n", se->ipaddr);
795 			mdb_printf("Local IP Address: %I\n", se->local_ipaddr);
796 			mdb_printf("Session KID: %u\n", se->s_kid);
797 			mdb_printf("Workstation Name: %s\n",
798 			    se->workstation);
799 			mdb_printf("Session state: %u (%s)\n", se->s_state,
800 			    state);
801 			mdb_printf("Number of Users: %u\n",
802 			    se->s_user_list.ll_count);
803 			mdb_printf("Number of Trees: %u\n", se->s_tree_cnt);
804 			mdb_printf("Number of Files: %u\n", se->s_file_cnt);
805 			mdb_printf("Number of Shares: %u\n", se->s_dir_cnt);
806 			mdb_printf("Number of active Transact.: %u\n\n",
807 			    se->s_xa_list.ll_count);
808 		} else {
809 			if (DCMD_HDRSPEC(flags))
810 				mdb_printf(
811 				    "%<b>%<u>%-?s "
812 				    "%-16s "
813 				    "%-16s%</u>%</b>\n",
814 				    "SESSION", "CLIENT_IP_ADDR",
815 				    "LOCAL_IP_ADDR");
816 
817 			mdb_printf(
818 			    "%-?p %-16I %-16I\n", addr, se->ipaddr.a_ipv4,
819 			    se->local_ipaddr.a_ipv4);
820 		}
821 	}
822 	if (smb_obj_expand(addr, opts, smb_session_exp, indent))
823 		return (DCMD_ERR);
824 	return (DCMD_OK);
825 }
826 
827 /*
828  * *****************************************************************************
829  * **************************** smb_request_t **********************************
830  * *****************************************************************************
831  */
832 
833 static const char *smb_request_state[SMB_REQ_STATE_SENTINEL] =
834 {
835 	"FREE",
836 	"INITIALIZING",
837 	"SUBMITTED",
838 	"ACTIVE",
839 	"WAITING_EVENT",
840 	"EVENT_OCCURRED",
841 	"WAITING_LOCK",
842 	"COMPLETED",
843 	"CANCELED",
844 	"CLEANED_UP"
845 };
846 
847 static int
848 smb_dcmd_request(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
849 {
850 	uint_t		opts;
851 
852 	if (smb_dcmd_getopt(&opts, argc, argv))
853 		return (DCMD_USAGE);
854 
855 	if (!(flags & DCMD_ADDRSPEC)) {
856 		opts |= SMB_OPT_REQUEST;
857 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_USER);
858 		return (smb_obj_list("smb_request", opts, flags));
859 	}
860 
861 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_REQUEST)) ||
862 	    !(opts & SMB_OPT_WALK)) {
863 		smb_request_t	*sr;
864 		const char	*state;
865 
866 		sr = mdb_alloc(sizeof (*sr), UM_SLEEP | UM_GC);
867 		if (mdb_vread(sr, sizeof (*sr), addr) == -1) {
868 			mdb_warn("failed to read smb_request at %p", addr);
869 			return (DCMD_ERR);
870 		}
871 
872 		if (sr->sr_state >= SMB_REQ_STATE_SENTINEL)
873 			state = "INVALID";
874 		else
875 			state = smb_request_state[sr->sr_state];
876 
877 		if (opts & SMB_OPT_VERBOSE) {
878 			mdb_printf(
879 			    "%</b>%</u>SMB request information (%p):"
880 			    "%</u>%</b>\n\n", addr);
881 			mdb_printf("First SMB COM: %u (%s)\n",
882 			    sr->first_smb_com,
883 			    smb_com[sr->first_smb_com]);
884 			mdb_printf("State: %u (%s)\n", sr->sr_state, state);
885 			mdb_printf("Tree: %u (%p)\n", sr->smb_tid,
886 			    sr->tid_tree);
887 			mdb_printf("User: %u (%p)\n", sr->smb_uid,
888 			    sr->uid_user);
889 			mdb_printf("File: %u (%p)\n",
890 			    sr->smb_fid, sr->fid_ofile);
891 			mdb_printf("PID: %u\n", sr->smb_pid);
892 			mdb_printf("MID: %u\n\n", sr->smb_mid);
893 			smb_worker_findstack((uintptr_t)sr->sr_worker);
894 		} else {
895 			if (DCMD_HDRSPEC(flags))
896 				mdb_printf(
897 				    "%<b>%<u>%-?s %-?s %-16s %s%</u>%</b>\n",
898 				    "ADDR", "Worker", "STATE", "COM");
899 
900 			mdb_printf("%-?p %-?p %-16s %s\n", addr, sr->sr_worker,
901 			    state, smb_com[sr->first_smb_com]);
902 		}
903 	}
904 	return (DCMD_OK);
905 }
906 
907 /*
908  * *****************************************************************************
909  * ****************************** smb_user_t ***********************************
910  * *****************************************************************************
911  */
912 
913 static const char *smb_user_state[SMB_USER_STATE_SENTINEL] =
914 {
915 	"LOGGED_IN",
916 	"LOGGING_OFF",
917 	"LOGGED_OFF"
918 };
919 
920 /*
921  * List of objects that can be expanded under a user structure.
922  */
923 static const smb_exp_t smb_user_exp[] =
924 {
925 	{ SMB_OPT_TREE | SMB_OPT_OFILE | SMB_OPT_ODIR,
926 	    offsetof(smb_user_t, u_tree_list.ll_list),
927 	    "smbtree", "smb_tree"},
928 	{ 0, 0, NULL, NULL}
929 };
930 
931 static void
932 smb_dcmd_user_help(void)
933 {
934 	mdb_printf(
935 	    "Display the contents of smb_user_t, with optional filtering.\n\n");
936 	(void) mdb_dec_indent(2);
937 	mdb_printf("%<b>OPTIONS%</b>\n");
938 	(void) mdb_inc_indent(2);
939 	mdb_printf(
940 	    "-v\tDisplay verbose smb_user information\n"
941 	    "-d\tDisplay the list of smb_odirs attached\n"
942 	    "-f\tDisplay the list of smb_ofiles attached\n"
943 	    "-t\tDisplay the list of smb_trees attached\n");
944 }
945 
946 static int
947 smb_dcmd_user(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
948 {
949 	uint_t		opts;
950 	ulong_t		indent = 0;
951 
952 	if (smb_dcmd_getopt(&opts, argc, argv))
953 		return (DCMD_USAGE);
954 
955 	if (!(flags & DCMD_ADDRSPEC)) {
956 		opts |= SMB_OPT_USER;
957 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST);
958 		return (smb_obj_list("smb_user", opts, flags));
959 	}
960 
961 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_USER)) ||
962 	    !(opts & SMB_OPT_WALK)) {
963 		smb_user_t	*user;
964 		char		*account;
965 
966 		indent = SMB_DCMD_INDENT;
967 
968 		user = mdb_alloc(sizeof (*user), UM_SLEEP | UM_GC);
969 		if (mdb_vread(user, sizeof (*user), addr) == -1) {
970 			mdb_warn("failed to read smb_user at %p", addr);
971 			return (DCMD_ERR);
972 		}
973 
974 		account = mdb_zalloc(user->u_domain_len + user->u_name_len + 2,
975 		    UM_SLEEP | UM_GC);
976 
977 		if (user->u_domain_len)
978 			(void) mdb_vread(account, user->u_domain_len,
979 			    (uintptr_t)user->u_domain);
980 
981 		strcat(account, "\\");
982 
983 		if (user->u_name_len)
984 			(void) mdb_vread(account + strlen(account),
985 			    user->u_name_len, (uintptr_t)user->u_name);
986 
987 		if (opts & SMB_OPT_VERBOSE) {
988 			const char	*state;
989 
990 			if (user->u_state >= SMB_USER_STATE_SENTINEL)
991 				state = "INVALID";
992 			else
993 				state = smb_user_state[user->u_state];
994 
995 			mdb_printf("%<b>%<u>SMB user information (%p):"
996 			    "%</u>%</b>\n", addr);
997 			mdb_printf("UID: %u\n", user->u_uid);
998 			mdb_printf("State: %d (%s)\n", user->u_state, state);
999 			mdb_printf("Flags: 0x%08x\n", user->u_flags);
1000 			mdb_printf("Privileges: 0x%08x\n", user->u_privileges);
1001 			mdb_printf("Credential: %p\n", user->u_cred);
1002 			mdb_printf("Reference Count: %d\n", user->u_refcnt);
1003 			mdb_printf("User Account: %s\n\n", account);
1004 		} else {
1005 			if (DCMD_HDRSPEC(flags))
1006 				mdb_printf(
1007 				    "%<b>%<u>%?-s "
1008 				    "%-5s "
1009 				    "%-32s%</u>%</b>\n",
1010 				    "USER", "UID", "ACCOUNT");
1011 
1012 			mdb_printf("%-?p %-5u %-32s\n", addr, user->u_uid,
1013 			    account);
1014 		}
1015 	}
1016 	if (smb_obj_expand(addr, opts, smb_user_exp, indent))
1017 		return (DCMD_ERR);
1018 	return (DCMD_OK);
1019 }
1020 
1021 /*
1022  * *****************************************************************************
1023  * ****************************** smb_tree_t ***********************************
1024  * *****************************************************************************
1025  */
1026 
1027 static const char *smb_tree_state[SMB_TREE_STATE_SENTINEL] =
1028 {
1029 	"CONNECTED",
1030 	"DISCONNECTING",
1031 	"DISCONNECTED"
1032 };
1033 
1034 /*
1035  * List of objects that can be expanded under a tree structure.
1036  */
1037 static const smb_exp_t smb_tree_exp[] =
1038 {
1039 	{ SMB_OPT_OFILE,
1040 	    offsetof(smb_tree_t, t_ofile_list.ll_list),
1041 	    "smbofile", "smb_ofile"},
1042 	{ SMB_OPT_ODIR,
1043 	    offsetof(smb_tree_t, t_odir_list.ll_list),
1044 	    "smbodir", "smb_odir"},
1045 	{ 0, 0, NULL, NULL}
1046 };
1047 
1048 static void
1049 smb_dcmd_tree_help(void)
1050 {
1051 	mdb_printf(
1052 	    "Display the contents of smb_tree_t, with optional filtering.\n\n");
1053 	(void) mdb_dec_indent(2);
1054 	mdb_printf("%<b>OPTIONS%</b>\n");
1055 	(void) mdb_inc_indent(2);
1056 	mdb_printf(
1057 	    "-v\tDisplay verbose smb_tree information\n"
1058 	    "-d\tDisplay the list of smb_odirs attached\n"
1059 	    "-f\tDisplay the list of smb_ofiles attached\n");
1060 }
1061 
1062 static int
1063 smb_dcmd_tree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1064 {
1065 	uint_t		opts;
1066 	ulong_t		indent = 0;
1067 
1068 	if (smb_dcmd_getopt(&opts, argc, argv))
1069 		return (DCMD_USAGE);
1070 
1071 	if (!(flags & DCMD_ADDRSPEC)) {
1072 		opts |= SMB_OPT_TREE;
1073 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1074 		    SMB_OPT_USER);
1075 		return (smb_obj_list("smb_tree", opts, flags));
1076 	}
1077 
1078 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_TREE)) ||
1079 	    !(opts & SMB_OPT_WALK)) {
1080 		smb_tree_t	*tree;
1081 
1082 		indent = SMB_DCMD_INDENT;
1083 
1084 		tree = mdb_alloc(sizeof (*tree), UM_SLEEP | UM_GC);
1085 		if (mdb_vread(tree, sizeof (*tree), addr) == -1) {
1086 			mdb_warn("failed to read smb_tree at %p", addr);
1087 			return (DCMD_ERR);
1088 		}
1089 
1090 		if (opts & SMB_OPT_VERBOSE) {
1091 			const char	*state;
1092 
1093 			if (tree->t_state >= SMB_TREE_STATE_SENTINEL)
1094 				state = "INVALID";
1095 			else
1096 				state = smb_tree_state[tree->t_state];
1097 
1098 			mdb_printf("%<b>%<u>SMB tree information (%p):"
1099 			    "%</u>%</b>\n\n", addr);
1100 			mdb_printf("TID: %04x\n", tree->t_tid);
1101 			mdb_printf("State: %d (%s)\n", tree->t_state, state);
1102 			mdb_printf("Share: %s\n", tree->t_sharename);
1103 			mdb_printf("Resource: %s\n", tree->t_resource);
1104 			mdb_printf("Type: %s\n", tree->t_typename);
1105 			mdb_printf("Volume: %s\n", tree->t_volume);
1106 			mdb_printf("Umask: %04x\n", tree->t_umask);
1107 			mdb_printf("Flags: %08x\n", tree->t_flags);
1108 			mdb_printf("SMB Node: %llx\n", tree->t_snode);
1109 			mdb_printf("Reference Count: %d\n\n", tree->t_refcnt);
1110 		} else {
1111 			if (DCMD_HDRSPEC(flags))
1112 				mdb_printf(
1113 				    "%<b>%<u>%-?s %-5s %-16s %-32s%</u>%</b>\n",
1114 				    "TREE", "TID", "SHARE NAME", "RESOURCE");
1115 
1116 			mdb_printf("%-?p %-5u %-16s %-32s\n", addr,
1117 			    tree->t_tid, tree->t_sharename, tree->t_resource);
1118 		}
1119 	}
1120 	if (smb_obj_expand(addr, opts, smb_tree_exp, indent))
1121 		return (DCMD_ERR);
1122 	return (DCMD_OK);
1123 }
1124 
1125 /*
1126  * *****************************************************************************
1127  * ****************************** smb_odir_t ***********************************
1128  * *****************************************************************************
1129  */
1130 
1131 static const char *smb_odir_state[SMB_ODIR_STATE_SENTINEL] =
1132 {
1133 	"OPEN",
1134 	"CLOSING",
1135 	"CLOSED"
1136 };
1137 
1138 static int
1139 smb_dcmd_odir(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1140 {
1141 	uint_t		opts;
1142 
1143 	if (smb_dcmd_getopt(&opts, argc, argv))
1144 		return (DCMD_USAGE);
1145 
1146 	if (!(flags & DCMD_ADDRSPEC)) {
1147 		opts |= SMB_OPT_ODIR;
1148 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1149 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_OFILE);
1150 		return (smb_obj_list("smb_odir", opts, flags));
1151 	}
1152 
1153 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_ODIR)) ||
1154 	    !(opts & SMB_OPT_WALK)) {
1155 		smb_odir_t	*od;
1156 
1157 		od = mdb_alloc(sizeof (*od), UM_SLEEP | UM_GC);
1158 		if (mdb_vread(od, sizeof (*od), addr) == -1) {
1159 			mdb_warn("failed to read smb_odir at %p", addr);
1160 			return (DCMD_ERR);
1161 		}
1162 
1163 		if (opts & SMB_OPT_VERBOSE) {
1164 			const char	*state;
1165 
1166 			if (od->d_state >= SMB_ODIR_STATE_SENTINEL)
1167 				state = "INVALID";
1168 			else
1169 				state = smb_odir_state[od->d_state];
1170 
1171 			mdb_printf(
1172 			    "%<b>%<u>SMB odir information (%p):%</u>%</b>\n\n",
1173 			    addr);
1174 			mdb_printf("State: %d (%s)\n", od->d_state, state);
1175 			mdb_printf("SID: %u\n", od->d_odid);
1176 			mdb_printf("Reference Count: %d\n", od->d_refcnt);
1177 			mdb_printf("Pattern: %s\n", od->d_pattern);
1178 			mdb_printf("SMB Node: %p\n\n", od->d_dnode);
1179 		} else {
1180 			if (DCMD_HDRSPEC(flags))
1181 				mdb_printf(
1182 				    "%<b>%<u>%-?s "
1183 				    "%-5s "
1184 				    "%-?s "
1185 				    "%-16s%</u>%</b>\n",
1186 				    "ODIR", "SID", "VNODE", "PATTERN");
1187 
1188 			mdb_printf("%?p %-5u %-16p %s\n",
1189 			    addr, od->d_odid, od->d_dnode, od->d_pattern);
1190 		}
1191 	}
1192 	return (DCMD_OK);
1193 }
1194 
1195 /*
1196  * *****************************************************************************
1197  * ****************************** smb_ofile_t **********************************
1198  * *****************************************************************************
1199  */
1200 
1201 static const char *smb_ofile_state[SMB_OFILE_STATE_SENTINEL] =
1202 {
1203 	"OPEN",
1204 	"CLOSING",
1205 	"CLOSED"
1206 };
1207 
1208 static int
1209 smb_dcmd_ofile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1210 {
1211 	uint_t		opts;
1212 
1213 	if (smb_dcmd_getopt(&opts, argc, argv))
1214 		return (DCMD_USAGE);
1215 
1216 	if (!(flags & DCMD_ADDRSPEC)) {
1217 		opts |= SMB_OPT_OFILE;
1218 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1219 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_ODIR);
1220 		return (smb_obj_list("smb_ofile", opts, flags));
1221 	}
1222 
1223 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_OFILE)) ||
1224 	    !(opts & SMB_OPT_WALK)) {
1225 		smb_ofile_t	*of;
1226 
1227 		of = mdb_alloc(sizeof (*of), UM_SLEEP | UM_GC);
1228 		if (mdb_vread(of, sizeof (*of), addr) == -1) {
1229 			mdb_warn("failed to read smb_ofile at %p", addr);
1230 			return (DCMD_ERR);
1231 		}
1232 
1233 		if (opts & SMB_OPT_VERBOSE) {
1234 			const char	*state;
1235 
1236 			if (of->f_state >= SMB_ODIR_STATE_SENTINEL)
1237 				state = "INVALID";
1238 			else
1239 				state = smb_ofile_state[of->f_state];
1240 
1241 			mdb_printf(
1242 			    "%<b>%<u>SMB ofile information (%p):%</u>%</b>\n\n",
1243 			    addr);
1244 			mdb_printf("FID: %u\n", of->f_fid);
1245 			mdb_printf("State: %d (%s)\n", of->f_state, state);
1246 			mdb_printf("SMB Node: %p\n", of->f_node);
1247 			mdb_printf("LLF Offset: 0x%llx (%s)\n",
1248 			    of->f_llf_pos,
1249 			    ((of->f_flags & SMB_OFLAGS_LLF_POS_VALID) ?
1250 			    "Valid" : "Invalid"));
1251 			mdb_printf("Flags: 0x%08x\n", of->f_flags);
1252 			mdb_printf("Credential: %p\n\n", of->f_cr);
1253 		} else {
1254 			if (DCMD_HDRSPEC(flags))
1255 				mdb_printf(
1256 				    "%<b>%<u>%-?s "
1257 				    "%-5s "
1258 				    "%-?s "
1259 				    "%-?s%</u>%</b>\n",
1260 				    "OFILE", "FID", "SMB NODE", "CRED");
1261 
1262 			mdb_printf("%?p %-5u %-p %p\n", addr,
1263 			    of->f_fid, of->f_node, of->f_cr);
1264 		}
1265 	}
1266 	return (DCMD_OK);
1267 }
1268 
1269 /*
1270  * *****************************************************************************
1271  * ******************************* smb_node_t **********************************
1272  * *****************************************************************************
1273  */
1274 
1275 static void
1276 smb_node_help(void)
1277 {
1278 	mdb_printf(
1279 	    "Display the contents of smb_node_t, with optional filtering.\n\n");
1280 	(void) mdb_dec_indent(2);
1281 	mdb_printf("%<b>OPTIONS%</b>\n");
1282 	(void) mdb_inc_indent(2);
1283 	mdb_printf(
1284 	    "-v\tDisplay verbose smb_node information\n"
1285 	    "-p\tDisplay the full path of the vnode associated\n"
1286 	    "-s\tDisplay the stack of the last 16 calls that modified the "
1287 	    "reference\n\tcount\n");
1288 }
1289 
1290 /*
1291  * ::smbnode
1292  *
1293  * smb_node dcmd - Print out smb_node structure.
1294  */
1295 static int
1296 smb_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1297 {
1298 	smb_node_t	node;
1299 	int		verbose = FALSE;
1300 	int		print_full_path = FALSE;
1301 	int		stack_trace = FALSE;
1302 	vnode_t		vnode;
1303 	char		od_name[MAXNAMELEN];
1304 	char		path_name[1024];
1305 	uintptr_t	list_addr;
1306 
1307 	if (mdb_getopts(argc, argv,
1308 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1309 	    'p', MDB_OPT_SETBITS, TRUE, &print_full_path,
1310 	    's', MDB_OPT_SETBITS, TRUE, &stack_trace,
1311 	    NULL) != argc)
1312 		return (DCMD_USAGE);
1313 
1314 	/*
1315 	 * If no smb_node address was specified on the command line, we can
1316 	 * print out all smb nodes by invoking the smb_node walker, using
1317 	 * this dcmd itself as the callback.
1318 	 */
1319 	if (!(flags & DCMD_ADDRSPEC)) {
1320 		if (mdb_walk_dcmd("smbnode_walker", "smbnode",
1321 		    argc, argv) == -1) {
1322 			mdb_warn("failed to walk 'smb_node'");
1323 			return (DCMD_ERR);
1324 		}
1325 		return (DCMD_OK);
1326 	}
1327 
1328 	/*
1329 	 * If this is the first invocation of the command, print a nice
1330 	 * header line for the output that will follow.
1331 	 */
1332 	if (DCMD_HDRSPEC(flags)) {
1333 		if (verbose) {
1334 			mdb_printf("%<b>%<u>SMB node information:%</u>%</b>\n");
1335 		} else {
1336 			mdb_printf(
1337 			    "%<b>%<u>%-?s "
1338 			    "%-?s "
1339 			    "%-18s "
1340 			    "%-6s "
1341 			    "%-6s "
1342 			    "%-6s%</u>%</b>\n",
1343 			    "ADDR", "VP", "NODE-NAME", "OFILES", "LOCKS",
1344 			    "REF");
1345 		}
1346 	}
1347 
1348 	/*
1349 	 * For each smb_node, we just need to read the smb_node_t struct, read
1350 	 * and then print out the following fields.
1351 	 */
1352 	if (mdb_vread(&node, sizeof (node), addr) == sizeof (node)) {
1353 		(void) mdb_snprintf(od_name, sizeof (od_name), "%s",
1354 		    node.od_name);
1355 		if (print_full_path) {
1356 			if (mdb_vread(&vnode, sizeof (vnode_t),
1357 			    (uintptr_t)node.vp) == sizeof (vnode_t)) {
1358 				if (mdb_readstr(path_name, sizeof (path_name),
1359 				    (uintptr_t)vnode.v_path) != 0) {
1360 					(void) mdb_snprintf(od_name,
1361 					    sizeof (od_name), "N/A");
1362 				}
1363 			}
1364 		}
1365 		if (verbose) {
1366 			mdb_printf("VP: %p\n", node.vp);
1367 			mdb_printf("Name: %s\n", od_name);
1368 			if (print_full_path)
1369 				mdb_printf("V-node Path: %s\n", path_name);
1370 			mdb_printf("Ofiles: %u\n", node.n_ofile_list.ll_count);
1371 			mdb_printf("Range Locks: %u\n",
1372 			    node.n_lock_list.ll_count);
1373 			if (node.n_lock_list.ll_count != 0) {
1374 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1375 				list_addr = addr +
1376 				    offsetof(smb_node_t, n_lock_list) +
1377 				    offsetof(smb_llist_t, ll_list);
1378 				if (mdb_pwalk_dcmd("list", "smblock", 0,
1379 				    NULL, list_addr)) {
1380 					mdb_warn("failed to walk node's active"
1381 					    " locks");
1382 				}
1383 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1384 			}
1385 			mdb_printf("Reference Count: %u\n\n", node.n_refcnt);
1386 		} else {
1387 			mdb_printf("%-?p %-?p %-18s %-6d %-6d %-6d\n",
1388 			    addr, node.vp, od_name, node.n_ofile_list.ll_count,
1389 			    node.n_lock_list.ll_count, node.n_refcnt);
1390 			if (print_full_path)
1391 				mdb_printf("\t%s\n", path_name);
1392 		}
1393 		if (stack_trace && node.n_audit_buf) {
1394 			int ctr;
1395 			smb_audit_buf_node_t *anb;
1396 
1397 			anb = mdb_alloc(sizeof (smb_audit_buf_node_t),
1398 			    UM_SLEEP | UM_GC);
1399 
1400 			if (mdb_vread(anb, sizeof (*anb),
1401 			    (uintptr_t)node.n_audit_buf) != sizeof (*anb)) {
1402 				mdb_warn("failed to read audit buffer");
1403 				return (DCMD_ERR);
1404 			}
1405 			ctr = anb->anb_max_index + 1;
1406 			anb->anb_index--;
1407 			anb->anb_index &= anb->anb_max_index;
1408 
1409 			while (ctr) {
1410 				smb_audit_record_node_t	*anr;
1411 
1412 				anr = anb->anb_records + anb->anb_index;
1413 
1414 				if (anr->anr_depth) {
1415 					char c[MDB_SYM_NAMLEN];
1416 					GElf_Sym sym;
1417 					int i;
1418 
1419 					mdb_printf("\nRefCnt: %u\t",
1420 					    anr->anr_refcnt);
1421 
1422 					for (i = 0;
1423 					    i < anr->anr_depth;
1424 					    i++) {
1425 						if (mdb_lookup_by_addr(
1426 						    anr->anr_stack[i],
1427 						    MDB_SYM_FUZZY,
1428 						    c, sizeof (c),
1429 						    &sym) == -1) {
1430 							continue;
1431 						}
1432 						mdb_printf("%s+0x%1x",
1433 						    c,
1434 						    anr->anr_stack[i] -
1435 						    (uintptr_t)sym.st_value);
1436 						++i;
1437 						break;
1438 					}
1439 
1440 					while (i < anr->anr_depth) {
1441 						if (mdb_lookup_by_addr(
1442 						    anr->anr_stack[i],
1443 						    MDB_SYM_FUZZY,
1444 						    c, sizeof (c),
1445 						    &sym) == -1) {
1446 							++i;
1447 							continue;
1448 						}
1449 						mdb_printf("\n\t\t%s+0x%1x",
1450 						    c,
1451 						    anr->anr_stack[i] -
1452 						    (uintptr_t)sym.st_value);
1453 						++i;
1454 					}
1455 					mdb_printf("\n");
1456 				}
1457 				anb->anb_index--;
1458 				anb->anb_index &= anb->anb_max_index;
1459 				ctr--;
1460 			}
1461 		}
1462 	} else {
1463 		mdb_warn("failed to read struct smb_node at %p", addr);
1464 		return (DCMD_ERR);
1465 	}
1466 
1467 	return (DCMD_OK);
1468 }
1469 
1470 /*
1471  * Initialize the smb_node_t walker by reading the value of smb_node_hash_table
1472  * in the kernel's symbol table. Only global walk supported.
1473  */
1474 static int
1475 smb_node_walk_init(mdb_walk_state_t *wsp)
1476 {
1477 	GElf_Sym	sym;
1478 	int		i;
1479 	uintptr_t	node_hash_table_addr;
1480 
1481 	if (wsp->walk_addr == NULL) {
1482 		if (mdb_lookup_by_name("smb_node_hash_table", &sym) == -1) {
1483 			mdb_warn("failed to find 'smb_node_hash_table'");
1484 			return (WALK_ERR);
1485 		}
1486 		node_hash_table_addr = (uintptr_t)sym.st_value;
1487 	} else {
1488 		mdb_printf("smb_node walk only supports global walks\n");
1489 		return (WALK_ERR);
1490 	}
1491 
1492 	for (i = 0; i < SMBND_HASH_MASK + 1; i++) {
1493 		wsp->walk_addr = node_hash_table_addr +
1494 		    (i * sizeof (smb_llist_t)) + offsetof(smb_llist_t, ll_list);
1495 		if (mdb_layered_walk("list", wsp) == -1) {
1496 			mdb_warn("failed to walk 'list'");
1497 			return (WALK_ERR);
1498 		}
1499 	}
1500 
1501 	return (WALK_NEXT);
1502 }
1503 
1504 static int
1505 smb_node_walk_step(mdb_walk_state_t *wsp)
1506 {
1507 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1508 	    wsp->walk_cbdata));
1509 }
1510 
1511 /*
1512  * *****************************************************************************
1513  * ****************************** smb_lock_t ***********************************
1514  * *****************************************************************************
1515  */
1516 
1517 static int
1518 smb_lock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1519 {
1520 	smb_lock_t	lock;
1521 	int		verbose = FALSE;
1522 	uintptr_t	list_addr;
1523 	char		*lock_type;
1524 
1525 	if (mdb_getopts(argc, argv,
1526 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1527 	    NULL) != argc)
1528 		return (DCMD_USAGE);
1529 
1530 	/*
1531 	 * An smb_lock_t address must be specified.
1532 	 */
1533 	if (!(flags & DCMD_ADDRSPEC))
1534 		return (DCMD_USAGE);
1535 
1536 	/*
1537 	 * If this is the first invocation of the command, print a nice
1538 	 * header line for the output that will follow.
1539 	 */
1540 	if (DCMD_HDRSPEC(flags)) {
1541 		if (verbose)
1542 			mdb_printf("SMB lock information:\n\n");
1543 		else
1544 			mdb_printf("%<u>%-?s %4s %16s %8s %9s%</u>\n",
1545 			    "Locks: ", "TYPE", "START", "LENGTH",
1546 			    "CONFLICTS");
1547 	}
1548 
1549 	if (mdb_vread(&lock, sizeof (lock), addr) == sizeof (lock)) {
1550 		switch (lock.l_type) {
1551 		case SMB_LOCK_TYPE_READWRITE:
1552 			lock_type = "RW";
1553 			break;
1554 		case SMB_LOCK_TYPE_READONLY:
1555 			lock_type = "RO";
1556 			break;
1557 		default:
1558 			lock_type = "N/A";
1559 			break;
1560 		}
1561 		if (verbose) {
1562 			mdb_printf("Type             :\t%s (%u)\n",
1563 			    lock_type, lock.l_type);
1564 			mdb_printf("Start            :\t%llx\n",
1565 			    lock.l_start);
1566 			mdb_printf("Length           :\t%lx\n",
1567 			    lock.l_length);
1568 			mdb_printf("Session          :\t%p\n",
1569 			    lock.l_session);
1570 			mdb_printf("File             :\t%p\n",
1571 			    lock.l_file);
1572 			mdb_printf("User ID          :\t%u\n",
1573 			    lock.l_uid);
1574 			mdb_printf("Process ID       :\t%u\n",
1575 			    lock.l_pid);
1576 			mdb_printf("Conflicts        :\t%u\n",
1577 			    lock.l_conflict_list.sl_count);
1578 			if (lock.l_conflict_list.sl_count != 0) {
1579 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1580 				list_addr = addr +
1581 				    offsetof(smb_lock_t, l_conflict_list) +
1582 				    offsetof(smb_slist_t, sl_list);
1583 				if (mdb_pwalk_dcmd("list", "smb_lock",
1584 				    0, NULL, list_addr)) {
1585 					mdb_warn("failed to walk conflict "
1586 					    "locks ");
1587 				}
1588 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1589 			}
1590 			mdb_printf("Blocked by       :\t%p\n",
1591 			    lock.l_blocked_by);
1592 			mdb_printf("Flags            :\t0x%x\n",
1593 			    lock.l_flags);
1594 			mdb_printf("\n");
1595 		} else {
1596 			mdb_printf("%?p %4s %16llx %08lx %9x", addr,
1597 			    lock_type, lock.l_start, lock.l_length,
1598 			    lock.l_conflict_list.sl_count);
1599 		}
1600 	} else {
1601 		mdb_warn("failed to read struct smb_request at %p", addr);
1602 		return (DCMD_ERR);
1603 	}
1604 
1605 	return (DCMD_OK);
1606 }
1607 
1608 /*
1609  * ::smb_dispatch_stats
1610  *
1611  * smb_dispatch_stats dcmd - Prints all dispatched SMB requests statistics.
1612  */
1613 /*ARGSUSED*/
1614 static int
1615 smb_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1616 {
1617 	smb_disp_entry_t	*disp;
1618 	GElf_Sym		sym;
1619 	int			nstats = 0, i;
1620 
1621 	if ((flags & DCMD_ADDRSPEC) || argc != 0)
1622 		return (DCMD_USAGE);
1623 
1624 	if (mdb_lookup_by_obj(MDB_OBJ_EVERY, "dispatch", &sym)) {
1625 		mdb_warn("failed to find dispatch object");
1626 		return (DCMD_ERR);
1627 	}
1628 
1629 	disp = mdb_alloc(sym.st_size, UM_SLEEP | UM_GC);
1630 	if (mdb_vread(disp, sym.st_size, sym.st_value) == -1) {
1631 		mdb_warn("failed to read from dispatch object");
1632 		return (DCMD_ERR);
1633 	}
1634 
1635 	nstats = sym.st_size / sizeof (smb_disp_entry_t);
1636 
1637 	mdb_printf("All dispatched SMB requests statistics:\n\n");
1638 	for (i = 0; i < nstats; i++) {
1639 		if (disp[i].sdt_function)
1640 			mdb_printf("    %40s\t: %lld\n",
1641 			    disp[i].sdt_dispatch_stats.name,
1642 			    disp[i].sdt_dispatch_stats.value.ui64);
1643 	}
1644 	return (DCMD_OK);
1645 }
1646 
1647 /*
1648  * *****************************************************************************
1649  * ******************************** smb_ace_t **********************************
1650  * *****************************************************************************
1651  */
1652 static const ace_type_entry_t	ace_types[ACE_TYPE_TABLEN] =
1653 {
1654 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_ACE_TYPE),
1655 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_ACE_TYPE),
1656 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_ACE_TYPE),
1657 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_ACE_TYPE),
1658 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE),
1659 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE),
1660 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_OBJECT_ACE_TYPE),
1661 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE),
1662 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE),
1663 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE),
1664 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE),
1665 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE),
1666 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE),
1667 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE),
1668 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE),
1669 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE),
1670 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE),
1671 	ACE_TYPE_ENTRY(0x11),
1672 	ACE_TYPE_ENTRY(0x12),
1673 	ACE_TYPE_ENTRY(0x13),
1674 	ACE_TYPE_ENTRY(0x14),
1675 	ACE_TYPE_ENTRY(0x15),
1676 	ACE_TYPE_ENTRY(0x16),
1677 	ACE_TYPE_ENTRY(0x17),
1678 	ACE_TYPE_ENTRY(0x18),
1679 	ACE_TYPE_ENTRY(0x19),
1680 	ACE_TYPE_ENTRY(0x1A),
1681 	ACE_TYPE_ENTRY(0x1B),
1682 	ACE_TYPE_ENTRY(0x1C),
1683 	ACE_TYPE_ENTRY(0x1D),
1684 	ACE_TYPE_ENTRY(0x1E),
1685 	ACE_TYPE_ENTRY(0x1F)
1686 };
1687 
1688 static const mdb_bitmask_t ace_flag_bits[] = {
1689 	{ "OBJECT_INHERIT_ACE", OBJECT_INHERIT_ACE, OBJECT_INHERIT_ACE },
1690 	{ "CONTAINER_INHERIT_ACE", CONTAINER_INHERIT_ACE,
1691 	    CONTAINER_INHERIT_ACE },
1692 	{ "NO_PROPOGATE_INHERIT_ACE", NO_PROPOGATE_INHERIT_ACE,
1693 	    NO_PROPOGATE_INHERIT_ACE },
1694 	{ "INHERIT_ONLY_ACE", INHERIT_ONLY_ACE, INHERIT_ONLY_ACE },
1695 	{ "INHERITED_ACE", INHERITED_ACE, INHERITED_ACE },
1696 	{ "SUCCESSFUL_ACCESS_ACE_FLAG", SUCCESSFUL_ACCESS_ACE_FLAG,
1697 	    SUCCESSFUL_ACCESS_ACE_FLAG },
1698 	{ "FAILED_ACCESS_ACE_FLAG", FAILED_ACCESS_ACE_FLAG,
1699 	    FAILED_ACCESS_ACE_FLAG },
1700 	{ NULL, 0, 0 }
1701 };
1702 
1703 /*
1704  * ::smbace
1705  */
1706 static int
1707 smb_ace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1708 {
1709 	smb_ace_t	ace;
1710 	int		verbose = FALSE;
1711 	const char	*ptr;
1712 	int		rc;
1713 
1714 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose,
1715 	    NULL) != argc)
1716 		return (DCMD_USAGE);
1717 
1718 	/*
1719 	 * An smb_ace address is required.
1720 	 */
1721 	if (!(flags & DCMD_ADDRSPEC))
1722 		return (DCMD_USAGE);
1723 
1724 	if (mdb_vread(&ace, sizeof (ace), addr) != sizeof (ace)) {
1725 		mdb_warn("failed to read struct smb_ace at %p", addr);
1726 		return (DCMD_ERR);
1727 	}
1728 
1729 	if (verbose) {
1730 		if (ace.se_hdr.se_type < ACE_TYPE_TABLEN)
1731 			ptr = ace_types[ace.se_hdr.se_type].ace_type_sting;
1732 		else
1733 			ptr = "Unknown";
1734 
1735 		mdb_printf("ACE Type: 0x%02x (%s)\n", ace.se_hdr.se_type, ptr);
1736 		mdb_printf("ACE Flags: %b\n", (int)ace.se_hdr.se_flags,
1737 		    ace_flag_bits);
1738 		mdb_printf("ACE Wire Size: 0x%04x\n", ace.se_hdr.se_bsize);
1739 		mdb_printf("ACE Mask: 0x%08x\n", ace.se_mask);
1740 		mdb_printf("ACE SID: ");
1741 	} else {
1742 		if (DCMD_HDRSPEC(flags))
1743 			mdb_printf(
1744 			    "%<b>%<u>%?-s %-4s %-4s %-8s %s%</u>%</b>\n",
1745 			    "ACE", "TYPE", "FLAGS", "MASK", "SID");
1746 		mdb_printf("%?p 0x%02x 0x%02x 0x%08x ", addr,
1747 		    ace.se_hdr.se_type, ace.se_hdr.se_flags, ace.se_mask);
1748 	}
1749 	rc = smb_sid_print((uintptr_t)ace.se_sid);
1750 	mdb_printf("\n");
1751 	return (rc);
1752 }
1753 
1754 static int
1755 smb_ace_walk_init(mdb_walk_state_t *wsp)
1756 {
1757 	if (wsp->walk_addr == 0) {
1758 		mdb_printf("smb_ace walk only supports local walks\n");
1759 		return (WALK_ERR);
1760 	}
1761 
1762 	wsp->walk_addr += offsetof(smb_acl_t, sl_sorted);
1763 
1764 	if (mdb_layered_walk("list", wsp) == -1) {
1765 		mdb_warn("failed to walk list of ACEs");
1766 		return (WALK_ERR);
1767 	}
1768 
1769 	return (WALK_NEXT);
1770 }
1771 
1772 static int
1773 smb_ace_walk_step(mdb_walk_state_t *wsp)
1774 {
1775 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1776 	    wsp->walk_cbdata));
1777 }
1778 
1779 /*
1780  * *****************************************************************************
1781  * ******************************** smb_acl_t **********************************
1782  * *****************************************************************************
1783  */
1784 
1785 /*
1786  * ::smbacl
1787  */
1788 static int
1789 smb_acl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1790 {
1791 	smb_acl_t	acl;
1792 
1793 	/* An smb_acl address is required. */
1794 	if (!(flags & DCMD_ADDRSPEC))
1795 		return (DCMD_USAGE);
1796 
1797 	if (mdb_vread(&acl, sizeof (acl), addr) != sizeof (acl)) {
1798 		mdb_warn("failed to read struct smb_acl at %p", addr);
1799 		return (DCMD_ERR);
1800 	}
1801 
1802 	mdb_printf("ACL Revision: %d\n", acl.sl_revision);
1803 	mdb_printf("ACL Size on Wire: %d\n", acl.sl_bsize);
1804 	mdb_printf("ACL Number of ACEs: %d\n", acl.sl_acecnt);
1805 
1806 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
1807 	if (mdb_pwalk_dcmd("smbace_walker", "smbace", argc, argv, addr)) {
1808 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
1809 		mdb_warn("failed to walk list of ACEs for ACL %p", addr);
1810 		return (DCMD_ERR);
1811 	}
1812 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
1813 	return (DCMD_OK);
1814 }
1815 
1816 /*
1817  * *****************************************************************************
1818  * ********************************* smb_sd_t **********************************
1819  * *****************************************************************************
1820  */
1821 
1822 /*
1823  * ::smbsd
1824  */
1825 static int
1826 smb_sd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1827 {
1828 	smb_sd_t	sd;
1829 	int		rc;
1830 
1831 	/*
1832 	 * An smb_sid address is required.
1833 	 */
1834 	if (!(flags & DCMD_ADDRSPEC))
1835 		return (DCMD_USAGE);
1836 
1837 	if (mdb_vread(&sd, sizeof (sd), addr) != sizeof (sd)) {
1838 		mdb_warn("failed to read struct smb_sd at %p", addr);
1839 		return (DCMD_ERR);
1840 	}
1841 
1842 	mdb_printf("SD Revision: %d\n", sd.sd_revision);
1843 	mdb_printf("SD Control: %04x\n", sd.sd_control);
1844 	if (sd.sd_control & SE_OWNER_DEFAULTED)
1845 		mdb_printf("\t    SE_OWNER_DEFAULTED\n");
1846 	if (sd.sd_control & SE_GROUP_DEFAULTED)
1847 		mdb_printf("\t    SE_GROUP_DEFAULTED\n");
1848 	if (sd.sd_control & SE_DACL_PRESENT)
1849 		mdb_printf("\t    SE_DACL_PRESENT\n");
1850 	if (sd.sd_control & SE_DACL_DEFAULTED)
1851 		mdb_printf("\t    SE_DACL_DEFAULTED\n");
1852 	if (sd.sd_control & SE_SACL_PRESENT)
1853 		mdb_printf("\t    SE_SACL_PRESENT\n");
1854 	if (sd.sd_control & SE_SACL_DEFAULTED)
1855 		mdb_printf("\t    SE_SACL_DEFAULTED\n");
1856 	if (sd.sd_control & SE_DACL_AUTO_INHERIT_REQ)
1857 		mdb_printf("\t    SE_DACL_AUTO_INHERIT_REQ\n");
1858 	if (sd.sd_control & SE_SACL_AUTO_INHERIT_REQ)
1859 		mdb_printf("\t    SE_SACL_AUTO_INHERIT_REQ\n");
1860 	if (sd.sd_control & SE_DACL_AUTO_INHERITED)
1861 		mdb_printf("\t    SE_DACL_AUTO_INHERITED\n");
1862 	if (sd.sd_control & SE_SACL_AUTO_INHERITED)
1863 		mdb_printf("\t    SE_SACL_AUTO_INHERITED\n");
1864 	if (sd.sd_control & SE_DACL_PROTECTED)
1865 		mdb_printf("\t    SE_DACL_PROTECTED\n");
1866 	if (sd.sd_control & SE_SACL_PROTECTED)
1867 		mdb_printf("\t    SE_SACL_PROTECTED\n");
1868 	if (sd.sd_control & SE_SELF_RELATIVE)
1869 		mdb_printf("\t    SE_SELF_RELATIVE\n");
1870 
1871 	mdb_printf("SID of Owner: ");
1872 	rc = smb_sid_print((uintptr_t)sd.sd_owner);
1873 	if (rc != DCMD_OK)
1874 		return (rc);
1875 	mdb_printf("\nSID of Group: ");
1876 	rc = smb_sid_print((uintptr_t)sd.sd_group);
1877 	if (rc != DCMD_OK)
1878 		return (rc);
1879 	mdb_printf("\n");
1880 
1881 	if (sd.sd_control & SE_SACL_PRESENT && sd.sd_sacl) {
1882 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
1883 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
1884 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_sacl, flags,
1885 		    argc, argv);
1886 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
1887 		if (rc != DCMD_OK)
1888 			return (rc);
1889 	}
1890 	if (sd.sd_control & SE_DACL_PRESENT && sd.sd_dacl) {
1891 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
1892 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
1893 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_dacl, flags,
1894 		    argc, argv);
1895 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
1896 		if (rc != DCMD_OK)
1897 			return (rc);
1898 	}
1899 
1900 	return (DCMD_OK);
1901 }
1902 
1903 /*
1904  * *****************************************************************************
1905  * ********************************* smb_sid_t *********************************
1906  * *****************************************************************************
1907  */
1908 
1909 /*
1910  * ::smbsid
1911  */
1912 /*ARGSUSED*/
1913 static int
1914 smb_sid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1915 {
1916 	/*
1917 	 * An smb_sid address is required.
1918 	 */
1919 	if (!(flags & DCMD_ADDRSPEC))
1920 		return (DCMD_USAGE);
1921 
1922 	return (smb_sid_print(addr));
1923 }
1924 
1925 /*
1926  * smb_sid_print
1927  */
1928 static int
1929 smb_sid_print(uintptr_t addr)
1930 {
1931 	smb_sid_t	sid;
1932 	smb_sid_t	*psid;
1933 	size_t		sid_size;
1934 	int		i;
1935 	uint64_t	authority;
1936 
1937 	sid_size = offsetof(smb_sid_t, sid_subauth);
1938 
1939 	if (mdb_vread(&sid, sid_size, addr) != sid_size) {
1940 		mdb_warn("failed to read struct smb_sid at %p", addr);
1941 		return (DCMD_ERR);
1942 	}
1943 
1944 	sid_size += sid.sid_subauthcnt * sizeof (sid.sid_subauth[0]);
1945 
1946 	psid = mdb_zalloc(sid_size, UM_SLEEP | UM_GC);
1947 	if (mdb_vread(psid, sid_size, addr) != sid_size) {
1948 		mdb_warn("failed to read struct smb_sid at %p", addr);
1949 		return (DCMD_ERR);
1950 	}
1951 
1952 	mdb_printf("S-%d", psid->sid_revision);
1953 	authority = 0;
1954 	for (i = 0; i < NT_SID_AUTH_MAX; i++) {
1955 		authority += ((uint64_t)psid->sid_authority[i]) <<
1956 		    (8 * (NT_SID_AUTH_MAX - 1) - i);
1957 	}
1958 	mdb_printf("-%ll", authority);
1959 
1960 	for (i = 0; i < psid->sid_subauthcnt; i++)
1961 		mdb_printf("-%d", psid->sid_subauth[i]);
1962 
1963 	return (DCMD_OK);
1964 }
1965 
1966 /*
1967  * *****************************************************************************
1968  * ********************************* smb_fssd_t ********************************
1969  * *****************************************************************************
1970  */
1971 
1972 /*
1973  * ::smbfssd
1974  */
1975 static int
1976 smb_fssd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1977 {
1978 	smb_fssd_t	fssd;
1979 	int		rc;
1980 
1981 	/*
1982 	 * An smb_fssd address is required.
1983 	 */
1984 	if (!(flags & DCMD_ADDRSPEC))
1985 		return (DCMD_USAGE);
1986 
1987 	if (mdb_vread(&fssd, sizeof (fssd), addr) != sizeof (fssd)) {
1988 		mdb_warn("failed to read struct smb_fssd at %p", addr);
1989 		return (DCMD_ERR);
1990 	}
1991 
1992 	mdb_printf("FSSD secinfo: 0x%x\n", fssd.sd_secinfo);
1993 	if (fssd.sd_secinfo & SMB_OWNER_SECINFO)
1994 		mdb_printf("FSSD uid: %d\n", fssd.sd_uid);
1995 	if (fssd.sd_secinfo & SMB_GROUP_SECINFO)
1996 		mdb_printf("FSSD gid: %d\n", fssd.sd_gid);
1997 	if (fssd.sd_secinfo & SMB_SACL_SECINFO && fssd.sd_zsacl) {
1998 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
1999 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
2000 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zsacl, flags,
2001 		    argc, argv);
2002 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2003 		if (rc != DCMD_OK)
2004 			return (rc);
2005 	}
2006 	if (fssd.sd_secinfo & SMB_DACL_SECINFO && fssd.sd_zdacl) {
2007 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
2008 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
2009 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zdacl, flags,
2010 		    argc, argv);
2011 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2012 		if (rc != DCMD_OK)
2013 			return (rc);
2014 	}
2015 
2016 	return (DCMD_OK);
2017 }
2018 
2019 /*
2020  * *****************************************************************************
2021  * **************************** Utility Funcions *******************************
2022  * *****************************************************************************
2023  */
2024 
2025 /*
2026  * smb_dcmd_getopt
2027  *
2028  * This function analyzes the arguments passed in and sets the bit corresponding
2029  * to the options found in the opts variable.
2030  *
2031  * Return Value
2032  *
2033  *	-1	An error occured during the decoding
2034  *	0	The decoding was successful
2035  */
2036 static int
2037 smb_dcmd_getopt(uint_t *opts, int argc, const mdb_arg_t *argv)
2038 {
2039 	*opts = 0;
2040 
2041 	if (mdb_getopts(argc, argv,
2042 	    's', MDB_OPT_SETBITS, SMB_OPT_SERVER, opts,
2043 	    'm', MDB_OPT_SETBITS, SMB_OPT_VFS, opts,
2044 	    'e', MDB_OPT_SETBITS, SMB_OPT_SESSION, opts,
2045 	    'r', MDB_OPT_SETBITS, SMB_OPT_REQUEST, opts,
2046 	    'u', MDB_OPT_SETBITS, SMB_OPT_USER, opts,
2047 	    't', MDB_OPT_SETBITS, SMB_OPT_TREE, opts,
2048 	    'f', MDB_OPT_SETBITS, SMB_OPT_OFILE, opts,
2049 	    'd', MDB_OPT_SETBITS, SMB_OPT_ODIR, opts,
2050 	    'w', MDB_OPT_SETBITS, SMB_OPT_WALK, opts,
2051 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, opts,
2052 	    NULL) != argc)
2053 		return (-1);
2054 
2055 	return (0);
2056 }
2057 
2058 /*
2059  * smb_dcmd_setopt
2060  *
2061  * This function set the arguments corresponding to the bits set in opts.
2062  *
2063  * Return Value
2064  *
2065  *	Number of arguments set.
2066  */
2067 static int
2068 smb_dcmd_setopt(uint_t opts, int max_argc, mdb_arg_t *argv)
2069 {
2070 	int	i;
2071 	uint_t	mask = 0x00000001;
2072 	int	argc = 0;
2073 
2074 	for (i = 0; i < SMB_MDB_MAX_OPTS; i++) {
2075 		if ((opts & mask) && (argc < max_argc)) {
2076 			argv->a_type = MDB_TYPE_STRING;
2077 			argv->a_un.a_str = smb_opts[i];
2078 			argc++;
2079 			argv++;
2080 		}
2081 		mask = mask << 1;
2082 	}
2083 	return (argc);
2084 }
2085 
2086 /*
2087  * smb_obj_expand
2088  */
2089 static int
2090 smb_obj_expand(uintptr_t addr, uint_t opts, const smb_exp_t *x, ulong_t indent)
2091 {
2092 	int		rc = 0;
2093 	int		argc;
2094 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
2095 
2096 	argc = smb_dcmd_setopt(opts | SMB_OPT_WALK, SMB_MDB_MAX_OPTS, argv);
2097 
2098 	(void) mdb_inc_indent(indent);
2099 	while (x->ex_dcmd) {
2100 		if (x->ex_mask & opts) {
2101 			rc = mdb_pwalk_dcmd("list", x->ex_dcmd, argc, argv,
2102 			    addr + x->ex_offset);
2103 
2104 			if (rc) {
2105 				mdb_warn("failed to walk the list of %s in %p",
2106 				    x->ex_name, addr + x->ex_offset);
2107 				break;
2108 			}
2109 		}
2110 		x++;
2111 	}
2112 	(void) mdb_dec_indent(indent);
2113 	return (rc);
2114 }
2115 
2116 /*
2117  * smb_obj_list
2118  *
2119  * Function called by the DCMDs when no address is provided. It expands the
2120  * tree under the object type associated with the calling DCMD (based on the
2121  * flags passed in).
2122  *
2123  * Return Value
2124  *
2125  *	DCMD_OK
2126  *	DCMD_ERR
2127  */
2128 static int
2129 smb_obj_list(const char *name, uint_t opts, uint_t flags)
2130 {
2131 	int		argc;
2132 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
2133 
2134 	argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, argv);
2135 
2136 	if (mdb_call_dcmd("smblist", 0, flags, argc, argv)) {
2137 		mdb_warn("failed to list %s", name);
2138 		return (DCMD_ERR);
2139 	}
2140 	return (DCMD_OK);
2141 }
2142 
2143 static int
2144 smb_worker_findstack(uintptr_t addr)
2145 {
2146 	kthread_t	t;
2147 	taskq_t		tq;
2148 	char		cmd[80];
2149 	mdb_arg_t	cmdarg;
2150 
2151 	if (mdb_vread(&t, sizeof (kthread_t), addr) == -1) {
2152 		mdb_warn("failed to read kthread_t at %p", addr);
2153 		return (DCMD_ERR);
2154 	}
2155 
2156 	if (mdb_vread(&tq, sizeof (taskq_t), (uintptr_t)t.t_taskq) == -1)
2157 		tq.tq_name[0] = '\0';
2158 
2159 	mdb_inc_indent(2);
2160 
2161 	mdb_printf("PC: %a", t.t_pc);
2162 	if (t.t_tid == 0) {
2163 		if (tq.tq_name[0] != '\0')
2164 			mdb_printf("    TASKQ: %s\n", tq.tq_name);
2165 		else
2166 			mdb_printf("    THREAD: %a()\n", t.t_startpc);
2167 	}
2168 
2169 	mdb_snprintf(cmd, sizeof (cmd), "<.$c%d", 16);
2170 	cmdarg.a_type = MDB_TYPE_STRING;
2171 	cmdarg.a_un.a_str = cmd;
2172 	(void) mdb_call_dcmd("findstack", addr, DCMD_ADDRSPEC, 1, &cmdarg);
2173 	mdb_dec_indent(2);
2174 	mdb_printf("\n");
2175 	return (DCMD_OK);
2176 }
2177