zdb_il.c revision 1.1.1.3 1 1.1 haad /*
2 1.1 haad * CDDL HEADER START
3 1.1 haad *
4 1.1 haad * The contents of this file are subject to the terms of the
5 1.1 haad * Common Development and Distribution License (the "License").
6 1.1 haad * You may not use this file except in compliance with the License.
7 1.1 haad *
8 1.1 haad * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 1.1 haad * or http://www.opensolaris.org/os/licensing.
10 1.1 haad * See the License for the specific language governing permissions
11 1.1 haad * and limitations under the License.
12 1.1 haad *
13 1.1 haad * When distributing Covered Code, include this CDDL HEADER in each
14 1.1 haad * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 1.1 haad * If applicable, add the following below this CDDL HEADER, with the
16 1.1 haad * fields enclosed by brackets "[]" replaced with your own identifying
17 1.1 haad * information: Portions Copyright [yyyy] [name of copyright owner]
18 1.1 haad *
19 1.1 haad * CDDL HEADER END
20 1.1 haad */
21 1.1 haad /*
22 1.1.1.2 haad * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 1.1 haad * Use is subject to license terms.
24 1.1 haad */
25 1.1 haad
26 1.1 haad /*
27 1.1.1.3 chs * Copyright (c) 2013, 2014 by Delphix. All rights reserved.
28 1.1.1.3 chs */
29 1.1.1.3 chs
30 1.1.1.3 chs /*
31 1.1 haad * Print intent log header and statistics.
32 1.1 haad */
33 1.1 haad
34 1.1 haad #include <stdio.h>
35 1.1 haad #include <stdlib.h>
36 1.1 haad #include <ctype.h>
37 1.1 haad #include <sys/zfs_context.h>
38 1.1 haad #include <sys/spa.h>
39 1.1 haad #include <sys/dmu.h>
40 1.1 haad #include <sys/stat.h>
41 1.1 haad #include <sys/resource.h>
42 1.1 haad #include <sys/zil.h>
43 1.1 haad #include <sys/zil_impl.h>
44 1.1 haad
45 1.1 haad extern uint8_t dump_opt[256];
46 1.1 haad
47 1.1.1.2 haad static char prefix[4] = "\t\t\t";
48 1.1.1.2 haad
49 1.1 haad static void
50 1.1 haad print_log_bp(const blkptr_t *bp, const char *prefix)
51 1.1 haad {
52 1.1 haad char blkbuf[BP_SPRINTF_LEN];
53 1.1 haad
54 1.1.1.3 chs snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
55 1.1 haad (void) printf("%s%s\n", prefix, blkbuf);
56 1.1 haad }
57 1.1 haad
58 1.1 haad /* ARGSUSED */
59 1.1 haad static void
60 1.1 haad zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
61 1.1 haad {
62 1.1 haad time_t crtime = lr->lr_crtime[0];
63 1.1.1.2 haad char *name, *link;
64 1.1.1.2 haad lr_attr_t *lrattr;
65 1.1 haad
66 1.1.1.2 haad name = (char *)(lr + 1);
67 1.1 haad
68 1.1.1.2 haad if (lr->lr_common.lrc_txtype == TX_CREATE_ATTR ||
69 1.1.1.2 haad lr->lr_common.lrc_txtype == TX_MKDIR_ATTR) {
70 1.1.1.2 haad lrattr = (lr_attr_t *)(lr + 1);
71 1.1.1.2 haad name += ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
72 1.1.1.2 haad }
73 1.1.1.2 haad
74 1.1.1.2 haad if (txtype == TX_SYMLINK) {
75 1.1.1.2 haad link = name + strlen(name) + 1;
76 1.1.1.2 haad (void) printf("%s%s -> %s\n", prefix, name, link);
77 1.1.1.2 haad } else if (txtype != TX_MKXATTR) {
78 1.1.1.2 haad (void) printf("%s%s\n", prefix, name);
79 1.1.1.2 haad }
80 1.1.1.2 haad
81 1.1.1.2 haad (void) printf("%s%s", prefix, ctime(&crtime));
82 1.1.1.2 haad (void) printf("%sdoid %llu, foid %llu, mode %llo\n", prefix,
83 1.1 haad (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
84 1.1 haad (longlong_t)lr->lr_mode);
85 1.1.1.2 haad (void) printf("%suid %llu, gid %llu, gen %llu, rdev 0x%llx\n", prefix,
86 1.1 haad (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
87 1.1 haad (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
88 1.1 haad }
89 1.1 haad
90 1.1 haad /* ARGSUSED */
91 1.1 haad static void
92 1.1 haad zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
93 1.1 haad {
94 1.1.1.2 haad (void) printf("%sdoid %llu, name %s\n", prefix,
95 1.1 haad (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
96 1.1 haad }
97 1.1 haad
98 1.1 haad /* ARGSUSED */
99 1.1 haad static void
100 1.1 haad zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
101 1.1 haad {
102 1.1.1.2 haad (void) printf("%sdoid %llu, link_obj %llu, name %s\n", prefix,
103 1.1 haad (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
104 1.1 haad (char *)(lr + 1));
105 1.1 haad }
106 1.1 haad
107 1.1 haad /* ARGSUSED */
108 1.1 haad static void
109 1.1 haad zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
110 1.1 haad {
111 1.1 haad char *snm = (char *)(lr + 1);
112 1.1 haad char *tnm = snm + strlen(snm) + 1;
113 1.1 haad
114 1.1.1.2 haad (void) printf("%ssdoid %llu, tdoid %llu\n", prefix,
115 1.1 haad (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
116 1.1.1.2 haad (void) printf("%ssrc %s tgt %s\n", prefix, snm, tnm);
117 1.1 haad }
118 1.1 haad
119 1.1 haad /* ARGSUSED */
120 1.1 haad static void
121 1.1 haad zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
122 1.1 haad {
123 1.1 haad char *data, *dlimit;
124 1.1 haad blkptr_t *bp = &lr->lr_blkptr;
125 1.1.1.3 chs zbookmark_phys_t zb;
126 1.1 haad char buf[SPA_MAXBLOCKSIZE];
127 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
128 1.1 haad int error;
129 1.1 haad
130 1.1.1.2 haad (void) printf("%sfoid %llu, offset %llx, length %llx\n", prefix,
131 1.1.1.2 haad (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_offset,
132 1.1.1.2 haad (u_longlong_t)lr->lr_length);
133 1.1 haad
134 1.1.1.2 haad if (txtype == TX_WRITE2 || verbose < 5)
135 1.1 haad return;
136 1.1 haad
137 1.1 haad if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
138 1.1.1.2 haad (void) printf("%shas blkptr, %s\n", prefix,
139 1.1.1.3 chs !BP_IS_HOLE(bp) &&
140 1.1 haad bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
141 1.1 haad "will claim" : "won't claim");
142 1.1.1.2 haad print_log_bp(bp, prefix);
143 1.1.1.2 haad
144 1.1.1.2 haad if (BP_IS_HOLE(bp)) {
145 1.1.1.2 haad (void) printf("\t\t\tLSIZE 0x%llx\n",
146 1.1.1.2 haad (u_longlong_t)BP_GET_LSIZE(bp));
147 1.1 haad bzero(buf, sizeof (buf));
148 1.1.1.2 haad (void) printf("%s<hole>\n", prefix);
149 1.1.1.2 haad return;
150 1.1.1.2 haad }
151 1.1.1.2 haad if (bp->blk_birth < zilog->zl_header->zh_claim_txg) {
152 1.1.1.2 haad (void) printf("%s<block already committed>\n", prefix);
153 1.1.1.2 haad return;
154 1.1 haad }
155 1.1.1.2 haad
156 1.1.1.2 haad SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
157 1.1.1.2 haad lr->lr_foid, ZB_ZIL_LEVEL,
158 1.1.1.2 haad lr->lr_offset / BP_GET_LSIZE(bp));
159 1.1.1.2 haad
160 1.1.1.2 haad error = zio_wait(zio_read(NULL, zilog->zl_spa,
161 1.1.1.2 haad bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
162 1.1.1.2 haad ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
163 1.1.1.2 haad if (error)
164 1.1.1.2 haad return;
165 1.1.1.2 haad data = buf;
166 1.1 haad } else {
167 1.1 haad data = (char *)(lr + 1);
168 1.1 haad }
169 1.1 haad
170 1.1 haad dlimit = data + MIN(lr->lr_length,
171 1.1 haad (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
172 1.1 haad
173 1.1.1.2 haad (void) printf("%s", prefix);
174 1.1 haad while (data < dlimit) {
175 1.1 haad if (isprint(*data))
176 1.1 haad (void) printf("%c ", *data);
177 1.1 haad else
178 1.1 haad (void) printf("%2X", *data);
179 1.1 haad data++;
180 1.1 haad }
181 1.1 haad (void) printf("\n");
182 1.1 haad }
183 1.1 haad
184 1.1 haad /* ARGSUSED */
185 1.1 haad static void
186 1.1 haad zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
187 1.1 haad {
188 1.1.1.2 haad (void) printf("%sfoid %llu, offset 0x%llx, length 0x%llx\n", prefix,
189 1.1 haad (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
190 1.1 haad (u_longlong_t)lr->lr_length);
191 1.1 haad }
192 1.1 haad
193 1.1 haad /* ARGSUSED */
194 1.1 haad static void
195 1.1 haad zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
196 1.1 haad {
197 1.1 haad time_t atime = (time_t)lr->lr_atime[0];
198 1.1 haad time_t mtime = (time_t)lr->lr_mtime[0];
199 1.1 haad
200 1.1.1.2 haad (void) printf("%sfoid %llu, mask 0x%llx\n", prefix,
201 1.1 haad (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
202 1.1 haad
203 1.1 haad if (lr->lr_mask & AT_MODE) {
204 1.1.1.2 haad (void) printf("%sAT_MODE %llo\n", prefix,
205 1.1 haad (longlong_t)lr->lr_mode);
206 1.1 haad }
207 1.1 haad
208 1.1 haad if (lr->lr_mask & AT_UID) {
209 1.1.1.2 haad (void) printf("%sAT_UID %llu\n", prefix,
210 1.1 haad (u_longlong_t)lr->lr_uid);
211 1.1 haad }
212 1.1 haad
213 1.1 haad if (lr->lr_mask & AT_GID) {
214 1.1.1.2 haad (void) printf("%sAT_GID %llu\n", prefix,
215 1.1 haad (u_longlong_t)lr->lr_gid);
216 1.1 haad }
217 1.1 haad
218 1.1 haad if (lr->lr_mask & AT_SIZE) {
219 1.1.1.2 haad (void) printf("%sAT_SIZE %llu\n", prefix,
220 1.1 haad (u_longlong_t)lr->lr_size);
221 1.1 haad }
222 1.1 haad
223 1.1 haad if (lr->lr_mask & AT_ATIME) {
224 1.1.1.2 haad (void) printf("%sAT_ATIME %llu.%09llu %s", prefix,
225 1.1 haad (u_longlong_t)lr->lr_atime[0],
226 1.1 haad (u_longlong_t)lr->lr_atime[1],
227 1.1 haad ctime(&atime));
228 1.1 haad }
229 1.1 haad
230 1.1 haad if (lr->lr_mask & AT_MTIME) {
231 1.1.1.2 haad (void) printf("%sAT_MTIME %llu.%09llu %s", prefix,
232 1.1 haad (u_longlong_t)lr->lr_mtime[0],
233 1.1 haad (u_longlong_t)lr->lr_mtime[1],
234 1.1 haad ctime(&mtime));
235 1.1 haad }
236 1.1 haad }
237 1.1 haad
238 1.1 haad /* ARGSUSED */
239 1.1 haad static void
240 1.1 haad zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
241 1.1 haad {
242 1.1.1.2 haad (void) printf("%sfoid %llu, aclcnt %llu\n", prefix,
243 1.1 haad (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
244 1.1 haad }
245 1.1 haad
246 1.1 haad typedef void (*zil_prt_rec_func_t)();
247 1.1 haad typedef struct zil_rec_info {
248 1.1 haad zil_prt_rec_func_t zri_print;
249 1.1 haad char *zri_name;
250 1.1 haad uint64_t zri_count;
251 1.1 haad } zil_rec_info_t;
252 1.1 haad
253 1.1 haad static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
254 1.1 haad { NULL, "Total " },
255 1.1 haad { zil_prt_rec_create, "TX_CREATE " },
256 1.1 haad { zil_prt_rec_create, "TX_MKDIR " },
257 1.1 haad { zil_prt_rec_create, "TX_MKXATTR " },
258 1.1 haad { zil_prt_rec_create, "TX_SYMLINK " },
259 1.1 haad { zil_prt_rec_remove, "TX_REMOVE " },
260 1.1 haad { zil_prt_rec_remove, "TX_RMDIR " },
261 1.1 haad { zil_prt_rec_link, "TX_LINK " },
262 1.1 haad { zil_prt_rec_rename, "TX_RENAME " },
263 1.1 haad { zil_prt_rec_write, "TX_WRITE " },
264 1.1 haad { zil_prt_rec_truncate, "TX_TRUNCATE " },
265 1.1 haad { zil_prt_rec_setattr, "TX_SETATTR " },
266 1.1 haad { zil_prt_rec_acl, "TX_ACL_V0 " },
267 1.1 haad { zil_prt_rec_acl, "TX_ACL_ACL " },
268 1.1 haad { zil_prt_rec_create, "TX_CREATE_ACL " },
269 1.1 haad { zil_prt_rec_create, "TX_CREATE_ATTR " },
270 1.1 haad { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
271 1.1 haad { zil_prt_rec_create, "TX_MKDIR_ACL " },
272 1.1 haad { zil_prt_rec_create, "TX_MKDIR_ATTR " },
273 1.1 haad { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
274 1.1.1.2 haad { zil_prt_rec_write, "TX_WRITE2 " },
275 1.1 haad };
276 1.1 haad
277 1.1 haad /* ARGSUSED */
278 1.1.1.2 haad static int
279 1.1 haad print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
280 1.1 haad {
281 1.1 haad int txtype;
282 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
283 1.1 haad
284 1.1 haad /* reduce size of txtype to strip off TX_CI bit */
285 1.1 haad txtype = lr->lrc_txtype;
286 1.1 haad
287 1.1 haad ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
288 1.1 haad ASSERT(lr->lrc_txg);
289 1.1 haad
290 1.1 haad (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
291 1.1 haad (lr->lrc_txtype & TX_CI) ? "CI-" : "",
292 1.1 haad zil_rec_info[txtype].zri_name,
293 1.1 haad (u_longlong_t)lr->lrc_reclen,
294 1.1 haad (u_longlong_t)lr->lrc_txg,
295 1.1 haad (u_longlong_t)lr->lrc_seq);
296 1.1 haad
297 1.1 haad if (txtype && verbose >= 3)
298 1.1 haad zil_rec_info[txtype].zri_print(zilog, txtype, lr);
299 1.1 haad
300 1.1 haad zil_rec_info[txtype].zri_count++;
301 1.1 haad zil_rec_info[0].zri_count++;
302 1.1.1.2 haad
303 1.1.1.2 haad return (0);
304 1.1 haad }
305 1.1 haad
306 1.1 haad /* ARGSUSED */
307 1.1.1.2 haad static int
308 1.1 haad print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
309 1.1 haad {
310 1.1.1.2 haad char blkbuf[BP_SPRINTF_LEN + 10];
311 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
312 1.1 haad char *claim;
313 1.1 haad
314 1.1 haad if (verbose <= 3)
315 1.1.1.2 haad return (0);
316 1.1 haad
317 1.1 haad if (verbose >= 5) {
318 1.1 haad (void) strcpy(blkbuf, ", ");
319 1.1.1.3 chs snprintf_blkptr(blkbuf + strlen(blkbuf),
320 1.1.1.3 chs sizeof (blkbuf) - strlen(blkbuf), bp);
321 1.1 haad } else {
322 1.1 haad blkbuf[0] = '\0';
323 1.1 haad }
324 1.1 haad
325 1.1 haad if (claim_txg != 0)
326 1.1 haad claim = "already claimed";
327 1.1 haad else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
328 1.1 haad claim = "will claim";
329 1.1 haad else
330 1.1 haad claim = "won't claim";
331 1.1 haad
332 1.1 haad (void) printf("\tBlock seqno %llu, %s%s\n",
333 1.1 haad (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
334 1.1.1.2 haad
335 1.1.1.2 haad return (0);
336 1.1 haad }
337 1.1 haad
338 1.1 haad static void
339 1.1 haad print_log_stats(int verbose)
340 1.1 haad {
341 1.1 haad int i, w, p10;
342 1.1 haad
343 1.1 haad if (verbose > 3)
344 1.1 haad (void) printf("\n");
345 1.1 haad
346 1.1 haad if (zil_rec_info[0].zri_count == 0)
347 1.1 haad return;
348 1.1 haad
349 1.1 haad for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
350 1.1 haad w++;
351 1.1 haad
352 1.1 haad for (i = 0; i < TX_MAX_TYPE; i++)
353 1.1 haad if (zil_rec_info[i].zri_count || verbose >= 3)
354 1.1 haad (void) printf("\t\t%s %*llu\n",
355 1.1 haad zil_rec_info[i].zri_name, w,
356 1.1 haad (u_longlong_t)zil_rec_info[i].zri_count);
357 1.1 haad (void) printf("\n");
358 1.1 haad }
359 1.1 haad
360 1.1 haad /* ARGSUSED */
361 1.1 haad void
362 1.1 haad dump_intent_log(zilog_t *zilog)
363 1.1 haad {
364 1.1 haad const zil_header_t *zh = zilog->zl_header;
365 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
366 1.1 haad int i;
367 1.1 haad
368 1.1.1.3 chs if (BP_IS_HOLE(&zh->zh_log) || verbose < 1)
369 1.1 haad return;
370 1.1 haad
371 1.1.1.2 haad (void) printf("\n ZIL header: claim_txg %llu, "
372 1.1.1.2 haad "claim_blk_seq %llu, claim_lr_seq %llu",
373 1.1.1.2 haad (u_longlong_t)zh->zh_claim_txg,
374 1.1.1.2 haad (u_longlong_t)zh->zh_claim_blk_seq,
375 1.1.1.2 haad (u_longlong_t)zh->zh_claim_lr_seq);
376 1.1.1.2 haad (void) printf(" replay_seq %llu, flags 0x%llx\n",
377 1.1.1.2 haad (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags);
378 1.1 haad
379 1.1 haad for (i = 0; i < TX_MAX_TYPE; i++)
380 1.1 haad zil_rec_info[i].zri_count = 0;
381 1.1 haad
382 1.1 haad if (verbose >= 2) {
383 1.1 haad (void) printf("\n");
384 1.1 haad (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
385 1.1 haad zh->zh_claim_txg);
386 1.1 haad print_log_stats(verbose);
387 1.1 haad }
388 1.1 haad }
389