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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Copyright (c) 2012 Cyril Plisko. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
32 * Print intent log header and statistics.
38 #include <sys/zfs_context.h>
42 #include <sys/resource.h>
44 #include <sys/zil_impl.h>
47 extern uint8_t dump_opt
[256];
49 static char prefix
[4] = "\t\t\t";
52 print_log_bp(const blkptr_t
*bp
, const char *prefix
)
54 char blkbuf
[BP_SPRINTF_LEN
];
56 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
57 (void) printf("%s%s\n", prefix
, blkbuf
);
62 zil_prt_rec_create(zilog_t
*zilog
, int txtype
, lr_create_t
*lr
)
64 time_t crtime
= lr
->lr_crtime
[0];
68 name
= (char *)(lr
+ 1);
70 if (lr
->lr_common
.lrc_txtype
== TX_CREATE_ATTR
||
71 lr
->lr_common
.lrc_txtype
== TX_MKDIR_ATTR
) {
72 lrattr
= (lr_attr_t
*)(lr
+ 1);
73 name
+= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
76 if (txtype
== TX_SYMLINK
) {
77 link
= name
+ strlen(name
) + 1;
78 (void) printf("%s%s -> %s\n", prefix
, name
, link
);
79 } else if (txtype
!= TX_MKXATTR
) {
80 (void) printf("%s%s\n", prefix
, name
);
83 (void) printf("%s%s", prefix
, ctime(&crtime
));
84 (void) printf("%sdoid %llu, foid %llu, slots %llu, mode %llo\n", prefix
,
85 (u_longlong_t
)lr
->lr_doid
,
86 (u_longlong_t
)LR_FOID_GET_OBJ(lr
->lr_foid
),
87 (u_longlong_t
)LR_FOID_GET_SLOTS(lr
->lr_foid
),
88 (longlong_t
)lr
->lr_mode
);
89 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix
,
90 (u_longlong_t
)lr
->lr_uid
, (u_longlong_t
)lr
->lr_gid
,
91 (u_longlong_t
)lr
->lr_gen
, (u_longlong_t
)lr
->lr_rdev
);
96 zil_prt_rec_remove(zilog_t
*zilog
, int txtype
, lr_remove_t
*lr
)
98 (void) printf("%sdoid %llu, name %s\n", prefix
,
99 (u_longlong_t
)lr
->lr_doid
, (char *)(lr
+ 1));
104 zil_prt_rec_link(zilog_t
*zilog
, int txtype
, lr_link_t
*lr
)
106 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix
,
107 (u_longlong_t
)lr
->lr_doid
, (u_longlong_t
)lr
->lr_link_obj
,
113 zil_prt_rec_rename(zilog_t
*zilog
, int txtype
, lr_rename_t
*lr
)
115 char *snm
= (char *)(lr
+ 1);
116 char *tnm
= snm
+ strlen(snm
) + 1;
118 (void) printf("%ssdoid %llu, tdoid %llu\n", prefix
,
119 (u_longlong_t
)lr
->lr_sdoid
, (u_longlong_t
)lr
->lr_tdoid
);
120 (void) printf("%ssrc %s tgt %s\n", prefix
, snm
, tnm
);
125 zil_prt_rec_write_cb(void *data
, size_t len
, void *unused
)
130 for (i
= 0; i
< len
; i
++) {
132 (void) printf("%c ", *cdata
);
134 (void) printf("%2X", *cdata
);
142 zil_prt_rec_write(zilog_t
*zilog
, int txtype
, lr_write_t
*lr
)
145 blkptr_t
*bp
= &lr
->lr_blkptr
;
147 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
150 (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix
,
151 (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_offset
,
152 (u_longlong_t
)lr
->lr_length
);
154 if (txtype
== TX_WRITE2
|| verbose
< 5)
157 if (lr
->lr_common
.lrc_reclen
== sizeof (lr_write_t
)) {
158 (void) printf("%shas blkptr, %s\n", prefix
,
160 bp
->blk_birth
>= spa_first_txg(zilog
->zl_spa
) ?
161 "will claim" : "won't claim");
162 print_log_bp(bp
, prefix
);
164 if (BP_IS_HOLE(bp
)) {
165 (void) printf("\t\t\tLSIZE 0x%llx\n",
166 (u_longlong_t
)BP_GET_LSIZE(bp
));
167 (void) printf("%s<hole>\n", prefix
);
170 if (bp
->blk_birth
< zilog
->zl_header
->zh_claim_txg
) {
171 (void) printf("%s<block already committed>\n", prefix
);
175 SET_BOOKMARK(&zb
, dmu_objset_id(zilog
->zl_os
),
176 lr
->lr_foid
, ZB_ZIL_LEVEL
,
177 lr
->lr_offset
/ BP_GET_LSIZE(bp
));
179 data
= abd_alloc(BP_GET_LSIZE(bp
), B_FALSE
);
180 error
= zio_wait(zio_read(NULL
, zilog
->zl_spa
,
181 bp
, data
, BP_GET_LSIZE(bp
), NULL
, NULL
,
182 ZIO_PRIORITY_SYNC_READ
, ZIO_FLAG_CANFAIL
, &zb
));
186 /* data is stored after the end of the lr_write record */
187 data
= abd_alloc(lr
->lr_length
, B_FALSE
);
188 abd_copy_from_buf(data
, lr
+ 1, lr
->lr_length
);
191 (void) printf("%s", prefix
);
192 (void) abd_iterate_func(data
,
193 0, MIN(lr
->lr_length
, (verbose
< 6 ? 20 : SPA_MAXBLOCKSIZE
)),
194 zil_prt_rec_write_cb
, NULL
);
203 zil_prt_rec_truncate(zilog_t
*zilog
, int txtype
, lr_truncate_t
*lr
)
205 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix
,
206 (u_longlong_t
)lr
->lr_foid
, (longlong_t
)lr
->lr_offset
,
207 (u_longlong_t
)lr
->lr_length
);
212 zil_prt_rec_setattr(zilog_t
*zilog
, int txtype
, lr_setattr_t
*lr
)
214 time_t atime
= (time_t)lr
->lr_atime
[0];
215 time_t mtime
= (time_t)lr
->lr_mtime
[0];
217 (void) printf("%sfoid %llu, mask 0x%llx\n", prefix
,
218 (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_mask
);
220 if (lr
->lr_mask
& AT_MODE
) {
221 (void) printf("%sAT_MODE %llo\n", prefix
,
222 (longlong_t
)lr
->lr_mode
);
225 if (lr
->lr_mask
& AT_UID
) {
226 (void) printf("%sAT_UID %llu\n", prefix
,
227 (u_longlong_t
)lr
->lr_uid
);
230 if (lr
->lr_mask
& AT_GID
) {
231 (void) printf("%sAT_GID %llu\n", prefix
,
232 (u_longlong_t
)lr
->lr_gid
);
235 if (lr
->lr_mask
& AT_SIZE
) {
236 (void) printf("%sAT_SIZE %llu\n", prefix
,
237 (u_longlong_t
)lr
->lr_size
);
240 if (lr
->lr_mask
& AT_ATIME
) {
241 (void) printf("%sAT_ATIME %llu.%09llu %s", prefix
,
242 (u_longlong_t
)lr
->lr_atime
[0],
243 (u_longlong_t
)lr
->lr_atime
[1],
247 if (lr
->lr_mask
& AT_MTIME
) {
248 (void) printf("%sAT_MTIME %llu.%09llu %s", prefix
,
249 (u_longlong_t
)lr
->lr_mtime
[0],
250 (u_longlong_t
)lr
->lr_mtime
[1],
257 zil_prt_rec_acl(zilog_t
*zilog
, int txtype
, lr_acl_t
*lr
)
259 (void) printf("%sfoid %llu, aclcnt %llu\n", prefix
,
260 (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_aclcnt
);
263 typedef void (*zil_prt_rec_func_t
)(zilog_t
*, int, void *);
264 typedef struct zil_rec_info
{
265 zil_prt_rec_func_t zri_print
;
270 static zil_rec_info_t zil_rec_info
[TX_MAX_TYPE
] = {
272 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_CREATE " },
273 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_MKDIR " },
274 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_MKXATTR " },
275 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_SYMLINK " },
276 { (zil_prt_rec_func_t
)zil_prt_rec_remove
, "TX_REMOVE " },
277 { (zil_prt_rec_func_t
)zil_prt_rec_remove
, "TX_RMDIR " },
278 { (zil_prt_rec_func_t
)zil_prt_rec_link
, "TX_LINK " },
279 { (zil_prt_rec_func_t
)zil_prt_rec_rename
, "TX_RENAME " },
280 { (zil_prt_rec_func_t
)zil_prt_rec_write
, "TX_WRITE " },
281 { (zil_prt_rec_func_t
)zil_prt_rec_truncate
, "TX_TRUNCATE " },
282 { (zil_prt_rec_func_t
)zil_prt_rec_setattr
, "TX_SETATTR " },
283 { (zil_prt_rec_func_t
)zil_prt_rec_acl
, "TX_ACL_V0 " },
284 { (zil_prt_rec_func_t
)zil_prt_rec_acl
, "TX_ACL_ACL " },
285 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_CREATE_ACL " },
286 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_CREATE_ATTR " },
287 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_CREATE_ACL_ATTR " },
288 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_MKDIR_ACL " },
289 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_MKDIR_ATTR " },
290 { (zil_prt_rec_func_t
)zil_prt_rec_create
, "TX_MKDIR_ACL_ATTR " },
291 { (zil_prt_rec_func_t
)zil_prt_rec_write
, "TX_WRITE2 " },
296 print_log_record(zilog_t
*zilog
, lr_t
*lr
, void *arg
, uint64_t claim_txg
)
299 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
301 /* reduce size of txtype to strip off TX_CI bit */
302 txtype
= lr
->lrc_txtype
;
304 ASSERT(txtype
!= 0 && (uint_t
)txtype
< TX_MAX_TYPE
);
307 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
308 (lr
->lrc_txtype
& TX_CI
) ? "CI-" : "",
309 zil_rec_info
[txtype
].zri_name
,
310 (u_longlong_t
)lr
->lrc_reclen
,
311 (u_longlong_t
)lr
->lrc_txg
,
312 (u_longlong_t
)lr
->lrc_seq
);
314 if (txtype
&& verbose
>= 3) {
315 if (!zilog
->zl_os
->os_encrypted
) {
316 zil_rec_info
[txtype
].zri_print(zilog
, txtype
, lr
);
318 (void) printf("%s(encrypted)\n", prefix
);
322 zil_rec_info
[txtype
].zri_count
++;
323 zil_rec_info
[0].zri_count
++;
330 print_log_block(zilog_t
*zilog
, blkptr_t
*bp
, void *arg
, uint64_t claim_txg
)
332 char blkbuf
[BP_SPRINTF_LEN
+ 10];
333 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
340 (void) strcpy(blkbuf
, ", ");
341 snprintf_blkptr(blkbuf
+ strlen(blkbuf
),
342 sizeof (blkbuf
) - strlen(blkbuf
), bp
);
348 claim
= "already claimed";
349 else if (bp
->blk_birth
>= spa_first_txg(zilog
->zl_spa
))
350 claim
= "will claim";
352 claim
= "won't claim";
354 (void) printf("\tBlock seqno %llu, %s%s\n",
355 (u_longlong_t
)bp
->blk_cksum
.zc_word
[ZIL_ZC_SEQ
], claim
, blkbuf
);
361 print_log_stats(int verbose
)
368 if (zil_rec_info
[0].zri_count
== 0)
371 for (w
= 1, p10
= 10; zil_rec_info
[0].zri_count
>= p10
; p10
*= 10)
374 for (i
= 0; i
< TX_MAX_TYPE
; i
++)
375 if (zil_rec_info
[i
].zri_count
|| verbose
>= 3)
376 (void) printf("\t\t%s %*llu\n",
377 zil_rec_info
[i
].zri_name
, w
,
378 (u_longlong_t
)zil_rec_info
[i
].zri_count
);
384 dump_intent_log(zilog_t
*zilog
)
386 const zil_header_t
*zh
= zilog
->zl_header
;
387 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
390 if (BP_IS_HOLE(&zh
->zh_log
) || verbose
< 1)
393 (void) printf("\n ZIL header: claim_txg %llu, "
394 "claim_blk_seq %llu, claim_lr_seq %llu",
395 (u_longlong_t
)zh
->zh_claim_txg
,
396 (u_longlong_t
)zh
->zh_claim_blk_seq
,
397 (u_longlong_t
)zh
->zh_claim_lr_seq
);
398 (void) printf(" replay_seq %llu, flags 0x%llx\n",
399 (u_longlong_t
)zh
->zh_replay_seq
, (u_longlong_t
)zh
->zh_flags
);
401 for (i
= 0; i
< TX_MAX_TYPE
; i
++)
402 zil_rec_info
[i
].zri_count
= 0;
406 (void) zil_parse(zilog
, print_log_block
, print_log_record
, NULL
,
407 zh
->zh_claim_txg
, B_FALSE
);
408 print_log_stats(verbose
);