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