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