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 * Copyright (c) 2012 Cyril Plisko. All rights reserved.
24 * Use is subject to license terms.
28 * Print intent log header and statistics.
34 #include <sys/zfs_context.h>
38 #include <sys/resource.h>
40 #include <sys/zil_impl.h>
42 extern uint8_t dump_opt[256];
44 static char prefix[4] = "\t\t\t";
47 print_log_bp(const blkptr_t *bp, const char *prefix)
49 char blkbuf[BP_SPRINTF_LEN];
51 sprintf_blkptr(blkbuf, bp);
52 (void) printf("%s%s\n", prefix, blkbuf);
57 zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
59 time_t crtime = lr->lr_crtime[0];
63 name = (char *)(lr + 1);
65 if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
66 lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
67 lrattr = (lr_attr_t *)(lr + 1);
68 name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
71 if (txtype == TX_SYMLINK) {
72 link = name + strlen(name) + 1;
73 (void) printf("%s%s -> %s\n", prefix, name, link);
74 } else if (txtype != TX_MKXATTR) {
75 (void) printf("%s%s\n", prefix, name);
78 (void) printf("%s%s", prefix, ctime(&crtime));
79 (void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix,
80 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
81 (longlong_t)lr->lr_mode);
82 (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix,
83 (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
84 (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
89 zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
91 (void) printf("%sdoid %llu, name %s\n", prefix,
92 (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
97 zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
99 (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix,
100 (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
106 zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
108 char *snm = (char *)(lr + 1);
109 char *tnm = snm + strlen(snm) + 1;
111 (void) printf("%ssdoid %llu, tdoid %llu\n", prefix,
112 (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
113 (void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm);
118 zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
121 blkptr_t *bp = &lr->lr_blkptr;
123 char buf[SPA_MAXBLOCKSIZE];
124 int verbose = MAX(dump_opt['d'], dump_opt['i']);
127 (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix,
128 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
129 (u_longlong_t)lr->lr_length);
131 if (txtype == TX_WRITE2 || verbose < 5)
134 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
135 (void) printf("%shas blkptr, %s\n", prefix,
136 bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
137 "will claim" : "won't claim");
138 print_log_bp(bp, prefix);
140 if (BP_IS_HOLE(bp)) {
141 (void) printf("\t\t\tLSIZE 0x%llx\n",
142 (u_longlong_t)BP_GET_LSIZE(bp));
144 if (bp->blk_birth == 0) {
145 bzero(buf, sizeof (buf));
146 (void) printf("%s<hole>\n", prefix);
149 if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
150 (void) printf("%s<block already committed>\n", prefix);
154 SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
155 lr->lr_foid, ZB_ZIL_LEVEL,
156 lr->lr_offset / BP_GET_LSIZE(bp));
158 error = zio_wait(zio_read(NULL, zilog->zl_spa,
159 bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
160 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
165 data = (char *)(lr + 1);
168 dlimit = data + MIN(lr->lr_length,
169 (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
171 (void) printf("%s", prefix);
172 while (data < dlimit) {
174 (void) printf("%c ", *data);
176 (void) printf("%2hhX", *data);
184 zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
186 (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix,
187 (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
188 (u_longlong_t)lr->lr_length);
193 zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
195 time_t atime = (time_t)lr->lr_atime[0];
196 time_t mtime = (time_t)lr->lr_mtime[0];
198 (void) printf("%sfoid %llu, mask 0x%llx\n", prefix,
199 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
201 if (lr->lr_mask & AT_MODE) {
202 (void) printf("%sAT_MODE %llo\n", prefix,
203 (longlong_t)lr->lr_mode);
206 if (lr->lr_mask & AT_UID) {
207 (void) printf("%sAT_UID %llu\n", prefix,
208 (u_longlong_t)lr->lr_uid);
211 if (lr->lr_mask & AT_GID) {
212 (void) printf("%sAT_GID %llu\n", prefix,
213 (u_longlong_t)lr->lr_gid);
216 if (lr->lr_mask & AT_SIZE) {
217 (void) printf("%sAT_SIZE %llu\n", prefix,
218 (u_longlong_t)lr->lr_size);
221 if (lr->lr_mask & AT_ATIME) {
222 (void) printf("%sAT_ATIME %llu.%09llu %s", prefix,
223 (u_longlong_t)lr->lr_atime[0],
224 (u_longlong_t)lr->lr_atime[1],
228 if (lr->lr_mask & AT_MTIME) {
229 (void) printf("%sAT_MTIME %llu.%09llu %s", prefix,
230 (u_longlong_t)lr->lr_mtime[0],
231 (u_longlong_t)lr->lr_mtime[1],
238 zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
240 (void) printf("%sfoid %llu, aclcnt %llu\n", prefix,
241 (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
244 typedef void (*zil_prt_rec_func_t)(zilog_t *, int, void *);
245 typedef struct zil_rec_info {
246 zil_prt_rec_func_t zri_print;
251 static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
253 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE " },
254 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR " },
255 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKXATTR " },
256 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_SYMLINK " },
257 { (zil_prt_rec_func_t)zil_prt_rec_remove, "TX_REMOVE " },
258 { (zil_prt_rec_func_t)zil_prt_rec_remove, "TX_RMDIR " },
259 { (zil_prt_rec_func_t)zil_prt_rec_link, "TX_LINK " },
260 { (zil_prt_rec_func_t)zil_prt_rec_rename, "TX_RENAME " },
261 { (zil_prt_rec_func_t)zil_prt_rec_write, "TX_WRITE " },
262 { (zil_prt_rec_func_t)zil_prt_rec_truncate, "TX_TRUNCATE " },
263 { (zil_prt_rec_func_t)zil_prt_rec_setattr, "TX_SETATTR " },
264 { (zil_prt_rec_func_t)zil_prt_rec_acl, "TX_ACL_V0 " },
265 { (zil_prt_rec_func_t)zil_prt_rec_acl, "TX_ACL_ACL " },
266 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE_ACL " },
267 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE_ATTR " },
268 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
269 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR_ACL " },
270 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR_ATTR " },
271 { (zil_prt_rec_func_t)zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
272 { (zil_prt_rec_func_t)zil_prt_rec_write, "TX_WRITE2 " },
277 print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
280 int verbose = MAX(dump_opt['d'], dump_opt['i']);
282 /* reduce size of txtype to strip off TX_CI bit */
283 txtype = lr->lrc_txtype;
285 ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
288 (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
289 (lr->lrc_txtype & TX_CI) ? "CI-" : "",
290 zil_rec_info[txtype].zri_name,
291 (u_longlong_t)lr->lrc_reclen,
292 (u_longlong_t)lr->lrc_txg,
293 (u_longlong_t)lr->lrc_seq);
295 if (txtype && verbose >= 3)
296 zil_rec_info[txtype].zri_print(zilog, txtype, lr);
298 zil_rec_info[txtype].zri_count++;
299 zil_rec_info[0].zri_count++;
306 print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
308 char blkbuf[BP_SPRINTF_LEN + 10];
309 int verbose = MAX(dump_opt['d'], dump_opt['i']);
316 (void) strcpy(blkbuf, ", ");
317 sprintf_blkptr(blkbuf + strlen(blkbuf), bp);
323 claim = "already claimed";
324 else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
325 claim = "will claim";
327 claim = "won't claim";
329 (void) printf("\tBlock seqno %llu, %s%s\n",
330 (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
336 print_log_stats(int verbose)
343 if (zil_rec_info[0].zri_count == 0)
346 for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
349 for (i = 0; i < TX_MAX_TYPE; i++)
350 if (zil_rec_info[i].zri_count || verbose >= 3)
351 (void) printf("\t\t%s %*llu\n",
352 zil_rec_info[i].zri_name, w,
353 (u_longlong_t)zil_rec_info[i].zri_count);
359 dump_intent_log(zilog_t *zilog)
361 const zil_header_t *zh = zilog->zl_header;
362 int verbose = MAX(dump_opt['d'], dump_opt['i']);
365 if (zh->zh_log.blk_birth == 0 || verbose < 1)
368 (void) printf("\n ZIL header: claim_txg %llu, "
369 "claim_blk_seq %llu, claim_lr_seq %llu",
370 (u_longlong_t)zh->zh_claim_txg,
371 (u_longlong_t)zh->zh_claim_blk_seq,
372 (u_longlong_t)zh->zh_claim_lr_seq);
373 (void) printf(" replay_seq %llu, flags 0x%llx\n",
374 (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
376 for (i = 0; i < TX_MAX_TYPE; i++)
377 zil_rec_info[i].zri_count = 0;
381 (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
383 print_log_stats(verbose);