usr/src/cmd/zdb/zdb.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 13618 c6ae14a341e8
child 13743 95aba6e49b9f
permissions -rw-r--r--
2619 asynchronous destruction of ZFS file systems 2747 SPA versioning with zfs feature flags Reviewed by: Matt Ahrens <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[email protected]>
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
 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
12050
5879aa161e65 6938757 SMB and NFS referrals not working correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
    23
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
    24
 * Copyright (c) 2012 by Delphix. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <stdio.h>
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
    28
#include <stdio_ext.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <stdlib.h>
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
    30
#include <ctype.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/zfs_znode.h>
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
    38
#include <sys/zfs_sa.h>
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
    39
#include <sys/sa.h>
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
    40
#include <sys/sa_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/vdev.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/metaslab_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/dsl_pool.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/zil_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#include <sys/dmu_traverse.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include <sys/zio_compress.h>
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
    56
#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
    57
#include <sys/arc.h>
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
    58
#include <sys/ddt.h>
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
    59
#include <sys/zfeature.h>
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    60
#undef ZFS_MAXNAMELEN
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    61
#undef verify
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    62
#include <libzfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    64
#define	ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    65
    zio_compress_table[(idx)].ci_name : "UNKNOWN")
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    66
#define	ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    67
    zio_checksum_table[(idx)].ci_name : "UNKNOWN")
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    68
#define	ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
    69
    dmu_ot[(idx)].ot_name : DMU_OT_IS_VALID(idx) ? \
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
    70
    dmu_ot_byteswap[DMU_OT_BYTESWAP(idx)].ob_name : "UNKNOWN")
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    71
#define	ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES)
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
    72
11726
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
    73
#ifndef lint
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
    74
extern int zfs_recover;
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
    75
#else
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
    76
int zfs_recover;
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
    77
#endif
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
    78
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
const char cmdname[] = "zdb";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
uint8_t dump_opt[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
extern void dump_intent_log(zilog_t *);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
uint64_t *zopt_object = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
int zopt_objects = 0;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
    87
libzfs_handle_t *g_zfs;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
 * These libumem hooks provide a reasonable set of defaults for the allocator's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
 * debugging facilities.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
_umem_debug_init()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
	return ("default,verbose"); /* $UMEM_DEBUG setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
_umem_logging_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	return ("fail,contents"); /* $UMEM_LOGGING setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
usage(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	(void) fprintf(stderr,
13618
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   109
	    "Usage: %s [-CumdibcsDvhLXFPA] [-t txg] [-e [-p path...]] "
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   110
	    "poolname [object...]\n"
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   111
	    "       %s [-divPA] [-e -p path...] dataset [object...]\n"
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   112
	    "       %s -m [-LXFPA] [-t txg] [-e [-p path...]] "
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   113
	    "poolname [vdev [metaslab...]]\n"
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   114
	    "       %s -R [-A] [-e [-p path...]] poolname "
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   115
	    "vdev:offset:size[:flags]\n"
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   116
	    "       %s -S [-PA] [-e [-p path...]] poolname\n"
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   117
	    "       %s -l [-uA] device\n"
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   118
	    "       %s -C [-A] [-U config]\n\n",
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
   119
	    cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   121
	(void) fprintf(stderr, "    Dataset name must include at least one "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   122
	    "separator character '/' or '@'\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   123
	(void) fprintf(stderr, "    If dataset name is specified, only that "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   124
	    "dataset is dumped\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   125
	(void) fprintf(stderr, "    If object numbers are specified, only "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   126
	    "those objects are dumped\n\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   127
	(void) fprintf(stderr, "    Options to control amount of output:\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   128
	(void) fprintf(stderr, "        -u uberblock\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   129
	(void) fprintf(stderr, "        -d dataset(s)\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   130
	(void) fprintf(stderr, "        -i intent logs\n");
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
   131
	(void) fprintf(stderr, "        -C config (or cachefile if alone)\n");
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   132
	(void) fprintf(stderr, "        -h pool history\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   133
	(void) fprintf(stderr, "        -b block statistics\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   134
	(void) fprintf(stderr, "        -m metaslabs\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   135
	(void) fprintf(stderr, "        -c checksum all metadata (twice for "
9463
d0bd231c7518 6764124 want zdb to be able to checksum metadata blocks only
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 9425
diff changeset
   136
	    "all data) blocks\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   137
	(void) fprintf(stderr, "        -s report stats on zdb's I/O\n");
11811
b25d9f1b5d8e 6914746 sprintf_blkptr() causes NULL pointer dereference
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11728
diff changeset
   138
	(void) fprintf(stderr, "        -D dedup statistics\n");
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   139
	(void) fprintf(stderr, "        -S simulate dedup to measure effect\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   140
	(void) fprintf(stderr, "        -v verbose (applies to all others)\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	(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
   142
	(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
   143
	    "load spacemaps)\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   144
	(void) fprintf(stderr, "        -R read and display block from a "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   145
	    "device\n\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   146
	(void) fprintf(stderr, "    Below options are intended for use "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   147
	    "with other options (except -l):\n");
11726
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
   148
	(void) fprintf(stderr, "        -A ignore assertions (-A), enable "
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
   149
	    "panic recovery (-AA) or both (-AAA)\n");
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
   150
	(void) fprintf(stderr, "        -F attempt automatic rewind within "
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
   151
	    "safe range of transaction groups\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   152
	(void) fprintf(stderr, "        -U <cachefile_path> -- use alternate "
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5959
diff changeset
   153
	    "cachefile\n");
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
   154
	(void) fprintf(stderr, "        -X attempt extreme rewind (does not "
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
   155
	    "work with dataset)\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   156
	(void) fprintf(stderr, "        -e pool is exported/destroyed/"
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   157
	    "has altroot/not in a cachefile\n");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   158
	(void) fprintf(stderr, "        -p <path> -- use one or more with "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   159
	    "-e to specify path to vdev dir\n");
13618
c6ae14a341e8 2088 zdb could use a reasonable manual page
Richard Lowe <richlowe@richlowe.net>
parents: 12961
diff changeset
   160
	(void) fprintf(stderr, "        -P print numbers in parseable form\n");
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
   161
	(void) fprintf(stderr, "        -t <txg> -- highest txg to use when "
8188
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
   162
	    "searching for uberblocks\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
	    "to make only that option verbose\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
	exit(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
8924
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
   169
/*
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
   170
 * Called for usage errors that are discovered after a call to spa_open(),
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
   171
 * dmu_bonus_hold(), or pool_match().  abort() is called for other errors.
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
   172
 */
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
   173
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
fatal(const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	va_list ap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
	va_start(ap, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	(void) fprintf(stderr, "%s: ", cmdname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
	(void) vfprintf(stderr, fmt, ap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
	va_end(ap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
	(void) fprintf(stderr, "\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
8924
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
   185
	exit(1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	nvlist_t *nv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
	size_t nvsize = *(uint64_t *)data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
   196
	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	umem_free(packed, nvsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
	dump_nvlist(nv, 8);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
	nvlist_free(nv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   207
static void
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   208
zdb_nicenum(uint64_t num, char *buf)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   209
{
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   210
	if (dump_opt['P'])
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   211
		(void) sprintf(buf, "%llu", (longlong_t)num);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   212
	else
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   213
		nicenum(num, buf);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   214
}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   215
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
const char dump_zap_stars[] = "****************************************";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
const int dump_zap_width = sizeof (dump_zap_stars) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	int minidx = ZAP_HISTOGRAM_SIZE - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
	int maxidx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	uint64_t max = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
		if (histo[i] > max)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
			max = histo[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
		if (histo[i] > 0 && i > maxidx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
			maxidx = i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
		if (histo[i] > 0 && i < minidx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
			minidx = i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	if (max < dump_zap_width)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
		max = dump_zap_width;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
	for (i = minidx; i <= maxidx; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
dump_zap_stats(objset_t *os, uint64_t object)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	zap_stats_t zs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	error = zap_get_stats(os, object, &zs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
	if (zs.zs_ptrtbl_len == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
		ASSERT(zs.zs_num_blocks == 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
		    (u_longlong_t)zs.zs_blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
		    (u_longlong_t)zs.zs_num_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	(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
   263
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   264
	(void) printf("\t\tPointer table:\n");
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   265
	(void) printf("\t\t\t%llu elements\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	    (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
   267
	(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
   268
	    (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
   269
	(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
   270
	    (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
   271
	(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
   272
	    (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
   273
	(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
   274
	    (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
   275
	(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
   276
	    (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
   277
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
	(void) printf("\t\tZAP entries: %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	    (u_longlong_t)zs.zs_num_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
	(void) printf("\t\tLeaf blocks: %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	    (u_longlong_t)zs.zs_num_leafs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
	(void) printf("\t\tTotal blocks: %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	    (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
   284
	(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
   285
	    (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
   286
	(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
   287
	    (u_longlong_t)zs.zs_magic);
7d486ebd46b7 6392291 zdb needs to tell the entire goodness of the fat zap
nd150628
parents: 1578
diff changeset
   288
	(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
   289
	    (u_longlong_t)zs.zs_salt);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
	(void) printf("\t\tLeafs with 2^n pointers:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	(void) printf("\t\tBlocks with n*5 entries:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	(void) printf("\t\tBlocks n/10 full:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	(void) printf("\t\tEntries with n chunks:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	dump_zap_histogram(zs.zs_entries_using_n_chunks);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	(void) printf("\t\tBuckets with n entries:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	dump_zap_histogram(zs.zs_buckets_with_n_entries);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
dump_none(objset_t *os, uint64_t object, void *data, size_t size)
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
/*ARGSUSED*/
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   314
static void
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   315
dump_unknown(objset_t *os, uint64_t object, void *data, size_t size)
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   316
{
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   317
	(void) printf("\tUNKNOWN OBJECT TYPE\n");
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   318
}
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   319
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
   320
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
dump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
dump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
	zap_cursor_t zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
	zap_attribute_t attr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	void *prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
	dump_zap_stats(os, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
	for (zap_cursor_init(&zc, os, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
	    zap_cursor_retrieve(&zc, &attr) == 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
	    zap_cursor_advance(&zc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
		(void) printf("\t\t%s = ", attr.za_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
		if (attr.za_num_integers == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
			(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
		prop = umem_zalloc(attr.za_num_integers *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
		    attr.za_integer_length, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
		(void) zap_lookup(os, object, attr.za_name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
		    attr.za_integer_length, attr.za_num_integers, prop);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
		if (attr.za_integer_length == 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
			(void) printf("%s", (char *)prop);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
			for (i = 0; i < attr.za_num_integers; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
				switch (attr.za_integer_length) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
				case 2:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
					(void) printf("%u ",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
					    ((uint16_t *)prop)[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
				case 4:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
					(void) printf("%u ",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
					    ((uint32_t *)prop)[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
				case 8:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
					(void) printf("%lld ",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
					    (u_longlong_t)((int64_t *)prop)[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	}
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 789
diff changeset
   379
	zap_cursor_fini(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   382
/*ARGSUSED*/
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   383
static void
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   384
dump_ddt_zap(objset_t *os, uint64_t object, void *data, size_t size)
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   385
{
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   386
	dump_zap_stats(os, object);
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   387
	/* contents are printed elsewhere, properly decoded */
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   388
}
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   389
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   390
/*ARGSUSED*/
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
   391
static void
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   392
dump_sa_attrs(objset_t *os, uint64_t object, void *data, size_t size)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   393
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   394
	zap_cursor_t zc;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   395
	zap_attribute_t attr;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   396
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   397
	dump_zap_stats(os, object);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   398
	(void) printf("\n");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   399
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   400
	for (zap_cursor_init(&zc, os, object);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   401
	    zap_cursor_retrieve(&zc, &attr) == 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   402
	    zap_cursor_advance(&zc)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   403
		(void) printf("\t\t%s = ", attr.za_name);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   404
		if (attr.za_num_integers == 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   405
			(void) printf("\n");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   406
			continue;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   407
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   408
		(void) printf(" %llx : [%d:%d:%d]\n",
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   409
		    (u_longlong_t)attr.za_first_integer,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   410
		    (int)ATTR_LENGTH(attr.za_first_integer),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   411
		    (int)ATTR_BSWAP(attr.za_first_integer),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   412
		    (int)ATTR_NUM(attr.za_first_integer));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   413
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   414
	zap_cursor_fini(&zc);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   415
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   416
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   417
/*ARGSUSED*/
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   418
static void
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   419
dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   420
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   421
	zap_cursor_t zc;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   422
	zap_attribute_t attr;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   423
	uint16_t *layout_attrs;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   424
	int i;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   425
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   426
	dump_zap_stats(os, object);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   427
	(void) printf("\n");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   428
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   429
	for (zap_cursor_init(&zc, os, object);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   430
	    zap_cursor_retrieve(&zc, &attr) == 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   431
	    zap_cursor_advance(&zc)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   432
		(void) printf("\t\t%s = [", attr.za_name);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   433
		if (attr.za_num_integers == 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   434
			(void) printf("\n");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   435
			continue;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   436
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   437
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   438
		VERIFY(attr.za_integer_length == 2);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   439
		layout_attrs = umem_zalloc(attr.za_num_integers *
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   440
		    attr.za_integer_length, UMEM_NOFAIL);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   441
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   442
		VERIFY(zap_lookup(os, object, attr.za_name,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   443
		    attr.za_integer_length,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   444
		    attr.za_num_integers, layout_attrs) == 0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   445
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   446
		for (i = 0; i != attr.za_num_integers; i++)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   447
			(void) printf(" %d ", (int)layout_attrs[i]);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   448
		(void) printf("]\n");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   449
		umem_free(layout_attrs,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   450
		    attr.za_num_integers * attr.za_integer_length);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   451
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   452
	zap_cursor_fini(&zc);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   453
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   454
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   455
/*ARGSUSED*/
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
   456
static void
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   457
dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   458
{
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   459
	zap_cursor_t zc;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   460
	zap_attribute_t attr;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   461
	const char *typenames[] = {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   462
		/* 0 */ "not specified",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   463
		/* 1 */ "FIFO",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   464
		/* 2 */ "Character Device",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   465
		/* 3 */ "3 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   466
		/* 4 */ "Directory",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   467
		/* 5 */ "5 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   468
		/* 6 */ "Block Device",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   469
		/* 7 */ "7 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   470
		/* 8 */ "Regular File",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   471
		/* 9 */ "9 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   472
		/* 10 */ "Symbolic Link",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   473
		/* 11 */ "11 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   474
		/* 12 */ "Socket",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   475
		/* 13 */ "Door",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   476
		/* 14 */ "Event Port",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   477
		/* 15 */ "15 (invalid)",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   478
	};
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   479
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   480
	dump_zap_stats(os, object);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   481
	(void) printf("\n");
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   482
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   483
	for (zap_cursor_init(&zc, os, object);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   484
	    zap_cursor_retrieve(&zc, &attr) == 0;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   485
	    zap_cursor_advance(&zc)) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   486
		(void) printf("\t\t%s = %lld (type: %s)\n",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   487
		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   488
		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   489
	}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   490
	zap_cursor_fini(&zc);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   491
}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   492
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
dump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
	uint64_t alloc, offset, entry;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   497
	uint8_t mapshift = sm->sm_shift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
	uint64_t mapstart = sm->sm_start;
3361
a3d194896a76 6480230 ::walk spa|::walk zms_freelist cause mdb to core dump
ck153898
parents: 3060
diff changeset
   499
	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
a3d194896a76 6480230 ::walk spa|::walk zms_freelist cause mdb to core dump
ck153898
parents: 3060
diff changeset
   500
			    "INVALID", "INVALID", "INVALID", "INVALID" };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	if (smo->smo_object == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
	 * Print out the freelist entries in both encoded and decoded form.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	alloc = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   510
		VERIFY3U(0, ==, dmu_read(os, smo->smo_object, offset,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
   511
		    sizeof (entry), &entry, DMU_READ_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
		if (SM_DEBUG_DECODE(entry)) {
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   513
			(void) printf("\t    [%6llu] %s: txg %llu, pass %llu\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
			    (u_longlong_t)(offset / sizeof (entry)),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   516
			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   517
			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
		} else {
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   519
			(void) printf("\t    [%6llu]    %c  range:"
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   520
			    " %010llx-%010llx  size: %06llx\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
			    (u_longlong_t)(offset / sizeof (entry)),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   523
			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   524
			    mapshift) + mapstart),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   525
			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   526
			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   527
			    mapshift)),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
   528
			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
				alloc += SM_RUN_DECODE(entry) << mapshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
				alloc -= SM_RUN_DECODE(entry) << mapshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
	if (alloc != smo->smo_alloc) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
		    "with space map summary (%llu)\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
static void
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   543
dump_metaslab_stats(metaslab_t *msp)
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   544
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   545
	char maxbuf[32];
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   546
	space_map_t *sm = &msp->ms_map;
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   547
	avl_tree_t *t = sm->sm_pp_root;
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   548
	int free_pct = sm->sm_space * 100 / sm->sm_size;
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   549
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   550
	zdb_nicenum(space_map_maxsize(sm), maxbuf);
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   551
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   552
	(void) printf("\t %25s %10lu   %7s  %6s   %4s %4d%%\n",
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   553
	    "segments", avl_numnodes(t), "maxsize", maxbuf,
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   554
	    "freepct", free_pct);
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   555
}
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   556
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   557
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
dump_metaslab(metaslab_t *msp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
	vdev_t *vd = msp->ms_group->mg_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
	spa_t *spa = vd->vdev_spa;
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   562
	space_map_t *sm = &msp->ms_map;
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   563
	space_map_obj_t *smo = &msp->ms_smo;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   564
	char freebuf[32];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   565
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   566
	zdb_nicenum(sm->sm_size - smo->smo_alloc, freebuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
	(void) printf(
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   569
	    "\tmetaslab %6llu   offset %12llx   spacemap %6llu   free    %5s\n",
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   570
	    (u_longlong_t)(sm->sm_start / sm->sm_size),
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   571
	    (u_longlong_t)sm->sm_start, (u_longlong_t)smo->smo_object, freebuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   573
	if (dump_opt['m'] > 1 && !dump_opt['L']) {
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   574
		mutex_enter(&msp->ms_lock);
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   575
		space_map_load_wait(sm);
11728
59fdb3b856f6 6918420 zdb -m has issues printing metaslab statistics
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11727
diff changeset
   576
		if (!sm->sm_loaded)
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   577
			VERIFY(space_map_load(sm, zfs_metaslab_ops,
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   578
			    SM_FREE, smo, spa->spa_meta_objset) == 0);
11728
59fdb3b856f6 6918420 zdb -m has issues printing metaslab statistics
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11727
diff changeset
   579
		dump_metaslab_stats(msp);
59fdb3b856f6 6918420 zdb -m has issues printing metaslab statistics
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11727
diff changeset
   580
		space_map_unload(sm);
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   581
		mutex_exit(&msp->ms_lock);
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   582
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   584
	if (dump_opt['d'] > 5 || dump_opt['m'] > 2) {
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   585
		ASSERT(sm->sm_size == (1ULL << vd->vdev_ms_shift));
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   586
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   587
		mutex_enter(&msp->ms_lock);
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
   588
		dump_spacemap(spa->spa_meta_objset, smo, sm);
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   589
		mutex_exit(&msp->ms_lock);
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   590
	}
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   591
}
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
   592
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   593
static void
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   594
print_vdev_metaslab_header(vdev_t *vd)
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   595
{
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   596
	(void) printf("\tvdev %10llu\n\t%-10s%5llu   %-19s   %-15s   %-10s\n",
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   597
	    (u_longlong_t)vd->vdev_id,
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   598
	    "metaslabs", (u_longlong_t)vd->vdev_ms_count,
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   599
	    "offset", "spacemap", "free");
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   600
	(void) printf("\t%15s   %19s   %15s   %10s\n",
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   601
	    "---------------", "-------------------",
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   602
	    "---------------", "-------------");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
dump_metaslabs(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
{
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   608
	vdev_t *vd, *rvd = spa->spa_root_vdev;
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   609
	uint64_t m, c = 0, children = rvd->vdev_children;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	(void) printf("\nMetaslabs:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   613
	if (!dump_opt['d'] && zopt_objects > 0) {
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   614
		c = zopt_object[0];
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   615
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   616
		if (c >= children)
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   617
			(void) fatal("bad vdev id: %llu", (u_longlong_t)c);
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   618
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   619
		if (zopt_objects > 1) {
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   620
			vd = rvd->vdev_child[c];
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   621
			print_vdev_metaslab_header(vd);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   623
			for (m = 1; m < zopt_objects; m++) {
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   624
				if (zopt_object[m] < vd->vdev_ms_count)
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   625
					dump_metaslab(
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   626
					    vd->vdev_ms[zopt_object[m]]);
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   627
				else
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   628
					(void) fprintf(stderr, "bad metaslab "
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   629
					    "number %llu\n",
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   630
					    (u_longlong_t)zopt_object[m]);
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   631
			}
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   632
			(void) printf("\n");
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   633
			return;
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   634
		}
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   635
		children = c + 1;
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   636
	}
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   637
	for (; c < children; c++) {
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   638
		vd = rvd->vdev_child[c];
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
   639
		print_vdev_metaslab_header(vd);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
		for (m = 0; m < vd->vdev_ms_count; m++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
			dump_metaslab(vd->vdev_ms[m]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   648
dump_dde(const ddt_t *ddt, const ddt_entry_t *dde, uint64_t index)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   649
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   650
	const ddt_phys_t *ddp = dde->dde_phys;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   651
	const ddt_key_t *ddk = &dde->dde_key;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   652
	char *types[4] = { "ditto", "single", "double", "triple" };
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   653
	char blkbuf[BP_SPRINTF_LEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   654
	blkptr_t blk;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   655
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   656
	for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   657
		if (ddp->ddp_phys_birth == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   658
			continue;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
   659
		ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   660
		sprintf_blkptr(blkbuf, &blk);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   661
		(void) printf("index %llx refcnt %llu %s %s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   662
		    (u_longlong_t)index, (u_longlong_t)ddp->ddp_refcnt,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   663
		    types[p], blkbuf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   664
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   665
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   666
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   667
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   668
dump_dedup_ratio(const ddt_stat_t *dds)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   669
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   670
	double rL, rP, rD, D, dedup, compress, copies;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   671
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   672
	if (dds->dds_blocks == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   673
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   674
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   675
	rL = (double)dds->dds_ref_lsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   676
	rP = (double)dds->dds_ref_psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   677
	rD = (double)dds->dds_ref_dsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   678
	D = (double)dds->dds_dsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   679
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   680
	dedup = rD / D;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   681
	compress = rL / rP;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   682
	copies = rD / rP;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   683
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   684
	(void) printf("dedup = %.2f, compress = %.2f, copies = %.2f, "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   685
	    "dedup * compress / copies = %.2f\n\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   686
	    dedup, compress, copies, dedup * compress / copies);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   687
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   688
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   689
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   690
dump_ddt(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   691
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   692
	char name[DDT_NAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   693
	ddt_entry_t dde;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   694
	uint64_t walk = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   695
	dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   696
	uint64_t count, dspace, mspace;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   697
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   698
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   699
	error = ddt_object_info(ddt, type, class, &doi);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   700
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   701
	if (error == ENOENT)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   702
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   703
	ASSERT(error == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   704
12671
2fee57289adb 6959651 assertion failed: ddo_total->ddo_dspace == 0, file: ../../common/fs/zfs/ddt.c, line: 460
George Wilson <George.Wilson@Sun.COM>
parents: 12493
diff changeset
   705
	if ((count = ddt_object_count(ddt, type, class)) == 0)
2fee57289adb 6959651 assertion failed: ddo_total->ddo_dspace == 0, file: ../../common/fs/zfs/ddt.c, line: 460
George Wilson <George.Wilson@Sun.COM>
parents: 12493
diff changeset
   706
		return;
2fee57289adb 6959651 assertion failed: ddo_total->ddo_dspace == 0, file: ../../common/fs/zfs/ddt.c, line: 460
George Wilson <George.Wilson@Sun.COM>
parents: 12493
diff changeset
   707
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   708
	dspace = doi.doi_physical_blocks_512 << 9;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   709
	mspace = doi.doi_fill_count * doi.doi_data_block_size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   710
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   711
	ddt_object_name(ddt, type, class, name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   712
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   713
	(void) printf("%s: %llu entries, size %llu on disk, %llu in core\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   714
	    name,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   715
	    (u_longlong_t)count,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   716
	    (u_longlong_t)(dspace / count),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   717
	    (u_longlong_t)(mspace / count));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   718
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   719
	if (dump_opt['D'] < 3)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   720
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   721
11149
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 11146
diff changeset
   722
	zpool_dump_ddt(NULL, &ddt->ddt_histogram[type][class]);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   723
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   724
	if (dump_opt['D'] < 4)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   725
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   726
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   727
	if (dump_opt['D'] < 5 && class == DDT_CLASS_UNIQUE)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   728
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   729
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   730
	(void) printf("%s contents:\n\n", name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   731
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
   732
	while ((error = ddt_object_walk(ddt, type, class, &walk, &dde)) == 0)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   733
		dump_dde(ddt, &dde, walk);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   734
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   735
	ASSERT(error == ENOENT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   736
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   737
	(void) printf("\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   738
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   739
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   740
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   741
dump_all_ddts(spa_t *spa)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   742
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   743
	ddt_histogram_t ddh_total = { 0 };
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   744
	ddt_stat_t dds_total = { 0 };
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   745
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   746
	for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   747
		ddt_t *ddt = spa->spa_ddt[c];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   748
		for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   749
			for (enum ddt_class class = 0; class < DDT_CLASSES;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   750
			    class++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   751
				dump_ddt(ddt, type, class);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   752
			}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   753
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   754
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   755
11149
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 11146
diff changeset
   756
	ddt_get_dedup_stats(spa, &dds_total);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   757
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   758
	if (dds_total.dds_blocks == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   759
		(void) printf("All DDTs are empty\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   760
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   761
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   762
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   763
	(void) printf("\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   764
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   765
	if (dump_opt['D'] > 1) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   766
		(void) printf("DDT histogram (aggregated over all DDTs):\n");
11149
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 11146
diff changeset
   767
		ddt_get_dedup_histogram(spa, &ddh_total);
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 11146
diff changeset
   768
		zpool_dump_ddt(&dds_total, &ddh_total);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   769
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   770
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   771
	dump_dedup_ratio(&dds_total);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   772
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   773
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   774
static void
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   775
dump_dtl_seg(space_map_t *sm, uint64_t start, uint64_t size)
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   776
{
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   777
	char *prefix = (void *)sm;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   778
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   779
	(void) printf("%s [%llu,%llu) length %llu\n",
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   780
	    prefix,
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   781
	    (u_longlong_t)start,
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   782
	    (u_longlong_t)(start + size),
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   783
	    (u_longlong_t)(size));
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   784
}
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   785
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   786
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
dump_dtl(vdev_t *vd, int indent)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
{
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   789
	spa_t *spa = vd->vdev_spa;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   790
	boolean_t required;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   791
	char *name[DTL_TYPES] = { "missing", "partial", "scrub", "outage" };
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   792
	char prefix[256];
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   793
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   794
	spa_vdev_state_enter(spa, SCL_NONE);
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   795
	required = vdev_dtl_required(vd);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   796
	(void) spa_vdev_state_exit(spa, NULL, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	if (indent == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
		(void) printf("\nDirty time logs:\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   801
	(void) printf("\t%*s%s [%s]\n", indent, "",
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
   802
	    vd->vdev_path ? vd->vdev_path :
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   803
	    vd->vdev_parent ? vd->vdev_ops->vdev_op_type : spa_name(spa),
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   804
	    required ? "DTL-required" : "DTL-expendable");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   806
	for (int t = 0; t < DTL_TYPES; t++) {
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   807
		space_map_t *sm = &vd->vdev_dtl[t];
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   808
		if (sm->sm_space == 0)
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   809
			continue;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   810
		(void) snprintf(prefix, sizeof (prefix), "\t%*s%s",
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   811
		    indent + 2, "", name[t]);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   812
		mutex_enter(sm->sm_lock);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   813
		space_map_walk(sm, dump_dtl_seg, (void *)prefix);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   814
		mutex_exit(sm->sm_lock);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   815
		if (dump_opt['d'] > 5 && vd->vdev_children == 0)
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   816
			dump_spacemap(spa->spa_meta_objset,
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   817
			    &vd->vdev_dtl_smo, sm);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
   820
	for (int c = 0; c < vd->vdev_children; c++)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
		dump_dtl(vd->vdev_child[c], indent + 4);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   824
static void
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   825
dump_history(spa_t *spa)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   826
{
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   827
	nvlist_t **events = NULL;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   828
	char buf[SPA_MAXBLOCKSIZE];
10857
2c20a0bd87cd 6892882 zdb -ddddd prints garbage from stack between dataset summary and rootbp
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10685
diff changeset
   829
	uint64_t resid, len, off = 0;
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   830
	uint_t num = 0;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   831
	int error;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   832
	time_t tsec;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   833
	struct tm t;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   834
	char tbuf[30];
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   835
	char internalstr[MAXPATHLEN];
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   836
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   837
	do {
10857
2c20a0bd87cd 6892882 zdb -ddddd prints garbage from stack between dataset summary and rootbp
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10685
diff changeset
   838
		len = sizeof (buf);
2c20a0bd87cd 6892882 zdb -ddddd prints garbage from stack between dataset summary and rootbp
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10685
diff changeset
   839
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   840
		if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   841
			(void) fprintf(stderr, "Unable to read history: "
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   842
			    "error %d\n", error);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   843
			return;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   844
		}
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   845
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   846
		if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   847
			break;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   848
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   849
		off -= resid;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   850
	} while (len != 0);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   851
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   852
	(void) printf("\nHistory:\n");
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   853
	for (int i = 0; i < num; i++) {
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   854
		uint64_t time, txg, ievent;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   855
		char *cmd, *intstr;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   856
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   857
		if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   858
		    &time) != 0)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   859
			continue;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   860
		if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   861
		    &cmd) != 0) {
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   862
			if (nvlist_lookup_uint64(events[i],
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   863
			    ZPOOL_HIST_INT_EVENT, &ievent) != 0)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   864
				continue;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   865
			verify(nvlist_lookup_uint64(events[i],
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   866
			    ZPOOL_HIST_TXG, &txg) == 0);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   867
			verify(nvlist_lookup_string(events[i],
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   868
			    ZPOOL_HIST_INT_STR, &intstr) == 0);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   869
			if (ievent >= LOG_END)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   870
				continue;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   871
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   872
			(void) snprintf(internalstr,
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   873
			    sizeof (internalstr),
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   874
			    "[internal %s txg:%lld] %s",
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   875
			    zfs_history_event_names[ievent], txg,
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   876
			    intstr);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   877
			cmd = internalstr;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   878
		}
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   879
		tsec = time;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   880
		(void) localtime_r(&tsec, &t);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   881
		(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   882
		(void) printf("%s %s\n", tbuf, cmd);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   883
	}
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   884
}
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
   885
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
dump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
static uint64_t
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   893
blkid2offset(const dnode_phys_t *dnp, const blkptr_t *bp, const zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   895
	if (dnp == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   896
		ASSERT(zb->zb_level < 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   897
		if (zb->zb_object == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   898
			return (zb->zb_blkid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   899
		return (zb->zb_blkid * BP_GET_LSIZE(bp));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   900
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   901
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   902
	ASSERT(zb->zb_level >= 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   903
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   904
	return ((zb->zb_blkid <<
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   905
	    (zb->zb_level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   909
static void
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   910
sprintf_blkptr_compact(char *blkbuf, const blkptr_t *bp)
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   911
{
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   912
	const dva_t *dva = bp->blk_dva;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   913
	int ndvas = dump_opt['d'] > 5 ? BP_GET_NDVAS(bp) : 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   914
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   915
	if (dump_opt['b'] >= 5) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   916
		sprintf_blkptr(blkbuf, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   917
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   918
	}
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   919
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   920
	blkbuf[0] = '\0';
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   921
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   922
	for (int i = 0; i < ndvas; i++)
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   923
		(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
   924
		    (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
   925
		    (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
   926
		    (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
   927
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   928
	(void) sprintf(blkbuf + strlen(blkbuf),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   929
	    "%llxL/%llxP F=%llu B=%llu/%llu",
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   930
	    (u_longlong_t)BP_GET_LSIZE(bp),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   931
	    (u_longlong_t)BP_GET_PSIZE(bp),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   932
	    (u_longlong_t)bp->blk_fill,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   933
	    (u_longlong_t)bp->blk_birth,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   934
	    (u_longlong_t)BP_PHYSICAL_BIRTH(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   935
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   936
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   937
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
   938
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
   939
    const dnode_phys_t *dnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
{
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   941
	char blkbuf[BP_SPRINTF_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
	int l;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   944
	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
   945
	ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   947
	(void) printf("%16llx ", (u_longlong_t)blkid2offset(dnp, bp, zb));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
	ASSERT(zb->zb_level >= 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
		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
   953
			(void) printf("L%llx", (u_longlong_t)zb->zb_level);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
		} 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
   955
			(void) printf(" ");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   959
	sprintf_blkptr_compact(blkbuf, bp);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   960
	(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
   961
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   962
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   963
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
   964
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
   965
    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
   966
{
10857
2c20a0bd87cd 6892882 zdb -ddddd prints garbage from stack between dataset summary and rootbp
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10685
diff changeset
   967
	int err = 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
   968
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   969
	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
   970
		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
   971
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   972
	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
   973
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   974
	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
   975
		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
   976
		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
   977
		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
   978
		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
   979
		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
   980
		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
   981
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   982
		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
   983
		    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
   984
		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
   985
			return (err);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
   986
		ASSERT(buf->b_data);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   987
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   988
		/* 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
   989
		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
   990
		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
   991
			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
   992
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   993
			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
   994
			    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
   995
			    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
   996
			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
   997
			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
   998
				break;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   999
			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
  1000
		}
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
  1001
		if (!err)
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8188
diff changeset
  1002
			ASSERT3U(fill, ==, bp->blk_fill);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1003
		(void) arc_buf_remove_ref(buf, &buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1006
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
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
  1011
dump_indirect(dnode_t *dn)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
{
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1013
	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
  1014
	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
  1015
	zbookmark_t czb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
	(void) printf("Indirect blocks:\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1019
	SET_BOOKMARK(&czb, dmu_objset_id(dn->dn_objset),
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1020
	    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
  1021
	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
  1022
		czb.zb_blkid = j;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1023
		(void) visit_indirect(dmu_objset_spa(dn->dn_objset), dnp,
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1024
		    &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
  1025
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
	dsl_dir_phys_t *dd = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
	time_t crtime;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1036
	char nice[32];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
	if (dd == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1041
	ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
	crtime = dd->dd_creation_time;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
	(void) printf("\t\thead_dataset_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
	    (u_longlong_t)dd->dd_head_dataset_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
	(void) printf("\t\tparent_dir_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	    (u_longlong_t)dd->dd_parent_obj);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1049
	(void) printf("\t\torigin_obj = %llu\n",
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1050
	    (u_longlong_t)dd->dd_origin_obj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
	(void) printf("\t\tchild_dir_zapobj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
	    (u_longlong_t)dd->dd_child_dir_zapobj);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1053
	zdb_nicenum(dd->dd_used_bytes, nice);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1054
	(void) printf("\t\tused_bytes = %s\n", nice);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1055
	zdb_nicenum(dd->dd_compressed_bytes, nice);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1056
	(void) printf("\t\tcompressed_bytes = %s\n", nice);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1057
	zdb_nicenum(dd->dd_uncompressed_bytes, nice);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1058
	(void) printf("\t\tuncompressed_bytes = %s\n", nice);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1059
	zdb_nicenum(dd->dd_quota, nice);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1060
	(void) printf("\t\tquota = %s\n", nice);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1061
	zdb_nicenum(dd->dd_reserved, nice);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1062
	(void) printf("\t\treserved = %s\n", nice);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
	(void) printf("\t\tprops_zapobj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
	    (u_longlong_t)dd->dd_props_zapobj);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1065
	(void) printf("\t\tdeleg_zapobj = %llu\n",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1066
	    (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
  1067
	(void) printf("\t\tflags = %llx\n",
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1068
	    (u_longlong_t)dd->dd_flags);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1069
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1070
#define	DO(which) \
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1071
	zdb_nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice); \
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1072
	(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
  1073
	DO(HEAD);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1074
	DO(SNAP);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1075
	DO(CHILD);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1076
	DO(CHILD_RSRV);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1077
	DO(REFRSRV);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1078
#undef DO
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
dump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
	dsl_dataset_phys_t *ds = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
	time_t crtime;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1087
	char used[32], compressed[32], uncompressed[32], unique[32];
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1088
	char blkbuf[BP_SPRINTF_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	if (ds == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
	ASSERT(size == sizeof (*ds));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
	crtime = ds->ds_creation_time;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1095
	zdb_nicenum(ds->ds_referenced_bytes, used);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1096
	zdb_nicenum(ds->ds_compressed_bytes, compressed);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1097
	zdb_nicenum(ds->ds_uncompressed_bytes, uncompressed);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1098
	zdb_nicenum(ds->ds_unique_bytes, unique);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1099
	sprintf_blkptr(blkbuf, &ds->ds_bp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1101
	(void) printf("\t\tdir_obj = %llu\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
	    (u_longlong_t)ds->ds_dir_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
	(void) printf("\t\tprev_snap_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
	    (u_longlong_t)ds->ds_prev_snap_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
	(void) printf("\t\tprev_snap_txg = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
	    (u_longlong_t)ds->ds_prev_snap_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
	(void) printf("\t\tnext_snap_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
	    (u_longlong_t)ds->ds_next_snap_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
	(void) printf("\t\tsnapnames_zapobj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
	    (u_longlong_t)ds->ds_snapnames_zapobj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
	(void) printf("\t\tnum_children = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
	    (u_longlong_t)ds->ds_num_children);
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 9512
diff changeset
  1113
	(void) printf("\t\tuserrefs_obj = %llu\n",
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 9512
diff changeset
  1114
	    (u_longlong_t)ds->ds_userrefs_obj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
	(void) printf("\t\tcreation_txg = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
	    (u_longlong_t)ds->ds_creation_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
	(void) printf("\t\tdeadlist_obj = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
	    (u_longlong_t)ds->ds_deadlist_obj);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
	(void) printf("\t\tused_bytes = %s\n", used);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
	(void) printf("\t\tunique = %s\n", unique);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
	(void) printf("\t\tfsid_guid = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
	    (u_longlong_t)ds->ds_fsid_guid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1126
	(void) printf("\t\tguid = %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1127
	    (u_longlong_t)ds->ds_guid);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
  1128
	(void) printf("\t\tflags = %llx\n",
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
  1129
	    (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
  1130
	(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
  1131
	    (u_longlong_t)ds->ds_next_clones_obj);
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7046
diff changeset
  1132
	(void) printf("\t\tprops_obj = %llu\n",
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7046
diff changeset
  1133
	    (u_longlong_t)ds->ds_props_obj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
	(void) printf("\t\tbp = %s\n", blkbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1137
/* ARGSUSED */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1138
static int
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1139
dump_bptree_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1140
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1141
	char blkbuf[BP_SPRINTF_LEN];
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1142
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1143
	if (bp->blk_birth != 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1144
		sprintf_blkptr(blkbuf, bp);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1145
		(void) printf("\t%s\n", blkbuf);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1146
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1147
	return (0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1148
}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1149
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1150
static void
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1151
dump_bptree(objset_t *os, uint64_t obj, char *name)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1152
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1153
	char bytes[32];
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1154
	bptree_phys_t *bt;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1155
	dmu_buf_t *db;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1156
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1157
	if (dump_opt['d'] < 3)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1158
		return;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1159
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1160
	VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1161
	bt = db->db_data;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1162
	zdb_nicenum(bt->bt_bytes, bytes);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1163
	(void) printf("\n    %s: %llu datasets, %s\n",
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1164
	    name, (unsigned long long)(bt->bt_end - bt->bt_begin), bytes);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1165
	dmu_buf_rele(db, FTAG);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1166
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1167
	if (dump_opt['d'] < 5)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1168
		return;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1169
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1170
	(void) printf("\n");
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1171
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1172
	(void) bptree_iterate(os, obj, B_FALSE, dump_bptree_cb, NULL, NULL);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1173
}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1174
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1175
/* ARGSUSED */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1176
static int
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1177
dump_bpobj_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
{
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1179
	char blkbuf[BP_SPRINTF_LEN];
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1180
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1181
	ASSERT(bp->blk_birth != 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1182
	sprintf_blkptr_compact(blkbuf, bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1183
	(void) printf("\t%s\n", blkbuf);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1184
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1185
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1186
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1187
static void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1188
dump_bpobj(bpobj_t *bpo, char *name)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1189
{
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1190
	char bytes[32];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1191
	char comp[32];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1192
	char uncomp[32];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
	if (dump_opt['d'] < 3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1197
	zdb_nicenum(bpo->bpo_phys->bpo_bytes, bytes);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1198
	if (bpo->bpo_havesubobj) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1199
		zdb_nicenum(bpo->bpo_phys->bpo_comp, comp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1200
		zdb_nicenum(bpo->bpo_phys->bpo_uncomp, uncomp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1201
		(void) printf("\n    %s: %llu local blkptrs, %llu subobjs, "
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1202
		    "%s (%s/%s comp)\n",
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1203
		    name, (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1204
		    (u_longlong_t)bpo->bpo_phys->bpo_num_subobjs,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
  1205
		    bytes, comp, uncomp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
  1206
	} else {
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1207
		(void) printf("\n    %s: %llu blkptrs, %s\n",
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1208
		    name, (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs, bytes);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
  1209
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1211
	if (dump_opt['d'] < 5)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1216
	(void) bpobj_iterate_nofree(bpo, dump_bpobj_cb, NULL, NULL);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1217
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1218
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1219
static void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1220
dump_deadlist(dsl_deadlist_t *dl)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1221
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1222
	dsl_deadlist_entry_t *dle;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1223
	char bytes[32];
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1224
	char comp[32];
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1225
	char uncomp[32];
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1226
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1227
	if (dump_opt['d'] < 3)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1228
		return;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1229
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1230
	zdb_nicenum(dl->dl_phys->dl_used, bytes);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1231
	zdb_nicenum(dl->dl_phys->dl_comp, comp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1232
	zdb_nicenum(dl->dl_phys->dl_uncomp, uncomp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1233
	(void) printf("\n    Deadlist: %s (%s/%s comp)\n",
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1234
	    bytes, comp, uncomp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1235
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1236
	if (dump_opt['d'] < 4)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1237
		return;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1238
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1239
	(void) printf("\n");
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1240
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1241
	for (dle = avl_first(&dl->dl_tree); dle;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1242
	    dle = AVL_NEXT(&dl->dl_tree, dle)) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1243
		(void) printf("      mintxg %llu -> obj %llu\n",
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1244
		    (longlong_t)dle->dle_mintxg,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1245
		    (longlong_t)dle->dle_bpobj.bpo_object);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1246
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1247
		if (dump_opt['d'] >= 5)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1248
			dump_bpobj(&dle->dle_bpobj, "");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1252
static avl_tree_t idx_tree;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1253
static avl_tree_t domain_tree;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1254
static boolean_t fuid_table_loaded;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1255
static boolean_t sa_loaded;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1256
sa_attr_type_t *sa_attr_table;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1257
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1258
static void
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1259
fuid_table_destroy()
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1260
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1261
	if (fuid_table_loaded) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1262
		zfs_fuid_table_destroy(&idx_tree, &domain_tree);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1263
		fuid_table_loaded = B_FALSE;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1264
	}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1265
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1266
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1267
/*
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1268
 * print uid or gid information.
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1269
 * 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
  1270
 * 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
  1271
 * the doman-rid string.
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1272
 */
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1273
static void
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1274
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
  1275
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1276
	if (FUID_INDEX(id)) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1277
		char *domain;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1278
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1279
		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
  1280
		(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
  1281
		    (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
  1282
	} else {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1283
		(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
  1284
	}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1285
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1286
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1287
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1288
static void
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1289
dump_uidgid(objset_t *os, uint64_t uid, uint64_t gid)
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1290
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1291
	uint32_t uid_idx, gid_idx;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1292
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1293
	uid_idx = FUID_INDEX(uid);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1294
	gid_idx = FUID_INDEX(gid);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1295
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1296
	/* Load domain table, if not already loaded */
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1297
	if (!fuid_table_loaded && (uid_idx || gid_idx)) {
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1298
		uint64_t fuid_obj;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1299
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1300
		/* 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
  1301
		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
  1302
		    8, 1, &fuid_obj) == 0);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8924
diff changeset
  1303
		zfs_fuid_avl_tree_create(&idx_tree, &domain_tree);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1304
		(void) zfs_fuid_table_load(os, fuid_obj,
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1305
		    &idx_tree, &domain_tree);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1306
		fuid_table_loaded = B_TRUE;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1307
	}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1308
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1309
	print_idstr(uid, "uid");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1310
	print_idstr(gid, "gid");
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1311
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1312
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
dump_znode(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
{
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1317
	char path[MAXPATHLEN * 2];	/* allow for xattr and failure prefix */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1318
	sa_handle_t *hdl;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1319
	uint64_t xattr, rdev, gen;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1320
	uint64_t uid, gid, mode, fsize, parent, links;
12050
5879aa161e65 6938757 SMB and NFS referrals not working correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1321
	uint64_t pflags;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1322
	uint64_t acctm[2], modtm[2], chgtm[2], crtm[2];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
	time_t z_crtime, z_atime, z_mtime, z_ctime;
12050
5879aa161e65 6938757 SMB and NFS referrals not working correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1324
	sa_bulk_attr_t bulk[12];
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1325
	int idx = 0;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1326
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1328
	if (!sa_loaded) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1329
		uint64_t sa_attrs = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1330
		uint64_t version;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1331
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1332
		VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1333
		    8, 1, &version) == 0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1334
		if (version >= ZPL_VERSION_SA) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1335
			VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZFS_SA_ATTRS,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1336
			    8, 1, &sa_attrs) == 0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1337
		}
12493
89ce40422cea 6952177 SA handling of on-disk corruption can be improved
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12470
diff changeset
  1338
		if ((error = sa_setup(os, sa_attrs, zfs_attr_table,
89ce40422cea 6952177 SA handling of on-disk corruption can be improved
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12470
diff changeset
  1339
		    ZPL_END, &sa_attr_table)) != 0) {
89ce40422cea 6952177 SA handling of on-disk corruption can be improved
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12470
diff changeset
  1340
			(void) printf("sa_setup failed errno %d, can't "
89ce40422cea 6952177 SA handling of on-disk corruption can be improved
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12470
diff changeset
  1341
			    "display znode contents\n", error);
89ce40422cea 6952177 SA handling of on-disk corruption can be improved
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12470
diff changeset
  1342
			return;
89ce40422cea 6952177 SA handling of on-disk corruption can be improved
Mark Shellenbaum <Mark.Shellenbaum@Oracle.COM>
parents: 12470
diff changeset
  1343
		}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1344
		sa_loaded = B_TRUE;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1345
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1346
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1347
	if (sa_handle_get(os, object, NULL, SA_HDL_PRIVATE, &hdl)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1348
		(void) printf("Failed to get handle for SA znode\n");
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1349
		return;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1350
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1351
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1352
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_UID], NULL, &uid, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1353
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_GID], NULL, &gid, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1354
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_LINKS], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1355
	    &links, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1356
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_GEN], NULL, &gen, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1357
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_MODE], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1358
	    &mode, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1359
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_PARENT],
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1360
	    NULL, &parent, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1361
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_SIZE], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1362
	    &fsize, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1363
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_ATIME], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1364
	    acctm, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1365
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_MTIME], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1366
	    modtm, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1367
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_CRTIME], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1368
	    crtm, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1369
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_CTIME], NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1370
	    chgtm, 16);
12050
5879aa161e65 6938757 SMB and NFS referrals not working correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1371
	SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_FLAGS], NULL,
5879aa161e65 6938757 SMB and NFS referrals not working correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1372
	    &pflags, 8);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1373
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1374
	if (sa_bulk_lookup(hdl, bulk, idx)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1375
		(void) sa_handle_destroy(hdl);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1376
		return;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1377
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1379
	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
  1380
	if (error != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1381
		(void) snprintf(path, sizeof (path), "\?\?\?<object#%llu>",
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1382
		    (u_longlong_t)object);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1383
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
	if (dump_opt['d'] < 3) {
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1385
		(void) printf("\t%s\n", path);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1386
		(void) sa_handle_destroy(hdl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1390
	z_crtime = (time_t)crtm[0];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1391
	z_atime = (time_t)acctm[0];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1392
	z_mtime = (time_t)modtm[0];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1393
	z_ctime = (time_t)chgtm[0];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3361
diff changeset
  1395
	(void) printf("\tpath	%s\n", path);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1396
	dump_uidgid(os, uid, gid);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
	(void) printf("\tatime	%s", ctime(&z_atime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
	(void) printf("\tmtime	%s", ctime(&z_mtime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
	(void) printf("\tctime	%s", ctime(&z_ctime));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
	(void) printf("\tcrtime	%s", ctime(&z_crtime));
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1401
	(void) printf("\tgen	%llu\n", (u_longlong_t)gen);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1402
	(void) printf("\tmode	%llo\n", (u_longlong_t)mode);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1403
	(void) printf("\tsize	%llu\n", (u_longlong_t)fsize);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1404
	(void) printf("\tparent	%llu\n", (u_longlong_t)parent);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1405
	(void) printf("\tlinks	%llu\n", (u_longlong_t)links);
12050
5879aa161e65 6938757 SMB and NFS referrals not working correctly
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  1406
	(void) printf("\tpflags	%llx\n", (u_longlong_t)pflags);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1407
	if (sa_lookup(hdl, sa_attr_table[ZPL_XATTR], &xattr,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1408
	    sizeof (uint64_t)) == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1409
		(void) printf("\txattr	%llu\n", (u_longlong_t)xattr);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1410
	if (sa_lookup(hdl, sa_attr_table[ZPL_RDEV], &rdev,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1411
	    sizeof (uint64_t)) == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1412
		(void) printf("\trdev	0x%016llx\n", (u_longlong_t)rdev);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1413
	sa_handle_destroy(hdl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
dump_acl(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
dump_dmu_objset(objset_t *os, uint64_t object, void *data, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1428
static object_viewer_t *object_viewer[DMU_OT_NUMTYPES + 1] = {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
	dump_none,		/* unallocated			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
	dump_zap,		/* object directory		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
	dump_uint64,		/* object array			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
	dump_none,		/* packed nvlist		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
	dump_packed_nvlist,	/* packed nvlist size		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
	dump_none,		/* bplist			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
	dump_none,		/* bplist header		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
	dump_none,		/* SPA space map header		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
	dump_none,		/* SPA space map		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
	dump_none,		/* ZIL intent log		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
	dump_dnode,		/* DMU dnode			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
	dump_dmu_objset,	/* DMU objset			*/
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1441
	dump_dsl_dir,		/* DSL directory		*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
	dump_zap,		/* DSL directory child map	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
	dump_zap,		/* DSL dataset snap map		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
	dump_zap,		/* DSL props			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
	dump_dsl_dataset,	/* DSL dataset			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
	dump_znode,		/* ZFS znode			*/
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1447
	dump_acl,		/* ZFS V0 ACL			*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1448
	dump_uint8,		/* ZFS plain file		*/
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1449
	dump_zpldir,		/* ZFS directory		*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1450
	dump_zap,		/* ZFS master node		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
	dump_zap,		/* ZFS delete queue		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
	dump_uint8,		/* zvol object			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
	dump_zap,		/* zvol prop			*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
	dump_uint8,		/* other uint8[]		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
	dump_uint64,		/* other uint64[]		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
	dump_zap,		/* other ZAP			*/
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1457
	dump_zap,		/* persistent error log		*/
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1458
	dump_uint8,		/* SPA history			*/
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1459
	dump_uint64,		/* SPA history offsets		*/
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3547
diff changeset
  1460
	dump_zap,		/* Pool properties		*/
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1461
	dump_zap,		/* DSL permissions		*/
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1462
	dump_acl,		/* ZFS ACL			*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1463
	dump_uint8,		/* ZFS SYSACL			*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1464
	dump_none,		/* FUID nvlist			*/
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1465
	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
  1466
	dump_zap,		/* DSL dataset next clones	*/
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1467
	dump_zap,		/* DSL scrub queue		*/
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1468
	dump_zap,		/* ZFS user/group used		*/
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1469
	dump_zap,		/* ZFS user/group quota		*/
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 9512
diff changeset
  1470
	dump_zap,		/* snapshot refcount tags	*/
11165
68184eb5449e 6903705 dedup=fletcher4,verify doesn't byteswap correctly, has lots of hash collisions
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11149
diff changeset
  1471
	dump_ddt_zap,		/* DDT ZAP object		*/
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1472
	dump_zap,		/* DDT statistics		*/
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1473
	dump_znode,		/* SA object			*/
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1474
	dump_zap,		/* SA Master Node		*/
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1475
	dump_sa_attrs,		/* SA attribute registration	*/
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1476
	dump_sa_layouts,	/* SA attribute layouts		*/
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1477
	dump_zap,		/* DSL scrub translations	*/
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1478
	dump_none,		/* fake dedup BP		*/
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1479
	dump_zap,		/* deadlist			*/
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1480
	dump_none,		/* deadlist hdr			*/
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1481
	dump_zap,		/* dsl clones			*/
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1482
	dump_none,		/* bpobj subobjs		*/
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1483
	dump_unknown,		/* Unknown type, must be last	*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
	dmu_buf_t *db = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
	dmu_object_info_t doi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
	dnode_t *dn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
	void *bonus = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
	size_t bsize = 0;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1494
	char iblk[32], dblk[32], lsize[32], asize[32], fill[32];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1495
	char bonus_size[32];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	char aux[50];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
	if (*print_header) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1500
		(void) printf("\n%10s  %3s  %5s  %5s  %5s  %5s  %6s  %s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1501
		    "Object", "lvl", "iblk", "dblk", "dsize", "lsize",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1502
		    "%full", "type");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
		*print_header = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
	if (object == 0) {
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12671
diff changeset
  1507
		dn = DMU_META_DNODE(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1509
		error = dmu_bonus_hold(os, object, FTAG, &db);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1510
		if (error)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1511
			fatal("dmu_bonus_hold(%llu) failed, errno %u",
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1512
			    object, error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
		bonus = db->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
		bsize = db->db_size;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12671
diff changeset
  1515
		dn = DB_DNODE((dmu_buf_impl_t *)db);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
	dmu_object_info_from_dnode(dn, &doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1519
	zdb_nicenum(doi.doi_metadata_block_size, iblk);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1520
	zdb_nicenum(doi.doi_data_block_size, dblk);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1521
	zdb_nicenum(doi.doi_max_offset, lsize);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1522
	zdb_nicenum(doi.doi_physical_blocks_512 << 9, asize);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1523
	zdb_nicenum(doi.doi_bonus_size, bonus_size);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1524
	(void) sprintf(fill, "%6.2f", 100.0 * doi.doi_fill_count *
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1525
	    doi.doi_data_block_size / (object == 0 ? DNODES_PER_BLOCK : 1) /
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1526
	    doi.doi_max_offset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
	aux[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1529
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1530
	if (doi.doi_checksum != ZIO_CHECKSUM_INHERIT || verbosity >= 6) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1531
		(void) snprintf(aux + strlen(aux), sizeof (aux), " (K=%s)",
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1532
		    ZDB_CHECKSUM_NAME(doi.doi_checksum));
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1533
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1534
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1535
	if (doi.doi_compress != ZIO_COMPRESS_INHERIT || verbosity >= 6) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
		(void) snprintf(aux + strlen(aux), sizeof (aux), " (Z=%s)",
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1537
		    ZDB_COMPRESS_NAME(doi.doi_compress));
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1538
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1540
	(void) printf("%10lld  %3u  %5s  %5s  %5s  %5s  %6s  %s%s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1541
	    (u_longlong_t)object, doi.doi_indirection, iblk, dblk,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1542
	    asize, lsize, fill, ZDB_OT_NAME(doi.doi_type), aux);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1544
	if (doi.doi_bonus_type != DMU_OT_NONE && verbosity > 3) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1545
		(void) printf("%10s  %3s  %5s  %5s  %5s  %5s  %6s  %s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1546
		    "", "", "", "", "", bonus_size, "bonus",
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1547
		    ZDB_OT_NAME(doi.doi_bonus_type));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1550
	if (verbosity >= 4) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1551
		(void) printf("\tdnode flags: %s%s%s\n",
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1552
		    (dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) ?
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1553
		    "USED_BYTES " : "",
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1554
		    (dn->dn_phys->dn_flags & DNODE_FLAG_USERUSED_ACCOUNTED) ?
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1555
		    "USERUSED_ACCOUNTED " : "",
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1556
		    (dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR) ?
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1557
		    "SPILL_BLKPTR" : "");
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1558
		(void) printf("\tdnode maxblkid: %llu\n",
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1559
		    (longlong_t)dn->dn_phys->dn_maxblkid);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1560
10859
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1561
		object_viewer[ZDB_OT_TYPE(doi.doi_bonus_type)](os, object,
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1562
		    bonus, bsize);
ea699e57196e 6761101 zdb/mdb crashes when printing bp with bad checksum, compress or type
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10858
diff changeset
  1563
		object_viewer[ZDB_OT_TYPE(doi.doi_type)](os, object, NULL, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
		*print_header = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
	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
  1568
		dump_indirect(dn);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
	if (verbosity >= 5) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
		 * Report the list of segments that comprise the object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
		uint64_t start = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
		uint64_t end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1576
		uint64_t blkfill = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
		int minlvl = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
		if (dn->dn_type == DMU_OT_DNODE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
			minlvl = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
			blkfill = DNODES_PER_BLOCK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
		for (;;) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1585
			char segsize[32];
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1586
			error = dnode_next_offset(dn,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1587
			    0, &start, minlvl, blkfill, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
			if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
			end = start;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1591
			error = dnode_next_offset(dn,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6957
diff changeset
  1592
			    DNODE_FIND_HOLE, &end, minlvl, blkfill, 0);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1593
			zdb_nicenum(end - start, segsize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
			(void) printf("\t\tsegment [%016llx, %016llx)"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
			    " size %5s\n", (u_longlong_t)start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
			    (u_longlong_t)end, segsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
			if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
			start = end;
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1603
	if (db != NULL)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1170
diff changeset
  1604
		dmu_buf_rele(db, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1605
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
static char *objset_types[DMU_OST_NUMTYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
	"NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1609
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1610
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
dump_dir(objset_t *os)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
	dmu_objset_stats_t dds;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
	uint64_t object, object_count;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1615
	uint64_t refdbytes, usedobjs, scratch;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1616
	char numbuf[32];
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1617
	char blkbuf[BP_SPRINTF_LEN + 20];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
	char *type = "UNKNOWN";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
	int verbosity = dump_opt['d'];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
	int print_header = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
	int i, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1624
	dmu_objset_fast_stat(os, &dds);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
	if (dds.dds_type < DMU_OST_NUMTYPES)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
		type = objset_types[dds.dds_type];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
	if (dds.dds_type == DMU_OST_META) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
		dds.dds_creation_txg = TXG_INITIAL;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1631
		usedobjs = os->os_rootbp->blk_fill;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1632
		refdbytes = os->os_spa->spa_dsl_pool->
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7265
diff changeset
  1633
		    dp_mos_dir->dd_phys->dd_used_bytes;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1634
	} else {
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1635
		dmu_objset_space(os, &refdbytes, &scratch, &usedobjs, &scratch);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1638
	ASSERT3U(usedobjs, ==, os->os_rootbp->blk_fill);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  1640
	zdb_nicenum(refdbytes, numbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
	if (verbosity >= 4) {
10857
2c20a0bd87cd 6892882 zdb -ddddd prints garbage from stack between dataset summary and rootbp
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10685
diff changeset
  1643
		(void) sprintf(blkbuf, ", rootbp ");
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1644
		(void) sprintf_blkptr(blkbuf + strlen(blkbuf), os->os_rootbp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
		blkbuf[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1651
	(void) printf("Dataset %s [%s], ID %llu, cr_txg %llu, "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
	    "%s, %llu objects%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
	    osname, type, (u_longlong_t)dmu_objset_id(os),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
	    (u_longlong_t)dds.dds_creation_txg,
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1655
	    numbuf, (u_longlong_t)usedobjs, blkbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1656
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1657
	if (zopt_objects != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1658
		for (i = 0; i < zopt_objects; i++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1659
			dump_object(os, zopt_object[i], verbosity,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1660
			    &print_header);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1661
		(void) printf("\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1662
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1663
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1664
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1665
	if (dump_opt['i'] != 0 || verbosity >= 2)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1666
		dump_intent_log(dmu_objset_zil(os));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1668
	if (dmu_objset_ds(os) != NULL)
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1669
		dump_deadlist(&dmu_objset_ds(os)->ds_deadlist);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1670
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1671
	if (verbosity < 2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1673
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1674
	if (os->os_rootbp->blk_birth == 0)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1675
		return;
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1676
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
	dump_object(os, 0, verbosity, &print_header);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1678
	object_count = 0;
12684
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12671
diff changeset
  1679
	if (DMU_USERUSED_DNODE(os) != NULL &&
397e44ebb8a9 6710343 dnode cache should register a dnode_move() callback to limit fragmentation
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 12671
diff changeset
  1680
	    DMU_USERUSED_DNODE(os)->dn_type != 0) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1681
		dump_object(os, DMU_USERUSED_OBJECT, verbosity, &print_header);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1682
		dump_object(os, DMU_GROUPUSED_OBJECT, verbosity, &print_header);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1683
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1684
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
	object = 0;
3025
4e5ee8301d84 6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents: 2926
diff changeset
  1686
	while ((error = dmu_object_next(os, &object, B_FALSE, 0)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
		dump_object(os, object, verbosity, &print_header);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
		object_count++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1691
	ASSERT3U(object_count, ==, usedobjs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
8924
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1695
	if (error != ESRCH) {
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1696
		(void) fprintf(stderr, "dmu_object_next() = %d\n", error);
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1697
		abort();
5af812f84759 6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1698
	}
789
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
static void
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1702
dump_uberblock(uberblock_t *ub, const char *header, const char *footer)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1703
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
	time_t timestamp = ub->ub_timestamp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1706
	(void) printf(header ? header : "");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
	(void) printf("\tmagic = %016llx\n", (u_longlong_t)ub->ub_magic);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
	(void) printf("\tversion = %llu\n", (u_longlong_t)ub->ub_version);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
	(void) printf("\ttxg = %llu\n", (u_longlong_t)ub->ub_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
	(void) printf("\tguid_sum = %llu\n", (u_longlong_t)ub->ub_guid_sum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1711
	(void) printf("\ttimestamp = %llu UTC = %s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1712
	    (u_longlong_t)ub->ub_timestamp, asctime(localtime(&timestamp)));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1713
	if (dump_opt['u'] >= 3) {
896
f5270e6bd04d 6348089 panic in dbuf_remove_ref
maybee
parents: 885
diff changeset
  1714
		char blkbuf[BP_SPRINTF_LEN];
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1715
		sprintf_blkptr(blkbuf, &ub->ub_rootbp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
		(void) printf("\trootbp = %s\n", blkbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
	}
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1718
	(void) printf(footer ? footer : "");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
static void
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1722
dump_config(spa_t *spa)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
{
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1724
	dmu_buf_t *db;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1725
	size_t nvsize = 0;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1726
	int error = 0;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1727
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1728
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1729
	error = dmu_bonus_hold(spa->spa_meta_objset,
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1730
	    spa->spa_config_object, FTAG, &db);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1732
	if (error == 0) {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1733
		nvsize = *(uint64_t *)db->db_data;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1734
		dmu_buf_rele(db, FTAG);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1735
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1736
		(void) printf("\nMOS Configuration:\n");
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1737
		dump_packed_nvlist(spa->spa_meta_objset,
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1738
		    spa->spa_config_object, (void *)&nvsize, 1);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1739
	} else {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1740
		(void) fprintf(stderr, "dmu_bonus_hold(%llu) failed, errno %d",
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  1741
		    (u_longlong_t)spa->spa_config_object, error);
789
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1745
static void
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1746
dump_cachefile(const char *cachefile)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1747
{
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1748
	int fd;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1749
	struct stat64 statbuf;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1750
	char *buf;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1751
	nvlist_t *config;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1752
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1753
	if ((fd = open64(cachefile, O_RDONLY)) < 0) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1754
		(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
  1755
		    strerror(errno));
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1756
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1757
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1758
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1759
	if (fstat64(fd, &statbuf) != 0) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1760
		(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
  1761
		    strerror(errno));
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1762
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1763
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1764
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1765
	if ((buf = malloc(statbuf.st_size)) == NULL) {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1766
		(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
  1767
		    (u_longlong_t)statbuf.st_size);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1768
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1769
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1770
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1771
	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
  1772
		(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
  1773
		    (u_longlong_t)statbuf.st_size);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1774
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1775
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1776
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1777
	(void) close(fd);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1778
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1779
	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
  1780
		(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
  1781
		exit(1);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1782
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1783
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1784
	free(buf);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1785
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1786
	dump_nvlist(config, 0);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1787
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1788
	nvlist_free(config);
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1789
}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1790
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1791
#define	ZDB_MAX_UB_HEADER_SIZE 32
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1792
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1793
static void
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1794
dump_label_uberblocks(vdev_label_t *lbl, uint64_t ashift)
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1795
{
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1796
	vdev_t vd;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1797
	vdev_t *vdp = &vd;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1798
	char header[ZDB_MAX_UB_HEADER_SIZE];
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1799
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1800
	vd.vdev_ashift = ashift;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1801
	vdp->vdev_top = vdp;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1802
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1803
	for (int i = 0; i < VDEV_UBERBLOCK_COUNT(vdp); i++) {
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1804
		uint64_t uoff = VDEV_UBERBLOCK_OFFSET(vdp, i);
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1805
		uberblock_t *ub = (void *)((char *)lbl + uoff);
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1806
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1807
		if (uberblock_verify(ub))
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1808
			continue;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1809
		(void) snprintf(header, ZDB_MAX_UB_HEADER_SIZE,
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1810
		    "Uberblock[%d]\n", i);
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1811
		dump_uberblock(ub, header, "");
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1812
	}
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1813
}
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1814
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1815
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
dump_label(const char *dev)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1817
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1818
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
	vdev_label_t label;
11826
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1820
	char *path, *buf = label.vl_vdev_phys.vp_nvlist;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
	size_t buflen = sizeof (label.vl_vdev_phys.vp_nvlist);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	struct stat64 statbuf;
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1823
	uint64_t psize, ashift;
11826
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1824
	int len = strlen(dev) + 1;
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1825
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1826
	if (strncmp(dev, "/dev/dsk/", 9) == 0) {
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1827
		len++;
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1828
		path = malloc(len);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1829
		(void) snprintf(path, len, "%s%s", "/dev/rdsk/", dev + 9);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1830
	} else {
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1831
		path = strdup(dev);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1832
	}
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1833
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1834
	if ((fd = open64(path, O_RDONLY)) < 0) {
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1835
		(void) printf("cannot open '%s': %s\n", path, strerror(errno));
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1836
		free(path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
		exit(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
	if (fstat64(fd, &statbuf) != 0) {
11826
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1841
		(void) printf("failed to stat '%s': %s\n", path,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
		    strerror(errno));
11826
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1843
		free(path);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1844
		(void) close(fd);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1845
		exit(1);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1846
	}
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1847
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1848
	if (S_ISBLK(statbuf.st_mode)) {
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1849
		(void) printf("cannot use '%s': character device required\n",
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1850
		    path);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1851
		free(path);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1852
		(void) close(fd);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1853
		exit(1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
	psize = statbuf.st_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
	psize = P2ALIGN(psize, (uint64_t)sizeof (vdev_label_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1859
	for (int l = 0; l < VDEV_LABELS; l++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
		nvlist_t *config = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
		(void) printf("--------------------------------------------\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
		(void) printf("LABEL %d\n", l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
		(void) printf("--------------------------------------------\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
1170
cbb023fb2c22 6366222 zdb(1M) needs to use largefile primitives when reading label
eschrock
parents: 896
diff changeset
  1866
		if (pread64(fd, &label, sizeof (label),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
		    vdev_label_offset(psize, l, 0)) != sizeof (label)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
			(void) printf("failed to read label %d\n", l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
		if (nvlist_unpack(buf, buflen, &config, 0) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
			(void) printf("failed to unpack label %d\n", l);
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1874
			ashift = SPA_MINBLOCKSHIFT;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1875
		} else {
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1876
			nvlist_t *vdev_tree = NULL;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1877
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1878
			dump_nvlist(config, 4);
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1879
			if ((nvlist_lookup_nvlist(config,
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1880
			    ZPOOL_CONFIG_VDEV_TREE, &vdev_tree) != 0) ||
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1881
			    (nvlist_lookup_uint64(vdev_tree,
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1882
			    ZPOOL_CONFIG_ASHIFT, &ashift) != 0))
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1883
				ashift = SPA_MINBLOCKSHIFT;
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1884
			nvlist_free(config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
		}
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1886
		if (dump_opt['u'])
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  1887
			dump_label_uberblocks(&label, ashift);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
	}
11826
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1889
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1890
	free(path);
f769bc37a3d0 6808244 changing vdev state doesn't update config file
George Wilson <George.Wilson@Sun.COM>
parents: 11811
diff changeset
  1891
	(void) close(fd);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
/*ARGSUSED*/
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1895
static int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11165
diff changeset
  1896
dump_one_dir(const char *dsname, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1898
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1899
	objset_t *os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1900
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1901
	error = dmu_objset_own(dsname, DMU_OST_ANY, B_TRUE, FTAG, &os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1902
	if (error) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1903
		(void) printf("Could not open %s, error %d\n", dsname, error);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1904
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1905
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1906
	dump_dir(os);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  1907
	dmu_objset_disown(os, FTAG);
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  1908
	fuid_table_destroy();
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  1909
	sa_loaded = B_FALSE;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1910
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1911
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1912
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1913
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1914
 * Block statistics.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1915
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1916
typedef struct zdb_blkstats {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1917
	uint64_t	zb_asize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1918
	uint64_t	zb_lsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1919
	uint64_t	zb_psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1920
	uint64_t	zb_count;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1921
} zdb_blkstats_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1923
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1924
 * Extended object types to report deferred frees and dedup auto-ditto blocks.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1925
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1926
#define	ZDB_OT_DEFERRED	(DMU_OT_NUMTYPES + 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1927
#define	ZDB_OT_DITTO	(DMU_OT_NUMTYPES + 1)
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1928
#define	ZDB_OT_OTHER	(DMU_OT_NUMTYPES + 2)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1929
#define	ZDB_OT_TOTAL	(DMU_OT_NUMTYPES + 3)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1930
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1931
static char *zdb_ot_extname[] = {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1932
	"deferred free",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1933
	"dedup ditto",
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  1934
	"other",
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1935
	"Total",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1936
};
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1937
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1938
#define	ZB_TOTAL	DN_MAX_LEVELS
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1939
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1940
typedef struct zdb_cb {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1941
	zdb_blkstats_t	zcb_type[ZB_TOTAL + 1][ZDB_OT_TOTAL + 1];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1942
	uint64_t	zcb_dedup_asize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1943
	uint64_t	zcb_dedup_blocks;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1944
	uint64_t	zcb_errors[256];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1945
	int		zcb_readfails;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1946
	int		zcb_haderrors;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1947
	spa_t		*zcb_spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1948
} zdb_cb_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1949
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1950
static void
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1951
zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1952
    dmu_object_type_t type)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1953
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1954
	uint64_t refcnt = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1955
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1956
	ASSERT(type < ZDB_OT_TOTAL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1957
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1958
	if (zilog && zil_bp_tree_add(zilog, bp) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1959
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1960
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1961
	for (int i = 0; i < 4; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1962
		int l = (i < 2) ? BP_GET_LEVEL(bp) : ZB_TOTAL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1963
		int t = (i & 1) ? type : ZDB_OT_TOTAL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1964
		zdb_blkstats_t *zb = &zcb->zcb_type[l][t];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1965
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1966
		zb->zb_asize += BP_GET_ASIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1967
		zb->zb_lsize += BP_GET_LSIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1968
		zb->zb_psize += BP_GET_PSIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1969
		zb->zb_count++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1970
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1971
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1972
	if (dump_opt['L'])
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1973
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1974
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1975
	if (BP_GET_DEDUP(bp)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1976
		ddt_t *ddt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1977
		ddt_entry_t *dde;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1978
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1979
		ddt = ddt_select(zcb->zcb_spa, bp);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1980
		ddt_enter(ddt);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1981
		dde = ddt_lookup(ddt, bp, B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1982
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1983
		if (dde == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1984
			refcnt = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1985
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1986
			ddt_phys_t *ddp = ddt_phys_select(dde, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1987
			ddt_phys_decref(ddp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1988
			refcnt = ddp->ddp_refcnt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1989
			if (ddt_phys_total_refcnt(dde) == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1990
				ddt_remove(ddt, dde);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1991
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1992
		ddt_exit(ddt);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1993
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1994
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1995
	VERIFY3U(zio_wait(zio_claim(NULL, zcb->zcb_spa,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  1996
	    refcnt ? 0 : spa_first_txg(zcb->zcb_spa),
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1997
	    bp, NULL, NULL, ZIO_FLAG_CANFAIL)), ==, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1998
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1999
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2000
/* ARGSUSED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2001
static int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2002
zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, arc_buf_t *pbuf,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2003
    const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2004
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2005
	zdb_cb_t *zcb = arg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2006
	char blkbuf[BP_SPRINTF_LEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2007
	dmu_object_type_t type;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2008
	boolean_t is_metadata;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2009
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2010
	if (bp == NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2011
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2012
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2013
	type = BP_GET_TYPE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2014
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2015
	zdb_count_block(zcb, zilog, bp,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2016
	    (type & DMU_OT_NEWTYPE) ? ZDB_OT_OTHER : type);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2017
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2018
	is_metadata = (BP_GET_LEVEL(bp) != 0 || DMU_OT_IS_METADATA(type));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2019
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2020
	if (dump_opt['c'] > 1 || (dump_opt['c'] && is_metadata)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2021
		int ioerr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2022
		size_t size = BP_GET_PSIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2023
		void *data = malloc(size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2024
		int flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_SCRUB | ZIO_FLAG_RAW;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2025
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2026
		/* If it's an intent log block, failure is expected. */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2027
		if (zb->zb_level == ZB_ZIL_LEVEL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2028
			flags |= ZIO_FLAG_SPECULATIVE;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2029
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2030
		ioerr = zio_wait(zio_read(NULL, spa, bp, data, size,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2031
		    NULL, NULL, ZIO_PRIORITY_ASYNC_READ, flags, zb));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2032
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2033
		free(data);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2034
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2035
		if (ioerr && !(flags & ZIO_FLAG_SPECULATIVE)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2036
			zcb->zcb_haderrors = 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2037
			zcb->zcb_errors[ioerr]++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2038
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2039
			if (dump_opt['b'] >= 2)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2040
				sprintf_blkptr(blkbuf, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2041
			else
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2042
				blkbuf[0] = '\0';
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2043
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2044
			(void) printf("zdb_blkptr_cb: "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2045
			    "Got error %d reading "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2046
			    "<%llu, %llu, %lld, %llx> %s -- skipping\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2047
			    ioerr,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2048
			    (u_longlong_t)zb->zb_objset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2049
			    (u_longlong_t)zb->zb_object,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2050
			    (u_longlong_t)zb->zb_level,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2051
			    (u_longlong_t)zb->zb_blkid,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2052
			    blkbuf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2053
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2054
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2055
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2056
	zcb->zcb_readfails = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2057
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2058
	if (dump_opt['b'] >= 4) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2059
		sprintf_blkptr(blkbuf, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2060
		(void) printf("objset %llu object %llu "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2061
		    "level %lld offset 0x%llx %s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2062
		    (u_longlong_t)zb->zb_objset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2063
		    (u_longlong_t)zb->zb_object,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2064
		    (longlong_t)zb->zb_level,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2065
		    (u_longlong_t)blkid2offset(dnp, bp, zb),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2066
		    blkbuf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2067
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2068
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2069
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2070
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2071
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2072
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
  2073
zdb_leak(space_map_t *sm, uint64_t start, uint64_t size)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2074
{
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
  2075
	vdev_t *vd = sm->sm_ppd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2076
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
	(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
  2078
	    (u_longlong_t)vd->vdev_id, (u_longlong_t)start, (u_longlong_t)size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2079
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2080
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
  2081
/* 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
  2082
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
  2083
zdb_space_map_load(space_map_t *sm)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2084
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2085
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2086
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2087
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
  2088
zdb_space_map_unload(space_map_t *sm)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2089
{
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
  2090
	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
  2091
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2092
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
  2093
/* 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
  2094
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
  2095
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
  2096
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
  2097
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2098
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
  2099
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
  2100
	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
  2101
	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
  2102
	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
  2103
	zdb_space_map_claim,
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
  2104
	NULL,	/* free */
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
  2105
	NULL	/* maxsize */
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
  2106
};
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
static void
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2109
zdb_ddt_leak_init(spa_t *spa, zdb_cb_t *zcb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2110
{
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2111
	ddt_bookmark_t ddb = { 0 };
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2112
	ddt_entry_t dde;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2113
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2114
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2115
	while ((error = ddt_walk(spa, &ddb, &dde)) == 0) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2116
		blkptr_t blk;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2117
		ddt_phys_t *ddp = dde.dde_phys;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2118
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2119
		if (ddb.ddb_class == DDT_CLASS_UNIQUE)
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2120
			return;
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2121
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2122
		ASSERT(ddt_phys_total_refcnt(&dde) > 1);
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2123
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2124
		for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2125
			if (ddp->ddp_phys_birth == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2126
				continue;
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2127
			ddt_bp_create(ddb.ddb_checksum,
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2128
			    &dde.dde_key, ddp, &blk);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2129
			if (p == DDT_PHYS_DITTO) {
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2130
				zdb_count_block(zcb, NULL, &blk, ZDB_OT_DITTO);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2131
			} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2132
				zcb->zcb_dedup_asize +=
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2133
				    BP_GET_ASIZE(&blk) * (ddp->ddp_refcnt - 1);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2134
				zcb->zcb_dedup_blocks++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2135
			}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2136
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2137
		if (!dump_opt['L']) {
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2138
			ddt_t *ddt = spa->spa_ddt[ddb.ddb_checksum];
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2139
			ddt_enter(ddt);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2140
			VERIFY(ddt_lookup(ddt, &blk, B_TRUE) != NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2141
			ddt_exit(ddt);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2144
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2145
	ASSERT(error == ENOENT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2146
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2147
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2148
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2149
zdb_leak_init(spa_t *spa, zdb_cb_t *zcb)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2150
{
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2151
	zcb->zcb_spa = spa;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2152
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2153
	if (!dump_opt['L']) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2154
		vdev_t *rvd = spa->spa_root_vdev;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2155
		for (int c = 0; c < rvd->vdev_children; c++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2156
			vdev_t *vd = rvd->vdev_child[c];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2157
			for (int m = 0; m < vd->vdev_ms_count; m++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2158
				metaslab_t *msp = vd->vdev_ms[m];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2159
				mutex_enter(&msp->ms_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2160
				space_map_unload(&msp->ms_map);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2161
				VERIFY(space_map_load(&msp->ms_map,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2162
				    &zdb_space_map_ops, SM_ALLOC, &msp->ms_smo,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2163
				    spa->spa_meta_objset) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2164
				msp->ms_map.sm_ppd = vd;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2165
				mutex_exit(&msp->ms_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2166
			}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2167
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2168
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2169
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2170
	spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2171
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2172
	zdb_ddt_leak_init(spa, zcb);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2173
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2174
	spa_config_exit(spa, SCL_CONFIG, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
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
  2178
zdb_leak_fini(spa_t *spa)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2180
	if (!dump_opt['L']) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2181
		vdev_t *rvd = spa->spa_root_vdev;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2182
		for (int c = 0; c < rvd->vdev_children; c++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2183
			vdev_t *vd = rvd->vdev_child[c];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2184
			for (int m = 0; m < vd->vdev_ms_count; m++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2185
				metaslab_t *msp = vd->vdev_ms[m];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2186
				mutex_enter(&msp->ms_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2187
				space_map_unload(&msp->ms_map);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2188
				mutex_exit(&msp->ms_lock);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  2189
			}
6217
40ffa8cc1b75 6656655 zdb should be able to display blkptr signatures
ek110237
parents: 5994
diff changeset
  2190
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2191
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2192
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2193
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2194
/* ARGSUSED */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2195
static int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2196
count_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2197
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2198
	zdb_cb_t *zcb = arg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2199
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2200
	if (dump_opt['b'] >= 4) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2201
		char blkbuf[BP_SPRINTF_LEN];
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2202
		sprintf_blkptr(blkbuf, bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2203
		(void) printf("[%s] %s\n",
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2204
		    "deferred free", blkbuf);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2205
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2206
	zdb_count_block(zcb, NULL, bp, ZDB_OT_DEFERRED);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2207
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2208
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2209
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
dump_block_stats(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
	zdb_cb_t zcb = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
	zdb_blkstats_t *zb, *tzb;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2215
	uint64_t norm_alloc, norm_space, total_alloc, total_found;
11724
a2728800460e 6848238 zdb -bcsv does not report all corruptions
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11497
diff changeset
  2216
	int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_HARD;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
	int leaks = 0;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2218
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2219
	(void) printf("\nTraversing all blocks %s%s%s%s%s...\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2220
	    (dump_opt['c'] || !dump_opt['L']) ? "to verify " : "",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2221
	    (dump_opt['c'] == 1) ? "metadata " : "",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2222
	    dump_opt['c'] ? "checksums " : "",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2223
	    (dump_opt['c'] && !dump_opt['L']) ? "and verify " : "",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2224
	    !dump_opt['L'] ? "nothing leaked " : "");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2225
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2226
	/*
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
  2227
	 * 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
  2228
	 * 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
  2229
	 * 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
  2230
	 * 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
  2231
	 * 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
  2232
	 * reference to a freed block, or an unclaimed log block.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2233
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2234
	zdb_leak_init(spa, &zcb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
	 * If there's a deferred-free bplist, process that first.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
	 */
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2239
	(void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2240
	    count_block_cb, &zcb, NULL);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2241
	(void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2242
	    count_block_cb, &zcb, NULL);
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2243
	if (spa_feature_is_active(spa,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2244
	    &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2245
		VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2246
		    spa->spa_dsl_pool->dp_bptree_obj, B_FALSE, count_block_cb,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2247
		    &zcb, NULL));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2248
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2250
	if (dump_opt['c'] > 1)
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2251
		flags |= TRAVERSE_PREFETCH_DATA;
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2252
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2253
	zcb.zcb_haderrors |= traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2255
	if (zcb.zcb_haderrors) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
		(void) printf("\nError counts:\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2257
		(void) printf("\t%5s  %s\n", "errno", "count");
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2258
		for (int e = 0; e < 256; e++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
			if (zcb.zcb_errors[e] != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
				(void) printf("\t%5d  %llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2261
				    e, (u_longlong_t)zcb.zcb_errors[e]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2263
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2265
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2266
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
	 * Report any leaked segments.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2269
	zdb_leak_fini(spa);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2270
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2271
	tzb = &zcb.zcb_type[ZB_TOTAL][ZDB_OT_TOTAL];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2272
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2273
	norm_alloc = metaslab_class_get_alloc(spa_normal_class(spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2274
	norm_space = metaslab_class_get_space(spa_normal_class(spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2275
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2276
	total_alloc = norm_alloc + metaslab_class_get_alloc(spa_log_class(spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2277
	total_found = tzb->zb_asize - zcb.zcb_dedup_asize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2278
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2279
	if (total_found == total_alloc) {
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
  2280
		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
  2281
			(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
  2282
			    " maps exactly)\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2283
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2284
		(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
  2285
		    "(%s %lld)\n",
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2286
		    (u_longlong_t)total_found,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2287
		    (u_longlong_t)total_alloc,
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
  2288
		    (dump_opt['L']) ? "unreachable" : "leaked",
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2289
		    (longlong_t)(total_alloc - total_found));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2290
		leaks = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2291
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2292
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2293
	if (tzb->zb_count == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2294
		return (2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2295
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2296
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2297
	(void) printf("\tbp count:      %10llu\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2298
	    (u_longlong_t)tzb->zb_count);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2299
	(void) printf("\tbp logical:    %10llu      avg: %6llu\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2300
	    (u_longlong_t)tzb->zb_lsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2301
	    (u_longlong_t)(tzb->zb_lsize / tzb->zb_count));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2302
	(void) printf("\tbp physical:   %10llu      avg:"
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2303
	    " %6llu     compression: %6.2f\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2304
	    (u_longlong_t)tzb->zb_psize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2305
	    (u_longlong_t)(tzb->zb_psize / tzb->zb_count),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2306
	    (double)tzb->zb_lsize / tzb->zb_psize);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2307
	(void) printf("\tbp allocated:  %10llu      avg:"
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2308
	    " %6llu     compression: %6.2f\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
	    (u_longlong_t)tzb->zb_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
	    (u_longlong_t)(tzb->zb_asize / tzb->zb_count),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2311
	    (double)tzb->zb_lsize / tzb->zb_asize);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2312
	(void) printf("\tbp deduped:    %10llu    ref>1:"
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2313
	    " %6llu   deduplication: %6.2f\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2314
	    (u_longlong_t)zcb.zcb_dedup_asize,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2315
	    (u_longlong_t)zcb.zcb_dedup_blocks,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2316
	    (double)zcb.zcb_dedup_asize / tzb->zb_asize + 1.0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2317
	(void) printf("\tSPA allocated: %10llu     used: %5.2f%%\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2318
	    (u_longlong_t)norm_alloc, 100.0 * norm_alloc / norm_space);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2320
	if (dump_opt['b'] >= 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2321
		int l, t, level;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2322
		(void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2323
		    "\t  avg\t comp\t%%Total\tType\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2324
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2325
		for (t = 0; t <= ZDB_OT_TOTAL; t++) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2326
			char csize[32], lsize[32], psize[32], asize[32];
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2327
			char avg[32];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
			char *typename;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2330
			if (t < DMU_OT_NUMTYPES)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2331
				typename = dmu_ot[t].ot_name;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2332
			else
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2333
				typename = zdb_ot_extname[t - DMU_OT_NUMTYPES];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2334
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2335
			if (zcb.zcb_type[ZB_TOTAL][t].zb_asize == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2336
				(void) printf("%6s\t%5s\t%5s\t%5s"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2337
				    "\t%5s\t%5s\t%6s\t%s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2338
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2339
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2340
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2341
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2343
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2344
				    "-",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2345
				    typename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2346
				continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2347
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2348
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2349
			for (l = ZB_TOTAL - 1; l >= -1; l--) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2350
				level = (l == -1 ? ZB_TOTAL : l);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2351
				zb = &zcb.zcb_type[level][t];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2352
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2353
				if (zb->zb_asize == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
					continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2355
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2356
				if (dump_opt['b'] < 3 && level != ZB_TOTAL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2357
					continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2358
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2359
				if (level == 0 && zb->zb_asize ==
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
				    zcb.zcb_type[ZB_TOTAL][t].zb_asize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
					continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2363
				zdb_nicenum(zb->zb_count, csize);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2364
				zdb_nicenum(zb->zb_lsize, lsize);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2365
				zdb_nicenum(zb->zb_psize, psize);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2366
				zdb_nicenum(zb->zb_asize, asize);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2367
				zdb_nicenum(zb->zb_asize / zb->zb_count, avg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2368
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2369
				(void) printf("%6s\t%5s\t%5s\t%5s\t%5s"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2370
				    "\t%5.2f\t%6.2f\t",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2371
				    csize, lsize, psize, asize, avg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
				    (double)zb->zb_lsize / zb->zb_psize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
				    100.0 * zb->zb_asize / tzb->zb_asize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
				if (level == ZB_TOTAL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2376
					(void) printf("%s\n", typename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2377
				else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2378
					(void) printf("    L%d %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
					    level, typename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2380
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2381
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2382
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2385
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2386
	if (leaks)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2387
		return (2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2388
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
	if (zcb.zcb_haderrors)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2390
		return (3);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2391
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2392
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2393
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2394
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2395
typedef struct zdb_ddt_entry {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2396
	ddt_key_t	zdde_key;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2397
	uint64_t	zdde_ref_blocks;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2398
	uint64_t	zdde_ref_lsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2399
	uint64_t	zdde_ref_psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2400
	uint64_t	zdde_ref_dsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2401
	avl_node_t	zdde_node;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2402
} zdb_ddt_entry_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2403
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2404
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2405
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2406
zdb_ddt_add_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  2407
    arc_buf_t *pbuf, const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2408
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2409
	avl_tree_t *t = arg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2410
	avl_index_t where;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2411
	zdb_ddt_entry_t *zdde, zdde_search;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2412
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2413
	if (bp == NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2414
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2415
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2416
	if (dump_opt['S'] > 1 && zb->zb_level == ZB_ROOT_LEVEL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2417
		(void) printf("traversing objset %llu, %llu objects, "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2418
		    "%lu blocks so far\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2419
		    (u_longlong_t)zb->zb_objset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2420
		    (u_longlong_t)bp->blk_fill,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2421
		    avl_numnodes(t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2422
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2423
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2424
	if (BP_IS_HOLE(bp) || BP_GET_CHECKSUM(bp) == ZIO_CHECKSUM_OFF ||
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2425
	    BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2426
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2427
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2428
	ddt_key_fill(&zdde_search.zdde_key, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2429
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2430
	zdde = avl_find(t, &zdde_search, &where);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2431
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2432
	if (zdde == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2433
		zdde = umem_zalloc(sizeof (*zdde), UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2434
		zdde->zdde_key = zdde_search.zdde_key;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2435
		avl_insert(t, zdde, where);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2436
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2437
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2438
	zdde->zdde_ref_blocks += 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2439
	zdde->zdde_ref_lsize += BP_GET_LSIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2440
	zdde->zdde_ref_psize += BP_GET_PSIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2441
	zdde->zdde_ref_dsize += bp_get_dsize_sync(spa, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2442
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2443
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2444
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2445
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2446
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2447
dump_simulated_ddt(spa_t *spa)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2448
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2449
	avl_tree_t t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2450
	void *cookie = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2451
	zdb_ddt_entry_t *zdde;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2452
	ddt_histogram_t ddh_total = { 0 };
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2453
	ddt_stat_t dds_total = { 0 };
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2454
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2455
	avl_create(&t, ddt_entry_compare,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2456
	    sizeof (zdb_ddt_entry_t), offsetof(zdb_ddt_entry_t, zdde_node));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2457
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2458
	spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2459
11125
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2460
	(void) traverse_pool(spa, 0, TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA,
fca3e6d28599 6899923 vdev_offline/vdev_add deadlock
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  2461
	    zdb_ddt_add_cb, &t);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2462
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2463
	spa_config_exit(spa, SCL_CONFIG, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2464
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2465
	while ((zdde = avl_destroy_nodes(&t, &cookie)) != NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2466
		ddt_stat_t dds;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2467
		uint64_t refcnt = zdde->zdde_ref_blocks;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2468
		ASSERT(refcnt != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2469
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2470
		dds.dds_blocks = zdde->zdde_ref_blocks / refcnt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2471
		dds.dds_lsize = zdde->zdde_ref_lsize / refcnt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2472
		dds.dds_psize = zdde->zdde_ref_psize / refcnt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2473
		dds.dds_dsize = zdde->zdde_ref_dsize / refcnt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2474
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2475
		dds.dds_ref_blocks = zdde->zdde_ref_blocks;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2476
		dds.dds_ref_lsize = zdde->zdde_ref_lsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2477
		dds.dds_ref_psize = zdde->zdde_ref_psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2478
		dds.dds_ref_dsize = zdde->zdde_ref_dsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2479
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2480
		ddt_stat_add(&ddh_total.ddh_stat[highbit(refcnt) - 1], &dds, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2481
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2482
		umem_free(zdde, sizeof (*zdde));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2483
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2484
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2485
	avl_destroy(&t);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2486
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2487
	ddt_histogram_stat(&dds_total, &ddh_total);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2488
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2489
	(void) printf("Simulated DDT histogram:\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2490
11149
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 11146
diff changeset
  2491
	zpool_dump_ddt(&dds_total, &ddh_total);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2492
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2493
	dump_dedup_ratio(&dds_total);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2494
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2495
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2496
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2497
dump_zpool(spa_t *spa)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2498
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2499
	dsl_pool_t *dp = spa_get_dsl(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2500
	int rc = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2501
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2502
	if (dump_opt['S']) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2503
		dump_simulated_ddt(spa);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2504
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2505
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2506
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2507
	if (!dump_opt['e'] && dump_opt['C'] > 1) {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2508
		(void) printf("\nCached configuration:\n");
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2509
		dump_nvlist(spa->spa_config, 8);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2510
	}
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2511
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2512
	if (dump_opt['C'])
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2513
		dump_config(spa);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2514
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2515
	if (dump_opt['u'])
11725
68a79ddc6b27 6720637 want zdb -l option to dump uberblock arrays as well
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11724
diff changeset
  2516
		dump_uberblock(&spa->spa_uberblock, "\nUberblock:\n", "\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2517
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2518
	if (dump_opt['D'])
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2519
		dump_all_ddts(spa);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2520
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
  2521
	if (dump_opt['d'] > 2 || dump_opt['m'])
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
  2522
		dump_metaslabs(spa);
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
  2523
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
  2524
	if (dump_opt['d'] || dump_opt['i']) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2525
		dump_dir(dp->dp_meta_objset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2526
		if (dump_opt['d'] >= 3) {
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2527
			dump_bpobj(&spa->spa_deferred_bpobj, "Deferred frees");
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2528
			if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2529
				dump_bpobj(&spa->spa_dsl_pool->dp_free_bpobj,
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2530
				    "Pool snapshot frees");
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2531
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2532
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2533
			if (spa_feature_is_active(spa,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2534
			    &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2535
				dump_bptree(spa->spa_meta_objset,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2536
				    spa->spa_dsl_pool->dp_bptree_obj,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13618
diff changeset
  2537
				    "Pool dataset frees");
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  2538
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2539
			dump_dtl(spa->spa_root_vdev, 0);
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
  2540
		}
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2541
		(void) dmu_objset_find(spa_name(spa), dump_one_dir,
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2542
		    NULL, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2544
	if (dump_opt['b'] || dump_opt['c'])
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2545
		rc = dump_block_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2547
	if (dump_opt['s'])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
		show_pool_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2549
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  2550
	if (dump_opt['h'])
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  2551
		dump_history(spa);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  2552
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2553
	if (rc != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2554
		exit(rc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2555
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2556
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2557
#define	ZDB_FLAG_CHECKSUM	0x0001
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2558
#define	ZDB_FLAG_DECOMPRESS	0x0002
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2559
#define	ZDB_FLAG_BSWAP		0x0004
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2560
#define	ZDB_FLAG_GBH		0x0008
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2561
#define	ZDB_FLAG_INDIRECT	0x0010
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2562
#define	ZDB_FLAG_PHYS		0x0020
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2563
#define	ZDB_FLAG_RAW		0x0040
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2564
#define	ZDB_FLAG_PRINT_BLKPTR	0x0080
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2565
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2566
int flagbits[256];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2567
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2568
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2569
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
  2570
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2571
	char blkbuf[BP_SPRINTF_LEN];
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2572
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2573
	if (flags & ZDB_FLAG_BSWAP)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2574
		byteswap_uint64_array((void *)bp, sizeof (blkptr_t));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2575
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2576
	sprintf_blkptr(blkbuf, bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2577
	(void) printf("%s\n", blkbuf);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2578
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2579
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2580
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2581
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
  2582
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2583
	int i;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2584
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2585
	for (i = 0; i < nbps; i++)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2586
		zdb_print_blkptr(&bp[i], flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2587
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2588
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2589
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2590
zdb_dump_gbh(void *buf, int flags)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2591
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2592
	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
  2593
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2594
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2595
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2596
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
  2597
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2598
	if (flags & ZDB_FLAG_BSWAP)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2599
		byteswap_uint64_array(buf, size);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2600
	(void) write(1, buf, size);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2601
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2602
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2603
static void
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2604
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
  2605
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2606
	uint64_t *d = (uint64_t *)buf;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2607
	int nwords = size / sizeof (uint64_t);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2608
	int do_bswap = !!(flags & ZDB_FLAG_BSWAP);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2609
	int i, j;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2610
	char *hdr, *c;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2611
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2612
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2613
	if (do_bswap)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2614
		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
  2615
	else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2616
		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
  2617
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2618
	(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
  2619
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2620
	for (i = 0; i < nwords; i += 2) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2621
		(void) printf("%06llx:  %016llx  %016llx  ",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2622
		    (u_longlong_t)(i * sizeof (uint64_t)),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2623
		    (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
  2624
		    (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
  2625
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2626
		c = (char *)&d[i];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2627
		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
  2628
			(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
  2629
		(void) printf("\n");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2630
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2631
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2632
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2633
/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2634
 * There are two acceptable formats:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2635
 *	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
  2636
 *	child[.child]*    - For example: 0.1.1
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2637
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2638
 * 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
  2639
 * 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
  2640
 * 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
  2641
 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2642
static vdev_t *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2643
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
  2644
{
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2645
	char *s, *p, *q;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2646
	int i;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2647
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2648
	if (vdev == NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2649
		return (NULL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2650
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2651
	/* 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
  2652
	i = (int)strtoul(path, &s, 10);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2653
	if (s == path || (s && *s != '.' && *s != '\0'))
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2654
		goto name;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2655
	if (i < 0 || i >= vdev->vdev_children)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2656
		return (NULL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2657
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2658
	vdev = vdev->vdev_child[i];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2659
	if (*s == '\0')
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2660
		return (vdev);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2661
	return (zdb_vdev_lookup(vdev, s+1));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2662
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2663
name:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2664
	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
  2665
		vdev_t *vc = vdev->vdev_child[i];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2666
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2667
		if (vc->vdev_path == NULL) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2668
			vc = zdb_vdev_lookup(vc, path);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2669
			if (vc == NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2670
				continue;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2671
			else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2672
				return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2673
		}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2674
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2675
		p = strrchr(vc->vdev_path, '/');
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2676
		p = p ? p + 1 : vc->vdev_path;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2677
		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
  2678
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2679
		if (strcmp(vc->vdev_path, path) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2680
			return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2681
		if (strcmp(p, path) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2682
			return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2683
		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
  2684
			return (vc);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2685
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2686
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2687
	return (NULL);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2688
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2689
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2690
/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2691
 * 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
  2692
 * block descriptor is:
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2693
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2694
 *	pool:vdev_specifier:offset:size[:flags]
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2695
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2696
 *	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
  2697
 *	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
  2698
 *	offset         - offset, in hex, in bytes
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2699
 *	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
  2700
 *	flags          - A string of characters specifying options
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2701
 *		 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
  2702
 *		*c: Calculate and display checksums
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2703
 *		 d: Decompress data before dumping
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2704
 *		 e: Byteswap data before dumping
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2705
 *		 g: Display data as a gang block header
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2706
 *		 i: Display as an indirect block
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2707
 *		 p: Do I/O to physical offset
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2708
 *		 r: Dump raw data to stdout
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2709
 *
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2710
 *              * = not yet implemented
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2711
 */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2712
static void
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2713
zdb_read_block(char *thing, spa_t *spa)
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2714
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2715
	blkptr_t blk, *bp = &blk;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2716
	dva_t *dva = bp->blk_dva;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2717
	int flags = 0;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2718
	uint64_t offset = 0, size = 0, psize = 0, lsize = 0, blkptr_offset = 0;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2719
	zio_t *zio;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2720
	vdev_t *vd;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2721
	void *pbuf, *lbuf, *buf;
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  2722
	char *s, *p, *dup, *vdev, *flagstr;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2723
	int i, error;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2724
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2725
	dup = strdup(thing);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2726
	s = strtok(dup, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2727
	vdev = s ? s : "";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2728
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2729
	offset = strtoull(s ? s : "", NULL, 16);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2730
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2731
	size = strtoull(s ? s : "", NULL, 16);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2732
	s = strtok(NULL, ":");
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2733
	flagstr = s ? s : "";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2734
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2735
	s = NULL;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2736
	if (size == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2737
		s = "size must not be zero";
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2738
	if (!IS_P2ALIGNED(size, DEV_BSIZE))
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2739
		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
  2740
	if (!IS_P2ALIGNED(offset, DEV_BSIZE))
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2741
		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
  2742
	if (s) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2743
		(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
  2744
		free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2745
		return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2746
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2747
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2748
	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
  2749
		for (i = 0; flagstr[i]; i++) {
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2417
diff changeset
  2750
			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
  2751
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2752
			if (bit == 0) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2753
				(void) printf("***Invalid flag: %c\n",
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2754
				    flagstr[i]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2755
				continue;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2756
			}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2757
			flags |= bit;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2758
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2759
			/* If it's not something with an argument, keep going */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2760
			if ((bit & (ZDB_FLAG_CHECKSUM |
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2761
			    ZDB_FLAG_PRINT_BLKPTR)) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2762
				continue;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2763
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2764
			p = &flagstr[i + 1];
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2765
			if (bit == ZDB_FLAG_PRINT_BLKPTR)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2766
				blkptr_offset = strtoull(p, &p, 16);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2767
			if (*p != ':' && *p != '\0') {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2768
				(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
  2769
				free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2770
				return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2771
			}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2772
		}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2773
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2774
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2775
	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
  2776
	if (vd == NULL) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2777
		(void) printf("***Invalid vdev: %s\n", vdev);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2778
		free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2779
		return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2780
	} else {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2781
		if (vd->vdev_path)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2782
			(void) fprintf(stderr, "Found vdev: %s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2783
			    vd->vdev_path);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2784
		else
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2785
			(void) fprintf(stderr, "Found vdev type: %s\n",
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2786
			    vd->vdev_ops->vdev_op_type);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2787
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2788
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2789
	psize = size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2790
	lsize = size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2791
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2792
	pbuf = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2793
	lbuf = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2794
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2795
	BP_ZERO(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2796
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2797
	DVA_SET_VDEV(&dva[0], vd->vdev_id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2798
	DVA_SET_OFFSET(&dva[0], offset);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2799
	DVA_SET_GANG(&dva[0], !!(flags & ZDB_FLAG_GBH));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2800
	DVA_SET_ASIZE(&dva[0], vdev_psize_to_asize(vd, psize));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2801
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2802
	BP_SET_BIRTH(bp, TXG_INITIAL, TXG_INITIAL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2803
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2804
	BP_SET_LSIZE(bp, lsize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2805
	BP_SET_PSIZE(bp, psize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2806
	BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2807
	BP_SET_CHECKSUM(bp, ZIO_CHECKSUM_OFF);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2808
	BP_SET_TYPE(bp, DMU_OT_NONE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2809
	BP_SET_LEVEL(bp, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2810
	BP_SET_DEDUP(bp, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2811
	BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2812
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
  2813
	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
  2814
	zio = zio_root(spa, NULL, NULL, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2815
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2816
	if (vd == vd->vdev_top) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2817
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2818
		 * Treat this as a normal block read.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2819
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2820
		zio_nowait(zio_read(zio, spa, bp, pbuf, psize, NULL, NULL,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2821
		    ZIO_PRIORITY_SYNC_READ,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2822
		    ZIO_FLAG_CANFAIL | ZIO_FLAG_RAW, NULL));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2823
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2824
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2825
		 * Treat this as a vdev child I/O.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2826
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2827
		zio_nowait(zio_vdev_child_io(zio, bp, vd, offset, pbuf, psize,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2828
		    ZIO_TYPE_READ, ZIO_PRIORITY_SYNC_READ,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2829
		    ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE |
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2830
		    ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY |
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2831
		    ZIO_FLAG_CANFAIL | ZIO_FLAG_RAW, NULL, NULL));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2832
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2833
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2834
	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
  2835
	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
  2836
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2837
	if (error) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2838
		(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
  2839
		goto out;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2840
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2841
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2842
	if (flags & ZDB_FLAG_DECOMPRESS) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2843
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2844
		 * We don't know how the data was compressed, so just try
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2845
		 * every decompress function at every inflated blocksize.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2846
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2847
		enum zio_compress c;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2848
		void *pbuf2 = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2849
		void *lbuf2 = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2850
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2851
		bcopy(pbuf, pbuf2, psize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2852
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2853
		VERIFY(random_get_pseudo_bytes((uint8_t *)pbuf + psize,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2854
		    SPA_MAXBLOCKSIZE - psize) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2855
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2856
		VERIFY(random_get_pseudo_bytes((uint8_t *)pbuf2 + psize,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2857
		    SPA_MAXBLOCKSIZE - psize) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2858
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2859
		for (lsize = SPA_MAXBLOCKSIZE; lsize > psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2860
		    lsize -= SPA_MINBLOCKSIZE) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2861
			for (c = 0; c < ZIO_COMPRESS_FUNCTIONS; c++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2862
				if (zio_decompress_data(c, pbuf, lbuf,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2863
				    psize, lsize) == 0 &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2864
				    zio_decompress_data(c, pbuf2, lbuf2,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2865
				    psize, lsize) == 0 &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2866
				    bcmp(lbuf, lbuf2, lsize) == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2867
					break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2868
			}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2869
			if (c != ZIO_COMPRESS_FUNCTIONS)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2870
				break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2871
			lsize -= SPA_MINBLOCKSIZE;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2872
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2873
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2874
		umem_free(pbuf2, SPA_MAXBLOCKSIZE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2875
		umem_free(lbuf2, SPA_MAXBLOCKSIZE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2876
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2877
		if (lsize <= psize) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2878
			(void) printf("Decompress of %s failed\n", thing);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2879
			goto out;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2880
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2881
		buf = lbuf;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2882
		size = lsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2883
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2884
		buf = pbuf;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2885
		size = psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2886
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2887
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2888
	if (flags & ZDB_FLAG_PRINT_BLKPTR)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2889
		zdb_print_blkptr((blkptr_t *)(void *)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2890
		    ((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
  2891
	else if (flags & ZDB_FLAG_RAW)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2892
		zdb_dump_block_raw(buf, size, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2893
	else if (flags & ZDB_FLAG_INDIRECT)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2894
		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
  2895
		    flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2896
	else if (flags & ZDB_FLAG_GBH)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2897
		zdb_dump_gbh(buf, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2898
	else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2899
		zdb_dump_block(thing, buf, size, flags);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2900
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2901
out:
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2902
	umem_free(pbuf, SPA_MAXBLOCKSIZE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  2903
	umem_free(lbuf, SPA_MAXBLOCKSIZE);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2904
	free(dup);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2905
}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2906
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2907
static boolean_t
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2908
pool_match(nvlist_t *cfg, char *tgt)
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2909
{
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2910
	uint64_t v, guid = strtoull(tgt, NULL, 0);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2911
	char *s;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2912
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2913
	if (guid != 0) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2914
		if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_GUID, &v) == 0)
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2915
			return (v == guid);
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2916
	} else {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2917
		if (nvlist_lookup_string(cfg, ZPOOL_CONFIG_POOL_NAME, &s) == 0)
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2918
			return (strcmp(s, tgt) == 0);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2919
	}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2920
	return (B_FALSE);
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2921
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2922
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2923
static char *
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2924
find_zpool(char **target, nvlist_t **configp, int dirc, char **dirv)
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2925
{
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2926
	nvlist_t *pools;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2927
	nvlist_t *match = NULL;
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2928
	char *name = NULL;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2929
	char *sepp = NULL;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2930
	char sep;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2931
	int count = 0;
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2932
	importargs_t args = { 0 };
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2933
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2934
	args.paths = dirc;
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2935
	args.path = dirv;
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2936
	args.can_be_active = B_TRUE;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2937
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2938
	if ((sepp = strpbrk(*target, "/@")) != NULL) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2939
		sep = *sepp;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2940
		*sepp = '\0';
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2941
	}
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2942
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2943
	pools = zpool_search_import(g_zfs, &args);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2944
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2945
	if (pools != NULL) {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2946
		nvpair_t *elem = NULL;
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2947
		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
  2948
			verify(nvpair_value_nvlist(elem, configp) == 0);
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2949
			if (pool_match(*configp, *target)) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2950
				count++;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2951
				if (match != NULL) {
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2952
					/* print previously found config */
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2953
					if (name != NULL) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2954
						(void) printf("%s\n", name);
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2955
						dump_nvlist(match, 8);
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2956
						name = NULL;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2957
					}
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2958
					(void) printf("%s\n",
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2959
					    nvpair_name(elem));
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2960
					dump_nvlist(*configp, 8);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2961
				} else {
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2962
					match = *configp;
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2963
					name = nvpair_name(elem);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2964
				}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2965
			}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2966
		}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2967
	}
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2968
	if (count > 1)
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2969
		(void) fatal("\tMatched %d pools - use pool GUID "
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2970
		    "instead of pool name or \n"
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2971
		    "\tpool name part of a dataset name to select pool", count);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2972
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2973
	if (sepp)
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2974
		*sepp = sep;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2975
	/*
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2976
	 * If pool GUID was specified for pool id, replace it with pool name
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2977
	 */
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2978
	if (name && (strstr(*target, name) != *target)) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2979
		int sz = 1 + strlen(name) + ((sepp) ? strlen(sepp) : 0);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2980
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2981
		*target = umem_alloc(sz, UMEM_NOFAIL);
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2982
		(void) snprintf(*target, sz, "%s%s", name, sepp ? sepp : "");
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2983
	}
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2984
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2985
	*configp = name ? match : NULL;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2986
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2987
	return (name);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2988
}
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  2989
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2990
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2991
main(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2992
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2993
	int i, c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2994
	struct rlimit rl = { 1024, 1024 };
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  2995
	spa_t *spa = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2996
	objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2997
	int dump_all = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2998
	int verbose = 0;
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  2999
	int error = 0;
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3000
	char **searchdirs = NULL;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3001
	int nsearch = 0;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3002
	char *target;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3003
	nvlist_t *policy = NULL;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3004
	uint64_t max_txg = UINT64_MAX;
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3005
	int rewind = ZPOOL_NEVER_REWIND;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3006
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3007
	(void) setrlimit(RLIMIT_NOFILE, &rl);
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
  3008
	(void) enable_extended_FILE_stdio(-1, -1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3009
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3010
	dprintf_setup(&argc, argv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3011
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  3012
	while ((c = getopt(argc, argv, "bcdhilmsuCDRSAFLXevp:t:U:P")) != -1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3013
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3014
		case 'b':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3015
		case 'c':
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3016
		case 'd':
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3017
		case 'h':
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3018
		case 'i':
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3019
		case 'l':
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
  3020
		case 'm':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3021
		case 's':
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3022
		case 'u':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3023
		case 'C':
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3024
		case 'D':
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  3025
		case 'R':
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3026
		case 'S':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3027
			dump_opt[c]++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3028
			dump_all = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3029
			break;
11726
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
  3030
		case 'A':
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3031
		case 'F':
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
  3032
		case 'L':
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3033
		case 'X':
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3034
		case 'e':
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  3035
		case 'P':
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
  3036
			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
  3037
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3038
		case 'v':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3039
			verbose++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3040
			break;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3041
		case 'p':
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3042
			if (searchdirs == NULL) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3043
				searchdirs = umem_alloc(sizeof (char *),
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3044
				    UMEM_NOFAIL);
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3045
			} else {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3046
				char **tmp = umem_alloc((nsearch + 1) *
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3047
				    sizeof (char *), UMEM_NOFAIL);
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3048
				bcopy(searchdirs, tmp, nsearch *
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3049
				    sizeof (char *));
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3050
				umem_free(searchdirs,
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3051
				    nsearch * sizeof (char *));
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3052
				searchdirs = tmp;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3053
			}
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3054
			searchdirs[nsearch++] = optarg;
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3055
			break;
8188
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
  3056
		case 't':
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3057
			max_txg = strtoull(optarg, NULL, 0);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3058
			if (max_txg < TXG_INITIAL) {
8188
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
  3059
				(void) fprintf(stderr, "incorrect txg "
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
  3060
				    "specified: %s\n", optarg);
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
  3061
				usage();
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
  3062
			}
fd00c0a81e80 6761100 want zdb option to select older uberblocks
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 8121
diff changeset
  3063
			break;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3064
		case 'U':
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3065
			spa_config_path = optarg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3066
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3067
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3068
			usage();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3069
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3070
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3071
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3072
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3073
	if (!dump_opt['e'] && searchdirs != NULL) {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  3074
		(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
  3075
		usage();
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  3076
	}
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3077
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3078
	kernel_init(FREAD);
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3079
	g_zfs = libzfs_init();
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4627
diff changeset
  3080
	ASSERT(g_zfs != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3081
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3082
	if (dump_all)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3083
		verbose = MAX(verbose, 1);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3084
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3085
	for (c = 0; c < 256; c++) {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12050
diff changeset
  3086
		if (dump_all && !strchr("elAFLRSXP", c))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3087
			dump_opt[c] = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3088
		if (dump_opt[c])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3089
			dump_opt[c] += verbose;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3090
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3091
11726
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
  3092
	aok = (dump_opt['A'] == 1) || (dump_opt['A'] > 2);
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
  3093
	zfs_recover = (dump_opt['A'] > 1);
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11725
diff changeset
  3094
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3095
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3096
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3097
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3098
	if (argc < 2 && dump_opt['R'])
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3099
		usage();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3100
	if (argc < 1) {
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3101
		if (!dump_opt['e'] && dump_opt['C']) {
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6807
diff changeset
  3102
			dump_cachefile(spa_config_path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3103
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3104
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3105
		usage();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3106
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3108
	if (dump_opt['l']) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3109
		dump_label(argv[0]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3110
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3111
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3112
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3113
	if (dump_opt['X'] || dump_opt['F'])
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3114
		rewind = ZPOOL_DO_REWIND |
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3115
		    (dump_opt['X'] ? ZPOOL_EXTREME_REWIND : 0);
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3116
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3117
	if (nvlist_alloc(&policy, NV_UNIQUE_NAME_TYPE, 0) != 0 ||
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3118
	    nvlist_add_uint64(policy, ZPOOL_REWIND_REQUEST_TXG, max_txg) != 0 ||
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3119
	    nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind) != 0)
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3120
		fatal("internal error: %s", strerror(ENOMEM));
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3121
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  3122
	error = 0;
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3123
	target = argv[0];
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3124
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3125
	if (dump_opt['e']) {
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3126
		nvlist_t *cfg = NULL;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3127
		char *name = find_zpool(&target, &cfg, nsearch, searchdirs);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4831
diff changeset
  3128
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3129
		error = ENOENT;
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3130
		if (name) {
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3131
			if (dump_opt['C'] > 1) {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3132
				(void) printf("\nConfiguration for import:\n");
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3133
				dump_nvlist(cfg, 8);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3134
			}
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11726
diff changeset
  3135
			if (nvlist_add_nvlist(cfg,
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3136
			    ZPOOL_REWIND_POLICY, policy) != 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3137
				fatal("can't open '%s': %s",
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3138
				    target, strerror(ENOMEM));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10861
diff changeset
  3139
			}
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12684
diff changeset
  3140
			if ((error = spa_import(name, cfg, NULL,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12684
diff changeset
  3141
			    ZFS_IMPORT_MISSING_LOG)) != 0) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12684
diff changeset
  3142
				error = spa_import(name, cfg, NULL,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12684
diff changeset
  3143
				    ZFS_IMPORT_VERBATIM);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12684
diff changeset
  3144
			}
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3145
		}
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  3146
	}
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  3147
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  3148
	if (error == 0) {
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3149
		if (strpbrk(target, "/@") == NULL || dump_opt['R']) {
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3150
			error = spa_open_rewind(target, &spa, FTAG, policy,
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3151
			    NULL);
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3152
			if (error) {
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3153
				/*
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3154
				 * If we're missing the log device then
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3155
				 * try opening the pool after clearing the
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3156
				 * log state.
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3157
				 */
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3158
				mutex_enter(&spa_namespace_lock);
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3159
				if ((spa = spa_lookup(target)) != NULL &&
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3160
				    spa->spa_log_state == SPA_LOG_MISSING) {
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3161
					spa->spa_log_state = SPA_LOG_CLEAR;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3162
					error = 0;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3163
				}
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3164
				mutex_exit(&spa_namespace_lock);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3165
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3166
				if (!error) {
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3167
					error = spa_open_rewind(target, &spa,
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3168
					    FTAG, policy, NULL);
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3169
				}
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3170
			}
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3171
		} else {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3172
			error = dmu_objset_own(target, DMU_OST_ANY,
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3173
			    B_TRUE, FTAG, &os);
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  3174
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3175
	}
11146
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3176
	nvlist_free(policy);
7e58f40bcb1c 6826241 Sync write IOPS drops dramatically during TXG sync
George Wilson <George.Wilson@Sun.COM>
parents: 11125
diff changeset
  3177
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3178
	if (error)
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10857
diff changeset
  3179
		fatal("can't open '%s': %s", target, strerror(error));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3180
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3181
	argv++;
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3182
	argc--;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3183
	if (!dump_opt['R']) {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3184
		if (argc > 0) {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3185
			zopt_objects = argc;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3186
			zopt_object = calloc(zopt_objects, sizeof (uint64_t));
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3187
			for (i = 0; i < zopt_objects; i++) {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3188
				errno = 0;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3189
				zopt_object[i] = strtoull(argv[i], NULL, 0);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3190
				if (zopt_object[i] == 0 && errno != 0)
10861
ae18f8a4df85 6887242 want to be able to dump specific metaslab(s) for specific vdev
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10860
diff changeset
  3191
					fatal("bad number %s: %s",
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3192
					    argv[i], strerror(errno));
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3193
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3194
		}
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3195
		(os != NULL) ? dump_dir(os) : dump_zpool(spa);
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3196
	} else {
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3197
		flagbits['b'] = ZDB_FLAG_PRINT_BLKPTR;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3198
		flagbits['c'] = ZDB_FLAG_CHECKSUM;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3199
		flagbits['d'] = ZDB_FLAG_DECOMPRESS;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3200
		flagbits['e'] = ZDB_FLAG_BSWAP;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3201
		flagbits['g'] = ZDB_FLAG_GBH;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3202
		flagbits['i'] = ZDB_FLAG_INDIRECT;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3203
		flagbits['p'] = ZDB_FLAG_PHYS;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3204
		flagbits['r'] = ZDB_FLAG_RAW;
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3205
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3206
		for (i = 0; i < argc; i++)
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3207
			zdb_read_block(argv[i], spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3208
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3209
10860
f850bd358163 6736356 zdb -R/-C needs to work with exported pools
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10859
diff changeset
  3210
	(os != NULL) ? dmu_objset_disown(os, FTAG) : spa_close(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3211
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  3212
	fuid_table_destroy();
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11826
diff changeset
  3213
	sa_loaded = B_FALSE;
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5530
diff changeset
  3214
4627
c85631613c19 6509812 it would be useful if zdb(1M) could run on exported pools
ck153898
parents: 4577
diff changeset
  3215
	libzfs_fini(g_zfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3216
	kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3218
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3219
}