xref: /illumos-gate/usr/src/cmd/zdb/zdb_il.c (revision eb633035)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
223589c4f0SNeil Perrin  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
2643466aaeSMax Grossman /*
2786714001SSerapheim Dimitropoulos  * Copyright (c) 2013, 2017 by Delphix. All rights reserved.
2843466aaeSMax Grossman  */
2943466aaeSMax Grossman 
30fa9e4066Sahrens /*
31fa9e4066Sahrens  * Print intent log header and statistics.
32fa9e4066Sahrens  */
34fa9e4066Sahrens #include <stdio.h>
35fa9e4066Sahrens #include <stdlib.h>
36fa9e4066Sahrens #include <ctype.h>
37fa9e4066Sahrens #include <sys/zfs_context.h>
38fa9e4066Sahrens #include <sys/spa.h>
39fa9e4066Sahrens #include <sys/dmu.h>
40fa9e4066Sahrens #include <sys/stat.h>
41fa9e4066Sahrens #include <sys/resource.h>
42fa9e4066Sahrens #include <sys/zil.h>
43fa9e4066Sahrens #include <sys/zil_impl.h>
4486714001SSerapheim Dimitropoulos #include <sys/spa_impl.h>
45770499e1SDan Kimmel #include <sys/abd.h>
473f7978d0SAlan Somers #include "zdb.h"
483f7978d0SAlan Somers 
49fa9e4066Sahrens extern uint8_t dump_opt[256];
513f7978d0SAlan Somers static char tab_prefix[4] = "\t\t\t";
52b24ab676SJeff Bonwick 
53fa9e4066Sahrens static void
print_log_bp(const blkptr_t * bp,const char * prefix)54d80c45e0Sbonwick print_log_bp(const blkptr_t *bp, const char *prefix)
55fa9e4066Sahrens {
56fbabab8fSmaybee 	char blkbuf[BP_SPRINTF_LEN];
5843466aaeSMax Grossman 	snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
59fa9e4066Sahrens 	(void) printf("%s%s\n", prefix, blkbuf);
60fa9e4066Sahrens }
62fa9e4066Sahrens /* ARGSUSED */
63fa9e4066Sahrens static void
zil_prt_rec_create(zilog_t * zilog,int txtype,void * arg)643f7978d0SAlan Somers zil_prt_rec_create(zilog_t *zilog, int txtype, void *arg)
65fa9e4066Sahrens {
663f7978d0SAlan Somers 	lr_create_t *lr = arg;
67fa9e4066Sahrens 	time_t crtime = lr->lr_crtime[0];
68faaa6415SEric Schrock 	char *name, *link;
69faaa6415SEric Schrock 	lr_attr_t *lrattr;
71faaa6415SEric Schrock 	name = (char *)(lr + 1);
72faaa6415SEric Schrock 
73faaa6415SEric Schrock 	if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
74faaa6415SEric Schrock 	    lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
75faaa6415SEric Schrock 		lrattr = (lr_attr_t *)(lr + 1);
76faaa6415SEric Schrock 		name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
77faaa6415SEric Schrock 	}
78faaa6415SEric Schrock 
79faaa6415SEric Schrock 	if (txtype == TX_SYMLINK) {
80faaa6415SEric Schrock 		link = name + strlen(name) + 1;
813f7978d0SAlan Somers 		(void) printf("%s%s -> %s\n", tab_prefix, name, link);
82faaa6415SEric Schrock 	} else if (txtype != TX_MKXATTR) {
833f7978d0SAlan Somers 		(void) printf("%s%s\n", tab_prefix, name);
84faaa6415SEric Schrock 	}
863f7978d0SAlan Somers 	(void) printf("%s%s", tab_prefix, ctime(&crtime));
8754811da5SToomas Soome 	(void) printf("%sdoid %" PRIu64 ", foid %" PRIu64 ", slots %" PRIu64
8854811da5SToomas Soome 	    ", mode %" PRIo64 "\n",
8954811da5SToomas Soome 	    tab_prefix, lr->lr_doid,
9054811da5SToomas Soome 	    LR_FOID_GET_OBJ(lr->lr_foid),
9154811da5SToomas Soome 	    LR_FOID_GET_SLOTS(lr->lr_foid),
9254811da5SToomas Soome 	    lr->lr_mode);
9354811da5SToomas Soome 	(void) printf("%suid %" PRIu64 ", gid %" PRIu64 ", gen %" PRIu64
9454811da5SToomas Soome 	    ", rdev %#" PRIx64 "\n",
9554811da5SToomas Soome 	    tab_prefix, lr->lr_uid, lr->lr_gid, lr->lr_gen, lr->lr_rdev);
96fa9e4066Sahrens }
98fa9e4066Sahrens /* ARGSUSED */
99fa9e4066Sahrens static void
zil_prt_rec_remove(zilog_t * zilog,int txtype,void * arg)1003f7978d0SAlan Somers zil_prt_rec_remove(zilog_t *zilog, int txtype, void *arg)
101fa9e4066Sahrens {
1023f7978d0SAlan Somers 	lr_remove_t *lr = arg;
1033f7978d0SAlan Somers 
1043f7978d0SAlan Somers 	(void) printf("%sdoid %llu, name %s\n", tab_prefix,
105fa9e4066Sahrens 	    (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
106fa9e4066Sahrens }
108fa9e4066Sahrens /* ARGSUSED */
109fa9e4066Sahrens static void
zil_prt_rec_link(zilog_t * zilog,int txtype,void * arg)1103f7978d0SAlan Somers zil_prt_rec_link(zilog_t *zilog, int txtype, void *arg)
111fa9e4066Sahrens {
1123f7978d0SAlan Somers 	lr_link_t *lr = arg;
1133f7978d0SAlan Somers 
1143f7978d0SAlan Somers 	(void) printf("%sdoid %llu, link_obj %llu, name %s\n", tab_prefix,
115fa9e4066Sahrens 	    (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
116fa9e4066Sahrens 	    (char *)(lr + 1));
117fa9e4066Sahrens }
119fa9e4066Sahrens /* ARGSUSED */
120fa9e4066Sahrens static void
zil_prt_rec_rename(zilog_t * zilog,int txtype,void * arg)1213f7978d0SAlan Somers zil_prt_rec_rename(zilog_t *zilog, int txtype, void *arg)
122fa9e4066Sahrens {
1233f7978d0SAlan Somers 	lr_rename_t *lr = arg;
124fa9e4066Sahrens 	char *snm = (char *)(lr + 1);
125fa9e4066Sahrens 	char *tnm = snm + strlen(snm) + 1;
1273f7978d0SAlan Somers 	(void) printf("%ssdoid %llu, tdoid %llu\n", tab_prefix,
128fa9e4066Sahrens 	    (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
1293f7978d0SAlan Somers 	(void) printf("%ssrc %s tgt %s\n", tab_prefix, snm, tnm);
130fa9e4066Sahrens }
132770499e1SDan Kimmel /* ARGSUSED */
133770499e1SDan Kimmel static int
zil_prt_rec_write_cb(void * data,size_t len,void * unused)134770499e1SDan Kimmel zil_prt_rec_write_cb(void *data, size_t len, void *unused)
135770499e1SDan Kimmel {
136770499e1SDan Kimmel 	char *cdata = data;
1373f7978d0SAlan Somers 	for (size_t i = 0; i < len; i++) {
138770499e1SDan Kimmel 		if (isprint(*cdata))
139770499e1SDan Kimmel 			(void) printf("%c ", *cdata);
140770499e1SDan Kimmel 		else
141770499e1SDan Kimmel 			(void) printf("%2X", *cdata);
142770499e1SDan Kimmel 		cdata++;
143770499e1SDan Kimmel 	}
144770499e1SDan Kimmel 	return (0);
145770499e1SDan Kimmel }
146770499e1SDan Kimmel 
147fa9e4066Sahrens /* ARGSUSED */
148fa9e4066Sahrens static void
zil_prt_rec_write(zilog_t * zilog,int txtype,void * arg)1493f7978d0SAlan Somers zil_prt_rec_write(zilog_t *zilog, int txtype, void *arg)
150fa9e4066Sahrens {
1513f7978d0SAlan Somers 	lr_write_t *lr = arg;
152770499e1SDan Kimmel 	abd_t *data;
153fa9e4066Sahrens 	blkptr_t *bp = &lr->lr_blkptr;
1547802d7bfSMatthew Ahrens 	zbookmark_phys_t zb;
155fa9e4066Sahrens 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
156fa9e4066Sahrens 	int error;
1583f7978d0SAlan Somers 	(void) printf("%sfoid %llu, offset %llx, length %llx\n", tab_prefix,
159b24ab676SJeff Bonwick 	    (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
160b24ab676SJeff Bonwick 	    (u_longlong_t)lr->lr_length);
162975c32a0SNeil Perrin 	if (txtype == TX_WRITE2 || verbose < 5)
163fa9e4066Sahrens 		return;
165fa9e4066Sahrens 	if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
1663f7978d0SAlan Somers 		(void) printf("%shas blkptr, %s\n", tab_prefix,
16743466aaeSMax Grossman 		    !BP_IS_HOLE(bp) &&
16886714001SSerapheim Dimitropoulos 		    bp->blk_birth >= spa_min_claim_txg(zilog->zl_spa) ?
169fa9e4066Sahrens 		    "will claim" : "won't claim");
1703f7978d0SAlan Somers 		print_log_bp(bp, tab_prefix);
171b24ab676SJeff Bonwick 
172975c32a0SNeil Perrin 		if (BP_IS_HOLE(bp)) {
173975c32a0SNeil Perrin 			(void) printf("\t\t\tLSIZE 0x%llx\n",
174975c32a0SNeil Perrin 			    (u_longlong_t)BP_GET_LSIZE(bp));
1753f7978d0SAlan Somers 			(void) printf("%s<hole>\n", tab_prefix);
176b24ab676SJeff Bonwick 			return;
177fa9e4066Sahrens 		}
178b24ab676SJeff Bonwick 		if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
1793f7978d0SAlan Somers 			(void) printf("%s<block already committed>\n",
1803f7978d0SAlan Somers 			    tab_prefix);
181b24ab676SJeff Bonwick 			return;
182b24ab676SJeff Bonwick 		}
183b24ab676SJeff Bonwick 
184b24ab676SJeff Bonwick 		SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
185b24ab676SJeff Bonwick 		    lr->lr_foid, ZB_ZIL_LEVEL,
186b24ab676SJeff Bonwick 		    lr->lr_offset / BP_GET_LSIZE(bp));
187b24ab676SJeff Bonwick 
188770499e1SDan Kimmel 		data = abd_alloc(BP_GET_LSIZE(bp), B_FALSE);
189b24ab676SJeff Bonwick 		error = zio_wait(zio_read(NULL, zilog->zl_spa,
190770499e1SDan Kimmel 		    bp, data, BP_GET_LSIZE(bp), NULL, NULL,
191b24ab676SJeff Bonwick 		    ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
192b24ab676SJeff Bonwick 		if (error)
193770499e1SDan Kimmel 			goto out;
194fa9e4066Sahrens 	} else {
195770499e1SDan Kimmel 		/* data is stored after the end of the lr_write record */
196770499e1SDan Kimmel 		data = abd_alloc(lr->lr_length, B_FALSE);
197770499e1SDan Kimmel 		abd_copy_from_buf(data, lr + 1, lr->lr_length);
198fa9e4066Sahrens 	}
2003f7978d0SAlan Somers 	(void) printf("%s", tab_prefix);
201770499e1SDan Kimmel 	(void) abd_iterate_func(data,
202770499e1SDan Kimmel 	    0, MIN(lr->lr_length, (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE)),
203770499e1SDan Kimmel 	    zil_prt_rec_write_cb, NULL);
204fa9e4066Sahrens 	(void) printf("\n");
205770499e1SDan Kimmel 
206770499e1SDan Kimmel out:
207770499e1SDan Kimmel 	abd_free(data);
208fa9e4066Sahrens }
210fa9e4066Sahrens /* ARGSUSED */
211fa9e4066Sahrens static void
zil_prt_rec_truncate(zilog_t * zilog,int txtype,void * arg)2123f7978d0SAlan Somers zil_prt_rec_truncate(zilog_t *zilog, int txtype, void *arg)
213fa9e4066Sahrens {
2143f7978d0SAlan Somers 	lr_truncate_t *lr = arg;
2153f7978d0SAlan Somers 
2163f7978d0SAlan Somers 	(void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", tab_prefix,
217fa9e4066Sahrens 	    (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
218fa9e4066Sahrens 	    (u_longlong_t)lr->lr_length);
219fa9e4066Sahrens }
221fa9e4066Sahrens /* ARGSUSED */
222fa9e4066Sahrens static void
zil_prt_rec_setattr(zilog_t * zilog,int txtype,void * arg)2233f7978d0SAlan Somers zil_prt_rec_setattr(zilog_t *zilog, int txtype, void *arg)
224fa9e4066Sahrens {
2253f7978d0SAlan Somers 	lr_setattr_t *lr = arg;
226fa9e4066Sahrens 	time_t atime = (time_t)lr->lr_atime[0];
227fa9e4066Sahrens 	time_t mtime = (time_t)lr->lr_mtime[0];
2293f7978d0SAlan Somers 	(void) printf("%sfoid %llu, mask 0x%llx\n", tab_prefix,
230fa9e4066Sahrens 	    (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
232fa9e4066Sahrens 	if (lr->lr_mask & AT_MODE) {
2333f7978d0SAlan Somers 		(void) printf("%sAT_MODE  %llo\n", tab_prefix,
234fa9e4066Sahrens 		    (longlong_t)lr->lr_mode);
235fa9e4066Sahrens 	}
237fa9e4066Sahrens 	if (lr->lr_mask & AT_UID) {
2383f7978d0SAlan Somers 		(void) printf("%sAT_UID   %llu\n", tab_prefix,
239fa9e4066Sahrens 		    (u_longlong_t)lr->lr_uid);
240fa9e4066Sahrens 	}
242fa9e4066Sahrens 	if (lr->lr_mask & AT_GID) {
2433f7978d0SAlan Somers 		(void) printf("%sAT_GID   %llu\n", tab_prefix,
244fa9e4066Sahrens 		    (u_longlong_t)lr->lr_gid);
245fa9e4066Sahrens 	}
247fa9e4066Sahrens 	if (lr->lr_mask & AT_SIZE) {
2483f7978d0SAlan Somers 		(void) printf("%sAT_SIZE  %llu\n", tab_prefix,
249fa9e4066Sahrens 		    (u_longlong_t)lr->lr_size);
250fa9e4066Sahrens 	}
252fa9e4066Sahrens 	if (lr->lr_mask & AT_ATIME) {
2533f7978d0SAlan Somers 		(void) printf("%sAT_ATIME %llu.%09llu %s", tab_prefix,
254fa9e4066Sahrens 		    (u_longlong_t)lr->lr_atime[0],
255fa9e4066Sahrens 		    (u_longlong_t)lr->lr_atime[1],
256fa9e4066Sahrens 		    ctime(&atime));
257fa9e4066Sahrens 	}
259fa9e4066Sahrens 	if (lr->lr_mask & AT_MTIME) {
2603f7978d0SAlan Somers 		(void) printf("%sAT_MTIME %llu.%09llu %s", tab_prefix,
261fa9e4066Sahrens 		    (u_longlong_t)lr->lr_mtime[0],
262fa9e4066Sahrens 		    (u_longlong_t)lr->lr_mtime[1],
263fa9e4066Sahrens 		    ctime(&mtime));
264fa9e4066Sahrens 	}
265fa9e4066Sahrens }
267fa9e4066Sahrens /* ARGSUSED */
268fa9e4066Sahrens static void
zil_prt_rec_acl(zilog_t * zilog,int txtype,void * arg)2693f7978d0SAlan Somers zil_prt_rec_acl(zilog_t *zilog, int txtype, void *arg)
270fa9e4066Sahrens {
2713f7978d0SAlan Somers 	lr_acl_t *lr = arg;
2723f7978d0SAlan Somers 
2733f7978d0SAlan Somers 	(void) printf("%sfoid %llu, aclcnt %llu\n", tab_prefix,
274fa9e4066Sahrens 	    (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
275fa9e4066Sahrens }
2773f7978d0SAlan Somers typedef void (*zil_prt_rec_func_t)(zilog_t *, int, void *);
278fa9e4066Sahrens typedef struct zil_rec_info {
279fa9e4066Sahrens 	zil_prt_rec_func_t	zri_print;
2803f7978d0SAlan Somers 	const char		*zri_name;
281fa9e4066Sahrens 	uint64_t		zri_count;
282fa9e4066Sahrens } zil_rec_info_t;
284fa9e4066Sahrens static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
2853f7978d0SAlan Somers 	{.zri_print = NULL,		    .zri_name = "Total              "},
2863f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_CREATE          "},
2873f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_MKDIR           "},
2883f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_MKXATTR         "},
2893f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_SYMLINK         "},
2903f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_remove,   .zri_name = "TX_REMOVE          "},
2913f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_remove,   .zri_name = "TX_RMDIR           "},
2923f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_link,	    .zri_name = "TX_LINK            "},
2933f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_rename,   .zri_name = "TX_RENAME          "},
2943f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_write,    .zri_name = "TX_WRITE           "},
2953f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_truncate, .zri_name = "TX_TRUNCATE        "},
2963f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_setattr,  .zri_name = "TX_SETATTR         "},
2973f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_acl,	    .zri_name = "TX_ACL_V0          "},
2983f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_acl,	    .zri_name = "TX_ACL_ACL         "},
2993f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_CREATE_ACL      "},
3003f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_CREATE_ATTR     "},
3013f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_CREATE_ACL_ATTR "},
3023f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_MKDIR_ACL       "},
3033f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_MKDIR_ATTR      "},
3043f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_create,   .zri_name = "TX_MKDIR_ACL_ATTR  "},
3053f7978d0SAlan Somers 	{.zri_print = zil_prt_rec_write,    .zri_name = "TX_WRITE2          "},
306fa9e4066Sahrens };
308fa9e4066Sahrens /* ARGSUSED */
309b24ab676SJeff Bonwick static int
print_log_record(zilog_t * zilog,lr_t * lr,void * arg,uint64_t claim_txg)3105dabedeeSbonwick print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
311fa9e4066Sahrens {
312fa9e4066Sahrens 	int txtype;
313fa9e4066Sahrens 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
315da6c28aaSamw 	/* reduce size of txtype to strip off TX_CI bit */
316fa9e4066Sahrens 	txtype = lr->lrc_txtype;
318fa9e4066Sahrens 	ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
319fa9e4066Sahrens 	ASSERT(lr->lrc_txg);
321da6c28aaSamw 	(void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
322da6c28aaSamw 	    (lr->lrc_txtype & TX_CI) ? "CI-" : "",
323fa9e4066Sahrens 	    zil_rec_info[txtype].zri_name,
324fa9e4066Sahrens 	    (u_longlong_t)lr->lrc_reclen,
325fa9e4066Sahrens 	    (u_longlong_t)lr->lrc_txg,
326fa9e4066Sahrens 	    (u_longlong_t)lr->lrc_seq);
328*eb633035STom Caputi 	if (txtype && verbose >= 3) {
329*eb633035STom Caputi 		if (!zilog->zl_os->os_encrypted) {
330*eb633035STom Caputi 			zil_rec_info[txtype].zri_print(zilog, txtype, lr);
331*eb633035STom Caputi 		} else {
332*eb633035STom Caputi 			(void) printf("%s(encrypted)\n", tab_prefix);
333*eb633035STom Caputi 		}
334*eb633035STom Caputi 	}
336fa9e4066Sahrens 	zil_rec_info[txtype].zri_count++;
337fa9e4066Sahrens 	zil_rec_info[0].zri_count++;
338b24ab676SJeff Bonwick 
339b24ab676SJeff Bonwick 	return (0);
340fa9e4066Sahrens }
342fa9e4066Sahrens /* ARGSUSED */
343b24ab676SJeff Bonwick static int
print_log_block(zilog_t * zilog,blkptr_t * bp,void * arg,uint64_t claim_txg)3445dabedeeSbonwick print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
345fa9e4066Sahrens {
346b24ab676SJeff Bonwick 	char blkbuf[BP_SPRINTF_LEN + 10];
347fa9e4066Sahrens 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
3483f7978d0SAlan Somers 	const char *claim;
350fa9e4066Sahrens 	if (verbose <= 3)
351b24ab676SJeff Bonwick 		return (0);
353fa9e4066Sahrens 	if (verbose >= 5) {
354fa9e4066Sahrens 		(void) strcpy(blkbuf, ", ");
35543466aaeSMax Grossman 		snprintf_blkptr(blkbuf + strlen(blkbuf),
35643466aaeSMax Grossman 		    sizeof (blkbuf) - strlen(blkbuf), bp);
357fa9e4066Sahrens 	} else {
358fa9e4066Sahrens 		blkbuf[0] = '\0';
359fa9e4066Sahrens 	}
3615dabedeeSbonwick 	if (claim_txg != 0)
3625dabedeeSbonwick 		claim = "already claimed";
36386714001SSerapheim Dimitropoulos 	else if (bp->blk_birth >= spa_min_claim_txg(zilog->zl_spa))
3645dabedeeSbonwick 		claim = "will claim";
3655dabedeeSbonwick 	else
3665dabedeeSbonwick 		claim = "won't claim";
368fa9e4066Sahrens 	(void) printf("\tBlock seqno %llu, %s%s\n",
369d80c45e0Sbonwick 	    (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
370b24ab676SJeff Bonwick 
371b24ab676SJeff Bonwick 	return (0);
372fa9e4066Sahrens }
374fa9e4066Sahrens static void
print_log_stats(int verbose)375fa9e4066Sahrens print_log_stats(int verbose)
376fa9e4066Sahrens {
3773f7978d0SAlan Somers 	unsigned i, w, p10;
379fa9e4066Sahrens 	if (verbose > 3)
380fa9e4066Sahrens 		(void) printf("\n");
382fa9e4066Sahrens 	if (zil_rec_info[0].zri_count == 0)
383fa9e4066Sahrens 		return;
385fa9e4066Sahrens 	for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
386fa9e4066Sahrens 		w++;
388fa9e4066Sahrens 	for (i = 0; i < TX_MAX_TYPE; i++)
389fa9e4066Sahrens 		if (zil_rec_info[i].zri_count || verbose >= 3)
390fa9e4066Sahrens 			(void) printf("\t\t%s %*llu\n",
391fa9e4066Sahrens 			    zil_rec_info[i].zri_name, w,
392fa9e4066Sahrens 			    (u_longlong_t)zil_rec_info[i].zri_count);
393fa9e4066Sahrens 	(void) printf("\n");
394fa9e4066Sahrens }
396fa9e4066Sahrens /* ARGSUSED */
397fa9e4066Sahrens void
dump_intent_log(zilog_t * zilog)398fa9e4066Sahrens dump_intent_log(zilog_t *zilog)
399fa9e4066Sahrens {
400d80c45e0Sbonwick 	const zil_header_t *zh = zilog->zl_header;
401fa9e4066Sahrens 	int verbose = MAX(dump_opt['d'], dump_opt['i']);
402fa9e4066Sahrens 	int i;
40443466aaeSMax Grossman 	if (BP_IS_HOLE(&zh->zh_log) || verbose < 1)
405fa9e4066Sahrens 		return;
407b24ab676SJeff Bonwick 	(void) printf("\n    ZIL header: claim_txg %llu, "
408b24ab676SJeff Bonwick 	    "claim_blk_seq %llu, claim_lr_seq %llu",
409b24ab676SJeff Bonwick 	    (u_longlong_t)zh->zh_claim_txg,
410b24ab676SJeff Bonwick 	    (u_longlong_t)zh->zh_claim_blk_seq,
411b24ab676SJeff Bonwick 	    (u_longlong_t)zh->zh_claim_lr_seq);
4123589c4f0SNeil Perrin 	(void) printf(" replay_seq %llu, flags 0x%llx\n",
4133589c4f0SNeil Perrin 	    (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
415fa9e4066Sahrens 	for (i = 0; i < TX_MAX_TYPE; i++)
416fa9e4066Sahrens 		zil_rec_info[i].zri_count = 0;
41886714001SSerapheim Dimitropoulos 	/* see comment in zil_claim() or zil_check_log_chain() */
41986714001SSerapheim Dimitropoulos 	if (zilog->zl_spa->spa_uberblock.ub_checkpoint_txg != 0 &&
42086714001SSerapheim Dimitropoulos 	    zh->zh_claim_txg == 0)
42186714001SSerapheim Dimitropoulos 		return;
42286714001SSerapheim Dimitropoulos 
423fa9e4066Sahrens 	if (verbose >= 2) {
424fa9e4066Sahrens 		(void) printf("\n");
425d80c45e0Sbonwick 		(void) zil_parse(zilog, print_log_block, print_log_record, NULL,
426*eb633035STom Caputi 		    zh->zh_claim_txg, B_FALSE);
427fa9e4066Sahrens 		print_log_stats(verbose);
428fa9e4066Sahrens 	}
429fa9e4066Sahrens }