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 https://opensource.org/licenses/CDDL-1.0.
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, 2017 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>
45 #include <sys/spa_impl.h>
50 extern uint8_t dump_opt
[256];
52 static char tab_prefix
[4] = "\t\t\t";
55 print_log_bp(const blkptr_t
*bp
, const char *prefix
)
57 char blkbuf
[BP_SPRINTF_LEN
];
59 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
60 (void) printf("%s%s\n", prefix
, blkbuf
);
64 zil_prt_rec_create(zilog_t
*zilog
, int txtype
, const void *arg
)
67 const lr_create_t
*lr
= arg
;
68 time_t crtime
= lr
->lr_crtime
[0];
72 name
= (char *)(lr
+ 1);
74 if (lr
->lr_common
.lrc_txtype
== TX_CREATE_ATTR
||
75 lr
->lr_common
.lrc_txtype
== TX_MKDIR_ATTR
) {
76 lrattr
= (lr_attr_t
*)(lr
+ 1);
77 name
+= ZIL_XVAT_SIZE(lrattr
->lr_attr_masksize
);
80 if (txtype
== TX_SYMLINK
) {
81 link
= name
+ strlen(name
) + 1;
82 (void) printf("%s%s -> %s\n", tab_prefix
, name
, link
);
83 } else if (txtype
!= TX_MKXATTR
) {
84 (void) printf("%s%s\n", tab_prefix
, name
);
87 (void) printf("%s%s", tab_prefix
, ctime(&crtime
));
88 (void) printf("%sdoid %llu, foid %llu, slots %llu, mode %llo\n",
89 tab_prefix
, (u_longlong_t
)lr
->lr_doid
,
90 (u_longlong_t
)LR_FOID_GET_OBJ(lr
->lr_foid
),
91 (u_longlong_t
)LR_FOID_GET_SLOTS(lr
->lr_foid
),
92 (longlong_t
)lr
->lr_mode
);
93 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n",
95 (u_longlong_t
)lr
->lr_uid
, (u_longlong_t
)lr
->lr_gid
,
96 (u_longlong_t
)lr
->lr_gen
, (u_longlong_t
)lr
->lr_rdev
);
100 zil_prt_rec_remove(zilog_t
*zilog
, int txtype
, const void *arg
)
102 (void) zilog
, (void) txtype
;
103 const lr_remove_t
*lr
= arg
;
105 (void) printf("%sdoid %llu, name %s\n", tab_prefix
,
106 (u_longlong_t
)lr
->lr_doid
, (char *)(lr
+ 1));
110 zil_prt_rec_link(zilog_t
*zilog
, int txtype
, const void *arg
)
112 (void) zilog
, (void) txtype
;
113 const lr_link_t
*lr
= arg
;
115 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", tab_prefix
,
116 (u_longlong_t
)lr
->lr_doid
, (u_longlong_t
)lr
->lr_link_obj
,
121 zil_prt_rec_rename(zilog_t
*zilog
, int txtype
, const void *arg
)
123 (void) zilog
, (void) txtype
;
124 const lr_rename_t
*lr
= arg
;
125 char *snm
= (char *)(lr
+ 1);
126 char *tnm
= snm
+ strlen(snm
) + 1;
128 (void) printf("%ssdoid %llu, tdoid %llu\n", tab_prefix
,
129 (u_longlong_t
)lr
->lr_sdoid
, (u_longlong_t
)lr
->lr_tdoid
);
130 (void) printf("%ssrc %s tgt %s\n", tab_prefix
, snm
, tnm
);
132 case TX_RENAME_EXCHANGE
:
133 (void) printf("%sflags RENAME_EXCHANGE\n", tab_prefix
);
135 case TX_RENAME_WHITEOUT
:
136 (void) printf("%sflags RENAME_WHITEOUT\n", tab_prefix
);
142 zil_prt_rec_write_cb(void *data
, size_t len
, void *unused
)
147 for (size_t i
= 0; i
< len
; i
++) {
149 (void) printf("%c ", *cdata
);
151 (void) printf("%2X", *cdata
);
158 zil_prt_rec_write(zilog_t
*zilog
, int txtype
, const void *arg
)
160 const lr_write_t
*lr
= arg
;
162 const blkptr_t
*bp
= &lr
->lr_blkptr
;
164 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
167 (void) printf("%sfoid %llu, offset %llx, length %llx\n", tab_prefix
,
168 (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_offset
,
169 (u_longlong_t
)lr
->lr_length
);
171 if (txtype
== TX_WRITE2
|| verbose
< 5)
174 if (lr
->lr_common
.lrc_reclen
== sizeof (lr_write_t
)) {
175 (void) printf("%shas blkptr, %s\n", tab_prefix
,
177 bp
->blk_birth
>= spa_min_claim_txg(zilog
->zl_spa
) ?
178 "will claim" : "won't claim");
179 print_log_bp(bp
, tab_prefix
);
181 if (BP_IS_HOLE(bp
)) {
182 (void) printf("\t\t\tLSIZE 0x%llx\n",
183 (u_longlong_t
)BP_GET_LSIZE(bp
));
184 (void) printf("%s<hole>\n", tab_prefix
);
187 if (bp
->blk_birth
< zilog
->zl_header
->zh_claim_txg
) {
188 (void) printf("%s<block already committed>\n",
193 ASSERT3U(BP_GET_LSIZE(bp
), !=, 0);
194 SET_BOOKMARK(&zb
, dmu_objset_id(zilog
->zl_os
),
195 lr
->lr_foid
, ZB_ZIL_LEVEL
,
196 lr
->lr_offset
/ BP_GET_LSIZE(bp
));
198 data
= abd_alloc(BP_GET_LSIZE(bp
), B_FALSE
);
199 error
= zio_wait(zio_read(NULL
, zilog
->zl_spa
,
200 bp
, data
, BP_GET_LSIZE(bp
), NULL
, NULL
,
201 ZIO_PRIORITY_SYNC_READ
, ZIO_FLAG_CANFAIL
, &zb
));
205 /* data is stored after the end of the lr_write record */
206 data
= abd_alloc(lr
->lr_length
, B_FALSE
);
207 abd_copy_from_buf(data
, lr
+ 1, lr
->lr_length
);
210 (void) printf("%s", tab_prefix
);
211 (void) abd_iterate_func(data
,
212 0, MIN(lr
->lr_length
, (verbose
< 6 ? 20 : SPA_MAXBLOCKSIZE
)),
213 zil_prt_rec_write_cb
, NULL
);
221 zil_prt_rec_truncate(zilog_t
*zilog
, int txtype
, const void *arg
)
223 (void) zilog
, (void) txtype
;
224 const lr_truncate_t
*lr
= arg
;
226 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", tab_prefix
,
227 (u_longlong_t
)lr
->lr_foid
, (longlong_t
)lr
->lr_offset
,
228 (u_longlong_t
)lr
->lr_length
);
232 zil_prt_rec_setattr(zilog_t
*zilog
, int txtype
, const void *arg
)
234 (void) zilog
, (void) txtype
;
235 const lr_setattr_t
*lr
= arg
;
236 time_t atime
= (time_t)lr
->lr_atime
[0];
237 time_t mtime
= (time_t)lr
->lr_mtime
[0];
239 (void) printf("%sfoid %llu, mask 0x%llx\n", tab_prefix
,
240 (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_mask
);
242 if (lr
->lr_mask
& AT_MODE
) {
243 (void) printf("%sAT_MODE %llo\n", tab_prefix
,
244 (longlong_t
)lr
->lr_mode
);
247 if (lr
->lr_mask
& AT_UID
) {
248 (void) printf("%sAT_UID %llu\n", tab_prefix
,
249 (u_longlong_t
)lr
->lr_uid
);
252 if (lr
->lr_mask
& AT_GID
) {
253 (void) printf("%sAT_GID %llu\n", tab_prefix
,
254 (u_longlong_t
)lr
->lr_gid
);
257 if (lr
->lr_mask
& AT_SIZE
) {
258 (void) printf("%sAT_SIZE %llu\n", tab_prefix
,
259 (u_longlong_t
)lr
->lr_size
);
262 if (lr
->lr_mask
& AT_ATIME
) {
263 (void) printf("%sAT_ATIME %llu.%09llu %s", tab_prefix
,
264 (u_longlong_t
)lr
->lr_atime
[0],
265 (u_longlong_t
)lr
->lr_atime
[1],
269 if (lr
->lr_mask
& AT_MTIME
) {
270 (void) printf("%sAT_MTIME %llu.%09llu %s", tab_prefix
,
271 (u_longlong_t
)lr
->lr_mtime
[0],
272 (u_longlong_t
)lr
->lr_mtime
[1],
278 zil_prt_rec_setsaxattr(zilog_t
*zilog
, int txtype
, const void *arg
)
280 (void) zilog
, (void) txtype
;
281 const lr_setsaxattr_t
*lr
= arg
;
283 char *name
= (char *)(lr
+ 1);
284 (void) printf("%sfoid %llu\n", tab_prefix
,
285 (u_longlong_t
)lr
->lr_foid
);
287 (void) printf("%sXAT_NAME %s\n", tab_prefix
, name
);
288 if (lr
->lr_size
== 0) {
289 (void) printf("%sXAT_VALUE NULL\n", tab_prefix
);
291 (void) printf("%sXAT_VALUE ", tab_prefix
);
292 char *val
= name
+ (strlen(name
) + 1);
293 for (int i
= 0; i
< lr
->lr_size
; i
++) {
294 (void) printf("%c", *val
);
301 zil_prt_rec_acl(zilog_t
*zilog
, int txtype
, const void *arg
)
303 (void) zilog
, (void) txtype
;
304 const lr_acl_t
*lr
= arg
;
306 (void) printf("%sfoid %llu, aclcnt %llu\n", tab_prefix
,
307 (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_aclcnt
);
311 zil_prt_rec_clone_range(zilog_t
*zilog
, int txtype
, const void *arg
)
313 (void) zilog
, (void) txtype
;
314 const lr_clone_range_t
*lr
= arg
;
316 (void) printf("%sfoid %llu, offset %llx, length %llx, blksize %llx\n",
317 tab_prefix
, (u_longlong_t
)lr
->lr_foid
, (u_longlong_t
)lr
->lr_offset
,
318 (u_longlong_t
)lr
->lr_length
, (u_longlong_t
)lr
->lr_blksz
);
320 for (unsigned int i
= 0; i
< lr
->lr_nbps
; i
++) {
321 (void) printf("%s[%u/%llu] ", tab_prefix
, i
+ 1,
322 (u_longlong_t
)lr
->lr_nbps
);
323 print_log_bp(&lr
->lr_bps
[i
], "");
327 typedef void (*zil_prt_rec_func_t
)(zilog_t
*, int, const void *);
328 typedef struct zil_rec_info
{
329 zil_prt_rec_func_t zri_print
;
330 const char *zri_name
;
334 static zil_rec_info_t zil_rec_info
[TX_MAX_TYPE
] = {
335 {.zri_print
= NULL
, .zri_name
= "Total "},
336 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_CREATE "},
337 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_MKDIR "},
338 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_MKXATTR "},
339 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_SYMLINK "},
340 {.zri_print
= zil_prt_rec_remove
, .zri_name
= "TX_REMOVE "},
341 {.zri_print
= zil_prt_rec_remove
, .zri_name
= "TX_RMDIR "},
342 {.zri_print
= zil_prt_rec_link
, .zri_name
= "TX_LINK "},
343 {.zri_print
= zil_prt_rec_rename
, .zri_name
= "TX_RENAME "},
344 {.zri_print
= zil_prt_rec_write
, .zri_name
= "TX_WRITE "},
345 {.zri_print
= zil_prt_rec_truncate
, .zri_name
= "TX_TRUNCATE "},
346 {.zri_print
= zil_prt_rec_setattr
, .zri_name
= "TX_SETATTR "},
347 {.zri_print
= zil_prt_rec_acl
, .zri_name
= "TX_ACL_V0 "},
348 {.zri_print
= zil_prt_rec_acl
, .zri_name
= "TX_ACL_ACL "},
349 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_CREATE_ACL "},
350 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_CREATE_ATTR "},
351 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_CREATE_ACL_ATTR "},
352 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_MKDIR_ACL "},
353 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_MKDIR_ATTR "},
354 {.zri_print
= zil_prt_rec_create
, .zri_name
= "TX_MKDIR_ACL_ATTR "},
355 {.zri_print
= zil_prt_rec_write
, .zri_name
= "TX_WRITE2 "},
356 {.zri_print
= zil_prt_rec_setsaxattr
,
357 .zri_name
= "TX_SETSAXATTR "},
358 {.zri_print
= zil_prt_rec_rename
, .zri_name
= "TX_RENAME_EXCHANGE "},
359 {.zri_print
= zil_prt_rec_rename
, .zri_name
= "TX_RENAME_WHITEOUT "},
360 {.zri_print
= zil_prt_rec_clone_range
,
361 .zri_name
= "TX_CLONE_RANGE "},
365 print_log_record(zilog_t
*zilog
, const lr_t
*lr
, void *arg
, uint64_t claim_txg
)
367 (void) arg
, (void) claim_txg
;
369 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
371 /* reduce size of txtype to strip off TX_CI bit */
372 txtype
= lr
->lrc_txtype
;
374 ASSERT(txtype
!= 0 && (uint_t
)txtype
< TX_MAX_TYPE
);
377 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
378 (lr
->lrc_txtype
& TX_CI
) ? "CI-" : "",
379 zil_rec_info
[txtype
].zri_name
,
380 (u_longlong_t
)lr
->lrc_reclen
,
381 (u_longlong_t
)lr
->lrc_txg
,
382 (u_longlong_t
)lr
->lrc_seq
);
384 if (txtype
&& verbose
>= 3) {
385 if (!zilog
->zl_os
->os_encrypted
) {
386 zil_rec_info
[txtype
].zri_print(zilog
, txtype
, lr
);
388 (void) printf("%s(encrypted)\n", tab_prefix
);
392 zil_rec_info
[txtype
].zri_count
++;
393 zil_rec_info
[0].zri_count
++;
399 print_log_block(zilog_t
*zilog
, const blkptr_t
*bp
, void *arg
,
403 char blkbuf
[BP_SPRINTF_LEN
+ 10];
404 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
411 (void) strcpy(blkbuf
, ", ");
412 snprintf_blkptr(blkbuf
+ strlen(blkbuf
),
413 sizeof (blkbuf
) - strlen(blkbuf
), bp
);
419 claim
= "already claimed";
420 else if (bp
->blk_birth
>= spa_min_claim_txg(zilog
->zl_spa
))
421 claim
= "will claim";
423 claim
= "won't claim";
425 (void) printf("\tBlock seqno %llu, %s%s\n",
426 (u_longlong_t
)bp
->blk_cksum
.zc_word
[ZIL_ZC_SEQ
], claim
, blkbuf
);
432 print_log_stats(int verbose
)
439 if (zil_rec_info
[0].zri_count
== 0)
442 for (w
= 1, p10
= 10; zil_rec_info
[0].zri_count
>= p10
; p10
*= 10)
445 for (i
= 0; i
< TX_MAX_TYPE
; i
++)
446 if (zil_rec_info
[i
].zri_count
|| verbose
>= 3)
447 (void) printf("\t\t%s %*llu\n",
448 zil_rec_info
[i
].zri_name
, w
,
449 (u_longlong_t
)zil_rec_info
[i
].zri_count
);
454 dump_intent_log(zilog_t
*zilog
)
456 const zil_header_t
*zh
= zilog
->zl_header
;
457 int verbose
= MAX(dump_opt
['d'], dump_opt
['i']);
460 if (BP_IS_HOLE(&zh
->zh_log
) || verbose
< 1)
463 (void) printf("\n ZIL header: claim_txg %llu, "
464 "claim_blk_seq %llu, claim_lr_seq %llu",
465 (u_longlong_t
)zh
->zh_claim_txg
,
466 (u_longlong_t
)zh
->zh_claim_blk_seq
,
467 (u_longlong_t
)zh
->zh_claim_lr_seq
);
468 (void) printf(" replay_seq %llu, flags 0x%llx\n",
469 (u_longlong_t
)zh
->zh_replay_seq
, (u_longlong_t
)zh
->zh_flags
);
471 for (i
= 0; i
< TX_MAX_TYPE
; i
++)
472 zil_rec_info
[i
].zri_count
= 0;
474 /* see comment in zil_claim() or zil_check_log_chain() */
475 if (zilog
->zl_spa
->spa_uberblock
.ub_checkpoint_txg
!= 0 &&
476 zh
->zh_claim_txg
== 0)
481 (void) zil_parse(zilog
, print_log_block
, print_log_record
, NULL
,
482 zh
->zh_claim_txg
, B_FALSE
);
483 print_log_stats(verbose
);