usr/src/cmd/zdb/zdb.c
author Victor Latushkin <Victor.Latushkin@Sun.COM>
Fri, 14 Nov 2008 15:07:41 -0800
changeset 8121 7fd09d4ebd9c
parent 7837 001de5627df3
child 8188 fd00c0a81e80
permissions -rw-r--r--
6757430 want an option for zdb to disable space map loading and leak tracking
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: 1170
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
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
/*
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
    22
 * Copyright 2008 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 <stdio.h>
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
    27
#include <stdio_ext.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <stdlib.h>
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
    29
#include <ctype.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/zfs_znode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/vdev.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/metaslab_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/dsl_pool.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/zil_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/dmu_traverse.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/zio_compress.h>
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
    52
#include <sys/zfs_fuid.h>
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
    53
#include <sys/arc.h>
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    54
#undef ZFS_MAXNAMELEN
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    55
#undef verify
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    56
#include <libzfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
const char cmdname[] = "zdb";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
uint8_t dump_opt[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
extern void dump_intent_log(zilog_t *);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
uint64_t *zopt_object = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
int zopt_objects = 0;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    66
libzfs_handle_t *g_zfs;
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
    67
boolean_t zdb_sig_user_data = B_TRUE;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
    68
int zdb_sig_cksumalg = ZIO_CHECKSUM_SHA256;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
 * These libumem hooks provide a reasonable set of defaults for the allocator's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
 * debugging facilities.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
_umem_debug_init()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	return ("default,verbose"); /* $UMEM_DEBUG setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
_umem_logging_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	return ("fail,contents"); /* $UMEM_LOGGING setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
usage(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	(void) fprintf(stderr,
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
    90
	    "Usage: %s [-udibcsvL] [-U cachefile_path] "
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
    91
	    "[-S user:cksumalg] "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	    "dataset [object...]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
	    "       %s -C [pool]\n"
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
    94
	    "       %s -l dev\n"
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6217
diff changeset
    95
	    "       %s -R pool:vdev:offset:size:flags\n"
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
    96
	    "       %s [-p path_to_vdev_dir]\n"
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
    97
	    "       %s -e pool | GUID | devid ...\n",
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
    98
	    cmdname, cmdname, cmdname, cmdname, cmdname, cmdname);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	(void) fprintf(stderr, "	-u uberblock\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	(void) fprintf(stderr, "	-d datasets\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	(void) fprintf(stderr, "        -C cached pool configuration\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	(void) fprintf(stderr, "	-i intent logs\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	(void) fprintf(stderr, "	-b block statistics\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	(void) fprintf(stderr, "	-c checksum all data blocks\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	(void) fprintf(stderr, "	-s report stats on zdb's I/O\n");
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
   107
	(void) fprintf(stderr, "	-S <user|all>:<cksum_alg|all> -- "
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
   108
	    "dump blkptr signatures\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	(void) fprintf(stderr, "	-v verbose (applies to all others)\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	(void) fprintf(stderr, "        -l dump label contents\n");
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
   111
	(void) fprintf(stderr, "        -L disable leak tracking (do not "
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
   112
	    "load spacemaps)\n");
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
   113
	(void) fprintf(stderr, "	-U cachefile_path -- use alternate "
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
   114
	    "cachefile\n");
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
   115
	(void) fprintf(stderr, "        -R read and display block from a "
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   116
	    "device\n");
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
   117
	(void) fprintf(stderr, "        -e Pool is exported/destroyed/"
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
   118
	    "has altroot\n");
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
   119
	(void) fprintf(stderr, "	-p <Path to vdev dir> (use with -e)\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	    "to make only that option verbose\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	exit(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
fatal(const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	va_list ap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	va_start(ap, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	(void) fprintf(stderr, "%s: ", cmdname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	(void) vfprintf(stderr, fmt, ap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
	va_end(ap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
	(void) fprintf(stderr, "\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   137
	abort();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
dump_nvlist(nvlist_t *list, int indent)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	nvpair_t *elem = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	while ((elem = nvlist_next_nvpair(list, elem)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
		switch (nvpair_type(elem)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
		case DATA_TYPE_STRING:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
				char *value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
				VERIFY(nvpair_value_string(elem, &value) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
				(void) printf("%*s%s='%s'\n", indent, "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
				    nvpair_name(elem), value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
		case DATA_TYPE_UINT64:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
				uint64_t value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
				VERIFY(nvpair_value_uint64(elem, &value) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
				(void) printf("%*s%s=%llu\n", indent, "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
				    nvpair_name(elem), (u_longlong_t)value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
		case DATA_TYPE_NVLIST:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
				nvlist_t *value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
				VERIFY(nvpair_value_nvlist(elem, &value) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
				(void) printf("%*s%s\n", indent, "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
				    nvpair_name(elem));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
				dump_nvlist(value, indent + 4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
		case DATA_TYPE_NVLIST_ARRAY:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
				nvlist_t **value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
				uint_t c, count;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
				VERIFY(nvpair_value_nvlist_array(elem, &value,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
				    &count) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
				for (c = 0; c < count; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
					(void) printf("%*s%s[%u]\n", indent, "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
					    nvpair_name(elem), c);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
					dump_nvlist(value[c], indent + 8);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
			(void) printf("bad config type %d for %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
			    nvpair_type(elem), nvpair_name(elem));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
	nvlist_t *nv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
	size_t nvsize = *(uint64_t *)data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
   210
	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
	umem_free(packed, nvsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	dump_nvlist(nv, 8);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
	nvlist_free(nv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
const char dump_zap_stars[] = "****************************************";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
const int dump_zap_width = sizeof (dump_zap_stars) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	int minidx = ZAP_HISTOGRAM_SIZE - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	int maxidx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	uint64_t max = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
		if (histo[i] > max)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
			max = histo[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
		if (histo[i] > 0 && i > maxidx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
			maxidx = i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
		if (histo[i] > 0 && i < minidx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
			minidx = i;
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
	if (max < dump_zap_width)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
		max = dump_zap_width;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	for (i = minidx; i <= maxidx; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
dump_zap_stats(objset_t *os, uint64_t object)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	zap_stats_t zs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	error = zap_get_stats(os, object, &zs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
	if (zs.zs_ptrtbl_len == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
		ASSERT(zs.zs_num_blocks == 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
		    (u_longlong_t)zs.zs_blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
		    (u_longlong_t)zs.zs_num_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
	(void) printf("\tFat ZAP stats:\n");
1632
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   268
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   269
	(void) printf("\t\tPointer table:\n");
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   270
	(void) printf("\t\t\t%llu elements\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
	    (u_longlong_t)zs.zs_ptrtbl_len);
1632
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   272
	(void) printf("\t\t\tzt_blk: %llu\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   273
	    (u_longlong_t)zs.zs_ptrtbl_zt_blk);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   274
	(void) printf("\t\t\tzt_numblks: %llu\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   275
	    (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   276
	(void) printf("\t\t\tzt_shift: %llu\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   277
	    (u_longlong_t)zs.zs_ptrtbl_zt_shift);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   278
	(void) printf("\t\t\tzt_blks_copied: %llu\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   279
	    (u_longlong_t)zs.zs_ptrtbl_blks_copied);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   280
	(void) printf("\t\t\tzt_nextblk: %llu\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   281
	    (u_longlong_t)zs.zs_ptrtbl_nextblk);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   282
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	(void) printf("\t\tZAP entries: %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	    (u_longlong_t)zs.zs_num_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	(void) printf("\t\tLeaf blocks: %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	    (u_longlong_t)zs.zs_num_leafs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	(void) printf("\t\tTotal blocks: %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	    (u_longlong_t)zs.zs_num_blocks);
1632
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   289
	(void) printf("\t\tzap_block_type: 0x%llx\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   290
	    (u_longlong_t)zs.zs_block_type);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   291
	(void) printf("\t\tzap_magic: 0x%llx\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   292
	    (u_longlong_t)zs.zs_magic);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   293
	(void) printf("\t\tzap_salt: 0x%llx\n",
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   294
	    (u_longlong_t)zs.zs_salt);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
	(void) printf("\t\tLeafs with 2^n pointers:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
	(void) printf("\t\tBlocks with n*5 entries:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
	(void) printf("\t\tBlocks n/10 full:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	(void) printf("\t\tEntries with n chunks:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
	dump_zap_histogram(zs.zs_entries_using_n_chunks);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
	(void) printf("\t\tBuckets with n entries:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
	dump_zap_histogram(zs.zs_buckets_with_n_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
dump_none(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
dump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
dump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
{
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 void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
	zap_cursor_t zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	zap_attribute_t attr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
	void *prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	dump_zap_stats(os, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
	for (zap_cursor_init(&zc, os, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	    zap_cursor_retrieve(&zc, &attr) == 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
	    zap_cursor_advance(&zc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
		(void) printf("\t\t%s = ", attr.za_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
		if (attr.za_num_integers == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
			(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
		prop = umem_zalloc(attr.za_num_integers *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
		    attr.za_integer_length, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
		(void) zap_lookup(os, object, attr.za_name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
		    attr.za_integer_length, attr.za_num_integers, prop);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
		if (attr.za_integer_length == 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
			(void) printf("%s", (char *)prop);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
			for (i = 0; i < attr.za_num_integers; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
				switch (attr.za_integer_length) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
				case 2:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
					(void) printf("%u ",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
					    ((uint16_t *)prop)[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
				case 4:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
					(void) printf("%u ",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
					    ((uint32_t *)prop)[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
				case 8:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
					(void) printf("%lld ",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
					    (u_longlong_t)((int64_t *)prop)[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
	}
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
   377
	zap_cursor_fini(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   380
/*ARGSUSED*/
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   381
static void
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   382
dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   383
{
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   384
	zap_cursor_t zc;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   385
	zap_attribute_t attr;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   386
	const char *typenames[] = {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   387
		/* 0 */ "not specified",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   388
		/* 1 */ "FIFO",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   389
		/* 2 */ "Character Device",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   390
		/* 3 */ "3 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   391
		/* 4 */ "Directory",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   392
		/* 5 */ "5 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   393
		/* 6 */ "Block Device",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   394
		/* 7 */ "7 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   395
		/* 8 */ "Regular File",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   396
		/* 9 */ "9 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   397
		/* 10 */ "Symbolic Link",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   398
		/* 11 */ "11 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   399
		/* 12 */ "Socket",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   400
		/* 13 */ "Door",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   401
		/* 14 */ "Event Port",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   402
		/* 15 */ "15 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   403
	};
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   404
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   405
	dump_zap_stats(os, object);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   406
	(void) printf("\n");
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   407
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   408
	for (zap_cursor_init(&zc, os, object);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   409
	    zap_cursor_retrieve(&zc, &attr) == 0;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   410
	    zap_cursor_advance(&zc)) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   411
		(void) printf("\t\t%s = %lld (type: %s)\n",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   412
		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   413
		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   414
	}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   415
	zap_cursor_fini(&zc);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   416
}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   417
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
dump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	uint64_t alloc, offset, entry;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   422
	uint8_t mapshift = sm->sm_shift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	uint64_t mapstart = sm->sm_start;
3361
a3d194896a76 6480230 ::walk spa|::walk zms_freelist cause mdb to core dump
ck153898
parents: 3060
diff changeset
   424
	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
a3d194896a76 6480230 ::walk spa|::walk zms_freelist cause mdb to core dump
ck153898
parents: 3060
diff changeset
   425
			    "INVALID", "INVALID", "INVALID", "INVALID" };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	if (smo->smo_object == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
	 * Print out the freelist entries in both encoded and decoded form.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
	alloc = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
   435
		VERIFY(0 == dmu_read(os, smo->smo_object, offset,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
   436
		    sizeof (entry), &entry));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
		if (SM_DEBUG_DECODE(entry)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
			(void) printf("\t\t[%4llu] %s: txg %llu, pass %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
			    (u_longlong_t)(offset / sizeof (entry)),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   441
			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   442
			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
			(void) printf("\t\t[%4llu]    %c  range:"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
			    " %08llx-%08llx  size: %06llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
			    (u_longlong_t)(offset / sizeof (entry)),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   448
			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   449
			    mapshift) + mapstart),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   450
			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   451
			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   452
			    mapshift)),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   453
			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
				alloc += SM_RUN_DECODE(entry) << mapshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
				alloc -= SM_RUN_DECODE(entry) << mapshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	if (alloc != smo->smo_alloc) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
		    "with space map summary (%llu)\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
dump_metaslab(metaslab_t *msp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
	char freebuf[5];
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   471
	space_map_obj_t *smo = &msp->ms_smo;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	vdev_t *vd = msp->ms_group->mg_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
	spa_t *spa = vd->vdev_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
	nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
	if (dump_opt['d'] <= 5) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
		(void) printf("\t%10llx   %10llu   %5s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
		    (u_longlong_t)msp->ms_map.sm_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
		    (u_longlong_t)smo->smo_object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
		    freebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
	(void) printf(
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
	    "\tvdev %llu   offset %08llx   spacemap %4llu   free %5s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
	    (u_longlong_t)vd->vdev_id, (u_longlong_t)msp->ms_map.sm_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	    (u_longlong_t)smo->smo_object, freebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
	ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
dump_metaslabs(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
	vdev_t *rvd = spa->spa_root_vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
	vdev_t *vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	int c, m;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	(void) printf("\nMetaslabs:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
	for (c = 0; c < rvd->vdev_children; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
		vd = rvd->vdev_child[c];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
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
   507
		(void) printf("\n    vdev %llu\n\n", (u_longlong_t)vd->vdev_id);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
		if (dump_opt['d'] <= 5) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
			(void) printf("\t%10s   %10s   %5s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
			    "offset", "spacemap", "free");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
			(void) printf("\t%10s   %10s   %5s\n",
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
		for (m = 0; m < vd->vdev_ms_count; m++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
			dump_metaslab(vd->vdev_ms[m]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
dump_dtl(vdev_t *vd, int indent)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
	avl_tree_t *t = &vd->vdev_dtl_map.sm_root;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
	space_seg_t *ss;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	vdev_t *pvd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	if (indent == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
		(void) printf("\nDirty time logs:\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
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
   532
	(void) printf("\t%*s%s\n", indent, "",
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   533
	    vd->vdev_path ? vd->vdev_path :
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   534
	    vd->vdev_parent ? vd->vdev_ops->vdev_op_type :
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   535
	    spa_name(vd->vdev_spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	for (ss = avl_first(t); ss; ss = AVL_NEXT(t, ss)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
		 * Everything in this DTL must appear in all parent DTL unions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
		for (pvd = vd; pvd; pvd = pvd->vdev_parent)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
			ASSERT(vdev_dtl_contains(&pvd->vdev_dtl_map,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
			    ss->ss_start, ss->ss_end - ss->ss_start));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
		(void) printf("\t%*soutage [%llu,%llu] length %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
		    indent, "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
		    (u_longlong_t)ss->ss_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
		    (u_longlong_t)ss->ss_end - 1,
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   548
		    (u_longlong_t)(ss->ss_end - ss->ss_start));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	if (dump_opt['d'] > 5 && vd->vdev_children == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
		dump_spacemap(vd->vdev_spa->spa_meta_objset, &vd->vdev_dtl,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
		    &vd->vdev_dtl_map);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
	for (c = 0; c < vd->vdev_children; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
		dump_dtl(vd->vdev_child[c], indent + 4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
dump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
static uint64_t
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   570
blkid2offset(const dnode_phys_t *dnp, int level, uint64_t blkid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
	if (level < 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
		return (blkid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
	return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   579
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   580
sprintf_blkptr_compact(char *blkbuf, blkptr_t *bp, int alldvas)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   581
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   582
	dva_t *dva = bp->blk_dva;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   583
	int ndvas = alldvas ? BP_GET_NDVAS(bp) : 1;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   584
	int i;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   585
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   586
	blkbuf[0] = '\0';
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   587
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   588
	for (i = 0; i < ndvas; i++)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   589
		(void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   590
		    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   591
		    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   592
		    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   593
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   594
	(void) sprintf(blkbuf + strlen(blkbuf), "%llxL/%llxP F=%llu B=%llu",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   595
	    (u_longlong_t)BP_GET_LSIZE(bp),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   596
	    (u_longlong_t)BP_GET_PSIZE(bp),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   597
	    (u_longlong_t)bp->blk_fill,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   598
	    (u_longlong_t)bp->blk_birth);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   599
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   600
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   601
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
   602
print_indirect(blkptr_t *bp, const zbookmark_t *zb,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   603
    const dnode_phys_t *dnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
{
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   605
	char blkbuf[BP_SPRINTF_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	int l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   608
	ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   609
	ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   611
	(void) printf("%16llx ",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
	    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
	ASSERT(zb->zb_level >= 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
		if (l == zb->zb_level) {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   618
			(void) printf("L%llx", (u_longlong_t)zb->zb_level);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
		} else {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   620
			(void) printf(" ");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   624
	sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   625
	(void) printf("%s\n", blkbuf);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   626
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   627
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   628
#define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   629
{                                                       \
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   630
	(zb)->zb_objset = objset;                       \
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   631
	(zb)->zb_object = object;                       \
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   632
	(zb)->zb_level = level;                         \
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   633
	(zb)->zb_blkid = blkid;                         \
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   634
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   635
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   636
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
   637
visit_indirect(spa_t *spa, const dnode_phys_t *dnp,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   638
    blkptr_t *bp, const zbookmark_t *zb)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   639
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   640
	int err;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   641
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   642
	if (bp->blk_birth == 0)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   643
		return (0);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   644
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   645
	print_indirect(bp, zb, dnp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   646
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   647
	if (BP_GET_LEVEL(bp) > 0) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   648
		uint32_t flags = ARC_WAIT;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   649
		int i;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   650
		blkptr_t *cbp;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   651
		int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   652
		arc_buf_t *buf;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   653
		uint64_t fill = 0;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   654
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   655
		err = arc_read_nolock(NULL, spa, bp, arc_getbuf_func, &buf,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   656
		    ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   657
		if (err)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   658
			return (err);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   659
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   660
		/* recursively visit blocks below this */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   661
		cbp = buf->b_data;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   662
		for (i = 0; i < epb; i++, cbp++) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   663
			zbookmark_t czb;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   664
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   665
			SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   666
			    zb->zb_level - 1,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   667
			    zb->zb_blkid * epb + i);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   668
			err = visit_indirect(spa, dnp, cbp, &czb);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   669
			if (err)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   670
				break;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   671
			fill += cbp->blk_fill;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   672
		}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   673
		ASSERT3U(fill, ==, bp->blk_fill);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   674
		(void) arc_buf_remove_ref(buf, &buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   677
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
static void
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   682
dump_indirect(dnode_t *dn)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
{
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   684
	dnode_phys_t *dnp = dn->dn_phys;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   685
	int j;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   686
	zbookmark_t czb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
	(void) printf("Indirect blocks:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   690
	SET_BOOKMARK(&czb, dmu_objset_id(&dn->dn_objset->os),
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   691
	    dn->dn_object, dnp->dn_nlevels - 1, 0);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   692
	for (j = 0; j < dnp->dn_nblkptr; j++) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   693
		czb.zb_blkid = j;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   694
		(void) visit_indirect(dmu_objset_spa(&dn->dn_objset->os), dnp,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   695
		    &dnp->dn_blkptr[j], &czb);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   696
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
	dsl_dir_phys_t *dd = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
	time_t crtime;
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   707
	char nice[6];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	if (dd == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   712
	ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
	crtime = dd->dd_creation_time;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	(void) printf("\t\thead_dataset_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
	    (u_longlong_t)dd->dd_head_dataset_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
	(void) printf("\t\tparent_dir_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	    (u_longlong_t)dd->dd_parent_obj);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   720
	(void) printf("\t\torigin_obj = %llu\n",
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   721
	    (u_longlong_t)dd->dd_origin_obj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
	(void) printf("\t\tchild_dir_zapobj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
	    (u_longlong_t)dd->dd_child_dir_zapobj);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   724
	nicenum(dd->dd_used_bytes, nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   725
	(void) printf("\t\tused_bytes = %s\n", nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   726
	nicenum(dd->dd_compressed_bytes, nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   727
	(void) printf("\t\tcompressed_bytes = %s\n", nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   728
	nicenum(dd->dd_uncompressed_bytes, nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   729
	(void) printf("\t\tuncompressed_bytes = %s\n", nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   730
	nicenum(dd->dd_quota, nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   731
	(void) printf("\t\tquota = %s\n", nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   732
	nicenum(dd->dd_reserved, nice);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   733
	(void) printf("\t\treserved = %s\n", nice);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
	(void) printf("\t\tprops_zapobj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
	    (u_longlong_t)dd->dd_props_zapobj);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
   736
	(void) printf("\t\tdeleg_zapobj = %llu\n",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
   737
	    (u_longlong_t)dd->dd_deleg_zapobj);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   738
	(void) printf("\t\tflags = %llx\n",
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   739
	    (u_longlong_t)dd->dd_flags);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   740
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   741
#define	DO(which) \
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   742
	nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice); \
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   743
	(void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   744
	DO(HEAD);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   745
	DO(SNAP);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   746
	DO(CHILD);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   747
	DO(CHILD_RSRV);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   748
	DO(REFRSRV);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
   749
#undef DO
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
dump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	dsl_dataset_phys_t *ds = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
	time_t crtime;
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
   758
	char used[6], compressed[6], uncompressed[6], unique[6];
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
   759
	char blkbuf[BP_SPRINTF_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
	if (ds == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	ASSERT(size == sizeof (*ds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
	crtime = ds->ds_creation_time;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
	nicenum(ds->ds_used_bytes, used);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
	nicenum(ds->ds_compressed_bytes, compressed);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
	nicenum(ds->ds_uncompressed_bytes, uncompressed);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
	nicenum(ds->ds_unique_bytes, unique);
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
   770
	sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ds->ds_bp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   772
	(void) printf("\t\tdir_obj = %llu\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	    (u_longlong_t)ds->ds_dir_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
	(void) printf("\t\tprev_snap_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
	    (u_longlong_t)ds->ds_prev_snap_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
	(void) printf("\t\tprev_snap_txg = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	    (u_longlong_t)ds->ds_prev_snap_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	(void) printf("\t\tnext_snap_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
	    (u_longlong_t)ds->ds_next_snap_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	(void) printf("\t\tsnapnames_zapobj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
	    (u_longlong_t)ds->ds_snapnames_zapobj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	(void) printf("\t\tnum_children = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	    (u_longlong_t)ds->ds_num_children);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	(void) printf("\t\tcreation_txg = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	    (u_longlong_t)ds->ds_creation_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	(void) printf("\t\tdeadlist_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
	    (u_longlong_t)ds->ds_deadlist_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	(void) printf("\t\tused_bytes = %s\n", used);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
	(void) printf("\t\tunique = %s\n", unique);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	(void) printf("\t\tfsid_guid = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
	    (u_longlong_t)ds->ds_fsid_guid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
	(void) printf("\t\tguid = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
	    (u_longlong_t)ds->ds_guid);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   797
	(void) printf("\t\tflags = %llx\n",
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   798
	    (u_longlong_t)ds->ds_flags);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   799
	(void) printf("\t\tnext_clones_obj = %llu\n",
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
   800
	    (u_longlong_t)ds->ds_next_clones_obj);
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7046
diff changeset
   801
	(void) printf("\t\tprops_obj = %llu\n",
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7046
diff changeset
   802
	    (u_longlong_t)ds->ds_props_obj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
	(void) printf("\t\tbp = %s\n", blkbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
dump_bplist(objset_t *mos, uint64_t object, char *name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
	bplist_t bpl = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
	blkptr_t blk, *bp = &blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
	uint64_t itor = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   812
	char bytes[6];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   813
	char comp[6];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   814
	char uncomp[6];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
	if (dump_opt['d'] < 3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   819
	mutex_init(&bpl.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
   820
	VERIFY(0 == bplist_open(&bpl, mos, object));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
	if (bplist_empty(&bpl)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
		bplist_close(&bpl);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   823
		mutex_destroy(&bpl.bpl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   827
	nicenum(bpl.bpl_phys->bpl_bytes, bytes);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   828
	if (bpl.bpl_dbuf->db_size == sizeof (bplist_phys_t)) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   829
		nicenum(bpl.bpl_phys->bpl_comp, comp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   830
		nicenum(bpl.bpl_phys->bpl_uncomp, uncomp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   831
		(void) printf("\n    %s: %llu entries, %s (%s/%s comp)\n",
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   832
		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   833
		    bytes, comp, uncomp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   834
	} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   835
		(void) printf("\n    %s: %llu entries, %s\n",
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   836
		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries, bytes);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   837
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
	if (dump_opt['d'] < 5) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
		bplist_close(&bpl);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   841
		mutex_destroy(&bpl.bpl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	while (bplist_iterate(&bpl, &itor, bp) == 0) {
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   848
		char blkbuf[BP_SPRINTF_LEN];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   849
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
		ASSERT(bp->blk_birth != 0);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   851
		sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   852
		(void) printf("\tItem %3llu: %s\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   853
		    (u_longlong_t)itor - 1, blkbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
	bplist_close(&bpl);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4787
diff changeset
   857
	mutex_destroy(&bpl.bpl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   860
static avl_tree_t idx_tree;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   861
static avl_tree_t domain_tree;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   862
static boolean_t fuid_table_loaded;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   863
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   864
static void
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   865
fuid_table_destroy()
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   866
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   867
	if (fuid_table_loaded) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   868
		zfs_fuid_table_destroy(&idx_tree, &domain_tree);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   869
		fuid_table_loaded = B_FALSE;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   870
	}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   871
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   872
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   873
/*
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   874
 * print uid or gid information.
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   875
 * For normal POSIX id just the id is printed in decimal format.
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   876
 * For CIFS files with FUID the fuid is printed in hex followed by
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   877
 * the doman-rid string.
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   878
 */
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   879
static void
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   880
print_idstr(uint64_t id, const char *id_type)
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   881
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   882
	if (FUID_INDEX(id)) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   883
		char *domain;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   884
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   885
		domain = zfs_fuid_idx_domain(&idx_tree, FUID_INDEX(id));
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   886
		(void) printf("\t%s     %llx [%s-%d]\n", id_type,
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   887
		    (u_longlong_t)id, domain, (int)FUID_RID(id));
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   888
	} else {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   889
		(void) printf("\t%s     %llu\n", id_type, (u_longlong_t)id);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   890
	}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   891
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   892
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   893
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   894
static void
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   895
dump_uidgid(objset_t *os, znode_phys_t *zp)
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   896
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   897
	uint32_t uid_idx, gid_idx;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   898
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   899
	uid_idx = FUID_INDEX(zp->zp_uid);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   900
	gid_idx = FUID_INDEX(zp->zp_gid);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   901
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   902
	/* Load domain table, if not already loaded */
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   903
	if (!fuid_table_loaded && (uid_idx || gid_idx)) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   904
		uint64_t fuid_obj;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   905
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   906
		/* first find the fuid object.  It lives in the master node */
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   907
		VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES,
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   908
		    8, 1, &fuid_obj) == 0);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   909
		(void) zfs_fuid_table_load(os, fuid_obj,
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   910
		    &idx_tree, &domain_tree);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   911
		fuid_table_loaded = B_TRUE;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   912
	}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   913
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   914
	print_idstr(zp->zp_uid, "uid");
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   915
	print_idstr(zp->zp_gid, "gid");
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   916
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   917
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
dump_znode(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
	znode_phys_t *zp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
	time_t z_crtime, z_atime, z_mtime, z_ctime;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
	char path[MAXPATHLEN * 2];	/* allow for xattr and failure prefix */
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   925
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	ASSERT(size >= sizeof (znode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   929
	error = zfs_obj_to_path(os, object, path, sizeof (path));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   930
	if (error != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   931
		(void) snprintf(path, sizeof (path), "\?\?\?<object#%llu>",
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   932
		    (u_longlong_t)object);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   933
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   934
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	if (dump_opt['d'] < 3) {
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   936
		(void) printf("\t%s\n", path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	z_crtime = (time_t)zp->zp_crtime[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
	z_atime = (time_t)zp->zp_atime[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
	z_mtime = (time_t)zp->zp_mtime[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
	z_ctime = (time_t)zp->zp_ctime[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
   945
	(void) printf("\tpath	%s\n", path);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
   946
	dump_uidgid(os, zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
	(void) printf("\tatime	%s", ctime(&z_atime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
	(void) printf("\tmtime	%s", ctime(&z_mtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
	(void) printf("\tctime	%s", ctime(&z_ctime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
	(void) printf("\tcrtime	%s", ctime(&z_crtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
	(void) printf("\tgen	%llu\n", (u_longlong_t)zp->zp_gen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
	(void) printf("\tmode	%llo\n", (u_longlong_t)zp->zp_mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
	(void) printf("\tsize	%llu\n", (u_longlong_t)zp->zp_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
	(void) printf("\tparent	%llu\n", (u_longlong_t)zp->zp_parent);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
	(void) printf("\tlinks	%llu\n", (u_longlong_t)zp->zp_links);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
	(void) printf("\txattr	%llu\n", (u_longlong_t)zp->zp_xattr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
	(void) printf("\trdev	0x%016llx\n", (u_longlong_t)zp->zp_rdev);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
dump_acl(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
{
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
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
dump_dmu_objset(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
static object_viewer_t *object_viewer[DMU_OT_NUMTYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
	dump_none,		/* unallocated			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
	dump_zap,		/* object directory		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
	dump_uint64,		/* object array			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
	dump_none,		/* packed nvlist		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
	dump_packed_nvlist,	/* packed nvlist size		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
	dump_none,		/* bplist			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
	dump_none,		/* bplist header		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	dump_none,		/* SPA space map header		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	dump_none,		/* SPA space map		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
	dump_none,		/* ZIL intent log		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
	dump_dnode,		/* DMU dnode			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	dump_dmu_objset,	/* DMU objset			*/
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
   985
	dump_dsl_dir,		/* DSL directory		*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	dump_zap,		/* DSL directory child map	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
	dump_zap,		/* DSL dataset snap map		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
	dump_zap,		/* DSL props			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
	dump_dsl_dataset,	/* DSL dataset			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
	dump_znode,		/* ZFS znode			*/
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   991
	dump_acl,		/* ZFS V0 ACL			*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
	dump_uint8,		/* ZFS plain file		*/
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   993
	dump_zpldir,		/* ZFS directory		*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
	dump_zap,		/* ZFS master node		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
	dump_zap,		/* ZFS delete queue		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	dump_uint8,		/* zvol object			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
	dump_zap,		/* zvol prop			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
	dump_uint8,		/* other uint8[]		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
	dump_uint64,		/* other uint64[]		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
	dump_zap,		/* other ZAP			*/
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1001
	dump_zap,		/* persistent error log		*/
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1002
	dump_uint8,		/* SPA history			*/
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1003
	dump_uint64,		/* SPA history offsets		*/
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3547
diff changeset
  1004
	dump_zap,		/* Pool properties		*/
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1005
	dump_zap,		/* DSL permissions		*/
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1006
	dump_acl,		/* ZFS ACL			*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1007
	dump_uint8,		/* ZFS SYSACL			*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1008
	dump_none,		/* FUID nvlist			*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1009
	dump_packed_nvlist,	/* FUID nvlist size		*/
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1010
	dump_zap,		/* DSL dataset next clones	*/
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1011
	dump_zap,		/* DSL scrub queue		*/
789
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
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
	dmu_buf_t *db = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
	dmu_object_info_t doi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
	dnode_t *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
	void *bonus = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
	size_t bsize = 0;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1022
	char iblk[6], dblk[6], lsize[6], asize[6], bonus_size[6], segsize[6];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
	char aux[50];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
	if (*print_header) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
		(void) printf("\n    Object  lvl   iblk   dblk  lsize"
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1028
		    "  asize  type\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
		*print_header = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
	if (object == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
		dn = os->os->os_meta_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1035
		error = dmu_bonus_hold(os, object, FTAG, &db);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1036
		if (error)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1037
			fatal("dmu_bonus_hold(%llu) failed, errno %u",
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1038
			    object, error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
		bonus = db->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
		bsize = db->db_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
		dn = ((dmu_buf_impl_t *)db)->db_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
	dmu_object_info_from_dnode(dn, &doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
	nicenum(doi.doi_metadata_block_size, iblk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
	nicenum(doi.doi_data_block_size, dblk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
	nicenum(doi.doi_data_block_size * (doi.doi_max_block_offset + 1),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	    lsize);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1049
	nicenum(doi.doi_physical_blks << 9, asize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
	nicenum(doi.doi_bonus_size, bonus_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
	aux[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1054
	if (doi.doi_checksum != ZIO_CHECKSUM_INHERIT || verbosity >= 6) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
		(void) snprintf(aux + strlen(aux), sizeof (aux), " (K=%s)",
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1056
		    zio_checksum_table[doi.doi_checksum].ci_name);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1057
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1059
	if (doi.doi_compress != ZIO_COMPRESS_INHERIT || verbosity >= 6) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
		(void) snprintf(aux + strlen(aux), sizeof (aux), " (Z=%s)",
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1061
		    zio_compress_table[doi.doi_compress].ci_name);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1062
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
	(void) printf("%10lld  %3u  %5s  %5s  %5s  %5s  %s%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
	    (u_longlong_t)object, doi.doi_indirection, iblk, dblk, lsize,
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1066
	    asize, dmu_ot[doi.doi_type].ot_name, aux);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
	if (doi.doi_bonus_type != DMU_OT_NONE && verbosity > 3) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
		(void) printf("%10s  %3s  %5s  %5s  %5s  %5s  %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
		    "", "", "", "", bonus_size, "bonus",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
		    dmu_ot[doi.doi_bonus_type].ot_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
	if (verbosity >= 4) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
		object_viewer[doi.doi_bonus_type](os, object, bonus, bsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
		object_viewer[doi.doi_type](os, object, NULL, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
		*print_header = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	if (verbosity >= 5)
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1081
		dump_indirect(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
	if (verbosity >= 5) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
		 * Report the list of segments that comprise the object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
		uint64_t start = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
		uint64_t end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
		uint64_t blkfill = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
		int minlvl = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
		if (dn->dn_type == DMU_OT_DNODE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
			minlvl = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
			blkfill = DNODES_PER_BLOCK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
		for (;;) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1098
			error = dnode_next_offset(dn,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1099
			    0, &start, minlvl, blkfill, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
			if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
			end = start;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1103
			error = dnode_next_offset(dn,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1104
			    DNODE_FIND_HOLE, &end, minlvl, blkfill, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
			nicenum(end - start, segsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
			(void) printf("\t\tsegment [%016llx, %016llx)"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
			    " size %5s\n", (u_longlong_t)start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
			    (u_longlong_t)end, segsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
			if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
			start = end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
	if (db != NULL)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1116
		dmu_buf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
static char *objset_types[DMU_OST_NUMTYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
	"NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
dump_dir(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
	dmu_objset_stats_t dds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1126
	uint64_t object, object_count;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1127
	uint64_t refdbytes, usedobjs, scratch;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1128
	char numbuf[8];
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1129
	char blkbuf[BP_SPRINTF_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1131
	char *type = "UNKNOWN";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	int verbosity = dump_opt['d'];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	int print_header = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
	int i, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1136
	dmu_objset_fast_stat(os, &dds);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
	if (dds.dds_type < DMU_OST_NUMTYPES)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
		type = objset_types[dds.dds_type];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
	if (dds.dds_type == DMU_OST_META) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
		dds.dds_creation_txg = TXG_INITIAL;
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3444
diff changeset
  1143
		usedobjs = os->os->os_rootbp->blk_fill;
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1144
		refdbytes = os->os->os_spa->spa_dsl_pool->
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1145
		    dp_mos_dir->dd_phys->dd_used_bytes;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1146
	} else {
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1147
		dmu_objset_space(os, &refdbytes, &scratch, &usedobjs, &scratch);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3444
diff changeset
  1150
	ASSERT3U(usedobjs, ==, os->os->os_rootbp->blk_fill);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1152
	nicenum(refdbytes, numbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
	if (verbosity >= 4) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
		(void) strcpy(blkbuf, ", rootbp ");
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1156
		sprintf_blkptr(blkbuf + strlen(blkbuf),
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3444
diff changeset
  1157
		    BP_SPRINTF_LEN - strlen(blkbuf), os->os->os_rootbp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
		blkbuf[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1164
	(void) printf("Dataset %s [%s], ID %llu, cr_txg %llu, "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
	    "%s, %llu objects%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
	    osname, type, (u_longlong_t)dmu_objset_id(os),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
	    (u_longlong_t)dds.dds_creation_txg,
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1168
	    numbuf, (u_longlong_t)usedobjs, blkbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
	dump_intent_log(dmu_objset_zil(os));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
	if (dmu_objset_ds(os) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
		dump_bplist(dmu_objset_pool(os)->dp_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
		    dmu_objset_ds(os)->ds_phys->ds_deadlist_obj, "Deadlist");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
	if (verbosity < 2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1179
	if (os->os->os_rootbp->blk_birth == 0)
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1180
		return;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1181
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	if (zopt_objects != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
		for (i = 0; i < zopt_objects; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
			dump_object(os, zopt_object[i], verbosity,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
			    &print_header);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
	dump_object(os, 0, verbosity, &print_header);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
	object_count = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
	object = 0;
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2926
diff changeset
  1194
	while ((error = dmu_object_next(os, &object, B_FALSE, 0)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
		dump_object(os, object, verbosity, &print_header);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
		object_count++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1199
	ASSERT3U(object_count, ==, usedobjs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
	if (error != ESRCH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
		fatal("dmu_object_next() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
dump_uberblock(uberblock_t *ub)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
	time_t timestamp = ub->ub_timestamp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
	(void) printf("Uberblock\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	(void) printf("\tmagic = %016llx\n", (u_longlong_t)ub->ub_magic);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	(void) printf("\tversion = %llu\n", (u_longlong_t)ub->ub_version);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
	(void) printf("\ttxg = %llu\n", (u_longlong_t)ub->ub_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
	(void) printf("\tguid_sum = %llu\n", (u_longlong_t)ub->ub_guid_sum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
	(void) printf("\ttimestamp = %llu UTC = %s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
	    (u_longlong_t)ub->ub_timestamp, asctime(localtime(&timestamp)));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
	if (dump_opt['u'] >= 3) {
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1220
		char blkbuf[BP_SPRINTF_LEN];
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1221
		sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ub->ub_rootbp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
		(void) printf("\trootbp = %s\n", blkbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
dump_config(const char *pool)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	spa_t *spa = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	mutex_enter(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
	while ((spa = spa_next(spa)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
		if (pool == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
			(void) printf("%s\n", spa_name(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
		if (pool == NULL || strcmp(pool, spa_name(spa)) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
			dump_nvlist(spa->spa_config, 4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
	mutex_exit(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
static void
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1243
dump_cachefile(const char *cachefile)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1244
{
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1245
	int fd;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1246
	struct stat64 statbuf;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1247
	char *buf;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1248
	nvlist_t *config;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1249
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1250
	if ((fd = open64(cachefile, O_RDONLY)) < 0) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1251
		(void) printf("cannot open '%s': %s\n", cachefile,
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1252
		    strerror(errno));
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1253
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1254
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1255
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1256
	if (fstat64(fd, &statbuf) != 0) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1257
		(void) printf("failed to stat '%s': %s\n", cachefile,
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1258
		    strerror(errno));
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1259
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1260
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1261
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1262
	if ((buf = malloc(statbuf.st_size)) == NULL) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1263
		(void) fprintf(stderr, "failed to allocate %llu bytes\n",
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1264
		    (u_longlong_t)statbuf.st_size);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1265
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1266
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1267
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1268
	if (read(fd, buf, statbuf.st_size) != statbuf.st_size) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1269
		(void) fprintf(stderr, "failed to read %llu bytes\n",
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1270
		    (u_longlong_t)statbuf.st_size);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1271
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1272
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1273
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1274
	(void) close(fd);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1275
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1276
	if (nvlist_unpack(buf, statbuf.st_size, &config, 0) != 0) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1277
		(void) fprintf(stderr, "failed to unpack nvlist\n");
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1278
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1279
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1280
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1281
	free(buf);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1282
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1283
	dump_nvlist(config, 0);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1284
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1285
	nvlist_free(config);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1286
}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1287
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1288
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1289
dump_label(const char *dev)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1290
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
	vdev_label_t label;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
	char *buf = label.vl_vdev_phys.vp_nvlist;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
	size_t buflen = sizeof (label.vl_vdev_phys.vp_nvlist);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1295
	struct stat64 statbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1296
	uint64_t psize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1297
	int l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1298
1170
cbb023fb2c22 6366222 zdb(1M) needs to use largefile primitives when reading label
eschrock
parents: 896
diff changeset
  1299
	if ((fd = open64(dev, O_RDONLY)) < 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1300
		(void) printf("cannot open '%s': %s\n", dev, strerror(errno));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1301
		exit(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1302
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1304
	if (fstat64(fd, &statbuf) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
		(void) printf("failed to stat '%s': %s\n", dev,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
		    strerror(errno));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1307
		exit(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
	psize = statbuf.st_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
	psize = P2ALIGN(psize, (uint64_t)sizeof (vdev_label_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
	for (l = 0; l < VDEV_LABELS; l++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
		nvlist_t *config = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1317
		(void) printf("--------------------------------------------\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
		(void) printf("LABEL %d\n", l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
		(void) printf("--------------------------------------------\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
1170
cbb023fb2c22 6366222 zdb(1M) needs to use largefile primitives when reading label
eschrock
parents: 896
diff changeset
  1321
		if (pread64(fd, &label, sizeof (label),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
		    vdev_label_offset(psize, l, 0)) != sizeof (label)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
			(void) printf("failed to read label %d\n", l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
		if (nvlist_unpack(buf, buflen, &config, 0) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
			(void) printf("failed to unpack label %d\n", l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
		dump_nvlist(config, 4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1335
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
/*ARGSUSED*/
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1337
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
dump_one_dir(char *dsname, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
	objset_t *os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1342
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
	error = dmu_objset_open(dsname, DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1344
	    DS_MODE_USER | DS_MODE_READONLY, &os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
		(void) printf("Could not open %s\n", dsname);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1347
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
	dump_dir(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
	dmu_objset_close(os);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1351
	fuid_table_destroy();
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1352
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1353
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1354
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
static void
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
  1356
zdb_leak(space_map_t *sm, uint64_t start, uint64_t size)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
{
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
  1358
	vdev_t *vd = sm->sm_ppd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
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
  1360
	(void) printf("leaked space: vdev %llu, offset 0x%llx, size %llu\n",
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1361
	    (u_longlong_t)vd->vdev_id, (u_longlong_t)start, (u_longlong_t)size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
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
  1364
/* ARGSUSED */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1365
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1366
zdb_space_map_load(space_map_t *sm)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1368
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1370
static void
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
  1371
zdb_space_map_unload(space_map_t *sm)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
{
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
  1373
	space_map_vacate(sm, zdb_leak, sm);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1374
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
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
  1376
/* ARGSUSED */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1377
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1378
zdb_space_map_claim(space_map_t *sm, uint64_t start, uint64_t size)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1379
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1380
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
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
  1382
static space_map_ops_t zdb_space_map_ops = {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1383
	zdb_space_map_load,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1384
	zdb_space_map_unload,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1385
	NULL,	/* alloc */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1386
	zdb_space_map_claim,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1387
	NULL	/* free */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1388
};
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
static void
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
  1391
zdb_leak_init(spa_t *spa)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
	vdev_t *rvd = spa->spa_root_vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
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
  1395
	for (int c = 0; c < rvd->vdev_children; c++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1396
		vdev_t *vd = rvd->vdev_child[c];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1397
		for (int m = 0; m < vd->vdev_ms_count; m++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
			metaslab_t *msp = vd->vdev_ms[m];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
			mutex_enter(&msp->ms_lock);
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
  1400
			VERIFY(space_map_load(&msp->ms_map, &zdb_space_map_ops,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1401
			    SM_ALLOC, &msp->ms_smo, spa->spa_meta_objset) == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1402
			msp->ms_map.sm_ppd = vd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
			mutex_exit(&msp->ms_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
static void
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
  1409
zdb_leak_fini(spa_t *spa)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
	vdev_t *rvd = spa->spa_root_vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
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
  1413
	for (int c = 0; c < rvd->vdev_children; c++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1414
		vdev_t *vd = rvd->vdev_child[c];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1415
		for (int m = 0; m < vd->vdev_ms_count; m++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1416
			metaslab_t *msp = vd->vdev_ms[m];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1417
			mutex_enter(&msp->ms_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1418
			space_map_unload(&msp->ms_map);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1419
			mutex_exit(&msp->ms_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1420
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1421
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
 * Verify that the sum of the sizes of all blocks in the pool adds up
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
 * to the SPA's sa_alloc total.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
typedef struct zdb_blkstats {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
	uint64_t	zb_asize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
	uint64_t	zb_lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
	uint64_t	zb_psize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
	uint64_t	zb_count;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
} zdb_blkstats_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
#define	DMU_OT_DEFERRED	DMU_OT_NONE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
#define	DMU_OT_TOTAL	DMU_OT_NUMTYPES
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1438
#define	ZB_TOTAL	DN_MAX_LEVELS
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
typedef struct zdb_cb {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1441
	zdb_blkstats_t	zcb_type[ZB_TOTAL + 1][DMU_OT_TOTAL + 1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
	uint64_t	zcb_errors[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
	int		zcb_readfails;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
	int		zcb_haderrors;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
} zdb_cb_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
static void
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1448
zdb_count_block(spa_t *spa, zdb_cb_t *zcb, blkptr_t *bp, dmu_object_type_t type)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
{
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
  1450
	for (int i = 0; i < 4; i++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
		int l = (i < 2) ? BP_GET_LEVEL(bp) : ZB_TOTAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
		int t = (i & 1) ? type : DMU_OT_TOTAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
		zdb_blkstats_t *zb = &zcb->zcb_type[l][t];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
		zb->zb_asize += BP_GET_ASIZE(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
		zb->zb_lsize += BP_GET_LSIZE(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
		zb->zb_psize += BP_GET_PSIZE(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
		zb->zb_count++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1459
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1460
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1461
	if (dump_opt['S']) {
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1462
		boolean_t print_sig;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1463
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1464
		print_sig = !zdb_sig_user_data || (BP_GET_LEVEL(bp) == 0 &&
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1465
		    BP_GET_TYPE(bp) == DMU_OT_PLAIN_FILE_CONTENTS);
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1466
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1467
		if (BP_GET_CHECKSUM(bp) < zdb_sig_cksumalg)
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1468
			print_sig = B_FALSE;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1469
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1470
		if (print_sig) {
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1471
			(void) printf("%llu\t%lld\t%lld\t%s\t%s\t%s\t"
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1472
			    "%llx:%llx:%llx:%llx\n",
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1473
			    (u_longlong_t)BP_GET_LEVEL(bp),
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1474
			    (longlong_t)BP_GET_PSIZE(bp),
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1475
			    (longlong_t)BP_GET_NDVAS(bp),
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1476
			    dmu_ot[BP_GET_TYPE(bp)].ot_name,
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1477
			    zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name,
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1478
			    zio_compress_table[BP_GET_COMPRESS(bp)].ci_name,
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1479
			    (u_longlong_t)bp->blk_cksum.zc_word[0],
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1480
			    (u_longlong_t)bp->blk_cksum.zc_word[1],
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1481
			    (u_longlong_t)bp->blk_cksum.zc_word[2],
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1482
			    (u_longlong_t)bp->blk_cksum.zc_word[3]);
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1483
		}
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1484
	}
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1485
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1486
	if (!dump_opt['L'])
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1487
		VERIFY(zio_wait(zio_claim(NULL, spa, spa_first_txg(spa), bp,
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1488
		    NULL, NULL, ZIO_FLAG_MUSTSUCCEED)) == 0);
789
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
static int
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1492
zdb_blkptr_cb(spa_t *spa, blkptr_t *bp, const zbookmark_t *zb,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1493
    const dnode_phys_t *dnp, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
	zdb_cb_t *zcb = arg;
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1496
	char blkbuf[BP_SPRINTF_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1498
	if (bp == NULL)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1499
		return (0);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1500
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1501
	zdb_count_block(spa, zcb, bp, BP_GET_TYPE(bp));
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
  1502
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1503
	if (dump_opt['c'] || dump_opt['S']) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1504
		int ioerr, size;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1505
		void *data;
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
  1506
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1507
		size = BP_GET_LSIZE(bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1508
		data = malloc(size);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1509
		ioerr = zio_wait(zio_read(NULL, spa, bp, data, size,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1510
		    NULL, NULL, ZIO_PRIORITY_ASYNC_READ,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1511
		    ZIO_FLAG_CANFAIL | ZIO_FLAG_SCRUB, zb));
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1512
		free(data);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1513
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1514
		/* We expect io errors on intent log */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1515
		if (ioerr && BP_GET_TYPE(bp) != DMU_OT_INTENT_LOG) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
			zcb->zcb_haderrors = 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
  1517
			zcb->zcb_errors[ioerr]++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1519
			if (dump_opt['b'] >= 2)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1520
				sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1521
			else
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1522
				blkbuf[0] = '\0';
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1524
			if (!dump_opt['S']) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1525
				(void) printf("zdb_blkptr_cb: "
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1526
				    "Got error %d reading "
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1527
				    "<%llu, %llu, %lld, %llx> %s -- skipping\n",
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1528
				    ioerr,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1529
				    (u_longlong_t)zb->zb_objset,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1530
				    (u_longlong_t)zb->zb_object,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1531
				    (u_longlong_t)zb->zb_level,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1532
				    (u_longlong_t)zb->zb_blkid,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1533
				    blkbuf);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1534
			}
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1535
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1537
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1538
	zcb->zcb_readfails = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
	if (dump_opt['b'] >= 4) {
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1541
		sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1542
		(void) printf("objset %llu object %llu offset 0x%llx %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
		    (u_longlong_t)zb->zb_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1544
		    (u_longlong_t)zb->zb_object,
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1545
		    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid),
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1546
		    blkbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1550
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1551
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1552
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1553
dump_block_stats(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1554
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1555
	zdb_cb_t zcb = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1556
	zdb_blkstats_t *zb, *tzb;
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1557
	uint64_t alloc, space, logalloc;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1558
	vdev_t *rvd = spa->spa_root_vdev;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1559
	int leaks = 0;
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1560
	int c, e;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1561
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1562
	if (!dump_opt['S']) {
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1563
		(void) printf("\nTraversing all blocks %s%s%s%s...\n",
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1564
		    (dump_opt['c'] || !dump_opt['L']) ? "to verify " : "",
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1565
		    dump_opt['c'] ? "checksums " : "",
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1566
		    (dump_opt['c'] && !dump_opt['L']) ? "and verify " : "",
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1567
		    !dump_opt['L'] ? "nothing leaked " : "");
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1568
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
	/*
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
  1571
	 * Load all space maps as SM_ALLOC maps, then traverse the pool
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1572
	 * claiming each block we discover.  If the pool is perfectly
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1573
	 * consistent, the space maps will be empty when we're done.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1574
	 * Anything left over is a leak; any block we can't claim (because
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1575
	 * it's not part of any space map) is a double allocation,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  1576
	 * reference to a freed block, or an unclaimed log block.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
	 */
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1578
	if (!dump_opt['L'])
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1579
		zdb_leak_init(spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
	 * If there's a deferred-free bplist, process that first.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
	if (spa->spa_sync_bplist_obj != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
		bplist_t *bpl = &spa->spa_sync_bplist;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
		blkptr_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
		uint64_t itor = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1589
		VERIFY(0 == bplist_open(bpl, spa->spa_meta_objset,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1590
		    spa->spa_sync_bplist_obj));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
		while (bplist_iterate(bpl, &itor, &blk) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
			if (dump_opt['b'] >= 4) {
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1594
				char blkbuf[BP_SPRINTF_LEN];
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1595
				sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &blk);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
				(void) printf("[%s] %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
				    "deferred free", blkbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
			}
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1599
			zdb_count_block(spa, &zcb, &blk, DMU_OT_DEFERRED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
		bplist_close(bpl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1603
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1604
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1605
	zcb.zcb_haderrors |= traverse_pool(spa, zdb_blkptr_cb, &zcb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1607
	if (zcb.zcb_haderrors && !dump_opt['S']) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
		(void) printf("\nError counts:\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1609
		(void) printf("\t%5s  %s\n", "errno", "count");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1610
		for (e = 0; e < 256; e++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
			if (zcb.zcb_errors[e] != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
				(void) printf("\t%5d  %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
				    e, (u_longlong_t)zcb.zcb_errors[e]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
	 * Report any leaked segments.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
	 */
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1621
	if (!dump_opt['L'])
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1622
		zdb_leak_fini(spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1624
	/*
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1625
	 * If we're interested in printing out the blkptr signatures,
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1626
	 * return now as we don't print out anything else (including
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1627
	 * errors and leaks).
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1628
	 */
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1629
	if (dump_opt['S'])
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1630
		return (zcb.zcb_haderrors ? 3 : 0);
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1631
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
	alloc = spa_get_alloc(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
	space = spa_get_space(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1634
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1635
	/*
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1636
	 * Log blocks allocated from a separate log device don't count
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1637
	 * as part of the normal pool space; factor them in here.
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1638
	 */
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1639
	logalloc = 0;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1640
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1641
	for (c = 0; c < rvd->vdev_children; c++)
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1642
		if (rvd->vdev_child[c]->vdev_islog)
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1643
			logalloc += rvd->vdev_child[c]->vdev_stat.vs_alloc;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1644
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	tzb = &zcb.zcb_type[ZB_TOTAL][DMU_OT_TOTAL];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1647
	if (tzb->zb_asize == alloc + logalloc) {
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1648
		if (!dump_opt['L'])
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1649
			(void) printf("\n\tNo leaks (block sum matches space"
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1650
			    " maps exactly)\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1651
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
		(void) printf("block traversal size %llu != alloc %llu "
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1653
		    "(%s %lld)\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
		    (u_longlong_t)tzb->zb_asize,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4070
diff changeset
  1655
		    (u_longlong_t)alloc + logalloc,
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1656
		    (dump_opt['L']) ? "unreachable" : "leaked",
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  1657
		    (longlong_t)(alloc + logalloc - tzb->zb_asize));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1658
		leaks = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1660
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
	if (tzb->zb_count == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1662
		return (2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1663
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1664
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1665
	(void) printf("\tbp count:      %10llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1666
	    (u_longlong_t)tzb->zb_count);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
	(void) printf("\tbp logical:    %10llu\t avg: %6llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1668
	    (u_longlong_t)tzb->zb_lsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1669
	    (u_longlong_t)(tzb->zb_lsize / tzb->zb_count));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1670
	(void) printf("\tbp physical:   %10llu\t avg:"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1671
	    " %6llu\tcompression: %6.2f\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
	    (u_longlong_t)tzb->zb_psize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1673
	    (u_longlong_t)(tzb->zb_psize / tzb->zb_count),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
	    (double)tzb->zb_lsize / tzb->zb_psize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
	(void) printf("\tbp allocated:  %10llu\t avg:"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1676
	    " %6llu\tcompression: %6.2f\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
	    (u_longlong_t)tzb->zb_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1678
	    (u_longlong_t)(tzb->zb_asize / tzb->zb_count),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
	    (double)tzb->zb_lsize / tzb->zb_asize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
	(void) printf("\tSPA allocated: %10llu\tused: %5.2f%%\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1681
	    (u_longlong_t)alloc, 100.0 * alloc / space);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1682
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
	if (dump_opt['b'] >= 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1684
		int l, t, level;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
		(void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1686
		    "\t  avg\t comp\t%%Total\tType\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
		for (t = 0; t <= DMU_OT_NUMTYPES; t++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
			char csize[6], lsize[6], psize[6], asize[6], avg[6];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
			char *typename;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
			typename = t == DMU_OT_DEFERRED ? "deferred free" :
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
			    t == DMU_OT_TOTAL ? "Total" : dmu_ot[t].ot_name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1695
			if (zcb.zcb_type[ZB_TOTAL][t].zb_asize == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
				(void) printf("%6s\t%5s\t%5s\t%5s"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1697
				    "\t%5s\t%5s\t%6s\t%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1699
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1700
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1701
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1702
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1703
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
				    typename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
				continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
			for (l = ZB_TOTAL - 1; l >= -1; l--) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
				level = (l == -1 ? ZB_TOTAL : l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1711
				zb = &zcb.zcb_type[level][t];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1713
				if (zb->zb_asize == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1714
					continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
				if (dump_opt['b'] < 3 && level != ZB_TOTAL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
					continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
				if (level == 0 && zb->zb_asize ==
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
				    zcb.zcb_type[ZB_TOTAL][t].zb_asize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
					continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
				nicenum(zb->zb_count, csize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
				nicenum(zb->zb_lsize, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
				nicenum(zb->zb_psize, psize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
				nicenum(zb->zb_asize, asize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
				nicenum(zb->zb_asize / zb->zb_count, avg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
				(void) printf("%6s\t%5s\t%5s\t%5s\t%5s"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1730
				    "\t%5.2f\t%6.2f\t",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
				    csize, lsize, psize, asize, avg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1732
				    (double)zb->zb_lsize / zb->zb_psize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
				    100.0 * zb->zb_asize / tzb->zb_asize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
				if (level == ZB_TOTAL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
					(void) printf("%s\n", typename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
				else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1738
					(void) printf("    L%d %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
					    level, typename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1744
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1745
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1746
	if (leaks)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1747
		return (2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1749
	if (zcb.zcb_haderrors)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1750
		return (3);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1752
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1753
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1754
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1755
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1756
dump_zpool(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1757
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1758
	dsl_pool_t *dp = spa_get_dsl(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1759
	int rc = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1760
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
	if (dump_opt['u'])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1762
		dump_uberblock(&spa->spa_uberblock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1764
	if (dump_opt['d'] || dump_opt['i']) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1765
		dump_dir(dp->dp_meta_objset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1766
		if (dump_opt['d'] >= 3) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1767
			dump_bplist(dp->dp_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1768
			    spa->spa_sync_bplist_obj, "Deferred frees");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1769
			dump_dtl(spa->spa_root_vdev, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1770
			dump_metaslabs(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1771
		}
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
  1772
		(void) dmu_objset_find(spa_name(spa), dump_one_dir, NULL,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1773
		    DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  1776
	if (dump_opt['b'] || dump_opt['c'] || dump_opt['S'])
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
		rc = dump_block_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1779
	if (dump_opt['s'])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1780
		show_pool_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
	if (rc != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1783
		exit(rc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1786
#define	ZDB_FLAG_CHECKSUM	0x0001
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1787
#define	ZDB_FLAG_DECOMPRESS	0x0002
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1788
#define	ZDB_FLAG_BSWAP		0x0004
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1789
#define	ZDB_FLAG_GBH		0x0008
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1790
#define	ZDB_FLAG_INDIRECT	0x0010
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1791
#define	ZDB_FLAG_PHYS		0x0020
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1792
#define	ZDB_FLAG_RAW		0x0040
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1793
#define	ZDB_FLAG_PRINT_BLKPTR	0x0080
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1794
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1795
int flagbits[256];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1796
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1797
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1798
zdb_print_blkptr(blkptr_t *bp, int flags)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1799
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1800
	dva_t *dva = bp->blk_dva;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1801
	int d;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1802
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1803
	if (flags & ZDB_FLAG_BSWAP)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1804
		byteswap_uint64_array((void *)bp, sizeof (blkptr_t));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1805
	/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1806
	 * 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
  1807
	 * cmd/mdb/common/modules/zfs/zfs.c .  Yeah, I hate code
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1808
	 * replication, too.
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1809
	 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1810
	for (d = 0; d < BP_GET_NDVAS(bp); d++) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1811
		(void) printf("\tDVA[%d]: vdev_id %lld / %llx\n", d,
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1812
		    (longlong_t)DVA_GET_VDEV(&dva[d]),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1813
		    (longlong_t)DVA_GET_OFFSET(&dva[d]));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1814
		(void) printf("\tDVA[%d]:       GANG: %-5s  GRID:  %04llx\t"
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1815
		    "ASIZE: %llx\n", d,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1816
		    DVA_GET_GANG(&dva[d]) ? "TRUE" : "FALSE",
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1817
		    (longlong_t)DVA_GET_GRID(&dva[d]),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1818
		    (longlong_t)DVA_GET_ASIZE(&dva[d]));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1819
		(void) printf("\tDVA[%d]: :%llu:%llx:%llx:%s%s%s%s\n", d,
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1820
		    (u_longlong_t)DVA_GET_VDEV(&dva[d]),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1821
		    (longlong_t)DVA_GET_OFFSET(&dva[d]),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1822
		    (longlong_t)BP_GET_PSIZE(bp),
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1823
		    BP_SHOULD_BYTESWAP(bp) ? "e" : "",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1824
		    !DVA_GET_GANG(&dva[d]) && BP_GET_LEVEL(bp) != 0 ?
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1825
		    "d" : "",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1826
		    DVA_GET_GANG(&dva[d]) ? "g" : "",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1827
		    BP_GET_COMPRESS(bp) != 0 ? "d" : "");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1828
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1829
	(void) printf("\tLSIZE:  %-16llx\t\tPSIZE: %llx\n",
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1830
	    (longlong_t)BP_GET_LSIZE(bp), (longlong_t)BP_GET_PSIZE(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1831
	(void) printf("\tENDIAN: %6s\t\t\t\t\tTYPE:  %s\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1832
	    BP_GET_BYTEORDER(bp) ? "LITTLE" : "BIG",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1833
	    dmu_ot[BP_GET_TYPE(bp)].ot_name);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1834
	(void) printf("\tBIRTH:  %-16llx   LEVEL: %-2llu\tFILL:  %llx\n",
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  1835
	    (u_longlong_t)bp->blk_birth, (u_longlong_t)BP_GET_LEVEL(bp),
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1836
	    (u_longlong_t)bp->blk_fill);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1837
	(void) printf("\tCKFUNC: %-16s\t\tCOMP:  %s\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1838
	    zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1839
	    zio_compress_table[BP_GET_COMPRESS(bp)].ci_name);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1840
	(void) printf("\tCKSUM:  %llx:%llx:%llx:%llx\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1841
	    (u_longlong_t)bp->blk_cksum.zc_word[0],
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1842
	    (u_longlong_t)bp->blk_cksum.zc_word[1],
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1843
	    (u_longlong_t)bp->blk_cksum.zc_word[2],
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1844
	    (u_longlong_t)bp->blk_cksum.zc_word[3]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1845
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1846
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1847
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1848
zdb_dump_indirect(blkptr_t *bp, int nbps, int flags)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1849
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1850
	int i;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1851
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1852
	for (i = 0; i < nbps; i++)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1853
		zdb_print_blkptr(&bp[i], flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1854
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1855
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1856
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1857
zdb_dump_gbh(void *buf, int flags)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1858
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1859
	zdb_dump_indirect((blkptr_t *)buf, SPA_GBH_NBLKPTRS, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1860
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1861
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1862
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1863
zdb_dump_block_raw(void *buf, uint64_t size, int flags)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1864
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1865
	if (flags & ZDB_FLAG_BSWAP)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1866
		byteswap_uint64_array(buf, size);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1867
	(void) write(2, buf, size);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1868
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1869
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1870
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1871
zdb_dump_block(char *label, void *buf, uint64_t size, int flags)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1872
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1873
	uint64_t *d = (uint64_t *)buf;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1874
	int nwords = size / sizeof (uint64_t);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1875
	int do_bswap = !!(flags & ZDB_FLAG_BSWAP);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1876
	int i, j;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1877
	char *hdr, *c;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1878
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1879
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1880
	if (do_bswap)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1881
		hdr = " 7 6 5 4 3 2 1 0   f e d c b a 9 8";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1882
	else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1883
		hdr = " 0 1 2 3 4 5 6 7   8 9 a b c d e f";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1884
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1885
	(void) printf("\n%s\n%6s   %s  0123456789abcdef\n", label, "", hdr);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1886
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1887
	for (i = 0; i < nwords; i += 2) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1888
		(void) printf("%06llx:  %016llx  %016llx  ",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1889
		    (u_longlong_t)(i * sizeof (uint64_t)),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1890
		    (u_longlong_t)(do_bswap ? BSWAP_64(d[i]) : d[i]),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1891
		    (u_longlong_t)(do_bswap ? BSWAP_64(d[i + 1]) : d[i + 1]));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1892
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1893
		c = (char *)&d[i];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1894
		for (j = 0; j < 2 * sizeof (uint64_t); j++)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1895
			(void) printf("%c", isprint(c[j]) ? c[j] : '.');
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1896
		(void) printf("\n");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1897
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1898
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1899
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1900
/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1901
 * There are two acceptable formats:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1902
 *	leaf_name	  - For example: c1t0d0 or /tmp/ztest.0a
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1903
 *	child[.child]*    - For example: 0.1.1
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1904
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1905
 * The second form can be used to specify arbitrary vdevs anywhere
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1906
 * in the heirarchy.  For example, in a pool with a mirror of
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1907
 * RAID-Zs, you can specify either RAID-Z vdev with 0.0 or 0.1 .
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1908
 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1909
static vdev_t *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1910
zdb_vdev_lookup(vdev_t *vdev, char *path)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1911
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1912
	char *s, *p, *q;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1913
	int i;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1914
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1915
	if (vdev == NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1916
		return (NULL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1917
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1918
	/* First, assume the x.x.x.x format */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1919
	i = (int)strtoul(path, &s, 10);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1920
	if (s == path || (s && *s != '.' && *s != '\0'))
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1921
		goto name;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1922
	if (i < 0 || i >= vdev->vdev_children)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1923
		return (NULL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1924
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1925
	vdev = vdev->vdev_child[i];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1926
	if (*s == '\0')
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1927
		return (vdev);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1928
	return (zdb_vdev_lookup(vdev, s+1));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1929
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1930
name:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1931
	for (i = 0; i < vdev->vdev_children; i++) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1932
		vdev_t *vc = vdev->vdev_child[i];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1933
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1934
		if (vc->vdev_path == NULL) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1935
			vc = zdb_vdev_lookup(vc, path);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1936
			if (vc == NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1937
				continue;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1938
			else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1939
				return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1940
		}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1941
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1942
		p = strrchr(vc->vdev_path, '/');
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1943
		p = p ? p + 1 : vc->vdev_path;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1944
		q = &vc->vdev_path[strlen(vc->vdev_path) - 2];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1945
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1946
		if (strcmp(vc->vdev_path, path) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1947
			return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1948
		if (strcmp(p, path) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1949
			return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1950
		if (strcmp(q, "s0") == 0 && strncmp(p, path, q - p) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1951
			return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1952
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1953
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1954
	return (NULL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1955
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1956
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1957
/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1958
 * Read a block from a pool and print it out.  The syntax of the
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1959
 * block descriptor is:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1960
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1961
 *	pool:vdev_specifier:offset:size[:flags]
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1962
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1963
 *	pool           - The name of the pool you wish to read from
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1964
 *	vdev_specifier - Which vdev (see comment for zdb_vdev_lookup)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1965
 *	offset         - offset, in hex, in bytes
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1966
 *	size           - Amount of data to read, in hex, in bytes
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1967
 *	flags          - A string of characters specifying options
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1968
 *		 b: Decode a blkptr at given offset within block
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1969
 *		*c: Calculate and display checksums
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1970
 *		*d: Decompress data before dumping
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1971
 *		 e: Byteswap data before dumping
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1972
 *		*g: Display data as a gang block header
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1973
 *		*i: Display as an indirect block
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1974
 *		 p: Do I/O to physical offset
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1975
 *		 r: Dump raw data to stdout
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1976
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1977
 *              * = not yet implemented
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1978
 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1979
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1980
zdb_read_block(char *thing, spa_t **spap)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1981
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1982
	spa_t *spa = *spap;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1983
	int flags = 0;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1984
	uint64_t offset = 0, size = 0, blkptr_offset = 0;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1985
	zio_t *zio;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1986
	vdev_t *vd;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1987
	void *buf;
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
  1988
	char *s, *p, *dup, *pool, *vdev, *flagstr;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1989
	int i, error, zio_flags;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1990
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1991
	dup = strdup(thing);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1992
	s = strtok(dup, ":");
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
  1993
	pool = s ? s : "";
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1994
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1995
	vdev = s ? s : "";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1996
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1997
	offset = strtoull(s ? s : "", NULL, 16);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1998
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1999
	size = strtoull(s ? s : "", NULL, 16);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2000
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2001
	flagstr = s ? s : "";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2002
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2003
	s = NULL;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2004
	if (size == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2005
		s = "size must not be zero";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2006
	if (!IS_P2ALIGNED(size, DEV_BSIZE))
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2007
		s = "size must be a multiple of sector size";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2008
	if (!IS_P2ALIGNED(offset, DEV_BSIZE))
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2009
		s = "offset must be a multiple of sector size";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2010
	if (s) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2011
		(void) printf("Invalid block specifier: %s  - %s\n", thing, s);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2012
		free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2013
		return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2014
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2015
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2016
	for (s = strtok(flagstr, ":"); s; s = strtok(NULL, ":")) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2017
		for (i = 0; flagstr[i]; i++) {
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  2018
			int bit = flagbits[(uchar_t)flagstr[i]];
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2019
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2020
			if (bit == 0) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2021
				(void) printf("***Invalid flag: %c\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2022
				    flagstr[i]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2023
				continue;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2024
			}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2025
			flags |= bit;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2026
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2027
			/* If it's not something with an argument, keep going */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2028
			if ((bit & (ZDB_FLAG_CHECKSUM | ZDB_FLAG_DECOMPRESS |
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2029
			    ZDB_FLAG_PRINT_BLKPTR)) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2030
				continue;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2031
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2032
			p = &flagstr[i + 1];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2033
			if (bit == ZDB_FLAG_PRINT_BLKPTR)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2034
				blkptr_offset = strtoull(p, &p, 16);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2035
			if (*p != ':' && *p != '\0') {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2036
				(void) printf("***Invalid flag arg: '%s'\n", s);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2037
				free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2038
				return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2039
			}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2040
		}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2041
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2042
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
  2043
	if (spa == NULL || strcmp(spa_name(spa), pool) != 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  2044
		if (spa)
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2045
			spa_close(spa, (void *)zdb_read_block);
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
  2046
		error = spa_open(pool, spap, (void *)zdb_read_block);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2047
		if (error)
4070
4390ea390a1e 6386594 zdb message should be clearer when failing for lack of permissions
mc142369
parents: 3912
diff changeset
  2048
			fatal("Failed to open pool '%s': %s",
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
  2049
			    pool, strerror(error));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2050
		spa = *spap;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2051
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2052
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2053
	vd = zdb_vdev_lookup(spa->spa_root_vdev, vdev);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2054
	if (vd == NULL) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2055
		(void) printf("***Invalid vdev: %s\n", vdev);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2056
		free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2057
		return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2058
	} else {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2059
		if (vd->vdev_path)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2060
			(void) printf("Found vdev: %s\n", vd->vdev_path);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2061
		else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2062
			(void) printf("Found vdev type: %s\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2063
			    vd->vdev_ops->vdev_op_type);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2064
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2065
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2066
	buf = umem_alloc(size, UMEM_NOFAIL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2067
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2068
	zio_flags = ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE |
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
  2069
	    ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2070
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
  2071
	spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2072
	zio = zio_root(spa, NULL, NULL, 0);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2073
	/* XXX todo - cons up a BP so RAID-Z will be happy */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2074
	zio_nowait(zio_vdev_child_io(zio, NULL, vd, offset, buf, size,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2075
	    ZIO_TYPE_READ, ZIO_PRIORITY_SYNC_READ, zio_flags, NULL, NULL));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2076
	error = zio_wait(zio);
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
  2077
	spa_config_exit(spa, SCL_STATE, FTAG);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2078
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2079
	if (error) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2080
		(void) printf("Read of %s failed, error: %d\n", thing, error);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2081
		goto out;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2082
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2083
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2084
	if (flags & ZDB_FLAG_PRINT_BLKPTR)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2085
		zdb_print_blkptr((blkptr_t *)(void *)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2086
		    ((uintptr_t)buf + (uintptr_t)blkptr_offset), flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2087
	else if (flags & ZDB_FLAG_RAW)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2088
		zdb_dump_block_raw(buf, size, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2089
	else if (flags & ZDB_FLAG_INDIRECT)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2090
		zdb_dump_indirect((blkptr_t *)buf, size / sizeof (blkptr_t),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2091
		    flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2092
	else if (flags & ZDB_FLAG_GBH)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2093
		zdb_dump_gbh(buf, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2094
	else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2095
		zdb_dump_block(thing, buf, size, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2096
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2097
out:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2098
	umem_free(buf, size);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2099
	free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2100
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2101
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2102
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2103
nvlist_string_match(nvlist_t *config, char *name, char *tgt)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2104
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2105
	char *s;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2106
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2107
	if (nvlist_lookup_string(config, name, &s) != 0)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2108
		return (B_FALSE);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2109
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2110
	return (strcmp(s, tgt) == 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2111
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2112
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2113
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2114
nvlist_uint64_match(nvlist_t *config, char *name, uint64_t tgt)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2115
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2116
	uint64_t val;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2117
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2118
	if (nvlist_lookup_uint64(config, name, &val) != 0)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2119
		return (B_FALSE);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2120
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2121
	return (val == tgt);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2122
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2123
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2124
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2125
vdev_child_guid_match(nvlist_t *vdev, uint64_t guid)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2126
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2127
	nvlist_t **child;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2128
	uint_t c, children;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2129
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2130
	verify(nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN,
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2131
	    &child, &children) == 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2132
	for (c = 0; c < children; ++c)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2133
		if (nvlist_uint64_match(child[c], ZPOOL_CONFIG_GUID, guid))
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2134
			return (B_TRUE);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2135
	return (B_FALSE);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2136
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2137
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2138
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2139
vdev_child_string_match(nvlist_t *vdev, char *tgt)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2140
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2141
	nvlist_t **child;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2142
	uint_t c, children;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2143
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2144
	verify(nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN,
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2145
	    &child, &children) == 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2146
	for (c = 0; c < children; ++c) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2147
		if (nvlist_string_match(child[c], ZPOOL_CONFIG_PATH, tgt) ||
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2148
		    nvlist_string_match(child[c], ZPOOL_CONFIG_DEVID, tgt))
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2149
			return (B_TRUE);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2150
	}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2151
	return (B_FALSE);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2152
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2153
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2154
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2155
vdev_guid_match(nvlist_t *config, uint64_t guid)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2156
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2157
	nvlist_t *nvroot;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2158
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2159
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2160
	    &nvroot) == 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2161
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2162
	return (nvlist_uint64_match(nvroot, ZPOOL_CONFIG_GUID, guid) ||
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2163
	    vdev_child_guid_match(nvroot, guid));
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2164
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2165
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2166
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2167
vdev_string_match(nvlist_t *config, char *tgt)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2168
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2169
	nvlist_t *nvroot;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2170
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2171
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2172
	    &nvroot) == 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2173
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2174
	return (vdev_child_string_match(nvroot, tgt));
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2175
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2176
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2177
static boolean_t
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2178
pool_match(nvlist_t *config, char *tgt)
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2179
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2180
	uint64_t guid = strtoull(tgt, NULL, 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2181
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2182
	if (guid != 0) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2183
		return (
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2184
		    nvlist_uint64_match(config, ZPOOL_CONFIG_POOL_GUID, guid) ||
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2185
		    vdev_guid_match(config, guid));
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2186
	} else {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2187
		return (
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2188
		    nvlist_string_match(config, ZPOOL_CONFIG_POOL_NAME, tgt) ||
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2189
		    vdev_string_match(config, tgt));
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2190
	}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2191
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2192
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2193
static int
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2194
find_exported_zpool(char *pool_id, nvlist_t **configp, char *vdev_dir)
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2195
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2196
	nvlist_t *pools;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2197
	int error = ENOENT;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2198
	nvlist_t *match = NULL;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2199
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2200
	if (vdev_dir != NULL)
6807
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6689
diff changeset
  2201
		pools = zpool_find_import_activeok(g_zfs, 1, &vdev_dir);
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2202
	else
6807
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6689
diff changeset
  2203
		pools = zpool_find_import_activeok(g_zfs, 0, NULL);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2204
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2205
	if (pools != NULL) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2206
		nvpair_t *elem = NULL;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2207
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2208
		while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2209
			verify(nvpair_value_nvlist(elem, configp) == 0);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2210
			if (pool_match(*configp, pool_id)) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2211
				if (match != NULL) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2212
					(void) fatal(
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2213
					    "More than one matching pool - "
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2214
					    "specify guid/devid/device path.");
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2215
				} else {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2216
					match = *configp;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2217
					error = 0;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2218
				}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2219
			}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2220
		}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2221
	}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2222
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2223
	*configp = error ? NULL : match;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2224
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2225
	return (error);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2226
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2227
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2228
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2229
main(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2230
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2231
	int i, c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2232
	struct rlimit rl = { 1024, 1024 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2233
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2234
	objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
	char *endstr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
	int dump_all = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
	int verbose = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
	int error;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2239
	int exported = 0;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2240
	char *vdev_dir = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
	(void) setrlimit(RLIMIT_NOFILE, &rl);
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
  2243
	(void) enable_extended_FILE_stdio(-1, -1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2244
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
	dprintf_setup(&argc, argv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  2247
	while ((c = getopt(argc, argv, "udibcsvCLS:U:lRep:")) != -1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
		case 'u':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
		case 'd':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2251
		case 'i':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
		case 'b':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2253
		case 'c':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
		case 's':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2255
		case 'C':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
		case 'l':
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2257
		case 'R':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
			dump_opt[c]++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
			dump_all = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
			break;
8121
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  2261
		case 'L':
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  2262
			dump_opt[c]++;
7fd09d4ebd9c 6757430 want an option for zdb to disable space map loading and leak tracking
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 7837
diff changeset
  2263
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
		case 'v':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2265
			verbose++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2266
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
		case 'U':
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2268
			spa_config_path = optarg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
			break;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2270
		case 'e':
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2271
			exported = 1;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2272
			break;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2273
		case 'p':
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2274
			vdev_dir = optarg;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2275
			break;
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2276
		case 'S':
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2277
			dump_opt[c]++;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2278
			dump_all = 0;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2279
			zdb_sig_user_data = (strncmp(optarg, "user:", 5) == 0);
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2280
			if (!zdb_sig_user_data && strncmp(optarg, "all:", 4))
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2281
				usage();
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2282
			endstr = strchr(optarg, ':') + 1;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2283
			if (strcmp(endstr, "fletcher2") == 0)
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2284
				zdb_sig_cksumalg = ZIO_CHECKSUM_FLETCHER_2;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2285
			else if (strcmp(endstr, "fletcher4") == 0)
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2286
				zdb_sig_cksumalg = ZIO_CHECKSUM_FLETCHER_4;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2287
			else if (strcmp(endstr, "sha256") == 0)
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2288
				zdb_sig_cksumalg = ZIO_CHECKSUM_SHA256;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2289
			else if (strcmp(endstr, "all") == 0)
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2290
				zdb_sig_cksumalg = ZIO_CHECKSUM_FLETCHER_2;
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2291
			else
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2292
				usage();
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2293
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2294
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2295
			usage();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2296
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2297
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2298
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2299
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2300
	if (vdev_dir != NULL && exported == 0) {
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2301
		(void) fprintf(stderr, "-p option requires use of -e\n");
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2302
		usage();
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2303
	}
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2304
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2305
	kernel_init(FREAD);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2306
	g_zfs = libzfs_init();
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4627
diff changeset
  2307
	ASSERT(g_zfs != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2308
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
	for (c = 0; c < 256; c++) {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2310
		if (dump_all && c != 'l' && c != 'R')
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2311
			dump_opt[c] = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2312
		if (dump_opt[c])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2313
			dump_opt[c] += verbose;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2314
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2315
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2316
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2317
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2318
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2320
		if (dump_opt['C']) {
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2321
			dump_cachefile(spa_config_path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2322
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2323
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2324
		usage();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2325
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2327
	if (dump_opt['l']) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
		dump_label(argv[0]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2330
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2331
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2332
	if (dump_opt['R']) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2333
		flagbits['b'] = ZDB_FLAG_PRINT_BLKPTR;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2334
		flagbits['c'] = ZDB_FLAG_CHECKSUM;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2335
		flagbits['d'] = ZDB_FLAG_DECOMPRESS;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2336
		flagbits['e'] = ZDB_FLAG_BSWAP;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2337
		flagbits['g'] = ZDB_FLAG_GBH;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2338
		flagbits['i'] = ZDB_FLAG_INDIRECT;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2339
		flagbits['p'] = ZDB_FLAG_PHYS;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2340
		flagbits['r'] = ZDB_FLAG_RAW;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2341
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2342
		spa = NULL;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2343
		while (argv[0]) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2344
			zdb_read_block(argv[0], &spa);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2345
			argv++;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2346
			argc--;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2347
		}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2348
		if (spa)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2349
			spa_close(spa, (void *)zdb_read_block);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2350
		return (0);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2351
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2352
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2353
	if (dump_opt['C'])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
		dump_config(argv[0]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2355
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2356
	error = 0;
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2357
	if (exported) {
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2358
		/*
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2359
		 * Check to see if the name refers to an exported zpool
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2360
		 */
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2361
		char *slash;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2362
		nvlist_t *exported_conf = NULL;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2363
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2364
		if ((slash = strchr(argv[0], '/')) != NULL)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2365
			*slash = '\0';
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2366
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  2367
		error = find_exported_zpool(argv[0], &exported_conf, vdev_dir);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2368
		if (error == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2369
			nvlist_t *nvl = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2370
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2371
			if (vdev_dir != NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2372
				if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2373
					error = ENOMEM;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2374
				else if (nvlist_add_string(nvl,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2375
				    zpool_prop_to_name(ZPOOL_PROP_ALTROOT),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2376
				    vdev_dir) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2377
					error = ENOMEM;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2378
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2379
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2380
			if (error == 0)
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2381
				error = spa_import_faulted(argv[0],
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2382
				    exported_conf, nvl);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2383
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  2384
			nvlist_free(nvl);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2385
		}
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2386
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2387
		if (slash != NULL)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2388
			*slash = '/';
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2389
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2390
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2391
	if (error == 0) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2392
		if (strchr(argv[0], '/') != NULL) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2393
			error = dmu_objset_open(argv[0], DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2394
			    DS_MODE_USER | DS_MODE_READONLY, &os);
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2395
		} else {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2396
			error = spa_open(argv[0], &spa, FTAG);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  2397
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2398
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2399
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2400
	if (error)
4070
4390ea390a1e 6386594 zdb message should be clearer when failing for lack of permissions
mc142369
parents: 3912
diff changeset
  2401
		fatal("can't open %s: %s", argv[0], strerror(error));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2402
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2403
	argv++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2404
	if (--argc > 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2405
		zopt_objects = argc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2406
		zopt_object = calloc(zopt_objects, sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2407
		for (i = 0; i < zopt_objects; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2408
			errno = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2409
			zopt_object[i] = strtoull(argv[i], NULL, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2410
			if (zopt_object[i] == 0 && errno != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2411
				fatal("bad object number %s: %s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2412
				    argv[i], strerror(errno));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2413
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2414
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2415
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2416
	if (os != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2417
		dump_dir(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2418
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2419
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2420
		dump_zpool(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2421
		spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2422
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2423
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  2424
	fuid_table_destroy();
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  2425
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2426
	libzfs_fini(g_zfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2427
	kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2429
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2430
}