]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/log_print_all.c
xfs_logprint: support bmap redo items
[thirdparty/xfsprogs-dev.git] / logprint / log_print_all.c
1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #include "libxfs.h"
19 #include "libxlog.h"
20
21 #include "logprint.h"
22
23 /*
24 * Start is defined to be the block pointing to the oldest valid log record.
25 */
26 int
27 xlog_print_find_oldest(
28 struct xlog *log,
29 xfs_daddr_t *last_blk)
30 {
31 xfs_buf_t *bp;
32 xfs_daddr_t first_blk;
33 uint first_half_cycle, last_half_cycle;
34 int error = 0;
35
36 if (xlog_find_zeroed(log, &first_blk))
37 return 0;
38
39 first_blk = 0; /* read first block */
40 bp = xlog_get_bp(log, 1);
41 xlog_bread_noalign(log, 0, 1, bp);
42 first_half_cycle = xlog_get_cycle(XFS_BUF_PTR(bp));
43 *last_blk = log->l_logBBsize-1; /* read last block */
44 xlog_bread_noalign(log, *last_blk, 1, bp);
45 last_half_cycle = xlog_get_cycle(XFS_BUF_PTR(bp));
46 ASSERT(last_half_cycle != 0);
47
48 if (first_half_cycle == last_half_cycle) /* all cycle nos are same */
49 *last_blk = 0;
50 else /* have 1st and last; look for middle cycle */
51 error = xlog_find_cycle_start(log, bp, first_blk,
52 last_blk, last_half_cycle);
53
54 xlog_put_bp(bp);
55 return error;
56 }
57
58 void
59 xlog_recover_print_data(
60 char *p,
61 int len)
62 {
63 if (print_data) {
64 uint *dp = (uint *)p;
65 int nums = len >> 2;
66 int j = 0;
67
68 while (j < nums) {
69 if ((j % 8) == 0)
70 printf("%2x ", j);
71 printf("%8x ", *dp);
72 dp++;
73 j++;
74 if ((j % 8) == 0)
75 printf("\n");
76 }
77 printf("\n");
78 }
79 }
80
81 STATIC void
82 xlog_recover_print_buffer(
83 xlog_recover_item_t *item)
84 {
85 xfs_agi_t *agi;
86 xfs_agf_t *agf;
87 xfs_buf_log_format_t *f;
88 char *p;
89 int len, num, i;
90 xfs_daddr_t blkno;
91 xfs_disk_dquot_t *ddq;
92
93 f = (xfs_buf_log_format_t *)item->ri_buf[0].i_addr;
94 printf(" ");
95 ASSERT(f->blf_type == XFS_LI_BUF);
96 printf(_("BUF: #regs:%d start blkno:0x%llx len:%d bmap size:%d flags:0x%x\n"),
97 f->blf_size, (long long)f->blf_blkno, f->blf_len, f->blf_map_size, f->blf_flags);
98 blkno = (xfs_daddr_t)f->blf_blkno;
99 num = f->blf_size-1;
100 i = 1;
101 while (num-- > 0) {
102 p = item->ri_buf[i].i_addr;
103 len = item->ri_buf[i].i_len;
104 i++;
105 if (blkno == 0) { /* super block */
106 printf(_(" SUPER Block Buffer:\n"));
107 if (!print_buffer)
108 continue;
109 printf(_(" icount:%llu ifree:%llu "),
110 (unsigned long long)
111 be64_to_cpu(*(__be64 *)(p)),
112 (unsigned long long)
113 be64_to_cpu(*(__be64 *)(p+8)));
114 printf(_("fdblks:%llu frext:%llu\n"),
115 (unsigned long long)
116 be64_to_cpu(*(__be64 *)(p+16)),
117 (unsigned long long)
118 be64_to_cpu(*(__be64 *)(p+24)));
119 printf(_(" sunit:%u swidth:%u\n"),
120 be32_to_cpu(*(__be32 *)(p+56)),
121 be32_to_cpu(*(__be32 *)(p+60)));
122 } else if (be32_to_cpu(*(__be32 *)p) == XFS_AGI_MAGIC) {
123 int bucket, buckets;
124 agi = (xfs_agi_t *)p;
125 printf(_(" AGI Buffer: (XAGI)\n"));
126 if (!print_buffer)
127 continue;
128 printf(_(" ver:%d "),
129 be32_to_cpu(agi->agi_versionnum));
130 printf(_("seq#:%d len:%d cnt:%d root:%d\n"),
131 be32_to_cpu(agi->agi_seqno),
132 be32_to_cpu(agi->agi_length),
133 be32_to_cpu(agi->agi_count),
134 be32_to_cpu(agi->agi_root));
135 printf(_(" level:%d free#:0x%x newino:0x%x\n"),
136 be32_to_cpu(agi->agi_level),
137 be32_to_cpu(agi->agi_freecount),
138 be32_to_cpu(agi->agi_newino));
139 if (len == 128) {
140 buckets = 17;
141 } else if (len == 256) {
142 buckets = 32 + 17;
143 } else {
144 buckets = XFS_AGI_UNLINKED_BUCKETS;
145 }
146 for (bucket = 0; bucket < buckets;) {
147 int col;
148 printf(_("bucket[%d - %d]: "), bucket, bucket+3);
149 for (col = 0; col < 4; col++, bucket++) {
150 if (bucket < buckets) {
151 printf("0x%x ",
152 be32_to_cpu(agi->agi_unlinked[bucket]));
153 }
154 }
155 printf("\n");
156 }
157 } else if (be32_to_cpu(*(__be32 *)p) == XFS_AGF_MAGIC) {
158 agf = (xfs_agf_t *)p;
159 printf(_(" AGF Buffer: (XAGF)\n"));
160 if (!print_buffer)
161 continue;
162 printf(_(" ver:%d seq#:%d len:%d \n"),
163 be32_to_cpu(agf->agf_versionnum),
164 be32_to_cpu(agf->agf_seqno),
165 be32_to_cpu(agf->agf_length));
166 printf(_(" root BNO:%d CNT:%d\n"),
167 be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNOi]),
168 be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNTi]));
169 printf(_(" level BNO:%d CNT:%d\n"),
170 be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNOi]),
171 be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNTi]));
172 printf(_(" 1st:%d last:%d cnt:%d "
173 "freeblks:%d longest:%d\n"),
174 be32_to_cpu(agf->agf_flfirst),
175 be32_to_cpu(agf->agf_fllast),
176 be32_to_cpu(agf->agf_flcount),
177 be32_to_cpu(agf->agf_freeblks),
178 be32_to_cpu(agf->agf_longest));
179 } else if (*(uint *)p == XFS_DQUOT_MAGIC) {
180 ddq = (xfs_disk_dquot_t *)p;
181 printf(_(" DQUOT Buffer:\n"));
182 if (!print_buffer)
183 continue;
184 printf(_(" UIDs 0x%lx-0x%lx\n"),
185 (unsigned long)be32_to_cpu(ddq->d_id),
186 (unsigned long)be32_to_cpu(ddq->d_id) +
187 (BBTOB(f->blf_len) / sizeof(xfs_dqblk_t)) - 1);
188 } else {
189 printf(_(" BUF DATA\n"));
190 if (!print_buffer) continue;
191 xlog_recover_print_data(p, len);
192 }
193 }
194 }
195
196 STATIC void
197 xlog_recover_print_quotaoff(
198 xlog_recover_item_t *item)
199 {
200 xfs_qoff_logformat_t *qoff_f;
201 char str[32] = { 0 };
202
203 qoff_f = (xfs_qoff_logformat_t *)item->ri_buf[0].i_addr;
204 ASSERT(qoff_f);
205 if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
206 strcat(str, "USER QUOTA");
207 if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
208 strcat(str, "GROUP QUOTA");
209 if (qoff_f->qf_flags & XFS_PQUOTA_ACCT)
210 strcat(str, "PROJECT QUOTA");
211 printf(_("\tQUOTAOFF: #regs:%d type:%s\n"),
212 qoff_f->qf_size, str);
213 }
214
215 STATIC void
216 xlog_recover_print_dquot(
217 xlog_recover_item_t *item)
218 {
219 xfs_dq_logformat_t *f;
220 xfs_disk_dquot_t *d;
221
222 f = (xfs_dq_logformat_t *)item->ri_buf[0].i_addr;
223 ASSERT(f);
224 ASSERT(f->qlf_len == 1);
225 d = (xfs_disk_dquot_t *)item->ri_buf[1].i_addr;
226 printf(_("\tDQUOT: #regs:%d blkno:%lld boffset:%u id: %d\n"),
227 f->qlf_size, (long long)f->qlf_blkno, f->qlf_boffset, f->qlf_id);
228 if (!print_quota)
229 return;
230 printf(_("\t\tmagic 0x%x\tversion 0x%x\tID 0x%x (%d)\t\n"),
231 be16_to_cpu(d->d_magic),
232 d->d_version,
233 be32_to_cpu(d->d_id),
234 be32_to_cpu(d->d_id));
235 printf(_("\t\tblk_hard 0x%x\tblk_soft 0x%x\tino_hard 0x%x"
236 "\tino_soft 0x%x\n"),
237 (int)be64_to_cpu(d->d_blk_hardlimit),
238 (int)be64_to_cpu(d->d_blk_softlimit),
239 (int)be64_to_cpu(d->d_ino_hardlimit),
240 (int)be64_to_cpu(d->d_ino_softlimit));
241 printf(_("\t\tbcount 0x%x (%d) icount 0x%x (%d)\n"),
242 (int)be64_to_cpu(d->d_bcount),
243 (int)be64_to_cpu(d->d_bcount),
244 (int)be64_to_cpu(d->d_icount),
245 (int)be64_to_cpu(d->d_icount));
246 printf(_("\t\tbtimer 0x%x itimer 0x%x \n"),
247 (int)be32_to_cpu(d->d_btimer),
248 (int)be32_to_cpu(d->d_itimer));
249 }
250
251 STATIC void
252 xlog_recover_print_inode_core(
253 struct xfs_log_dinode *di)
254 {
255 printf(_(" CORE inode:\n"));
256 if (!print_inode)
257 return;
258 printf(_(" magic:%c%c mode:0x%x ver:%d format:%d\n"),
259 (di->di_magic>>8) & 0xff, di->di_magic & 0xff,
260 di->di_mode, di->di_version, di->di_format);
261 printf(_(" uid:%d gid:%d nlink:%d projid:0x%04x%04x\n"),
262 di->di_uid, di->di_gid, di->di_nlink,
263 di->di_projid_hi, di->di_projid_lo);
264 printf(_(" atime:%d mtime:%d ctime:%d\n"),
265 di->di_atime.t_sec, di->di_mtime.t_sec, di->di_ctime.t_sec);
266 printf(_(" flushiter:%d\n"), di->di_flushiter);
267 printf(_(" size:0x%llx nblks:0x%llx exsize:%d "
268 "nextents:%d anextents:%d\n"), (unsigned long long)
269 di->di_size, (unsigned long long)di->di_nblocks,
270 di->di_extsize, di->di_nextents, (int)di->di_anextents);
271 printf(_(" forkoff:%d dmevmask:0x%x dmstate:%d flags:0x%x "
272 "gen:%d\n"),
273 (int)di->di_forkoff, di->di_dmevmask, (int)di->di_dmstate,
274 (int)di->di_flags, di->di_gen);
275 if (di->di_version == 3) {
276 printf(_("flags2 0x%llx cowextsize 0x%x\n"),
277 (unsigned long long)di->di_flags2, di->di_cowextsize);
278 }
279 }
280
281 STATIC void
282 xlog_recover_print_inode(
283 xlog_recover_item_t *item)
284 {
285 xfs_inode_log_format_t f_buf;
286 xfs_inode_log_format_t *f;
287 int attr_index;
288 int hasdata;
289 int hasattr;
290
291 ASSERT(item->ri_buf[0].i_len == sizeof(xfs_inode_log_format_32_t) ||
292 item->ri_buf[0].i_len == sizeof(xfs_inode_log_format_64_t));
293 f = xfs_inode_item_format_convert(item->ri_buf[0].i_addr, item->ri_buf[0].i_len, &f_buf);
294
295 printf(_(" INODE: #regs:%d ino:0x%llx flags:0x%x dsize:%d\n"),
296 f->ilf_size, (unsigned long long)f->ilf_ino, f->ilf_fields,
297 f->ilf_dsize);
298
299 /* core inode comes 2nd */
300 ASSERT(item->ri_buf[1].i_len == xfs_log_dinode_size(2) ||
301 item->ri_buf[1].i_len == xfs_log_dinode_size(3));
302 xlog_recover_print_inode_core((struct xfs_log_dinode *)
303 item->ri_buf[1].i_addr);
304
305 hasdata = (f->ilf_fields & XFS_ILOG_DFORK) != 0;
306 hasattr = (f->ilf_fields & XFS_ILOG_AFORK) != 0;
307 /* does anything come next */
308 switch (f->ilf_fields & (XFS_ILOG_DFORK|XFS_ILOG_DEV|XFS_ILOG_UUID)) {
309 case XFS_ILOG_DEXT:
310 ASSERT(f->ilf_size == 3 + hasattr);
311 printf(_(" DATA FORK EXTENTS inode data:\n"));
312 if (print_inode && print_data)
313 xlog_recover_print_data(item->ri_buf[2].i_addr,
314 item->ri_buf[2].i_len);
315 break;
316 case XFS_ILOG_DBROOT:
317 ASSERT(f->ilf_size == 3 + hasattr);
318 printf(_(" DATA FORK BTREE inode data:\n"));
319 if (print_inode && print_data)
320 xlog_recover_print_data(item->ri_buf[2].i_addr,
321 item->ri_buf[2].i_len);
322 break;
323 case XFS_ILOG_DDATA:
324 ASSERT(f->ilf_size == 3 + hasattr);
325 printf(_(" DATA FORK LOCAL inode data:\n"));
326 if (print_inode && print_data)
327 xlog_recover_print_data(item->ri_buf[2].i_addr,
328 item->ri_buf[2].i_len);
329 break;
330 case XFS_ILOG_DEV:
331 ASSERT(f->ilf_size == 2 + hasattr);
332 printf(_(" DEV inode: no extra region\n"));
333 break;
334 case XFS_ILOG_UUID:
335 ASSERT(f->ilf_size == 2 + hasattr);
336 printf(_(" UUID inode: no extra region\n"));
337 break;
338
339 case 0:
340 ASSERT(f->ilf_size == 2 + hasattr);
341 break;
342 default:
343 xlog_panic("xlog_print_trans_inode: illegal inode type");
344 }
345
346 if (hasattr) {
347 attr_index = 2 + hasdata;
348 switch (f->ilf_fields & XFS_ILOG_AFORK) {
349 case XFS_ILOG_AEXT:
350 ASSERT(f->ilf_size == 3 + hasdata);
351 printf(_(" ATTR FORK EXTENTS inode data:\n"));
352 if (print_inode && print_data)
353 xlog_recover_print_data(
354 item->ri_buf[attr_index].i_addr,
355 item->ri_buf[attr_index].i_len);
356 break;
357 case XFS_ILOG_ABROOT:
358 ASSERT(f->ilf_size == 3 + hasdata);
359 printf(_(" ATTR FORK BTREE inode data:\n"));
360 if (print_inode && print_data)
361 xlog_recover_print_data(
362 item->ri_buf[attr_index].i_addr,
363 item->ri_buf[attr_index].i_len);
364 break;
365 case XFS_ILOG_ADATA:
366 ASSERT(f->ilf_size == 3 + hasdata);
367 printf(_(" ATTR FORK LOCAL inode data:\n"));
368 if (print_inode && print_data)
369 xlog_recover_print_data(
370 item->ri_buf[attr_index].i_addr,
371 item->ri_buf[attr_index].i_len);
372 break;
373 default:
374 xlog_panic("%s: illegal inode log flag", __FUNCTION__);
375 }
376 }
377 }
378
379
380 STATIC void
381 xlog_recover_print_icreate(
382 struct xlog_recover_item *item)
383 {
384 struct xfs_icreate_log *icl;
385
386 icl = (struct xfs_icreate_log *)item->ri_buf[0].i_addr;
387
388 printf(_(" ICR: #ag: %d agbno: 0x%x len: %d\n"
389 " cnt: %d isize: %d gen: 0x%x\n"),
390 be32_to_cpu(icl->icl_ag), be32_to_cpu(icl->icl_agbno),
391 be32_to_cpu(icl->icl_length), be32_to_cpu(icl->icl_count),
392 be32_to_cpu(icl->icl_isize), be32_to_cpu(icl->icl_gen));
393 }
394
395 void
396 xlog_recover_print_logitem(
397 xlog_recover_item_t *item)
398 {
399 switch (ITEM_TYPE(item)) {
400 case XFS_LI_BUF:
401 xlog_recover_print_buffer(item);
402 break;
403 case XFS_LI_ICREATE:
404 xlog_recover_print_icreate(item);
405 break;
406 case XFS_LI_INODE:
407 xlog_recover_print_inode(item);
408 break;
409 case XFS_LI_EFD:
410 xlog_recover_print_efd(item);
411 break;
412 case XFS_LI_EFI:
413 xlog_recover_print_efi(item);
414 break;
415 case XFS_LI_RUD:
416 xlog_recover_print_rud(item);
417 break;
418 case XFS_LI_RUI:
419 xlog_recover_print_rui(item);
420 break;
421 case XFS_LI_CUD:
422 xlog_recover_print_cud(item);
423 break;
424 case XFS_LI_CUI:
425 xlog_recover_print_cui(item);
426 break;
427 case XFS_LI_BUD:
428 xlog_recover_print_bud(item);
429 break;
430 case XFS_LI_BUI:
431 xlog_recover_print_bui(item);
432 break;
433 case XFS_LI_DQUOT:
434 xlog_recover_print_dquot(item);
435 break;
436 case XFS_LI_QUOTAOFF:
437 xlog_recover_print_quotaoff(item);
438 break;
439 default:
440 printf(_("xlog_recover_print_logitem: illegal type\n"));
441 break;
442 }
443 }
444
445 void
446 xlog_recover_print_item(
447 xlog_recover_item_t *item)
448 {
449 int i;
450
451 switch (ITEM_TYPE(item)) {
452 case XFS_LI_BUF:
453 printf("BUF");
454 break;
455 case XFS_LI_ICREATE:
456 printf("ICR");
457 break;
458 case XFS_LI_INODE:
459 printf("INO");
460 break;
461 case XFS_LI_EFD:
462 printf("EFD");
463 break;
464 case XFS_LI_EFI:
465 printf("EFI");
466 break;
467 case XFS_LI_RUD:
468 printf("RUD");
469 break;
470 case XFS_LI_RUI:
471 printf("RUI");
472 break;
473 case XFS_LI_CUD:
474 printf("CUD");
475 break;
476 case XFS_LI_CUI:
477 printf("CUI");
478 break;
479 case XFS_LI_BUD:
480 printf("BUD");
481 break;
482 case XFS_LI_BUI:
483 printf("BUI");
484 break;
485 case XFS_LI_DQUOT:
486 printf("DQ ");
487 break;
488 case XFS_LI_QUOTAOFF:
489 printf("QOFF");
490 break;
491 default:
492 cmn_err(CE_PANIC, _("%s: illegal type"), __FUNCTION__);
493 break;
494 }
495
496 /* type isn't filled in yet
497 printf(_("ITEM: type: %d cnt: %d total: %d "),
498 item->ri_type, item->ri_cnt, item->ri_total);
499 */
500 printf(_(": cnt:%d total:%d "), item->ri_cnt, item->ri_total);
501 for (i=0; i<item->ri_cnt; i++) {
502 printf(_("a:0x%lx len:%d "),
503 (long)item->ri_buf[i].i_addr, item->ri_buf[i].i_len);
504 }
505 printf("\n");
506 xlog_recover_print_logitem(item);
507 }
508
509 void
510 xlog_recover_print_trans(
511 xlog_recover_t *trans,
512 struct list_head *itemq,
513 int print)
514 {
515 xlog_recover_item_t *item;
516
517 if (print < 3)
518 return;
519
520 print_xlog_record_line();
521 xlog_recover_print_trans_head(trans);
522 list_for_each_entry(item, itemq, ri_list)
523 xlog_recover_print_item(item);
524 }