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