usr/src/cmd/mdb/common/modules/zfs/zfs.c
author Matthew Ahrens <Matthew.Ahrens@Sun.COM>
Fri, 28 Aug 2009 13:57:58 -0700
changeset 10407 34e10c4af053
parent 10298 a0d52501437c
child 10859 ea699e57196e
permissions -rw-r--r--
6875779 zfs user accounting callbacks can be simplified 6771468 ::blkptr prints incorrectly on 32-bit 6832861 zcmd_alloc_dst_nvlist's default size is too small 6876808 want ::refcount to print refcount_t details
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 952
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 952
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
    22
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <mdb/mdb_ctf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/mdb_modapi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/dsl_pool.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/metaslab_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/space_map.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/list.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/zio_compress.h>
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
    39
#include <ctype.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#ifndef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include "../genunix/list.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#ifdef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#define	ZFS_OBJ_NAME	"zfs"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#define	ZFS_OBJ_NAME	"libzpool.so.1"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
static char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
local_strdup(const char *s)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	char *s1 = mdb_alloc(strlen(s) + 1, UM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
	(void) strcpy(s1, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
	return (s1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
getmember(uintptr_t addr, const char *type, mdb_ctf_id_t *idp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
    const char *member, int len, void *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
	mdb_ctf_id_t id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
	ulong_t off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
	char name[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	if (idp == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
		if (mdb_ctf_lookup_by_name(type, &id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
			mdb_warn("couldn't find type %s", type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
		idp = &id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
		type = name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
		mdb_ctf_type_name(*idp, name, sizeof (name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	if (mdb_ctf_offsetof(*idp, member, &off) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
		mdb_warn("couldn't find member %s of type %s\n", member, type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	if (off % 8 != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
		mdb_warn("member %s of type %s is unsupported bitfield",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
		    member, type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
	off /= 8;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	if (mdb_vread(buf, len, addr + off) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
		mdb_warn("failed to read %s from %s at %p",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
		    member, type, addr + off);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
	/* mdb_warn("read %s from %s at %p+%llx\n", member, type, addr, off); */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
#define	GETMEMB(addr, type, member, dest) \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	getmember(addr, #type, NULL, #member, sizeof (dest), &(dest))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
#define	GETMEMBID(addr, ctfid, member, dest) \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	getmember(addr, NULL, ctfid, #member, sizeof (dest), &(dest))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
getrefcount(uintptr_t addr, mdb_ctf_id_t *id,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
    const char *member, uint64_t *rc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	static int gotid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	static mdb_ctf_id_t rc_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	ulong_t off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	if (!gotid) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
		if (mdb_ctf_lookup_by_name("struct refcount", &rc_id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
			mdb_warn("couldn't find struct refcount");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
		gotid = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	if (mdb_ctf_offsetof(*id, member, &off) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
		char name[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
		mdb_ctf_type_name(*id, name, sizeof (name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
		mdb_warn("couldn't find member %s of type %s\n", member, name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	off /= 8;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	return (GETMEMBID(addr + off, &rc_id, rc_count, *rc));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
read_symbol(char *sym_name, void **bufp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	GElf_Sym sym;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
	if (mdb_lookup_by_obj(MDB_TGT_OBJ_EVERY, sym_name, &sym)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
		mdb_warn("can't find symbol %s", sym_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	*bufp = mdb_alloc(sym.st_size, UM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	if (mdb_vread(*bufp, sym.st_size, sym.st_value) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
		mdb_warn("can't read data for symbol %s", sym_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
		mdb_free(*bufp, sym.st_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
static int verbose;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
freelist_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
	if (wsp->walk_addr == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
		mdb_warn("must supply starting address\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
	wsp->walk_data = 0;  /* Index into the freelist */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
	return (WALK_NEXT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
freelist_walk_step(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
	uint64_t entry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
	uintptr_t number = (uintptr_t)wsp->walk_data;
3361
a3d194896a76 6480230 ::walk spa|::walk zms_freelist cause mdb to core dump
ck153898
parents: 3158
diff changeset
   173
	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
a3d194896a76 6480230 ::walk spa|::walk zms_freelist cause mdb to core dump
ck153898
parents: 3158
diff changeset
   174
			    "INVALID", "INVALID", "INVALID", "INVALID" };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
	int mapshift = SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	if (mdb_vread(&entry, sizeof (entry), wsp->walk_addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
		mdb_warn("failed to read freelist entry %p", wsp->walk_addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
		return (WALK_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
	wsp->walk_addr += sizeof (entry);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
	wsp->walk_data = (void *)(number + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
	if (SM_DEBUG_DECODE(entry)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
		mdb_printf("DEBUG: %3u  %10s: txg=%llu  pass=%llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
		    number,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
		    ddata[SM_DEBUG_ACTION_DECODE(entry)],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
		    SM_DEBUG_TXG_DECODE(entry),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
		    SM_DEBUG_SYNCPASS_DECODE(entry));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
		mdb_printf("Entry: %3u  offsets=%08llx-%08llx  type=%c  "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
		    "size=%06llx", number,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
		    SM_OFFSET_DECODE(entry) << mapshift,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
		    (SM_OFFSET_DECODE(entry) + SM_RUN_DECODE(entry)) <<
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
		    mapshift,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
		    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
		    SM_RUN_DECODE(entry) << mapshift);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
		if (verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
			mdb_printf("      (raw=%012llx)\n", entry);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
		mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
	return (WALK_NEXT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
dataset_name(uintptr_t addr, char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
	static int gotid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
	static mdb_ctf_id_t dd_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
	uintptr_t dd_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	char dd_myname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
	if (!gotid) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
		if (mdb_ctf_lookup_by_name("struct dsl_dir",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
		    &dd_id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
			mdb_warn("couldn't find struct dsl_dir");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
		gotid = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	if (GETMEMBID(addr, &dd_id, dd_parent, dd_parent) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	    GETMEMBID(addr, &dd_id, dd_myname, dd_myname)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	if (dd_parent) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
		if (dataset_name(dd_parent, buf))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
		strcat(buf, "/");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	if (dd_myname[0])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
		strcat(buf, dd_myname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
		strcat(buf, "???");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
objset_name(uintptr_t addr, char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	static int gotid;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9480
diff changeset
   245
	static mdb_ctf_id_t os_id, ds_id;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	uintptr_t os_dsl_dataset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
	char ds_snapname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	uintptr_t ds_dir;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	buf[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	if (!gotid) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9480
diff changeset
   253
		if (mdb_ctf_lookup_by_name("struct objset",
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9480
diff changeset
   254
		    &os_id) == -1) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9480
diff changeset
   255
			mdb_warn("couldn't find struct objset");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
		if (mdb_ctf_lookup_by_name("struct dsl_dataset",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
		    &ds_id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
			mdb_warn("couldn't find struct dsl_dataset");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
		gotid = TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9480
diff changeset
   267
	if (GETMEMBID(addr, &os_id, os_dsl_dataset, os_dsl_dataset))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
	if (os_dsl_dataset == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
		strcat(buf, "mos");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	if (GETMEMBID(os_dsl_dataset, &ds_id, ds_snapname, ds_snapname) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	    GETMEMBID(os_dsl_dataset, &ds_id, ds_dir, ds_dir)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
	if (ds_dir && dataset_name(ds_dir, buf))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	if (ds_snapname[0]) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
		strcat(buf, "@");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
		strcat(buf, ds_snapname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
enum_lookup(char *out, size_t size, mdb_ctf_id_t id, int val,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
    const char *prefix)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	const char *cp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	size_t len = strlen(prefix);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	if ((cp = mdb_ctf_enum_name(id, val)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
		if (strncmp(cp, prefix, len) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
			cp += len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
		(void) strncpy(out, cp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
		mdb_snprintf(out, size, "? (%d)", val);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
zio_pipeline(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	mdb_ctf_id_t pipe_enum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
	char stage[1024];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	if (mdb_ctf_lookup_by_name("enum zio_stage", &pipe_enum) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		mdb_warn("Could not find enum zio_stage");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	for (i = 0; i < 32; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
		if (addr & (1U << i)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
			enum_lookup(stage, sizeof (stage), pipe_enum, i,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
			    "ZIO_STAGE_");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
			mdb_printf("    %s\n", stage);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
static int
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   332
zfs_params(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   333
{
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   334
	/*
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   335
	 * This table can be approximately generated by running:
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   336
	 * egrep "^[a-z0-9_]+ [a-z0-9_]+( =.*)?;" *.c | cut -d ' ' -f 2
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   337
	 */
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   338
	static const char *params[] = {
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   339
		"arc_reduce_dnlc_percent",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   340
		"zfs_arc_max",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   341
		"zfs_arc_min",
3158
f30a3849aa23 6493923 nfsfind on ZFS filesystem quickly depletes memory in a 1GB system
maybee
parents: 3059
diff changeset
   342
		"arc_shrink_shift",
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   343
		"zfs_mdcomp_disable",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   344
		"zfs_prefetch_disable",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   345
		"zfetch_max_streams",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   346
		"zfetch_min_sec_reap",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   347
		"zfetch_block_cap",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   348
		"zfetch_array_rd_sz",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   349
		"zfs_default_bs",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   350
		"zfs_default_ibs",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   351
		"metaslab_aliquot",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   352
		"reference_tracking_enable",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   353
		"reference_history",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   354
		"zio_taskq_threads",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   355
		"spa_max_replication_override",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   356
		"spa_mode",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   357
		"zfs_flags",
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   358
		"zfs_txg_synctime",
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   359
		"zfs_txg_timeout",
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   360
		"zfs_write_limit_min",
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   361
		"zfs_write_limit_max",
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   362
		"zfs_write_limit_shift",
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   363
		"zfs_write_limit_override",
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   364
		"zfs_no_write_throttle",
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   365
		"zfs_vdev_cache_max",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   366
		"zfs_vdev_cache_size",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   367
		"zfs_vdev_cache_bshift",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   368
		"vdev_mirror_shift",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   369
		"zfs_vdev_max_pending",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   370
		"zfs_vdev_min_pending",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   371
		"zfs_scrub_limit",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   372
		"zfs_vdev_time_shift",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   373
		"zfs_vdev_ramp_rate",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   374
		"zfs_vdev_aggregation_limit",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   375
		"fzap_default_block_shift",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   376
		"zfs_immediate_write_sz",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   377
		"zfs_read_chunk_size",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   378
		"zil_disable",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   379
		"zfs_nocacheflush",
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5367
diff changeset
   380
		"metaslab_gang_bang",
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 8632
diff changeset
   381
		"metaslab_df_alloc_threshold",
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 8632
diff changeset
   382
		"metaslab_df_free_pct",
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   383
		"zio_injection_enabled",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   384
		"zvol_immediate_write_sz",
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   385
	};
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   386
	int i;
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   387
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   388
	for (i = 0; i < sizeof (params) / sizeof (params[0]); i++) {
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   389
		int sz;
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   390
		uint64_t val64;
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   391
		uint32_t *val32p = (uint32_t *)&val64;
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   392
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   393
		sz = mdb_readvar(&val64, params[i]);
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   394
		if (sz == 4) {
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   395
			mdb_printf("%s = 0x%x\n", params[i], *val32p);
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   396
		} else if (sz == 8) {
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   397
			mdb_printf("%s = 0x%llx\n", params[i], val64);
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   398
		} else {
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   399
			mdb_warn("variable %s not found", params[i]);
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   400
		}
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   401
	}
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   402
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   403
	return (DCMD_OK);
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   404
}
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   405
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   406
/* ARGSUSED */
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
   407
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
blkptr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
	blkptr_t bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
	dmu_object_type_info_t *doti;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
	zio_compress_info_t *zct;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
	zio_checksum_info_t *zci;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
	char buf[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
	if (mdb_vread(&bp, sizeof (blkptr_t), addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
		mdb_warn("failed to read blkptr_t");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
	if (read_symbol("dmu_ot", (void **)&doti) != DCMD_OK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	for (i = 0; i < DMU_OT_NUMTYPES; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
		mdb_readstr(buf, sizeof (buf), (uintptr_t)doti[i].ot_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
		doti[i].ot_name = local_strdup(buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	if (read_symbol("zio_checksum_table", (void **)&zci) != DCMD_OK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
	for (i = 0; i < ZIO_CHECKSUM_FUNCTIONS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
		mdb_readstr(buf, sizeof (buf), (uintptr_t)zci[i].ci_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
		zci[i].ci_name = local_strdup(buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	if (read_symbol("zio_compress_table", (void **)&zct) != DCMD_OK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
	for (i = 0; i < ZIO_COMPRESS_FUNCTIONS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
		mdb_readstr(buf, sizeof (buf), (uintptr_t)zct[i].ci_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
		zct[i].ci_name = local_strdup(buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   443
	/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   444
	 * Super-ick warning:  This code is also duplicated in
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   445
	 * cmd/zdb.c .   Yeah, I hate code replication, too.
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   446
	 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   447
	for (i = 0; i < BP_GET_NDVAS(&bp); i++) {
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   448
		dva_t *dva = &bp.blk_dva[i];
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   449
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   450
		mdb_printf("DVA[%d]: vdev_id %lld / %llx\n", i,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   451
		    DVA_GET_VDEV(dva), DVA_GET_OFFSET(dva));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   452
		mdb_printf("DVA[%d]:       GANG: %-5s  GRID:  %04x\t"
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   453
		    "ASIZE: %llx\n", i, DVA_GET_GANG(dva) ? "TRUE" : "FALSE",
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
   454
		    (int)DVA_GET_GRID(dva), DVA_GET_ASIZE(dva));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   455
		mdb_printf("DVA[%d]: :%llu:%llx:%llx:%s%s%s%s\n", i,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   456
		    DVA_GET_VDEV(dva), DVA_GET_OFFSET(dva), BP_GET_PSIZE(&bp),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   457
		    BP_SHOULD_BYTESWAP(&bp) ? "e" : "",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   458
		    !DVA_GET_GANG(dva) && BP_GET_LEVEL(&bp) != 0 ? "i" : "",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   459
		    DVA_GET_GANG(dva) ? "g" : "",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   460
		    BP_GET_COMPRESS(&bp) != 0 ? "d" : "");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	mdb_printf("LSIZE:  %-16llx\t\tPSIZE: %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	    BP_GET_LSIZE(&bp), BP_GET_PSIZE(&bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   464
	mdb_printf("ENDIAN: %6s\t\t\t\t\tTYPE:  %s\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
	    BP_GET_BYTEORDER(&bp) ? "LITTLE" : "BIG",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
	    doti[BP_GET_TYPE(&bp)].ot_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
	mdb_printf("BIRTH:  %-16llx   LEVEL: %-2d\tFILL:  %llx\n",
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
   468
	    bp.blk_birth, (int)BP_GET_LEVEL(&bp), bp.blk_fill);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
	mdb_printf("CKFUNC: %-16s\t\tCOMP:  %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
	    zci[BP_GET_CHECKSUM(&bp)].ci_name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
	    zct[BP_GET_COMPRESS(&bp)].ci_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	mdb_printf("CKSUM:  %llx:%llx:%llx:%llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
	    bp.blk_cksum.zc_word[0],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	    bp.blk_cksum.zc_word[1],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
	    bp.blk_cksum.zc_word[2],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
	    bp.blk_cksum.zc_word[3]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
dbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
	mdb_ctf_id_t id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
	dmu_buf_t db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
	uintptr_t objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	uint8_t level;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
	uint64_t blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
	uint64_t holds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
	char objectname[32];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	char blkidname[32];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
	char path[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
	if (DCMD_HDRSPEC(flags)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
		mdb_printf("        addr object lvl blkid holds os\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
	if (mdb_ctf_lookup_by_name("struct dmu_buf_impl", &id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
		mdb_warn("couldn't find struct dmu_buf_impl_t");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
	if (GETMEMBID(addr, &id, db_objset, objset) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
	    GETMEMBID(addr, &id, db, db) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
	    GETMEMBID(addr, &id, db_level, level) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
	    GETMEMBID(addr, &id, db_blkid, blkid)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
	if (getrefcount(addr, &id, "db_holds", &holds)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
	if (db.db_object == DMU_META_DNODE_OBJECT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
		(void) strcpy(objectname, "mdn");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
		(void) mdb_snprintf(objectname, sizeof (objectname), "%llx",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
		    (u_longlong_t)db.db_object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	if (blkid == DB_BONUS_BLKID)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
		(void) strcpy(blkidname, "bonus");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
		(void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
		    (u_longlong_t)blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
	if (objset_name(objset, path)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	mdb_printf("%p %8s %1u %9s %2llu %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
	    addr, objectname, level, blkidname, holds, path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
dbuf_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
#define	HISTOSZ 32
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
	uintptr_t dbp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
	dmu_buf_impl_t db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
	dbuf_hash_table_t ht;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
	uint64_t bucket, ndbufs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
	uint64_t histo[HISTOSZ];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	uint64_t histo2[HISTOSZ];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
	int i, maxidx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
	if (mdb_readvar(&ht, "dbuf_hash_table") == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
		mdb_warn("failed to read 'dbuf_hash_table'");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
	for (i = 0; i < HISTOSZ; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
		histo[i] = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
		histo2[i] = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
	ndbufs = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
	for (bucket = 0; bucket < ht.hash_table_mask+1; bucket++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
		int len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
		if (mdb_vread(&dbp, sizeof (void *),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
		    (uintptr_t)(ht.hash_table+bucket)) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
			mdb_warn("failed to read hash bucket %u at %p",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
			    bucket, ht.hash_table+bucket);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
		len = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
		while (dbp != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
			if (mdb_vread(&db, sizeof (dmu_buf_impl_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
			    dbp) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
				mdb_warn("failed to read dbuf at %p", dbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
				return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
			dbp = (uintptr_t)db.db_hash_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
			for (i = MIN(len, HISTOSZ - 1); i >= 0; i--)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
				histo2[i]++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
			len++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
			ndbufs++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
		if (len >= HISTOSZ)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
			len = HISTOSZ-1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
		histo[len]++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
	mdb_printf("hash table has %llu buckets, %llu dbufs "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
	    "(avg %llu buckets/dbuf)\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
	    ht.hash_table_mask+1, ndbufs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	    (ht.hash_table_mask+1)/ndbufs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
	mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	maxidx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
	for (i = 0; i < HISTOSZ; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
		if (histo[i] > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
			maxidx = i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
	mdb_printf("hash chain length	number of buckets\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
	for (i = 0; i <= maxidx; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
		mdb_printf("%u			%llu\n", i, histo[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
	mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
	maxidx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	for (i = 0; i < HISTOSZ; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
		if (histo2[i] > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
			maxidx = i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
	mdb_printf("hash chain depth	number of dbufs\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
	for (i = 0; i <= maxidx; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
		mdb_printf("%u or more		%llu	%llu%%\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
		    i, histo2[i], histo2[i]*100/ndbufs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
typedef struct dbufs_data {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
	mdb_ctf_id_t id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	uint64_t objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
	uint64_t object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
	uint64_t level;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
	uint64_t blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
	char *osname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
} dbufs_data_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
#define	DBUFS_UNSET	(0xbaddcafedeadbeefULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
dbufs_cb(uintptr_t addr, const void *unknown, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
	dbufs_data_t *data = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
	uintptr_t objset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
	dmu_buf_t db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
	uint8_t level;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
	uint64_t blkid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
	if (GETMEMBID(addr, &data->id, db_objset, objset) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
	    GETMEMBID(addr, &data->id, db, db) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
	    GETMEMBID(addr, &data->id, db_level, level) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
	    GETMEMBID(addr, &data->id, db_blkid, blkid)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
	if ((data->objset == DBUFS_UNSET || data->objset == objset) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
	    (data->osname == NULL || (objset_name(objset, osname) == 0 &&
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
   649
	    strcmp(data->osname, osname) == 0)) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
	    (data->object == DBUFS_UNSET || data->object == db.db_object) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	    (data->level == DBUFS_UNSET || data->level == level) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
	    (data->blkid == DBUFS_UNSET || data->blkid == blkid)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
		mdb_printf("%#lr\n", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
	return (WALK_NEXT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
dbufs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
	dbufs_data_t data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	char *object = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	char *blkid = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
	data.objset = data.object = data.level = data.blkid = DBUFS_UNSET;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
	data.osname = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
	if (mdb_getopts(argc, argv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	    'O', MDB_OPT_UINT64, &data.objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
	    'n', MDB_OPT_STR, &data.osname,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
	    'o', MDB_OPT_STR, &object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
	    'l', MDB_OPT_UINT64, &data.level,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
	    'b', MDB_OPT_STR, &blkid) != argc) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
	if (object) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
		if (strcmp(object, "mdn") == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
			data.object = DMU_META_DNODE_OBJECT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
			data.object = mdb_strtoull(object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
	if (blkid) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
		if (strcmp(blkid, "bonus") == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
			data.blkid = DB_BONUS_BLKID;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
			data.blkid = mdb_strtoull(blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	if (mdb_ctf_lookup_by_name("struct dmu_buf_impl", &data.id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
		mdb_warn("couldn't find struct dmu_buf_impl_t");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
   699
	if (mdb_walk("dmu_buf_impl_t", dbufs_cb, &data) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
		mdb_warn("can't walk dbufs");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
typedef struct abuf_find_data {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
	dva_t dva;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	mdb_ctf_id_t id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
} abuf_find_data_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
abuf_find_cb(uintptr_t addr, const void *unknown, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	abuf_find_data_t *data = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
	dva_t dva;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	if (GETMEMBID(addr, &data->id, b_dva, dva)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
	if (dva.dva_word[0] == data->dva.dva_word[0] &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
	    dva.dva_word[1] == data->dva.dva_word[1]) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
		mdb_printf("%#lr\n", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
	return (WALK_NEXT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
abuf_find(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
	abuf_find_data_t data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
	GElf_Sym sym;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	const char *syms[] = {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2459
diff changeset
   738
		"ARC_mru",
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2459
diff changeset
   739
		"ARC_mru_ghost",
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2459
diff changeset
   740
		"ARC_mfu",
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2459
diff changeset
   741
		"ARC_mfu_ghost",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
	};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	if (argc != 2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
	for (i = 0; i < 2; i ++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
		switch (argv[i].a_type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
		case MDB_TYPE_STRING:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
			data.dva.dva_word[i] = mdb_strtoull(argv[i].a_un.a_str);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
		case MDB_TYPE_IMMEDIATE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
			data.dva.dva_word[i] = argv[i].a_un.a_val;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
			return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
	if (mdb_ctf_lookup_by_name("struct arc_buf_hdr", &data.id) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
		mdb_warn("couldn't find struct arc_buf_hdr");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
	for (i = 0; i < sizeof (syms) / sizeof (syms[0]); i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
		if (mdb_lookup_by_name(syms[i], &sym)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
			mdb_warn("can't find symbol %s", syms[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
		if (mdb_pwalk("list", abuf_find_cb, &data, sym.st_value) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
			mdb_warn("can't walk %s", syms[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   780
/*ARGSUSED*/
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   781
static int
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   782
arc_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   783
{
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   784
	kstat_named_t *stats;
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   785
	GElf_Sym sym;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   786
	int nstats, i;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   787
	uint_t opt_a = FALSE;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   788
	uint_t opt_b = FALSE;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   789
	uint_t shift = 0;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   790
	const char *suffix;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   791
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   792
	static const char *bytestats[] = {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   793
		"p", "c", "c_min", "c_max", "size", NULL
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   794
	};
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   795
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   796
	static const char *extras[] = {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   797
		"arc_no_grow", "arc_tempreserve",
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   798
		"arc_meta_used", "arc_meta_limit", "arc_meta_max",
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   799
		NULL
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   800
	};
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   801
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   802
	if (mdb_lookup_by_name("arc_stats", &sym) == -1) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   803
		mdb_warn("failed to find 'arc_stats'");
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   804
		return (DCMD_ERR);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   805
	}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   806
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   807
	stats = mdb_zalloc(sym.st_size, UM_SLEEP | UM_GC);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   808
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   809
	if (mdb_vread(stats, sym.st_size, sym.st_value) == -1) {
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   810
		mdb_warn("couldn't read 'arc_stats' at %p", sym.st_value);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   811
		return (DCMD_ERR);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   812
	}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   813
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   814
	nstats = sym.st_size / sizeof (kstat_named_t);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   815
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   816
	/* NB: -a / opt_a are ignored for backwards compatability */
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   817
	if (mdb_getopts(argc, argv,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   818
	    'a', MDB_OPT_SETBITS, TRUE, &opt_a,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   819
	    'b', MDB_OPT_SETBITS, TRUE, &opt_b,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   820
	    'k', MDB_OPT_SETBITS, 10, &shift,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   821
	    'm', MDB_OPT_SETBITS, 20, &shift,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   822
	    'g', MDB_OPT_SETBITS, 30, &shift,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   823
	    NULL) != argc)
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   824
		return (DCMD_USAGE);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   825
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   826
	if (!opt_b && !shift)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   827
		shift = 20;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   828
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   829
	switch (shift) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   830
	case 0:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   831
		suffix = "B";
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   832
		break;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   833
	case 10:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   834
		suffix = "KB";
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   835
		break;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   836
	case 20:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   837
		suffix = "MB";
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   838
		break;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   839
	case 30:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   840
		suffix = "GB";
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   841
		break;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   842
	default:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   843
		suffix = "XX";
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   844
	}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   845
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   846
	for (i = 0; i < nstats; i++) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   847
		int j;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   848
		boolean_t bytes = B_FALSE;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   849
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   850
		for (j = 0; bytestats[j]; j++) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   851
			if (strcmp(stats[i].name, bytestats[j]) == 0) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   852
				bytes = B_TRUE;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   853
				break;
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   854
			}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   855
		}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   856
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   857
		if (bytes) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   858
			mdb_printf("%-25s = %9llu %s\n", stats[i].name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   859
			    stats[i].value.ui64 >> shift, suffix);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   860
		} else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   861
			mdb_printf("%-25s = %9llu\n", stats[i].name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   862
			    stats[i].value.ui64);
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   863
		}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   864
	}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   865
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   866
	for (i = 0; extras[i]; i++) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   867
		uint64_t buf;
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   868
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   869
		if (mdb_lookup_by_name(extras[i], &sym) == -1) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   870
			mdb_warn("failed to find '%s'", extras[i]);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   871
			return (DCMD_ERR);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   872
		}
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   873
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   874
		if (sym.st_size != sizeof (uint64_t) &&
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   875
		    sym.st_size != sizeof (uint32_t)) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   876
			mdb_warn("expected scalar for variable '%s'\n",
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   877
			    extras[i]);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   878
			return (DCMD_ERR);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   879
		}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   880
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   881
		if (mdb_vread(&buf, sym.st_size, sym.st_value) == -1) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   882
			mdb_warn("couldn't read '%s'", extras[i]);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   883
			return (DCMD_ERR);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   884
		}
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   885
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   886
		mdb_printf("%-25s = ", extras[i]);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   887
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   888
		/* NB: all the 64-bit extras happen to be byte counts */
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   889
		if (sym.st_size == sizeof (uint64_t))
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   890
			mdb_printf("%9llu %s\n", buf >> shift, suffix);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   891
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   892
		if (sym.st_size == sizeof (uint32_t))
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   893
			mdb_printf("%9d\n", *((uint32_t *)&buf));
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
   894
	}
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   895
	return (DCMD_OK);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   896
}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 3361
diff changeset
   897
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
 * ::spa
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
 * 	-c	Print configuration information as well
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
 * 	-v	Print vdev state
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
 * 	-e	Print vdev error stats
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
 * Print a summarized spa_t.  When given no arguments, prints out a table of all
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
 * active pools on the system.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
spa_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
	spa_t spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
	const char *statetab[] = { "ACTIVE", "EXPORTED", "DESTROYED",
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   914
		"SPARE", "L2CACHE", "UNINIT", "UNAVAIL", "POTENTIAL" };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
	const char *state;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
	int config = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
	int vdevs = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
	int errors = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
	if (mdb_getopts(argc, argv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
	    'c', MDB_OPT_SETBITS, TRUE, &config,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
	    'v', MDB_OPT_SETBITS, TRUE, &vdevs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
	    'e', MDB_OPT_SETBITS, TRUE, &errors,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
	    NULL) != argc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	if (!(flags & DCMD_ADDRSPEC)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
		if (mdb_walk_dcmd("spa", "spa", argc, argv) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
			mdb_warn("can't walk spa");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
		return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
	if (flags & DCMD_PIPE_OUT) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
		mdb_printf("%#lr\n", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
		return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
	if (DCMD_HDRSPEC(flags))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
		mdb_printf("%<u>%-?s %9s %-*s%</u>\n", "ADDR", "STATE",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
		    sizeof (uintptr_t) == 4 ? 60 : 52, "NAME");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
		mdb_warn("failed to read spa_t at %p", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
	if (spa.spa_state < 0 || spa.spa_state > POOL_STATE_UNAVAIL)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 952
diff changeset
   951
		state = "UNKNOWN";
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
		state = statetab[spa.spa_state];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   955
	mdb_printf("%0?p %9s %s\n", addr, state, spa.spa_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
	if (config) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
		mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
		mdb_inc_indent(4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
		if (mdb_call_dcmd("spa_config", addr, flags, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
		    NULL) != DCMD_OK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
		mdb_dec_indent(4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
	if (vdevs || errors) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
		mdb_arg_t v;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
		v.a_type = MDB_TYPE_STRING;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
		v.a_un.a_str = "-e";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
		mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
		mdb_inc_indent(4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
		if (mdb_call_dcmd("spa_vdevs", addr, flags, errors ? 1 : 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
		    &v) != DCMD_OK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
		mdb_dec_indent(4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
 * ::spa_config
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
 * Given a spa_t, print the configuration information stored in spa_config.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
 * Since it's just an nvlist, format it as an indented list of name=value pairs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
 * We simply read the value of spa_config and pass off to ::nvlist.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
spa_print_config(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
	spa_t spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	if (argc != 0 || !(flags & DCMD_ADDRSPEC))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
		mdb_warn("failed to read spa_t at %p", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
	if (spa.spa_config == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
		mdb_printf("(none)\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
		return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
	return (mdb_call_dcmd("nvlist", (uintptr_t)spa.spa_config, flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
	    0, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
 * ::vdev
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
 * Print out a summarized vdev_t, in the following form:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
 * ADDR             STATE	AUX            DESC
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
 * fffffffbcde23df0 HEALTHY	-              /dev/dsk/c0t0d0
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
 * If '-r' is specified, recursively visit all children.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
 * With '-e', the statistics associated with the vdev are printed as well.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
static int
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
  1026
do_print_vdev(uintptr_t addr, int flags, int depth, int stats,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
    int recursive)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	vdev_t vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
	char desc[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
	int c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
	uintptr_t *child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
	const char *state, *aux;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
	if (mdb_vread(&vdev, sizeof (vdev), (uintptr_t)addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
		mdb_warn("failed to read vdev_t at %p\n", (uintptr_t)addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
	if (flags & DCMD_PIPE_OUT) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
		mdb_printf("%#lr", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
		if (vdev.vdev_path != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
			if (mdb_readstr(desc, sizeof (desc),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
			    (uintptr_t)vdev.vdev_path) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
				mdb_warn("failed to read vdev_path at %p\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
				    vdev.vdev_path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
				return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
		} else if (vdev.vdev_ops != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
			vdev_ops_t ops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
			if (mdb_vread(&ops, sizeof (ops),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
			    (uintptr_t)vdev.vdev_ops) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
				mdb_warn("failed to read vdev_ops at %p\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
				    vdev.vdev_ops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
				return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
			(void) strcpy(desc, ops.vdev_op_type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
			(void) strcpy(desc, "<unknown>");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
		if (depth == 0 && DCMD_HDRSPEC(flags))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
			mdb_printf("%<u>%-?s %-9s %-12s %-*s%</u>\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
			    "ADDR", "STATE", "AUX",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
			    sizeof (uintptr_t) == 4 ? 43 : 35,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
			    "DESCRIPTION");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
		mdb_printf("%0?p ", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
		switch (vdev.vdev_state) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
		case VDEV_STATE_CLOSED:
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1073
			state = "CLOSED";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1074
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
		case VDEV_STATE_OFFLINE:
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1076
			state = "OFFLINE";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1077
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
		case VDEV_STATE_CANT_OPEN:
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1079
			state = "CANT_OPEN";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1080
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
		case VDEV_STATE_DEGRADED:
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1082
			state = "DEGRADED";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1083
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
		case VDEV_STATE_HEALTHY:
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1085
			state = "HEALTHY";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1086
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4217
diff changeset
  1087
		case VDEV_STATE_REMOVED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4217
diff changeset
  1088
			state = "REMOVED";
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4217
diff changeset
  1089
			break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4217
diff changeset
  1090
		case VDEV_STATE_FAULTED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4217
diff changeset
  1091
			state = "FAULTED";
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4217
diff changeset
  1092
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
		default:
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1094
			state = "UNKNOWN";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1095
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
		switch (vdev.vdev_stat.vs_aux) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
		case VDEV_AUX_NONE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
			aux = "-";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
		case VDEV_AUX_OPEN_FAILED:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
			aux = "OPEN_FAILED";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
		case VDEV_AUX_CORRUPT_DATA:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
			aux = "CORRUPT_DATA";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
		case VDEV_AUX_NO_REPLICAS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
			aux = "NO_REPLICAS";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
		case VDEV_AUX_BAD_GUID_SUM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
			aux = "BAD_GUID_SUM";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
		case VDEV_AUX_TOO_SMALL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
			aux = "TOO_SMALL";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
		case VDEV_AUX_BAD_LABEL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
			aux = "BAD_LABEL";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
			break;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1120
		case VDEV_AUX_VERSION_NEWER:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1121
			aux = "VERS_NEWER";
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1122
			break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1123
		case VDEV_AUX_VERSION_OLDER:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1124
			aux = "VERS_OLDER";
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1125
			break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1126
		case VDEV_AUX_SPARED:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1127
			aux = "SPARED";
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1128
			break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1129
		case VDEV_AUX_ERR_EXCEEDED:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1130
			aux = "ERR_EXCEEDED";
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1131
			break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1132
		case VDEV_AUX_IO_FAILURE:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1133
			aux = "IO_FAILURE";
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1134
			break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1135
		case VDEV_AUX_BAD_LOG:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1136
			aux = "BAD_LOG";
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6643
diff changeset
  1137
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
			aux = "UNKNOWN";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
		mdb_printf("%-9s %-12s %*s%s\n", state, aux, depth, "", desc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
		if (stats) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
			vdev_stat_t *vs = &vdev.vdev_stat;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
			int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
			mdb_inc_indent(4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
			mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
			mdb_printf("%<u>       %12s %12s %12s %12s "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
			    "%12s%</u>\n", "READ", "WRITE", "FREE", "CLAIM",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
			    "IOCTL");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
			mdb_printf("OPS     ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
			for (i = 1; i < ZIO_TYPES; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
				mdb_printf("%11#llx%s", vs->vs_ops[i],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
				    i == ZIO_TYPES - 1 ? "" : "  ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
			mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
			mdb_printf("BYTES   ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
			for (i = 1; i < ZIO_TYPES; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
				mdb_printf("%11#llx%s", vs->vs_bytes[i],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
				    i == ZIO_TYPES - 1 ? "" : "  ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
			mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
			mdb_printf("EREAD    %10#llx\n", vs->vs_read_errors);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
			mdb_printf("EWRITE   %10#llx\n", vs->vs_write_errors);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
			mdb_printf("ECKSUM   %10#llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
			    vs->vs_checksum_errors);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
			mdb_dec_indent(4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
  1173
		if (stats)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
			mdb_printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
	children = vdev.vdev_children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
	if (children == 0 || !recursive)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
		return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	child = mdb_alloc(children * sizeof (void *), UM_SLEEP | UM_GC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
	if (mdb_vread(child, children * sizeof (void *),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
	    (uintptr_t)vdev.vdev_child) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
		mdb_warn("failed to read vdev children at %p", vdev.vdev_child);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
	for (c = 0; c < children; c++) {
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
  1190
		if (do_print_vdev(child[c], flags, depth + 2, stats,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
		    recursive))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
			return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
vdev_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	int recursive = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	int stats = FALSE;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1203
	uint64_t depth = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	if (mdb_getopts(argc, argv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
	    'r', MDB_OPT_SETBITS, TRUE, &recursive,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	    'e', MDB_OPT_SETBITS, TRUE, &stats,
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1208
	    'd', MDB_OPT_UINT64, &depth,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
	    NULL) != argc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
	if (!(flags & DCMD_ADDRSPEC)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
		mdb_warn("no vdev_t address given\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1217
	return (do_print_vdev(addr, flags, (int)depth, stats, recursive));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1220
typedef struct metaslab_walk_data {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1221
	uint64_t mw_numvdevs;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1222
	uintptr_t *mw_vdevs;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1223
	int mw_curvdev;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1224
	uint64_t mw_nummss;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1225
	uintptr_t *mw_mss;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1226
	int mw_curms;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1227
} metaslab_walk_data_t;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1228
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1229
static int
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1230
metaslab_walk_step(mdb_walk_state_t *wsp)
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1231
{
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1232
	metaslab_walk_data_t *mw = wsp->walk_data;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1233
	metaslab_t ms;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1234
	uintptr_t msp;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1235
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1236
	if (mw->mw_curvdev >= mw->mw_numvdevs)
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1237
		return (WALK_DONE);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1238
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1239
	if (mw->mw_mss == NULL) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1240
		uintptr_t mssp;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1241
		uintptr_t vdevp;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1242
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1243
		ASSERT(mw->mw_curms == 0);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1244
		ASSERT(mw->mw_nummss == 0);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1245
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1246
		vdevp = mw->mw_vdevs[mw->mw_curvdev];
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1247
		if (GETMEMB(vdevp, struct vdev, vdev_ms, mssp) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1248
		    GETMEMB(vdevp, struct vdev, vdev_ms_count, mw->mw_nummss)) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1249
			return (WALK_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1250
		}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1251
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1252
		mw->mw_mss = mdb_alloc(mw->mw_nummss * sizeof (void*),
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1253
		    UM_SLEEP | UM_GC);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1254
		if (mdb_vread(mw->mw_mss, mw->mw_nummss * sizeof (void*),
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1255
		    mssp) == -1) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1256
			mdb_warn("failed to read vdev_ms at %p", mssp);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1257
			return (WALK_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1258
		}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1259
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1260
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1261
	if (mw->mw_curms >= mw->mw_nummss) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1262
		mw->mw_mss = NULL;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1263
		mw->mw_curms = 0;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1264
		mw->mw_nummss = 0;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1265
		mw->mw_curvdev++;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1266
		return (WALK_NEXT);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1267
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1268
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1269
	msp = mw->mw_mss[mw->mw_curms];
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1270
	if (mdb_vread(&ms, sizeof (metaslab_t), msp) == -1) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1271
		mdb_warn("failed to read metaslab_t at %p", msp);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1272
		return (WALK_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1273
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1274
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1275
	mw->mw_curms++;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1276
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1277
	return (wsp->walk_callback(msp, &ms, wsp->walk_cbdata));
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1278
}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1279
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1280
/* ARGSUSED */
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1281
static int
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1282
metaslab_walk_init(mdb_walk_state_t *wsp)
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1283
{
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1284
	metaslab_walk_data_t *mw;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1285
	uintptr_t root_vdevp;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1286
	uintptr_t childp;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1287
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1288
	if (wsp->walk_addr == NULL) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1289
		mdb_warn("must supply address of spa_t\n");
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1290
		return (WALK_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1291
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1292
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1293
	mw = mdb_zalloc(sizeof (metaslab_walk_data_t), UM_SLEEP | UM_GC);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1294
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1295
	if (GETMEMB(wsp->walk_addr, struct spa, spa_root_vdev, root_vdevp) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1296
	    GETMEMB(root_vdevp, struct vdev, vdev_children, mw->mw_numvdevs) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1297
	    GETMEMB(root_vdevp, struct vdev, vdev_child, childp)) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1298
		return (DCMD_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1299
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1300
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1301
	mw->mw_vdevs = mdb_alloc(mw->mw_numvdevs * sizeof (void *),
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1302
	    UM_SLEEP | UM_GC);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1303
	if (mdb_vread(mw->mw_vdevs, mw->mw_numvdevs * sizeof (void *),
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1304
	    childp) == -1) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1305
		mdb_warn("failed to read root vdev children at %p", childp);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1306
		return (DCMD_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1307
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1308
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1309
	wsp->walk_data = mw;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1310
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1311
	return (WALK_NEXT);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1312
}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1313
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
typedef struct mdb_spa {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
	uintptr_t spa_dsl_pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
	uintptr_t spa_root_vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1317
} mdb_spa_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
typedef struct mdb_dsl_dir {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
	uintptr_t dd_phys;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
	int64_t dd_space_towrite[TXG_SIZE];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
} mdb_dsl_dir_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
typedef struct mdb_dsl_dir_phys {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
	uint64_t dd_used_bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
	uint64_t dd_compressed_bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
	uint64_t dd_uncompressed_bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
} mdb_dsl_dir_phys_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
typedef struct mdb_vdev {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
	uintptr_t vdev_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
	uintptr_t vdev_ms;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
	uint64_t vdev_ms_count;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
	vdev_stat_t vdev_stat;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1335
} mdb_vdev_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
typedef struct mdb_metaslab {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
	space_map_t ms_allocmap[TXG_SIZE];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
	space_map_t ms_freemap[TXG_SIZE];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
	space_map_t ms_map;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1341
	space_map_obj_t ms_smo;
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1342
	space_map_obj_t ms_smo_syncing;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
} mdb_metaslab_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1345
typedef struct space_data {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1346
	uint64_t ms_allocmap[TXG_SIZE];
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1347
	uint64_t ms_freemap[TXG_SIZE];
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1348
	uint64_t ms_map;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1349
	uint64_t avail;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1350
	uint64_t nowavail;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1351
} space_data_t;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1352
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1353
/* ARGSUSED */
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1354
static int
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1355
space_cb(uintptr_t addr, const void *unknown, void *arg)
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1356
{
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1357
	space_data_t *sd = arg;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1358
	mdb_metaslab_t ms;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1359
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1360
	if (GETMEMB(addr, struct metaslab, ms_allocmap, ms.ms_allocmap) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1361
	    GETMEMB(addr, struct metaslab, ms_freemap, ms.ms_freemap) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1362
	    GETMEMB(addr, struct metaslab, ms_map, ms.ms_map) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1363
	    GETMEMB(addr, struct metaslab, ms_smo, ms.ms_smo) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1364
	    GETMEMB(addr, struct metaslab, ms_smo_syncing, ms.ms_smo_syncing)) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1365
		return (WALK_ERR);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1366
	}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1367
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1368
	sd->ms_allocmap[0] += ms.ms_allocmap[0].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1369
	sd->ms_allocmap[1] += ms.ms_allocmap[1].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1370
	sd->ms_allocmap[2] += ms.ms_allocmap[2].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1371
	sd->ms_allocmap[3] += ms.ms_allocmap[3].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1372
	sd->ms_freemap[0] += ms.ms_freemap[0].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1373
	sd->ms_freemap[1] += ms.ms_freemap[1].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1374
	sd->ms_freemap[2] += ms.ms_freemap[2].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1375
	sd->ms_freemap[3] += ms.ms_freemap[3].sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1376
	sd->ms_map += ms.ms_map.sm_space;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1377
	sd->avail += ms.ms_map.sm_size - ms.ms_smo.smo_alloc;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1378
	sd->nowavail += ms.ms_map.sm_size - ms.ms_smo_syncing.smo_alloc;
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1379
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1380
	return (WALK_NEXT);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1381
}
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1382
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1383
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
 * ::spa_space [-b]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1386
 * Given a spa_t, print out it's on-disk space usage and in-core
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
 * estimates of future usage.  If -b is given, print space in bytes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
 * Otherwise print in megabytes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
spa_space(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
	mdb_spa_t spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
	uintptr_t dp_root_dir;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
	mdb_dsl_dir_t dd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
	mdb_dsl_dir_phys_t dsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
	uint64_t children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
	uintptr_t childaddr;
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1400
	space_data_t sd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
	int shift = 20;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
	char *suffix = "M";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
	int bits = FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
	if (mdb_getopts(argc, argv, 'b', MDB_OPT_SETBITS, TRUE, &bits, NULL) !=
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
	    argc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
	if (!(flags & DCMD_ADDRSPEC))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
	if (bits) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
		shift = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
		suffix = "";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
	if (GETMEMB(addr, struct spa, spa_dsl_pool, spa.spa_dsl_pool) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
	    GETMEMB(addr, struct spa, spa_root_vdev, spa.spa_root_vdev) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
	    GETMEMB(spa.spa_root_vdev, struct vdev, vdev_children, children) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
	    GETMEMB(spa.spa_root_vdev, struct vdev, vdev_child, childaddr) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
	    GETMEMB(spa.spa_dsl_pool, struct dsl_pool,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1421
	    dp_root_dir, dp_root_dir) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
	    GETMEMB(dp_root_dir, struct dsl_dir, dd_phys, dd.dd_phys) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
	    GETMEMB(dp_root_dir, struct dsl_dir,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
	    dd_space_towrite, dd.dd_space_towrite) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
	    GETMEMB(dd.dd_phys, struct dsl_dir_phys,
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1426
	    dd_used_bytes, dsp.dd_used_bytes) ||
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1427
	    GETMEMB(dd.dd_phys, struct dsl_dir_phys,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
	    dd_compressed_bytes, dsp.dd_compressed_bytes) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
	    GETMEMB(dd.dd_phys, struct dsl_dir_phys,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
	    dd_uncompressed_bytes, dsp.dd_uncompressed_bytes)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
	mdb_printf("dd_space_towrite = %llu%s %llu%s %llu%s %llu%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
	    dd.dd_space_towrite[0] >> shift, suffix,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
	    dd.dd_space_towrite[1] >> shift, suffix,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
	    dd.dd_space_towrite[2] >> shift, suffix,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
	    dd.dd_space_towrite[3] >> shift, suffix);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
	mdb_printf("dd_phys.dd_used_bytes = %llu%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1441
	    dsp.dd_used_bytes >> shift, suffix);
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1442
	mdb_printf("dd_phys.dd_compressed_bytes = %llu%s\n",
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1443
	    dsp.dd_compressed_bytes >> shift, suffix);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1444
	mdb_printf("dd_phys.dd_uncompressed_bytes = %llu%s\n",
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1445
	    dsp.dd_uncompressed_bytes >> shift, suffix);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1447
	bzero(&sd, sizeof (sd));
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1448
	if (mdb_pwalk("metaslab", space_cb, &sd, addr) != 0) {
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1449
		mdb_warn("can't walk metaslabs");
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1450
		return (DCMD_ERR);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
	mdb_printf("ms_allocmap = %llu%s %llu%s %llu%s %llu%s\n",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1454
	    sd.ms_allocmap[0] >> shift, suffix,
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1455
	    sd.ms_allocmap[1] >> shift, suffix,
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1456
	    sd.ms_allocmap[2] >> shift, suffix,
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1457
	    sd.ms_allocmap[3] >> shift, suffix);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
	mdb_printf("ms_freemap = %llu%s %llu%s %llu%s %llu%s\n",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1459
	    sd.ms_freemap[0] >> shift, suffix,
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1460
	    sd.ms_freemap[1] >> shift, suffix,
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1461
	    sd.ms_freemap[2] >> shift, suffix,
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1462
	    sd.ms_freemap[3] >> shift, suffix);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1463
	mdb_printf("ms_map = %llu%s\n", sd.ms_map >> shift, suffix);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1464
	mdb_printf("last synced avail = %llu%s\n", sd.avail >> shift, suffix);
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1465
	mdb_printf("current syncing avail = %llu%s\n",
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  1466
	    sd.nowavail >> shift, suffix);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1468
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1470
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
 * ::spa_verify
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1473
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1474
 * Given a spa_t, verify that that the pool is self-consistent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
 * Currently, it only checks to make sure that the vdev tree exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1476
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1477
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
spa_verify(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1481
	spa_t spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1482
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
	if (argc != 0 || !(flags & DCMD_ADDRSPEC))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
		mdb_warn("failed to read spa_t at %p", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
	if (spa.spa_root_vdev == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
		mdb_printf("no vdev tree present\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
		return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	return (DCMD_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
8341
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1499
static int
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1500
spa_print_aux(spa_aux_vdev_t *sav, uint_t flags, mdb_arg_t *v,
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1501
    const char *name)
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1502
{
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1503
	uintptr_t *aux;
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1504
	size_t len;
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1505
	int ret, i;
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1506
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1507
	/*
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1508
	 * Iterate over aux vdevs and print those out as well.  This is a
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1509
	 * little annoying because we don't have a root vdev to pass to ::vdev.
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1510
	 * Instead, we print a single line and then call it for each child
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1511
	 * vdev.
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1512
	 */
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1513
	if (sav->sav_count != 0) {
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1514
		v[1].a_type = MDB_TYPE_STRING;
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1515
		v[1].a_un.a_str = "-d";
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1516
		v[2].a_type = MDB_TYPE_IMMEDIATE;
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1517
		v[2].a_un.a_val = 2;
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1518
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1519
		len = sav->sav_count * sizeof (uintptr_t);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1520
		aux = mdb_alloc(len, UM_SLEEP);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1521
		if (mdb_vread(aux, len,
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1522
		    (uintptr_t)sav->sav_vdevs) == -1) {
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1523
			mdb_free(aux, len);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1524
			mdb_warn("failed to read l2cache vdevs at %p",
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1525
			    sav->sav_vdevs);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1526
			return (DCMD_ERR);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1527
		}
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1528
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1529
		mdb_printf("%-?s %-9s %-12s %s\n", "-", "-", "-", name);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1530
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1531
		for (i = 0; i < sav->sav_count; i++) {
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1532
			ret = mdb_call_dcmd("vdev", aux[i], flags, 3, v);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1533
			if (ret != DCMD_OK) {
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1534
				mdb_free(aux, len);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1535
				return (ret);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1536
			}
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1537
		}
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1538
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1539
		mdb_free(aux, len);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1540
	}
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1541
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1542
	return (0);
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1543
}
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1544
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
 * ::spa_vdevs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
 * 	-e	Include error stats
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1550
 * Print out a summarized list of vdevs for the given spa_t.
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1551
 * This is accomplished by invoking "::vdev -re" on the root vdev, as well as
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1552
 * iterating over the cache devices.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1553
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1554
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1555
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1556
spa_vdevs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1557
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
	spa_t spa;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1559
	mdb_arg_t v[3];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1560
	int errors = FALSE;
8341
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1561
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
	if (mdb_getopts(argc, argv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
	    'e', MDB_OPT_SETBITS, TRUE, &errors,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
	    NULL) != argc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
	if (!(flags & DCMD_ADDRSPEC))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
		return (DCMD_USAGE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
		mdb_warn("failed to read spa_t at %p", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
		return (DCMD_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1576
	/*
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1577
	 * Unitialized spa_t structures can have a NULL root vdev.
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1578
	 */
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1579
	if (spa.spa_root_vdev == NULL) {
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1580
		mdb_printf("no associated vdevs\n");
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1581
		return (DCMD_OK);
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1582
	}
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1583
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1584
	v[0].a_type = MDB_TYPE_STRING;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1585
	v[0].a_un.a_str = errors ? "-re" : "-r";
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1586
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1587
	ret = mdb_call_dcmd("vdev", (uintptr_t)spa.spa_root_vdev,
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1588
	    flags, 1, v);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1589
	if (ret != DCMD_OK)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1590
		return (ret);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1591
8341
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1592
	if (spa_print_aux(&spa.spa_l2cache, flags, v, "cache") != 0 ||
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1593
	    spa_print_aux(&spa.spa_spares, flags, v, "spares") != 0)
53c5e7987263 6783576 ::spa -v should include spares
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7846
diff changeset
  1594
		return (DCMD_ERR);
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1595
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6245
diff changeset
  1596
	return (DCMD_OK);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1599
/*
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1600
 * ::zio
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1601
 *
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1602
 * Print a summary of zio_t and all its children.  This is intended to display a
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1603
 * zio tree, and hence we only pick the most important pieces of information for
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1604
 * the main summary.  More detailed information can always be found by doing a
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1605
 * '::print zio' on the underlying zio_t.  The columns we display are:
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1606
 *
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1607
 *	ADDRESS		TYPE	STAGE		WAITER
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1608
 *
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1609
 * The 'address' column is indented by one space for each depth level as we
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1610
 * descend down the tree.
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1611
 */
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4055
diff changeset
  1612
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1613
#define	ZIO_MAXINDENT	24
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1614
#define	ZIO_MAXWIDTH	(sizeof (uintptr_t) * 2 + ZIO_MAXINDENT)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1615
#define	ZIO_WALK_SELF	0
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1616
#define	ZIO_WALK_CHILD	1
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1617
#define	ZIO_WALK_PARENT	2
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1618
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1619
typedef struct zio_print_args {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1620
	int	zpa_current_depth;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1621
	int	zpa_min_depth;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1622
	int	zpa_max_depth;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1623
	int	zpa_type;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1624
	uint_t	zpa_flags;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1625
} zio_print_args_t;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1626
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1627
static int zio_child_cb(uintptr_t addr, const void *unknown, void *arg);
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4055
diff changeset
  1628
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1629
static int
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1630
zio_print_cb(uintptr_t addr, const void *data, void *priv)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1631
{
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1632
	const zio_t *zio = data;
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1633
	zio_print_args_t *zpa = priv;
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1634
	mdb_ctf_id_t type_enum, stage_enum;
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1635
	int indent = zpa->zpa_current_depth;
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1636
	const char *type, *stage;
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1637
	uintptr_t laddr;
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1638
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1639
	if (indent > ZIO_MAXINDENT)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1640
		indent = ZIO_MAXINDENT;
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1641
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1642
	if (mdb_ctf_lookup_by_name("enum zio_type", &type_enum) == -1 ||
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1643
	    mdb_ctf_lookup_by_name("enum zio_stage", &stage_enum) == -1) {
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1644
		mdb_warn("failed to lookup zio enums");
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1645
		return (WALK_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1646
	}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1647
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1648
	if ((type = mdb_ctf_enum_name(type_enum, zio->io_type)) != NULL)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1649
		type += sizeof ("ZIO_TYPE_") - 1;
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1650
	else
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1651
		type = "?";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1652
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1653
	if ((stage = mdb_ctf_enum_name(stage_enum, zio->io_stage)) != NULL)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1654
		stage += sizeof ("ZIO_STAGE_") - 1;
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1655
	else
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1656
		stage = "?";
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1657
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1658
	if (zpa->zpa_current_depth >= zpa->zpa_min_depth) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1659
		if (zpa->zpa_flags & DCMD_PIPE_OUT) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1660
			mdb_printf("%?p\n", addr);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1661
		} else {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1662
			mdb_printf("%*s%-*p %-5s %-16s ", indent, "",
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1663
			    ZIO_MAXWIDTH - indent, addr, type, stage);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1664
			if (zio->io_waiter)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1665
				mdb_printf("%?p\n", zio->io_waiter);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1666
			else
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1667
				mdb_printf("-\n");
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1668
		}
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1669
	}
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1670
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1671
	if (zpa->zpa_current_depth >= zpa->zpa_max_depth)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1672
		return (WALK_NEXT);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1673
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1674
	if (zpa->zpa_type == ZIO_WALK_PARENT)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1675
		laddr = addr + OFFSETOF(zio_t, io_parent_list);
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1676
	else
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1677
		laddr = addr + OFFSETOF(zio_t, io_child_list);
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1678
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1679
	zpa->zpa_current_depth++;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1680
	if (mdb_pwalk("list", zio_child_cb, zpa, laddr) != 0) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1681
		mdb_warn("failed to walk zio_t children at %p\n", laddr);
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1682
		return (WALK_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1683
	}
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1684
	zpa->zpa_current_depth--;
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1685
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1686
	return (WALK_NEXT);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1687
}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1688
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1689
/* ARGSUSED */
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1690
static int
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1691
zio_child_cb(uintptr_t addr, const void *unknown, void *arg)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1692
{
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1693
	zio_link_t zl;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1694
	zio_t zio;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1695
	uintptr_t ziop;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1696
	zio_print_args_t *zpa = arg;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1697
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1698
	if (mdb_vread(&zl, sizeof (zl), addr) == -1) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1699
		mdb_warn("failed to read zio_link_t at %p", addr);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1700
		return (WALK_ERR);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1701
	}
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1702
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1703
	if (zpa->zpa_type == ZIO_WALK_PARENT)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1704
		ziop = (uintptr_t)zl.zl_parent;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1705
	else
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1706
		ziop = (uintptr_t)zl.zl_child;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1707
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1708
	if (mdb_vread(&zio, sizeof (zio_t), ziop) == -1) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1709
		mdb_warn("failed to read zio_t at %p", ziop);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1710
		return (WALK_ERR);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1711
	}
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1712
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1713
	return (zio_print_cb(ziop, &zio, arg));
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1714
}
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1715
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1716
/* ARGSUSED */
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1717
static int
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1718
zio_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1719
{
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1720
	zio_t zio;
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1721
	zio_print_args_t zpa = { 0 };
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1722
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1723
	if (!(flags & DCMD_ADDRSPEC))
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1724
		return (DCMD_USAGE);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1725
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1726
	if (mdb_getopts(argc, argv,
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1727
	    'r', MDB_OPT_SETBITS, INT_MAX, &zpa.zpa_max_depth,
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1728
	    'c', MDB_OPT_SETBITS, ZIO_WALK_CHILD, &zpa.zpa_type,
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1729
	    'p', MDB_OPT_SETBITS, ZIO_WALK_PARENT, &zpa.zpa_type,
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1730
	    NULL) != argc)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1731
		return (DCMD_USAGE);
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1732
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1733
	zpa.zpa_flags = flags;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1734
	if (zpa.zpa_max_depth != 0) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1735
		if (zpa.zpa_type == ZIO_WALK_SELF)
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1736
			zpa.zpa_type = ZIO_WALK_CHILD;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1737
	} else if (zpa.zpa_type != ZIO_WALK_SELF) {
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1738
		zpa.zpa_min_depth = 1;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1739
		zpa.zpa_max_depth = 1;
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1740
	}
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1741
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1742
	if (mdb_vread(&zio, sizeof (zio_t), addr) == -1) {
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1743
		mdb_warn("failed to read zio_t at %p", addr);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1744
		return (DCMD_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1745
	}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1746
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1747
	if (!(flags & DCMD_PIPE_OUT) && DCMD_HDRSPEC(flags))
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1748
		mdb_printf("%<u>%-*s %-5s %-16s %-?s%</u>\n", ZIO_MAXWIDTH,
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4055
diff changeset
  1749
		    "ADDRESS", "TYPE", "STAGE", "WAITER");
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4055
diff changeset
  1750
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1751
	if (zio_print_cb(addr, &zio, &zpa) != WALK_NEXT)
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1752
		return (DCMD_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1753
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1754
	return (DCMD_OK);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1755
}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1756
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1757
/*
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1758
 * [addr]::zio_state
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1759
 *
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1760
 * Print a summary of all zio_t structures on the system, or for a particular
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1761
 * pool.  This is equivalent to '::walk zio_root | ::zio'.
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1762
 */
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1763
/*ARGSUSED*/
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1764
static int
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1765
zio_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1766
{
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1767
	/*
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1768
	 * MDB will remember the last address of the pipeline, so if we don't
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1769
	 * zero this we'll end up trying to walk zio structures for a
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1770
	 * non-existent spa_t.
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1771
	 */
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1772
	if (!(flags & DCMD_ADDRSPEC))
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1773
		addr = 0;
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1774
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1775
	return (mdb_pwalk_dcmd("zio_root", "zio", argc, argv, addr));
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1776
}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1777
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
typedef struct txg_list_walk_data {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1779
	uintptr_t lw_head[TXG_SIZE];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1780
	int	lw_txgoff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
	int	lw_maxoff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
	size_t	lw_offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1783
	void	*lw_obj;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
} txg_list_walk_data_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1786
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1787
txg_list_walk_init_common(mdb_walk_state_t *wsp, int txg, int maxoff)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1788
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1789
	txg_list_walk_data_t *lwd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1790
	txg_list_t list;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1793
	lwd = mdb_alloc(sizeof (txg_list_walk_data_t), UM_SLEEP | UM_GC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1794
	if (mdb_vread(&list, sizeof (txg_list_t), wsp->walk_addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
		mdb_warn("failed to read txg_list_t at %#lx", wsp->walk_addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1797
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
	for (i = 0; i < TXG_SIZE; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
		lwd->lw_head[i] = (uintptr_t)list.tl_head[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1801
	lwd->lw_offset = list.tl_offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1802
	lwd->lw_obj = mdb_alloc(lwd->lw_offset + sizeof (txg_node_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1803
	    UM_SLEEP | UM_GC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1804
	lwd->lw_txgoff = txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1805
	lwd->lw_maxoff = maxoff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1806
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1807
	wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1808
	wsp->walk_data = lwd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1809
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
	return (WALK_NEXT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1811
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1812
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
txg_list_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
	return (txg_list_walk_init_common(wsp, 0, TXG_SIZE-1));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1817
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1818
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1820
txg_list0_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	return (txg_list_walk_init_common(wsp, 0, 0));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
txg_list1_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
	return (txg_list_walk_init_common(wsp, 1, 1));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
txg_list2_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1833
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1834
	return (txg_list_walk_init_common(wsp, 2, 2));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1835
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1836
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
txg_list3_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1839
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
	return (txg_list_walk_init_common(wsp, 3, 3));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1844
txg_list_walk_step(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1845
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1846
	txg_list_walk_data_t *lwd = wsp->walk_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1847
	uintptr_t addr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1848
	txg_node_t *node;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1849
	int status;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
	while (wsp->walk_addr == NULL && lwd->lw_txgoff < lwd->lw_maxoff) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1852
		lwd->lw_txgoff++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1853
		wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
	if (wsp->walk_addr == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
		return (WALK_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1859
	addr = wsp->walk_addr - lwd->lw_offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
	if (mdb_vread(lwd->lw_obj,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
	    lwd->lw_offset + sizeof (txg_node_t), addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
		mdb_warn("failed to read list element at %#lx", addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
	status = wsp->walk_callback(addr, lwd->lw_obj, wsp->walk_cbdata);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
	node = (txg_node_t *)((uintptr_t)lwd->lw_obj + lwd->lw_offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
	wsp->walk_addr = (uintptr_t)node->tn_next[lwd->lw_txgoff];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
	return (status);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1874
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1875
 * ::walk spa
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1876
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1877
 * Walk all named spa_t structures in the namespace.  This is nothing more than
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1878
 * a layered avl walk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1879
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1880
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1881
spa_walk_init(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1882
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
	GElf_Sym sym;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1884
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
	if (wsp->walk_addr != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1886
		mdb_warn("spa walk only supports global walks\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1887
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
	if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "spa_namespace_avl", &sym) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1891
		mdb_warn("failed to find symbol 'spa_namespace_avl'");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1895
	wsp->walk_addr = (uintptr_t)sym.st_value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1896
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
	if (mdb_layered_walk("avl", wsp) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1898
		mdb_warn("failed to walk 'avl'\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1899
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1900
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1901
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1902
	return (WALK_NEXT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1903
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1904
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1905
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1906
spa_walk_step(mdb_walk_state_t *wsp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1907
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1908
	spa_t	spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1909
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1910
	if (mdb_vread(&spa, sizeof (spa), wsp->walk_addr) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1911
		mdb_warn("failed to read spa_t at %p", wsp->walk_addr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1912
		return (WALK_ERR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1913
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1914
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1915
	return (wsp->walk_callback(wsp->walk_addr, &spa, wsp->walk_cbdata));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1916
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1917
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1918
/*
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1919
 * [addr]::walk zio
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1920
 *
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1921
 * Walk all active zio_t structures on the system.  This is simply a layered
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1922
 * walk on top of ::walk zio_cache, with the optional ability to limit the
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1923
 * structures to a particular pool.
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1924
 */
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1925
static int
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1926
zio_walk_init(mdb_walk_state_t *wsp)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1927
{
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1928
	wsp->walk_data = (void *)wsp->walk_addr;
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1929
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1930
	if (mdb_layered_walk("zio_cache", wsp) == -1) {
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1931
		mdb_warn("failed to walk 'zio_cache'\n");
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1932
		return (WALK_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1933
	}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1934
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1935
	return (WALK_NEXT);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1936
}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1937
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1938
static int
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1939
zio_walk_step(mdb_walk_state_t *wsp)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1940
{
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1941
	zio_t zio;
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1942
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1943
	if (mdb_vread(&zio, sizeof (zio), wsp->walk_addr) == -1) {
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1944
		mdb_warn("failed to read zio_t at %p", wsp->walk_addr);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1945
		return (WALK_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1946
	}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1947
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1948
	if (wsp->walk_data != NULL && wsp->walk_data != zio.io_spa)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1949
		return (WALK_NEXT);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1950
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1951
	return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1952
}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1953
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1954
/*
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1955
 * [addr]::walk zio_root
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1956
 *
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1957
 * Walk only root zio_t structures, optionally for a particular spa_t.
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1958
 */
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1959
static int
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1960
zio_walk_root_step(mdb_walk_state_t *wsp)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1961
{
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1962
	zio_t zio;
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1963
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1964
	if (mdb_vread(&zio, sizeof (zio), wsp->walk_addr) == -1) {
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1965
		mdb_warn("failed to read zio_t at %p", wsp->walk_addr);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1966
		return (WALK_ERR);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1967
	}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1968
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1969
	if (wsp->walk_data != NULL && wsp->walk_data != zio.io_spa)
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1970
		return (WALK_NEXT);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1971
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1972
	/* If the parent list is not empty, ignore */
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1973
	if (zio.io_parent_list.list_head.list_next !=
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  1974
	    &((zio_t *)wsp->walk_addr)->io_parent_list.list_head)
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1975
		return (WALK_NEXT);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1976
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1977
	return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1978
}
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  1979
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1980
#define	NICENUM_BUFLEN 6
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1981
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1982
static int
7846
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  1983
snprintfrac(char *buf, int len,
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  1984
    uint64_t numerator, uint64_t denom, int frac_digits)
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1985
{
7846
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  1986
	int mul = 1;
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1987
	int whole, frac, i;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1988
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1989
	for (i = frac_digits; i; i--)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1990
		mul *= 10;
7846
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  1991
	whole = numerator / denom;
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  1992
	frac = mul * numerator / denom - mul * whole;
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1993
	return (mdb_snprintf(buf, len, "%u.%0*u", whole, frac_digits, frac));
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1994
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1995
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1996
static void
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1997
mdb_nicenum(uint64_t num, char *buf)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1998
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1999
	uint64_t n = num;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2000
	int index = 0;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2001
	char *u;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2002
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2003
	while (n >= 1024) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2004
		n = (n + (1024 / 2)) / 1024; /* Round up or down */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2005
		index++;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2006
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2007
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2008
	u = &" \0K\0M\0G\0T\0P\0E\0"[index*2];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2009
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2010
	if (index == 0) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2011
		(void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2012
		    (u_longlong_t)n);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2013
	} else if (n < 10 && (num & (num - 1)) != 0) {
7846
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2014
		(void) snprintfrac(buf, NICENUM_BUFLEN,
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2015
		    num, 1ULL << 10 * index, 2);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2016
		strcat(buf, u);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2017
	} else if (n < 100 && (num & (num - 1)) != 0) {
7846
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2018
		(void) snprintfrac(buf, NICENUM_BUFLEN,
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2019
		    num, 1ULL << 10 * index, 1);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2020
		strcat(buf, u);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2021
	} else {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2022
		(void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu%s",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2023
		    (u_longlong_t)n, u);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2024
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2025
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2026
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2027
/*
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2028
 * ::zfs_blkstats
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2029
 *
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2030
 * 	-v	print verbose per-level information
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2031
 *
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2032
 */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2033
static int
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2034
zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2035
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2036
	boolean_t verbose = B_FALSE;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2037
	zfs_all_blkstats_t stats;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2038
	dmu_object_type_t t;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2039
	zfs_blkstat_t *tzb;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2040
	uint64_t ditto;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2041
	dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES + 10];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2042
	/* +10 in case it grew */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2043
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2044
	if (mdb_readvar(&dmu_ot, "dmu_ot") == -1) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2045
		mdb_warn("failed to read 'dmu_ot'");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2046
		return (DCMD_ERR);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2047
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2048
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2049
	if (mdb_getopts(argc, argv,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2050
	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2051
	    NULL) != argc)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2052
		return (DCMD_USAGE);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2053
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2054
	if (!(flags & DCMD_ADDRSPEC))
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2055
		return (DCMD_USAGE);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2056
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2057
	if (GETMEMB(addr, struct spa, spa_dsl_pool, addr) ||
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2058
	    GETMEMB(addr, struct dsl_pool, dp_blkstats, addr) ||
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2059
	    mdb_vread(&stats, sizeof (zfs_all_blkstats_t), addr) == -1) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2060
		mdb_warn("failed to read data at %p;", addr);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2061
		mdb_printf("maybe no stats? run \"zpool scrub\" first.");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2062
		return (DCMD_ERR);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2063
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2064
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2065
	tzb = &stats.zab_type[DN_MAX_LEVELS][DMU_OT_NUMTYPES];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2066
	if (tzb->zb_gangs != 0) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2067
		mdb_printf("Ganged blocks: %llu\n",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2068
		    (longlong_t)tzb->zb_gangs);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2069
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2070
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2071
	ditto = tzb->zb_ditto_2_of_2_samevdev + tzb->zb_ditto_2_of_3_samevdev +
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2072
	    tzb->zb_ditto_3_of_3_samevdev;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2073
	if (ditto != 0) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2074
		mdb_printf("Dittoed blocks on same vdev: %llu\n",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2075
		    (longlong_t)ditto);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2076
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2077
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2078
	mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2079
	    "\t  avg\t comp\t%%Total\tType\n");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2080
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2081
	for (t = 0; t <= DMU_OT_NUMTYPES; t++) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2082
		char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2083
		char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2084
		char avg[NICENUM_BUFLEN];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2085
		char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2086
		char typename[64];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2087
		int l;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2088
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2089
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2090
		if (t == DMU_OT_DEFERRED)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2091
			strcpy(typename, "deferred free");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2092
		else if (t == DMU_OT_TOTAL)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2093
			strcpy(typename, "Total");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2094
		else if (mdb_readstr(typename, sizeof (typename),
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2095
		    (uintptr_t)dmu_ot[t].ot_name) == -1) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2096
			mdb_warn("failed to read type name");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2097
			return (DCMD_ERR);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2098
		}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2099
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2100
		if (stats.zab_type[DN_MAX_LEVELS][t].zb_asize == 0)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2101
			continue;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2102
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2103
		for (l = -1; l < DN_MAX_LEVELS; l++) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2104
			int level = (l == -1 ? DN_MAX_LEVELS : l);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2105
			zfs_blkstat_t *zb = &stats.zab_type[level][t];
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2106
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2107
			if (zb->zb_asize == 0)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2108
				continue;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2109
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2110
			/*
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2111
			 * Don't print each level unless requested.
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2112
			 */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2113
			if (!verbose && level != DN_MAX_LEVELS)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2114
				continue;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2115
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2116
			/*
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2117
			 * If all the space is level 0, don't print the
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2118
			 * level 0 separately.
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2119
			 */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2120
			if (level == 0 && zb->zb_asize ==
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2121
			    stats.zab_type[DN_MAX_LEVELS][t].zb_asize)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2122
				continue;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2123
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2124
			mdb_nicenum(zb->zb_count, csize);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2125
			mdb_nicenum(zb->zb_lsize, lsize);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2126
			mdb_nicenum(zb->zb_psize, psize);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2127
			mdb_nicenum(zb->zb_asize, asize);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2128
			mdb_nicenum(zb->zb_asize / zb->zb_count, avg);
7846
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2129
			(void) snprintfrac(comp, NICENUM_BUFLEN,
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2130
			    zb->zb_lsize, zb->zb_psize, 2);
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2131
			(void) snprintfrac(pct, NICENUM_BUFLEN,
a07ebe2d4dfa 6725668 want ::zfs_blkstats to show block type stats after scrub (fix kmdb)
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7837
diff changeset
  2132
			    100 * zb->zb_asize, tzb->zb_asize, 2);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2133
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2134
			mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2135
			    "\t%5s\t%6s\t",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2136
			    csize, lsize, psize, asize, avg, comp, pct);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2137
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2138
			if (level == DN_MAX_LEVELS)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2139
				mdb_printf("%s\n", typename);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2140
			else
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2141
				mdb_printf("  L%d %s\n",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2142
				    level, typename);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2143
		}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2144
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2145
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2146
	return (DCMD_OK);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2147
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2148
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2149
/* ARGSUSED */
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2150
static int
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2151
reference_cb(uintptr_t addr, const void *ignored, void *arg)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2152
{
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2153
	static int gotid;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2154
	static mdb_ctf_id_t ref_id;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2155
	uintptr_t ref_holder;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2156
	uintptr_t ref_removed;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2157
	uint64_t ref_number;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2158
	boolean_t holder_is_str;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2159
	char holder_str[128];
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2160
	boolean_t removed = (boolean_t)arg;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2161
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2162
	if (!gotid) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2163
		if (mdb_ctf_lookup_by_name("struct reference", &ref_id) == -1) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2164
			mdb_warn("couldn't find struct reference");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2165
			return (WALK_ERR);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2166
		}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2167
		gotid = TRUE;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2168
	}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2169
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2170
	if (GETMEMBID(addr, &ref_id, ref_holder, ref_holder) ||
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2171
	    GETMEMBID(addr, &ref_id, ref_removed, ref_removed) ||
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2172
	    GETMEMBID(addr, &ref_id, ref_number, ref_number))
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2173
		return (WALK_ERR);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2174
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2175
	if (mdb_readstr(holder_str, sizeof (holder_str), ref_holder) != -1) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2176
		char *cp;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2177
		holder_is_str = B_TRUE;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2178
		for (cp = holder_str; *cp; cp++) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2179
			if (!isprint(*cp)) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2180
				holder_is_str = B_FALSE;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2181
				break;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2182
			}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2183
		}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2184
	} else {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2185
		holder_is_str = B_FALSE;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2186
	}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2187
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2188
	if (removed)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2189
		mdb_printf("removed ");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2190
	mdb_printf("reference ");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2191
	if (ref_number != 1)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2192
		mdb_printf("with count=%llu ", ref_number);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2193
	mdb_printf("with tag %p", (void*)ref_holder);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2194
	if (holder_is_str)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2195
		mdb_printf(" \"%s\"", holder_str);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2196
	mdb_printf(", held at:\n");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2197
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2198
	(void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2199
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2200
	if (removed) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2201
		mdb_printf("removed at:\n");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2202
		(void) mdb_call_dcmd("whatis", ref_removed,
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2203
		    DCMD_ADDRSPEC, 0, NULL);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2204
	}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2205
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2206
	mdb_printf("\n");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2207
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2208
	return (WALK_NEXT);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2209
}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2210
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2211
/* ARGSUSED */
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2212
static int
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2213
refcount(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2214
{
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2215
	uint64_t rc_count, rc_removed_count;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2216
	uintptr_t rc_list, rc_removed;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2217
	static int gotid;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2218
	static mdb_ctf_id_t rc_id;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2219
	ulong_t off;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2220
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2221
	if (!(flags & DCMD_ADDRSPEC))
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2222
		return (DCMD_USAGE);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2223
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2224
	if (!gotid) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2225
		if (mdb_ctf_lookup_by_name("struct refcount", &rc_id) == -1) {
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2226
			mdb_warn("couldn't find struct refcount");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2227
			return (DCMD_ERR);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2228
		}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2229
		gotid = TRUE;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2230
	}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2231
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2232
	if (GETMEMBID(addr, &rc_id, rc_count, rc_count) ||
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2233
	    GETMEMBID(addr, &rc_id, rc_removed_count, rc_removed_count))
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2234
		return (DCMD_ERR);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2235
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2236
	mdb_printf("refcount_t at %p has %llu current holds, "
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2237
	    "%llu recently released holds\n",
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2238
	    addr, (longlong_t)rc_count, (longlong_t)rc_removed_count);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2239
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2240
	if (rc_count > 0)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2241
		mdb_printf("current holds:\n");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2242
	if (mdb_ctf_offsetof(rc_id, "rc_list", &off) == -1)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2243
		return (DCMD_ERR);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2244
	rc_list = addr + off/NBBY;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2245
	mdb_pwalk("list", reference_cb, (void*)B_FALSE, rc_list);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2246
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2247
	if (rc_removed_count > 0)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2248
		mdb_printf("released holds:\n");
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2249
	if (mdb_ctf_offsetof(rc_id, "rc_removed", &off) == -1)
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2250
		return (DCMD_ERR);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2251
	rc_removed = addr + off/NBBY;
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2252
	mdb_pwalk("list", reference_cb, (void*)B_TRUE, rc_removed);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2253
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2254
	return (DCMD_OK);
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2255
}
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2256
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2257
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
 * MDB module linkage information:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
 * We declare a list of structures describing our dcmds, and a function
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2261
 * named _mdb_init to return a pointer to our module information.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2263
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
static const mdb_dcmd_t dcmds[] = {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
  2265
	{ "arc", "[-bkmg]", "print ARC variables", arc_print },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2266
	{ "blkptr", ":", "print blkptr_t", blkptr },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
	{ "dbuf", ":", "print dmu_buf_impl_t", dbuf },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
	{ "dbuf_stats", ":", "dbuf stats", dbuf_stats },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
	{ "dbufs",
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9480
diff changeset
  2270
	    "\t[-O objset_t*] [-n objset_name | \"mos\"] "
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2271
	    "[-o object | \"mdn\"] \n"
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2272
	    "\t[-l level] [-b blkid | \"bonus\"]",
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2273
	    "find dmu_buf_impl_t's that match specified criteria", dbufs },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2274
	{ "abuf_find", "dva_word[0] dva_word[1]",
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2275
	    "find arc_buf_hdr_t of a specified DVA",
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2276
	    abuf_find },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2277
	{ "spa", "?[-cv]", "spa_t summary", spa_print },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2278
	{ "spa_config", ":", "print spa_t configuration", spa_print_config },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
	{ "spa_verify", ":", "verify spa_t consistency", spa_verify },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2280
	{ "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2281
	{ "spa_vdevs", ":", "given a spa_t, print vdev summary", spa_vdevs },
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4451
diff changeset
  2282
	{ "vdev", ":[-re]\n"
8632
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2283
	    "\t-r display recursively\n"
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2284
	    "\t-e print statistics",
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2285
	    "vdev_t summary", vdev_print },
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2286
	{ "zio", ":[cpr]\n"
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2287
	    "\t-c display children\n"
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2288
	    "\t-p display parents\n"
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2289
	    "\t-r display recursively",
36ef517870a3 6798384 It can take a village to raise a zio
Bill Moore <Bill.Moore@Sun.COM>
parents: 8341
diff changeset
  2290
	    "zio_t summary", zio_print },
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2291
	{ "zio_state", "?", "print out all zio_t structures on system or "
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2292
	    "for a particular pool", zio_state },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2293
	{ "zio_pipeline", ":", "decode a zio pipeline", zio_pipeline },
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2294
	{ "zfs_blkstats", ":[-v]",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2295
	    "given a spa_t, print block type stats from last scrub",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2296
	    zfs_blkstats },
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 2885
diff changeset
  2297
	{ "zfs_params", "", "print zfs tunable parameters", zfs_params },
10407
34e10c4af053 6875779 zfs user accounting callbacks can be simplified
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10298
diff changeset
  2298
	{ "refcount", "", "print refcount_t holders", refcount },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2299
	{ NULL }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2300
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2301
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2302
static const mdb_walker_t walkers[] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2303
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2304
	 * In userland, there is no generic provider of list_t walkers, so we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2305
	 * need to add it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2306
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2307
#ifndef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2308
	{ LIST_WALK_NAME, LIST_WALK_DESC,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
		list_walk_init, list_walk_step, list_walk_fini },
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2311
	{ "zms_freelist", "walk ZFS metaslab freelist",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2312
		freelist_walk_init, freelist_walk_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2313
	{ "txg_list", "given any txg_list_t *, walk all entries in all txgs",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2314
		txg_list_walk_init, txg_list_walk_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2315
	{ "txg_list0", "given any txg_list_t *, walk all entries in txg 0",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2316
		txg_list0_walk_init, txg_list_walk_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2317
	{ "txg_list1", "given any txg_list_t *, walk all entries in txg 1",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2318
		txg_list1_walk_init, txg_list_walk_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
	{ "txg_list2", "given any txg_list_t *, walk all entries in txg 2",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2320
		txg_list2_walk_init, txg_list_walk_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2321
	{ "txg_list3", "given any txg_list_t *, walk all entries in txg 3",
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2322
		txg_list3_walk_init, txg_list_walk_step, NULL },
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2323
	{ "zio", "walk all zio structures, optionally for a particular spa_t",
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2324
		zio_walk_init, zio_walk_step, NULL },
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2325
	{ "zio_root", "walk all root zio_t structures, optionally for a "
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2326
	    "particular spa_t",
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3403
diff changeset
  2327
		zio_walk_init, zio_walk_root_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
	{ "spa", "walk all spa_t entries in the namespace",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
		spa_walk_init, spa_walk_step, NULL },
2459
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2330
	{ "metaslab", "given a spa_t *, walk all metaslab_t structures",
7511d9859fcd 6452923 really out of space panic even though ms_map.sm_space > 0
ahrens
parents: 2082
diff changeset
  2331
		metaslab_walk_init, metaslab_walk_step, NULL },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2332
	{ NULL }
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2333
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2334
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2335
static const mdb_modinfo_t modinfo = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2336
	MDB_API_VERSION, dcmds, walkers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2337
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2338
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2339
const mdb_modinfo_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2340
_mdb_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2341
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
	return (&modinfo);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2343
}