dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / smbsrv / smbsrv.c
blob0f08b86bf4e21c5ab1533bc2210f55d3071f0959
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
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 #include <mdb/mdb_modapi.h>
28 #include <mdb/mdb_ks.h>
29 #include <sys/thread.h>
30 #include <sys/taskq.h>
31 #include <smbsrv/smb_vops.h>
32 #include <smbsrv/smb.h>
33 #include <smbsrv/smb_ktypes.h>
35 #define SMBSRV_OBJNAME "smbsrv"
37 #define SMB_DCMD_INDENT 2
38 #define ACE_TYPE_TABLEN (ACE_ALL_TYPES + 1)
39 #define ACE_TYPE_ENTRY(_v_) {_v_, #_v_}
40 #define SMB_COM_ENTRY(_v_, _x_) {#_v_, _x_}
42 #define SMB_MDB_MAX_OPTS 9
44 #define SMB_OPT_SERVER 0x00000001
45 #define SMB_OPT_SESSION 0x00000002
46 #define SMB_OPT_REQUEST 0x00000004
47 #define SMB_OPT_USER 0x00000008
48 #define SMB_OPT_TREE 0x00000010
49 #define SMB_OPT_OFILE 0x00000020
50 #define SMB_OPT_ODIR 0x00000040
51 #define SMB_OPT_WALK 0x00000100
52 #define SMB_OPT_VERBOSE 0x00000200
53 #define SMB_OPT_ALL_OBJ 0x000000FF
56 * Structure associating an ACE type to a string.
58 typedef struct {
59 uint8_t ace_type_value;
60 const char *ace_type_sting;
61 } ace_type_entry_t;
64 * Structure containing strings describing an SMB command.
66 typedef struct {
67 const char *smb_com;
68 const char *smb_andx;
69 } smb_com_entry_t;
72 * Structure describing an object to be expanded (displayed).
74 typedef struct {
75 uint_t ex_mask;
76 size_t ex_offset;
77 const char *ex_dcmd;
78 const char *ex_name;
79 } smb_exp_t;
82 * List of supported options. Ther order has the match the bits SMB_OPT_xxx.
84 typedef struct smb_mdb_opts {
85 char *o_name;
86 uint32_t o_value;
87 } smb_mdb_opts_t;
89 static smb_mdb_opts_t smb_opts[SMB_MDB_MAX_OPTS] =
91 { "-s", SMB_OPT_SERVER },
92 { "-e", SMB_OPT_SESSION },
93 { "-r", SMB_OPT_REQUEST },
94 { "-u", SMB_OPT_USER },
95 { "-t", SMB_OPT_TREE },
96 { "-f", SMB_OPT_OFILE },
97 { "-d", SMB_OPT_ODIR },
98 { "-w", SMB_OPT_WALK },
99 { "-v", SMB_OPT_VERBOSE }
102 static smb_com_entry_t smb_com[256] =
104 SMB_COM_ENTRY(SMB_COM_CREATE_DIRECTORY, "No"),
105 SMB_COM_ENTRY(SMB_COM_DELETE_DIRECTORY, "No"),
106 SMB_COM_ENTRY(SMB_COM_OPEN, "No"),
107 SMB_COM_ENTRY(SMB_COM_CREATE, "No"),
108 SMB_COM_ENTRY(SMB_COM_CLOSE, "No"),
109 SMB_COM_ENTRY(SMB_COM_FLUSH, "No"),
110 SMB_COM_ENTRY(SMB_COM_DELETE, "No"),
111 SMB_COM_ENTRY(SMB_COM_RENAME, "No"),
112 SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION, "No"),
113 SMB_COM_ENTRY(SMB_COM_SET_INFORMATION, "No"),
114 SMB_COM_ENTRY(SMB_COM_READ, "No"),
115 SMB_COM_ENTRY(SMB_COM_WRITE, "No"),
116 SMB_COM_ENTRY(SMB_COM_LOCK_BYTE_RANGE, "No"),
117 SMB_COM_ENTRY(SMB_COM_UNLOCK_BYTE_RANGE, "No"),
118 SMB_COM_ENTRY(SMB_COM_CREATE_TEMPORARY, "No"),
119 SMB_COM_ENTRY(SMB_COM_CREATE_NEW, "No"),
120 SMB_COM_ENTRY(SMB_COM_CHECK_DIRECTORY, "No"),
121 SMB_COM_ENTRY(SMB_COM_PROCESS_EXIT, "No"),
122 SMB_COM_ENTRY(SMB_COM_SEEK, "No"),
123 SMB_COM_ENTRY(SMB_COM_LOCK_AND_READ, "No"),
124 SMB_COM_ENTRY(SMB_COM_WRITE_AND_UNLOCK, "No"),
125 SMB_COM_ENTRY(0x15, "?"),
126 SMB_COM_ENTRY(0x16, "?"),
127 SMB_COM_ENTRY(0x17, "?"),
128 SMB_COM_ENTRY(0x18, "?"),
129 SMB_COM_ENTRY(0x19, "?"),
130 SMB_COM_ENTRY(SMB_COM_READ_RAW, "No"),
131 SMB_COM_ENTRY(SMB_COM_READ_MPX, "No"),
132 SMB_COM_ENTRY(SMB_COM_READ_MPX_SECONDARY, "No"),
133 SMB_COM_ENTRY(SMB_COM_WRITE_RAW, "No"),
134 SMB_COM_ENTRY(SMB_COM_WRITE_MPX, "No"),
135 SMB_COM_ENTRY(SMB_COM_WRITE_MPX_SECONDARY, "No"),
136 SMB_COM_ENTRY(SMB_COM_WRITE_COMPLETE, "No"),
137 SMB_COM_ENTRY(SMB_COM_QUERY_SERVER, "No"),
138 SMB_COM_ENTRY(SMB_COM_SET_INFORMATION2, "No"),
139 SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION2, "No"),
140 SMB_COM_ENTRY(SMB_COM_LOCKING_ANDX, "No"),
141 SMB_COM_ENTRY(SMB_COM_TRANSACTION, "No"),
142 SMB_COM_ENTRY(SMB_COM_TRANSACTION_SECONDARY, "No"),
143 SMB_COM_ENTRY(SMB_COM_IOCTL, "No"),
144 SMB_COM_ENTRY(SMB_COM_IOCTL_SECONDARY, "No"),
145 SMB_COM_ENTRY(SMB_COM_COPY, "No"),
146 SMB_COM_ENTRY(SMB_COM_MOVE, "No"),
147 SMB_COM_ENTRY(SMB_COM_ECHO, "No"),
148 SMB_COM_ENTRY(SMB_COM_WRITE_AND_CLOSE, "No"),
149 SMB_COM_ENTRY(SMB_COM_OPEN_ANDX, "No"),
150 SMB_COM_ENTRY(SMB_COM_READ_ANDX, "No"),
151 SMB_COM_ENTRY(SMB_COM_WRITE_ANDX, "No"),
152 SMB_COM_ENTRY(SMB_COM_NEW_FILE_SIZE, "No"),
153 SMB_COM_ENTRY(SMB_COM_CLOSE_AND_TREE_DISC, "No"),
154 SMB_COM_ENTRY(SMB_COM_TRANSACTION2, "No"),
155 SMB_COM_ENTRY(SMB_COM_TRANSACTION2_SECONDARY, "No"),
156 SMB_COM_ENTRY(SMB_COM_FIND_CLOSE2, "No"),
157 SMB_COM_ENTRY(SMB_COM_FIND_NOTIFY_CLOSE, "No"),
158 SMB_COM_ENTRY(0x36, "?"),
159 SMB_COM_ENTRY(0x37, "?"),
160 SMB_COM_ENTRY(0x38, "?"),
161 SMB_COM_ENTRY(0x39, "?"),
162 SMB_COM_ENTRY(0x3A, "?"),
163 SMB_COM_ENTRY(0x3B, "?"),
164 SMB_COM_ENTRY(0x3C, "?"),
165 SMB_COM_ENTRY(0x3D, "?"),
166 SMB_COM_ENTRY(0x3E, "?"),
167 SMB_COM_ENTRY(0x3F, "?"),
168 SMB_COM_ENTRY(0x40, "?"),
169 SMB_COM_ENTRY(0x41, "?"),
170 SMB_COM_ENTRY(0x42, "?"),
171 SMB_COM_ENTRY(0x43, "?"),
172 SMB_COM_ENTRY(0x44, "?"),
173 SMB_COM_ENTRY(0x45, "?"),
174 SMB_COM_ENTRY(0x46, "?"),
175 SMB_COM_ENTRY(0x47, "?"),
176 SMB_COM_ENTRY(0x48, "?"),
177 SMB_COM_ENTRY(0x49, "?"),
178 SMB_COM_ENTRY(0x4A, "?"),
179 SMB_COM_ENTRY(0x4B, "?"),
180 SMB_COM_ENTRY(0x4C, "?"),
181 SMB_COM_ENTRY(0x4D, "?"),
182 SMB_COM_ENTRY(0x4E, "?"),
183 SMB_COM_ENTRY(0x4F, "?"),
184 SMB_COM_ENTRY(0x50, "?"),
185 SMB_COM_ENTRY(0x51, "?"),
186 SMB_COM_ENTRY(0x52, "?"),
187 SMB_COM_ENTRY(0x53, "?"),
188 SMB_COM_ENTRY(0x54, "?"),
189 SMB_COM_ENTRY(0x55, "?"),
190 SMB_COM_ENTRY(0x56, "?"),
191 SMB_COM_ENTRY(0x57, "?"),
192 SMB_COM_ENTRY(0x58, "?"),
193 SMB_COM_ENTRY(0x59, "?"),
194 SMB_COM_ENTRY(0x5A, "?"),
195 SMB_COM_ENTRY(0x5B, "?"),
196 SMB_COM_ENTRY(0x5C, "?"),
197 SMB_COM_ENTRY(0x5D, "?"),
198 SMB_COM_ENTRY(0x5E, "?"),
199 SMB_COM_ENTRY(0x5F, "?"),
200 SMB_COM_ENTRY(0x60, "?"),
201 SMB_COM_ENTRY(0x61, "?"),
202 SMB_COM_ENTRY(0x62, "?"),
203 SMB_COM_ENTRY(0x63, "?"),
204 SMB_COM_ENTRY(0x64, "?"),
205 SMB_COM_ENTRY(0x65, "?"),
206 SMB_COM_ENTRY(0x66, "?"),
207 SMB_COM_ENTRY(0x67, "?"),
208 SMB_COM_ENTRY(0x68, "?"),
209 SMB_COM_ENTRY(0x69, "?"),
210 SMB_COM_ENTRY(0x6A, "?"),
211 SMB_COM_ENTRY(0x6B, "?"),
212 SMB_COM_ENTRY(0x6C, "?"),
213 SMB_COM_ENTRY(0x6D, "?"),
214 SMB_COM_ENTRY(0x6E, "?"),
215 SMB_COM_ENTRY(0x6F, "?"),
216 SMB_COM_ENTRY(SMB_COM_TREE_CONNECT, "No"),
217 SMB_COM_ENTRY(SMB_COM_TREE_DISCONNECT, "No"),
218 SMB_COM_ENTRY(SMB_COM_NEGOTIATE, "No"),
219 SMB_COM_ENTRY(SMB_COM_SESSION_SETUP_ANDX, "No"),
220 SMB_COM_ENTRY(SMB_COM_LOGOFF_ANDX, "No"),
221 SMB_COM_ENTRY(SMB_COM_TREE_CONNECT_ANDX, "No"),
222 SMB_COM_ENTRY(0x76, "?"),
223 SMB_COM_ENTRY(0x77, "?"),
224 SMB_COM_ENTRY(0x78, "?"),
225 SMB_COM_ENTRY(0x79, "?"),
226 SMB_COM_ENTRY(0x7A, "?"),
227 SMB_COM_ENTRY(0x7B, "?"),
228 SMB_COM_ENTRY(0x7C, "?"),
229 SMB_COM_ENTRY(0x7D, "?"),
230 SMB_COM_ENTRY(0x7E, "?"),
231 SMB_COM_ENTRY(0x7F, "?"),
232 SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION_DISK, "No"),
233 SMB_COM_ENTRY(SMB_COM_SEARCH, "No"),
234 SMB_COM_ENTRY(SMB_COM_FIND, "No"),
235 SMB_COM_ENTRY(SMB_COM_FIND_UNIQUE, "No"),
236 SMB_COM_ENTRY(SMB_COM_FIND_CLOSE, "No"),
237 SMB_COM_ENTRY(0x85, "?"),
238 SMB_COM_ENTRY(0x86, "?"),
239 SMB_COM_ENTRY(0x87, "?"),
240 SMB_COM_ENTRY(0x88, "?"),
241 SMB_COM_ENTRY(0x89, "?"),
242 SMB_COM_ENTRY(0x8A, "?"),
243 SMB_COM_ENTRY(0x8B, "?"),
244 SMB_COM_ENTRY(0x8C, "?"),
245 SMB_COM_ENTRY(0x8D, "?"),
246 SMB_COM_ENTRY(0x8E, "?"),
247 SMB_COM_ENTRY(0x8F, "?"),
248 SMB_COM_ENTRY(0x90, "?"),
249 SMB_COM_ENTRY(0x91, "?"),
250 SMB_COM_ENTRY(0x92, "?"),
251 SMB_COM_ENTRY(0x93, "?"),
252 SMB_COM_ENTRY(0x94, "?"),
253 SMB_COM_ENTRY(0x95, "?"),
254 SMB_COM_ENTRY(0x96, "?"),
255 SMB_COM_ENTRY(0x97, "?"),
256 SMB_COM_ENTRY(0x98, "?"),
257 SMB_COM_ENTRY(0x99, "?"),
258 SMB_COM_ENTRY(0x9A, "?"),
259 SMB_COM_ENTRY(0x9B, "?"),
260 SMB_COM_ENTRY(0x9C, "?"),
261 SMB_COM_ENTRY(0x9D, "?"),
262 SMB_COM_ENTRY(0x9E, "?"),
263 SMB_COM_ENTRY(0x9F, "?"),
264 SMB_COM_ENTRY(SMB_COM_NT_TRANSACT, "No"),
265 SMB_COM_ENTRY(SMB_COM_NT_TRANSACT_SECONDARY, "No"),
266 SMB_COM_ENTRY(SMB_COM_NT_CREATE_ANDX, "No"),
267 SMB_COM_ENTRY(0xA3, "?"),
268 SMB_COM_ENTRY(SMB_COM_NT_CANCEL, "No"),
269 SMB_COM_ENTRY(SMB_COM_NT_RENAME, "No"),
270 SMB_COM_ENTRY(0xA6, "?"),
271 SMB_COM_ENTRY(0xA7, "?"),
272 SMB_COM_ENTRY(0xA8, "?"),
273 SMB_COM_ENTRY(0xA9, "?"),
274 SMB_COM_ENTRY(0xAA, "?"),
275 SMB_COM_ENTRY(0xAB, "?"),
276 SMB_COM_ENTRY(0xAC, "?"),
277 SMB_COM_ENTRY(0xAD, "?"),
278 SMB_COM_ENTRY(0xAE, "?"),
279 SMB_COM_ENTRY(0xAF, "?"),
280 SMB_COM_ENTRY(0xB0, "?"),
281 SMB_COM_ENTRY(0xB1, "?"),
282 SMB_COM_ENTRY(0xB2, "?"),
283 SMB_COM_ENTRY(0xB3, "?"),
284 SMB_COM_ENTRY(0xB4, "?"),
285 SMB_COM_ENTRY(0xB5, "?"),
286 SMB_COM_ENTRY(0xB6, "?"),
287 SMB_COM_ENTRY(0xB7, "?"),
288 SMB_COM_ENTRY(0xB8, "?"),
289 SMB_COM_ENTRY(0xB9, "?"),
290 SMB_COM_ENTRY(0xBA, "?"),
291 SMB_COM_ENTRY(0xBB, "?"),
292 SMB_COM_ENTRY(0xBC, "?"),
293 SMB_COM_ENTRY(0xBD, "?"),
294 SMB_COM_ENTRY(0xBE, "?"),
295 SMB_COM_ENTRY(0xBF, "?"),
296 SMB_COM_ENTRY(SMB_COM_OPEN_PRINT_FILE, "No"),
297 SMB_COM_ENTRY(SMB_COM_WRITE_PRINT_FILE, "No"),
298 SMB_COM_ENTRY(SMB_COM_CLOSE_PRINT_FILE, "No"),
299 SMB_COM_ENTRY(SMB_COM_GET_PRINT_QUEUE, "No"),
300 SMB_COM_ENTRY(0xC4, "?"),
301 SMB_COM_ENTRY(0xC5, "?"),
302 SMB_COM_ENTRY(0xC6, "?"),
303 SMB_COM_ENTRY(0xC7, "?"),
304 SMB_COM_ENTRY(0xC8, "?"),
305 SMB_COM_ENTRY(0xC9, "?"),
306 SMB_COM_ENTRY(0xCA, "?"),
307 SMB_COM_ENTRY(0xCB, "?"),
308 SMB_COM_ENTRY(0xCC, "?"),
309 SMB_COM_ENTRY(0xCD, "?"),
310 SMB_COM_ENTRY(0xCE, "?"),
311 SMB_COM_ENTRY(0xCF, "?"),
312 SMB_COM_ENTRY(0xD0, "?"),
313 SMB_COM_ENTRY(0xD1, "?"),
314 SMB_COM_ENTRY(0xD2, "?"),
315 SMB_COM_ENTRY(0xD3, "?"),
316 SMB_COM_ENTRY(0xD4, "?"),
317 SMB_COM_ENTRY(0xD5, "?"),
318 SMB_COM_ENTRY(0xD6, "?"),
319 SMB_COM_ENTRY(0xD7, "?"),
320 SMB_COM_ENTRY(SMB_COM_READ_BULK, "No"),
321 SMB_COM_ENTRY(SMB_COM_WRITE_BULK, "No"),
322 SMB_COM_ENTRY(SMB_COM_WRITE_BULK_DATA, "No"),
323 SMB_COM_ENTRY(0xDB, "?"),
324 SMB_COM_ENTRY(0xDC, "?"),
325 SMB_COM_ENTRY(0xDD, "?"),
326 SMB_COM_ENTRY(0xDE, "?"),
327 SMB_COM_ENTRY(0xDF, "?"),
328 SMB_COM_ENTRY(0xE0, "?"),
329 SMB_COM_ENTRY(0xE1, "?"),
330 SMB_COM_ENTRY(0xE2, "?"),
331 SMB_COM_ENTRY(0xE3, "?"),
332 SMB_COM_ENTRY(0xE4, "?"),
333 SMB_COM_ENTRY(0xE5, "?"),
334 SMB_COM_ENTRY(0xE6, "?"),
335 SMB_COM_ENTRY(0xE7, "?"),
336 SMB_COM_ENTRY(0xE8, "?"),
337 SMB_COM_ENTRY(0xE9, "?"),
338 SMB_COM_ENTRY(0xEA, "?"),
339 SMB_COM_ENTRY(0xEB, "?"),
340 SMB_COM_ENTRY(0xEC, "?"),
341 SMB_COM_ENTRY(0xED, "?"),
342 SMB_COM_ENTRY(0xEE, "?"),
343 SMB_COM_ENTRY(0xEF, "?"),
344 SMB_COM_ENTRY(0xF0, "?"),
345 SMB_COM_ENTRY(0xF1, "?"),
346 SMB_COM_ENTRY(0xF2, "?"),
347 SMB_COM_ENTRY(0xF3, "?"),
348 SMB_COM_ENTRY(0xF4, "?"),
349 SMB_COM_ENTRY(0xF5, "?"),
350 SMB_COM_ENTRY(0xF6, "?"),
351 SMB_COM_ENTRY(0xF7, "?"),
352 SMB_COM_ENTRY(0xF8, "?"),
353 SMB_COM_ENTRY(0xF9, "?"),
354 SMB_COM_ENTRY(0xFA, "?"),
355 SMB_COM_ENTRY(0xFB, "?"),
356 SMB_COM_ENTRY(0xFC, "?"),
357 SMB_COM_ENTRY(0xFD, "?"),
358 SMB_COM_ENTRY(0xFE, "?"),
359 SMB_COM_ENTRY(0xFF, "?")
362 static const char *smb2_cmd_names[SMB2__NCMDS] = {
363 "smb2_negotiate",
364 "smb2_session_setup",
365 "smb2_logoff",
366 "smb2_tree_connect",
367 "smb2_tree_disconn",
368 "smb2_create",
369 "smb2_close",
370 "smb2_flush",
371 "smb2_read",
372 "smb2_write",
373 "smb2_lock",
374 "smb2_ioctl",
375 "smb2_cancel",
376 "smb2_echo",
377 "smb2_query_dir",
378 "smb2_change_notify",
379 "smb2_query_info",
380 "smb2_set_info",
381 "smb2_oplock_break",
382 "smb2_invalid_cmd"
385 static int smb_dcmd_list(uintptr_t, uint_t, int, const mdb_arg_t *);
386 static void smb_dcmd_list_help(void);
387 static int smb_dcmd_server(uintptr_t, uint_t, int, const mdb_arg_t *);
388 static void smb_dcmd_session_help(void);
389 static int smb_dcmd_session(uintptr_t, uint_t, int, const mdb_arg_t *);
390 static int smb_dcmd_request(uintptr_t, uint_t, int, const mdb_arg_t *);
391 static void smb_dcmd_user_help(void);
392 static int smb_dcmd_user(uintptr_t, uint_t, int, const mdb_arg_t *);
393 static void smb_dcmd_tree_help(void);
394 static int smb_dcmd_tree(uintptr_t, uint_t, int, const mdb_arg_t *);
395 static int smb_dcmd_odir(uintptr_t, uint_t, int, const mdb_arg_t *);
396 static int smb_dcmd_ofile(uintptr_t, uint_t, int, const mdb_arg_t *);
397 static int smb_dcmd_kshare(uintptr_t, uint_t, int, const mdb_arg_t *);
398 static int smb_dcmd_vfs(uintptr_t, uint_t, int, const mdb_arg_t *);
399 static int smb_vfs_walk_init(mdb_walk_state_t *);
400 static int smb_vfs_walk_step(mdb_walk_state_t *);
401 static void smb_node_help(void);
402 static int smb_dcmd_node(uintptr_t, uint_t, int, const mdb_arg_t *);
403 static int smb_node_walk_init(mdb_walk_state_t *);
404 static int smb_node_walk_step(mdb_walk_state_t *);
405 static int smb_lock(uintptr_t, uint_t, int, const mdb_arg_t *);
406 static int smb_oplock(uintptr_t, uint_t, int, const mdb_arg_t *);
407 static int smb_oplock_grant(uintptr_t, uint_t, int, const mdb_arg_t *);
408 static int smb_ace(uintptr_t, uint_t, int, const mdb_arg_t *);
409 static int smb_ace_walk_init(mdb_walk_state_t *);
410 static int smb_ace_walk_step(mdb_walk_state_t *);
411 static int smb_acl(uintptr_t, uint_t, int, const mdb_arg_t *);
412 static int smb_sd(uintptr_t, uint_t, int, const mdb_arg_t *);
413 static int smb_sid(uintptr_t, uint_t, int, const mdb_arg_t *);
414 static int smb_sid_print(uintptr_t);
415 static int smb_fssd(uintptr_t, uint_t, int, const mdb_arg_t *);
416 static int smb_dcmd_getopt(uint_t *, int, const mdb_arg_t *);
417 static int smb_dcmd_setopt(uint_t, int, mdb_arg_t *);
418 static int smb_obj_expand(uintptr_t, uint_t, const smb_exp_t *, ulong_t);
419 static int smb_obj_list(const char *, uint_t, uint_t);
420 static int smb_worker_findstack(uintptr_t);
421 static int smb_stats(uintptr_t, uint_t, int, const mdb_arg_t *);
424 * MDB module linkage information:
426 * We declare a list of structures describing our dcmds, a list of structures
427 * describing our walkers and a function named _mdb_init to return a pointer
428 * to our module information.
430 static const mdb_dcmd_t dcmds[] = {
431 { "smblist",
432 "[-seutfdwv]",
433 "print tree of SMB objects",
434 smb_dcmd_list,
435 smb_dcmd_list_help },
436 { "smbsrv",
437 "[-seutfdwv]",
438 "print smb_server information",
439 smb_dcmd_server },
440 { "smbshares",
441 "[-v]",
442 "print smb_kshare_t information",
443 smb_dcmd_kshare },
444 { "smbvfs",
445 "[-v]",
446 "print smb_vfs information",
447 smb_dcmd_vfs },
448 { "smbnode",
449 "?[-vps]",
450 "print smb_node_t information",
451 smb_dcmd_node,
452 smb_node_help },
453 { "smbsess",
454 "[-utfdwv]",
455 "print smb_session_t information",
456 smb_dcmd_session,
457 smb_dcmd_session_help},
458 { "smbreq",
459 ":[-v]",
460 "print smb_request_t information",
461 smb_dcmd_request },
462 { "smblock", ":[-v]",
463 "print smb_lock_t information", smb_lock },
464 { "smbuser",
465 ":[-vdftq]",
466 "print smb_user_t information",
467 smb_dcmd_user,
468 smb_dcmd_user_help },
469 { "smbtree",
470 ":[-vdf]",
471 "print smb_tree_t information",
472 smb_dcmd_tree,
473 smb_dcmd_tree_help },
474 { "smbodir",
475 ":[-v]",
476 "print smb_odir_t information",
477 smb_dcmd_odir },
478 { "smbofile",
479 "[-v]",
480 "print smb_file_t information",
481 smb_dcmd_ofile },
482 { "smboplock", NULL,
483 "print smb_oplock_t information", smb_oplock },
484 { "smboplockgrant", NULL,
485 "print smb_oplock_grant_t information", smb_oplock_grant },
486 { "smbstat", NULL,
487 "print all smb dispatched requests statistics",
488 smb_stats },
489 { "smbace", "[-v]",
490 "print smb_ace_t information", smb_ace },
491 { "smbacl", "[-v]",
492 "print smb_acl_t information", smb_acl },
493 { "smbsid", "[-v]",
494 "print smb_sid_t information", smb_sid },
495 { "smbsd", "[-v]",
496 "print smb_sd_t information", smb_sd },
497 { "smbfssd", "[-v]",
498 "print smb_fssd_t information", smb_fssd },
499 { NULL }
502 static const mdb_walker_t walkers[] = {
503 { "smbnode_walker",
504 "walk list of smb_node_t structures",
505 smb_node_walk_init,
506 smb_node_walk_step,
507 NULL,
508 NULL },
509 { "smbvfs_walker",
510 "walk list of smb_vfs_t structures",
511 smb_vfs_walk_init,
512 smb_vfs_walk_step,
513 NULL,
514 NULL },
515 { "smbace_walker",
516 "walk list of smb_ace_t structures",
517 smb_ace_walk_init,
518 smb_ace_walk_step,
519 NULL,
520 NULL },
521 { NULL }
524 static const mdb_modinfo_t modinfo = {
525 MDB_API_VERSION, dcmds, walkers
528 const mdb_modinfo_t *
529 _mdb_init(void)
531 return (&modinfo);
535 * *****************************************************************************
536 * ****************************** Top level DCMD *******************************
537 * *****************************************************************************
540 static void
541 smb_dcmd_list_help(void)
543 mdb_printf(
544 "Displays the list of objects using an indented tree format.\n"
545 "If no option is specified the entire tree is displayed\n\n");
546 (void) mdb_dec_indent(2);
547 mdb_printf("%<b>OPTIONS%</b>\n");
548 (void) mdb_inc_indent(2);
549 mdb_printf(
550 "-v\tDisplay verbose information\n"
551 "-s\tDisplay the list of servers\n"
552 "-e\tDisplay the list of sessions\n"
553 "-r\tDisplay the list of smb requests\n"
554 "-u\tDisplay the list of users\n"
555 "-t\tDisplay the list of trees\n"
556 "-f\tDisplay the list of open files\n"
557 "-d\tDisplay the list of open searches\n");
561 * ::smblist
563 * This function lists the objects specified on the command line. If no object
564 * is specified the entire tree (server through ofile and odir) is displayed.
567 /*ARGSUSED*/
568 static int
569 smb_dcmd_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
571 GElf_Sym sym;
572 uint_t opts = 0;
573 int new_argc;
574 mdb_arg_t new_argv[SMB_MDB_MAX_OPTS];
576 if (smb_dcmd_getopt(&opts, argc, argv))
577 return (DCMD_USAGE);
579 if (!(opts & ~(SMB_OPT_WALK | SMB_OPT_VERBOSE)))
580 opts |= SMB_OPT_ALL_OBJ;
582 opts |= SMB_OPT_WALK;
584 new_argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, new_argv);
586 if (mdb_lookup_by_obj(SMBSRV_OBJNAME, "smb_servers", &sym) == -1) {
587 mdb_warn("failed to find symbol smb_servers");
588 return (DCMD_ERR);
591 addr = (uintptr_t)sym.st_value + OFFSETOF(smb_llist_t, ll_list);
593 if (mdb_pwalk_dcmd("list", "smbsrv", new_argc, new_argv, addr)) {
594 mdb_warn("cannot walk smb_server list");
595 return (DCMD_ERR);
597 return (DCMD_OK);
601 * *****************************************************************************
602 * ***************************** smb_server_t **********************************
603 * *****************************************************************************
606 static const char *smb_server_state[SMB_SERVER_STATE_SENTINEL] =
608 "CREATED",
609 "CONFIGURED",
610 "RUNNING",
611 "STOPPING",
612 "DELETING"
616 * List of objects that can be expanded under a server structure.
618 static const smb_exp_t smb_server_exp[] =
620 { SMB_OPT_ALL_OBJ,
621 OFFSETOF(smb_server_t, sv_nbt_daemon.ld_session_list.ll_list),
622 "smbsess", "smb_session"},
623 { SMB_OPT_ALL_OBJ,
624 OFFSETOF(smb_server_t, sv_tcp_daemon.ld_session_list.ll_list),
625 "smbsess", "smb_session"},
626 { 0, 0, NULL, NULL }
630 * ::smbsrv
632 * smbsrv dcmd - Print out smb_server structures.
634 /*ARGSUSED*/
635 static int
636 smb_dcmd_server(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
638 uint_t opts;
639 ulong_t indent = 0;
641 if (smb_dcmd_getopt(&opts, argc, argv))
642 return (DCMD_USAGE);
644 if (!(flags & DCMD_ADDRSPEC))
645 return (smb_obj_list("smb_server", opts | SMB_OPT_SERVER,
646 flags));
648 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SERVER)) ||
649 !(opts & SMB_OPT_WALK)) {
650 smb_server_t *sv;
651 const char *state;
653 sv = mdb_alloc(sizeof (smb_server_t), UM_SLEEP | UM_GC);
654 if (mdb_vread(sv, sizeof (smb_server_t), addr) == -1) {
655 mdb_warn("failed to read smb_server at %p", addr);
656 return (DCMD_ERR);
659 indent = SMB_DCMD_INDENT;
661 if (opts & SMB_OPT_VERBOSE) {
662 mdb_arg_t argv;
664 argv.a_type = MDB_TYPE_STRING;
665 argv.a_un.a_str = "smb_server_t";
666 if (mdb_call_dcmd("print", addr, flags, 1, &argv))
667 return (DCMD_ERR);
668 } else {
669 if (DCMD_HDRSPEC(flags))
670 mdb_printf(
671 "%<b>%<u>%-?s% "
672 "%-4s% "
673 "%-32s% "
674 "%</u>%</b>\n",
675 "SERVER", "ZONE", "STATE");
677 if (sv->sv_state >= SMB_SERVER_STATE_SENTINEL)
678 state = "UNKNOWN";
679 else
680 state = smb_server_state[sv->sv_state];
682 mdb_printf("%-?p %-4d %-32s \n",
683 addr, sv->sv_zid, state);
686 if (smb_obj_expand(addr, opts, smb_server_exp, indent))
687 return (DCMD_ERR);
688 return (DCMD_OK);
692 * *****************************************************************************
693 * ***************************** smb_session_t *********************************
694 * *****************************************************************************
697 static const char *smb_session_state[SMB_SESSION_STATE_SENTINEL] =
699 "INITIALIZED",
700 "DISCONNECTED",
701 "CONNECTED",
702 "ESTABLISHED",
703 "NEGOTIATED",
704 "TERMINATED"
708 * List of objects that can be expanded under a session structure.
710 static const smb_exp_t smb_session_exp[] =
712 { SMB_OPT_REQUEST,
713 OFFSETOF(smb_session_t, s_req_list.sl_list),
714 "smbreq", "smb_request"},
715 { SMB_OPT_USER,
716 OFFSETOF(smb_session_t, s_user_list.ll_list),
717 "smbuser", "smb_user"},
718 { SMB_OPT_TREE | SMB_OPT_OFILE | SMB_OPT_ODIR,
719 OFFSETOF(smb_session_t, s_tree_list.ll_list),
720 "smbtree", "smb_tree"},
721 { 0, 0, NULL, NULL}
724 static void
725 smb_dcmd_session_help(void)
727 mdb_printf(
728 "Display the contents of smb_session_t, with optional"
729 " filtering.\n\n");
730 (void) mdb_dec_indent(2);
731 mdb_printf("%<b>OPTIONS%</b>\n");
732 (void) mdb_inc_indent(2);
733 mdb_printf(
734 "-v\tDisplay verbose smb_session information\n"
735 "-r\tDisplay the list of smb requests attached\n"
736 "-u\tDisplay the list of users attached\n");
740 * ::smbsess
742 * smbsess dcmd - Print out the smb_session structure.
744 static int
745 smb_dcmd_session(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
747 uint_t opts;
748 ulong_t indent = 0;
750 if (smb_dcmd_getopt(&opts, argc, argv))
751 return (DCMD_USAGE);
753 if (!(flags & DCMD_ADDRSPEC)) {
754 opts |= SMB_OPT_SESSION;
755 opts &= ~SMB_OPT_SERVER;
756 return (smb_obj_list("smb_session", opts, flags));
759 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SESSION)) ||
760 !(opts & SMB_OPT_WALK)) {
761 char cipaddr[INET6_ADDRSTRLEN];
762 char lipaddr[INET6_ADDRSTRLEN];
763 int ipaddrstrlen;
764 smb_session_t *se;
765 const char *state;
767 indent = SMB_DCMD_INDENT;
769 se = mdb_alloc(sizeof (*se), UM_SLEEP | UM_GC);
770 if (mdb_vread(se, sizeof (*se), addr) == -1) {
771 mdb_warn("failed to read smb_session at %p", addr);
772 return (DCMD_ERR);
774 if (se->s_state >= SMB_SESSION_STATE_SENTINEL)
775 state = "INVALID";
776 else
777 state = smb_session_state[se->s_state];
779 switch (se->ipaddr.a_family) {
780 case AF_INET:
781 ipaddrstrlen = INET_ADDRSTRLEN;
782 (void) mdb_snprintf(cipaddr, sizeof (cipaddr),
783 "%I", se->ipaddr.a_ipv4);
784 (void) mdb_snprintf(lipaddr, sizeof (lipaddr),
785 "%I", se->local_ipaddr.a_ipv4);
786 break;
787 case AF_INET6:
788 ipaddrstrlen = INET6_ADDRSTRLEN;
789 (void) mdb_snprintf(cipaddr, sizeof (cipaddr),
790 "%N", &(se->ipaddr.a_ipv6));
791 (void) mdb_snprintf(lipaddr, sizeof (lipaddr),
792 "%N", &(se->local_ipaddr.a_ipv6));
793 break;
794 default:
795 ipaddrstrlen = INET_ADDRSTRLEN;
796 (void) mdb_snprintf(cipaddr, sizeof (cipaddr),
797 "unknown");
798 (void) mdb_snprintf(lipaddr, sizeof (lipaddr),
799 "unknown");
802 if (opts & SMB_OPT_VERBOSE) {
803 mdb_printf("%<b>%<u>SMB session information "
804 "(%p): %</u>%</b>\n", addr);
805 mdb_printf("Client IP address: %s %d\n",
806 cipaddr, se->s_remote_port);
807 mdb_printf("Local IP Address: %s %d\n",
808 lipaddr, se->s_local_port);
809 mdb_printf("Session KID: %u\n", se->s_kid);
810 mdb_printf("Workstation Name: %s\n",
811 se->workstation);
812 mdb_printf("Session state: %u (%s)\n", se->s_state,
813 state);
814 mdb_printf("Session dialect: %#x\n", se->dialect);
815 mdb_printf("Number of Users: %u\n",
816 se->s_user_list.ll_count);
817 mdb_printf("Number of Trees: %u\n", se->s_tree_cnt);
818 mdb_printf("Number of Files: %u\n", se->s_file_cnt);
819 mdb_printf("Number of Shares: %u\n", se->s_dir_cnt);
820 mdb_printf("Number of active Transact.: %u\n\n",
821 se->s_xa_list.ll_count);
822 } else {
823 if (DCMD_HDRSPEC(flags)) {
824 mdb_printf(
825 "%<b>%<u>%-?s %-*s %-8s %-8s %-12s%</u>%</b>\n",
826 "SESSION", ipaddrstrlen, "IP_ADDR",
827 "PORT", "DIALECT", "STATE");
829 mdb_printf("%-?p %-*s %-8d %-8#x %s\n",
830 addr, ipaddrstrlen, cipaddr,
831 se->s_remote_port, se->dialect, state);
834 if (smb_obj_expand(addr, opts, smb_session_exp, indent))
835 return (DCMD_ERR);
836 return (DCMD_OK);
840 * *****************************************************************************
841 * **************************** smb_request_t **********************************
842 * *****************************************************************************
845 static const char *smb_request_state[SMB_REQ_STATE_SENTINEL] =
847 "FREE",
848 "INITIALIZING",
849 "SUBMITTED",
850 "ACTIVE",
851 "WAITING_EVENT",
852 "EVENT_OCCURRED",
853 "WAITING_LOCK",
854 "COMPLETED",
855 "CANCELED",
856 "CLEANED_UP"
859 #define SMB_REQUEST_BANNER \
860 "%<b>%<u>%-?s %-?s %-14s %-14s %-16s %-32s%</u>%</b>\n"
861 #define SMB_REQUEST_FORMAT \
862 "%-?p %-?p %-14lld %-14lld %-16s %s\n"
864 static int
865 smb_dcmd_request(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
867 uint_t opts;
869 if (smb_dcmd_getopt(&opts, argc, argv))
870 return (DCMD_USAGE);
872 if (!(flags & DCMD_ADDRSPEC)) {
873 opts |= SMB_OPT_REQUEST;
874 opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_USER);
875 return (smb_obj_list("smb_request", opts, flags));
878 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_REQUEST)) ||
879 !(opts & SMB_OPT_WALK)) {
880 smb_request_t *sr;
881 const char *state;
882 const char *cur_cmd_name;
883 uint_t cur_cmd_code;
884 uint64_t waiting;
885 uint64_t running;
887 sr = mdb_alloc(sizeof (*sr), UM_SLEEP | UM_GC);
888 if (mdb_vread(sr, sizeof (*sr), addr) == -1) {
889 mdb_warn("failed to read smb_request at %p", addr);
890 return (DCMD_ERR);
892 if (sr->sr_magic != SMB_REQ_MAGIC) {
893 mdb_warn("not an smb_request_t (%p)>", addr);
894 return (DCMD_ERR);
896 waiting = 0;
897 running = 0;
899 * Note: mdb_gethrtime() is only available in kmdb
901 #ifdef _KERNEL
902 if (sr->sr_time_submitted != 0) {
903 if (sr->sr_time_active != 0) {
904 waiting = sr->sr_time_active -
905 sr->sr_time_submitted;
906 running = mdb_gethrtime() -
907 sr->sr_time_active;
908 } else {
909 waiting = mdb_gethrtime() -
910 sr->sr_time_submitted;
913 waiting /= NANOSEC;
914 running /= NANOSEC;
915 #endif /* _KERNEL */
917 if (sr->sr_state >= SMB_REQ_STATE_SENTINEL)
918 state = "INVALID";
919 else
920 state = smb_request_state[sr->sr_state];
922 if (sr->smb2_cmd_code != 0) {
923 /* SMB2 request */
924 cur_cmd_code = sr->smb2_cmd_code;
925 if (cur_cmd_code > SMB2_INVALID_CMD)
926 cur_cmd_code = SMB2_INVALID_CMD;
927 cur_cmd_name = smb2_cmd_names[cur_cmd_code];
928 } else {
929 /* SMB1 request */
930 cur_cmd_code = sr->smb_com & 0xFF;
931 cur_cmd_name = smb_com[cur_cmd_code].smb_com;
934 if (opts & SMB_OPT_VERBOSE) {
935 mdb_printf(
936 "%</b>%</u>SMB request information (%p):"
937 "%</u>%</b>\n\n", addr);
939 if (sr->smb2_cmd_code == 0) {
940 /* SMB1 request */
941 mdb_printf(
942 "first SMB COM: %u (%s)\n",
943 sr->first_smb_com,
944 smb_com[sr->first_smb_com].smb_com);
947 mdb_printf(
948 "current SMB COM: %u (%s)\n",
949 cur_cmd_code, cur_cmd_name);
951 mdb_printf(
952 "state: %u (%s)\n",
953 sr->sr_state, state);
955 mdb_printf(
956 "TID(tree): %u (%p)\n",
957 sr->smb_tid, sr->tid_tree);
959 mdb_printf(
960 "UID(user): %u (%p)\n",
961 sr->smb_uid, sr->uid_user);
963 mdb_printf(
964 "FID(file): %u (%p)\n",
965 sr->smb_fid, sr->fid_ofile);
967 mdb_printf(
968 "PID: %u\n",
969 sr->smb_pid);
971 if (sr->smb2_messageid != 0) {
972 mdb_printf(
973 "MID: 0x%llx\n\n",
974 sr->smb2_messageid);
975 } else {
976 mdb_printf(
977 "MID: %u\n\n",
978 sr->smb_mid);
981 mdb_printf(
982 "waiting time: %lld\n",
983 waiting);
985 mdb_printf(
986 "running time: %lld\n",
987 running);
989 mdb_printf(
990 "worker thread: %p\n",
991 sr->sr_worker);
992 smb_worker_findstack((uintptr_t)sr->sr_worker);
993 } else {
994 if (DCMD_HDRSPEC(flags))
995 mdb_printf(
996 SMB_REQUEST_BANNER,
997 "ADDR",
998 "WORKER",
999 "WAITING(s)",
1000 "RUNNING(s)",
1001 "STATE",
1002 "COMMAND");
1004 mdb_printf(
1005 SMB_REQUEST_FORMAT,
1006 addr,
1007 sr->sr_worker,
1008 waiting,
1009 running,
1010 state,
1011 cur_cmd_name);
1014 return (DCMD_OK);
1018 * *****************************************************************************
1019 * ****************************** smb_user_t ***********************************
1020 * *****************************************************************************
1023 static const char *smb_user_state[SMB_USER_STATE_SENTINEL] =
1025 "LOGGING_ON",
1026 "LOGGED_ON",
1027 "LOGGING_OFF",
1028 "LOGGED_OFF"
1031 static void
1032 smb_dcmd_user_help(void)
1034 mdb_printf(
1035 "Display the contents of smb_user_t, with optional filtering.\n\n");
1036 (void) mdb_dec_indent(2);
1037 mdb_printf("%<b>OPTIONS%</b>\n");
1038 (void) mdb_inc_indent(2);
1039 mdb_printf(
1040 "-v\tDisplay verbose smb_user information\n");
1043 static int
1044 smb_dcmd_user(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1046 uint_t opts;
1048 if (smb_dcmd_getopt(&opts, argc, argv))
1049 return (DCMD_USAGE);
1051 if (!(flags & DCMD_ADDRSPEC)) {
1052 opts |= SMB_OPT_USER;
1053 opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST);
1054 return (smb_obj_list("smb_user", opts, flags));
1057 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_USER)) ||
1058 !(opts & SMB_OPT_WALK)) {
1059 smb_user_t *user;
1060 char *account;
1062 user = mdb_alloc(sizeof (*user), UM_SLEEP | UM_GC);
1063 if (mdb_vread(user, sizeof (*user), addr) == -1) {
1064 mdb_warn("failed to read smb_user at %p", addr);
1065 return (DCMD_ERR);
1067 account = mdb_zalloc(user->u_domain_len + user->u_name_len + 2,
1068 UM_SLEEP | UM_GC);
1070 if (user->u_domain_len)
1071 (void) mdb_vread(account, user->u_domain_len,
1072 (uintptr_t)user->u_domain);
1074 strcat(account, "\\");
1076 if (user->u_name_len)
1077 (void) mdb_vread(account + strlen(account),
1078 user->u_name_len, (uintptr_t)user->u_name);
1080 if (opts & SMB_OPT_VERBOSE) {
1081 const char *state;
1083 if (user->u_state >= SMB_USER_STATE_SENTINEL)
1084 state = "INVALID";
1085 else
1086 state = smb_user_state[user->u_state];
1088 mdb_printf("%<b>%<u>SMB user information (%p):"
1089 "%</u>%</b>\n", addr);
1090 mdb_printf("UID: %u\n", user->u_uid);
1091 mdb_printf("State: %d (%s)\n", user->u_state, state);
1092 mdb_printf("Flags: 0x%08x\n", user->u_flags);
1093 mdb_printf("Privileges: 0x%08x\n", user->u_privileges);
1094 mdb_printf("Credential: %p\n", user->u_cred);
1095 mdb_printf("Reference Count: %d\n", user->u_refcnt);
1096 mdb_printf("User Account: %s\n\n", account);
1097 } else {
1098 if (DCMD_HDRSPEC(flags))
1099 mdb_printf(
1100 "%<b>%<u>%?-s "
1101 "%-5s "
1102 "%-32s%</u>%</b>\n",
1103 "USER", "UID", "ACCOUNT");
1105 mdb_printf("%-?p %-5u %-32s\n", addr, user->u_uid,
1106 account);
1109 return (DCMD_OK);
1113 * *****************************************************************************
1114 * ****************************** smb_tree_t ***********************************
1115 * *****************************************************************************
1118 static const char *smb_tree_state[SMB_TREE_STATE_SENTINEL] =
1120 "CONNECTED",
1121 "DISCONNECTING",
1122 "DISCONNECTED"
1126 * List of objects that can be expanded under a tree structure.
1128 static const smb_exp_t smb_tree_exp[] =
1130 { SMB_OPT_OFILE,
1131 OFFSETOF(smb_tree_t, t_ofile_list.ll_list),
1132 "smbofile", "smb_ofile"},
1133 { SMB_OPT_ODIR,
1134 OFFSETOF(smb_tree_t, t_odir_list.ll_list),
1135 "smbodir", "smb_odir"},
1136 { 0, 0, NULL, NULL}
1139 static void
1140 smb_dcmd_tree_help(void)
1142 mdb_printf(
1143 "Display the contents of smb_tree_t, with optional filtering.\n\n");
1144 (void) mdb_dec_indent(2);
1145 mdb_printf("%<b>OPTIONS%</b>\n");
1146 (void) mdb_inc_indent(2);
1147 mdb_printf(
1148 "-v\tDisplay verbose smb_tree information\n"
1149 "-d\tDisplay the list of smb_odirs attached\n"
1150 "-f\tDisplay the list of smb_ofiles attached\n");
1153 static int
1154 smb_dcmd_tree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1156 uint_t opts;
1157 ulong_t indent = 0;
1159 if (smb_dcmd_getopt(&opts, argc, argv))
1160 return (DCMD_USAGE);
1162 if (!(flags & DCMD_ADDRSPEC)) {
1163 opts |= SMB_OPT_TREE;
1164 opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1165 SMB_OPT_USER);
1166 return (smb_obj_list("smb_tree", opts, flags));
1169 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_TREE)) ||
1170 !(opts & SMB_OPT_WALK)) {
1171 smb_tree_t *tree;
1173 indent = SMB_DCMD_INDENT;
1175 tree = mdb_alloc(sizeof (*tree), UM_SLEEP | UM_GC);
1176 if (mdb_vread(tree, sizeof (*tree), addr) == -1) {
1177 mdb_warn("failed to read smb_tree at %p", addr);
1178 return (DCMD_ERR);
1180 if (opts & SMB_OPT_VERBOSE) {
1181 const char *state;
1183 if (tree->t_state >= SMB_TREE_STATE_SENTINEL)
1184 state = "INVALID";
1185 else
1186 state = smb_tree_state[tree->t_state];
1188 mdb_printf("%<b>%<u>SMB tree information (%p):"
1189 "%</u>%</b>\n\n", addr);
1190 mdb_printf("TID: %04x\n", tree->t_tid);
1191 mdb_printf("State: %d (%s)\n", tree->t_state, state);
1192 mdb_printf("Share: %s\n", tree->t_sharename);
1193 mdb_printf("Resource: %s\n", tree->t_resource);
1194 mdb_printf("Type: %s\n", tree->t_typename);
1195 mdb_printf("Volume: %s\n", tree->t_volume);
1196 mdb_printf("Umask: %04x\n", tree->t_umask);
1197 mdb_printf("Flags: %08x\n", tree->t_flags);
1198 mdb_printf("SMB Node: %llx\n", tree->t_snode);
1199 mdb_printf("Reference Count: %d\n\n", tree->t_refcnt);
1200 } else {
1201 if (DCMD_HDRSPEC(flags))
1202 mdb_printf(
1203 "%<b>%<u>%-?s %-5s %-16s %-32s%</u>%</b>\n",
1204 "TREE", "TID", "SHARE NAME", "RESOURCE");
1206 mdb_printf("%-?p %-5u %-16s %-32s\n", addr,
1207 tree->t_tid, tree->t_sharename, tree->t_resource);
1210 if (smb_obj_expand(addr, opts, smb_tree_exp, indent))
1211 return (DCMD_ERR);
1212 return (DCMD_OK);
1216 * *****************************************************************************
1217 * ****************************** smb_odir_t ***********************************
1218 * *****************************************************************************
1221 static const char *smb_odir_state[SMB_ODIR_STATE_SENTINEL] =
1223 "OPEN",
1224 "IN_USE",
1225 "CLOSING",
1226 "CLOSED"
1229 static int
1230 smb_dcmd_odir(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1232 uint_t opts;
1234 if (smb_dcmd_getopt(&opts, argc, argv))
1235 return (DCMD_USAGE);
1237 if (!(flags & DCMD_ADDRSPEC)) {
1238 opts |= SMB_OPT_ODIR;
1239 opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1240 SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_OFILE);
1241 return (smb_obj_list("smb_odir", opts, flags));
1244 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_ODIR)) ||
1245 !(opts & SMB_OPT_WALK)) {
1246 smb_odir_t *od;
1248 od = mdb_alloc(sizeof (*od), UM_SLEEP | UM_GC);
1249 if (mdb_vread(od, sizeof (*od), addr) == -1) {
1250 mdb_warn("failed to read smb_odir at %p", addr);
1251 return (DCMD_ERR);
1253 if (opts & SMB_OPT_VERBOSE) {
1254 const char *state;
1256 if (od->d_state >= SMB_ODIR_STATE_SENTINEL)
1257 state = "INVALID";
1258 else
1259 state = smb_odir_state[od->d_state];
1261 mdb_printf(
1262 "%<b>%<u>SMB odir information (%p):%</u>%</b>\n\n",
1263 addr);
1264 mdb_printf("State: %d (%s)\n", od->d_state, state);
1265 mdb_printf("SID: %u\n", od->d_odid);
1266 mdb_printf("User: %p\n", od->d_user);
1267 mdb_printf("Tree: %p\n", od->d_tree);
1268 mdb_printf("Reference Count: %d\n", od->d_refcnt);
1269 mdb_printf("Pattern: %s\n", od->d_pattern);
1270 mdb_printf("SMB Node: %p\n\n", od->d_dnode);
1271 } else {
1272 if (DCMD_HDRSPEC(flags))
1273 mdb_printf(
1274 "%<b>%<u>%-?s "
1275 "%-5s "
1276 "%-?s "
1277 "%-16s%</u>%</b>\n",
1278 "ODIR", "SID", "VNODE", "PATTERN");
1280 mdb_printf("%?p %-5u %-16p %s\n",
1281 addr, od->d_odid, od->d_dnode, od->d_pattern);
1284 return (DCMD_OK);
1288 * *****************************************************************************
1289 * ****************************** smb_ofile_t **********************************
1290 * *****************************************************************************
1293 static const char *smb_ofile_state[SMB_OFILE_STATE_SENTINEL] =
1295 "OPEN",
1296 "CLOSING",
1297 "CLOSED"
1300 static int
1301 smb_dcmd_ofile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1303 uint_t opts;
1305 if (smb_dcmd_getopt(&opts, argc, argv))
1306 return (DCMD_USAGE);
1308 if (!(flags & DCMD_ADDRSPEC)) {
1309 opts |= SMB_OPT_OFILE;
1310 opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1311 SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_ODIR);
1312 return (smb_obj_list("smb_ofile", opts, flags));
1315 if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_OFILE)) ||
1316 !(opts & SMB_OPT_WALK)) {
1317 smb_ofile_t *of;
1319 of = mdb_alloc(sizeof (*of), UM_SLEEP | UM_GC);
1320 if (mdb_vread(of, sizeof (*of), addr) == -1) {
1321 mdb_warn("failed to read smb_ofile at %p", addr);
1322 return (DCMD_ERR);
1324 if (opts & SMB_OPT_VERBOSE) {
1325 const char *state;
1327 if (of->f_state >= SMB_OFILE_STATE_SENTINEL)
1328 state = "INVALID";
1329 else
1330 state = smb_ofile_state[of->f_state];
1332 mdb_printf(
1333 "%<b>%<u>SMB ofile information (%p):%</u>%</b>\n\n",
1334 addr);
1335 mdb_printf("FID: %u\n", of->f_fid);
1336 mdb_printf("State: %d (%s)\n", of->f_state, state);
1337 mdb_printf("SMB Node: %p\n", of->f_node);
1338 mdb_printf("LLF Offset: 0x%llx (%s)\n",
1339 of->f_llf_pos,
1340 ((of->f_flags & SMB_OFLAGS_LLF_POS_VALID) ?
1341 "Valid" : "Invalid"));
1342 mdb_printf("Flags: 0x%08x\n", of->f_flags);
1343 mdb_printf("User: %p\n", of->f_user);
1344 mdb_printf("Tree: %p\n", of->f_tree);
1345 mdb_printf("Credential: %p\n\n", of->f_cr);
1346 } else {
1347 if (DCMD_HDRSPEC(flags))
1348 mdb_printf(
1349 "%<b>%<u>%-?s "
1350 "%-5s "
1351 "%-?s "
1352 "%-?s%</u>%</b>\n",
1353 "OFILE", "FID", "SMB NODE", "CRED");
1355 mdb_printf("%?p %-5u %-p %p\n", addr,
1356 of->f_fid, of->f_node, of->f_cr);
1359 return (DCMD_OK);
1363 * *****************************************************************************
1364 * ******************************** smb_kshare_t *******************************
1365 * *****************************************************************************
1368 static int
1369 smb_kshare_cb(uintptr_t addr, const void *data, void *arg)
1371 uint_t *opts = arg;
1372 uintptr_t ta, sa;
1373 char name[32];
1374 char path[64];
1375 _NOTE(ARGUNUSED(data));
1377 if (*opts & SMB_OPT_VERBOSE) {
1378 mdb_arg_t argv;
1380 argv.a_type = MDB_TYPE_STRING;
1381 argv.a_un.a_str = "smb_kshare_t";
1382 /* Don't fail the walk if this fails. */
1383 mdb_call_dcmd("print", addr, 0, 1, &argv);
1384 } else {
1386 * Summary line for a kshare
1387 * Don't fail the walk if any of these fail.
1389 ta = addr + OFFSETOF(smb_kshare_t, shr_name);
1390 if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
1391 mdb_readstr(name, sizeof (name), sa) <= 0)
1392 strcpy(name, "?");
1394 ta = addr + OFFSETOF(smb_kshare_t, shr_path);
1395 if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
1396 mdb_readstr(path, sizeof (path), sa) <= 0)
1397 strcpy(path, "?");
1399 mdb_printf("%-?p ", addr); /* smb_kshare_t */
1400 mdb_printf("%-16s ", name);
1401 mdb_printf("%-s", path);
1402 mdb_printf("\n");
1405 return (WALK_NEXT);
1409 * ::smbshares
1411 * dcmd - Print out smb_kshare structures.
1412 * requires addr of an smb_server_t
1414 /*ARGSUSED*/
1415 static int
1416 smb_dcmd_kshare(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1418 uint_t opts = 0;
1420 if (mdb_getopts(argc, argv,
1421 'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, &opts,
1422 NULL) != argc)
1423 return (DCMD_USAGE);
1425 if (!(flags & DCMD_ADDRSPEC))
1426 return (DCMD_USAGE);
1427 addr += OFFSETOF(smb_server_t, sv_export.e_share_avl.avl_tree);
1429 if (DCMD_HDRSPEC(flags)) {
1430 mdb_printf(
1431 "%<b>%<u>"
1432 "%-?s "
1433 "%-16s "
1434 "%-s"
1435 "%</u>%</b>\n",
1436 "smb_kshare_t", "name", "path");
1439 if (mdb_pwalk("avl", smb_kshare_cb, &opts, addr) == -1) {
1440 mdb_warn("cannot walk smb_kshare avl");
1441 return (DCMD_ERR);
1444 return (DCMD_OK);
1448 * *****************************************************************************
1449 * ******************************** smb_vfs_t **********************************
1450 * *****************************************************************************
1454 * ::smbvfs
1456 * smbvfs dcmd - Prints out smb_vfs structures.
1458 /*ARGSUSED*/
1459 static int
1460 smb_dcmd_vfs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1462 int verbose = FALSE;
1463 smb_vfs_t *sf;
1464 vnode_t *vn;
1465 char *path;
1467 if (mdb_getopts(argc, argv,
1468 'v', MDB_OPT_SETBITS, TRUE, &verbose,
1469 NULL) != argc)
1470 return (DCMD_USAGE);
1473 * If no smb_vfs address was specified on the command line, we can
1474 * print out all smb_vfs by invoking the smb_vfs walker, using
1475 * this dcmd itself as the callback.
1477 if (!(flags & DCMD_ADDRSPEC)) {
1478 if (mdb_walk_dcmd("smbvfs_walker", "smbvfs",
1479 argc, argv) == -1) {
1480 mdb_warn("failed to walk 'smb_vfs'");
1481 return (DCMD_ERR);
1483 return (DCMD_OK);
1486 if (DCMD_HDRSPEC(flags)) {
1487 mdb_printf(
1488 "%<b>%<u>"
1489 "%-?s "
1490 "%-10s "
1491 "%-16s "
1492 "%-16s"
1493 "%-s"
1494 "%</u>%</b>\n",
1495 "SMB_VFS", "REFCNT", "VFS", "VNODE", "ROOT");
1498 sf = mdb_alloc(sizeof (*sf), UM_SLEEP | UM_GC);
1499 if (mdb_vread(sf, sizeof (*sf), addr) == -1) {
1500 mdb_warn("failed to read smb_vfs at %p", addr);
1501 return (DCMD_ERR);
1504 vn = mdb_alloc(sizeof (*vn), UM_SLEEP | UM_GC);
1505 if (mdb_vread(vn, sizeof (*vn),
1506 (uintptr_t)sf->sv_rootvp) == -1) {
1507 mdb_warn("failed to read vnode at %p", sf->sv_rootvp);
1508 return (DCMD_ERR);
1511 path = mdb_zalloc(MAXPATHLEN, UM_SLEEP | UM_GC);
1512 (void) mdb_vread(path, MAXPATHLEN, (uintptr_t)vn->v_path);
1514 mdb_printf(
1515 "%-?p %-10d %-?p %-?p %-s\n", addr, sf->sv_refcnt,
1516 sf->sv_vfsp, sf->sv_rootvp, path);
1518 return (DCMD_OK);
1522 * Initialize the smb_vfs_t walker to point to the smb_export
1523 * in the specified smb_server_t instance. (no global walks)
1525 static int
1526 smb_vfs_walk_init(mdb_walk_state_t *wsp)
1528 if (wsp->walk_addr == (uintptr_t)NULL) {
1529 mdb_printf("require address of an smb_server_t\n");
1530 return (WALK_ERR);
1533 wsp->walk_addr +=
1534 OFFSETOF(smb_server_t, sv_export.e_vfs_list.ll_list);
1536 if (mdb_layered_walk("list", wsp) == -1) {
1537 mdb_warn("failed to walk list of VFS");
1538 return (WALK_ERR);
1541 return (WALK_NEXT);
1544 static int
1545 smb_vfs_walk_step(mdb_walk_state_t *wsp)
1547 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1548 wsp->walk_cbdata));
1552 * *****************************************************************************
1553 * ******************************* smb_node_t **********************************
1554 * *****************************************************************************
1557 static void
1558 smb_node_help(void)
1560 mdb_printf(
1561 "Display the contents of smb_node_t, with optional filtering.\n\n");
1562 (void) mdb_dec_indent(2);
1563 mdb_printf("%<b>OPTIONS%</b>\n");
1564 (void) mdb_inc_indent(2);
1565 mdb_printf(
1566 "-v\tDisplay verbose smb_node information\n"
1567 "-p\tDisplay the full path of the vnode associated\n"
1568 "-s\tDisplay the stack of the last 16 calls that modified the "
1569 "reference\n\tcount\n");
1573 * ::smbnode
1575 * smb_node dcmd - Print out smb_node structure.
1577 static int
1578 smb_dcmd_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1580 smb_node_t node;
1581 int rc;
1582 int verbose = FALSE;
1583 int print_full_path = FALSE;
1584 int stack_trace = FALSE;
1585 vnode_t vnode;
1586 char od_name[MAXNAMELEN];
1587 char path_name[1024];
1588 uintptr_t list_addr, oplock_addr;
1590 if (mdb_getopts(argc, argv,
1591 'v', MDB_OPT_SETBITS, TRUE, &verbose,
1592 'p', MDB_OPT_SETBITS, TRUE, &print_full_path,
1593 's', MDB_OPT_SETBITS, TRUE, &stack_trace,
1594 NULL) != argc)
1595 return (DCMD_USAGE);
1598 * If no smb_node address was specified on the command line, we can
1599 * print out all smb nodes by invoking the smb_node walker, using
1600 * this dcmd itself as the callback.
1602 if (!(flags & DCMD_ADDRSPEC)) {
1603 if (mdb_walk_dcmd("smbnode_walker", "smbnode",
1604 argc, argv) == -1) {
1605 mdb_warn("failed to walk 'smb_node'");
1606 return (DCMD_ERR);
1608 return (DCMD_OK);
1612 * If this is the first invocation of the command, print a nice
1613 * header line for the output that will follow.
1615 if (DCMD_HDRSPEC(flags)) {
1616 if (verbose) {
1617 mdb_printf("%<b>%<u>SMB node information:%</u>%</b>\n");
1618 } else {
1619 mdb_printf(
1620 "%<b>%<u>%-?s "
1621 "%-?s "
1622 "%-18s "
1623 "%-6s "
1624 "%-6s "
1625 "%-8s "
1626 "%-6s%</u>%</b>\n",
1627 "ADDR", "VP", "NODE-NAME", "OFILES", "LOCKS",
1628 "OPLOCK", "REF");
1633 * For each smb_node, we just need to read the smb_node_t struct, read
1634 * and then print out the following fields.
1636 if (mdb_vread(&node, sizeof (node), addr) == sizeof (node)) {
1637 (void) mdb_snprintf(od_name, sizeof (od_name), "%s",
1638 node.od_name);
1639 if (print_full_path) {
1640 if (mdb_vread(&vnode, sizeof (vnode_t),
1641 (uintptr_t)node.vp) == sizeof (vnode_t)) {
1642 if (mdb_readstr(path_name, sizeof (path_name),
1643 (uintptr_t)vnode.v_path) != 0) {
1644 (void) mdb_snprintf(od_name,
1645 sizeof (od_name), "N/A");
1649 if (verbose) {
1650 mdb_printf("VP: %p\n", node.vp);
1651 mdb_printf("Name: %s\n", od_name);
1652 if (print_full_path)
1653 mdb_printf("V-node Path: %s\n", path_name);
1654 mdb_printf("Ofiles: %u\n", node.n_ofile_list.ll_count);
1655 mdb_printf("Range Locks: %u\n",
1656 node.n_lock_list.ll_count);
1657 if (node.n_lock_list.ll_count != 0) {
1658 (void) mdb_inc_indent(SMB_DCMD_INDENT);
1659 list_addr = addr +
1660 OFFSETOF(smb_node_t, n_lock_list) +
1661 OFFSETOF(smb_llist_t, ll_list);
1662 if (mdb_pwalk_dcmd("list", "smblock", 0,
1663 NULL, list_addr)) {
1664 mdb_warn("failed to walk node's active"
1665 " locks");
1667 (void) mdb_dec_indent(SMB_DCMD_INDENT);
1669 if (node.n_oplock.ol_count == 0) {
1670 mdb_printf("Opportunistic Locks: 0\n");
1671 } else {
1672 oplock_addr =
1673 addr + OFFSETOF(smb_node_t, n_oplock);
1674 mdb_printf("Opportunistic Lock: %p\n",
1675 oplock_addr);
1676 rc = mdb_call_dcmd("smboplock", oplock_addr,
1677 flags, argc, argv);
1678 if (rc != DCMD_OK)
1679 return (rc);
1681 mdb_printf("Reference Count: %u\n\n", node.n_refcnt);
1682 } else {
1683 mdb_printf("%-?p %-?p %-18s %-6d %-6d %-8d %-6d ",
1684 addr, node.vp, od_name, node.n_ofile_list.ll_count,
1685 node.n_lock_list.ll_count,
1686 node.n_oplock.ol_count, node.n_refcnt);
1688 if (print_full_path)
1689 mdb_printf("\t%s\n", path_name);
1691 if (stack_trace && node.n_audit_buf) {
1692 int ctr;
1693 smb_audit_buf_node_t *anb;
1695 anb = mdb_alloc(sizeof (smb_audit_buf_node_t),
1696 UM_SLEEP | UM_GC);
1698 if (mdb_vread(anb, sizeof (*anb),
1699 (uintptr_t)node.n_audit_buf) != sizeof (*anb)) {
1700 mdb_warn("failed to read audit buffer");
1701 return (DCMD_ERR);
1703 ctr = anb->anb_max_index + 1;
1704 anb->anb_index--;
1705 anb->anb_index &= anb->anb_max_index;
1707 while (ctr) {
1708 smb_audit_record_node_t *anr;
1710 anr = anb->anb_records + anb->anb_index;
1712 if (anr->anr_depth) {
1713 char c[MDB_SYM_NAMLEN];
1714 GElf_Sym sym;
1715 int i;
1717 mdb_printf("\nRefCnt: %u\t",
1718 anr->anr_refcnt);
1720 for (i = 0;
1721 i < anr->anr_depth;
1722 i++) {
1723 if (mdb_lookup_by_addr(
1724 anr->anr_stack[i],
1725 MDB_SYM_FUZZY,
1726 c, sizeof (c),
1727 &sym) == -1) {
1728 continue;
1730 mdb_printf("%s+0x%1x",
1732 anr->anr_stack[i] -
1733 (uintptr_t)sym.st_value);
1734 ++i;
1735 break;
1738 while (i < anr->anr_depth) {
1739 if (mdb_lookup_by_addr(
1740 anr->anr_stack[i],
1741 MDB_SYM_FUZZY,
1742 c, sizeof (c),
1743 &sym) == -1) {
1744 ++i;
1745 continue;
1747 mdb_printf("\n\t\t%s+0x%1x",
1749 anr->anr_stack[i] -
1750 (uintptr_t)sym.st_value);
1751 ++i;
1753 mdb_printf("\n");
1755 anb->anb_index--;
1756 anb->anb_index &= anb->anb_max_index;
1757 ctr--;
1760 } else {
1761 mdb_warn("failed to read struct smb_node at %p", addr);
1762 return (DCMD_ERR);
1765 return (DCMD_OK);
1769 * Initialize the smb_node_t walker by reading the value of smb_node_hash_table
1770 * in the kernel's symbol table. Only global walk supported.
1772 static int
1773 smb_node_walk_init(mdb_walk_state_t *wsp)
1775 GElf_Sym sym;
1776 int i;
1777 uintptr_t node_hash_table_addr;
1779 if (wsp->walk_addr == (uintptr_t)NULL) {
1780 if (mdb_lookup_by_obj(SMBSRV_OBJNAME, "smb_node_hash_table",
1781 &sym) == -1) {
1782 mdb_warn("failed to find 'smb_node_hash_table'");
1783 return (WALK_ERR);
1785 node_hash_table_addr = (uintptr_t)sym.st_value;
1786 } else {
1787 mdb_printf("smb_node walk only supports global walks\n");
1788 return (WALK_ERR);
1791 for (i = 0; i < SMBND_HASH_MASK + 1; i++) {
1792 wsp->walk_addr = node_hash_table_addr +
1793 (i * sizeof (smb_llist_t)) + OFFSETOF(smb_llist_t, ll_list);
1794 if (mdb_layered_walk("list", wsp) == -1) {
1795 mdb_warn("failed to walk 'list'");
1796 return (WALK_ERR);
1800 return (WALK_NEXT);
1803 static int
1804 smb_node_walk_step(mdb_walk_state_t *wsp)
1806 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1807 wsp->walk_cbdata));
1811 * *****************************************************************************
1812 * ****************************** smb_lock_t ***********************************
1813 * *****************************************************************************
1816 static int
1817 smb_lock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1819 smb_lock_t lock;
1820 int verbose = FALSE;
1821 uintptr_t list_addr;
1822 char *lock_type;
1824 if (mdb_getopts(argc, argv,
1825 'v', MDB_OPT_SETBITS, TRUE, &verbose,
1826 NULL) != argc)
1827 return (DCMD_USAGE);
1830 * An smb_lock_t address must be specified.
1832 if (!(flags & DCMD_ADDRSPEC))
1833 return (DCMD_USAGE);
1836 * If this is the first invocation of the command, print a nice
1837 * header line for the output that will follow.
1839 if (DCMD_HDRSPEC(flags)) {
1840 if (verbose)
1841 mdb_printf("SMB lock information:\n\n");
1842 else
1843 mdb_printf("%<u>%-?s %4s %16s %8s %9s%</u>\n",
1844 "Locks: ", "TYPE", "START", "LENGTH",
1845 "CONFLICTS");
1848 if (mdb_vread(&lock, sizeof (lock), addr) == sizeof (lock)) {
1849 switch (lock.l_type) {
1850 case SMB_LOCK_TYPE_READWRITE:
1851 lock_type = "RW";
1852 break;
1853 case SMB_LOCK_TYPE_READONLY:
1854 lock_type = "RO";
1855 break;
1856 default:
1857 lock_type = "N/A";
1858 break;
1860 if (verbose) {
1861 mdb_printf("Type :\t%s (%u)\n",
1862 lock_type, lock.l_type);
1863 mdb_printf("Start :\t%llx\n",
1864 lock.l_start);
1865 mdb_printf("Length :\t%lx\n",
1866 lock.l_length);
1867 mdb_printf("Session :\t%p\n",
1868 lock.l_session);
1869 mdb_printf("File :\t%p\n",
1870 lock.l_file);
1871 mdb_printf("User ID :\t%u\n",
1872 lock.l_uid);
1873 mdb_printf("Process ID :\t%u\n",
1874 lock.l_pid);
1875 mdb_printf("Conflicts :\t%u\n",
1876 lock.l_conflict_list.sl_count);
1877 if (lock.l_conflict_list.sl_count != 0) {
1878 (void) mdb_inc_indent(SMB_DCMD_INDENT);
1879 list_addr = addr +
1880 OFFSETOF(smb_lock_t, l_conflict_list) +
1881 OFFSETOF(smb_slist_t, sl_list);
1882 if (mdb_pwalk_dcmd("list", "smb_lock",
1883 0, NULL, list_addr)) {
1884 mdb_warn("failed to walk conflict "
1885 "locks ");
1887 (void) mdb_dec_indent(SMB_DCMD_INDENT);
1889 mdb_printf("Blocked by :\t%p\n",
1890 lock.l_blocked_by);
1891 mdb_printf("Flags :\t0x%x\n",
1892 lock.l_flags);
1893 mdb_printf("\n");
1894 } else {
1895 mdb_printf("%?p %4s %16llx %08lx %9x", addr,
1896 lock_type, lock.l_start, lock.l_length,
1897 lock.l_conflict_list.sl_count);
1899 } else {
1900 mdb_warn("failed to read struct smb_request at %p", addr);
1901 return (DCMD_ERR);
1904 return (DCMD_OK);
1908 * *****************************************************************************
1909 * ************************** smb_oplock_grant_t *******************************
1910 * *****************************************************************************
1912 /*ARGSUSED*/
1913 static int
1914 smb_oplock_grant(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1916 smb_oplock_grant_t grant;
1917 char *level;
1919 if (!(flags & DCMD_ADDRSPEC))
1920 return (DCMD_USAGE);
1923 * If this is the first invocation of the command, print a nice
1924 * header line for the output that will follow.
1926 if (DCMD_HDRSPEC(flags)) {
1927 mdb_printf("%<u>%-16s %-10s %-16s%</u>\n",
1928 "Grants:", "LEVEL", "OFILE");
1931 if (mdb_vread(&grant, sizeof (grant), addr) == sizeof (grant)) {
1932 switch (grant.og_level) {
1933 case SMB_OPLOCK_EXCLUSIVE:
1934 level = "EXCLUSIVE";
1935 break;
1936 case SMB_OPLOCK_BATCH:
1937 level = "BATCH";
1938 break;
1939 case SMB_OPLOCK_LEVEL_II:
1940 level = "LEVEL_II";
1941 break;
1942 default:
1943 level = "UNKNOWN";
1944 break;
1947 mdb_printf("%-16p %-10s %-16p", addr, level, grant.og_ofile);
1949 return (DCMD_OK);
1953 * *****************************************************************************
1954 * ***************************** smb_oplock_t **********************************
1955 * *****************************************************************************
1957 /*ARGSUSED*/
1958 static int
1959 smb_oplock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1961 smb_oplock_t oplock;
1962 uintptr_t list_addr;
1964 if (!(flags & DCMD_ADDRSPEC))
1965 return (DCMD_USAGE);
1967 if (mdb_vread(&oplock, sizeof (oplock), addr) != sizeof (oplock)) {
1968 mdb_warn("failed to read struct smb_oplock at %p", addr);
1969 return (DCMD_ERR);
1972 if (oplock.ol_count == 0)
1973 return (DCMD_OK);
1975 (void) mdb_inc_indent(SMB_DCMD_INDENT);
1976 switch (oplock.ol_break) {
1977 case SMB_OPLOCK_BREAK_TO_NONE:
1978 mdb_printf("Break Pending: BREAK_TO_NONE\n");
1979 break;
1980 case SMB_OPLOCK_BREAK_TO_LEVEL_II:
1981 mdb_printf(
1982 "Break Pending: BREAK_TO_LEVEL_II\n");
1983 break;
1984 default:
1985 break;
1988 list_addr = addr + OFFSETOF(smb_oplock_t, ol_grants);
1990 if (mdb_pwalk_dcmd("list", "smboplockgrant",
1991 argc, argv, list_addr)) {
1992 mdb_warn("failed to walk oplock grants");
1995 (void) mdb_dec_indent(SMB_DCMD_INDENT);
1997 return (DCMD_OK);
2001 * ::smbstat
2003 * Prints SMB requests statistics.
2005 /*ARGSUSED*/
2006 static int
2007 smb_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2009 smb_server_t *sv;
2011 if (!(flags & DCMD_ADDRSPEC))
2012 return (DCMD_USAGE);
2014 sv = mdb_alloc(sizeof (*sv), UM_SLEEP | UM_GC);
2015 if (mdb_vread(sv, sizeof (*sv), addr) == -1) {
2016 mdb_warn("failed to read server object at %p", addr);
2017 return (DCMD_ERR);
2019 if (sv->sv_magic != SMB_SERVER_MAGIC) {
2020 mdb_warn("not an smb_server_t (%p)>", addr);
2021 return (DCMD_ERR);
2023 mdb_printf(
2024 "\n%<b> nbt tcp users trees files pipes%</b>\n"
2025 "%5d %5d %5d %5d %5d %5d\n",
2026 sv->sv_nbt_sess,
2027 sv->sv_tcp_sess,
2028 sv->sv_users,
2029 sv->sv_trees,
2030 sv->sv_files,
2031 sv->sv_pipes);
2033 return (DCMD_OK);
2037 * *****************************************************************************
2038 * ******************************** smb_ace_t **********************************
2039 * *****************************************************************************
2041 static const ace_type_entry_t ace_types[ACE_TYPE_TABLEN] =
2043 ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_ACE_TYPE),
2044 ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_ACE_TYPE),
2045 ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_ACE_TYPE),
2046 ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_ACE_TYPE),
2047 ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE),
2048 ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE),
2049 ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_OBJECT_ACE_TYPE),
2050 ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE),
2051 ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE),
2052 ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE),
2053 ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE),
2054 ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE),
2055 ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE),
2056 ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE),
2057 ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE),
2058 ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE),
2059 ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE),
2060 ACE_TYPE_ENTRY(0x11),
2061 ACE_TYPE_ENTRY(0x12),
2062 ACE_TYPE_ENTRY(0x13),
2063 ACE_TYPE_ENTRY(0x14),
2064 ACE_TYPE_ENTRY(0x15),
2065 ACE_TYPE_ENTRY(0x16),
2066 ACE_TYPE_ENTRY(0x17),
2067 ACE_TYPE_ENTRY(0x18),
2068 ACE_TYPE_ENTRY(0x19),
2069 ACE_TYPE_ENTRY(0x1A),
2070 ACE_TYPE_ENTRY(0x1B),
2071 ACE_TYPE_ENTRY(0x1C),
2072 ACE_TYPE_ENTRY(0x1D),
2073 ACE_TYPE_ENTRY(0x1E),
2074 ACE_TYPE_ENTRY(0x1F)
2077 static const mdb_bitmask_t ace_flag_bits[] = {
2078 { "OBJECT_INHERIT_ACE", OBJECT_INHERIT_ACE, OBJECT_INHERIT_ACE },
2079 { "CONTAINER_INHERIT_ACE", CONTAINER_INHERIT_ACE,
2080 CONTAINER_INHERIT_ACE },
2081 { "NO_PROPOGATE_INHERIT_ACE", NO_PROPOGATE_INHERIT_ACE,
2082 NO_PROPOGATE_INHERIT_ACE },
2083 { "INHERIT_ONLY_ACE", INHERIT_ONLY_ACE, INHERIT_ONLY_ACE },
2084 { "INHERITED_ACE", INHERITED_ACE, INHERITED_ACE },
2085 { "SUCCESSFUL_ACCESS_ACE_FLAG", SUCCESSFUL_ACCESS_ACE_FLAG,
2086 SUCCESSFUL_ACCESS_ACE_FLAG },
2087 { "FAILED_ACCESS_ACE_FLAG", FAILED_ACCESS_ACE_FLAG,
2088 FAILED_ACCESS_ACE_FLAG },
2089 { NULL, 0, 0 }
2093 * ::smbace
2095 static int
2096 smb_ace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2098 smb_ace_t ace;
2099 int verbose = FALSE;
2100 const char *ptr;
2101 int rc;
2103 if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2104 NULL) != argc)
2105 return (DCMD_USAGE);
2108 * An smb_ace address is required.
2110 if (!(flags & DCMD_ADDRSPEC))
2111 return (DCMD_USAGE);
2113 if (mdb_vread(&ace, sizeof (ace), addr) != sizeof (ace)) {
2114 mdb_warn("failed to read struct smb_ace at %p", addr);
2115 return (DCMD_ERR);
2118 if (verbose) {
2119 if (ace.se_hdr.se_type < ACE_TYPE_TABLEN)
2120 ptr = ace_types[ace.se_hdr.se_type].ace_type_sting;
2121 else
2122 ptr = "Unknown";
2124 mdb_printf("ACE Type: 0x%02x (%s)\n", ace.se_hdr.se_type, ptr);
2125 mdb_printf("ACE Flags: %b\n", (int)ace.se_hdr.se_flags,
2126 ace_flag_bits);
2127 mdb_printf("ACE Wire Size: 0x%04x\n", ace.se_hdr.se_bsize);
2128 mdb_printf("ACE Mask: 0x%08x\n", ace.se_mask);
2129 mdb_printf("ACE SID: ");
2130 } else {
2131 if (DCMD_HDRSPEC(flags))
2132 mdb_printf(
2133 "%<b>%<u>%?-s %-4s %-4s %-8s %s%</u>%</b>\n",
2134 "ACE", "TYPE", "FLAGS", "MASK", "SID");
2135 mdb_printf("%?p 0x%02x 0x%02x 0x%08x ", addr,
2136 ace.se_hdr.se_type, ace.se_hdr.se_flags, ace.se_mask);
2138 rc = smb_sid_print((uintptr_t)ace.se_sid);
2139 mdb_printf("\n");
2140 return (rc);
2143 static int
2144 smb_ace_walk_init(mdb_walk_state_t *wsp)
2146 if (wsp->walk_addr == (uintptr_t)NULL) {
2147 mdb_printf("smb_ace walk only supports local walks\n");
2148 return (WALK_ERR);
2151 wsp->walk_addr += OFFSETOF(smb_acl_t, sl_sorted);
2153 if (mdb_layered_walk("list", wsp) == -1) {
2154 mdb_warn("failed to walk list of ACEs");
2155 return (WALK_ERR);
2158 return (WALK_NEXT);
2161 static int
2162 smb_ace_walk_step(mdb_walk_state_t *wsp)
2164 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
2165 wsp->walk_cbdata));
2169 * *****************************************************************************
2170 * ******************************** smb_acl_t **********************************
2171 * *****************************************************************************
2175 * ::smbacl
2177 static int
2178 smb_acl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2180 smb_acl_t acl;
2182 /* An smb_acl address is required. */
2183 if (!(flags & DCMD_ADDRSPEC))
2184 return (DCMD_USAGE);
2186 if (mdb_vread(&acl, sizeof (acl), addr) != sizeof (acl)) {
2187 mdb_warn("failed to read struct smb_acl at %p", addr);
2188 return (DCMD_ERR);
2191 mdb_printf("ACL Revision: %d\n", acl.sl_revision);
2192 mdb_printf("ACL Size on Wire: %d\n", acl.sl_bsize);
2193 mdb_printf("ACL Number of ACEs: %d\n", acl.sl_acecnt);
2195 (void) mdb_inc_indent(SMB_DCMD_INDENT);
2196 if (mdb_pwalk_dcmd("smbace_walker", "smbace", argc, argv, addr)) {
2197 (void) mdb_dec_indent(SMB_DCMD_INDENT);
2198 mdb_warn("failed to walk list of ACEs for ACL %p", addr);
2199 return (DCMD_ERR);
2201 (void) mdb_dec_indent(SMB_DCMD_INDENT);
2202 return (DCMD_OK);
2206 * *****************************************************************************
2207 * ********************************* smb_sd_t **********************************
2208 * *****************************************************************************
2212 * ::smbsd
2214 static int
2215 smb_sd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2217 smb_sd_t sd;
2218 int rc;
2221 * An smb_sid address is required.
2223 if (!(flags & DCMD_ADDRSPEC))
2224 return (DCMD_USAGE);
2226 if (mdb_vread(&sd, sizeof (sd), addr) != sizeof (sd)) {
2227 mdb_warn("failed to read struct smb_sd at %p", addr);
2228 return (DCMD_ERR);
2231 mdb_printf("SD Revision: %d\n", sd.sd_revision);
2232 mdb_printf("SD Control: %04x\n", sd.sd_control);
2233 if (sd.sd_control & SE_OWNER_DEFAULTED)
2234 mdb_printf("\t SE_OWNER_DEFAULTED\n");
2235 if (sd.sd_control & SE_GROUP_DEFAULTED)
2236 mdb_printf("\t SE_GROUP_DEFAULTED\n");
2237 if (sd.sd_control & SE_DACL_PRESENT)
2238 mdb_printf("\t SE_DACL_PRESENT\n");
2239 if (sd.sd_control & SE_DACL_DEFAULTED)
2240 mdb_printf("\t SE_DACL_DEFAULTED\n");
2241 if (sd.sd_control & SE_SACL_PRESENT)
2242 mdb_printf("\t SE_SACL_PRESENT\n");
2243 if (sd.sd_control & SE_SACL_DEFAULTED)
2244 mdb_printf("\t SE_SACL_DEFAULTED\n");
2245 if (sd.sd_control & SE_DACL_AUTO_INHERIT_REQ)
2246 mdb_printf("\t SE_DACL_AUTO_INHERIT_REQ\n");
2247 if (sd.sd_control & SE_SACL_AUTO_INHERIT_REQ)
2248 mdb_printf("\t SE_SACL_AUTO_INHERIT_REQ\n");
2249 if (sd.sd_control & SE_DACL_AUTO_INHERITED)
2250 mdb_printf("\t SE_DACL_AUTO_INHERITED\n");
2251 if (sd.sd_control & SE_SACL_AUTO_INHERITED)
2252 mdb_printf("\t SE_SACL_AUTO_INHERITED\n");
2253 if (sd.sd_control & SE_DACL_PROTECTED)
2254 mdb_printf("\t SE_DACL_PROTECTED\n");
2255 if (sd.sd_control & SE_SACL_PROTECTED)
2256 mdb_printf("\t SE_SACL_PROTECTED\n");
2257 if (sd.sd_control & SE_SELF_RELATIVE)
2258 mdb_printf("\t SE_SELF_RELATIVE\n");
2260 mdb_printf("SID of Owner: ");
2261 rc = smb_sid_print((uintptr_t)sd.sd_owner);
2262 if (rc != DCMD_OK)
2263 return (rc);
2264 mdb_printf("\nSID of Group: ");
2265 rc = smb_sid_print((uintptr_t)sd.sd_group);
2266 if (rc != DCMD_OK)
2267 return (rc);
2268 mdb_printf("\n");
2270 if (sd.sd_control & SE_SACL_PRESENT && sd.sd_sacl) {
2271 mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
2272 (void) mdb_inc_indent(SMB_DCMD_INDENT);
2273 rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_sacl, flags,
2274 argc, argv);
2275 (void) mdb_dec_indent(SMB_DCMD_INDENT);
2276 if (rc != DCMD_OK)
2277 return (rc);
2279 if (sd.sd_control & SE_DACL_PRESENT && sd.sd_dacl) {
2280 mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
2281 (void) mdb_inc_indent(SMB_DCMD_INDENT);
2282 rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_dacl, flags,
2283 argc, argv);
2284 (void) mdb_dec_indent(SMB_DCMD_INDENT);
2285 if (rc != DCMD_OK)
2286 return (rc);
2289 return (DCMD_OK);
2293 * *****************************************************************************
2294 * ********************************* smb_sid_t *********************************
2295 * *****************************************************************************
2299 * ::smbsid
2301 /*ARGSUSED*/
2302 static int
2303 smb_sid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2306 * An smb_sid address is required.
2308 if (!(flags & DCMD_ADDRSPEC))
2309 return (DCMD_USAGE);
2311 return (smb_sid_print(addr));
2315 * smb_sid_print
2317 static int
2318 smb_sid_print(uintptr_t addr)
2320 smb_sid_t sid;
2321 smb_sid_t *psid;
2322 size_t sid_size;
2323 int i;
2324 uint64_t authority;
2326 sid_size = OFFSETOF(smb_sid_t, sid_subauth);
2328 if (mdb_vread(&sid, sid_size, addr) != sid_size) {
2329 mdb_warn("failed to read struct smb_sid at %p", addr);
2330 return (DCMD_ERR);
2333 sid_size += sid.sid_subauthcnt * sizeof (sid.sid_subauth[0]);
2335 psid = mdb_zalloc(sid_size, UM_SLEEP | UM_GC);
2336 if (mdb_vread(psid, sid_size, addr) != sid_size) {
2337 mdb_warn("failed to read struct smb_sid at %p", addr);
2338 return (DCMD_ERR);
2341 mdb_printf("S-%d", psid->sid_revision);
2342 authority = 0;
2343 for (i = 0; i < NT_SID_AUTH_MAX; i++) {
2344 authority += ((uint64_t)psid->sid_authority[i]) <<
2345 (8 * (NT_SID_AUTH_MAX - 1) - i);
2347 mdb_printf("-%ll", authority);
2349 for (i = 0; i < psid->sid_subauthcnt; i++)
2350 mdb_printf("-%d", psid->sid_subauth[i]);
2352 return (DCMD_OK);
2356 * *****************************************************************************
2357 * ********************************* smb_fssd_t ********************************
2358 * *****************************************************************************
2362 * ::smbfssd
2364 static int
2365 smb_fssd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2367 smb_fssd_t fssd;
2368 int rc;
2371 * An smb_fssd address is required.
2373 if (!(flags & DCMD_ADDRSPEC))
2374 return (DCMD_USAGE);
2376 if (mdb_vread(&fssd, sizeof (fssd), addr) != sizeof (fssd)) {
2377 mdb_warn("failed to read struct smb_fssd at %p", addr);
2378 return (DCMD_ERR);
2381 mdb_printf("FSSD secinfo: 0x%x\n", fssd.sd_secinfo);
2382 if (fssd.sd_secinfo & SMB_OWNER_SECINFO)
2383 mdb_printf("FSSD uid: %d\n", fssd.sd_uid);
2384 if (fssd.sd_secinfo & SMB_GROUP_SECINFO)
2385 mdb_printf("FSSD gid: %d\n", fssd.sd_gid);
2386 if (fssd.sd_secinfo & SMB_SACL_SECINFO && fssd.sd_zsacl) {
2387 mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
2388 (void) mdb_inc_indent(SMB_DCMD_INDENT);
2389 rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zsacl, flags,
2390 argc, argv);
2391 (void) mdb_dec_indent(SMB_DCMD_INDENT);
2392 if (rc != DCMD_OK)
2393 return (rc);
2395 if (fssd.sd_secinfo & SMB_DACL_SECINFO && fssd.sd_zdacl) {
2396 mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
2397 (void) mdb_inc_indent(SMB_DCMD_INDENT);
2398 rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zdacl, flags,
2399 argc, argv);
2400 (void) mdb_dec_indent(SMB_DCMD_INDENT);
2401 if (rc != DCMD_OK)
2402 return (rc);
2405 return (DCMD_OK);
2409 * *****************************************************************************
2410 * **************************** Utility Funcions *******************************
2411 * *****************************************************************************
2415 * smb_dcmd_getopt
2417 * This function analyzes the arguments passed in and sets the bit corresponding
2418 * to the options found in the opts variable.
2420 * Return Value
2422 * -1 An error occured during the decoding
2423 * 0 The decoding was successful
2425 static int
2426 smb_dcmd_getopt(uint_t *opts, int argc, const mdb_arg_t *argv)
2428 *opts = 0;
2430 if (mdb_getopts(argc, argv,
2431 's', MDB_OPT_SETBITS, SMB_OPT_SERVER, opts,
2432 'e', MDB_OPT_SETBITS, SMB_OPT_SESSION, opts,
2433 'r', MDB_OPT_SETBITS, SMB_OPT_REQUEST, opts,
2434 'u', MDB_OPT_SETBITS, SMB_OPT_USER, opts,
2435 't', MDB_OPT_SETBITS, SMB_OPT_TREE, opts,
2436 'f', MDB_OPT_SETBITS, SMB_OPT_OFILE, opts,
2437 'd', MDB_OPT_SETBITS, SMB_OPT_ODIR, opts,
2438 'w', MDB_OPT_SETBITS, SMB_OPT_WALK, opts,
2439 'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, opts,
2440 NULL) != argc)
2441 return (-1);
2443 return (0);
2447 * smb_dcmd_setopt
2449 * This function set the arguments corresponding to the bits set in opts.
2451 * Return Value
2453 * Number of arguments set.
2455 static int
2456 smb_dcmd_setopt(uint_t opts, int max_argc, mdb_arg_t *argv)
2458 int i;
2459 int argc = 0;
2461 for (i = 0; i < SMB_MDB_MAX_OPTS; i++) {
2462 if ((opts & smb_opts[i].o_value) && (argc < max_argc)) {
2463 argv->a_type = MDB_TYPE_STRING;
2464 argv->a_un.a_str = smb_opts[i].o_name;
2465 argc++;
2466 argv++;
2469 return (argc);
2473 * smb_obj_expand
2475 static int
2476 smb_obj_expand(uintptr_t addr, uint_t opts, const smb_exp_t *x, ulong_t indent)
2478 int rc = 0;
2479 int argc;
2480 mdb_arg_t argv[SMB_MDB_MAX_OPTS];
2482 argc = smb_dcmd_setopt(opts | SMB_OPT_WALK, SMB_MDB_MAX_OPTS, argv);
2484 (void) mdb_inc_indent(indent);
2485 while (x->ex_dcmd) {
2486 if (x->ex_mask & opts) {
2487 rc = mdb_pwalk_dcmd("list", x->ex_dcmd, argc, argv,
2488 addr + x->ex_offset);
2490 if (rc) {
2491 mdb_warn("failed to walk the list of %s in %p",
2492 x->ex_name, addr + x->ex_offset);
2493 break;
2496 x++;
2498 (void) mdb_dec_indent(indent);
2499 return (rc);
2503 * smb_obj_list
2505 * Function called by the DCMDs when no address is provided. It expands the
2506 * tree under the object type associated with the calling DCMD (based on the
2507 * flags passed in).
2509 * Return Value
2511 * DCMD_OK
2512 * DCMD_ERR
2514 static int
2515 smb_obj_list(const char *name, uint_t opts, uint_t flags)
2517 int argc;
2518 mdb_arg_t argv[SMB_MDB_MAX_OPTS];
2520 argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, argv);
2522 if (mdb_call_dcmd("smblist", 0, flags, argc, argv)) {
2523 mdb_warn("failed to list %s", name);
2524 return (DCMD_ERR);
2526 return (DCMD_OK);
2529 static int
2530 smb_worker_findstack(uintptr_t addr)
2532 char cmd[80];
2533 mdb_arg_t cmdarg;
2535 mdb_inc_indent(2);
2536 mdb_snprintf(cmd, sizeof (cmd), "<.$c%d", 16);
2537 cmdarg.a_type = MDB_TYPE_STRING;
2538 cmdarg.a_un.a_str = cmd;
2539 (void) mdb_call_dcmd("findstack", addr, DCMD_ADDRSPEC, 1, &cmdarg);
2540 mdb_dec_indent(2);
2541 mdb_printf("\n");
2542 return (DCMD_OK);