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 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 #include <sys/mdb_modapi.h>
29 #include <sys/types.h>
30 #include <sys/refstr_impl.h>
31 #include <sys/vnode.h>
32 #include <sys/vfs.h>
33
34 #include <smbfs/smbfs.h>
35 #include <smbfs/smbfs_node.h>
36
37 #define OPT_VERBOSE 0x0001 /* Be [-v]erbose in dcmd's */
38
39 /*
40 * This macro lets us easily use both sizeof (typename)
41 * and the string-ified typename for the error message.
42 */
43 #define SMBFS_OBJ_FETCH(obj_addr, obj_type, dest, err) \
44 if (mdb_vread(dest, sizeof (obj_type), ((uintptr_t)obj_addr)) \
45 != sizeof (obj_type)) { \
46 mdb_warn("error reading "#obj_type" at %p", obj_addr); \
47 return (err); \
48 }
49
132
133 cbd = mdb_zalloc(sizeof (*cbd), UM_SLEEP | UM_GC);
134
135 /*
136 * Get the ops address here, so things work
137 * even if the smbfs module is loaded later
138 * than this mdb module.
139 */
140 if (mdb_readvar(&cbd->vfsops, "smbfs_vfsops") == -1) {
141 mdb_warn("failed to find 'smbfs_vfsops'\n");
142 return (DCMD_ERR);
143 }
144
145 if (mdb_getopts(argc, argv,
146 'v', MDB_OPT_SETBITS, OPT_VERBOSE, &cbd->flags,
147 NULL) != argc) {
148 return (DCMD_USAGE);
149 }
150
151 if (!(flags & DCMD_ADDRSPEC)) {
152 if (mdb_walk("genunix`vfs", smbfs_vfs_cb, cbd)
153 == -1) {
154 mdb_warn("can't walk smbfs vfs");
155 return (DCMD_ERR);
156 }
157 return (DCMD_OK);
158 }
159
160 vfs = mdb_alloc(sizeof (*vfs), UM_SLEEP | UM_GC);
161 SMBFS_OBJ_FETCH(addr, vfs_t, vfs, DCMD_ERR);
162 smbfs_vfs_cb(addr, vfs, cbd);
163 return (DCMD_OK);
164 }
165
166 void
167 smbfs_vfs_help(void)
168 {
169 mdb_printf(
170 "Display addresses of the mounted smbfs structures\n"
171 "and the pathname of the mountpoint\n"
172 "\nOptions:\n"
221
222 int
223 smbfs_node_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
224 {
225 smbfs_node_cbdata_t *cbd;
226
227 cbd = mdb_zalloc(sizeof (*cbd), UM_SLEEP | UM_GC);
228
229 if (mdb_getopts(argc, argv,
230 'v', MDB_OPT_SETBITS, OPT_VERBOSE, &cbd->flags,
231 NULL) != argc) {
232 return (DCMD_USAGE);
233 }
234
235 if (!(flags & DCMD_ADDRSPEC)) {
236 mdb_warn("expect an smbmntinfo_t addr");
237 return (DCMD_USAGE);
238 }
239 addr += OFFSETOF(smbmntinfo_t, smi_hash_avl);
240
241 if (mdb_pwalk("genunix`avl", smbfs_node_cb, cbd, addr) == -1) {
242 mdb_warn("cannot walk smbfs nodes");
243 return (DCMD_ERR);
244 }
245
246 return (DCMD_OK);
247 }
248
249 void
250 smbfs_node_help(void)
251 {
252 mdb_printf("Options:\n"
253 " -v be verbose when displaying smbnodes\n");
254 }
255
256 static const mdb_dcmd_t dcmds[] = {
257 {
258 "smbfs_vfs", "?[-v]",
259 "show smbfs-mounted vfs structs",
260 smbfs_vfs_dcmd, smbfs_vfs_help
261 },
262 {
263 "smbfs_node", "?[-v]",
264 "given an smbmntinfo_t, list smbnodes",
265 smbfs_node_dcmd, smbfs_node_help
266 },
267 {NULL}
268 };
269
270 static const mdb_walker_t walkers[] = {
271 {NULL}
272 };
273
274 static const mdb_modinfo_t modinfo = {
275 MDB_API_VERSION,
276 dcmds,
277 walkers
278 };
279
280 const mdb_modinfo_t *
281 _mdb_init(void)
282 {
283 return (&modinfo);
284 }
|
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 /*
23 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 #include <sys/types.h>
29 #include <sys/mdb_modapi.h>
30
31 #ifdef _USER
32 #include "../genunix/avl.h"
33 #define _FAKE_KERNEL
34 #endif
35
36 #include <sys/refstr_impl.h>
37 #include <sys/vnode.h>
38 #include <sys/vfs.h>
39
40 #include <smbfs/smbfs.h>
41 #include <smbfs/smbfs_node.h>
42
43 #define OPT_VERBOSE 0x0001 /* Be [-v]erbose in dcmd's */
44
45 /*
46 * This macro lets us easily use both sizeof (typename)
47 * and the string-ified typename for the error message.
48 */
49 #define SMBFS_OBJ_FETCH(obj_addr, obj_type, dest, err) \
50 if (mdb_vread(dest, sizeof (obj_type), ((uintptr_t)obj_addr)) \
51 != sizeof (obj_type)) { \
52 mdb_warn("error reading "#obj_type" at %p", obj_addr); \
53 return (err); \
54 }
55
138
139 cbd = mdb_zalloc(sizeof (*cbd), UM_SLEEP | UM_GC);
140
141 /*
142 * Get the ops address here, so things work
143 * even if the smbfs module is loaded later
144 * than this mdb module.
145 */
146 if (mdb_readvar(&cbd->vfsops, "smbfs_vfsops") == -1) {
147 mdb_warn("failed to find 'smbfs_vfsops'\n");
148 return (DCMD_ERR);
149 }
150
151 if (mdb_getopts(argc, argv,
152 'v', MDB_OPT_SETBITS, OPT_VERBOSE, &cbd->flags,
153 NULL) != argc) {
154 return (DCMD_USAGE);
155 }
156
157 if (!(flags & DCMD_ADDRSPEC)) {
158 if (mdb_walk("vfs", smbfs_vfs_cb, cbd)
159 == -1) {
160 mdb_warn("can't walk smbfs vfs");
161 return (DCMD_ERR);
162 }
163 return (DCMD_OK);
164 }
165
166 vfs = mdb_alloc(sizeof (*vfs), UM_SLEEP | UM_GC);
167 SMBFS_OBJ_FETCH(addr, vfs_t, vfs, DCMD_ERR);
168 smbfs_vfs_cb(addr, vfs, cbd);
169 return (DCMD_OK);
170 }
171
172 void
173 smbfs_vfs_help(void)
174 {
175 mdb_printf(
176 "Display addresses of the mounted smbfs structures\n"
177 "and the pathname of the mountpoint\n"
178 "\nOptions:\n"
227
228 int
229 smbfs_node_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
230 {
231 smbfs_node_cbdata_t *cbd;
232
233 cbd = mdb_zalloc(sizeof (*cbd), UM_SLEEP | UM_GC);
234
235 if (mdb_getopts(argc, argv,
236 'v', MDB_OPT_SETBITS, OPT_VERBOSE, &cbd->flags,
237 NULL) != argc) {
238 return (DCMD_USAGE);
239 }
240
241 if (!(flags & DCMD_ADDRSPEC)) {
242 mdb_warn("expect an smbmntinfo_t addr");
243 return (DCMD_USAGE);
244 }
245 addr += OFFSETOF(smbmntinfo_t, smi_hash_avl);
246
247 if (mdb_pwalk("avl", smbfs_node_cb, cbd, addr) == -1) {
248 mdb_warn("cannot walk smbfs nodes");
249 return (DCMD_ERR);
250 }
251
252 return (DCMD_OK);
253 }
254
255 void
256 smbfs_node_help(void)
257 {
258 mdb_printf("Options:\n"
259 " -v be verbose when displaying smbnodes\n");
260 }
261
262 static const mdb_dcmd_t dcmds[] = {
263 {
264 "smbfs_vfs", "?[-v]",
265 "show smbfs-mounted vfs structs",
266 smbfs_vfs_dcmd, smbfs_vfs_help
267 },
268 {
269 "smbfs_node", "?[-v]",
270 "given an smbmntinfo_t, list smbnodes",
271 smbfs_node_dcmd, smbfs_node_help
272 },
273 {NULL}
274 };
275
276 #ifdef _USER
277 /*
278 * Sadly, can't just compile ../genunix/vfs.c with this since
279 * it has become a catch-all for FS-specific headers etc.
280 */
281 int
282 vfs_walk_init(mdb_walk_state_t *wsp)
283 {
284 if (wsp->walk_addr == NULL &&
285 mdb_readvar(&wsp->walk_addr, "rootvfs") == -1) {
286 mdb_warn("failed to read 'rootvfs'");
287 return (WALK_ERR);
288 }
289
290 wsp->walk_data = (void *)wsp->walk_addr;
291 return (WALK_NEXT);
292 }
293
294 int
295 vfs_walk_step(mdb_walk_state_t *wsp)
296 {
297 vfs_t vfs;
298 int status;
299
300 if (mdb_vread(&vfs, sizeof (vfs), wsp->walk_addr) == -1) {
301 mdb_warn("failed to read vfs_t at %p", wsp->walk_addr);
302 return (WALK_DONE);
303 }
304
305 status = wsp->walk_callback(wsp->walk_addr, &vfs, wsp->walk_cbdata);
306
307 if (vfs.vfs_next == wsp->walk_data)
308 return (WALK_DONE);
309
310 wsp->walk_addr = (uintptr_t)vfs.vfs_next;
311
312 return (status);
313 }
314 #endif // _USER
315
316 static const mdb_walker_t walkers[] = {
317 #ifdef _USER
318 /* from avl.c */
319 { AVL_WALK_NAME, AVL_WALK_DESC,
320 avl_walk_init, avl_walk_step, avl_walk_fini },
321 /* from vfs.c */
322 { "vfs", "walk file system list",
323 vfs_walk_init, vfs_walk_step },
324 #endif // _USER
325 {NULL}
326 };
327
328
329 static const mdb_modinfo_t modinfo = {
330 MDB_API_VERSION,
331 dcmds,
332 walkers
333 };
334
335 const mdb_modinfo_t *
336 _mdb_init(void)
337 {
338 return (&modinfo);
339 }
|