Print this page
4101 metaslab_debug should allow for fine-grained control
4102 space_maps should store more information about themselves
4103 space map object blocksize should be increased
4104 ::spa_space no longer works
4105 removing a mirrored log device results in a leaked object
4106 asynchronously load metaslab
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Sebastien Roy <seb@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/modules/zfs/zfs.c
+++ new/usr/src/cmd/mdb/common/modules/zfs/zfs.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 *
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 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 25 */
26 26
27 27 /* Portions Copyright 2010 Robert Milkowski */
28 28
29 29 #include <mdb/mdb_ctf.h>
30 30 #include <sys/zfs_context.h>
31 31 #include <sys/mdb_modapi.h>
32 32 #include <sys/dbuf.h>
33 33 #include <sys/dmu_objset.h>
34 34 #include <sys/dsl_dir.h>
35 35 #include <sys/dsl_pool.h>
36 36 #include <sys/metaslab_impl.h>
37 37 #include <sys/space_map.h>
38 38 #include <sys/list.h>
39 39 #include <sys/vdev_impl.h>
40 40 #include <sys/zap_leaf.h>
41 41 #include <sys/zap_impl.h>
42 42 #include <ctype.h>
43 43 #include <sys/zfs_acl.h>
44 44 #include <sys/sa_impl.h>
45 45
46 46 #ifdef _KERNEL
47 47 #define ZFS_OBJ_NAME "zfs"
48 48 extern int64_t mdb_gethrtime(void);
49 49 #else
50 50 #define ZFS_OBJ_NAME "libzpool.so.1"
51 51 #endif
52 52
53 53 #define ZFS_STRUCT "struct " ZFS_OBJ_NAME "`"
54 54
55 55 #ifndef _KERNEL
56 56 int aok;
57 57 #endif
58 58
59 59 static int
60 60 getmember(uintptr_t addr, const char *type, mdb_ctf_id_t *idp,
61 61 const char *member, int len, void *buf)
62 62 {
63 63 mdb_ctf_id_t id;
64 64 ulong_t off;
65 65 char name[64];
66 66
67 67 if (idp == NULL) {
68 68 if (mdb_ctf_lookup_by_name(type, &id) == -1) {
69 69 mdb_warn("couldn't find type %s", type);
70 70 return (DCMD_ERR);
71 71 }
72 72 idp = &id;
73 73 } else {
74 74 type = name;
75 75 mdb_ctf_type_name(*idp, name, sizeof (name));
76 76 }
77 77
78 78 if (mdb_ctf_offsetof(*idp, member, &off) == -1) {
79 79 mdb_warn("couldn't find member %s of type %s\n", member, type);
80 80 return (DCMD_ERR);
81 81 }
82 82 if (off % 8 != 0) {
83 83 mdb_warn("member %s of type %s is unsupported bitfield",
84 84 member, type);
85 85 return (DCMD_ERR);
86 86 }
87 87 off /= 8;
88 88
89 89 if (mdb_vread(buf, len, addr + off) == -1) {
90 90 mdb_warn("failed to read %s from %s at %p",
91 91 member, type, addr + off);
92 92 return (DCMD_ERR);
93 93 }
94 94 /* mdb_warn("read %s from %s at %p+%llx\n", member, type, addr, off); */
95 95
96 96 return (0);
97 97 }
98 98
99 99 #define GETMEMB(addr, structname, member, dest) \
100 100 getmember(addr, ZFS_STRUCT structname, NULL, #member, \
101 101 sizeof (dest), &(dest))
102 102
103 103 #define GETMEMBID(addr, ctfid, member, dest) \
104 104 getmember(addr, NULL, ctfid, #member, sizeof (dest), &(dest))
105 105
106 106 static boolean_t
107 107 strisprint(const char *cp)
108 108 {
109 109 for (; *cp; cp++) {
110 110 if (!isprint(*cp))
111 111 return (B_FALSE);
112 112 }
113 113 return (B_TRUE);
114 114 }
115 115
116 116 static int verbose;
117 117
118 118 static int
119 119 freelist_walk_init(mdb_walk_state_t *wsp)
120 120 {
121 121 if (wsp->walk_addr == NULL) {
122 122 mdb_warn("must supply starting address\n");
123 123 return (WALK_ERR);
124 124 }
125 125
126 126 wsp->walk_data = 0; /* Index into the freelist */
127 127 return (WALK_NEXT);
128 128 }
129 129
130 130 static int
131 131 freelist_walk_step(mdb_walk_state_t *wsp)
132 132 {
133 133 uint64_t entry;
134 134 uintptr_t number = (uintptr_t)wsp->walk_data;
135 135 char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
136 136 "INVALID", "INVALID", "INVALID", "INVALID" };
137 137 int mapshift = SPA_MINBLOCKSHIFT;
138 138
139 139 if (mdb_vread(&entry, sizeof (entry), wsp->walk_addr) == -1) {
140 140 mdb_warn("failed to read freelist entry %p", wsp->walk_addr);
141 141 return (WALK_DONE);
142 142 }
143 143 wsp->walk_addr += sizeof (entry);
144 144 wsp->walk_data = (void *)(number + 1);
145 145
146 146 if (SM_DEBUG_DECODE(entry)) {
147 147 mdb_printf("DEBUG: %3u %10s: txg=%llu pass=%llu\n",
148 148 number,
149 149 ddata[SM_DEBUG_ACTION_DECODE(entry)],
150 150 SM_DEBUG_TXG_DECODE(entry),
151 151 SM_DEBUG_SYNCPASS_DECODE(entry));
152 152 } else {
153 153 mdb_printf("Entry: %3u offsets=%08llx-%08llx type=%c "
154 154 "size=%06llx", number,
155 155 SM_OFFSET_DECODE(entry) << mapshift,
156 156 (SM_OFFSET_DECODE(entry) + SM_RUN_DECODE(entry)) <<
157 157 mapshift,
158 158 SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
159 159 SM_RUN_DECODE(entry) << mapshift);
160 160 if (verbose)
161 161 mdb_printf(" (raw=%012llx)\n", entry);
162 162 mdb_printf("\n");
163 163 }
164 164 return (WALK_NEXT);
165 165 }
166 166
167 167 static int
168 168 mdb_dsl_dir_name(uintptr_t addr, char *buf)
169 169 {
170 170 static int gotid;
171 171 static mdb_ctf_id_t dd_id;
172 172 uintptr_t dd_parent;
173 173 char dd_myname[MAXNAMELEN];
174 174
175 175 if (!gotid) {
176 176 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "dsl_dir",
177 177 &dd_id) == -1) {
178 178 mdb_warn("couldn't find struct dsl_dir");
179 179 return (DCMD_ERR);
180 180 }
181 181 gotid = TRUE;
182 182 }
183 183 if (GETMEMBID(addr, &dd_id, dd_parent, dd_parent) ||
184 184 GETMEMBID(addr, &dd_id, dd_myname, dd_myname)) {
185 185 return (DCMD_ERR);
186 186 }
187 187
188 188 if (dd_parent) {
189 189 if (mdb_dsl_dir_name(dd_parent, buf))
190 190 return (DCMD_ERR);
191 191 strcat(buf, "/");
192 192 }
193 193
194 194 if (dd_myname[0])
195 195 strcat(buf, dd_myname);
196 196 else
197 197 strcat(buf, "???");
198 198
199 199 return (0);
200 200 }
201 201
202 202 static int
203 203 objset_name(uintptr_t addr, char *buf)
204 204 {
205 205 static int gotid;
206 206 static mdb_ctf_id_t os_id, ds_id;
207 207 uintptr_t os_dsl_dataset;
208 208 char ds_snapname[MAXNAMELEN];
209 209 uintptr_t ds_dir;
210 210
211 211 buf[0] = '\0';
212 212
213 213 if (!gotid) {
214 214 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "objset",
215 215 &os_id) == -1) {
216 216 mdb_warn("couldn't find struct objset");
217 217 return (DCMD_ERR);
218 218 }
219 219 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "dsl_dataset",
220 220 &ds_id) == -1) {
221 221 mdb_warn("couldn't find struct dsl_dataset");
222 222 return (DCMD_ERR);
223 223 }
224 224
225 225 gotid = TRUE;
226 226 }
227 227
228 228 if (GETMEMBID(addr, &os_id, os_dsl_dataset, os_dsl_dataset))
229 229 return (DCMD_ERR);
230 230
231 231 if (os_dsl_dataset == 0) {
232 232 strcat(buf, "mos");
233 233 return (0);
234 234 }
235 235
236 236 if (GETMEMBID(os_dsl_dataset, &ds_id, ds_snapname, ds_snapname) ||
237 237 GETMEMBID(os_dsl_dataset, &ds_id, ds_dir, ds_dir)) {
238 238 return (DCMD_ERR);
239 239 }
240 240
241 241 if (ds_dir && mdb_dsl_dir_name(ds_dir, buf))
242 242 return (DCMD_ERR);
243 243
244 244 if (ds_snapname[0]) {
245 245 strcat(buf, "@");
246 246 strcat(buf, ds_snapname);
247 247 }
248 248 return (0);
249 249 }
250 250
251 251 static void
252 252 enum_lookup(char *out, size_t size, mdb_ctf_id_t id, int val,
253 253 const char *prefix)
254 254 {
255 255 const char *cp;
256 256 size_t len = strlen(prefix);
257 257
258 258 if ((cp = mdb_ctf_enum_name(id, val)) != NULL) {
259 259 if (strncmp(cp, prefix, len) == 0)
260 260 cp += len;
261 261 (void) strncpy(out, cp, size);
262 262 } else {
263 263 mdb_snprintf(out, size, "? (%d)", val);
264 264 }
265 265 }
266 266
267 267 /* ARGSUSED */
268 268 static int
269 269 zfs_params(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
270 270 {
271 271 /*
272 272 * This table can be approximately generated by running:
273 273 * egrep "^[a-z0-9_]+ [a-z0-9_]+( =.*)?;" *.c | cut -d ' ' -f 2
274 274 */
275 275 static const char *params[] = {
276 276 "arc_reduce_dnlc_percent",
277 277 "arc_lotsfree_percent",
278 278 "zfs_dirty_data_max",
279 279 "zfs_dirty_data_sync",
280 280 "zfs_delay_max_ns",
281 281 "zfs_delay_min_dirty_percent",
282 282 "zfs_delay_scale",
283 283 "zfs_vdev_max_active",
284 284 "zfs_vdev_sync_read_min_active",
285 285 "zfs_vdev_sync_read_max_active",
286 286 "zfs_vdev_sync_write_min_active",
287 287 "zfs_vdev_sync_write_max_active",
288 288 "zfs_vdev_async_read_min_active",
289 289 "zfs_vdev_async_read_max_active",
290 290 "zfs_vdev_async_write_min_active",
291 291 "zfs_vdev_async_write_max_active",
292 292 "zfs_vdev_scrub_min_active",
293 293 "zfs_vdev_scrub_max_active",
294 294 "zfs_vdev_async_write_active_min_dirty_percent",
295 295 "zfs_vdev_async_write_active_max_dirty_percent",
296 296 "spa_asize_inflation",
297 297 "zfs_arc_max",
298 298 "zfs_arc_min",
299 299 "arc_shrink_shift",
300 300 "zfs_mdcomp_disable",
301 301 "zfs_prefetch_disable",
302 302 "zfetch_max_streams",
303 303 "zfetch_min_sec_reap",
304 304 "zfetch_block_cap",
305 305 "zfetch_array_rd_sz",
306 306 "zfs_default_bs",
307 307 "zfs_default_ibs",
308 308 "metaslab_aliquot",
309 309 "reference_tracking_enable",
310 310 "reference_history",
311 311 "spa_max_replication_override",
312 312 "spa_mode_global",
313 313 "zfs_flags",
314 314 "zfs_txg_timeout",
315 315 "zfs_vdev_cache_max",
316 316 "zfs_vdev_cache_size",
317 317 "zfs_vdev_cache_bshift",
318 318 "vdev_mirror_shift",
319 319 "zfs_scrub_limit",
320 320 "zfs_no_scrub_io",
321 321 "zfs_no_scrub_prefetch",
322 322 "zfs_vdev_aggregation_limit",
323 323 "fzap_default_block_shift",
324 324 "zfs_immediate_write_sz",
325 325 "zfs_read_chunk_size",
326 326 "zfs_nocacheflush",
327 327 "zil_replay_disable",
328 328 "metaslab_gang_bang",
329 329 "metaslab_df_alloc_threshold",
330 330 "metaslab_df_free_pct",
331 331 "zio_injection_enabled",
332 332 "zvol_immediate_write_sz",
333 333 };
334 334
335 335 for (int i = 0; i < sizeof (params) / sizeof (params[0]); i++) {
336 336 int sz;
337 337 uint64_t val64;
338 338 uint32_t *val32p = (uint32_t *)&val64;
339 339
340 340 sz = mdb_readvar(&val64, params[i]);
341 341 if (sz == 4) {
342 342 mdb_printf("%s = 0x%x\n", params[i], *val32p);
343 343 } else if (sz == 8) {
344 344 mdb_printf("%s = 0x%llx\n", params[i], val64);
345 345 } else {
346 346 mdb_warn("variable %s not found", params[i]);
347 347 }
348 348 }
349 349
350 350 return (DCMD_OK);
351 351 }
352 352
353 353 /* ARGSUSED */
354 354 static int
355 355 blkptr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
356 356 {
357 357 mdb_ctf_id_t type_enum, checksum_enum, compress_enum;
358 358 char type[80], checksum[80], compress[80];
359 359 blkptr_t blk, *bp = &blk;
360 360 char buf[BP_SPRINTF_LEN];
361 361
362 362 if (mdb_vread(&blk, sizeof (blkptr_t), addr) == -1) {
363 363 mdb_warn("failed to read blkptr_t");
364 364 return (DCMD_ERR);
365 365 }
366 366
367 367 if (mdb_ctf_lookup_by_name("enum dmu_object_type", &type_enum) == -1 ||
368 368 mdb_ctf_lookup_by_name("enum zio_checksum", &checksum_enum) == -1 ||
369 369 mdb_ctf_lookup_by_name("enum zio_compress", &compress_enum) == -1) {
370 370 mdb_warn("Could not find blkptr enumerated types");
371 371 return (DCMD_ERR);
372 372 }
373 373
374 374 enum_lookup(type, sizeof (type), type_enum,
375 375 BP_GET_TYPE(bp), "DMU_OT_");
376 376 enum_lookup(checksum, sizeof (checksum), checksum_enum,
377 377 BP_GET_CHECKSUM(bp), "ZIO_CHECKSUM_");
378 378 enum_lookup(compress, sizeof (compress), compress_enum,
379 379 BP_GET_COMPRESS(bp), "ZIO_COMPRESS_");
380 380
381 381 SPRINTF_BLKPTR(mdb_snprintf, '\n', buf, bp, type, checksum, compress);
382 382
383 383 mdb_printf("%s\n", buf);
384 384
385 385 return (DCMD_OK);
386 386 }
387 387
388 388 typedef struct mdb_dmu_buf_impl {
389 389 struct {
390 390 uint64_t db_object;
391 391 } db;
392 392 uintptr_t db_objset;
393 393 uint64_t db_level;
394 394 uint64_t db_blkid;
395 395 struct {
396 396 uint64_t rc_count;
397 397 } db_holds;
398 398 } mdb_dmu_buf_impl_t;
399 399
400 400 /* ARGSUSED */
401 401 static int
402 402 dbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
403 403 {
404 404 mdb_dmu_buf_impl_t db;
405 405 char objectname[32];
406 406 char blkidname[32];
407 407 char path[MAXNAMELEN];
408 408
409 409 if (DCMD_HDRSPEC(flags))
410 410 mdb_printf(" addr object lvl blkid holds os\n");
411 411
412 412 if (mdb_ctf_vread(&db, ZFS_STRUCT "dmu_buf_impl", "mdb_dmu_buf_impl_t",
413 413 addr, 0) == -1)
414 414 return (DCMD_ERR);
415 415
416 416 if (db.db.db_object == DMU_META_DNODE_OBJECT)
417 417 (void) strcpy(objectname, "mdn");
418 418 else
419 419 (void) mdb_snprintf(objectname, sizeof (objectname), "%llx",
420 420 (u_longlong_t)db.db.db_object);
421 421
422 422 if (db.db_blkid == DMU_BONUS_BLKID)
423 423 (void) strcpy(blkidname, "bonus");
424 424 else
425 425 (void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
426 426 (u_longlong_t)db.db_blkid);
427 427
428 428 if (objset_name(db.db_objset, path)) {
429 429 return (DCMD_ERR);
430 430 }
431 431
432 432 mdb_printf("%p %8s %1u %9s %2llu %s\n", addr,
433 433 objectname, (int)db.db_level, blkidname,
434 434 db.db_holds.rc_count, path);
435 435
436 436 return (DCMD_OK);
437 437 }
438 438
439 439 /* ARGSUSED */
440 440 static int
441 441 dbuf_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
442 442 {
443 443 #define HISTOSZ 32
444 444 uintptr_t dbp;
445 445 dmu_buf_impl_t db;
446 446 dbuf_hash_table_t ht;
447 447 uint64_t bucket, ndbufs;
448 448 uint64_t histo[HISTOSZ];
449 449 uint64_t histo2[HISTOSZ];
450 450 int i, maxidx;
451 451
452 452 if (mdb_readvar(&ht, "dbuf_hash_table") == -1) {
453 453 mdb_warn("failed to read 'dbuf_hash_table'");
454 454 return (DCMD_ERR);
455 455 }
456 456
457 457 for (i = 0; i < HISTOSZ; i++) {
458 458 histo[i] = 0;
459 459 histo2[i] = 0;
460 460 }
461 461
462 462 ndbufs = 0;
463 463 for (bucket = 0; bucket < ht.hash_table_mask+1; bucket++) {
464 464 int len;
465 465
466 466 if (mdb_vread(&dbp, sizeof (void *),
467 467 (uintptr_t)(ht.hash_table+bucket)) == -1) {
468 468 mdb_warn("failed to read hash bucket %u at %p",
469 469 bucket, ht.hash_table+bucket);
470 470 return (DCMD_ERR);
471 471 }
472 472
473 473 len = 0;
474 474 while (dbp != 0) {
475 475 if (mdb_vread(&db, sizeof (dmu_buf_impl_t),
476 476 dbp) == -1) {
477 477 mdb_warn("failed to read dbuf at %p", dbp);
478 478 return (DCMD_ERR);
479 479 }
480 480 dbp = (uintptr_t)db.db_hash_next;
481 481 for (i = MIN(len, HISTOSZ - 1); i >= 0; i--)
482 482 histo2[i]++;
483 483 len++;
484 484 ndbufs++;
485 485 }
486 486
487 487 if (len >= HISTOSZ)
488 488 len = HISTOSZ-1;
489 489 histo[len]++;
490 490 }
491 491
492 492 mdb_printf("hash table has %llu buckets, %llu dbufs "
493 493 "(avg %llu buckets/dbuf)\n",
494 494 ht.hash_table_mask+1, ndbufs,
495 495 (ht.hash_table_mask+1)/ndbufs);
496 496
497 497 mdb_printf("\n");
498 498 maxidx = 0;
499 499 for (i = 0; i < HISTOSZ; i++)
500 500 if (histo[i] > 0)
501 501 maxidx = i;
502 502 mdb_printf("hash chain length number of buckets\n");
503 503 for (i = 0; i <= maxidx; i++)
504 504 mdb_printf("%u %llu\n", i, histo[i]);
505 505
506 506 mdb_printf("\n");
507 507 maxidx = 0;
508 508 for (i = 0; i < HISTOSZ; i++)
509 509 if (histo2[i] > 0)
510 510 maxidx = i;
511 511 mdb_printf("hash chain depth number of dbufs\n");
512 512 for (i = 0; i <= maxidx; i++)
513 513 mdb_printf("%u or more %llu %llu%%\n",
514 514 i, histo2[i], histo2[i]*100/ndbufs);
515 515
516 516
517 517 return (DCMD_OK);
518 518 }
519 519
520 520 #define CHAIN_END 0xffff
521 521 /*
522 522 * ::zap_leaf [-v]
523 523 *
524 524 * Print a zap_leaf_phys_t, assumed to be 16k
525 525 */
526 526 /* ARGSUSED */
527 527 static int
528 528 zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
529 529 {
530 530 char buf[16*1024];
531 531 int verbose = B_FALSE;
532 532 int four = B_FALSE;
533 533 zap_leaf_t l;
534 534 zap_leaf_phys_t *zlp = (void *)buf;
535 535 int i;
536 536
537 537 if (mdb_getopts(argc, argv,
538 538 'v', MDB_OPT_SETBITS, TRUE, &verbose,
539 539 '4', MDB_OPT_SETBITS, TRUE, &four,
540 540 NULL) != argc)
541 541 return (DCMD_USAGE);
542 542
543 543 l.l_phys = zlp;
544 544 l.l_bs = 14; /* assume 16k blocks */
545 545 if (four)
546 546 l.l_bs = 12;
547 547
548 548 if (!(flags & DCMD_ADDRSPEC)) {
549 549 return (DCMD_USAGE);
550 550 }
551 551
552 552 if (mdb_vread(buf, sizeof (buf), addr) == -1) {
553 553 mdb_warn("failed to read zap_leaf_phys_t at %p", addr);
554 554 return (DCMD_ERR);
555 555 }
556 556
557 557 if (zlp->l_hdr.lh_block_type != ZBT_LEAF ||
558 558 zlp->l_hdr.lh_magic != ZAP_LEAF_MAGIC) {
559 559 mdb_warn("This does not appear to be a zap_leaf_phys_t");
560 560 return (DCMD_ERR);
561 561 }
562 562
563 563 mdb_printf("zap_leaf_phys_t at %p:\n", addr);
564 564 mdb_printf(" lh_prefix_len = %u\n", zlp->l_hdr.lh_prefix_len);
565 565 mdb_printf(" lh_prefix = %llx\n", zlp->l_hdr.lh_prefix);
566 566 mdb_printf(" lh_nentries = %u\n", zlp->l_hdr.lh_nentries);
567 567 mdb_printf(" lh_nfree = %u\n", zlp->l_hdr.lh_nfree,
568 568 zlp->l_hdr.lh_nfree * 100 / (ZAP_LEAF_NUMCHUNKS(&l)));
569 569 mdb_printf(" lh_freelist = %u\n", zlp->l_hdr.lh_freelist);
570 570 mdb_printf(" lh_flags = %x (%s)\n", zlp->l_hdr.lh_flags,
571 571 zlp->l_hdr.lh_flags & ZLF_ENTRIES_CDSORTED ?
572 572 "ENTRIES_CDSORTED" : "");
573 573
574 574 if (verbose) {
575 575 mdb_printf(" hash table:\n");
576 576 for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++) {
577 577 if (zlp->l_hash[i] != CHAIN_END)
578 578 mdb_printf(" %u: %u\n", i, zlp->l_hash[i]);
579 579 }
580 580 }
581 581
582 582 mdb_printf(" chunks:\n");
583 583 for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
584 584 /* LINTED: alignment */
585 585 zap_leaf_chunk_t *zlc = &ZAP_LEAF_CHUNK(&l, i);
586 586 switch (zlc->l_entry.le_type) {
587 587 case ZAP_CHUNK_FREE:
588 588 if (verbose) {
589 589 mdb_printf(" %u: free; lf_next = %u\n",
590 590 i, zlc->l_free.lf_next);
591 591 }
592 592 break;
593 593 case ZAP_CHUNK_ENTRY:
594 594 mdb_printf(" %u: entry\n", i);
595 595 if (verbose) {
596 596 mdb_printf(" le_next = %u\n",
597 597 zlc->l_entry.le_next);
598 598 }
599 599 mdb_printf(" le_name_chunk = %u\n",
600 600 zlc->l_entry.le_name_chunk);
601 601 mdb_printf(" le_name_numints = %u\n",
602 602 zlc->l_entry.le_name_numints);
603 603 mdb_printf(" le_value_chunk = %u\n",
604 604 zlc->l_entry.le_value_chunk);
605 605 mdb_printf(" le_value_intlen = %u\n",
606 606 zlc->l_entry.le_value_intlen);
607 607 mdb_printf(" le_value_numints = %u\n",
608 608 zlc->l_entry.le_value_numints);
609 609 mdb_printf(" le_cd = %u\n",
610 610 zlc->l_entry.le_cd);
611 611 mdb_printf(" le_hash = %llx\n",
612 612 zlc->l_entry.le_hash);
613 613 break;
614 614 case ZAP_CHUNK_ARRAY:
615 615 mdb_printf(" %u: array", i);
616 616 if (strisprint((char *)zlc->l_array.la_array))
617 617 mdb_printf(" \"%s\"", zlc->l_array.la_array);
618 618 mdb_printf("\n");
619 619 if (verbose) {
620 620 int j;
621 621 mdb_printf(" ");
622 622 for (j = 0; j < ZAP_LEAF_ARRAY_BYTES; j++) {
623 623 mdb_printf("%02x ",
624 624 zlc->l_array.la_array[j]);
625 625 }
626 626 mdb_printf("\n");
627 627 }
628 628 if (zlc->l_array.la_next != CHAIN_END) {
629 629 mdb_printf(" lf_next = %u\n",
630 630 zlc->l_array.la_next);
631 631 }
632 632 break;
633 633 default:
634 634 mdb_printf(" %u: undefined type %u\n",
635 635 zlc->l_entry.le_type);
636 636 }
637 637 }
638 638
639 639 return (DCMD_OK);
640 640 }
641 641
642 642 typedef struct dbufs_data {
643 643 mdb_ctf_id_t id;
644 644 uint64_t objset;
645 645 uint64_t object;
646 646 uint64_t level;
647 647 uint64_t blkid;
648 648 char *osname;
649 649 } dbufs_data_t;
650 650
651 651 #define DBUFS_UNSET (0xbaddcafedeadbeefULL)
652 652
653 653 /* ARGSUSED */
654 654 static int
655 655 dbufs_cb(uintptr_t addr, const void *unknown, void *arg)
656 656 {
657 657 dbufs_data_t *data = arg;
658 658 uintptr_t objset;
659 659 dmu_buf_t db;
660 660 uint8_t level;
661 661 uint64_t blkid;
662 662 char osname[MAXNAMELEN];
663 663
664 664 if (GETMEMBID(addr, &data->id, db_objset, objset) ||
665 665 GETMEMBID(addr, &data->id, db, db) ||
666 666 GETMEMBID(addr, &data->id, db_level, level) ||
667 667 GETMEMBID(addr, &data->id, db_blkid, blkid)) {
668 668 return (WALK_ERR);
669 669 }
670 670
671 671 if ((data->objset == DBUFS_UNSET || data->objset == objset) &&
672 672 (data->osname == NULL || (objset_name(objset, osname) == 0 &&
673 673 strcmp(data->osname, osname) == 0)) &&
674 674 (data->object == DBUFS_UNSET || data->object == db.db_object) &&
675 675 (data->level == DBUFS_UNSET || data->level == level) &&
676 676 (data->blkid == DBUFS_UNSET || data->blkid == blkid)) {
677 677 mdb_printf("%#lr\n", addr);
678 678 }
679 679 return (WALK_NEXT);
680 680 }
681 681
682 682 /* ARGSUSED */
683 683 static int
684 684 dbufs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
685 685 {
686 686 dbufs_data_t data;
687 687 char *object = NULL;
688 688 char *blkid = NULL;
689 689
690 690 data.objset = data.object = data.level = data.blkid = DBUFS_UNSET;
691 691 data.osname = NULL;
692 692
693 693 if (mdb_getopts(argc, argv,
694 694 'O', MDB_OPT_UINT64, &data.objset,
695 695 'n', MDB_OPT_STR, &data.osname,
696 696 'o', MDB_OPT_STR, &object,
697 697 'l', MDB_OPT_UINT64, &data.level,
698 698 'b', MDB_OPT_STR, &blkid) != argc) {
699 699 return (DCMD_USAGE);
700 700 }
701 701
702 702 if (object) {
703 703 if (strcmp(object, "mdn") == 0) {
704 704 data.object = DMU_META_DNODE_OBJECT;
705 705 } else {
706 706 data.object = mdb_strtoull(object);
707 707 }
708 708 }
709 709
710 710 if (blkid) {
711 711 if (strcmp(blkid, "bonus") == 0) {
712 712 data.blkid = DMU_BONUS_BLKID;
713 713 } else {
714 714 data.blkid = mdb_strtoull(blkid);
715 715 }
716 716 }
717 717
718 718 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "dmu_buf_impl", &data.id) == -1) {
719 719 mdb_warn("couldn't find struct dmu_buf_impl_t");
720 720 return (DCMD_ERR);
721 721 }
722 722
723 723 if (mdb_walk("dmu_buf_impl_t", dbufs_cb, &data) != 0) {
724 724 mdb_warn("can't walk dbufs");
725 725 return (DCMD_ERR);
726 726 }
727 727
728 728 return (DCMD_OK);
729 729 }
730 730
731 731 typedef struct abuf_find_data {
732 732 dva_t dva;
733 733 mdb_ctf_id_t id;
734 734 } abuf_find_data_t;
735 735
736 736 /* ARGSUSED */
737 737 static int
738 738 abuf_find_cb(uintptr_t addr, const void *unknown, void *arg)
739 739 {
740 740 abuf_find_data_t *data = arg;
741 741 dva_t dva;
742 742
743 743 if (GETMEMBID(addr, &data->id, b_dva, dva)) {
744 744 return (WALK_ERR);
745 745 }
746 746
747 747 if (dva.dva_word[0] == data->dva.dva_word[0] &&
748 748 dva.dva_word[1] == data->dva.dva_word[1]) {
749 749 mdb_printf("%#lr\n", addr);
750 750 }
751 751 return (WALK_NEXT);
752 752 }
753 753
754 754 /* ARGSUSED */
755 755 static int
756 756 abuf_find(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
757 757 {
758 758 abuf_find_data_t data;
759 759 GElf_Sym sym;
760 760 int i;
761 761 const char *syms[] = {
762 762 "ARC_mru",
763 763 "ARC_mru_ghost",
764 764 "ARC_mfu",
765 765 "ARC_mfu_ghost",
766 766 };
767 767
768 768 if (argc != 2)
769 769 return (DCMD_USAGE);
770 770
771 771 for (i = 0; i < 2; i ++) {
772 772 switch (argv[i].a_type) {
773 773 case MDB_TYPE_STRING:
774 774 data.dva.dva_word[i] = mdb_strtoull(argv[i].a_un.a_str);
775 775 break;
776 776 case MDB_TYPE_IMMEDIATE:
777 777 data.dva.dva_word[i] = argv[i].a_un.a_val;
778 778 break;
779 779 default:
780 780 return (DCMD_USAGE);
781 781 }
782 782 }
783 783
784 784 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "arc_buf_hdr", &data.id) == -1) {
785 785 mdb_warn("couldn't find struct arc_buf_hdr");
786 786 return (DCMD_ERR);
787 787 }
788 788
789 789 for (i = 0; i < sizeof (syms) / sizeof (syms[0]); i++) {
790 790 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, syms[i], &sym)) {
791 791 mdb_warn("can't find symbol %s", syms[i]);
792 792 return (DCMD_ERR);
793 793 }
794 794
795 795 if (mdb_pwalk("list", abuf_find_cb, &data, sym.st_value) != 0) {
796 796 mdb_warn("can't walk %s", syms[i]);
797 797 return (DCMD_ERR);
798 798 }
799 799 }
800 800
801 801 return (DCMD_OK);
802 802 }
803 803
804 804
805 805 typedef struct dbgmsg_arg {
806 806 boolean_t da_verbose;
807 807 boolean_t da_address;
808 808 } dbgmsg_arg_t;
809 809
810 810 /* ARGSUSED */
811 811 static int
812 812 dbgmsg_cb(uintptr_t addr, const void *unknown, void *arg)
813 813 {
814 814 static mdb_ctf_id_t id;
815 815 static boolean_t gotid;
816 816 static ulong_t off;
817 817
818 818 dbgmsg_arg_t *da = arg;
819 819 time_t timestamp;
820 820 char buf[1024];
821 821
822 822 if (!gotid) {
823 823 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "zfs_dbgmsg", &id) ==
824 824 -1) {
825 825 mdb_warn("couldn't find struct zfs_dbgmsg");
826 826 return (WALK_ERR);
827 827 }
828 828 gotid = TRUE;
829 829 if (mdb_ctf_offsetof(id, "zdm_msg", &off) == -1) {
830 830 mdb_warn("couldn't find zdm_msg");
831 831 return (WALK_ERR);
832 832 }
833 833 off /= 8;
834 834 }
835 835
836 836
837 837 if (GETMEMBID(addr, &id, zdm_timestamp, timestamp)) {
838 838 return (WALK_ERR);
839 839 }
840 840
841 841 if (mdb_readstr(buf, sizeof (buf), addr + off) == -1) {
842 842 mdb_warn("failed to read zdm_msg at %p\n", addr + off);
843 843 return (DCMD_ERR);
844 844 }
845 845
846 846 if (da->da_address)
847 847 mdb_printf("%p ", addr);
848 848 if (da->da_verbose)
849 849 mdb_printf("%Y ", timestamp);
850 850
851 851 mdb_printf("%s\n", buf);
852 852
853 853 if (da->da_verbose)
854 854 (void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
855 855
856 856 return (WALK_NEXT);
857 857 }
858 858
859 859 /* ARGSUSED */
860 860 static int
861 861 dbgmsg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
862 862 {
863 863 GElf_Sym sym;
864 864 dbgmsg_arg_t da = { 0 };
865 865
866 866 if (mdb_getopts(argc, argv,
867 867 'v', MDB_OPT_SETBITS, B_TRUE, &da.da_verbose,
868 868 'a', MDB_OPT_SETBITS, B_TRUE, &da.da_address,
869 869 NULL) != argc)
870 870 return (DCMD_USAGE);
871 871
872 872 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "zfs_dbgmsgs", &sym)) {
873 873 mdb_warn("can't find zfs_dbgmsgs");
874 874 return (DCMD_ERR);
875 875 }
876 876
877 877 if (mdb_pwalk("list", dbgmsg_cb, &da, sym.st_value) != 0) {
878 878 mdb_warn("can't walk zfs_dbgmsgs");
879 879 return (DCMD_ERR);
880 880 }
881 881
882 882 return (DCMD_OK);
883 883 }
884 884
885 885 /*ARGSUSED*/
886 886 static int
887 887 arc_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
888 888 {
889 889 kstat_named_t *stats;
890 890 GElf_Sym sym;
891 891 int nstats, i;
892 892 uint_t opt_a = FALSE;
893 893 uint_t opt_b = FALSE;
894 894 uint_t shift = 0;
895 895 const char *suffix;
896 896
897 897 static const char *bytestats[] = {
898 898 "p", "c", "c_min", "c_max", "size", "duplicate_buffers_size",
899 899 "arc_meta_used", "arc_meta_limit", "arc_meta_max",
900 900 NULL
901 901 };
902 902
903 903 static const char *extras[] = {
904 904 "arc_no_grow", "arc_tempreserve",
905 905 NULL
906 906 };
907 907
908 908 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "arc_stats", &sym) == -1) {
909 909 mdb_warn("failed to find 'arc_stats'");
910 910 return (DCMD_ERR);
911 911 }
912 912
913 913 stats = mdb_zalloc(sym.st_size, UM_SLEEP | UM_GC);
914 914
915 915 if (mdb_vread(stats, sym.st_size, sym.st_value) == -1) {
916 916 mdb_warn("couldn't read 'arc_stats' at %p", sym.st_value);
917 917 return (DCMD_ERR);
918 918 }
919 919
920 920 nstats = sym.st_size / sizeof (kstat_named_t);
921 921
922 922 /* NB: -a / opt_a are ignored for backwards compatability */
923 923 if (mdb_getopts(argc, argv,
924 924 'a', MDB_OPT_SETBITS, TRUE, &opt_a,
925 925 'b', MDB_OPT_SETBITS, TRUE, &opt_b,
926 926 'k', MDB_OPT_SETBITS, 10, &shift,
927 927 'm', MDB_OPT_SETBITS, 20, &shift,
928 928 'g', MDB_OPT_SETBITS, 30, &shift,
929 929 NULL) != argc)
930 930 return (DCMD_USAGE);
931 931
932 932 if (!opt_b && !shift)
933 933 shift = 20;
934 934
935 935 switch (shift) {
936 936 case 0:
937 937 suffix = "B";
938 938 break;
939 939 case 10:
940 940 suffix = "KB";
941 941 break;
942 942 case 20:
943 943 suffix = "MB";
944 944 break;
945 945 case 30:
946 946 suffix = "GB";
947 947 break;
948 948 default:
949 949 suffix = "XX";
950 950 }
951 951
952 952 for (i = 0; i < nstats; i++) {
953 953 int j;
954 954 boolean_t bytes = B_FALSE;
955 955
956 956 for (j = 0; bytestats[j]; j++) {
957 957 if (strcmp(stats[i].name, bytestats[j]) == 0) {
958 958 bytes = B_TRUE;
959 959 break;
960 960 }
961 961 }
962 962
963 963 if (bytes) {
964 964 mdb_printf("%-25s = %9llu %s\n", stats[i].name,
965 965 stats[i].value.ui64 >> shift, suffix);
966 966 } else {
967 967 mdb_printf("%-25s = %9llu\n", stats[i].name,
968 968 stats[i].value.ui64);
969 969 }
970 970 }
971 971
972 972 for (i = 0; extras[i]; i++) {
973 973 uint64_t buf;
974 974
975 975 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, extras[i], &sym) == -1) {
976 976 mdb_warn("failed to find '%s'", extras[i]);
977 977 return (DCMD_ERR);
978 978 }
979 979
980 980 if (sym.st_size != sizeof (uint64_t) &&
981 981 sym.st_size != sizeof (uint32_t)) {
982 982 mdb_warn("expected scalar for variable '%s'\n",
983 983 extras[i]);
984 984 return (DCMD_ERR);
985 985 }
986 986
987 987 if (mdb_vread(&buf, sym.st_size, sym.st_value) == -1) {
988 988 mdb_warn("couldn't read '%s'", extras[i]);
989 989 return (DCMD_ERR);
990 990 }
991 991
992 992 mdb_printf("%-25s = ", extras[i]);
993 993
994 994 /* NB: all the 64-bit extras happen to be byte counts */
995 995 if (sym.st_size == sizeof (uint64_t))
996 996 mdb_printf("%9llu %s\n", buf >> shift, suffix);
997 997
998 998 if (sym.st_size == sizeof (uint32_t))
999 999 mdb_printf("%9d\n", *((uint32_t *)&buf));
1000 1000 }
1001 1001 return (DCMD_OK);
1002 1002 }
1003 1003
1004 1004 typedef struct mdb_spa_print {
1005 1005 pool_state_t spa_state;
1006 1006 char spa_name[MAXNAMELEN];
1007 1007 } mdb_spa_print_t;
1008 1008
1009 1009 /*
1010 1010 * ::spa
1011 1011 *
1012 1012 * -c Print configuration information as well
1013 1013 * -v Print vdev state
1014 1014 * -e Print vdev error stats
1015 1015 *
1016 1016 * Print a summarized spa_t. When given no arguments, prints out a table of all
1017 1017 * active pools on the system.
1018 1018 */
1019 1019 /* ARGSUSED */
1020 1020 static int
1021 1021 spa_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1022 1022 {
1023 1023 const char *statetab[] = { "ACTIVE", "EXPORTED", "DESTROYED",
1024 1024 "SPARE", "L2CACHE", "UNINIT", "UNAVAIL", "POTENTIAL" };
1025 1025 const char *state;
1026 1026 int config = FALSE;
1027 1027 int vdevs = FALSE;
1028 1028 int errors = FALSE;
1029 1029
1030 1030 if (mdb_getopts(argc, argv,
1031 1031 'c', MDB_OPT_SETBITS, TRUE, &config,
1032 1032 'v', MDB_OPT_SETBITS, TRUE, &vdevs,
1033 1033 'e', MDB_OPT_SETBITS, TRUE, &errors,
1034 1034 NULL) != argc)
1035 1035 return (DCMD_USAGE);
1036 1036
1037 1037 if (!(flags & DCMD_ADDRSPEC)) {
1038 1038 if (mdb_walk_dcmd("spa", "spa", argc, argv) == -1) {
1039 1039 mdb_warn("can't walk spa");
1040 1040 return (DCMD_ERR);
1041 1041 }
1042 1042
1043 1043 return (DCMD_OK);
1044 1044 }
1045 1045
1046 1046 if (flags & DCMD_PIPE_OUT) {
1047 1047 mdb_printf("%#lr\n", addr);
1048 1048 return (DCMD_OK);
1049 1049 }
1050 1050
1051 1051 if (DCMD_HDRSPEC(flags))
1052 1052 mdb_printf("%<u>%-?s %9s %-*s%</u>\n", "ADDR", "STATE",
1053 1053 sizeof (uintptr_t) == 4 ? 60 : 52, "NAME");
1054 1054
1055 1055 mdb_spa_print_t spa;
1056 1056 if (mdb_ctf_vread(&spa, "spa_t", "mdb_spa_print_t", addr, 0) == -1)
1057 1057 return (DCMD_ERR);
1058 1058
1059 1059 if (spa.spa_state < 0 || spa.spa_state > POOL_STATE_UNAVAIL)
1060 1060 state = "UNKNOWN";
1061 1061 else
1062 1062 state = statetab[spa.spa_state];
1063 1063
1064 1064 mdb_printf("%0?p %9s %s\n", addr, state, spa.spa_name);
1065 1065
1066 1066 if (config) {
1067 1067 mdb_printf("\n");
1068 1068 mdb_inc_indent(4);
1069 1069 if (mdb_call_dcmd("spa_config", addr, flags, 0,
1070 1070 NULL) != DCMD_OK)
1071 1071 return (DCMD_ERR);
1072 1072 mdb_dec_indent(4);
1073 1073 }
1074 1074
1075 1075 if (vdevs || errors) {
1076 1076 mdb_arg_t v;
1077 1077
1078 1078 v.a_type = MDB_TYPE_STRING;
1079 1079 v.a_un.a_str = "-e";
1080 1080
1081 1081 mdb_printf("\n");
1082 1082 mdb_inc_indent(4);
1083 1083 if (mdb_call_dcmd("spa_vdevs", addr, flags, errors ? 1 : 0,
1084 1084 &v) != DCMD_OK)
1085 1085 return (DCMD_ERR);
1086 1086 mdb_dec_indent(4);
1087 1087 }
1088 1088
1089 1089 return (DCMD_OK);
1090 1090 }
1091 1091
1092 1092 typedef struct mdb_spa_config_spa {
1093 1093 uintptr_t spa_config;
1094 1094 } mdb_spa_config_spa_t;
1095 1095
1096 1096 /*
1097 1097 * ::spa_config
1098 1098 *
1099 1099 * Given a spa_t, print the configuration information stored in spa_config.
1100 1100 * Since it's just an nvlist, format it as an indented list of name=value pairs.
1101 1101 * We simply read the value of spa_config and pass off to ::nvlist.
1102 1102 */
1103 1103 /* ARGSUSED */
1104 1104 static int
1105 1105 spa_print_config(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1106 1106 {
1107 1107 mdb_spa_config_spa_t spa;
1108 1108
1109 1109 if (argc != 0 || !(flags & DCMD_ADDRSPEC))
1110 1110 return (DCMD_USAGE);
1111 1111
1112 1112 if (mdb_ctf_vread(&spa, ZFS_STRUCT "spa", "mdb_spa_config_spa_t",
1113 1113 addr, 0) == -1)
1114 1114 return (DCMD_ERR);
1115 1115
1116 1116 if (spa.spa_config == 0) {
1117 1117 mdb_printf("(none)\n");
1118 1118 return (DCMD_OK);
1119 1119 }
1120 1120
1121 1121 return (mdb_call_dcmd("nvlist", spa.spa_config, flags,
1122 1122 0, NULL));
1123 1123 }
1124 1124
1125 1125 /*
1126 1126 * ::vdev
1127 1127 *
1128 1128 * Print out a summarized vdev_t, in the following form:
1129 1129 *
1130 1130 * ADDR STATE AUX DESC
1131 1131 * fffffffbcde23df0 HEALTHY - /dev/dsk/c0t0d0
1132 1132 *
1133 1133 * If '-r' is specified, recursively visit all children.
1134 1134 *
1135 1135 * With '-e', the statistics associated with the vdev are printed as well.
1136 1136 */
1137 1137 static int
1138 1138 do_print_vdev(uintptr_t addr, int flags, int depth, int stats,
1139 1139 int recursive)
1140 1140 {
1141 1141 vdev_t vdev;
1142 1142 char desc[MAXNAMELEN];
1143 1143 int c, children;
1144 1144 uintptr_t *child;
1145 1145 const char *state, *aux;
1146 1146
1147 1147 if (mdb_vread(&vdev, sizeof (vdev), (uintptr_t)addr) == -1) {
1148 1148 mdb_warn("failed to read vdev_t at %p\n", (uintptr_t)addr);
1149 1149 return (DCMD_ERR);
1150 1150 }
1151 1151
1152 1152 if (flags & DCMD_PIPE_OUT) {
1153 1153 mdb_printf("%#lr\n", addr);
1154 1154 } else {
1155 1155 if (vdev.vdev_path != NULL) {
1156 1156 if (mdb_readstr(desc, sizeof (desc),
1157 1157 (uintptr_t)vdev.vdev_path) == -1) {
1158 1158 mdb_warn("failed to read vdev_path at %p\n",
1159 1159 vdev.vdev_path);
1160 1160 return (DCMD_ERR);
1161 1161 }
1162 1162 } else if (vdev.vdev_ops != NULL) {
1163 1163 vdev_ops_t ops;
1164 1164 if (mdb_vread(&ops, sizeof (ops),
1165 1165 (uintptr_t)vdev.vdev_ops) == -1) {
1166 1166 mdb_warn("failed to read vdev_ops at %p\n",
1167 1167 vdev.vdev_ops);
1168 1168 return (DCMD_ERR);
1169 1169 }
1170 1170 (void) strcpy(desc, ops.vdev_op_type);
1171 1171 } else {
1172 1172 (void) strcpy(desc, "<unknown>");
1173 1173 }
1174 1174
1175 1175 if (depth == 0 && DCMD_HDRSPEC(flags))
1176 1176 mdb_printf("%<u>%-?s %-9s %-12s %-*s%</u>\n",
1177 1177 "ADDR", "STATE", "AUX",
1178 1178 sizeof (uintptr_t) == 4 ? 43 : 35,
1179 1179 "DESCRIPTION");
1180 1180
1181 1181 mdb_printf("%0?p ", addr);
1182 1182
1183 1183 switch (vdev.vdev_state) {
1184 1184 case VDEV_STATE_CLOSED:
1185 1185 state = "CLOSED";
1186 1186 break;
1187 1187 case VDEV_STATE_OFFLINE:
1188 1188 state = "OFFLINE";
1189 1189 break;
1190 1190 case VDEV_STATE_CANT_OPEN:
1191 1191 state = "CANT_OPEN";
1192 1192 break;
1193 1193 case VDEV_STATE_DEGRADED:
1194 1194 state = "DEGRADED";
1195 1195 break;
1196 1196 case VDEV_STATE_HEALTHY:
1197 1197 state = "HEALTHY";
1198 1198 break;
1199 1199 case VDEV_STATE_REMOVED:
1200 1200 state = "REMOVED";
1201 1201 break;
1202 1202 case VDEV_STATE_FAULTED:
1203 1203 state = "FAULTED";
1204 1204 break;
1205 1205 default:
1206 1206 state = "UNKNOWN";
1207 1207 break;
1208 1208 }
1209 1209
1210 1210 switch (vdev.vdev_stat.vs_aux) {
1211 1211 case VDEV_AUX_NONE:
1212 1212 aux = "-";
1213 1213 break;
1214 1214 case VDEV_AUX_OPEN_FAILED:
1215 1215 aux = "OPEN_FAILED";
1216 1216 break;
1217 1217 case VDEV_AUX_CORRUPT_DATA:
1218 1218 aux = "CORRUPT_DATA";
1219 1219 break;
1220 1220 case VDEV_AUX_NO_REPLICAS:
1221 1221 aux = "NO_REPLICAS";
1222 1222 break;
1223 1223 case VDEV_AUX_BAD_GUID_SUM:
1224 1224 aux = "BAD_GUID_SUM";
1225 1225 break;
1226 1226 case VDEV_AUX_TOO_SMALL:
1227 1227 aux = "TOO_SMALL";
1228 1228 break;
1229 1229 case VDEV_AUX_BAD_LABEL:
1230 1230 aux = "BAD_LABEL";
1231 1231 break;
1232 1232 case VDEV_AUX_VERSION_NEWER:
1233 1233 aux = "VERS_NEWER";
1234 1234 break;
1235 1235 case VDEV_AUX_VERSION_OLDER:
1236 1236 aux = "VERS_OLDER";
1237 1237 break;
1238 1238 case VDEV_AUX_UNSUP_FEAT:
1239 1239 aux = "UNSUP_FEAT";
1240 1240 break;
1241 1241 case VDEV_AUX_SPARED:
1242 1242 aux = "SPARED";
1243 1243 break;
1244 1244 case VDEV_AUX_ERR_EXCEEDED:
1245 1245 aux = "ERR_EXCEEDED";
1246 1246 break;
1247 1247 case VDEV_AUX_IO_FAILURE:
1248 1248 aux = "IO_FAILURE";
1249 1249 break;
1250 1250 case VDEV_AUX_BAD_LOG:
1251 1251 aux = "BAD_LOG";
1252 1252 break;
1253 1253 case VDEV_AUX_EXTERNAL:
1254 1254 aux = "EXTERNAL";
1255 1255 break;
1256 1256 case VDEV_AUX_SPLIT_POOL:
1257 1257 aux = "SPLIT_POOL";
1258 1258 break;
1259 1259 default:
1260 1260 aux = "UNKNOWN";
1261 1261 break;
1262 1262 }
1263 1263
1264 1264 mdb_printf("%-9s %-12s %*s%s\n", state, aux, depth, "", desc);
1265 1265
1266 1266 if (stats) {
1267 1267 vdev_stat_t *vs = &vdev.vdev_stat;
1268 1268 int i;
1269 1269
1270 1270 mdb_inc_indent(4);
1271 1271 mdb_printf("\n");
1272 1272 mdb_printf("%<u> %12s %12s %12s %12s "
1273 1273 "%12s%</u>\n", "READ", "WRITE", "FREE", "CLAIM",
1274 1274 "IOCTL");
1275 1275 mdb_printf("OPS ");
1276 1276 for (i = 1; i < ZIO_TYPES; i++)
1277 1277 mdb_printf("%11#llx%s", vs->vs_ops[i],
1278 1278 i == ZIO_TYPES - 1 ? "" : " ");
1279 1279 mdb_printf("\n");
1280 1280 mdb_printf("BYTES ");
1281 1281 for (i = 1; i < ZIO_TYPES; i++)
1282 1282 mdb_printf("%11#llx%s", vs->vs_bytes[i],
1283 1283 i == ZIO_TYPES - 1 ? "" : " ");
1284 1284
1285 1285
1286 1286 mdb_printf("\n");
1287 1287 mdb_printf("EREAD %10#llx\n", vs->vs_read_errors);
1288 1288 mdb_printf("EWRITE %10#llx\n", vs->vs_write_errors);
1289 1289 mdb_printf("ECKSUM %10#llx\n",
1290 1290 vs->vs_checksum_errors);
1291 1291 mdb_dec_indent(4);
1292 1292 }
1293 1293
1294 1294 if (stats)
1295 1295 mdb_printf("\n");
1296 1296 }
1297 1297
1298 1298 children = vdev.vdev_children;
1299 1299
1300 1300 if (children == 0 || !recursive)
1301 1301 return (DCMD_OK);
1302 1302
1303 1303 child = mdb_alloc(children * sizeof (void *), UM_SLEEP | UM_GC);
1304 1304 if (mdb_vread(child, children * sizeof (void *),
1305 1305 (uintptr_t)vdev.vdev_child) == -1) {
1306 1306 mdb_warn("failed to read vdev children at %p", vdev.vdev_child);
1307 1307 return (DCMD_ERR);
1308 1308 }
1309 1309
1310 1310 for (c = 0; c < children; c++) {
1311 1311 if (do_print_vdev(child[c], flags, depth + 2, stats,
1312 1312 recursive))
1313 1313 return (DCMD_ERR);
1314 1314 }
1315 1315
1316 1316 return (DCMD_OK);
1317 1317 }
1318 1318
1319 1319 static int
1320 1320 vdev_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1321 1321 {
1322 1322 int recursive = FALSE;
1323 1323 int stats = FALSE;
1324 1324 uint64_t depth = 0;
1325 1325
1326 1326 if (mdb_getopts(argc, argv,
1327 1327 'r', MDB_OPT_SETBITS, TRUE, &recursive,
1328 1328 'e', MDB_OPT_SETBITS, TRUE, &stats,
1329 1329 'd', MDB_OPT_UINT64, &depth,
1330 1330 NULL) != argc)
1331 1331 return (DCMD_USAGE);
1332 1332
1333 1333 if (!(flags & DCMD_ADDRSPEC)) {
1334 1334 mdb_warn("no vdev_t address given\n");
1335 1335 return (DCMD_ERR);
1336 1336 }
1337 1337
1338 1338 return (do_print_vdev(addr, flags, (int)depth, stats, recursive));
1339 1339 }
1340 1340
1341 1341 typedef struct metaslab_walk_data {
1342 1342 uint64_t mw_numvdevs;
1343 1343 uintptr_t *mw_vdevs;
1344 1344 int mw_curvdev;
1345 1345 uint64_t mw_nummss;
1346 1346 uintptr_t *mw_mss;
1347 1347 int mw_curms;
1348 1348 } metaslab_walk_data_t;
1349 1349
1350 1350 static int
1351 1351 metaslab_walk_step(mdb_walk_state_t *wsp)
1352 1352 {
1353 1353 metaslab_walk_data_t *mw = wsp->walk_data;
1354 1354 metaslab_t ms;
1355 1355 uintptr_t msp;
1356 1356
1357 1357 if (mw->mw_curvdev >= mw->mw_numvdevs)
1358 1358 return (WALK_DONE);
1359 1359
1360 1360 if (mw->mw_mss == NULL) {
1361 1361 uintptr_t mssp;
1362 1362 uintptr_t vdevp;
1363 1363
1364 1364 ASSERT(mw->mw_curms == 0);
1365 1365 ASSERT(mw->mw_nummss == 0);
1366 1366
1367 1367 vdevp = mw->mw_vdevs[mw->mw_curvdev];
1368 1368 if (GETMEMB(vdevp, "vdev", vdev_ms, mssp) ||
1369 1369 GETMEMB(vdevp, "vdev", vdev_ms_count, mw->mw_nummss)) {
1370 1370 return (WALK_ERR);
1371 1371 }
1372 1372
1373 1373 mw->mw_mss = mdb_alloc(mw->mw_nummss * sizeof (void*),
1374 1374 UM_SLEEP | UM_GC);
1375 1375 if (mdb_vread(mw->mw_mss, mw->mw_nummss * sizeof (void*),
1376 1376 mssp) == -1) {
1377 1377 mdb_warn("failed to read vdev_ms at %p", mssp);
1378 1378 return (WALK_ERR);
1379 1379 }
1380 1380 }
1381 1381
1382 1382 if (mw->mw_curms >= mw->mw_nummss) {
1383 1383 mw->mw_mss = NULL;
1384 1384 mw->mw_curms = 0;
1385 1385 mw->mw_nummss = 0;
1386 1386 mw->mw_curvdev++;
1387 1387 return (WALK_NEXT);
1388 1388 }
1389 1389
1390 1390 msp = mw->mw_mss[mw->mw_curms];
1391 1391 if (mdb_vread(&ms, sizeof (metaslab_t), msp) == -1) {
1392 1392 mdb_warn("failed to read metaslab_t at %p", msp);
1393 1393 return (WALK_ERR);
1394 1394 }
1395 1395
1396 1396 mw->mw_curms++;
1397 1397
1398 1398 return (wsp->walk_callback(msp, &ms, wsp->walk_cbdata));
1399 1399 }
1400 1400
1401 1401 /* ARGSUSED */
1402 1402 static int
1403 1403 metaslab_walk_init(mdb_walk_state_t *wsp)
1404 1404 {
1405 1405 metaslab_walk_data_t *mw;
1406 1406 uintptr_t root_vdevp;
1407 1407 uintptr_t childp;
1408 1408
1409 1409 if (wsp->walk_addr == NULL) {
1410 1410 mdb_warn("must supply address of spa_t\n");
1411 1411 return (WALK_ERR);
1412 1412 }
1413 1413
1414 1414 mw = mdb_zalloc(sizeof (metaslab_walk_data_t), UM_SLEEP | UM_GC);
1415 1415
1416 1416 if (GETMEMB(wsp->walk_addr, "spa", spa_root_vdev, root_vdevp) ||
1417 1417 GETMEMB(root_vdevp, "vdev", vdev_children, mw->mw_numvdevs) ||
1418 1418 GETMEMB(root_vdevp, "vdev", vdev_child, childp)) {
1419 1419 return (DCMD_ERR);
1420 1420 }
1421 1421
1422 1422 mw->mw_vdevs = mdb_alloc(mw->mw_numvdevs * sizeof (void *),
1423 1423 UM_SLEEP | UM_GC);
1424 1424 if (mdb_vread(mw->mw_vdevs, mw->mw_numvdevs * sizeof (void *),
1425 1425 childp) == -1) {
1426 1426 mdb_warn("failed to read root vdev children at %p", childp);
1427 1427 return (DCMD_ERR);
1428 1428 }
1429 1429
1430 1430 wsp->walk_data = mw;
1431 1431
1432 1432 return (WALK_NEXT);
1433 1433 }
1434 1434
1435 1435 typedef struct mdb_spa {
1436 1436 uintptr_t spa_dsl_pool;
1437 1437 uintptr_t spa_root_vdev;
1438 1438 } mdb_spa_t;
1439 1439
1440 1440 typedef struct mdb_dsl_dir {
1441 1441 uintptr_t dd_phys;
1442 1442 int64_t dd_space_towrite[TXG_SIZE];
1443 1443 } mdb_dsl_dir_t;
1444 1444
1445 1445 typedef struct mdb_dsl_dir_phys {
1446 1446 uint64_t dd_used_bytes;
1447 1447 uint64_t dd_compressed_bytes;
↓ open down ↓ |
1447 lines elided |
↑ open up ↑ |
1448 1448 uint64_t dd_uncompressed_bytes;
1449 1449 } mdb_dsl_dir_phys_t;
1450 1450
1451 1451 typedef struct mdb_vdev {
1452 1452 uintptr_t vdev_parent;
1453 1453 uintptr_t vdev_ms;
1454 1454 uint64_t vdev_ms_count;
1455 1455 vdev_stat_t vdev_stat;
1456 1456 } mdb_vdev_t;
1457 1457
1458 +typedef struct mdb_space_map_phys_t {
1459 + uint64_t smp_alloc;
1460 +} mdb_space_map_phys_t;
1461 +
1462 +typedef struct mdb_space_map {
1463 + uint64_t sm_size;
1464 + uint64_t sm_alloc;
1465 + uintptr_t sm_phys;
1466 +} mdb_space_map_t;
1467 +
1468 +typedef struct mdb_range_tree {
1469 + uint64_t rt_space;
1470 +} mdb_range_tree_t;
1471 +
1458 1472 typedef struct mdb_metaslab {
1459 - space_map_t ms_allocmap[TXG_SIZE];
1460 - space_map_t ms_freemap[TXG_SIZE];
1461 - space_map_t ms_map;
1462 - space_map_obj_t ms_smo;
1463 - space_map_obj_t ms_smo_syncing;
1473 + uintptr_t ms_alloctree[TXG_SIZE];
1474 + uintptr_t ms_freetree[TXG_SIZE];
1475 + uintptr_t ms_tree;
1476 + uintptr_t ms_sm;
1464 1477 } mdb_metaslab_t;
1465 1478
1466 1479 typedef struct space_data {
1467 - uint64_t ms_allocmap[TXG_SIZE];
1468 - uint64_t ms_freemap[TXG_SIZE];
1469 - uint64_t ms_map;
1480 + uint64_t ms_alloctree[TXG_SIZE];
1481 + uint64_t ms_freetree[TXG_SIZE];
1482 + uint64_t ms_tree;
1470 1483 uint64_t avail;
1471 1484 uint64_t nowavail;
1472 1485 } space_data_t;
1473 1486
1474 1487 /* ARGSUSED */
1475 1488 static int
1476 1489 space_cb(uintptr_t addr, const void *unknown, void *arg)
1477 1490 {
1478 1491 space_data_t *sd = arg;
1479 1492 mdb_metaslab_t ms;
1493 + mdb_range_tree_t rt;
1494 + mdb_space_map_t sm;
1495 + mdb_space_map_phys_t smp = { 0 };
1496 + int i;
1480 1497
1481 - if (GETMEMB(addr, "metaslab", ms_allocmap, ms.ms_allocmap) ||
1482 - GETMEMB(addr, "metaslab", ms_freemap, ms.ms_freemap) ||
1483 - GETMEMB(addr, "metaslab", ms_map, ms.ms_map) ||
1484 - GETMEMB(addr, "metaslab", ms_smo, ms.ms_smo) ||
1485 - GETMEMB(addr, "metaslab", ms_smo_syncing, ms.ms_smo_syncing)) {
1498 + if (mdb_ctf_vread(&ms, "metaslab_t", "mdb_metaslab_t",
1499 + addr, 0) == -1)
1486 1500 return (WALK_ERR);
1501 +
1502 + for (i = 0; i < TXG_SIZE; i++) {
1503 +
1504 + if (mdb_ctf_vread(&rt, "range_tree_t",
1505 + "mdb_range_tree_t", ms.ms_alloctree[i], 0) == -1)
1506 + sd->ms_alloctree[i] += rt.rt_space;
1507 +
1508 + if (mdb_ctf_vread(&rt, "range_tree_t",
1509 + "mdb_range_tree_t", ms.ms_freetree[i], 0) == -1)
1510 + sd->ms_freetree[i] += rt.rt_space;
1487 1511 }
1488 1512
1489 - sd->ms_allocmap[0] += ms.ms_allocmap[0].sm_space;
1490 - sd->ms_allocmap[1] += ms.ms_allocmap[1].sm_space;
1491 - sd->ms_allocmap[2] += ms.ms_allocmap[2].sm_space;
1492 - sd->ms_allocmap[3] += ms.ms_allocmap[3].sm_space;
1493 - sd->ms_freemap[0] += ms.ms_freemap[0].sm_space;
1494 - sd->ms_freemap[1] += ms.ms_freemap[1].sm_space;
1495 - sd->ms_freemap[2] += ms.ms_freemap[2].sm_space;
1496 - sd->ms_freemap[3] += ms.ms_freemap[3].sm_space;
1497 - sd->ms_map += ms.ms_map.sm_space;
1498 - sd->avail += ms.ms_map.sm_size - ms.ms_smo.smo_alloc;
1499 - sd->nowavail += ms.ms_map.sm_size - ms.ms_smo_syncing.smo_alloc;
1513 + if (mdb_ctf_vread(&rt, "range_tree_t",
1514 + "mdb_range_tree_t", ms.ms_tree, 0) == -1 ||
1515 + mdb_ctf_vread(&sm, "space_map_t",
1516 + "mdb_space_map_t", ms.ms_sm, 0) == -1)
1517 + return (WALK_ERR);
1500 1518
1519 + if (sm.sm_phys != NULL) {
1520 + (void) mdb_ctf_vread(&smp, "space_map_phys_t",
1521 + "mdb_space_map_phys_t", sm.sm_phys, 0);
1522 + }
1523 +
1524 + sd->ms_tree += rt.rt_space;
1525 + sd->avail += sm.sm_size - sm.sm_alloc;
1526 + sd->nowavail += sm.sm_size - smp.smp_alloc;
1527 +
1501 1528 return (WALK_NEXT);
1502 1529 }
1503 1530
1504 1531 /*
1505 1532 * ::spa_space [-b]
1506 1533 *
1507 1534 * Given a spa_t, print out it's on-disk space usage and in-core
1508 1535 * estimates of future usage. If -b is given, print space in bytes.
1509 1536 * Otherwise print in megabytes.
1510 1537 */
1511 1538 /* ARGSUSED */
1512 1539 static int
1513 1540 spa_space(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1514 1541 {
1515 1542 mdb_spa_t spa;
1516 1543 uintptr_t dp_root_dir;
1517 1544 mdb_dsl_dir_t dd;
1518 1545 mdb_dsl_dir_phys_t dsp;
1519 1546 uint64_t children;
1520 1547 uintptr_t childaddr;
1521 1548 space_data_t sd;
1522 1549 int shift = 20;
1523 1550 char *suffix = "M";
1524 1551 int bytes = B_FALSE;
1525 1552
1526 1553 if (mdb_getopts(argc, argv, 'b', MDB_OPT_SETBITS, TRUE, &bytes, NULL) !=
1527 1554 argc)
1528 1555 return (DCMD_USAGE);
1529 1556 if (!(flags & DCMD_ADDRSPEC))
1530 1557 return (DCMD_USAGE);
1531 1558
1532 1559 if (bytes) {
1533 1560 shift = 0;
1534 1561 suffix = "";
1535 1562 }
1536 1563
1537 1564 if (GETMEMB(addr, "spa", spa_dsl_pool, spa.spa_dsl_pool) ||
1538 1565 GETMEMB(addr, "spa", spa_root_vdev, spa.spa_root_vdev) ||
1539 1566 GETMEMB(spa.spa_root_vdev, "vdev", vdev_children, children) ||
1540 1567 GETMEMB(spa.spa_root_vdev, "vdev", vdev_child, childaddr) ||
1541 1568 GETMEMB(spa.spa_dsl_pool, "dsl_pool",
1542 1569 dp_root_dir, dp_root_dir) ||
1543 1570 GETMEMB(dp_root_dir, "dsl_dir", dd_phys, dd.dd_phys) ||
1544 1571 GETMEMB(dp_root_dir, "dsl_dir",
1545 1572 dd_space_towrite, dd.dd_space_towrite) ||
1546 1573 GETMEMB(dd.dd_phys, "dsl_dir_phys",
1547 1574 dd_used_bytes, dsp.dd_used_bytes) ||
1548 1575 GETMEMB(dd.dd_phys, "dsl_dir_phys",
1549 1576 dd_compressed_bytes, dsp.dd_compressed_bytes) ||
1550 1577 GETMEMB(dd.dd_phys, "dsl_dir_phys",
1551 1578 dd_uncompressed_bytes, dsp.dd_uncompressed_bytes)) {
1552 1579 return (DCMD_ERR);
1553 1580 }
1554 1581
1555 1582 mdb_printf("dd_space_towrite = %llu%s %llu%s %llu%s %llu%s\n",
1556 1583 dd.dd_space_towrite[0] >> shift, suffix,
1557 1584 dd.dd_space_towrite[1] >> shift, suffix,
1558 1585 dd.dd_space_towrite[2] >> shift, suffix,
1559 1586 dd.dd_space_towrite[3] >> shift, suffix);
1560 1587
1561 1588 mdb_printf("dd_phys.dd_used_bytes = %llu%s\n",
1562 1589 dsp.dd_used_bytes >> shift, suffix);
1563 1590 mdb_printf("dd_phys.dd_compressed_bytes = %llu%s\n",
1564 1591 dsp.dd_compressed_bytes >> shift, suffix);
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
1565 1592 mdb_printf("dd_phys.dd_uncompressed_bytes = %llu%s\n",
1566 1593 dsp.dd_uncompressed_bytes >> shift, suffix);
1567 1594
1568 1595 bzero(&sd, sizeof (sd));
1569 1596 if (mdb_pwalk("metaslab", space_cb, &sd, addr) != 0) {
1570 1597 mdb_warn("can't walk metaslabs");
1571 1598 return (DCMD_ERR);
1572 1599 }
1573 1600
1574 1601 mdb_printf("ms_allocmap = %llu%s %llu%s %llu%s %llu%s\n",
1575 - sd.ms_allocmap[0] >> shift, suffix,
1576 - sd.ms_allocmap[1] >> shift, suffix,
1577 - sd.ms_allocmap[2] >> shift, suffix,
1578 - sd.ms_allocmap[3] >> shift, suffix);
1602 + sd.ms_alloctree[0] >> shift, suffix,
1603 + sd.ms_alloctree[1] >> shift, suffix,
1604 + sd.ms_alloctree[2] >> shift, suffix,
1605 + sd.ms_alloctree[3] >> shift, suffix);
1579 1606 mdb_printf("ms_freemap = %llu%s %llu%s %llu%s %llu%s\n",
1580 - sd.ms_freemap[0] >> shift, suffix,
1581 - sd.ms_freemap[1] >> shift, suffix,
1582 - sd.ms_freemap[2] >> shift, suffix,
1583 - sd.ms_freemap[3] >> shift, suffix);
1584 - mdb_printf("ms_map = %llu%s\n", sd.ms_map >> shift, suffix);
1607 + sd.ms_freetree[0] >> shift, suffix,
1608 + sd.ms_freetree[1] >> shift, suffix,
1609 + sd.ms_freetree[2] >> shift, suffix,
1610 + sd.ms_freetree[3] >> shift, suffix);
1611 + mdb_printf("ms_tree = %llu%s\n", sd.ms_tree >> shift, suffix);
1585 1612 mdb_printf("last synced avail = %llu%s\n", sd.avail >> shift, suffix);
1586 1613 mdb_printf("current syncing avail = %llu%s\n",
1587 1614 sd.nowavail >> shift, suffix);
1588 1615
1589 1616 return (DCMD_OK);
1590 1617 }
1591 1618
1592 1619 typedef struct mdb_spa_aux_vdev {
1593 1620 int sav_count;
1594 1621 uintptr_t sav_vdevs;
1595 1622 } mdb_spa_aux_vdev_t;
1596 1623
1597 1624 typedef struct mdb_spa_vdevs {
1598 1625 uintptr_t spa_root_vdev;
1599 1626 mdb_spa_aux_vdev_t spa_l2cache;
1600 1627 mdb_spa_aux_vdev_t spa_spares;
1601 1628 } mdb_spa_vdevs_t;
1602 1629
1603 1630 static int
1604 1631 spa_print_aux(mdb_spa_aux_vdev_t *sav, uint_t flags, mdb_arg_t *v,
1605 1632 const char *name)
1606 1633 {
1607 1634 uintptr_t *aux;
1608 1635 size_t len;
1609 1636 int ret, i;
1610 1637
1611 1638 /*
1612 1639 * Iterate over aux vdevs and print those out as well. This is a
1613 1640 * little annoying because we don't have a root vdev to pass to ::vdev.
1614 1641 * Instead, we print a single line and then call it for each child
1615 1642 * vdev.
1616 1643 */
1617 1644 if (sav->sav_count != 0) {
1618 1645 v[1].a_type = MDB_TYPE_STRING;
1619 1646 v[1].a_un.a_str = "-d";
1620 1647 v[2].a_type = MDB_TYPE_IMMEDIATE;
1621 1648 v[2].a_un.a_val = 2;
1622 1649
1623 1650 len = sav->sav_count * sizeof (uintptr_t);
1624 1651 aux = mdb_alloc(len, UM_SLEEP);
1625 1652 if (mdb_vread(aux, len, sav->sav_vdevs) == -1) {
1626 1653 mdb_free(aux, len);
1627 1654 mdb_warn("failed to read l2cache vdevs at %p",
1628 1655 sav->sav_vdevs);
1629 1656 return (DCMD_ERR);
1630 1657 }
1631 1658
1632 1659 mdb_printf("%-?s %-9s %-12s %s\n", "-", "-", "-", name);
1633 1660
1634 1661 for (i = 0; i < sav->sav_count; i++) {
1635 1662 ret = mdb_call_dcmd("vdev", aux[i], flags, 3, v);
1636 1663 if (ret != DCMD_OK) {
1637 1664 mdb_free(aux, len);
1638 1665 return (ret);
1639 1666 }
1640 1667 }
1641 1668
1642 1669 mdb_free(aux, len);
1643 1670 }
1644 1671
1645 1672 return (0);
1646 1673 }
1647 1674
1648 1675 /*
1649 1676 * ::spa_vdevs
1650 1677 *
1651 1678 * -e Include error stats
1652 1679 *
1653 1680 * Print out a summarized list of vdevs for the given spa_t.
1654 1681 * This is accomplished by invoking "::vdev -re" on the root vdev, as well as
1655 1682 * iterating over the cache devices.
1656 1683 */
1657 1684 /* ARGSUSED */
1658 1685 static int
1659 1686 spa_vdevs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1660 1687 {
1661 1688 mdb_arg_t v[3];
1662 1689 int errors = FALSE;
1663 1690 int ret;
1664 1691
1665 1692 if (mdb_getopts(argc, argv,
1666 1693 'e', MDB_OPT_SETBITS, TRUE, &errors,
1667 1694 NULL) != argc)
1668 1695 return (DCMD_USAGE);
1669 1696
1670 1697 if (!(flags & DCMD_ADDRSPEC))
1671 1698 return (DCMD_USAGE);
1672 1699
1673 1700 mdb_spa_vdevs_t spa;
1674 1701 if (mdb_ctf_vread(&spa, "spa_t", "mdb_spa_vdevs_t", addr, 0) == -1)
1675 1702 return (DCMD_ERR);
1676 1703
1677 1704 /*
1678 1705 * Unitialized spa_t structures can have a NULL root vdev.
1679 1706 */
1680 1707 if (spa.spa_root_vdev == NULL) {
1681 1708 mdb_printf("no associated vdevs\n");
1682 1709 return (DCMD_OK);
1683 1710 }
1684 1711
1685 1712 v[0].a_type = MDB_TYPE_STRING;
1686 1713 v[0].a_un.a_str = errors ? "-re" : "-r";
1687 1714
1688 1715 ret = mdb_call_dcmd("vdev", (uintptr_t)spa.spa_root_vdev,
1689 1716 flags, 1, v);
1690 1717 if (ret != DCMD_OK)
1691 1718 return (ret);
1692 1719
1693 1720 if (spa_print_aux(&spa.spa_l2cache, flags, v, "cache") != 0 ||
1694 1721 spa_print_aux(&spa.spa_spares, flags, v, "spares") != 0)
1695 1722 return (DCMD_ERR);
1696 1723
1697 1724 return (DCMD_OK);
1698 1725 }
1699 1726
1700 1727 /*
1701 1728 * ::zio
1702 1729 *
1703 1730 * Print a summary of zio_t and all its children. This is intended to display a
1704 1731 * zio tree, and hence we only pick the most important pieces of information for
1705 1732 * the main summary. More detailed information can always be found by doing a
1706 1733 * '::print zio' on the underlying zio_t. The columns we display are:
1707 1734 *
1708 1735 * ADDRESS TYPE STAGE WAITER TIME_ELAPSED
1709 1736 *
1710 1737 * The 'address' column is indented by one space for each depth level as we
1711 1738 * descend down the tree.
1712 1739 */
1713 1740
1714 1741 #define ZIO_MAXINDENT 7
1715 1742 #define ZIO_MAXWIDTH (sizeof (uintptr_t) * 2 + ZIO_MAXINDENT)
1716 1743 #define ZIO_WALK_SELF 0
1717 1744 #define ZIO_WALK_CHILD 1
1718 1745 #define ZIO_WALK_PARENT 2
1719 1746
1720 1747 typedef struct zio_print_args {
1721 1748 int zpa_current_depth;
1722 1749 int zpa_min_depth;
1723 1750 int zpa_max_depth;
1724 1751 int zpa_type;
1725 1752 uint_t zpa_flags;
1726 1753 } zio_print_args_t;
1727 1754
1728 1755 typedef struct mdb_zio {
1729 1756 enum zio_type io_type;
1730 1757 enum zio_stage io_stage;
1731 1758 uintptr_t io_waiter;
1732 1759 uintptr_t io_spa;
1733 1760 struct {
1734 1761 struct {
1735 1762 uintptr_t list_next;
1736 1763 } list_head;
1737 1764 } io_parent_list;
1738 1765 int io_error;
1739 1766 } mdb_zio_t;
1740 1767
1741 1768 typedef struct mdb_zio_timestamp {
1742 1769 hrtime_t io_timestamp;
1743 1770 } mdb_zio_timestamp_t;
1744 1771
1745 1772 static int zio_child_cb(uintptr_t addr, const void *unknown, void *arg);
1746 1773
1747 1774 static int
1748 1775 zio_print_cb(uintptr_t addr, zio_print_args_t *zpa)
1749 1776 {
1750 1777 mdb_ctf_id_t type_enum, stage_enum;
1751 1778 int indent = zpa->zpa_current_depth;
1752 1779 const char *type, *stage;
1753 1780 uintptr_t laddr;
1754 1781 mdb_zio_t zio;
1755 1782 mdb_zio_timestamp_t zio_timestamp = { 0 };
1756 1783
1757 1784 if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t", addr, 0) == -1)
1758 1785 return (WALK_ERR);
1759 1786 (void) mdb_ctf_vread(&zio_timestamp, ZFS_STRUCT "zio",
1760 1787 "mdb_zio_timestamp_t", addr, MDB_CTF_VREAD_QUIET);
1761 1788
1762 1789 if (indent > ZIO_MAXINDENT)
1763 1790 indent = ZIO_MAXINDENT;
1764 1791
1765 1792 if (mdb_ctf_lookup_by_name("enum zio_type", &type_enum) == -1 ||
1766 1793 mdb_ctf_lookup_by_name("enum zio_stage", &stage_enum) == -1) {
1767 1794 mdb_warn("failed to lookup zio enums");
1768 1795 return (WALK_ERR);
1769 1796 }
1770 1797
1771 1798 if ((type = mdb_ctf_enum_name(type_enum, zio.io_type)) != NULL)
1772 1799 type += sizeof ("ZIO_TYPE_") - 1;
1773 1800 else
1774 1801 type = "?";
1775 1802
1776 1803 if (zio.io_error == 0) {
1777 1804 stage = mdb_ctf_enum_name(stage_enum, zio.io_stage);
1778 1805 if (stage != NULL)
1779 1806 stage += sizeof ("ZIO_STAGE_") - 1;
1780 1807 else
1781 1808 stage = "?";
1782 1809 } else {
1783 1810 stage = "FAILED";
1784 1811 }
1785 1812
1786 1813 if (zpa->zpa_current_depth >= zpa->zpa_min_depth) {
1787 1814 if (zpa->zpa_flags & DCMD_PIPE_OUT) {
1788 1815 mdb_printf("%?p\n", addr);
1789 1816 } else {
1790 1817 mdb_printf("%*s%-*p %-5s %-16s ", indent, "",
1791 1818 ZIO_MAXWIDTH - indent, addr, type, stage);
1792 1819 if (zio.io_waiter != 0)
1793 1820 mdb_printf("%-16lx ", zio.io_waiter);
1794 1821 else
1795 1822 mdb_printf("%-16s ", "-");
1796 1823 #ifdef _KERNEL
1797 1824 if (zio_timestamp.io_timestamp != 0) {
1798 1825 mdb_printf("%llums", (mdb_gethrtime() -
1799 1826 zio_timestamp.io_timestamp) /
1800 1827 1000000);
1801 1828 } else {
1802 1829 mdb_printf("%-12s ", "-");
1803 1830 }
1804 1831 #else
1805 1832 mdb_printf("%-12s ", "-");
1806 1833 #endif
1807 1834 mdb_printf("\n");
1808 1835 }
1809 1836 }
1810 1837
1811 1838 if (zpa->zpa_current_depth >= zpa->zpa_max_depth)
1812 1839 return (WALK_NEXT);
1813 1840
1814 1841 if (zpa->zpa_type == ZIO_WALK_PARENT)
1815 1842 laddr = addr + mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio",
1816 1843 "io_parent_list");
1817 1844 else
1818 1845 laddr = addr + mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio",
1819 1846 "io_child_list");
1820 1847
1821 1848 zpa->zpa_current_depth++;
1822 1849 if (mdb_pwalk("list", zio_child_cb, zpa, laddr) != 0) {
1823 1850 mdb_warn("failed to walk zio_t children at %p\n", laddr);
1824 1851 return (WALK_ERR);
1825 1852 }
1826 1853 zpa->zpa_current_depth--;
1827 1854
1828 1855 return (WALK_NEXT);
1829 1856 }
1830 1857
1831 1858 /* ARGSUSED */
1832 1859 static int
1833 1860 zio_child_cb(uintptr_t addr, const void *unknown, void *arg)
1834 1861 {
1835 1862 zio_link_t zl;
1836 1863 uintptr_t ziop;
1837 1864 zio_print_args_t *zpa = arg;
1838 1865
1839 1866 if (mdb_vread(&zl, sizeof (zl), addr) == -1) {
1840 1867 mdb_warn("failed to read zio_link_t at %p", addr);
1841 1868 return (WALK_ERR);
1842 1869 }
1843 1870
1844 1871 if (zpa->zpa_type == ZIO_WALK_PARENT)
1845 1872 ziop = (uintptr_t)zl.zl_parent;
1846 1873 else
1847 1874 ziop = (uintptr_t)zl.zl_child;
1848 1875
1849 1876 return (zio_print_cb(ziop, zpa));
1850 1877 }
1851 1878
1852 1879 /* ARGSUSED */
1853 1880 static int
1854 1881 zio_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1855 1882 {
1856 1883 zio_print_args_t zpa = { 0 };
1857 1884
1858 1885 if (!(flags & DCMD_ADDRSPEC))
1859 1886 return (DCMD_USAGE);
1860 1887
1861 1888 if (mdb_getopts(argc, argv,
1862 1889 'r', MDB_OPT_SETBITS, INT_MAX, &zpa.zpa_max_depth,
1863 1890 'c', MDB_OPT_SETBITS, ZIO_WALK_CHILD, &zpa.zpa_type,
1864 1891 'p', MDB_OPT_SETBITS, ZIO_WALK_PARENT, &zpa.zpa_type,
1865 1892 NULL) != argc)
1866 1893 return (DCMD_USAGE);
1867 1894
1868 1895 zpa.zpa_flags = flags;
1869 1896 if (zpa.zpa_max_depth != 0) {
1870 1897 if (zpa.zpa_type == ZIO_WALK_SELF)
1871 1898 zpa.zpa_type = ZIO_WALK_CHILD;
1872 1899 } else if (zpa.zpa_type != ZIO_WALK_SELF) {
1873 1900 zpa.zpa_min_depth = 1;
1874 1901 zpa.zpa_max_depth = 1;
1875 1902 }
1876 1903
1877 1904 if (!(flags & DCMD_PIPE_OUT) && DCMD_HDRSPEC(flags)) {
1878 1905 mdb_printf("%<u>%-*s %-5s %-16s %-16s %-12s%</u>\n",
1879 1906 ZIO_MAXWIDTH, "ADDRESS", "TYPE", "STAGE", "WAITER",
1880 1907 "TIME_ELAPSED");
1881 1908 }
1882 1909
1883 1910 if (zio_print_cb(addr, &zpa) != WALK_NEXT)
1884 1911 return (DCMD_ERR);
1885 1912
1886 1913 return (DCMD_OK);
1887 1914 }
1888 1915
1889 1916 /*
1890 1917 * [addr]::zio_state
1891 1918 *
1892 1919 * Print a summary of all zio_t structures on the system, or for a particular
1893 1920 * pool. This is equivalent to '::walk zio_root | ::zio'.
1894 1921 */
1895 1922 /*ARGSUSED*/
1896 1923 static int
1897 1924 zio_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1898 1925 {
1899 1926 /*
1900 1927 * MDB will remember the last address of the pipeline, so if we don't
1901 1928 * zero this we'll end up trying to walk zio structures for a
1902 1929 * non-existent spa_t.
1903 1930 */
1904 1931 if (!(flags & DCMD_ADDRSPEC))
1905 1932 addr = 0;
1906 1933
1907 1934 return (mdb_pwalk_dcmd("zio_root", "zio", argc, argv, addr));
1908 1935 }
1909 1936
1910 1937 typedef struct txg_list_walk_data {
1911 1938 uintptr_t lw_head[TXG_SIZE];
1912 1939 int lw_txgoff;
1913 1940 int lw_maxoff;
1914 1941 size_t lw_offset;
1915 1942 void *lw_obj;
1916 1943 } txg_list_walk_data_t;
1917 1944
1918 1945 static int
1919 1946 txg_list_walk_init_common(mdb_walk_state_t *wsp, int txg, int maxoff)
1920 1947 {
1921 1948 txg_list_walk_data_t *lwd;
1922 1949 txg_list_t list;
1923 1950 int i;
1924 1951
1925 1952 lwd = mdb_alloc(sizeof (txg_list_walk_data_t), UM_SLEEP | UM_GC);
1926 1953 if (mdb_vread(&list, sizeof (txg_list_t), wsp->walk_addr) == -1) {
1927 1954 mdb_warn("failed to read txg_list_t at %#lx", wsp->walk_addr);
1928 1955 return (WALK_ERR);
1929 1956 }
1930 1957
1931 1958 for (i = 0; i < TXG_SIZE; i++)
1932 1959 lwd->lw_head[i] = (uintptr_t)list.tl_head[i];
1933 1960 lwd->lw_offset = list.tl_offset;
1934 1961 lwd->lw_obj = mdb_alloc(lwd->lw_offset + sizeof (txg_node_t),
1935 1962 UM_SLEEP | UM_GC);
1936 1963 lwd->lw_txgoff = txg;
1937 1964 lwd->lw_maxoff = maxoff;
1938 1965
1939 1966 wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
1940 1967 wsp->walk_data = lwd;
1941 1968
1942 1969 return (WALK_NEXT);
1943 1970 }
1944 1971
1945 1972 static int
1946 1973 txg_list_walk_init(mdb_walk_state_t *wsp)
1947 1974 {
1948 1975 return (txg_list_walk_init_common(wsp, 0, TXG_SIZE-1));
1949 1976 }
1950 1977
1951 1978 static int
1952 1979 txg_list0_walk_init(mdb_walk_state_t *wsp)
1953 1980 {
1954 1981 return (txg_list_walk_init_common(wsp, 0, 0));
1955 1982 }
1956 1983
1957 1984 static int
1958 1985 txg_list1_walk_init(mdb_walk_state_t *wsp)
1959 1986 {
1960 1987 return (txg_list_walk_init_common(wsp, 1, 1));
1961 1988 }
1962 1989
1963 1990 static int
1964 1991 txg_list2_walk_init(mdb_walk_state_t *wsp)
1965 1992 {
1966 1993 return (txg_list_walk_init_common(wsp, 2, 2));
1967 1994 }
1968 1995
1969 1996 static int
1970 1997 txg_list3_walk_init(mdb_walk_state_t *wsp)
1971 1998 {
1972 1999 return (txg_list_walk_init_common(wsp, 3, 3));
1973 2000 }
1974 2001
1975 2002 static int
1976 2003 txg_list_walk_step(mdb_walk_state_t *wsp)
1977 2004 {
1978 2005 txg_list_walk_data_t *lwd = wsp->walk_data;
1979 2006 uintptr_t addr;
1980 2007 txg_node_t *node;
1981 2008 int status;
1982 2009
1983 2010 while (wsp->walk_addr == NULL && lwd->lw_txgoff < lwd->lw_maxoff) {
1984 2011 lwd->lw_txgoff++;
1985 2012 wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
1986 2013 }
1987 2014
1988 2015 if (wsp->walk_addr == NULL)
1989 2016 return (WALK_DONE);
1990 2017
1991 2018 addr = wsp->walk_addr - lwd->lw_offset;
1992 2019
1993 2020 if (mdb_vread(lwd->lw_obj,
1994 2021 lwd->lw_offset + sizeof (txg_node_t), addr) == -1) {
1995 2022 mdb_warn("failed to read list element at %#lx", addr);
1996 2023 return (WALK_ERR);
1997 2024 }
1998 2025
1999 2026 status = wsp->walk_callback(addr, lwd->lw_obj, wsp->walk_cbdata);
2000 2027 node = (txg_node_t *)((uintptr_t)lwd->lw_obj + lwd->lw_offset);
2001 2028 wsp->walk_addr = (uintptr_t)node->tn_next[lwd->lw_txgoff];
2002 2029
2003 2030 return (status);
2004 2031 }
2005 2032
2006 2033 /*
2007 2034 * ::walk spa
2008 2035 *
2009 2036 * Walk all named spa_t structures in the namespace. This is nothing more than
2010 2037 * a layered avl walk.
2011 2038 */
2012 2039 static int
2013 2040 spa_walk_init(mdb_walk_state_t *wsp)
2014 2041 {
2015 2042 GElf_Sym sym;
2016 2043
2017 2044 if (wsp->walk_addr != NULL) {
2018 2045 mdb_warn("spa walk only supports global walks\n");
2019 2046 return (WALK_ERR);
2020 2047 }
2021 2048
2022 2049 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "spa_namespace_avl", &sym) == -1) {
2023 2050 mdb_warn("failed to find symbol 'spa_namespace_avl'");
2024 2051 return (WALK_ERR);
2025 2052 }
2026 2053
2027 2054 wsp->walk_addr = (uintptr_t)sym.st_value;
2028 2055
2029 2056 if (mdb_layered_walk("avl", wsp) == -1) {
2030 2057 mdb_warn("failed to walk 'avl'\n");
2031 2058 return (WALK_ERR);
2032 2059 }
2033 2060
2034 2061 return (WALK_NEXT);
2035 2062 }
2036 2063
2037 2064 static int
2038 2065 spa_walk_step(mdb_walk_state_t *wsp)
2039 2066 {
2040 2067 return (wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata));
2041 2068 }
2042 2069
2043 2070 /*
2044 2071 * [addr]::walk zio
2045 2072 *
2046 2073 * Walk all active zio_t structures on the system. This is simply a layered
2047 2074 * walk on top of ::walk zio_cache, with the optional ability to limit the
2048 2075 * structures to a particular pool.
2049 2076 */
2050 2077 static int
2051 2078 zio_walk_init(mdb_walk_state_t *wsp)
2052 2079 {
2053 2080 wsp->walk_data = &wsp->walk_addr;
2054 2081
2055 2082 if (mdb_layered_walk("zio_cache", wsp) == -1) {
2056 2083 mdb_warn("failed to walk 'zio_cache'\n");
2057 2084 return (WALK_ERR);
2058 2085 }
2059 2086
2060 2087 return (WALK_NEXT);
2061 2088 }
2062 2089
2063 2090 static int
2064 2091 zio_walk_step(mdb_walk_state_t *wsp)
2065 2092 {
2066 2093 mdb_zio_t zio;
2067 2094 uintptr_t *spap = wsp->walk_data;
2068 2095
2069 2096 if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t",
2070 2097 wsp->walk_addr, 0) == -1)
2071 2098 return (WALK_ERR);
2072 2099
2073 2100 if (*spap != 0 && *spap != zio.io_spa)
2074 2101 return (WALK_NEXT);
2075 2102
2076 2103 return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
2077 2104 }
2078 2105
2079 2106 /*
2080 2107 * [addr]::walk zio_root
2081 2108 *
2082 2109 * Walk only root zio_t structures, optionally for a particular spa_t.
2083 2110 */
2084 2111 static int
2085 2112 zio_walk_root_step(mdb_walk_state_t *wsp)
2086 2113 {
2087 2114 mdb_zio_t zio;
2088 2115 uintptr_t *spap = wsp->walk_data;
2089 2116
2090 2117 if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t",
2091 2118 wsp->walk_addr, 0) == -1)
2092 2119 return (WALK_ERR);
2093 2120
2094 2121 if (*spap != 0 && *spap != zio.io_spa)
2095 2122 return (WALK_NEXT);
2096 2123
2097 2124 /* If the parent list is not empty, ignore */
2098 2125 if (zio.io_parent_list.list_head.list_next !=
2099 2126 wsp->walk_addr +
2100 2127 mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio", "io_parent_list") +
2101 2128 mdb_ctf_offsetof_by_name("struct list", "list_head"))
2102 2129 return (WALK_NEXT);
2103 2130
2104 2131 return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
2105 2132 }
2106 2133
2107 2134 #define NICENUM_BUFLEN 6
2108 2135
2109 2136 static int
2110 2137 snprintfrac(char *buf, int len,
2111 2138 uint64_t numerator, uint64_t denom, int frac_digits)
2112 2139 {
2113 2140 int mul = 1;
2114 2141 int whole, frac, i;
2115 2142
2116 2143 for (i = frac_digits; i; i--)
2117 2144 mul *= 10;
2118 2145 whole = numerator / denom;
2119 2146 frac = mul * numerator / denom - mul * whole;
2120 2147 return (mdb_snprintf(buf, len, "%u.%0*u", whole, frac_digits, frac));
2121 2148 }
2122 2149
2123 2150 static void
2124 2151 mdb_nicenum(uint64_t num, char *buf)
2125 2152 {
2126 2153 uint64_t n = num;
2127 2154 int index = 0;
2128 2155 char *u;
2129 2156
2130 2157 while (n >= 1024) {
2131 2158 n = (n + (1024 / 2)) / 1024; /* Round up or down */
2132 2159 index++;
2133 2160 }
2134 2161
2135 2162 u = &" \0K\0M\0G\0T\0P\0E\0"[index*2];
2136 2163
2137 2164 if (index == 0) {
2138 2165 (void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu",
2139 2166 (u_longlong_t)n);
2140 2167 } else if (n < 10 && (num & (num - 1)) != 0) {
2141 2168 (void) snprintfrac(buf, NICENUM_BUFLEN,
2142 2169 num, 1ULL << 10 * index, 2);
2143 2170 strcat(buf, u);
2144 2171 } else if (n < 100 && (num & (num - 1)) != 0) {
2145 2172 (void) snprintfrac(buf, NICENUM_BUFLEN,
2146 2173 num, 1ULL << 10 * index, 1);
2147 2174 strcat(buf, u);
2148 2175 } else {
2149 2176 (void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu%s",
2150 2177 (u_longlong_t)n, u);
2151 2178 }
2152 2179 }
2153 2180
2154 2181 /*
2155 2182 * ::zfs_blkstats
2156 2183 *
2157 2184 * -v print verbose per-level information
2158 2185 *
2159 2186 */
2160 2187 static int
2161 2188 zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2162 2189 {
2163 2190 boolean_t verbose = B_FALSE;
2164 2191 zfs_all_blkstats_t stats;
2165 2192 dmu_object_type_t t;
2166 2193 zfs_blkstat_t *tzb;
2167 2194 uint64_t ditto;
2168 2195 dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES + 10];
2169 2196 /* +10 in case it grew */
2170 2197
2171 2198 if (mdb_readvar(&dmu_ot, "dmu_ot") == -1) {
2172 2199 mdb_warn("failed to read 'dmu_ot'");
2173 2200 return (DCMD_ERR);
2174 2201 }
2175 2202
2176 2203 if (mdb_getopts(argc, argv,
2177 2204 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2178 2205 NULL) != argc)
2179 2206 return (DCMD_USAGE);
2180 2207
2181 2208 if (!(flags & DCMD_ADDRSPEC))
2182 2209 return (DCMD_USAGE);
2183 2210
2184 2211 if (GETMEMB(addr, "spa", spa_dsl_pool, addr) ||
2185 2212 GETMEMB(addr, "dsl_pool", dp_blkstats, addr) ||
2186 2213 mdb_vread(&stats, sizeof (zfs_all_blkstats_t), addr) == -1) {
2187 2214 mdb_warn("failed to read data at %p;", addr);
2188 2215 mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2189 2216 return (DCMD_ERR);
2190 2217 }
2191 2218
2192 2219 tzb = &stats.zab_type[DN_MAX_LEVELS][DMU_OT_TOTAL];
2193 2220 if (tzb->zb_gangs != 0) {
2194 2221 mdb_printf("Ganged blocks: %llu\n",
2195 2222 (longlong_t)tzb->zb_gangs);
2196 2223 }
2197 2224
2198 2225 ditto = tzb->zb_ditto_2_of_2_samevdev + tzb->zb_ditto_2_of_3_samevdev +
2199 2226 tzb->zb_ditto_3_of_3_samevdev;
2200 2227 if (ditto != 0) {
2201 2228 mdb_printf("Dittoed blocks on same vdev: %llu\n",
2202 2229 (longlong_t)ditto);
2203 2230 }
2204 2231
2205 2232 mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2206 2233 "\t avg\t comp\t%%Total\tType\n");
2207 2234
2208 2235 for (t = 0; t <= DMU_OT_TOTAL; t++) {
2209 2236 char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
2210 2237 char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
2211 2238 char avg[NICENUM_BUFLEN];
2212 2239 char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
2213 2240 char typename[64];
2214 2241 int l;
2215 2242
2216 2243
2217 2244 if (t == DMU_OT_DEFERRED)
2218 2245 strcpy(typename, "deferred free");
2219 2246 else if (t == DMU_OT_OTHER)
2220 2247 strcpy(typename, "other");
2221 2248 else if (t == DMU_OT_TOTAL)
2222 2249 strcpy(typename, "Total");
2223 2250 else if (mdb_readstr(typename, sizeof (typename),
2224 2251 (uintptr_t)dmu_ot[t].ot_name) == -1) {
2225 2252 mdb_warn("failed to read type name");
2226 2253 return (DCMD_ERR);
2227 2254 }
2228 2255
2229 2256 if (stats.zab_type[DN_MAX_LEVELS][t].zb_asize == 0)
2230 2257 continue;
2231 2258
2232 2259 for (l = -1; l < DN_MAX_LEVELS; l++) {
2233 2260 int level = (l == -1 ? DN_MAX_LEVELS : l);
2234 2261 zfs_blkstat_t *zb = &stats.zab_type[level][t];
2235 2262
2236 2263 if (zb->zb_asize == 0)
2237 2264 continue;
2238 2265
2239 2266 /*
2240 2267 * Don't print each level unless requested.
2241 2268 */
2242 2269 if (!verbose && level != DN_MAX_LEVELS)
2243 2270 continue;
2244 2271
2245 2272 /*
2246 2273 * If all the space is level 0, don't print the
2247 2274 * level 0 separately.
2248 2275 */
2249 2276 if (level == 0 && zb->zb_asize ==
2250 2277 stats.zab_type[DN_MAX_LEVELS][t].zb_asize)
2251 2278 continue;
2252 2279
2253 2280 mdb_nicenum(zb->zb_count, csize);
2254 2281 mdb_nicenum(zb->zb_lsize, lsize);
2255 2282 mdb_nicenum(zb->zb_psize, psize);
2256 2283 mdb_nicenum(zb->zb_asize, asize);
2257 2284 mdb_nicenum(zb->zb_asize / zb->zb_count, avg);
2258 2285 (void) snprintfrac(comp, NICENUM_BUFLEN,
2259 2286 zb->zb_lsize, zb->zb_psize, 2);
2260 2287 (void) snprintfrac(pct, NICENUM_BUFLEN,
2261 2288 100 * zb->zb_asize, tzb->zb_asize, 2);
2262 2289
2263 2290 mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"
2264 2291 "\t%5s\t%6s\t",
2265 2292 csize, lsize, psize, asize, avg, comp, pct);
2266 2293
2267 2294 if (level == DN_MAX_LEVELS)
2268 2295 mdb_printf("%s\n", typename);
2269 2296 else
2270 2297 mdb_printf(" L%d %s\n",
2271 2298 level, typename);
2272 2299 }
2273 2300 }
2274 2301
2275 2302 return (DCMD_OK);
2276 2303 }
2277 2304
2278 2305 typedef struct mdb_reference {
2279 2306 uintptr_t ref_holder;
2280 2307 uintptr_t ref_removed;
2281 2308 uint64_t ref_number;
2282 2309 } mdb_reference_t;
2283 2310
2284 2311 /* ARGSUSED */
2285 2312 static int
2286 2313 reference_cb(uintptr_t addr, const void *ignored, void *arg)
2287 2314 {
2288 2315 mdb_reference_t ref;
2289 2316 boolean_t holder_is_str = B_FALSE;
2290 2317 char holder_str[128];
2291 2318 boolean_t removed = (boolean_t)arg;
2292 2319
2293 2320 if (mdb_ctf_vread(&ref, "reference_t", "mdb_reference_t", addr,
2294 2321 0) == -1)
2295 2322 return (DCMD_ERR);
2296 2323
2297 2324 if (mdb_readstr(holder_str, sizeof (holder_str),
2298 2325 ref.ref_holder) != -1)
2299 2326 holder_is_str = strisprint(holder_str);
2300 2327
2301 2328 if (removed)
2302 2329 mdb_printf("removed ");
2303 2330 mdb_printf("reference ");
2304 2331 if (ref.ref_number != 1)
2305 2332 mdb_printf("with count=%llu ", ref.ref_number);
2306 2333 mdb_printf("with tag %lx", ref.ref_holder);
2307 2334 if (holder_is_str)
2308 2335 mdb_printf(" \"%s\"", holder_str);
2309 2336 mdb_printf(", held at:\n");
2310 2337
2311 2338 (void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
2312 2339
2313 2340 if (removed) {
2314 2341 mdb_printf("removed at:\n");
2315 2342 (void) mdb_call_dcmd("whatis", ref.ref_removed,
2316 2343 DCMD_ADDRSPEC, 0, NULL);
2317 2344 }
2318 2345
2319 2346 mdb_printf("\n");
2320 2347
2321 2348 return (WALK_NEXT);
2322 2349 }
2323 2350
2324 2351 typedef struct mdb_refcount {
2325 2352 uint64_t rc_count;
2326 2353 } mdb_refcount_t;
2327 2354
2328 2355 typedef struct mdb_refcount_removed {
2329 2356 uint64_t rc_removed_count;
2330 2357 } mdb_refcount_removed_t;
2331 2358
2332 2359 typedef struct mdb_refcount_tracked {
2333 2360 boolean_t rc_tracked;
2334 2361 } mdb_refcount_tracked_t;
2335 2362
2336 2363 /* ARGSUSED */
2337 2364 static int
2338 2365 refcount(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2339 2366 {
2340 2367 mdb_refcount_t rc;
2341 2368 mdb_refcount_removed_t rcr;
2342 2369 mdb_refcount_tracked_t rct;
2343 2370 int off;
2344 2371 boolean_t released = B_FALSE;
2345 2372
2346 2373 if (!(flags & DCMD_ADDRSPEC))
2347 2374 return (DCMD_USAGE);
2348 2375
2349 2376 if (mdb_getopts(argc, argv,
2350 2377 'r', MDB_OPT_SETBITS, B_TRUE, &released,
2351 2378 NULL) != argc)
2352 2379 return (DCMD_USAGE);
2353 2380
2354 2381 if (mdb_ctf_vread(&rc, "refcount_t", "mdb_refcount_t", addr,
2355 2382 0) == -1)
2356 2383 return (DCMD_ERR);
2357 2384
2358 2385 if (mdb_ctf_vread(&rcr, "refcount_t", "mdb_refcount_removed_t", addr,
2359 2386 MDB_CTF_VREAD_QUIET) == -1) {
2360 2387 mdb_printf("refcount_t at %p has %llu holds (untracked)\n",
2361 2388 addr, (longlong_t)rc.rc_count);
2362 2389 return (DCMD_OK);
2363 2390 }
2364 2391
2365 2392 if (mdb_ctf_vread(&rct, "refcount_t", "mdb_refcount_tracked_t", addr,
2366 2393 MDB_CTF_VREAD_QUIET) == -1) {
2367 2394 /* If this is an old target, it might be tracked. */
2368 2395 rct.rc_tracked = B_TRUE;
2369 2396 }
2370 2397
2371 2398 mdb_printf("refcount_t at %p has %llu current holds, "
2372 2399 "%llu recently released holds\n",
2373 2400 addr, (longlong_t)rc.rc_count, (longlong_t)rcr.rc_removed_count);
2374 2401
2375 2402 if (rct.rc_tracked && rc.rc_count > 0)
2376 2403 mdb_printf("current holds:\n");
2377 2404 off = mdb_ctf_offsetof_by_name("refcount_t", "rc_list");
2378 2405 if (off == -1)
2379 2406 return (DCMD_ERR);
2380 2407 mdb_pwalk("list", reference_cb, (void*)B_FALSE, addr + off);
2381 2408
2382 2409 if (released && rcr.rc_removed_count > 0) {
2383 2410 mdb_printf("released holds:\n");
2384 2411
2385 2412 off = mdb_ctf_offsetof_by_name("refcount_t", "rc_removed");
2386 2413 if (off == -1)
2387 2414 return (DCMD_ERR);
2388 2415 mdb_pwalk("list", reference_cb, (void*)B_FALSE, addr + off);
2389 2416 }
2390 2417
2391 2418 return (DCMD_OK);
2392 2419 }
2393 2420
2394 2421 /* ARGSUSED */
2395 2422 static int
2396 2423 sa_attr_table(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2397 2424 {
2398 2425 sa_attr_table_t *table;
2399 2426 sa_os_t sa_os;
2400 2427 char *name;
2401 2428 int i;
2402 2429
2403 2430 if (mdb_vread(&sa_os, sizeof (sa_os_t), addr) == -1) {
2404 2431 mdb_warn("failed to read sa_os at %p", addr);
2405 2432 return (DCMD_ERR);
2406 2433 }
2407 2434
2408 2435 table = mdb_alloc(sizeof (sa_attr_table_t) * sa_os.sa_num_attrs,
2409 2436 UM_SLEEP | UM_GC);
2410 2437 name = mdb_alloc(MAXPATHLEN, UM_SLEEP | UM_GC);
2411 2438
2412 2439 if (mdb_vread(table, sizeof (sa_attr_table_t) * sa_os.sa_num_attrs,
2413 2440 (uintptr_t)sa_os.sa_attr_table) == -1) {
2414 2441 mdb_warn("failed to read sa_os at %p", addr);
2415 2442 return (DCMD_ERR);
2416 2443 }
2417 2444
2418 2445 mdb_printf("%<u>%-10s %-10s %-10s %-10s %s%</u>\n",
2419 2446 "ATTR ID", "REGISTERED", "LENGTH", "BSWAP", "NAME");
2420 2447 for (i = 0; i != sa_os.sa_num_attrs; i++) {
2421 2448 mdb_readstr(name, MAXPATHLEN, (uintptr_t)table[i].sa_name);
2422 2449 mdb_printf("%5x %8x %8x %8x %-s\n",
2423 2450 (int)table[i].sa_attr, (int)table[i].sa_registered,
2424 2451 (int)table[i].sa_length, table[i].sa_byteswap, name);
2425 2452 }
2426 2453
2427 2454 return (DCMD_OK);
2428 2455 }
2429 2456
2430 2457 static int
2431 2458 sa_get_off_table(uintptr_t addr, uint32_t **off_tab, int attr_count)
2432 2459 {
2433 2460 uintptr_t idx_table;
2434 2461
2435 2462 if (GETMEMB(addr, "sa_idx_tab", sa_idx_tab, idx_table)) {
2436 2463 mdb_printf("can't find offset table in sa_idx_tab\n");
2437 2464 return (-1);
2438 2465 }
2439 2466
2440 2467 *off_tab = mdb_alloc(attr_count * sizeof (uint32_t),
2441 2468 UM_SLEEP | UM_GC);
2442 2469
2443 2470 if (mdb_vread(*off_tab,
2444 2471 attr_count * sizeof (uint32_t), idx_table) == -1) {
2445 2472 mdb_warn("failed to attribute offset table %p", idx_table);
2446 2473 return (-1);
2447 2474 }
2448 2475
2449 2476 return (DCMD_OK);
2450 2477 }
2451 2478
2452 2479 /*ARGSUSED*/
2453 2480 static int
2454 2481 sa_attr_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2455 2482 {
2456 2483 uint32_t *offset_tab;
2457 2484 int attr_count;
2458 2485 uint64_t attr_id;
2459 2486 uintptr_t attr_addr;
2460 2487 uintptr_t bonus_tab, spill_tab;
2461 2488 uintptr_t db_bonus, db_spill;
2462 2489 uintptr_t os, os_sa;
2463 2490 uintptr_t db_data;
2464 2491
2465 2492 if (argc != 1)
2466 2493 return (DCMD_USAGE);
2467 2494
2468 2495 if (argv[0].a_type == MDB_TYPE_STRING)
2469 2496 attr_id = mdb_strtoull(argv[0].a_un.a_str);
2470 2497 else
2471 2498 return (DCMD_USAGE);
2472 2499
2473 2500 if (GETMEMB(addr, "sa_handle", sa_bonus_tab, bonus_tab) ||
2474 2501 GETMEMB(addr, "sa_handle", sa_spill_tab, spill_tab) ||
2475 2502 GETMEMB(addr, "sa_handle", sa_os, os) ||
2476 2503 GETMEMB(addr, "sa_handle", sa_bonus, db_bonus) ||
2477 2504 GETMEMB(addr, "sa_handle", sa_spill, db_spill)) {
2478 2505 mdb_printf("Can't find necessary information in sa_handle "
2479 2506 "in sa_handle\n");
2480 2507 return (DCMD_ERR);
2481 2508 }
2482 2509
2483 2510 if (GETMEMB(os, "objset", os_sa, os_sa)) {
2484 2511 mdb_printf("Can't find os_sa in objset\n");
2485 2512 return (DCMD_ERR);
2486 2513 }
2487 2514
2488 2515 if (GETMEMB(os_sa, "sa_os", sa_num_attrs, attr_count)) {
2489 2516 mdb_printf("Can't find sa_num_attrs\n");
2490 2517 return (DCMD_ERR);
2491 2518 }
2492 2519
2493 2520 if (attr_id > attr_count) {
2494 2521 mdb_printf("attribute id number is out of range\n");
2495 2522 return (DCMD_ERR);
2496 2523 }
2497 2524
2498 2525 if (bonus_tab) {
2499 2526 if (sa_get_off_table(bonus_tab, &offset_tab,
2500 2527 attr_count) == -1) {
2501 2528 return (DCMD_ERR);
2502 2529 }
2503 2530
2504 2531 if (GETMEMB(db_bonus, "dmu_buf", db_data, db_data)) {
2505 2532 mdb_printf("can't find db_data in bonus dbuf\n");
2506 2533 return (DCMD_ERR);
2507 2534 }
2508 2535 }
2509 2536
2510 2537 if (bonus_tab && !TOC_ATTR_PRESENT(offset_tab[attr_id]) &&
2511 2538 spill_tab == NULL) {
2512 2539 mdb_printf("Attribute does not exist\n");
2513 2540 return (DCMD_ERR);
2514 2541 } else if (!TOC_ATTR_PRESENT(offset_tab[attr_id]) && spill_tab) {
2515 2542 if (sa_get_off_table(spill_tab, &offset_tab,
2516 2543 attr_count) == -1) {
2517 2544 return (DCMD_ERR);
2518 2545 }
2519 2546 if (GETMEMB(db_spill, "dmu_buf", db_data, db_data)) {
2520 2547 mdb_printf("can't find db_data in spill dbuf\n");
2521 2548 return (DCMD_ERR);
2522 2549 }
2523 2550 if (!TOC_ATTR_PRESENT(offset_tab[attr_id])) {
2524 2551 mdb_printf("Attribute does not exist\n");
2525 2552 return (DCMD_ERR);
2526 2553 }
2527 2554 }
2528 2555 attr_addr = db_data + TOC_OFF(offset_tab[attr_id]);
2529 2556 mdb_printf("%p\n", attr_addr);
2530 2557 return (DCMD_OK);
2531 2558 }
2532 2559
2533 2560 /* ARGSUSED */
2534 2561 static int
2535 2562 zfs_ace_print_common(uintptr_t addr, uint_t flags,
2536 2563 uint64_t id, uint32_t access_mask, uint16_t ace_flags,
2537 2564 uint16_t ace_type, int verbose)
2538 2565 {
2539 2566 if (DCMD_HDRSPEC(flags) && !verbose)
2540 2567 mdb_printf("%<u>%-?s %-8s %-8s %-8s %s%</u>\n",
2541 2568 "ADDR", "FLAGS", "MASK", "TYPE", "ID");
2542 2569
2543 2570 if (!verbose) {
2544 2571 mdb_printf("%0?p %-8x %-8x %-8x %-llx\n", addr,
2545 2572 ace_flags, access_mask, ace_type, id);
2546 2573 return (DCMD_OK);
2547 2574 }
2548 2575
2549 2576 switch (ace_flags & ACE_TYPE_FLAGS) {
2550 2577 case ACE_OWNER:
2551 2578 mdb_printf("owner@:");
2552 2579 break;
2553 2580 case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
2554 2581 mdb_printf("group@:");
2555 2582 break;
2556 2583 case ACE_EVERYONE:
2557 2584 mdb_printf("everyone@:");
2558 2585 break;
2559 2586 case ACE_IDENTIFIER_GROUP:
2560 2587 mdb_printf("group:%llx:", (u_longlong_t)id);
2561 2588 break;
2562 2589 case 0: /* User entry */
2563 2590 mdb_printf("user:%llx:", (u_longlong_t)id);
2564 2591 break;
2565 2592 }
2566 2593
2567 2594 /* print out permission mask */
2568 2595 if (access_mask & ACE_READ_DATA)
2569 2596 mdb_printf("r");
2570 2597 else
2571 2598 mdb_printf("-");
2572 2599 if (access_mask & ACE_WRITE_DATA)
2573 2600 mdb_printf("w");
2574 2601 else
2575 2602 mdb_printf("-");
2576 2603 if (access_mask & ACE_EXECUTE)
2577 2604 mdb_printf("x");
2578 2605 else
2579 2606 mdb_printf("-");
2580 2607 if (access_mask & ACE_APPEND_DATA)
2581 2608 mdb_printf("p");
2582 2609 else
2583 2610 mdb_printf("-");
2584 2611 if (access_mask & ACE_DELETE)
2585 2612 mdb_printf("d");
2586 2613 else
2587 2614 mdb_printf("-");
2588 2615 if (access_mask & ACE_DELETE_CHILD)
2589 2616 mdb_printf("D");
2590 2617 else
2591 2618 mdb_printf("-");
2592 2619 if (access_mask & ACE_READ_ATTRIBUTES)
2593 2620 mdb_printf("a");
2594 2621 else
2595 2622 mdb_printf("-");
2596 2623 if (access_mask & ACE_WRITE_ATTRIBUTES)
2597 2624 mdb_printf("A");
2598 2625 else
2599 2626 mdb_printf("-");
2600 2627 if (access_mask & ACE_READ_NAMED_ATTRS)
2601 2628 mdb_printf("R");
2602 2629 else
2603 2630 mdb_printf("-");
2604 2631 if (access_mask & ACE_WRITE_NAMED_ATTRS)
2605 2632 mdb_printf("W");
2606 2633 else
2607 2634 mdb_printf("-");
2608 2635 if (access_mask & ACE_READ_ACL)
2609 2636 mdb_printf("c");
2610 2637 else
2611 2638 mdb_printf("-");
2612 2639 if (access_mask & ACE_WRITE_ACL)
2613 2640 mdb_printf("C");
2614 2641 else
2615 2642 mdb_printf("-");
2616 2643 if (access_mask & ACE_WRITE_OWNER)
2617 2644 mdb_printf("o");
2618 2645 else
2619 2646 mdb_printf("-");
2620 2647 if (access_mask & ACE_SYNCHRONIZE)
2621 2648 mdb_printf("s");
2622 2649 else
2623 2650 mdb_printf("-");
2624 2651
2625 2652 mdb_printf(":");
2626 2653
2627 2654 /* Print out inheritance flags */
2628 2655 if (ace_flags & ACE_FILE_INHERIT_ACE)
2629 2656 mdb_printf("f");
2630 2657 else
2631 2658 mdb_printf("-");
2632 2659 if (ace_flags & ACE_DIRECTORY_INHERIT_ACE)
2633 2660 mdb_printf("d");
2634 2661 else
2635 2662 mdb_printf("-");
2636 2663 if (ace_flags & ACE_INHERIT_ONLY_ACE)
2637 2664 mdb_printf("i");
2638 2665 else
2639 2666 mdb_printf("-");
2640 2667 if (ace_flags & ACE_NO_PROPAGATE_INHERIT_ACE)
2641 2668 mdb_printf("n");
2642 2669 else
2643 2670 mdb_printf("-");
2644 2671 if (ace_flags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG)
2645 2672 mdb_printf("S");
2646 2673 else
2647 2674 mdb_printf("-");
2648 2675 if (ace_flags & ACE_FAILED_ACCESS_ACE_FLAG)
2649 2676 mdb_printf("F");
2650 2677 else
2651 2678 mdb_printf("-");
2652 2679 if (ace_flags & ACE_INHERITED_ACE)
2653 2680 mdb_printf("I");
2654 2681 else
2655 2682 mdb_printf("-");
2656 2683
2657 2684 switch (ace_type) {
2658 2685 case ACE_ACCESS_ALLOWED_ACE_TYPE:
2659 2686 mdb_printf(":allow\n");
2660 2687 break;
2661 2688 case ACE_ACCESS_DENIED_ACE_TYPE:
2662 2689 mdb_printf(":deny\n");
2663 2690 break;
2664 2691 case ACE_SYSTEM_AUDIT_ACE_TYPE:
2665 2692 mdb_printf(":audit\n");
2666 2693 break;
2667 2694 case ACE_SYSTEM_ALARM_ACE_TYPE:
2668 2695 mdb_printf(":alarm\n");
2669 2696 break;
2670 2697 default:
2671 2698 mdb_printf(":?\n");
2672 2699 }
2673 2700 return (DCMD_OK);
2674 2701 }
2675 2702
2676 2703 /* ARGSUSED */
2677 2704 static int
2678 2705 zfs_ace_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2679 2706 {
2680 2707 zfs_ace_t zace;
2681 2708 int verbose = FALSE;
2682 2709 uint64_t id;
2683 2710
2684 2711 if (!(flags & DCMD_ADDRSPEC))
2685 2712 return (DCMD_USAGE);
2686 2713
2687 2714 if (mdb_getopts(argc, argv,
2688 2715 'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
2689 2716 return (DCMD_USAGE);
2690 2717
2691 2718 if (mdb_vread(&zace, sizeof (zfs_ace_t), addr) == -1) {
2692 2719 mdb_warn("failed to read zfs_ace_t");
2693 2720 return (DCMD_ERR);
2694 2721 }
2695 2722
2696 2723 if ((zace.z_hdr.z_flags & ACE_TYPE_FLAGS) == 0 ||
2697 2724 (zace.z_hdr.z_flags & ACE_TYPE_FLAGS) == ACE_IDENTIFIER_GROUP)
2698 2725 id = zace.z_fuid;
2699 2726 else
2700 2727 id = -1;
2701 2728
2702 2729 return (zfs_ace_print_common(addr, flags, id, zace.z_hdr.z_access_mask,
2703 2730 zace.z_hdr.z_flags, zace.z_hdr.z_type, verbose));
2704 2731 }
2705 2732
2706 2733 /* ARGSUSED */
2707 2734 static int
2708 2735 zfs_ace0_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2709 2736 {
2710 2737 ace_t ace;
2711 2738 uint64_t id;
2712 2739 int verbose = FALSE;
2713 2740
2714 2741 if (!(flags & DCMD_ADDRSPEC))
2715 2742 return (DCMD_USAGE);
2716 2743
2717 2744 if (mdb_getopts(argc, argv,
2718 2745 'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
2719 2746 return (DCMD_USAGE);
2720 2747
2721 2748 if (mdb_vread(&ace, sizeof (ace_t), addr) == -1) {
2722 2749 mdb_warn("failed to read ace_t");
2723 2750 return (DCMD_ERR);
2724 2751 }
2725 2752
2726 2753 if ((ace.a_flags & ACE_TYPE_FLAGS) == 0 ||
2727 2754 (ace.a_flags & ACE_TYPE_FLAGS) == ACE_IDENTIFIER_GROUP)
2728 2755 id = ace.a_who;
2729 2756 else
2730 2757 id = -1;
2731 2758
2732 2759 return (zfs_ace_print_common(addr, flags, id, ace.a_access_mask,
2733 2760 ace.a_flags, ace.a_type, verbose));
2734 2761 }
2735 2762
2736 2763 typedef struct acl_dump_args {
2737 2764 int a_argc;
2738 2765 const mdb_arg_t *a_argv;
2739 2766 uint16_t a_version;
2740 2767 int a_flags;
2741 2768 } acl_dump_args_t;
2742 2769
2743 2770 /* ARGSUSED */
2744 2771 static int
2745 2772 acl_aces_cb(uintptr_t addr, const void *unknown, void *arg)
2746 2773 {
2747 2774 acl_dump_args_t *acl_args = (acl_dump_args_t *)arg;
2748 2775
2749 2776 if (acl_args->a_version == 1) {
2750 2777 if (mdb_call_dcmd("zfs_ace", addr,
2751 2778 DCMD_ADDRSPEC|acl_args->a_flags, acl_args->a_argc,
2752 2779 acl_args->a_argv) != DCMD_OK) {
2753 2780 return (WALK_ERR);
2754 2781 }
2755 2782 } else {
2756 2783 if (mdb_call_dcmd("zfs_ace0", addr,
2757 2784 DCMD_ADDRSPEC|acl_args->a_flags, acl_args->a_argc,
2758 2785 acl_args->a_argv) != DCMD_OK) {
2759 2786 return (WALK_ERR);
2760 2787 }
2761 2788 }
2762 2789 acl_args->a_flags = DCMD_LOOP;
2763 2790 return (WALK_NEXT);
2764 2791 }
2765 2792
2766 2793 /* ARGSUSED */
2767 2794 static int
2768 2795 acl_cb(uintptr_t addr, const void *unknown, void *arg)
2769 2796 {
2770 2797 acl_dump_args_t *acl_args = (acl_dump_args_t *)arg;
2771 2798
2772 2799 if (acl_args->a_version == 1) {
2773 2800 if (mdb_pwalk("zfs_acl_node_aces", acl_aces_cb,
2774 2801 arg, addr) != 0) {
2775 2802 mdb_warn("can't walk ACEs");
2776 2803 return (DCMD_ERR);
2777 2804 }
2778 2805 } else {
2779 2806 if (mdb_pwalk("zfs_acl_node_aces0", acl_aces_cb,
2780 2807 arg, addr) != 0) {
2781 2808 mdb_warn("can't walk ACEs");
2782 2809 return (DCMD_ERR);
2783 2810 }
2784 2811 }
2785 2812 return (WALK_NEXT);
2786 2813 }
2787 2814
2788 2815 /* ARGSUSED */
2789 2816 static int
2790 2817 zfs_acl_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2791 2818 {
2792 2819 zfs_acl_t zacl;
2793 2820 int verbose = FALSE;
2794 2821 acl_dump_args_t acl_args;
2795 2822
2796 2823 if (!(flags & DCMD_ADDRSPEC))
2797 2824 return (DCMD_USAGE);
2798 2825
2799 2826 if (mdb_getopts(argc, argv,
2800 2827 'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
2801 2828 return (DCMD_USAGE);
2802 2829
2803 2830 if (mdb_vread(&zacl, sizeof (zfs_acl_t), addr) == -1) {
2804 2831 mdb_warn("failed to read zfs_acl_t");
2805 2832 return (DCMD_ERR);
2806 2833 }
2807 2834
2808 2835 acl_args.a_argc = argc;
2809 2836 acl_args.a_argv = argv;
2810 2837 acl_args.a_version = zacl.z_version;
2811 2838 acl_args.a_flags = DCMD_LOOPFIRST;
2812 2839
2813 2840 if (mdb_pwalk("zfs_acl_node", acl_cb, &acl_args, addr) != 0) {
2814 2841 mdb_warn("can't walk ACL");
2815 2842 return (DCMD_ERR);
2816 2843 }
2817 2844
2818 2845 return (DCMD_OK);
2819 2846 }
2820 2847
2821 2848 /* ARGSUSED */
2822 2849 static int
2823 2850 zfs_acl_node_walk_init(mdb_walk_state_t *wsp)
2824 2851 {
2825 2852 if (wsp->walk_addr == NULL) {
2826 2853 mdb_warn("must supply address of zfs_acl_node_t\n");
2827 2854 return (WALK_ERR);
2828 2855 }
2829 2856
2830 2857 wsp->walk_addr +=
2831 2858 mdb_ctf_offsetof_by_name(ZFS_STRUCT "zfs_acl", "z_acl");
2832 2859
2833 2860 if (mdb_layered_walk("list", wsp) == -1) {
2834 2861 mdb_warn("failed to walk 'list'\n");
2835 2862 return (WALK_ERR);
2836 2863 }
2837 2864
2838 2865 return (WALK_NEXT);
2839 2866 }
2840 2867
2841 2868 static int
2842 2869 zfs_acl_node_walk_step(mdb_walk_state_t *wsp)
2843 2870 {
2844 2871 zfs_acl_node_t aclnode;
2845 2872
2846 2873 if (mdb_vread(&aclnode, sizeof (zfs_acl_node_t),
2847 2874 wsp->walk_addr) == -1) {
2848 2875 mdb_warn("failed to read zfs_acl_node at %p", wsp->walk_addr);
2849 2876 return (WALK_ERR);
2850 2877 }
2851 2878
2852 2879 return (wsp->walk_callback(wsp->walk_addr, &aclnode, wsp->walk_cbdata));
2853 2880 }
2854 2881
2855 2882 typedef struct ace_walk_data {
2856 2883 int ace_count;
2857 2884 int ace_version;
2858 2885 } ace_walk_data_t;
2859 2886
2860 2887 static int
2861 2888 zfs_aces_walk_init_common(mdb_walk_state_t *wsp, int version,
2862 2889 int ace_count, uintptr_t ace_data)
2863 2890 {
2864 2891 ace_walk_data_t *ace_walk_data;
2865 2892
2866 2893 if (wsp->walk_addr == NULL) {
2867 2894 mdb_warn("must supply address of zfs_acl_node_t\n");
2868 2895 return (WALK_ERR);
2869 2896 }
2870 2897
2871 2898 ace_walk_data = mdb_alloc(sizeof (ace_walk_data_t), UM_SLEEP | UM_GC);
2872 2899
2873 2900 ace_walk_data->ace_count = ace_count;
2874 2901 ace_walk_data->ace_version = version;
2875 2902
2876 2903 wsp->walk_addr = ace_data;
2877 2904 wsp->walk_data = ace_walk_data;
2878 2905
2879 2906 return (WALK_NEXT);
2880 2907 }
2881 2908
2882 2909 static int
2883 2910 zfs_acl_node_aces_walk_init_common(mdb_walk_state_t *wsp, int version)
2884 2911 {
2885 2912 static int gotid;
2886 2913 static mdb_ctf_id_t acl_id;
2887 2914 int z_ace_count;
2888 2915 uintptr_t z_acldata;
2889 2916
2890 2917 if (!gotid) {
2891 2918 if (mdb_ctf_lookup_by_name("struct zfs_acl_node",
2892 2919 &acl_id) == -1) {
2893 2920 mdb_warn("couldn't find struct zfs_acl_node");
2894 2921 return (DCMD_ERR);
2895 2922 }
2896 2923 gotid = TRUE;
2897 2924 }
2898 2925
2899 2926 if (GETMEMBID(wsp->walk_addr, &acl_id, z_ace_count, z_ace_count)) {
2900 2927 return (DCMD_ERR);
2901 2928 }
2902 2929 if (GETMEMBID(wsp->walk_addr, &acl_id, z_acldata, z_acldata)) {
2903 2930 return (DCMD_ERR);
2904 2931 }
2905 2932
2906 2933 return (zfs_aces_walk_init_common(wsp, version,
2907 2934 z_ace_count, z_acldata));
2908 2935 }
2909 2936
2910 2937 /* ARGSUSED */
2911 2938 static int
2912 2939 zfs_acl_node_aces_walk_init(mdb_walk_state_t *wsp)
2913 2940 {
2914 2941 return (zfs_acl_node_aces_walk_init_common(wsp, 1));
2915 2942 }
2916 2943
2917 2944 /* ARGSUSED */
2918 2945 static int
2919 2946 zfs_acl_node_aces0_walk_init(mdb_walk_state_t *wsp)
2920 2947 {
2921 2948 return (zfs_acl_node_aces_walk_init_common(wsp, 0));
2922 2949 }
2923 2950
2924 2951 static int
2925 2952 zfs_aces_walk_step(mdb_walk_state_t *wsp)
2926 2953 {
2927 2954 ace_walk_data_t *ace_data = wsp->walk_data;
2928 2955 zfs_ace_t zace;
2929 2956 ace_t *acep;
2930 2957 int status;
2931 2958 int entry_type;
2932 2959 int allow_type;
2933 2960 uintptr_t ptr;
2934 2961
2935 2962 if (ace_data->ace_count == 0)
2936 2963 return (WALK_DONE);
2937 2964
2938 2965 if (mdb_vread(&zace, sizeof (zfs_ace_t), wsp->walk_addr) == -1) {
2939 2966 mdb_warn("failed to read zfs_ace_t at %#lx",
2940 2967 wsp->walk_addr);
2941 2968 return (WALK_ERR);
2942 2969 }
2943 2970
2944 2971 switch (ace_data->ace_version) {
2945 2972 case 0:
2946 2973 acep = (ace_t *)&zace;
2947 2974 entry_type = acep->a_flags & ACE_TYPE_FLAGS;
2948 2975 allow_type = acep->a_type;
2949 2976 break;
2950 2977 case 1:
2951 2978 entry_type = zace.z_hdr.z_flags & ACE_TYPE_FLAGS;
2952 2979 allow_type = zace.z_hdr.z_type;
2953 2980 break;
2954 2981 default:
2955 2982 return (WALK_ERR);
2956 2983 }
2957 2984
2958 2985 ptr = (uintptr_t)wsp->walk_addr;
2959 2986 switch (entry_type) {
2960 2987 case ACE_OWNER:
2961 2988 case ACE_EVERYONE:
2962 2989 case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
2963 2990 ptr += ace_data->ace_version == 0 ?
2964 2991 sizeof (ace_t) : sizeof (zfs_ace_hdr_t);
2965 2992 break;
2966 2993 case ACE_IDENTIFIER_GROUP:
2967 2994 default:
2968 2995 switch (allow_type) {
2969 2996 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
2970 2997 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
2971 2998 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
2972 2999 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
2973 3000 ptr += ace_data->ace_version == 0 ?
2974 3001 sizeof (ace_t) : sizeof (zfs_object_ace_t);
2975 3002 break;
2976 3003 default:
2977 3004 ptr += ace_data->ace_version == 0 ?
2978 3005 sizeof (ace_t) : sizeof (zfs_ace_t);
2979 3006 break;
2980 3007 }
2981 3008 }
2982 3009
2983 3010 ace_data->ace_count--;
2984 3011 status = wsp->walk_callback(wsp->walk_addr,
2985 3012 (void *)(uintptr_t)&zace, wsp->walk_cbdata);
2986 3013
2987 3014 wsp->walk_addr = ptr;
2988 3015 return (status);
2989 3016 }
2990 3017
2991 3018 typedef struct mdb_zfs_rrwlock {
2992 3019 uintptr_t rr_writer;
2993 3020 boolean_t rr_writer_wanted;
2994 3021 } mdb_zfs_rrwlock_t;
2995 3022
2996 3023 static uint_t rrw_key;
2997 3024
2998 3025 /* ARGSUSED */
2999 3026 static int
3000 3027 rrwlock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3001 3028 {
3002 3029 mdb_zfs_rrwlock_t rrw;
3003 3030
3004 3031 if (rrw_key == 0) {
3005 3032 if (mdb_ctf_readsym(&rrw_key, "uint_t", "rrw_tsd_key", 0) == -1)
3006 3033 return (DCMD_ERR);
3007 3034 }
3008 3035
3009 3036 if (mdb_ctf_vread(&rrw, "rrwlock_t", "mdb_zfs_rrwlock_t", addr,
3010 3037 0) == -1)
3011 3038 return (DCMD_ERR);
3012 3039
3013 3040 if (rrw.rr_writer != 0) {
3014 3041 mdb_printf("write lock held by thread %lx\n", rrw.rr_writer);
3015 3042 return (DCMD_OK);
3016 3043 }
3017 3044
3018 3045 if (rrw.rr_writer_wanted) {
3019 3046 mdb_printf("writer wanted\n");
3020 3047 }
3021 3048
3022 3049 mdb_printf("anonymous references:\n");
3023 3050 (void) mdb_call_dcmd("refcount", addr +
3024 3051 mdb_ctf_offsetof_by_name(ZFS_STRUCT "rrwlock", "rr_anon_rcount"),
3025 3052 DCMD_ADDRSPEC, 0, NULL);
3026 3053
3027 3054 mdb_printf("linked references:\n");
3028 3055 (void) mdb_call_dcmd("refcount", addr +
3029 3056 mdb_ctf_offsetof_by_name(ZFS_STRUCT "rrwlock", "rr_linked_rcount"),
3030 3057 DCMD_ADDRSPEC, 0, NULL);
3031 3058
3032 3059 /*
3033 3060 * XXX This should find references from
3034 3061 * "::walk thread | ::tsd -v <rrw_key>", but there is no support
3035 3062 * for programmatic consumption of dcmds, so this would be
3036 3063 * difficult, potentially requiring reimplementing ::tsd (both
3037 3064 * user and kernel versions) in this MDB module.
3038 3065 */
3039 3066
3040 3067 return (DCMD_OK);
3041 3068 }
3042 3069
3043 3070 /*
3044 3071 * MDB module linkage information:
3045 3072 *
3046 3073 * We declare a list of structures describing our dcmds, and a function
3047 3074 * named _mdb_init to return a pointer to our module information.
3048 3075 */
3049 3076
3050 3077 static const mdb_dcmd_t dcmds[] = {
3051 3078 { "arc", "[-bkmg]", "print ARC variables", arc_print },
3052 3079 { "blkptr", ":", "print blkptr_t", blkptr },
3053 3080 { "dbuf", ":", "print dmu_buf_impl_t", dbuf },
3054 3081 { "dbuf_stats", ":", "dbuf stats", dbuf_stats },
3055 3082 { "dbufs",
3056 3083 "\t[-O objset_t*] [-n objset_name | \"mos\"] "
3057 3084 "[-o object | \"mdn\"] \n"
3058 3085 "\t[-l level] [-b blkid | \"bonus\"]",
3059 3086 "find dmu_buf_impl_t's that match specified criteria", dbufs },
3060 3087 { "abuf_find", "dva_word[0] dva_word[1]",
3061 3088 "find arc_buf_hdr_t of a specified DVA",
3062 3089 abuf_find },
3063 3090 { "spa", "?[-cv]", "spa_t summary", spa_print },
3064 3091 { "spa_config", ":", "print spa_t configuration", spa_print_config },
3065 3092 { "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space },
3066 3093 { "spa_vdevs", ":", "given a spa_t, print vdev summary", spa_vdevs },
3067 3094 { "vdev", ":[-re]\n"
3068 3095 "\t-r display recursively\n"
3069 3096 "\t-e print statistics",
3070 3097 "vdev_t summary", vdev_print },
3071 3098 { "zio", ":[cpr]\n"
3072 3099 "\t-c display children\n"
3073 3100 "\t-p display parents\n"
3074 3101 "\t-r display recursively",
3075 3102 "zio_t summary", zio_print },
3076 3103 { "zio_state", "?", "print out all zio_t structures on system or "
3077 3104 "for a particular pool", zio_state },
3078 3105 { "zfs_blkstats", ":[-v]",
3079 3106 "given a spa_t, print block type stats from last scrub",
3080 3107 zfs_blkstats },
3081 3108 { "zfs_params", "", "print zfs tunable parameters", zfs_params },
3082 3109 { "refcount", ":[-r]\n"
3083 3110 "\t-r display recently removed references",
3084 3111 "print refcount_t holders", refcount },
3085 3112 { "zap_leaf", "", "print zap_leaf_phys_t", zap_leaf },
3086 3113 { "zfs_aces", ":[-v]", "print all ACEs from a zfs_acl_t",
3087 3114 zfs_acl_dump },
3088 3115 { "zfs_ace", ":[-v]", "print zfs_ace", zfs_ace_print },
3089 3116 { "zfs_ace0", ":[-v]", "print zfs_ace0", zfs_ace0_print },
3090 3117 { "sa_attr_table", ":", "print SA attribute table from sa_os_t",
3091 3118 sa_attr_table},
3092 3119 { "sa_attr", ": attr_id",
3093 3120 "print SA attribute address when given sa_handle_t", sa_attr_print},
3094 3121 { "zfs_dbgmsg", ":[-va]",
3095 3122 "print zfs debug log", dbgmsg},
3096 3123 { "rrwlock", ":",
3097 3124 "print rrwlock_t, including readers", rrwlock},
3098 3125 { NULL }
3099 3126 };
3100 3127
3101 3128 static const mdb_walker_t walkers[] = {
3102 3129 { "zms_freelist", "walk ZFS metaslab freelist",
3103 3130 freelist_walk_init, freelist_walk_step, NULL },
3104 3131 { "txg_list", "given any txg_list_t *, walk all entries in all txgs",
3105 3132 txg_list_walk_init, txg_list_walk_step, NULL },
3106 3133 { "txg_list0", "given any txg_list_t *, walk all entries in txg 0",
3107 3134 txg_list0_walk_init, txg_list_walk_step, NULL },
3108 3135 { "txg_list1", "given any txg_list_t *, walk all entries in txg 1",
3109 3136 txg_list1_walk_init, txg_list_walk_step, NULL },
3110 3137 { "txg_list2", "given any txg_list_t *, walk all entries in txg 2",
3111 3138 txg_list2_walk_init, txg_list_walk_step, NULL },
3112 3139 { "txg_list3", "given any txg_list_t *, walk all entries in txg 3",
3113 3140 txg_list3_walk_init, txg_list_walk_step, NULL },
3114 3141 { "zio", "walk all zio structures, optionally for a particular spa_t",
3115 3142 zio_walk_init, zio_walk_step, NULL },
3116 3143 { "zio_root",
3117 3144 "walk all root zio_t structures, optionally for a particular spa_t",
3118 3145 zio_walk_init, zio_walk_root_step, NULL },
3119 3146 { "spa", "walk all spa_t entries in the namespace",
3120 3147 spa_walk_init, spa_walk_step, NULL },
3121 3148 { "metaslab", "given a spa_t *, walk all metaslab_t structures",
3122 3149 metaslab_walk_init, metaslab_walk_step, NULL },
3123 3150 { "zfs_acl_node", "given a zfs_acl_t, walk all zfs_acl_nodes",
3124 3151 zfs_acl_node_walk_init, zfs_acl_node_walk_step, NULL },
3125 3152 { "zfs_acl_node_aces", "given a zfs_acl_node_t, walk all ACEs",
3126 3153 zfs_acl_node_aces_walk_init, zfs_aces_walk_step, NULL },
3127 3154 { "zfs_acl_node_aces0",
3128 3155 "given a zfs_acl_node_t, walk all ACEs as ace_t",
3129 3156 zfs_acl_node_aces0_walk_init, zfs_aces_walk_step, NULL },
3130 3157 { NULL }
3131 3158 };
3132 3159
3133 3160 static const mdb_modinfo_t modinfo = {
3134 3161 MDB_API_VERSION, dcmds, walkers
3135 3162 };
3136 3163
3137 3164 const mdb_modinfo_t *
3138 3165 _mdb_init(void)
3139 3166 {
3140 3167 return (&modinfo);
3141 3168 }
↓ open down ↓ |
1547 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX