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 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>
45 extern uint8_t dump_opt[256];
47 static char prefix[4] = "\t\t\t";
50 print_log_bp(const blkptr_t *bp, const char *prefix)
52 char blkbuf[BP_SPRINTF_LEN];
54 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
55 (void) printf("%s%s\n", prefix, blkbuf);
60 zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
62 time_t crtime = lr->lr_crtime[0];
66 name = (char *)(lr + 1);
68 if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
69 lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
70 lrattr = (lr_attr_t *)(lr + 1);
71 name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
74 if (txtype == TX_SYMLINK) {
75 link = name + strlen(name) + 1;
76 (void) printf("%s%s -> %s\n", prefix, name, link);
77 } else if (txtype != TX_MKXATTR) {
78 (void) printf("%s%s\n", prefix, name);
81 (void) printf("%s%s", prefix, ctime(&crtime));
82 (void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix,
83 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
84 (longlong_t)lr->lr_mode);
85 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix,
86 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
87 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
92 zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
94 (void) printf("%sdoid %llu, name %s\n", prefix,
95 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
100 zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
102 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix,
103 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
109 zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
111 char *snm = (char *)(lr + 1);
112 char *tnm = snm + strlen(snm) + 1;
114 (void) printf("%ssdoid %llu, tdoid %llu\n", prefix,
115 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
116 (void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm);
121 zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
124 blkptr_t *bp = &lr->lr_blkptr;
126 char buf[SPA_MAXBLOCKSIZE];
127 int verbose = MAX(dump_opt['d'], dump_opt['i']);
130 (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix,
131 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
132 (u_longlong_t)lr->lr_length);
134 if (txtype == TX_WRITE2 || verbose < 5)
137 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
138 (void) printf("%shas blkptr, %s\n", prefix,
140 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
141 "will claim" : "won't claim");
142 print_log_bp(bp, prefix);
144 if (BP_IS_HOLE(bp)) {
145 (void) printf("\t\t\tLSIZE 0x%llx\n",
146 (u_longlong_t)BP_GET_LSIZE(bp));
147 bzero(buf, sizeof (buf));
148 (void) printf("%s<hole>\n", prefix);
151 if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
152 (void) printf("%s<block already committed>\n", prefix);
156 SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
157 lr->lr_foid, ZB_ZIL_LEVEL,
158 lr->lr_offset / BP_GET_LSIZE(bp));
160 error = zio_wait(zio_read(NULL, zilog->zl_spa,
161 bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
162 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
167 data = (char *)(lr + 1);
170 dlimit = data + MIN(lr->lr_length,
171 (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
173 (void) printf("%s", prefix);
174 while (data < dlimit) {
176 (void) printf("%c ", *data);
178 (void) printf("%2X", *data);
186 zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
188 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix,
189 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
190 (u_longlong_t)lr->lr_length);
195 zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
197 time_t atime = (time_t)lr->lr_atime[0];
198 time_t mtime = (time_t)lr->lr_mtime[0];
200 (void) printf("%sfoid %llu, mask 0x%llx\n", prefix,
201 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
203 if (lr->lr_mask & AT_MODE) {
204 (void) printf("%sAT_MODE %llo\n", prefix,
205 (longlong_t)lr->lr_mode);
208 if (lr->lr_mask & AT_UID) {
209 (void) printf("%sAT_UID %llu\n", prefix,
210 (u_longlong_t)lr->lr_uid);
213 if (lr->lr_mask & AT_GID) {
214 (void) printf("%sAT_GID %llu\n", prefix,
215 (u_longlong_t)lr->lr_gid);
218 if (lr->lr_mask & AT_SIZE) {
219 (void) printf("%sAT_SIZE %llu\n", prefix,
220 (u_longlong_t)lr->lr_size);
223 if (lr->lr_mask & AT_ATIME) {
224 (void) printf("%sAT_ATIME %llu.%09llu %s", prefix,
225 (u_longlong_t)lr->lr_atime[0],
226 (u_longlong_t)lr->lr_atime[1],
230 if (lr->lr_mask & AT_MTIME) {
231 (void) printf("%sAT_MTIME %llu.%09llu %s", prefix,
232 (u_longlong_t)lr->lr_mtime[0],
233 (u_longlong_t)lr->lr_mtime[1],
240 zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
242 (void) printf("%sfoid %llu, aclcnt %llu\n", prefix,
243 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
246 typedef void (*zil_prt_rec_func_t)();
247 typedef struct zil_rec_info {
248 zil_prt_rec_func_t zri_print;
253 static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
255 { zil_prt_rec_create, "TX_CREATE " },
256 { zil_prt_rec_create, "TX_MKDIR " },
257 { zil_prt_rec_create, "TX_MKXATTR " },
258 { zil_prt_rec_create, "TX_SYMLINK " },
259 { zil_prt_rec_remove, "TX_REMOVE " },
260 { zil_prt_rec_remove, "TX_RMDIR " },
261 { zil_prt_rec_link, "TX_LINK " },
262 { zil_prt_rec_rename, "TX_RENAME " },
263 { zil_prt_rec_write, "TX_WRITE " },
264 { zil_prt_rec_truncate, "TX_TRUNCATE " },
265 { zil_prt_rec_setattr, "TX_SETATTR " },
266 { zil_prt_rec_acl, "TX_ACL_V0 " },
267 { zil_prt_rec_acl, "TX_ACL_ACL " },
268 { zil_prt_rec_create, "TX_CREATE_ACL " },
269 { zil_prt_rec_create, "TX_CREATE_ATTR " },
270 { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
271 { zil_prt_rec_create, "TX_MKDIR_ACL " },
272 { zil_prt_rec_create, "TX_MKDIR_ATTR " },
273 { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
274 { zil_prt_rec_write, "TX_WRITE2 " },
279 print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
282 int verbose = MAX(dump_opt['d'], dump_opt['i']);
284 /* reduce size of txtype to strip off TX_CI bit */
285 txtype = lr->lrc_txtype;
287 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
290 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
291 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
292 zil_rec_info[txtype].zri_name,
293 (u_longlong_t)lr->lrc_reclen,
294 (u_longlong_t)lr->lrc_txg,
295 (u_longlong_t)lr->lrc_seq);
297 if (txtype && verbose >= 3)
298 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
300 zil_rec_info[txtype].zri_count++;
301 zil_rec_info[0].zri_count++;
308 print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
310 char blkbuf[BP_SPRINTF_LEN + 10];
311 int verbose = MAX(dump_opt['d'], dump_opt['i']);
318 (void) strcpy(blkbuf, ", ");
319 snprintf_blkptr(blkbuf + strlen(blkbuf),
320 sizeof (blkbuf) - strlen(blkbuf), bp);
326 claim = "already claimed";
327 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
328 claim = "will claim";
330 claim = "won't claim";
332 (void) printf("\tBlock seqno %llu, %s%s\n",
333 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
339 print_log_stats(int verbose)
346 if (zil_rec_info[0].zri_count == 0)
349 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
352 for (i = 0; i < TX_MAX_TYPE; i++)
353 if (zil_rec_info[i].zri_count || verbose >= 3)
354 (void) printf("\t\t%s %*llu\n",
355 zil_rec_info[i].zri_name, w,
356 (u_longlong_t)zil_rec_info[i].zri_count);
362 dump_intent_log(zilog_t *zilog)
364 const zil_header_t *zh = zilog->zl_header;
365 int verbose = MAX(dump_opt['d'], dump_opt['i']);
368 if (BP_IS_HOLE(&zh->zh_log) || verbose < 1)
371 (void) printf("\n ZIL header: claim_txg %llu, "
372 "claim_blk_seq %llu, claim_lr_seq %llu",
373 (u_longlong_t)zh->zh_claim_txg,
374 (u_longlong_t)zh->zh_claim_blk_seq,
375 (u_longlong_t)zh->zh_claim_lr_seq);
376 (void) printf(" replay_seq %llu, flags 0x%llx\n",
377 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
379 for (i = 0; i < TX_MAX_TYPE; i++)
380 zil_rec_info[i].zri_count = 0;
384 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
386 print_log_stats(verbose);