Deleted Added
full compact
zdb_il.c (200724) zdb_il.c (209962)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/*
27 * Print intent log header and statistics.
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <ctype.h>
33#include <sys/zfs_context.h>
34#include <sys/spa.h>
35#include <sys/dmu.h>
36#include <sys/stat.h>
37#include <sys/resource.h>
38#include <sys/zil.h>
39#include <sys/zil_impl.h>
40
41extern uint8_t dump_opt[256];
42
43static void
44print_log_bp(const blkptr_t *bp, const char *prefix)
45{
46 char blkbuf[BP_SPRINTF_LEN];
47
48 sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp);
49 (void) printf("%s%s\n", prefix, blkbuf);
50}
51
52/* ARGSUSED */
53static void
54zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
55{
56 time_t crtime = lr->lr_crtime[0];
57 char *name = (char *)(lr + 1);
58 char *link = name + strlen(name) + 1;
59
60 if (txtype == TX_SYMLINK)
61 (void) printf("\t\t\t%s -> %s\n", name, link);
62 else
63 (void) printf("\t\t\t%s\n", name);
64
65 (void) printf("\t\t\t%s", ctime(&crtime));
66 (void) printf("\t\t\tdoid %llu, foid %llu, mode %llo\n",
67 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
68 (longlong_t)lr->lr_mode);
69 (void) printf("\t\t\tuid %llu, gid %llu, gen %llu, rdev 0x%llx\n",
70 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
71 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
72}
73
74/* ARGSUSED */
75static void
76zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
77{
78 (void) printf("\t\t\tdoid %llu, name %s\n",
79 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
80}
81
82/* ARGSUSED */
83static void
84zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
85{
86 (void) printf("\t\t\tdoid %llu, link_obj %llu, name %s\n",
87 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
88 (char *)(lr + 1));
89}
90
91/* ARGSUSED */
92static void
93zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
94{
95 char *snm = (char *)(lr + 1);
96 char *tnm = snm + strlen(snm) + 1;
97
98 (void) printf("\t\t\tsdoid %llu, tdoid %llu\n",
99 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
100 (void) printf("\t\t\tsrc %s tgt %s\n", snm, tnm);
101}
102
103/* ARGSUSED */
104static void
105zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
106{
107 char *data, *dlimit;
108 blkptr_t *bp = &lr->lr_blkptr;
109 char buf[SPA_MAXBLOCKSIZE];
110 int verbose = MAX(dump_opt['d'], dump_opt['i']);
111 int error;
112
113 (void) printf("\t\t\tfoid %llu, offset 0x%llx,"
114 " length 0x%llx, blkoff 0x%llx\n",
115 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
116 (u_longlong_t)lr->lr_length, (u_longlong_t)lr->lr_blkoff);
117
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/*
27 * Print intent log header and statistics.
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <ctype.h>
33#include <sys/zfs_context.h>
34#include <sys/spa.h>
35#include <sys/dmu.h>
36#include <sys/stat.h>
37#include <sys/resource.h>
38#include <sys/zil.h>
39#include <sys/zil_impl.h>
40
41extern uint8_t dump_opt[256];
42
43static void
44print_log_bp(const blkptr_t *bp, const char *prefix)
45{
46 char blkbuf[BP_SPRINTF_LEN];
47
48 sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp);
49 (void) printf("%s%s\n", prefix, blkbuf);
50}
51
52/* ARGSUSED */
53static void
54zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
55{
56 time_t crtime = lr->lr_crtime[0];
57 char *name = (char *)(lr + 1);
58 char *link = name + strlen(name) + 1;
59
60 if (txtype == TX_SYMLINK)
61 (void) printf("\t\t\t%s -> %s\n", name, link);
62 else
63 (void) printf("\t\t\t%s\n", name);
64
65 (void) printf("\t\t\t%s", ctime(&crtime));
66 (void) printf("\t\t\tdoid %llu, foid %llu, mode %llo\n",
67 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
68 (longlong_t)lr->lr_mode);
69 (void) printf("\t\t\tuid %llu, gid %llu, gen %llu, rdev 0x%llx\n",
70 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
71 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
72}
73
74/* ARGSUSED */
75static void
76zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
77{
78 (void) printf("\t\t\tdoid %llu, name %s\n",
79 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
80}
81
82/* ARGSUSED */
83static void
84zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
85{
86 (void) printf("\t\t\tdoid %llu, link_obj %llu, name %s\n",
87 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
88 (char *)(lr + 1));
89}
90
91/* ARGSUSED */
92static void
93zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
94{
95 char *snm = (char *)(lr + 1);
96 char *tnm = snm + strlen(snm) + 1;
97
98 (void) printf("\t\t\tsdoid %llu, tdoid %llu\n",
99 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
100 (void) printf("\t\t\tsrc %s tgt %s\n", snm, tnm);
101}
102
103/* ARGSUSED */
104static void
105zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
106{
107 char *data, *dlimit;
108 blkptr_t *bp = &lr->lr_blkptr;
109 char buf[SPA_MAXBLOCKSIZE];
110 int verbose = MAX(dump_opt['d'], dump_opt['i']);
111 int error;
112
113 (void) printf("\t\t\tfoid %llu, offset 0x%llx,"
114 " length 0x%llx, blkoff 0x%llx\n",
115 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
116 (u_longlong_t)lr->lr_length, (u_longlong_t)lr->lr_blkoff);
117
118 if (verbose < 5)
118 if (txtype == TX_WRITE2 || verbose < 5)
119 return;
120
121 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
122 (void) printf("\t\t\thas blkptr, %s\n",
123 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
124 "will claim" : "won't claim");
125 print_log_bp(bp, "\t\t\t");
119 return;
120
121 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
122 (void) printf("\t\t\thas blkptr, %s\n",
123 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
124 "will claim" : "won't claim");
125 print_log_bp(bp, "\t\t\t");
126 if (BP_IS_HOLE(bp)) {
127 (void) printf("\t\t\tLSIZE 0x%llx\n",
128 (u_longlong_t)BP_GET_LSIZE(bp));
129 }
126 if (bp->blk_birth == 0) {
127 bzero(buf, sizeof (buf));
128 } else {
129 zbookmark_t zb;
130
130 if (bp->blk_birth == 0) {
131 bzero(buf, sizeof (buf));
132 } else {
133 zbookmark_t zb;
134
131 ASSERT3U(bp->blk_cksum.zc_word[ZIL_ZC_OBJSET], ==,
132 dmu_objset_id(zilog->zl_os));
135 zb.zb_objset = dmu_objset_id(zilog->zl_os);
136 zb.zb_object = lr->lr_foid;
137 zb.zb_level = 0;
138 zb.zb_blkid = -1; /* unknown */
133
139
134 zb.zb_objset = bp->blk_cksum.zc_word[ZIL_ZC_OBJSET];
135 zb.zb_object = 0;
136 zb.zb_level = -1;
137 zb.zb_blkid = bp->blk_cksum.zc_word[ZIL_ZC_SEQ];
138
139 error = zio_wait(zio_read(NULL, zilog->zl_spa,
140 bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
141 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
142 if (error)
143 return;
144 }
145 data = buf + lr->lr_blkoff;
146 } else {
147 data = (char *)(lr + 1);
148 }
149
150 dlimit = data + MIN(lr->lr_length,
151 (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
152
153 (void) printf("\t\t\t");
154 while (data < dlimit) {
155 if (isprint(*data))
156 (void) printf("%c ", *data);
157 else
158 (void) printf("%2X", *data);
159 data++;
160 }
161 (void) printf("\n");
162}
163
164/* ARGSUSED */
165static void
166zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
167{
168 (void) printf("\t\t\tfoid %llu, offset 0x%llx, length 0x%llx\n",
169 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
170 (u_longlong_t)lr->lr_length);
171}
172
173/* ARGSUSED */
174static void
175zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
176{
177 time_t atime = (time_t)lr->lr_atime[0];
178 time_t mtime = (time_t)lr->lr_mtime[0];
179
180 (void) printf("\t\t\tfoid %llu, mask 0x%llx\n",
181 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
182
183 if (lr->lr_mask & AT_MODE) {
184 (void) printf("\t\t\tAT_MODE %llo\n",
185 (longlong_t)lr->lr_mode);
186 }
187
188 if (lr->lr_mask & AT_UID) {
189 (void) printf("\t\t\tAT_UID %llu\n",
190 (u_longlong_t)lr->lr_uid);
191 }
192
193 if (lr->lr_mask & AT_GID) {
194 (void) printf("\t\t\tAT_GID %llu\n",
195 (u_longlong_t)lr->lr_gid);
196 }
197
198 if (lr->lr_mask & AT_SIZE) {
199 (void) printf("\t\t\tAT_SIZE %llu\n",
200 (u_longlong_t)lr->lr_size);
201 }
202
203 if (lr->lr_mask & AT_ATIME) {
204 (void) printf("\t\t\tAT_ATIME %llu.%09llu %s",
205 (u_longlong_t)lr->lr_atime[0],
206 (u_longlong_t)lr->lr_atime[1],
207 ctime(&atime));
208 }
209
210 if (lr->lr_mask & AT_MTIME) {
211 (void) printf("\t\t\tAT_MTIME %llu.%09llu %s",
212 (u_longlong_t)lr->lr_mtime[0],
213 (u_longlong_t)lr->lr_mtime[1],
214 ctime(&mtime));
215 }
216}
217
218/* ARGSUSED */
219static void
220zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
221{
222 (void) printf("\t\t\tfoid %llu, aclcnt %llu\n",
223 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
224}
225
226typedef void (*zil_prt_rec_func_t)();
227typedef struct zil_rec_info {
228 zil_prt_rec_func_t zri_print;
229 char *zri_name;
230 uint64_t zri_count;
231} zil_rec_info_t;
232
233static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
234 { NULL, "Total " },
235 { zil_prt_rec_create, "TX_CREATE " },
236 { zil_prt_rec_create, "TX_MKDIR " },
237 { zil_prt_rec_create, "TX_MKXATTR " },
238 { zil_prt_rec_create, "TX_SYMLINK " },
239 { zil_prt_rec_remove, "TX_REMOVE " },
240 { zil_prt_rec_remove, "TX_RMDIR " },
241 { zil_prt_rec_link, "TX_LINK " },
242 { zil_prt_rec_rename, "TX_RENAME " },
243 { zil_prt_rec_write, "TX_WRITE " },
244 { zil_prt_rec_truncate, "TX_TRUNCATE " },
245 { zil_prt_rec_setattr, "TX_SETATTR " },
246 { zil_prt_rec_acl, "TX_ACL_V0 " },
247 { zil_prt_rec_acl, "TX_ACL_ACL " },
248 { zil_prt_rec_create, "TX_CREATE_ACL " },
249 { zil_prt_rec_create, "TX_CREATE_ATTR " },
250 { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
251 { zil_prt_rec_create, "TX_MKDIR_ACL " },
252 { zil_prt_rec_create, "TX_MKDIR_ATTR " },
253 { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
140 error = zio_wait(zio_read(NULL, zilog->zl_spa,
141 bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
142 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
143 if (error)
144 return;
145 }
146 data = buf + lr->lr_blkoff;
147 } else {
148 data = (char *)(lr + 1);
149 }
150
151 dlimit = data + MIN(lr->lr_length,
152 (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
153
154 (void) printf("\t\t\t");
155 while (data < dlimit) {
156 if (isprint(*data))
157 (void) printf("%c ", *data);
158 else
159 (void) printf("%2X", *data);
160 data++;
161 }
162 (void) printf("\n");
163}
164
165/* ARGSUSED */
166static void
167zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
168{
169 (void) printf("\t\t\tfoid %llu, offset 0x%llx, length 0x%llx\n",
170 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
171 (u_longlong_t)lr->lr_length);
172}
173
174/* ARGSUSED */
175static void
176zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
177{
178 time_t atime = (time_t)lr->lr_atime[0];
179 time_t mtime = (time_t)lr->lr_mtime[0];
180
181 (void) printf("\t\t\tfoid %llu, mask 0x%llx\n",
182 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
183
184 if (lr->lr_mask & AT_MODE) {
185 (void) printf("\t\t\tAT_MODE %llo\n",
186 (longlong_t)lr->lr_mode);
187 }
188
189 if (lr->lr_mask & AT_UID) {
190 (void) printf("\t\t\tAT_UID %llu\n",
191 (u_longlong_t)lr->lr_uid);
192 }
193
194 if (lr->lr_mask & AT_GID) {
195 (void) printf("\t\t\tAT_GID %llu\n",
196 (u_longlong_t)lr->lr_gid);
197 }
198
199 if (lr->lr_mask & AT_SIZE) {
200 (void) printf("\t\t\tAT_SIZE %llu\n",
201 (u_longlong_t)lr->lr_size);
202 }
203
204 if (lr->lr_mask & AT_ATIME) {
205 (void) printf("\t\t\tAT_ATIME %llu.%09llu %s",
206 (u_longlong_t)lr->lr_atime[0],
207 (u_longlong_t)lr->lr_atime[1],
208 ctime(&atime));
209 }
210
211 if (lr->lr_mask & AT_MTIME) {
212 (void) printf("\t\t\tAT_MTIME %llu.%09llu %s",
213 (u_longlong_t)lr->lr_mtime[0],
214 (u_longlong_t)lr->lr_mtime[1],
215 ctime(&mtime));
216 }
217}
218
219/* ARGSUSED */
220static void
221zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
222{
223 (void) printf("\t\t\tfoid %llu, aclcnt %llu\n",
224 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
225}
226
227typedef void (*zil_prt_rec_func_t)();
228typedef struct zil_rec_info {
229 zil_prt_rec_func_t zri_print;
230 char *zri_name;
231 uint64_t zri_count;
232} zil_rec_info_t;
233
234static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
235 { NULL, "Total " },
236 { zil_prt_rec_create, "TX_CREATE " },
237 { zil_prt_rec_create, "TX_MKDIR " },
238 { zil_prt_rec_create, "TX_MKXATTR " },
239 { zil_prt_rec_create, "TX_SYMLINK " },
240 { zil_prt_rec_remove, "TX_REMOVE " },
241 { zil_prt_rec_remove, "TX_RMDIR " },
242 { zil_prt_rec_link, "TX_LINK " },
243 { zil_prt_rec_rename, "TX_RENAME " },
244 { zil_prt_rec_write, "TX_WRITE " },
245 { zil_prt_rec_truncate, "TX_TRUNCATE " },
246 { zil_prt_rec_setattr, "TX_SETATTR " },
247 { zil_prt_rec_acl, "TX_ACL_V0 " },
248 { zil_prt_rec_acl, "TX_ACL_ACL " },
249 { zil_prt_rec_create, "TX_CREATE_ACL " },
250 { zil_prt_rec_create, "TX_CREATE_ATTR " },
251 { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
252 { zil_prt_rec_create, "TX_MKDIR_ACL " },
253 { zil_prt_rec_create, "TX_MKDIR_ATTR " },
254 { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
255 { zil_prt_rec_write, "TX_WRITE2 " },
254};
255
256/* ARGSUSED */
257static void
258print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
259{
260 int txtype;
261 int verbose = MAX(dump_opt['d'], dump_opt['i']);
262
263 /* reduce size of txtype to strip off TX_CI bit */
264 txtype = lr->lrc_txtype;
265
266 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
267 ASSERT(lr->lrc_txg);
268
269 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
270 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
271 zil_rec_info[txtype].zri_name,
272 (u_longlong_t)lr->lrc_reclen,
273 (u_longlong_t)lr->lrc_txg,
274 (u_longlong_t)lr->lrc_seq);
275
276 if (txtype && verbose >= 3)
277 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
278
279 zil_rec_info[txtype].zri_count++;
280 zil_rec_info[0].zri_count++;
281}
282
283/* ARGSUSED */
284static void
285print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
286{
287 char blkbuf[BP_SPRINTF_LEN];
288 int verbose = MAX(dump_opt['d'], dump_opt['i']);
289 char *claim;
290
291 if (verbose <= 3)
292 return;
293
294 if (verbose >= 5) {
295 (void) strcpy(blkbuf, ", ");
296 sprintf_blkptr(blkbuf + strlen(blkbuf),
297 BP_SPRINTF_LEN - strlen(blkbuf), bp);
298 } else {
299 blkbuf[0] = '\0';
300 }
301
302 if (claim_txg != 0)
303 claim = "already claimed";
304 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
305 claim = "will claim";
306 else
307 claim = "won't claim";
308
309 (void) printf("\tBlock seqno %llu, %s%s\n",
310 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
311}
312
313static void
314print_log_stats(int verbose)
315{
316 int i, w, p10;
317
318 if (verbose > 3)
319 (void) printf("\n");
320
321 if (zil_rec_info[0].zri_count == 0)
322 return;
323
324 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
325 w++;
326
327 for (i = 0; i < TX_MAX_TYPE; i++)
328 if (zil_rec_info[i].zri_count || verbose >= 3)
329 (void) printf("\t\t%s %*llu\n",
330 zil_rec_info[i].zri_name, w,
331 (u_longlong_t)zil_rec_info[i].zri_count);
332 (void) printf("\n");
333}
334
335/* ARGSUSED */
336void
337dump_intent_log(zilog_t *zilog)
338{
339 const zil_header_t *zh = zilog->zl_header;
340 int verbose = MAX(dump_opt['d'], dump_opt['i']);
341 int i;
342
343 if (zh->zh_log.blk_birth == 0 || verbose < 2)
344 return;
345
346 (void) printf("\n ZIL header: claim_txg %llu, claim_seq %llu",
347 (u_longlong_t)zh->zh_claim_txg, (u_longlong_t)zh->zh_claim_seq);
348 (void) printf(" replay_seq %llu, flags 0x%llx\n",
349 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
350
351 if (verbose >= 4)
352 print_log_bp(&zh->zh_log, "\n\tfirst block: ");
353
354 for (i = 0; i < TX_MAX_TYPE; i++)
355 zil_rec_info[i].zri_count = 0;
356
357 if (verbose >= 2) {
358 (void) printf("\n");
359 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
360 zh->zh_claim_txg);
361 print_log_stats(verbose);
362 }
363}
256};
257
258/* ARGSUSED */
259static void
260print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
261{
262 int txtype;
263 int verbose = MAX(dump_opt['d'], dump_opt['i']);
264
265 /* reduce size of txtype to strip off TX_CI bit */
266 txtype = lr->lrc_txtype;
267
268 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
269 ASSERT(lr->lrc_txg);
270
271 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
272 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
273 zil_rec_info[txtype].zri_name,
274 (u_longlong_t)lr->lrc_reclen,
275 (u_longlong_t)lr->lrc_txg,
276 (u_longlong_t)lr->lrc_seq);
277
278 if (txtype && verbose >= 3)
279 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
280
281 zil_rec_info[txtype].zri_count++;
282 zil_rec_info[0].zri_count++;
283}
284
285/* ARGSUSED */
286static void
287print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
288{
289 char blkbuf[BP_SPRINTF_LEN];
290 int verbose = MAX(dump_opt['d'], dump_opt['i']);
291 char *claim;
292
293 if (verbose <= 3)
294 return;
295
296 if (verbose >= 5) {
297 (void) strcpy(blkbuf, ", ");
298 sprintf_blkptr(blkbuf + strlen(blkbuf),
299 BP_SPRINTF_LEN - strlen(blkbuf), bp);
300 } else {
301 blkbuf[0] = '\0';
302 }
303
304 if (claim_txg != 0)
305 claim = "already claimed";
306 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
307 claim = "will claim";
308 else
309 claim = "won't claim";
310
311 (void) printf("\tBlock seqno %llu, %s%s\n",
312 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
313}
314
315static void
316print_log_stats(int verbose)
317{
318 int i, w, p10;
319
320 if (verbose > 3)
321 (void) printf("\n");
322
323 if (zil_rec_info[0].zri_count == 0)
324 return;
325
326 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
327 w++;
328
329 for (i = 0; i < TX_MAX_TYPE; i++)
330 if (zil_rec_info[i].zri_count || verbose >= 3)
331 (void) printf("\t\t%s %*llu\n",
332 zil_rec_info[i].zri_name, w,
333 (u_longlong_t)zil_rec_info[i].zri_count);
334 (void) printf("\n");
335}
336
337/* ARGSUSED */
338void
339dump_intent_log(zilog_t *zilog)
340{
341 const zil_header_t *zh = zilog->zl_header;
342 int verbose = MAX(dump_opt['d'], dump_opt['i']);
343 int i;
344
345 if (zh->zh_log.blk_birth == 0 || verbose < 2)
346 return;
347
348 (void) printf("\n ZIL header: claim_txg %llu, claim_seq %llu",
349 (u_longlong_t)zh->zh_claim_txg, (u_longlong_t)zh->zh_claim_seq);
350 (void) printf(" replay_seq %llu, flags 0x%llx\n",
351 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
352
353 if (verbose >= 4)
354 print_log_bp(&zh->zh_log, "\n\tfirst block: ");
355
356 for (i = 0; i < TX_MAX_TYPE; i++)
357 zil_rec_info[i].zri_count = 0;
358
359 if (verbose >= 2) {
360 (void) printf("\n");
361 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
362 zh->zh_claim_txg);
363 print_log_stats(verbose);
364 }
365}