zdb_il.c revision 1.1 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 haad * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI"
27 1.1 haad
28 1.1 haad /*
29 1.1 haad * Print intent log header and statistics.
30 1.1 haad */
31 1.1 haad
32 1.1 haad #include <stdio.h>
33 1.1 haad #include <stdlib.h>
34 1.1 haad #include <ctype.h>
35 1.1 haad #include <sys/zfs_context.h>
36 1.1 haad #include <sys/spa.h>
37 1.1 haad #include <sys/dmu.h>
38 1.1 haad #include <sys/stat.h>
39 1.1 haad #include <sys/resource.h>
40 1.1 haad #include <sys/zil.h>
41 1.1 haad #include <sys/zil_impl.h>
42 1.1 haad
43 1.1 haad extern uint8_t dump_opt[256];
44 1.1 haad
45 1.1 haad static void
46 1.1 haad print_log_bp(const blkptr_t *bp, const char *prefix)
47 1.1 haad {
48 1.1 haad char blkbuf[BP_SPRINTF_LEN];
49 1.1 haad
50 1.1 haad sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp);
51 1.1 haad (void) printf("%s%s\n", prefix, blkbuf);
52 1.1 haad }
53 1.1 haad
54 1.1 haad /* ARGSUSED */
55 1.1 haad static void
56 1.1 haad zil_prt_rec_create(zilog_t *zilog, int txtype, lr_create_t *lr)
57 1.1 haad {
58 1.1 haad time_t crtime = lr->lr_crtime[0];
59 1.1 haad char *name = (char *)(lr + 1);
60 1.1 haad char *link = name + strlen(name) + 1;
61 1.1 haad
62 1.1 haad if (txtype == TX_SYMLINK)
63 1.1 haad (void) printf("\t\t\t%s -> %s\n", name, link);
64 1.1 haad else
65 1.1 haad (void) printf("\t\t\t%s\n", name);
66 1.1 haad
67 1.1 haad (void) printf("\t\t\t%s", ctime(&crtime));
68 1.1 haad (void) printf("\t\t\tdoid %llu, foid %llu, mode %llo\n",
69 1.1 haad (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_foid,
70 1.1 haad (longlong_t)lr->lr_mode);
71 1.1 haad (void) printf("\t\t\tuid %llu, gid %llu, gen %llu, rdev 0x%llx\n",
72 1.1 haad (u_longlong_t)lr->lr_uid, (u_longlong_t)lr->lr_gid,
73 1.1 haad (u_longlong_t)lr->lr_gen, (u_longlong_t)lr->lr_rdev);
74 1.1 haad }
75 1.1 haad
76 1.1 haad /* ARGSUSED */
77 1.1 haad static void
78 1.1 haad zil_prt_rec_remove(zilog_t *zilog, int txtype, lr_remove_t *lr)
79 1.1 haad {
80 1.1 haad (void) printf("\t\t\tdoid %llu, name %s\n",
81 1.1 haad (u_longlong_t)lr->lr_doid, (char *)(lr + 1));
82 1.1 haad }
83 1.1 haad
84 1.1 haad /* ARGSUSED */
85 1.1 haad static void
86 1.1 haad zil_prt_rec_link(zilog_t *zilog, int txtype, lr_link_t *lr)
87 1.1 haad {
88 1.1 haad (void) printf("\t\t\tdoid %llu, link_obj %llu, name %s\n",
89 1.1 haad (u_longlong_t)lr->lr_doid, (u_longlong_t)lr->lr_link_obj,
90 1.1 haad (char *)(lr + 1));
91 1.1 haad }
92 1.1 haad
93 1.1 haad /* ARGSUSED */
94 1.1 haad static void
95 1.1 haad zil_prt_rec_rename(zilog_t *zilog, int txtype, lr_rename_t *lr)
96 1.1 haad {
97 1.1 haad char *snm = (char *)(lr + 1);
98 1.1 haad char *tnm = snm + strlen(snm) + 1;
99 1.1 haad
100 1.1 haad (void) printf("\t\t\tsdoid %llu, tdoid %llu\n",
101 1.1 haad (u_longlong_t)lr->lr_sdoid, (u_longlong_t)lr->lr_tdoid);
102 1.1 haad (void) printf("\t\t\tsrc %s tgt %s\n", snm, tnm);
103 1.1 haad }
104 1.1 haad
105 1.1 haad /* ARGSUSED */
106 1.1 haad static void
107 1.1 haad zil_prt_rec_write(zilog_t *zilog, int txtype, lr_write_t *lr)
108 1.1 haad {
109 1.1 haad char *data, *dlimit;
110 1.1 haad blkptr_t *bp = &lr->lr_blkptr;
111 1.1 haad char buf[SPA_MAXBLOCKSIZE];
112 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
113 1.1 haad int error;
114 1.1 haad
115 1.1 haad (void) printf("\t\t\tfoid %llu, offset 0x%llx,"
116 1.1 haad " length 0x%llx, blkoff 0x%llx\n",
117 1.1 haad (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
118 1.1 haad (u_longlong_t)lr->lr_length, (u_longlong_t)lr->lr_blkoff);
119 1.1 haad
120 1.1 haad if (verbose < 5)
121 1.1 haad return;
122 1.1 haad
123 1.1 haad if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
124 1.1 haad (void) printf("\t\t\thas blkptr, %s\n",
125 1.1 haad bp->blk_birth >= spa_first_txg(zilog->zl_spa) ?
126 1.1 haad "will claim" : "won't claim");
127 1.1 haad print_log_bp(bp, "\t\t\t");
128 1.1 haad if (bp->blk_birth == 0) {
129 1.1 haad bzero(buf, sizeof (buf));
130 1.1 haad } else {
131 1.1 haad zbookmark_t zb;
132 1.1 haad
133 1.1 haad ASSERT3U(bp->blk_cksum.zc_word[ZIL_ZC_OBJSET], ==,
134 1.1 haad dmu_objset_id(zilog->zl_os));
135 1.1 haad
136 1.1 haad zb.zb_objset = bp->blk_cksum.zc_word[ZIL_ZC_OBJSET];
137 1.1 haad zb.zb_object = 0;
138 1.1 haad zb.zb_level = -1;
139 1.1 haad zb.zb_blkid = bp->blk_cksum.zc_word[ZIL_ZC_SEQ];
140 1.1 haad
141 1.1 haad error = zio_wait(zio_read(NULL, zilog->zl_spa,
142 1.1 haad bp, buf, BP_GET_LSIZE(bp), NULL, NULL,
143 1.1 haad ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL, &zb));
144 1.1 haad if (error)
145 1.1 haad return;
146 1.1 haad }
147 1.1 haad data = buf + lr->lr_blkoff;
148 1.1 haad } else {
149 1.1 haad data = (char *)(lr + 1);
150 1.1 haad }
151 1.1 haad
152 1.1 haad dlimit = data + MIN(lr->lr_length,
153 1.1 haad (verbose < 6 ? 20 : SPA_MAXBLOCKSIZE));
154 1.1 haad
155 1.1 haad (void) printf("\t\t\t");
156 1.1 haad while (data < dlimit) {
157 1.1 haad if (isprint(*data))
158 1.1 haad (void) printf("%c ", *data);
159 1.1 haad else
160 1.1 haad (void) printf("%2X", *data);
161 1.1 haad data++;
162 1.1 haad }
163 1.1 haad (void) printf("\n");
164 1.1 haad }
165 1.1 haad
166 1.1 haad /* ARGSUSED */
167 1.1 haad static void
168 1.1 haad zil_prt_rec_truncate(zilog_t *zilog, int txtype, lr_truncate_t *lr)
169 1.1 haad {
170 1.1 haad (void) printf("\t\t\tfoid %llu, offset 0x%llx, length 0x%llx\n",
171 1.1 haad (u_longlong_t)lr->lr_foid, (longlong_t)lr->lr_offset,
172 1.1 haad (u_longlong_t)lr->lr_length);
173 1.1 haad }
174 1.1 haad
175 1.1 haad /* ARGSUSED */
176 1.1 haad static void
177 1.1 haad zil_prt_rec_setattr(zilog_t *zilog, int txtype, lr_setattr_t *lr)
178 1.1 haad {
179 1.1 haad time_t atime = (time_t)lr->lr_atime[0];
180 1.1 haad time_t mtime = (time_t)lr->lr_mtime[0];
181 1.1 haad
182 1.1 haad (void) printf("\t\t\tfoid %llu, mask 0x%llx\n",
183 1.1 haad (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_mask);
184 1.1 haad
185 1.1 haad if (lr->lr_mask & AT_MODE) {
186 1.1 haad (void) printf("\t\t\tAT_MODE %llo\n",
187 1.1 haad (longlong_t)lr->lr_mode);
188 1.1 haad }
189 1.1 haad
190 1.1 haad if (lr->lr_mask & AT_UID) {
191 1.1 haad (void) printf("\t\t\tAT_UID %llu\n",
192 1.1 haad (u_longlong_t)lr->lr_uid);
193 1.1 haad }
194 1.1 haad
195 1.1 haad if (lr->lr_mask & AT_GID) {
196 1.1 haad (void) printf("\t\t\tAT_GID %llu\n",
197 1.1 haad (u_longlong_t)lr->lr_gid);
198 1.1 haad }
199 1.1 haad
200 1.1 haad if (lr->lr_mask & AT_SIZE) {
201 1.1 haad (void) printf("\t\t\tAT_SIZE %llu\n",
202 1.1 haad (u_longlong_t)lr->lr_size);
203 1.1 haad }
204 1.1 haad
205 1.1 haad if (lr->lr_mask & AT_ATIME) {
206 1.1 haad (void) printf("\t\t\tAT_ATIME %llu.%09llu %s",
207 1.1 haad (u_longlong_t)lr->lr_atime[0],
208 1.1 haad (u_longlong_t)lr->lr_atime[1],
209 1.1 haad ctime(&atime));
210 1.1 haad }
211 1.1 haad
212 1.1 haad if (lr->lr_mask & AT_MTIME) {
213 1.1 haad (void) printf("\t\t\tAT_MTIME %llu.%09llu %s",
214 1.1 haad (u_longlong_t)lr->lr_mtime[0],
215 1.1 haad (u_longlong_t)lr->lr_mtime[1],
216 1.1 haad ctime(&mtime));
217 1.1 haad }
218 1.1 haad }
219 1.1 haad
220 1.1 haad /* ARGSUSED */
221 1.1 haad static void
222 1.1 haad zil_prt_rec_acl(zilog_t *zilog, int txtype, lr_acl_t *lr)
223 1.1 haad {
224 1.1 haad (void) printf("\t\t\tfoid %llu, aclcnt %llu\n",
225 1.1 haad (u_longlong_t)lr->lr_foid, (u_longlong_t)lr->lr_aclcnt);
226 1.1 haad }
227 1.1 haad
228 1.1 haad typedef void (*zil_prt_rec_func_t)();
229 1.1 haad typedef struct zil_rec_info {
230 1.1 haad zil_prt_rec_func_t zri_print;
231 1.1 haad char *zri_name;
232 1.1 haad uint64_t zri_count;
233 1.1 haad } zil_rec_info_t;
234 1.1 haad
235 1.1 haad static zil_rec_info_t zil_rec_info[TX_MAX_TYPE] = {
236 1.1 haad { NULL, "Total " },
237 1.1 haad { zil_prt_rec_create, "TX_CREATE " },
238 1.1 haad { zil_prt_rec_create, "TX_MKDIR " },
239 1.1 haad { zil_prt_rec_create, "TX_MKXATTR " },
240 1.1 haad { zil_prt_rec_create, "TX_SYMLINK " },
241 1.1 haad { zil_prt_rec_remove, "TX_REMOVE " },
242 1.1 haad { zil_prt_rec_remove, "TX_RMDIR " },
243 1.1 haad { zil_prt_rec_link, "TX_LINK " },
244 1.1 haad { zil_prt_rec_rename, "TX_RENAME " },
245 1.1 haad { zil_prt_rec_write, "TX_WRITE " },
246 1.1 haad { zil_prt_rec_truncate, "TX_TRUNCATE " },
247 1.1 haad { zil_prt_rec_setattr, "TX_SETATTR " },
248 1.1 haad { zil_prt_rec_acl, "TX_ACL_V0 " },
249 1.1 haad { zil_prt_rec_acl, "TX_ACL_ACL " },
250 1.1 haad { zil_prt_rec_create, "TX_CREATE_ACL " },
251 1.1 haad { zil_prt_rec_create, "TX_CREATE_ATTR " },
252 1.1 haad { zil_prt_rec_create, "TX_CREATE_ACL_ATTR " },
253 1.1 haad { zil_prt_rec_create, "TX_MKDIR_ACL " },
254 1.1 haad { zil_prt_rec_create, "TX_MKDIR_ATTR " },
255 1.1 haad { zil_prt_rec_create, "TX_MKDIR_ACL_ATTR " },
256 1.1 haad };
257 1.1 haad
258 1.1 haad /* ARGSUSED */
259 1.1 haad static void
260 1.1 haad print_log_record(zilog_t *zilog, lr_t *lr, void *arg, uint64_t claim_txg)
261 1.1 haad {
262 1.1 haad int txtype;
263 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
264 1.1 haad
265 1.1 haad /* reduce size of txtype to strip off TX_CI bit */
266 1.1 haad txtype = lr->lrc_txtype;
267 1.1 haad
268 1.1 haad ASSERT(txtype != 0 && (uint_t)txtype < TX_MAX_TYPE);
269 1.1 haad ASSERT(lr->lrc_txg);
270 1.1 haad
271 1.1 haad (void) printf("\t\t%s%s len %6llu, txg %llu, seq %llu\n",
272 1.1 haad (lr->lrc_txtype & TX_CI) ? "CI-" : "",
273 1.1 haad zil_rec_info[txtype].zri_name,
274 1.1 haad (u_longlong_t)lr->lrc_reclen,
275 1.1 haad (u_longlong_t)lr->lrc_txg,
276 1.1 haad (u_longlong_t)lr->lrc_seq);
277 1.1 haad
278 1.1 haad if (txtype && verbose >= 3)
279 1.1 haad zil_rec_info[txtype].zri_print(zilog, txtype, lr);
280 1.1 haad
281 1.1 haad zil_rec_info[txtype].zri_count++;
282 1.1 haad zil_rec_info[0].zri_count++;
283 1.1 haad }
284 1.1 haad
285 1.1 haad /* ARGSUSED */
286 1.1 haad static void
287 1.1 haad print_log_block(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
288 1.1 haad {
289 1.1 haad char blkbuf[BP_SPRINTF_LEN];
290 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
291 1.1 haad char *claim;
292 1.1 haad
293 1.1 haad if (verbose <= 3)
294 1.1 haad return;
295 1.1 haad
296 1.1 haad if (verbose >= 5) {
297 1.1 haad (void) strcpy(blkbuf, ", ");
298 1.1 haad sprintf_blkptr(blkbuf + strlen(blkbuf),
299 1.1 haad BP_SPRINTF_LEN - strlen(blkbuf), bp);
300 1.1 haad } else {
301 1.1 haad blkbuf[0] = '\0';
302 1.1 haad }
303 1.1 haad
304 1.1 haad if (claim_txg != 0)
305 1.1 haad claim = "already claimed";
306 1.1 haad else if (bp->blk_birth >= spa_first_txg(zilog->zl_spa))
307 1.1 haad claim = "will claim";
308 1.1 haad else
309 1.1 haad claim = "won't claim";
310 1.1 haad
311 1.1 haad (void) printf("\tBlock seqno %llu, %s%s\n",
312 1.1 haad (u_longlong_t)bp->blk_cksum.zc_word[ZIL_ZC_SEQ], claim, blkbuf);
313 1.1 haad }
314 1.1 haad
315 1.1 haad static void
316 1.1 haad print_log_stats(int verbose)
317 1.1 haad {
318 1.1 haad int i, w, p10;
319 1.1 haad
320 1.1 haad if (verbose > 3)
321 1.1 haad (void) printf("\n");
322 1.1 haad
323 1.1 haad if (zil_rec_info[0].zri_count == 0)
324 1.1 haad return;
325 1.1 haad
326 1.1 haad for (w = 1, p10 = 10; zil_rec_info[0].zri_count >= p10; p10 *= 10)
327 1.1 haad w++;
328 1.1 haad
329 1.1 haad for (i = 0; i < TX_MAX_TYPE; i++)
330 1.1 haad if (zil_rec_info[i].zri_count || verbose >= 3)
331 1.1 haad (void) printf("\t\t%s %*llu\n",
332 1.1 haad zil_rec_info[i].zri_name, w,
333 1.1 haad (u_longlong_t)zil_rec_info[i].zri_count);
334 1.1 haad (void) printf("\n");
335 1.1 haad }
336 1.1 haad
337 1.1 haad /* ARGSUSED */
338 1.1 haad void
339 1.1 haad dump_intent_log(zilog_t *zilog)
340 1.1 haad {
341 1.1 haad const zil_header_t *zh = zilog->zl_header;
342 1.1 haad int verbose = MAX(dump_opt['d'], dump_opt['i']);
343 1.1 haad int i;
344 1.1 haad
345 1.1 haad if (zh->zh_log.blk_birth == 0 || verbose < 2)
346 1.1 haad return;
347 1.1 haad
348 1.1 haad (void) printf("\n ZIL header: claim_txg %llu, seq %llu\n",
349 1.1 haad (u_longlong_t)zh->zh_claim_txg, (u_longlong_t)zh->zh_replay_seq);
350 1.1 haad
351 1.1 haad if (verbose >= 4)
352 1.1 haad print_log_bp(&zh->zh_log, "\n\tfirst block: ");
353 1.1 haad
354 1.1 haad for (i = 0; i < TX_MAX_TYPE; i++)
355 1.1 haad zil_rec_info[i].zri_count = 0;
356 1.1 haad
357 1.1 haad if (verbose >= 2) {
358 1.1 haad (void) printf("\n");
359 1.1 haad (void) zil_parse(zilog, print_log_block, print_log_record, NULL,
360 1.1 haad zh->zh_claim_txg);
361 1.1 haad print_log_stats(verbose);
362 1.1 haad }
363 1.1 haad }
364