2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
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.
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.
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
25 #include "err_protos.h"
31 * validates inode block or chunk, returns # of good inodes
32 * the dinodes are verified using verify_uncertain_dinode() which
33 * means only the basic inode info is checked, no fork checks.
37 check_aginode_block(xfs_mount_t
*mp
,
48 * it's ok to read these possible inode blocks in one at
49 * a time because they don't belong to known inodes (if
50 * they did, we'd know about them courtesy of the incore inode
51 * tree and we wouldn't be here and we stale the buffers out
52 * so no one else will overlap them.
54 bp
= libxfs_readbuf(mp
->m_dev
, XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
55 XFS_FSB_TO_BB(mp
, 1), 0);
57 do_warn(_("cannot read agbno (%u/%u), disk block %lld\n"), agno
,
58 agbno
, (xfs_daddr_t
)XFS_AGB_TO_DADDR(mp
, agno
, agbno
));
62 for (i
= 0; i
< mp
->m_sb
.sb_inopblock
; i
++) {
63 dino_p
= XFS_MAKE_IPTR(mp
, bp
, i
);
64 if (!verify_uncertain_dinode(mp
, dino_p
, agno
,
65 XFS_OFFBNO_TO_AGINO(mp
, agbno
, i
)))
74 check_inode_block(xfs_mount_t
*mp
,
77 return(check_aginode_block(mp
, XFS_INO_TO_AGNO(mp
, ino
),
78 XFS_INO_TO_AGBNO(mp
, ino
)));
82 * tries to establish if the inode really exists in a valid
83 * inode chunk. returns number of new inodes if things are good
84 * and 0 if bad. start is the start of the discovered inode chunk.
85 * routine assumes that ino is a legal inode number
86 * (verified by verify_inum()). If the inode chunk turns out
87 * to be good, this routine will put the inode chunk into
88 * the good inode chunk tree if required.
90 * the verify_(ag)inode* family of routines are utility
91 * routines called by check_uncertain_aginodes() and
92 * process_uncertain_aginodes().
95 verify_inode_chunk(xfs_mount_t
*mp
,
101 xfs_agino_t start_agino
;
103 xfs_agblock_t start_agbno
= 0;
104 xfs_agblock_t end_agbno
;
105 xfs_agblock_t max_agbno
;
106 xfs_agblock_t cur_agbno
;
107 xfs_agblock_t chunk_start_agbno
;
108 xfs_agblock_t chunk_stop_agbno
;
109 ino_tree_node_t
*irec_before_p
= NULL
;
110 ino_tree_node_t
*irec_after_p
= NULL
;
111 ino_tree_node_t
*irec_p
;
112 ino_tree_node_t
*irec_next_p
;
120 agno
= XFS_INO_TO_AGNO(mp
, ino
);
121 agino
= XFS_INO_TO_AGINO(mp
, ino
);
122 agbno
= XFS_INO_TO_AGBNO(mp
, ino
);
123 *start_ino
= NULLFSINO
;
125 ASSERT(XFS_IALLOC_BLOCKS(mp
) > 0);
127 if (agno
== mp
->m_sb
.sb_agcount
- 1)
128 max_agbno
= mp
->m_sb
.sb_dblocks
-
129 (xfs_drfsbno_t
) mp
->m_sb
.sb_agblocks
* agno
;
131 max_agbno
= mp
->m_sb
.sb_agblocks
;
134 * is the inode beyond the end of the AG?
136 if (agbno
>= max_agbno
)
140 * check for the easy case, inodes per block >= XFS_INODES_PER_CHUNK
141 * (multiple chunks per block)
143 if (XFS_IALLOC_BLOCKS(mp
) == 1) {
144 if (agbno
> max_agbno
)
147 if (check_inode_block(mp
, ino
) == 0)
150 switch (state
= get_agbno_state(mp
, agno
, agbno
)) {
153 _("uncertain inode block %d/%d already known\n"),
159 set_agbno_state(mp
, agno
, agbno
, XR_E_INO
);
166 * if block is already claimed, forget it.
169 _("inode block %d/%d multiply claimed, (state %d)\n"),
171 set_agbno_state(mp
, agno
, agbno
, XR_E_MULT
);
175 _("inode block %d/%d bad state, (state %d)\n"),
177 set_agbno_state(mp
, agno
, agbno
, XR_E_INO
);
181 start_agino
= XFS_OFFBNO_TO_AGINO(mp
, agbno
, 0);
182 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
185 * put new inode record(s) into inode tree
187 for (j
= 0; j
< chunks_pblock
; j
++) {
188 if ((irec_p
= find_inode_rec(agno
, start_agino
))
190 irec_p
= set_inode_free_alloc(agno
,
192 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
193 set_inode_free(irec_p
, i
);
195 if (start_agino
<= agino
&& agino
<
196 start_agino
+ XFS_INODES_PER_CHUNK
)
197 set_inode_used(irec_p
, agino
- start_agino
);
199 start_agino
+= XFS_INODES_PER_CHUNK
;
200 ino_cnt
+= XFS_INODES_PER_CHUNK
;
204 } else if (fs_aligned_inodes
) {
206 * next easy case -- aligned inode filesystem.
207 * just check out the chunk
209 start_agbno
= rounddown(XFS_INO_TO_AGBNO(mp
, ino
),
211 end_agbno
= start_agbno
+ XFS_IALLOC_BLOCKS(mp
);
214 * if this fs has aligned inodes but the end of the
215 * chunk is beyond the end of the ag, this is a bad
218 if (end_agbno
> max_agbno
)
222 * check out all blocks in chunk
225 for (cur_agbno
= start_agbno
; cur_agbno
< end_agbno
;
227 ino_cnt
+= check_aginode_block(mp
, agno
, cur_agbno
);
231 * if we lose either 2 blocks worth of inodes or >25% of
232 * the chunk, just forget it.
234 if (ino_cnt
< XFS_INODES_PER_CHUNK
- 2 * mp
->m_sb
.sb_inopblock
235 || ino_cnt
< XFS_INODES_PER_CHUNK
- 16)
239 * ok, put the record into the tree, if no conflict.
241 if (find_uncertain_inode_rec(agno
,
242 XFS_OFFBNO_TO_AGINO(mp
, start_agbno
, 0)))
245 start_agino
= XFS_OFFBNO_TO_AGINO(mp
, start_agbno
, 0);
246 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
248 irec_p
= set_inode_free_alloc(agno
,
249 XFS_OFFBNO_TO_AGINO(mp
, start_agbno
, 0));
251 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
252 set_inode_free(irec_p
, i
);
254 ASSERT(start_agino
<= agino
&&
255 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
257 set_inode_used(irec_p
, agino
- start_agino
);
259 return(XFS_INODES_PER_CHUNK
);
263 * hard case -- pre-6.3 filesystem.
264 * set default start/end agbnos and ensure agbnos are legal.
265 * we're setting a range [start_agbno, end_agbno) such that
266 * a discovered inode chunk completely within that range
267 * would include the inode passed into us.
269 if (XFS_IALLOC_BLOCKS(mp
) > 1) {
270 if (agino
> XFS_IALLOC_INODES(mp
))
271 start_agbno
= agbno
- XFS_IALLOC_BLOCKS(mp
) + 1;
276 end_agbno
= agbno
+ XFS_IALLOC_BLOCKS(mp
);
278 if (end_agbno
> max_agbno
)
279 end_agbno
= max_agbno
;
282 * search tree for known inodes within +/- 1 inode chunk range
284 irec_before_p
= irec_after_p
= NULL
;
286 find_inode_rec_range(agno
, XFS_OFFBNO_TO_AGINO(mp
, start_agbno
, 0),
287 XFS_OFFBNO_TO_AGINO(mp
, end_agbno
, mp
->m_sb
.sb_inopblock
- 1),
288 &irec_before_p
, &irec_after_p
);
291 * if we have known inode chunks in our search range, establish
292 * their start and end-points to tighten our search range. range
293 * is [start, end) -- e.g. max/end agbno is one beyond the
294 * last block to be examined. the avl routines work this way.
298 * only one inode record in the range, move one boundary in
300 if (irec_before_p
== irec_after_p
) {
301 if (irec_before_p
->ino_startnum
< agino
)
302 start_agbno
= XFS_AGINO_TO_AGBNO(mp
,
303 irec_before_p
->ino_startnum
+
304 XFS_INODES_PER_CHUNK
);
306 end_agbno
= XFS_AGINO_TO_AGBNO(mp
,
307 irec_before_p
->ino_startnum
);
311 * find the start of the gap in the search range (which
312 * should contain our unknown inode). if the only irec
313 * within +/- 1 chunks starts after the inode we're
314 * looking for, skip this stuff since the end_agbno
315 * of the range has already been trimmed in to not
318 if (irec_before_p
->ino_startnum
< agino
) {
319 irec_p
= irec_before_p
;
320 irec_next_p
= next_ino_rec(irec_p
);
322 while(irec_next_p
!= NULL
&&
323 irec_p
->ino_startnum
+ XFS_INODES_PER_CHUNK
==
324 irec_next_p
->ino_startnum
) {
325 irec_p
= irec_next_p
;
326 irec_next_p
= next_ino_rec(irec_next_p
);
329 start_agbno
= XFS_AGINO_TO_AGBNO(mp
,
330 irec_p
->ino_startnum
) +
331 XFS_IALLOC_BLOCKS(mp
);
334 * we know that the inode we're trying to verify isn't
335 * in an inode chunk so the next ino_rec marks the end
336 * of the gap -- is it within the search range?
338 if (irec_next_p
!= NULL
&&
339 agino
+ XFS_IALLOC_INODES(mp
) >=
340 irec_next_p
->ino_startnum
)
341 end_agbno
= XFS_AGINO_TO_AGBNO(mp
,
342 irec_next_p
->ino_startnum
);
345 ASSERT(start_agbno
< end_agbno
);
349 * if the gap is too small to contain a chunk, we lose.
350 * this means that inode chunks known to be good surround
351 * the inode in question and that the space between them
352 * is too small for a legal inode chunk
354 if (end_agbno
- start_agbno
< XFS_IALLOC_BLOCKS(mp
))
358 * now grunge around the disk, start at the inode block and
359 * go in each direction until you hit a non-inode block or
360 * run into a range boundary. A non-inode block is block
361 * with *no* good inodes in it. Unfortunately, we can't
362 * co-opt bad blocks into inode chunks (which might take
363 * care of disk blocks that turn into zeroes) because the
364 * filesystem could very well allocate two inode chunks
365 * with a one block file in between and we'd zap the file.
366 * We're better off just losing the rest of the
367 * inode chunk instead.
369 for (cur_agbno
= agbno
; cur_agbno
>= start_agbno
; cur_agbno
--) {
371 * if the block has no inodes, it's a bad block so
372 * break out now without decrementing cur_agbno so
373 * chunk start blockno will be set to the last good block
375 if (!(irec_cnt
= check_aginode_block(mp
, agno
, cur_agbno
)))
380 chunk_start_agbno
= cur_agbno
+ 1;
382 for (cur_agbno
= agbno
+ 1; cur_agbno
< end_agbno
; cur_agbno
++) {
384 * if the block has no inodes, it's a bad block so
385 * break out now without incrementing cur_agbno so
386 * chunk start blockno will be set to the block
387 * immediately after the last good block.
389 if (!(irec_cnt
= check_aginode_block(mp
, agno
, cur_agbno
)))
394 chunk_stop_agbno
= cur_agbno
;
396 num_blks
= chunk_stop_agbno
- chunk_start_agbno
;
398 if (num_blks
< XFS_IALLOC_BLOCKS(mp
) || ino_cnt
== 0)
402 * XXX - later - if the entire range is selected and they're all
403 * good inodes, keep searching in either direction.
404 * until you the range of inodes end, then split into chunks
405 * for now, just take one chunk's worth starting at the lowest
406 * possible point and hopefully we'll pick the rest up later.
408 * XXX - if we were going to fix up an inode chunk for
409 * any good inodes in the chunk, this is where we would
410 * do it. For now, keep it simple and lose the rest of
414 if (num_blks
% XFS_IALLOC_BLOCKS(mp
) != 0) {
415 num_blks
= rounddown(num_blks
, XFS_IALLOC_BLOCKS(mp
));
416 chunk_stop_agbno
= chunk_start_agbno
+ num_blks
;
420 * ok, we've got a candidate inode chunk. now we have to
421 * verify that we aren't trying to use blocks that are already
422 * in use. If so, mark them as multiply claimed since odds
423 * are very low that we found this chunk by stumbling across
424 * user data -- we're probably here as a result of a directory
425 * entry or an iunlinked pointer
427 for (j
= 0, cur_agbno
= chunk_start_agbno
;
428 cur_agbno
< chunk_stop_agbno
; cur_agbno
++) {
429 switch (state
= get_agbno_state(mp
, agno
, cur_agbno
)) {
435 _("inode block %d/%d multiply claimed, (state %d)\n"),
436 agno
, cur_agbno
, state
);
437 set_agbno_state(mp
, agno
, cur_agbno
, XR_E_MULT
);
442 _("uncertain inode block overlap, agbno = %d, ino = %llu\n"),
454 * ok, chunk is good. put the record into the tree if required,
455 * and fill in the bitmap. All inodes will be marked as "free"
456 * except for the one that led us to discover the chunk. That's
457 * ok because we'll override the free setting later if the
458 * contents of the inode indicate it's in use.
460 start_agino
= XFS_OFFBNO_TO_AGINO(mp
, chunk_start_agbno
, 0);
461 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
463 ASSERT(find_inode_rec(agno
, start_agino
) == NULL
);
465 irec_p
= set_inode_free_alloc(agno
, start_agino
);
466 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
467 set_inode_free(irec_p
, i
);
469 ASSERT(start_agino
<= agino
&&
470 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
472 set_inode_used(irec_p
, agino
- start_agino
);
474 for (cur_agbno
= chunk_start_agbno
;
475 cur_agbno
< chunk_stop_agbno
; cur_agbno
++) {
476 switch (state
= get_agbno_state(mp
, agno
, cur_agbno
)) {
479 _("uncertain inode block %llu already known\n"),
480 XFS_AGB_TO_FSB(mp
, agno
, cur_agbno
));
485 set_agbno_state(mp
, agno
, cur_agbno
, XR_E_INO
);
492 _("inode block %d/%d multiply claimed, (state %d)\n"),
493 agno
, cur_agbno
, state
);
497 _("inode block %d/%d bad state, (state %d)\n"),
498 agno
, cur_agbno
, state
);
499 set_agbno_state(mp
, agno
, cur_agbno
, XR_E_INO
);
508 * same as above only for ag inode chunks
511 verify_aginode_chunk(xfs_mount_t
*mp
,
514 xfs_agino_t
*agino_start
)
519 res
= verify_inode_chunk(mp
, XFS_AGINO_TO_INO(mp
, agno
, agino
), &ino
);
522 *agino_start
= XFS_INO_TO_AGINO(mp
, ino
);
524 *agino_start
= NULLAGINO
;
530 * this does the same as the two above only it returns a pointer
531 * to the inode record in the good inode tree
534 verify_aginode_chunk_irec(xfs_mount_t
*mp
,
538 xfs_agino_t start_agino
;
539 ino_tree_node_t
*irec
= NULL
;
541 if (verify_aginode_chunk(mp
, agno
, agino
, &start_agino
))
542 irec
= find_inode_rec(agno
, start_agino
);
550 * processes an inode allocation chunk/block, returns 1 on I/O errors,
553 * *bogus is set to 1 if the entire set of inodes is bad.
557 process_inode_chunk(xfs_mount_t
*mp
, xfs_agnumber_t agno
, int num_inos
,
558 ino_tree_node_t
*first_irec
, int ino_discovery
,
559 int check_dups
, int extra_attr_check
, int *bogus
)
562 ino_tree_node_t
*ino_rec
;
579 ASSERT(first_irec
!= NULL
);
580 ASSERT(XFS_AGINO_TO_OFFSET(mp
, first_irec
->ino_startnum
) == 0);
583 ASSERT(XFS_IALLOC_BLOCKS(mp
) > 0);
586 * get all blocks required to read in this chunk (may wind up
587 * having to process more chunks in a multi-chunk per block fs)
589 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
591 bp
= libxfs_readbuf(mp
->m_dev
, XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
592 XFS_FSB_TO_BB(mp
, XFS_IALLOC_BLOCKS(mp
)), 0);
594 do_warn(_("cannot read inode %llu, disk block %lld, cnt %d\n"),
595 XFS_AGINO_TO_INO(mp
, agno
, first_irec
->ino_startnum
),
596 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
597 (int)XFS_FSB_TO_BB(mp
, XFS_IALLOC_BLOCKS(mp
)));
604 ino_rec
= first_irec
;
606 * initialize counters
615 * verify inode chunk if necessary
622 dino
= XFS_MAKE_IPTR(mp
, bp
, icnt
);
623 agino
= irec_offset
+ ino_rec
->ino_startnum
;
626 * we always think that the root and realtime
627 * inodes are verified even though we may have
628 * to reset them later to keep from losing the
629 * chunk that they're in
631 if (verify_dinode(mp
, dino
, agno
, agino
) == 0 ||
633 (mp
->m_sb
.sb_rootino
== agino
||
634 mp
->m_sb
.sb_rsumino
== agino
||
635 mp
->m_sb
.sb_rbmino
== agino
)))
641 if (icnt
== XFS_IALLOC_INODES(mp
) &&
642 irec_offset
== XFS_INODES_PER_CHUNK
) {
644 * done! - finished up irec and block
650 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
652 * get new irec (multiple chunks per block fs)
654 ino_rec
= next_ino_rec(ino_rec
);
655 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
661 * if chunk/block is bad, blow it off. the inode records
662 * will be deleted by the caller if appropriate.
666 if (!done
) /* already free'd */
672 * reset irec and counters
674 ino_rec
= first_irec
;
682 /* nathans TODO ... memory leak here?: */
687 bp
= libxfs_readbuf(mp
->m_dev
,
688 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
689 XFS_FSB_TO_BB(mp
, XFS_IALLOC_BLOCKS(mp
)), 0);
691 do_warn(_("can't read inode %llu, disk block %lld, "
692 "cnt %d\n"), XFS_AGINO_TO_INO(mp
, agno
, agino
),
693 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
694 (int)XFS_FSB_TO_BB(mp
, XFS_IALLOC_BLOCKS(mp
)));
700 * mark block as an inode block in the incore bitmap
702 switch (state
= get_agbno_state(mp
, agno
, agbno
)) {
703 case XR_E_INO
: /* already marked */
708 set_agbno_state(mp
, agno
, agbno
, XR_E_INO
);
711 do_error(_("bad state in block map %d\n"), state
);
714 set_agbno_state(mp
, agno
, agbno
, XR_E_MULT
);
715 do_warn(_("inode block %llu multiply claimed, state was %d\n"),
716 XFS_AGB_TO_FSB(mp
, agno
, agbno
), state
);
724 dino
= XFS_MAKE_IPTR(mp
, bp
, icnt
);
725 agino
= irec_offset
+ ino_rec
->ino_startnum
;
731 status
= process_dinode(mp
, dino
, agno
, agino
,
732 is_inode_free(ino_rec
, irec_offset
),
733 &ino_dirty
, &cleared
, &is_used
,
734 ino_discovery
, check_dups
,
735 extra_attr_check
, &isa_dir
, &parent
);
737 ASSERT(is_used
!= 3);
741 * XXX - if we want to try and keep
742 * track of whether we need to bang on
743 * the inode maps (instead of just
744 * blindly reconstructing them like
745 * we do now, this is where to start.
748 if (is_inode_free(ino_rec
, irec_offset
)) {
749 if (verbose
|| no_modify
||
750 XFS_AGINO_TO_INO(mp
, agno
, agino
) !=
752 do_warn(_("imap claims in-use inode "
754 XFS_AGINO_TO_INO(mp
, agno
,
758 if (verbose
|| (!no_modify
&&
759 XFS_AGINO_TO_INO(mp
, agno
, agino
) !=
761 do_warn(_("correcting imap\n"));
763 do_warn(_("would correct imap\n"));
765 set_inode_used(ino_rec
, irec_offset
);
767 set_inode_free(ino_rec
, irec_offset
);
771 * if we lose the root inode, or it turns into
772 * a non-directory, that allows us to double-check
773 * later whether or not we need to reinitialize it.
776 set_inode_isadir(ino_rec
, irec_offset
);
778 * we always set the parent but
779 * we may as well wait until
780 * phase 4 (no inode discovery)
781 * because the parent info will
784 if (!ino_discovery
) {
786 set_inode_parent(ino_rec
, irec_offset
, parent
);
788 get_inode_parent(ino_rec
, irec_offset
));
791 clear_inode_isadir(ino_rec
, irec_offset
);
795 if (mp
->m_sb
.sb_rootino
==
796 XFS_AGINO_TO_INO(mp
, agno
, agino
)) {
800 do_warn(_("cleared root inode %llu\n"),
801 XFS_AGINO_TO_INO(mp
, agno
,
804 do_warn(_("would clear root inode %llu\n"),
805 XFS_AGINO_TO_INO(mp
, agno
,
808 } else if (mp
->m_sb
.sb_rbmino
==
809 XFS_AGINO_TO_INO(mp
, agno
, agino
)) {
813 do_warn(_("cleared realtime bitmap "
815 XFS_AGINO_TO_INO(mp
, agno
,
818 do_warn(_("would clear realtime bitmap "
820 XFS_AGINO_TO_INO(mp
, agno
,
823 } else if (mp
->m_sb
.sb_rsumino
==
824 XFS_AGINO_TO_INO(mp
, agno
, agino
)) {
828 do_warn(_("cleared realtime summary "
830 XFS_AGINO_TO_INO(mp
, agno
,
833 do_warn(_("would clear realtime summary"
835 XFS_AGINO_TO_INO(mp
, agno
,
838 } else if (!no_modify
) {
839 do_warn(_("cleared inode %llu\n"),
840 XFS_AGINO_TO_INO(mp
, agno
, agino
));
842 do_warn(_("would have cleared inode %llu\n"),
843 XFS_AGINO_TO_INO(mp
, agno
, agino
));
851 if (icnt
== XFS_IALLOC_INODES(mp
) &&
852 irec_offset
== XFS_INODES_PER_CHUNK
) {
854 * done! - finished up irec and block simultaneously
856 if (dirty
&& !no_modify
)
857 libxfs_writebuf(bp
, 0);
863 } else if (ibuf_offset
== mp
->m_sb
.sb_inopblock
) {
865 * mark block as an inode block in the incore bitmap
866 * and reset inode buffer offset counter
871 switch (state
= get_agbno_state(mp
, agno
, agbno
)) {
872 case XR_E_INO
: /* already marked */
877 set_agbno_state(mp
, agno
, agbno
, XR_E_INO
);
880 do_error(_("bad state in block map %d\n"),
884 set_agbno_state(mp
, agno
, agbno
, XR_E_MULT
);
885 do_warn(_("inode block %llu multiply claimed, "
887 XFS_AGB_TO_FSB(mp
, agno
, agbno
), state
);
891 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
893 * get new irec (multiple chunks per block fs)
895 ino_rec
= next_ino_rec(ino_rec
);
896 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
904 * check all inodes mentioned in the ag's incore inode maps.
905 * the map may be incomplete. If so, we'll catch the missing
906 * inodes (hopefully) when we traverse the directory tree.
907 * check_dirs is set to 1 if directory inodes should be
908 * processed for internal consistency, parent setting and
909 * discovery of unknown inodes. this only happens
910 * in phase 3. check_dups is set to 1 if we're looking for
911 * inodes that reference duplicate blocks so we can trash
912 * the inode right then and there. this is set only in
913 * phase 4 after we've run through and set the bitmap once.
916 process_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
,
917 int ino_discovery
, int check_dups
, int extra_attr_check
)
920 ino_tree_node_t
*ino_rec
, *first_ino_rec
, *prev_ino_rec
;
922 first_ino_rec
= ino_rec
= findfirst_inode_rec(agno
);
923 while (ino_rec
!= NULL
) {
925 * paranoia - step through inode records until we step
926 * through a full allocation of inodes. this could
927 * be an issue in big-block filesystems where a block
928 * can hold more than one inode chunk. make sure to
929 * grab the record corresponding to the beginning of
930 * the next block before we call the processing routines.
932 num_inos
= XFS_INODES_PER_CHUNK
;
933 while (num_inos
< XFS_IALLOC_INODES(mp
) && ino_rec
!= NULL
) {
934 ASSERT(ino_rec
!= NULL
);
936 * inodes chunks will always be aligned and sized
939 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
940 num_inos
+= XFS_INODES_PER_CHUNK
;
943 ASSERT(num_inos
== XFS_IALLOC_INODES(mp
));
945 if (process_inode_chunk(mp
, agno
, num_inos
, first_ino_rec
,
946 ino_discovery
, check_dups
, extra_attr_check
, &bogus
)) {
947 /* XXX - i/o error, we've got a problem */
952 first_ino_rec
= ino_rec
= next_ino_rec(ino_rec
);
955 * inodes pointed to by this record are
956 * completely bogus, blow the records for
958 * the inode block(s) will get reclaimed
959 * in phase 4 when the block map is
960 * reconstructed after inodes claiming
961 * duplicate blocks are deleted.
964 ino_rec
= first_ino_rec
;
965 while (num_inos
< XFS_IALLOC_INODES(mp
) &&
967 prev_ino_rec
= ino_rec
;
969 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
970 num_inos
+= XFS_INODES_PER_CHUNK
;
972 get_inode_rec(agno
, prev_ino_rec
);
973 free_inode_rec(agno
, prev_ino_rec
);
976 first_ino_rec
= ino_rec
;
982 * verify the uncertain inode list for an ag.
983 * Good inodes get moved into the good inode tree.
984 * returns 0 if there are no uncertain inode records to
985 * be processed, 1 otherwise. This routine destroys the
986 * the entire uncertain inode tree for the ag as a side-effect.
989 check_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
991 ino_tree_node_t
*irec
;
992 ino_tree_node_t
*nrec
;
1001 clear_uncertain_ino_cache(agno
);
1003 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1007 * the trick here is to find a contiguous range
1008 * of inodes, make sure that it doesn't overlap
1009 * with a known to exist chunk, and then make
1010 * sure it is a number of entire chunks.
1011 * we check on-disk once we have an idea of what's
1012 * going on just to double-check.
1014 * process the uncertain inode record list and look
1015 * on disk to see if the referenced inodes are good
1018 do_warn(_("found inodes not in the inode allocation tree\n"));
1022 * check every confirmed (which in this case means
1023 * inode that we really suspect to be an inode) inode
1025 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1026 if (!is_inode_confirmed(irec
, i
))
1029 agino
= i
+ irec
->ino_startnum
;
1031 if (verify_aginum(mp
, agno
, agino
))
1034 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1035 agino
< nrec
->ino_startnum
+
1036 XFS_INODES_PER_CHUNK
)
1039 if ((nrec
= find_inode_rec(agno
, agino
)) == NULL
)
1040 if (!verify_aginum(mp
, agno
, agino
))
1041 if (verify_aginode_chunk(mp
, agno
,
1046 get_uncertain_inode_rec(agno
, irec
);
1047 free_inode_rec(agno
, irec
);
1049 irec
= findfirst_uncertain_inode_rec(agno
);
1050 } while (irec
!= NULL
);
1053 do_warn(_("found inodes not in the inode allocation tree\n"));
1059 * verify and process the uncertain inodes for an ag.
1060 * this is different from check_ in that we can't just
1061 * move the good inodes into the good inode tree and let
1062 * process_aginodes() deal with them because this gets called
1063 * after process_aginodes() has been run on the ag inode tree.
1064 * So we have to process the inodes as well as verify since
1065 * we don't want to rerun process_aginodes() on a tree that has
1066 * mostly been processed.
1068 * Note that if this routine does process some inodes, it can
1069 * add uncertain inodes to any ag which would require that
1070 * the routine be called again to process those newly-added
1073 * returns 0 if no inodes were processed and 1 if inodes
1074 * were processed (and it is possible that new uncertain
1075 * inodes were discovered).
1077 * as a side-effect, this routine tears down the uncertain
1078 * inode tree for the ag.
1081 process_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1083 ino_tree_node_t
*irec
;
1084 ino_tree_node_t
*nrec
;
1091 #ifdef XR_INODE_TRACE
1092 fprintf(stderr
, "in process_uncertain_aginodes, agno = %d\n", agno
);
1097 clear_uncertain_ino_cache(agno
);
1099 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1106 * check every confirmed inode
1108 for (cnt
= i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1109 if (!is_inode_confirmed(irec
, i
))
1112 agino
= i
+ irec
->ino_startnum
;
1113 #ifdef XR_INODE_TRACE
1114 fprintf(stderr
, "ag inode = %d (0x%x)\n", agino
, agino
);
1117 * skip over inodes already processed (in the
1118 * good tree), bad inode numbers, and inode numbers
1119 * pointing to bogus inodes
1121 if (verify_aginum(mp
, agno
, agino
))
1124 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1125 agino
< nrec
->ino_startnum
+
1126 XFS_INODES_PER_CHUNK
)
1129 if ((nrec
= find_inode_rec(agno
, agino
)) != NULL
)
1133 * verify the chunk. if good, it will be
1134 * added to the good inode tree.
1136 if ((nrec
= verify_aginode_chunk_irec(mp
,
1137 agno
, agino
)) == NULL
)
1143 * process the inode record we just added
1144 * to the good inode tree. The inode
1145 * processing may add more records to the
1146 * uncertain inode lists.
1148 if (process_inode_chunk(mp
, agno
, XFS_IALLOC_INODES(mp
),
1149 nrec
, 1, 0, 0, &bogus
)) {
1150 /* XXX - i/o error, we've got a problem */
1157 * now return the uncertain inode record to the free pool
1158 * and pull another one off the list for processing
1160 get_uncertain_inode_rec(agno
, irec
);
1161 free_inode_rec(agno
, irec
);
1163 irec
= findfirst_uncertain_inode_rec(agno
);
1164 } while (irec
!= NULL
);
1167 do_warn(_("found inodes not in the inode allocation tree\n"));