Print this page
NEX-16818 Add fksmbcl development tool
NEX-17264 SMB client test tp_smbutil_013 fails after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (fix ref leaks)
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/mdb/common/modules/smbfs/smbfs.c
+++ new/usr/src/cmd/mdb/common/modules/smbfs/smbfs.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 - * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
24 24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 25 * Use is subject to license terms.
26 26 */
27 27
28 -#include <sys/mdb_modapi.h>
29 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 +
30 36 #include <sys/refstr_impl.h>
31 37 #include <sys/vnode.h>
32 38 #include <sys/vfs.h>
33 39
34 40 #include <smbfs/smbfs.h>
35 41 #include <smbfs/smbfs_node.h>
36 42
37 43 #define OPT_VERBOSE 0x0001 /* Be [-v]erbose in dcmd's */
38 44
39 45 /*
40 46 * This macro lets us easily use both sizeof (typename)
41 47 * and the string-ified typename for the error message.
42 48 */
43 49 #define SMBFS_OBJ_FETCH(obj_addr, obj_type, dest, err) \
44 50 if (mdb_vread(dest, sizeof (obj_type), ((uintptr_t)obj_addr)) \
45 51 != sizeof (obj_type)) { \
46 52 mdb_warn("error reading "#obj_type" at %p", obj_addr); \
47 53 return (err); \
48 54 }
49 55
50 56 /*
51 57 * We need to read in a private copy
52 58 * of every string we want to print out.
53 59 */
54 60 void
55 61 print_str(uintptr_t addr)
56 62 {
57 63 char buf[64];
58 64 int len, mx = sizeof (buf) - 4;
59 65
60 66 if ((len = mdb_readstr(buf, sizeof (buf), addr)) <= 0) {
61 67 mdb_printf(" (%p)", addr);
62 68 } else {
63 69 if (len > mx)
64 70 strcpy(&buf[mx], "...");
65 71 mdb_printf(" %s", buf);
66 72 }
67 73 }
68 74
69 75 /*
70 76 * Dcmd (and callback function) to print a summary of
71 77 * all "smbfs" entries in the VFS list.
72 78 */
73 79
74 80 typedef struct smbfs_vfs_cbdata {
75 81 int flags;
76 82 int printed_header;
77 83 uintptr_t vfsops; /* filter by vfs ops pointer */
78 84 smbmntinfo_t smi; /* scratch space for smbfs_vfs_cb */
79 85 } smbfs_vfs_cbdata_t;
80 86
81 87 int
82 88 smbfs_vfs_cb(uintptr_t addr, const void *data, void *arg)
83 89 {
84 90 const vfs_t *vfs = data;
85 91 smbfs_vfs_cbdata_t *cbd = arg;
86 92 uintptr_t ta;
87 93
88 94 /* Filter by matching smbfs ops vector. */
89 95 if (cbd->vfsops && cbd->vfsops != (uintptr_t)vfs->vfs_op) {
90 96 return (WALK_NEXT);
91 97 }
92 98
93 99 if (cbd->printed_header == 0) {
94 100 cbd->printed_header = 1;
95 101 mdb_printf("// vfs_t smbmntinfo_t mnt_path\n");
96 102 }
97 103
98 104 mdb_printf(" %-p", addr); /* vfs_t */
99 105 mdb_printf(" %-p", (uintptr_t)vfs->vfs_data);
100 106 /*
101 107 * Note: vfs_mntpt is a refstr_t.
102 108 * Advance to string member.
103 109 */
104 110 ta = (uintptr_t)vfs->vfs_mntpt;
105 111 ta += OFFSETOF(struct refstr, rs_string);
106 112 print_str(ta);
107 113 mdb_printf("\n");
108 114
109 115 if (cbd->flags & OPT_VERBOSE) {
110 116 mdb_inc_indent(2);
111 117 /* Don't fail the walk if this fails. */
112 118 if (mdb_vread(&cbd->smi, sizeof (cbd->smi),
113 119 (uintptr_t)vfs->vfs_data) == -1) {
114 120 mdb_warn("error reading smbmntinfo_t at %p",
115 121 (uintptr_t)vfs->vfs_data);
116 122 } else {
117 123 /* Interesting parts of smbmntinfo_t */
118 124 mdb_printf("smi_share: %p, smi_root: %p\n",
119 125 cbd->smi.smi_share, cbd->smi.smi_root);
120 126 }
121 127 mdb_dec_indent(2);
122 128 }
123 129
124 130 return (WALK_NEXT);
125 131 }
126 132
127 133 int
128 134 smbfs_vfs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
129 135 {
130 136 smbfs_vfs_cbdata_t *cbd;
131 137 vfs_t *vfs;
132 138
133 139 cbd = mdb_zalloc(sizeof (*cbd), UM_SLEEP | UM_GC);
134 140
135 141 /*
136 142 * Get the ops address here, so things work
137 143 * even if the smbfs module is loaded later
138 144 * than this mdb module.
139 145 */
140 146 if (mdb_readvar(&cbd->vfsops, "smbfs_vfsops") == -1) {
141 147 mdb_warn("failed to find 'smbfs_vfsops'\n");
|
↓ open down ↓ |
102 lines elided |
↑ open up ↑ |
142 148 return (DCMD_ERR);
143 149 }
144 150
145 151 if (mdb_getopts(argc, argv,
146 152 'v', MDB_OPT_SETBITS, OPT_VERBOSE, &cbd->flags,
147 153 NULL) != argc) {
148 154 return (DCMD_USAGE);
149 155 }
150 156
151 157 if (!(flags & DCMD_ADDRSPEC)) {
152 - if (mdb_walk("genunix`vfs", smbfs_vfs_cb, cbd)
158 + if (mdb_walk("vfs", smbfs_vfs_cb, cbd)
153 159 == -1) {
154 160 mdb_warn("can't walk smbfs vfs");
155 161 return (DCMD_ERR);
156 162 }
157 163 return (DCMD_OK);
158 164 }
159 165
160 166 vfs = mdb_alloc(sizeof (*vfs), UM_SLEEP | UM_GC);
161 167 SMBFS_OBJ_FETCH(addr, vfs_t, vfs, DCMD_ERR);
162 168 smbfs_vfs_cb(addr, vfs, cbd);
163 169 return (DCMD_OK);
164 170 }
165 171
166 172 void
167 173 smbfs_vfs_help(void)
168 174 {
169 175 mdb_printf(
170 176 "Display addresses of the mounted smbfs structures\n"
171 177 "and the pathname of the mountpoint\n"
172 178 "\nOptions:\n"
173 179 " -v display details of the smbmntinfo\n");
174 180 }
175 181
176 182 /*
177 183 * Dcmd (and callback function) to print a summary of
178 184 * all smbnodes in the node "hash" (cache) AVL tree.
179 185 */
180 186
181 187 typedef struct smbfs_node_cbdata {
182 188 int flags;
183 189 int printed_header;
184 190 vnode_t vn;
185 191 } smbfs_node_cbdata_t;
186 192
187 193 int
188 194 smbfs_node_cb(uintptr_t addr, const void *data, void *arg)
189 195 {
190 196 const smbnode_t *np = data;
191 197 smbfs_node_cbdata_t *cbd = arg;
192 198
193 199 if (cbd->printed_header == 0) {
194 200 cbd->printed_header = 1;
195 201 mdb_printf("// vnode smbnode rpath\n");
196 202 }
197 203
198 204 mdb_printf(" %-p", (uintptr_t)np->r_vnode);
199 205 mdb_printf(" %-p", addr); /* smbnode */
200 206 print_str((uintptr_t)np->n_rpath);
201 207 mdb_printf("\n");
202 208
203 209 if (cbd->flags & OPT_VERBOSE) {
204 210 mdb_inc_indent(2);
205 211 /* Don't fail the walk if this fails. */
206 212 if (mdb_vread(&cbd->vn, sizeof (cbd->vn),
207 213 (uintptr_t)np->r_vnode) == -1) {
208 214 mdb_warn("error reading vnode_t at %p",
209 215 (uintptr_t)np->r_vnode);
210 216 } else {
211 217 /* Interesting parts of vnode_t */
212 218 mdb_printf("v_type=%d v_count=%d",
213 219 cbd->vn.v_type, cbd->vn.v_count);
214 220 mdb_printf("\n");
215 221 }
216 222 mdb_dec_indent(2);
217 223 }
218 224
219 225 return (WALK_NEXT);
220 226 }
221 227
222 228 int
223 229 smbfs_node_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
224 230 {
225 231 smbfs_node_cbdata_t *cbd;
226 232
227 233 cbd = mdb_zalloc(sizeof (*cbd), UM_SLEEP | UM_GC);
228 234
229 235 if (mdb_getopts(argc, argv,
230 236 'v', MDB_OPT_SETBITS, OPT_VERBOSE, &cbd->flags,
|
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
231 237 NULL) != argc) {
232 238 return (DCMD_USAGE);
233 239 }
234 240
235 241 if (!(flags & DCMD_ADDRSPEC)) {
236 242 mdb_warn("expect an smbmntinfo_t addr");
237 243 return (DCMD_USAGE);
238 244 }
239 245 addr += OFFSETOF(smbmntinfo_t, smi_hash_avl);
240 246
241 - if (mdb_pwalk("genunix`avl", smbfs_node_cb, cbd, addr) == -1) {
247 + if (mdb_pwalk("avl", smbfs_node_cb, cbd, addr) == -1) {
242 248 mdb_warn("cannot walk smbfs nodes");
243 249 return (DCMD_ERR);
244 250 }
245 251
246 252 return (DCMD_OK);
247 253 }
248 254
249 255 void
250 256 smbfs_node_help(void)
251 257 {
252 258 mdb_printf("Options:\n"
253 259 " -v be verbose when displaying smbnodes\n");
254 260 }
255 261
256 262 static const mdb_dcmd_t dcmds[] = {
257 263 {
258 264 "smbfs_vfs", "?[-v]",
259 265 "show smbfs-mounted vfs structs",
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
260 266 smbfs_vfs_dcmd, smbfs_vfs_help
261 267 },
262 268 {
263 269 "smbfs_node", "?[-v]",
264 270 "given an smbmntinfo_t, list smbnodes",
265 271 smbfs_node_dcmd, smbfs_node_help
266 272 },
267 273 {NULL}
268 274 };
269 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 +
270 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
271 325 {NULL}
272 326 };
273 327
328 +
274 329 static const mdb_modinfo_t modinfo = {
275 330 MDB_API_VERSION,
276 331 dcmds,
277 332 walkers
278 333 };
279 334
280 335 const mdb_modinfo_t *
281 336 _mdb_init(void)
282 337 {
283 338 return (&modinfo);
284 339 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX