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>
46 extern uint8_t dump_opt[256];
48 static char prefix[4] = "\t\t\t";
51 print_log_bp(const blkptr_t *bp, const char *prefix)
53 char blkbuf[BP_SPRINTF_LEN];
55 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
56 (void) printf("%s%s\n", prefix, blkbuf);
61 zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
63 time_t crtime = lr->lr_crtime[0];
67 name = (char *)(lr + 1);
69 if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
70 lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
71 lrattr = (lr_attr_t *)(lr + 1);
72 name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
75 if (txtype == TX_SYMLINK) {
76 link = name + strlen(name) + 1;
77 (void) printf("%s%s -> %s\n", prefix, name, link);
78 } else if (txtype != TX_MKXATTR) {
79 (void) printf("%s%s\n", prefix, name);
82 (void) printf("%s%s", prefix, ctime(&crtime));
83 (void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix,
84 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
85 (longlong_t)lr->lr_mode);
86 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix,
87 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
88 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
93 zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
95 (void) printf("%sdoid %llu, name %s\n", prefix,
96 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
101 zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
103 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix,
104 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
110 zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
112 char *snm = (char *)(lr + 1);
113 char *tnm = snm + strlen(snm) + 1;
115 (void) printf("%ssdoid %llu, tdoid %llu\n", prefix,
116 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
117 (void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm);
122 zil_prt_rec_write_cb(void *data, size_t len, void *unused)
125 for (int i = 0; i < len; i++) {
127 (void) printf("%c ", *cdata);
129 (void) printf("%2X", *cdata);
137 zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
140 blkptr_t *bp = &lr->lr_blkptr;
142 int verbose = MAX(dump_opt['d'], dump_opt['i']);
145 (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix,
146 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
147 (u_longlong_t)lr->lr_length);
149 if (txtype == TX_WRITE2 || verbose < 5)
152 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
153 (void) printf("%shas blkptr, %s\n", prefix,
155 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
156 "will claim" : "won't claim");
157 print_log_bp(bp, prefix);
159 if (BP_IS_HOLE(bp)) {
160 (void) printf("\t\t\tLSIZE 0x%llx\n",
161 (u_longlong_t)BP_GET_LSIZE(bp));
162 (void) printf("%s<hole>\n", prefix);
165 if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
166 (void) printf("%s<block already committed>\n", prefix);
170 SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
171 lr->lr_foid, ZB_ZIL_LEVEL,
172 lr->lr_offset / BP_GET_LSIZE(bp));
174 data = abd_alloc(BP_GET_LSIZE(bp), B_FALSE);
175 error = zio_wait(zio_read(NULL, zilog->zl_spa,
176 bp, data, BP_GET_LSIZE(bp), NULL, NULL,
177 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
181 /* data is stored after the end of the lr_write record */
182 data = abd_alloc(lr->lr_length, B_FALSE);
183 abd_copy_from_buf(data, lr + 1, lr->lr_length);
186 (void) printf("%s", prefix);
187 (void) abd_iterate_func(data,
188 0, MIN(lr->lr_length, (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE)),
189 zil_prt_rec_write_cb, NULL);
198 zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
200 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix,
201 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
202 (u_longlong_t)lr->lr_length);
207 zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
209 time_t atime = (time_t)lr->lr_atime[0];
210 time_t mtime = (time_t)lr->lr_mtime[0];
212 (void) printf("%sfoid %llu, mask 0x%llx\n", prefix,
213 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
215 if (lr->lr_mask & AT_MODE) {
216 (void) printf("%sAT_MODE %llo\n", prefix,
217 (longlong_t)lr->lr_mode);
220 if (lr->lr_mask & AT_UID) {
221 (void) printf("%sAT_UID %llu\n", prefix,
222 (u_longlong_t)lr->lr_uid);
225 if (lr->lr_mask & AT_GID) {
226 (void) printf("%sAT_GID %llu\n", prefix,
227 (u_longlong_t)lr->lr_gid);
230 if (lr->lr_mask & AT_SIZE) {
231 (void) printf("%sAT_SIZE %llu\n", prefix,
232 (u_longlong_t)lr->lr_size);
235 if (lr->lr_mask & AT_ATIME) {
236 (void) printf("%sAT_ATIME %llu.%09llu %s", prefix,
237 (u_longlong_t)lr->lr_atime[0],
238 (u_longlong_t)lr->lr_atime[1],
242 if (lr->lr_mask & AT_MTIME) {
243 (void) printf("%sAT_MTIME %llu.%09llu %s", prefix,
244 (u_longlong_t)lr->lr_mtime[0],
245 (u_longlong_t)lr->lr_mtime[1],
252 zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
254 (void) printf("%sfoid %llu, aclcnt %llu\n", prefix,
255 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
258 typedef void (*zil_prt_rec_func_t)();
259 typedef struct zil_rec_info {
260 zil_prt_rec_func_t zri_print;
265 static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
267 { zil_prt_rec_create, "TX_CREATE " },
268 { zil_prt_rec_create, "TX_MKDIR " },
269 { zil_prt_rec_create, "TX_MKXATTR " },
270 { zil_prt_rec_create, "TX_SYMLINK " },
271 { zil_prt_rec_remove, "TX_REMOVE " },
272 { zil_prt_rec_remove, "TX_RMDIR " },
273 { zil_prt_rec_link, "TX_LINK " },
274 { zil_prt_rec_rename, "TX_RENAME " },
275 { zil_prt_rec_write, "TX_WRITE " },
276 { zil_prt_rec_truncate, "TX_TRUNCATE " },
277 { zil_prt_rec_setattr, "TX_SETATTR " },
278 { zil_prt_rec_acl, "TX_ACL_V0 " },
279 { zil_prt_rec_acl, "TX_ACL_ACL " },
280 { zil_prt_rec_create, "TX_CREATE_ACL " },
281 { zil_prt_rec_create, "TX_CREATE_ATTR " },
282 { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
283 { zil_prt_rec_create, "TX_MKDIR_ACL " },
284 { zil_prt_rec_create, "TX_MKDIR_ATTR " },
285 { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
286 { zil_prt_rec_write, "TX_WRITE2 " },
291 print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
294 int verbose = MAX(dump_opt['d'], dump_opt['i']);
296 /* reduce size of txtype to strip off TX_CI bit */
297 txtype = lr->lrc_txtype;
299 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
302 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
303 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
304 zil_rec_info[txtype].zri_name,
305 (u_longlong_t)lr->lrc_reclen,
306 (u_longlong_t)lr->lrc_txg,
307 (u_longlong_t)lr->lrc_seq);
309 if (txtype && verbose >= 3)
310 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
312 zil_rec_info[txtype].zri_count++;
313 zil_rec_info[0].zri_count++;
320 print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
322 char blkbuf[BP_SPRINTF_LEN + 10];
323 int verbose = MAX(dump_opt['d'], dump_opt['i']);
330 (void) strcpy(blkbuf, ", ");
331 snprintf_blkptr(blkbuf + strlen(blkbuf),
332 sizeof (blkbuf) - strlen(blkbuf), bp);
338 claim = "already claimed";
339 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
340 claim = "will claim";
342 claim = "won't claim";
344 (void) printf("\tBlock seqno %llu, %s%s\n",
345 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
351 print_log_stats(int verbose)
358 if (zil_rec_info[0].zri_count == 0)
361 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
364 for (i = 0; i < TX_MAX_TYPE; i++)
365 if (zil_rec_info[i].zri_count || verbose >= 3)
366 (void) printf("\t\t%s %*llu\n",
367 zil_rec_info[i].zri_name, w,
368 (u_longlong_t)zil_rec_info[i].zri_count);
374 dump_intent_log(zilog_t *zilog)
376 const zil_header_t *zh = zilog->zl_header;
377 int verbose = MAX(dump_opt['d'], dump_opt['i']);
380 if (BP_IS_HOLE(&zh->zh_log) || verbose < 1)
383 (void) printf("\n ZIL header: claim_txg %llu, "
384 "claim_blk_seq %llu, claim_lr_seq %llu",
385 (u_longlong_t)zh->zh_claim_txg,
386 (u_longlong_t)zh->zh_claim_blk_seq,
387 (u_longlong_t)zh->zh_claim_lr_seq);
388 (void) printf(" replay_seq %llu, flags 0x%llx\n",
389 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
391 for (i = 0; i < TX_MAX_TYPE; i++)
392 zil_rec_info[i].zri_count = 0;
396 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
398 print_log_stats(verbose);