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 * Use is subject to license terms.
27 * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31 * Print intent log header and statistics.
37 #include <sys/zfs_context.h>
41 #include <sys/resource.h>
43 #include <sys/zil_impl.h>
48 extern uint8_t dump_opt[256];
50 static char tab_prefix[4] = "\t\t\t";
53 print_log_bp(const blkptr_t *bp, const char *prefix)
55 char blkbuf[BP_SPRINTF_LEN];
57 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
58 (void) printf("%s%s\n", prefix, blkbuf);
63 zil_prt_rec_create(zilog_t *zilog, int txtype, void *arg)
65 lr_create_t *lr = arg;
66 time_t crtime = lr->lr_crtime[0];
70 name = (char *)(lr + 1);
72 if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
73 lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
74 lrattr = (lr_attr_t *)(lr + 1);
75 name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
78 if (txtype == TX_SYMLINK) {
79 link = name + strlen(name) + 1;
80 (void) printf("%s%s -> %s\n", tab_prefix, name, link);
81 } else if (txtype != TX_MKXATTR) {
82 (void) printf("%s%s\n", tab_prefix, name);
85 (void) printf("%s%s", tab_prefix, ctime(&crtime));
86 (void) printf("%sdoid %llu, foid %llu, mode %llo\n", tab_prefix,
87 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
88 (longlong_t)lr->lr_mode);
89 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n",
91 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
92 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
97 zil_prt_rec_remove(zilog_t *zilog, int txtype, void *arg)
99 lr_remove_t *lr = arg;
101 (void) printf("%sdoid %llu, name %s\n", tab_prefix,
102 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
107 zil_prt_rec_link(zilog_t *zilog, int txtype, void *arg)
111 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", tab_prefix,
112 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
118 zil_prt_rec_rename(zilog_t *zilog, int txtype, void *arg)
120 lr_rename_t *lr = arg;
121 char *snm = (char *)(lr + 1);
122 char *tnm = snm + strlen(snm) + 1;
124 (void) printf("%ssdoid %llu, tdoid %llu\n", tab_prefix,
125 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
126 (void) printf("%ssrc %s tgt %s\n", tab_prefix, snm, tnm);
131 zil_prt_rec_write_cb(void *data, size_t len, void *unused)
134 for (size_t i = 0; i < len; i++) {
136 (void) printf("%c ", *cdata);
138 (void) printf("%2X", *cdata);
146 zil_prt_rec_write(zilog_t *zilog, int txtype, void *arg)
148 lr_write_t *lr = arg;
150 blkptr_t *bp = &lr->lr_blkptr;
152 int verbose = MAX(dump_opt['d'], dump_opt['i']);
155 (void) printf("%sfoid %llu, offset %llx, length %llx\n", tab_prefix,
156 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
157 (u_longlong_t)lr->lr_length);
159 if (txtype == TX_WRITE2 || verbose < 5)
162 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
163 (void) printf("%shas blkptr, %s\n", tab_prefix,
165 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
166 "will claim" : "won't claim");
167 print_log_bp(bp, tab_prefix);
169 if (BP_IS_HOLE(bp)) {
170 (void) printf("\t\t\tLSIZE 0x%llx\n",
171 (u_longlong_t)BP_GET_LSIZE(bp));
172 (void) printf("%s<hole>\n", tab_prefix);
175 if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
176 (void) printf("%s<block already committed>\n",
181 SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
182 lr->lr_foid, ZB_ZIL_LEVEL,
183 lr->lr_offset / BP_GET_LSIZE(bp));
185 data = abd_alloc(BP_GET_LSIZE(bp), B_FALSE);
186 error = zio_wait(zio_read(NULL, zilog->zl_spa,
187 bp, data, BP_GET_LSIZE(bp), NULL, NULL,
188 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
192 /* data is stored after the end of the lr_write record */
193 data = abd_alloc(lr->lr_length, B_FALSE);
194 abd_copy_from_buf(data, lr + 1, lr->lr_length);
197 (void) printf("%s", tab_prefix);
198 (void) abd_iterate_func(data,
199 0, MIN(lr->lr_length, (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE)),
200 zil_prt_rec_write_cb, NULL);
209 zil_prt_rec_truncate(zilog_t *zilog, int txtype, void *arg)
211 lr_truncate_t *lr = arg;
213 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", tab_prefix,
214 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
215 (u_longlong_t)lr->lr_length);
220 zil_prt_rec_setattr(zilog_t *zilog, int txtype, void *arg)
222 lr_setattr_t *lr = arg;
223 time_t atime = (time_t)lr->lr_atime[0];
224 time_t mtime = (time_t)lr->lr_mtime[0];
226 (void) printf("%sfoid %llu, mask 0x%llx\n", tab_prefix,
227 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
229 if (lr->lr_mask & AT_MODE) {
230 (void) printf("%sAT_MODE %llo\n", tab_prefix,
231 (longlong_t)lr->lr_mode);
234 if (lr->lr_mask & AT_UID) {
235 (void) printf("%sAT_UID %llu\n", tab_prefix,
236 (u_longlong_t)lr->lr_uid);
239 if (lr->lr_mask & AT_GID) {
240 (void) printf("%sAT_GID %llu\n", tab_prefix,
241 (u_longlong_t)lr->lr_gid);
244 if (lr->lr_mask & AT_SIZE) {
245 (void) printf("%sAT_SIZE %llu\n", tab_prefix,
246 (u_longlong_t)lr->lr_size);
249 if (lr->lr_mask & AT_ATIME) {
250 (void) printf("%sAT_ATIME %llu.%09llu %s", tab_prefix,
251 (u_longlong_t)lr->lr_atime[0],
252 (u_longlong_t)lr->lr_atime[1],
256 if (lr->lr_mask & AT_MTIME) {
257 (void) printf("%sAT_MTIME %llu.%09llu %s", tab_prefix,
258 (u_longlong_t)lr->lr_mtime[0],
259 (u_longlong_t)lr->lr_mtime[1],
266 zil_prt_rec_acl(zilog_t *zilog, int txtype, void *arg)
270 (void) printf("%sfoid %llu, aclcnt %llu\n", tab_prefix,
271 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
274 typedef void (*zil_prt_rec_func_t)(zilog_t *, int, void *);
275 typedef struct zil_rec_info {
276 zil_prt_rec_func_t zri_print;
277 const char *zri_name;
281 static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
282 {.zri_print = NULL, .zri_name = "Total "},
283 {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE "},
284 {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR "},
285 {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKXATTR "},
286 {.zri_print = zil_prt_rec_create, .zri_name = "TX_SYMLINK "},
287 {.zri_print = zil_prt_rec_remove, .zri_name = "TX_REMOVE "},
288 {.zri_print = zil_prt_rec_remove, .zri_name = "TX_RMDIR "},
289 {.zri_print = zil_prt_rec_link, .zri_name = "TX_LINK "},
290 {.zri_print = zil_prt_rec_rename, .zri_name = "TX_RENAME "},
291 {.zri_print = zil_prt_rec_write, .zri_name = "TX_WRITE "},
292 {.zri_print = zil_prt_rec_truncate, .zri_name = "TX_TRUNCATE "},
293 {.zri_print = zil_prt_rec_setattr, .zri_name = "TX_SETATTR "},
294 {.zri_print = zil_prt_rec_acl, .zri_name = "TX_ACL_V0 "},
295 {.zri_print = zil_prt_rec_acl, .zri_name = "TX_ACL_ACL "},
296 {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE_ACL "},
297 {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE_ATTR "},
298 {.zri_print = zil_prt_rec_create, .zri_name = "TX_CREATE_ACL_ATTR "},
299 {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR_ACL "},
300 {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR_ATTR "},
301 {.zri_print = zil_prt_rec_create, .zri_name = "TX_MKDIR_ACL_ATTR "},
302 {.zri_print = zil_prt_rec_write, .zri_name = "TX_WRITE2 "},
307 print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
310 int verbose = MAX(dump_opt['d'], dump_opt['i']);
312 /* reduce size of txtype to strip off TX_CI bit */
313 txtype = lr->lrc_txtype;
315 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
318 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
319 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
320 zil_rec_info[txtype].zri_name,
321 (u_longlong_t)lr->lrc_reclen,
322 (u_longlong_t)lr->lrc_txg,
323 (u_longlong_t)lr->lrc_seq);
325 if (txtype && verbose >= 3)
326 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
328 zil_rec_info[txtype].zri_count++;
329 zil_rec_info[0].zri_count++;
336 print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
338 char blkbuf[BP_SPRINTF_LEN + 10];
339 int verbose = MAX(dump_opt['d'], dump_opt['i']);
346 (void) strcpy(blkbuf, ", ");
347 snprintf_blkptr(blkbuf + strlen(blkbuf),
348 sizeof (blkbuf) - strlen(blkbuf), bp);
354 claim = "already claimed";
355 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
356 claim = "will claim";
358 claim = "won't claim";
360 (void) printf("\tBlock seqno %llu, %s%s\n",
361 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
367 print_log_stats(int verbose)
374 if (zil_rec_info[0].zri_count == 0)
377 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
380 for (i = 0; i < TX_MAX_TYPE; i++)
381 if (zil_rec_info[i].zri_count || verbose >= 3)
382 (void) printf("\t\t%s %*llu\n",
383 zil_rec_info[i].zri_name, w,
384 (u_longlong_t)zil_rec_info[i].zri_count);
390 dump_intent_log(zilog_t *zilog)
392 const zil_header_t *zh = zilog->zl_header;
393 int verbose = MAX(dump_opt['d'], dump_opt['i']);
396 if (BP_IS_HOLE(&zh->zh_log) || verbose < 1)
399 (void) printf("\n ZIL header: claim_txg %llu, "
400 "claim_blk_seq %llu, claim_lr_seq %llu",
401 (u_longlong_t)zh->zh_claim_txg,
402 (u_longlong_t)zh->zh_claim_blk_seq,
403 (u_longlong_t)zh->zh_claim_lr_seq);
404 (void) printf(" replay_seq %llu, flags 0x%llx\n",
405 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
407 for (i = 0; i < TX_MAX_TYPE; i++)
408 zil_rec_info[i].zri_count = 0;
412 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
414 print_log_stats(verbose);