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 * Print intent log header and statistics.
33 #include <sys/zfs_context.h>
37 #include <sys/resource.h>
39 #include <sys/zil_impl.h>
41 extern uint8_t dump_opt[256];
43 static char prefix[4] = "\t\t\t";
46 print_log_bp(const blkptr_t *bp, const char *prefix)
48 char blkbuf[BP_SPRINTF_LEN];
50 sprintf_blkptr(blkbuf, bp);
51 (void) printf("%s%s\n", prefix, blkbuf);
56 zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
58 time_t crtime = lr->lr_crtime[0];
62 name = (char *)(lr + 1);
64 if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
65 lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
66 lrattr = (lr_attr_t *)(lr + 1);
67 name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
70 if (txtype == TX_SYMLINK) {
71 link = name + strlen(name) + 1;
72 (void) printf("%s%s -> %s\n", prefix, name, link);
73 } else if (txtype != TX_MKXATTR) {
74 (void) printf("%s%s\n", prefix, name);
77 (void) printf("%s%s", prefix, ctime(&crtime));
78 (void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix,
79 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
80 (longlong_t)lr->lr_mode);
81 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix,
82 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
83 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
88 zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
90 (void) printf("%sdoid %llu, name %s\n", prefix,
91 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
96 zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
98 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix,
99 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
105 zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
107 char *snm = (char *)(lr + 1);
108 char *tnm = snm + strlen(snm) + 1;
110 (void) printf("%ssdoid %llu, tdoid %llu\n", prefix,
111 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
112 (void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm);
117 zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
120 blkptr_t *bp = &lr->lr_blkptr;
122 char buf[SPA_MAXBLOCKSIZE];
123 int verbose = MAX(dump_opt['d'], dump_opt['i']);
126 (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix,
127 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
128 (u_longlong_t)lr->lr_length);
130 if (txtype == TX_WRITE2 || verbose < 5)
133 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
134 (void) printf("%shas blkptr, %s\n", prefix,
135 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
136 "will claim" : "won't claim");
137 print_log_bp(bp, prefix);
139 if (BP_IS_HOLE(bp)) {
140 (void) printf("\t\t\tLSIZE 0x%llx\n",
141 (u_longlong_t)BP_GET_LSIZE(bp));
143 if (bp->blk_birth == 0) {
144 bzero(buf, sizeof (buf));
145 (void) printf("%s<hole>\n", prefix);
148 if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
149 (void) printf("%s<block already committed>\n", prefix);
153 SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
154 lr->lr_foid, ZB_ZIL_LEVEL,
155 lr->lr_offset / BP_GET_LSIZE(bp));
157 error = zio_wait(zio_read(NULL, zilog->zl_spa,
158 bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
159 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
164 data = (char *)(lr + 1);
167 dlimit = data + MIN(lr->lr_length,
168 (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
170 (void) printf("%s", prefix);
171 while (data < dlimit) {
173 (void) printf("%c ", *data);
175 (void) printf("%2X", *data);
183 zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
185 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix,
186 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
187 (u_longlong_t)lr->lr_length);
192 zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
194 time_t atime = (time_t)lr->lr_atime[0];
195 time_t mtime = (time_t)lr->lr_mtime[0];
197 (void) printf("%sfoid %llu, mask 0x%llx\n", prefix,
198 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
200 if (lr->lr_mask & AT_MODE) {
201 (void) printf("%sAT_MODE %llo\n", prefix,
202 (longlong_t)lr->lr_mode);
205 if (lr->lr_mask & AT_UID) {
206 (void) printf("%sAT_UID %llu\n", prefix,
207 (u_longlong_t)lr->lr_uid);
210 if (lr->lr_mask & AT_GID) {
211 (void) printf("%sAT_GID %llu\n", prefix,
212 (u_longlong_t)lr->lr_gid);
215 if (lr->lr_mask & AT_SIZE) {
216 (void) printf("%sAT_SIZE %llu\n", prefix,
217 (u_longlong_t)lr->lr_size);
220 if (lr->lr_mask & AT_ATIME) {
221 (void) printf("%sAT_ATIME %llu.%09llu %s", prefix,
222 (u_longlong_t)lr->lr_atime[0],
223 (u_longlong_t)lr->lr_atime[1],
227 if (lr->lr_mask & AT_MTIME) {
228 (void) printf("%sAT_MTIME %llu.%09llu %s", prefix,
229 (u_longlong_t)lr->lr_mtime[0],
230 (u_longlong_t)lr->lr_mtime[1],
237 zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
239 (void) printf("%sfoid %llu, aclcnt %llu\n", prefix,
240 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
243 typedef void (*zil_prt_rec_func_t)(zilog_t *, int, void *);
244 typedef struct zil_rec_info {
245 zil_prt_rec_func_t zri_print;
250 static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
252 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE " },
253 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR " },
254 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKXATTR " },
255 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_SYMLINK " },
256 { (zil_prt_rec_func_t)zil_prt_rec_remove, "TX_REMOVE " },
257 { (zil_prt_rec_func_t)zil_prt_rec_remove, "TX_RMDIR " },
258 { (zil_prt_rec_func_t)zil_prt_rec_link, "TX_LINK " },
259 { (zil_prt_rec_func_t)zil_prt_rec_rename, "TX_RENAME " },
260 { (zil_prt_rec_func_t)zil_prt_rec_write, "TX_WRITE " },
261 { (zil_prt_rec_func_t)zil_prt_rec_truncate, "TX_TRUNCATE " },
262 { (zil_prt_rec_func_t)zil_prt_rec_setattr, "TX_SETATTR " },
263 { (zil_prt_rec_func_t)zil_prt_rec_acl, "TX_ACL_V0 " },
264 { (zil_prt_rec_func_t)zil_prt_rec_acl, "TX_ACL_ACL " },
265 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE_ACL " },
266 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE_ATTR " },
267 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
268 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR_ACL " },
269 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR_ATTR " },
270 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
271 { (zil_prt_rec_func_t)zil_prt_rec_write, "TX_WRITE2 " },
276 print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
279 int verbose = MAX(dump_opt['d'], dump_opt['i']);
281 /* reduce size of txtype to strip off TX_CI bit */
282 txtype = lr->lrc_txtype;
284 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
287 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
288 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
289 zil_rec_info[txtype].zri_name,
290 (u_longlong_t)lr->lrc_reclen,
291 (u_longlong_t)lr->lrc_txg,
292 (u_longlong_t)lr->lrc_seq);
294 if (txtype && verbose >= 3)
295 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
297 zil_rec_info[txtype].zri_count++;
298 zil_rec_info[0].zri_count++;
305 print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
307 char blkbuf[BP_SPRINTF_LEN + 10];
308 int verbose = MAX(dump_opt['d'], dump_opt['i']);
315 (void) strcpy(blkbuf, ", ");
316 sprintf_blkptr(blkbuf + strlen(blkbuf), bp);
322 claim = "already claimed";
323 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
324 claim = "will claim";
326 claim = "won't claim";
328 (void) printf("\tBlock seqno %llu, %s%s\n",
329 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
335 print_log_stats(int verbose)
342 if (zil_rec_info[0].zri_count == 0)
345 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
348 for (i = 0; i < TX_MAX_TYPE; i++)
349 if (zil_rec_info[i].zri_count || verbose >= 3)
350 (void) printf("\t\t%s %*llu\n",
351 zil_rec_info[i].zri_name, w,
352 (u_longlong_t)zil_rec_info[i].zri_count);
358 dump_intent_log(zilog_t *zilog)
360 const zil_header_t *zh = zilog->zl_header;
361 int verbose = MAX(dump_opt['d'], dump_opt['i']);
364 if (zh->zh_log.blk_birth == 0 || verbose < 1)
367 (void) printf("\n ZIL header: claim_txg %llu, "
368 "claim_blk_seq %llu, claim_lr_seq %llu",
369 (u_longlong_t)zh->zh_claim_txg,
370 (u_longlong_t)zh->zh_claim_blk_seq,
371 (u_longlong_t)zh->zh_claim_lr_seq);
372 (void) printf(" replay_seq %llu, flags 0x%llx\n",
373 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
375 for (i = 0; i < TX_MAX_TYPE; i++)
376 zil_rec_info[i].zri_count = 0;
380 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
382 print_log_stats(verbose);