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"
32 * validates inode block or chunk, returns # of good inodes
33 * the dinodes are verified using verify_uncertain_dinode() which
34 * 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, NULL
);
57 do_warn(_("cannot read agbno (%u/%u), disk block %" PRId64
"\n"),
58 agno
, agbno
, 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
)))
69 bp
->b_ops
= &xfs_inode_buf_ops
;
76 * tries to establish if the inode really exists in a valid
77 * inode chunk. returns number of new inodes if things are good
78 * and 0 if bad. start is the start of the discovered inode chunk.
79 * routine assumes that ino is a legal inode number
80 * (verified by verify_inum()). If the inode chunk turns out
81 * to be good, this routine will put the inode chunk into
82 * the good inode chunk tree if required.
84 * the verify_(ag)inode* family of routines are utility
85 * routines called by check_uncertain_aginodes() and
86 * process_uncertain_aginodes().
89 verify_inode_chunk(xfs_mount_t
*mp
,
95 xfs_agino_t start_agino
;
97 xfs_agblock_t start_agbno
= 0;
98 xfs_agblock_t end_agbno
;
99 xfs_agblock_t max_agbno
;
100 xfs_agblock_t cur_agbno
;
101 xfs_agblock_t chunk_start_agbno
;
102 xfs_agblock_t chunk_stop_agbno
;
103 ino_tree_node_t
*irec_before_p
= NULL
;
104 ino_tree_node_t
*irec_after_p
= NULL
;
105 ino_tree_node_t
*irec_p
;
106 ino_tree_node_t
*irec_next_p
;
115 agno
= XFS_INO_TO_AGNO(mp
, ino
);
116 agino
= XFS_INO_TO_AGINO(mp
, ino
);
117 agbno
= XFS_INO_TO_AGBNO(mp
, ino
);
118 *start_ino
= NULLFSINO
;
120 ASSERT(mp
->m_ialloc_blks
> 0);
122 if (agno
== mp
->m_sb
.sb_agcount
- 1)
123 max_agbno
= mp
->m_sb
.sb_dblocks
-
124 (xfs_rfsblock_t
) mp
->m_sb
.sb_agblocks
* agno
;
126 max_agbno
= mp
->m_sb
.sb_agblocks
;
129 * is the inode beyond the end of the AG?
131 if (agbno
>= max_agbno
)
135 * check for the easy case, inodes per block >= XFS_INODES_PER_CHUNK
136 * (multiple chunks per block)
138 if (mp
->m_ialloc_blks
== 1) {
139 if (agbno
> max_agbno
)
141 if (check_aginode_block(mp
, agno
, agino
) == 0)
144 pthread_mutex_lock(&ag_locks
[agno
].lock
);
146 state
= get_bmap(agno
, agbno
);
150 _("uncertain inode block %d/%d already known\n"),
156 set_bmap(agno
, agbno
, XR_E_INO
);
163 * if block is already claimed, forget it.
166 _("inode block %d/%d multiply claimed, (state %d)\n"),
168 set_bmap(agno
, agbno
, XR_E_MULT
);
169 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
173 _("inode block %d/%d bad state, (state %d)\n"),
175 set_bmap(agno
, agbno
, XR_E_INO
);
179 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
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(mp
, agno
, start_agino
))
190 irec_p
= set_inode_free_alloc(mp
, 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
+ mp
->m_ialloc_blks
;
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(mp
, 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 (mp
->m_ialloc_blks
> 1) {
270 if (agino
> mp
->m_ialloc_inos
)
271 start_agbno
= agbno
- mp
->m_ialloc_blks
+ 1;
276 end_agbno
= agbno
+ mp
->m_ialloc_blks
;
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(mp
, 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
) +
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
+ mp
->m_ialloc_inos
>=
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
< mp
->m_ialloc_blks
)
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
< mp
->m_ialloc_blks
|| 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
% mp
->m_ialloc_blks
!= 0) {
415 num_blks
= rounddown(num_blks
, mp
->m_ialloc_blks
);
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 pthread_mutex_lock(&ag_locks
[agno
].lock
);
428 for (cur_agbno
= chunk_start_agbno
;
429 cur_agbno
< chunk_stop_agbno
;
431 state
= get_bmap_ext(agno
, cur_agbno
, chunk_stop_agbno
, &blen
);
438 _("inode block %d/%d multiply claimed, (state %d)\n"),
439 agno
, cur_agbno
, state
);
440 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_MULT
);
441 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
445 _("uncertain inode block overlap, agbno = %d, ino = %" PRIu64
"\n"),
452 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
455 * ok, chunk is good. put the record into the tree if required,
456 * and fill in the bitmap. All inodes will be marked as "free"
457 * except for the one that led us to discover the chunk. That's
458 * ok because we'll override the free setting later if the
459 * contents of the inode indicate it's in use.
461 start_agino
= XFS_OFFBNO_TO_AGINO(mp
, chunk_start_agbno
, 0);
462 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
464 ASSERT(find_inode_rec(mp
, agno
, start_agino
) == NULL
);
466 irec_p
= set_inode_free_alloc(mp
, agno
, start_agino
);
467 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
468 set_inode_free(irec_p
, i
);
470 ASSERT(start_agino
<= agino
&&
471 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
473 set_inode_used(irec_p
, agino
- start_agino
);
475 pthread_mutex_lock(&ag_locks
[agno
].lock
);
477 for (cur_agbno
= chunk_start_agbno
;
478 cur_agbno
< chunk_stop_agbno
;
480 state
= get_bmap_ext(agno
, cur_agbno
, chunk_stop_agbno
, &blen
);
484 _("uncertain inode block %" PRIu64
" already known\n"),
485 XFS_AGB_TO_FSB(mp
, agno
, cur_agbno
));
490 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_INO
);
497 _("inode block %d/%d multiply claimed, (state %d)\n"),
498 agno
, cur_agbno
, state
);
502 _("inode block %d/%d bad state, (state %d)\n"),
503 agno
, cur_agbno
, state
);
504 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_INO
);
508 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
514 * same as above only for ag inode chunks
517 verify_aginode_chunk(xfs_mount_t
*mp
,
520 xfs_agino_t
*agino_start
)
525 res
= verify_inode_chunk(mp
, XFS_AGINO_TO_INO(mp
, agno
, agino
), &ino
);
528 *agino_start
= XFS_INO_TO_AGINO(mp
, ino
);
530 *agino_start
= NULLAGINO
;
536 * this does the same as the two above only it returns a pointer
537 * to the inode record in the good inode tree
539 static ino_tree_node_t
*
540 verify_aginode_chunk_irec(xfs_mount_t
*mp
,
544 xfs_agino_t start_agino
;
545 ino_tree_node_t
*irec
= NULL
;
547 if (verify_aginode_chunk(mp
, agno
, agino
, &start_agino
))
548 irec
= find_inode_rec(mp
, agno
, start_agino
);
556 * processes an inode allocation chunk/block, returns 1 on I/O errors,
559 * *bogus is set to 1 if the entire set of inodes is bad.
568 ino_tree_node_t
*first_irec
,
571 int extra_attr_check
,
575 ino_tree_node_t
*ino_rec
;
590 int blks_per_cluster
;
595 ASSERT(first_irec
!= NULL
);
596 ASSERT(XFS_AGINO_TO_OFFSET(mp
, first_irec
->ino_startnum
) == 0);
599 ASSERT(mp
->m_ialloc_blks
> 0);
601 blks_per_cluster
= mp
->m_inode_cluster_size
>> mp
->m_sb
.sb_blocklog
;
602 if (blks_per_cluster
== 0)
603 blks_per_cluster
= 1;
604 cluster_count
= XFS_INODES_PER_CHUNK
/ inodes_per_cluster
;
605 if (cluster_count
== 0)
609 * get all blocks required to read in this chunk (may wind up
610 * having to process more chunks in a multi-chunk per block fs)
612 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
617 ino_rec
= first_irec
;
620 bplist
= malloc(cluster_count
* sizeof(xfs_buf_t
*));
622 do_error(_("failed to allocate %zd bytes of memory\n"),
623 cluster_count
* sizeof(xfs_buf_t
*));
625 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
627 * Skip the cluster buffer if the first inode is sparse. The
628 * remaining inodes in the cluster share the same state as
629 * sparse inodes occur at cluster granularity.
631 if (is_inode_sparse(ino_rec
, irec_offset
)) {
632 pftrace("skip sparse inode, startnum 0x%x idx %d",
633 ino_rec
->ino_startnum
, irec_offset
);
634 bplist
[bp_index
] = NULL
;
638 pftrace("about to read off %llu in AG %d",
639 XFS_AGB_TO_DADDR(mp
, agno
, agbno
), agno
);
641 bplist
[bp_index
] = libxfs_readbuf(mp
->m_dev
,
642 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
643 XFS_FSB_TO_BB(mp
, blks_per_cluster
), 0,
645 if (!bplist
[bp_index
]) {
646 do_warn(_("cannot read inode %" PRIu64
", disk block %" PRId64
", cnt %d\n"),
647 XFS_AGINO_TO_INO(mp
, agno
, first_irec
->ino_startnum
),
648 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
649 XFS_FSB_TO_BB(mp
, blks_per_cluster
));
650 while (bp_index
> 0) {
652 libxfs_putbuf(bplist
[bp_index
]);
658 pftrace("readbuf %p (%llu, %d) in AG %d", bplist
[bp_index
],
659 (long long)XFS_BUF_ADDR(bplist
[bp_index
]),
660 XFS_BUF_COUNT(bplist
[bp_index
]), agno
);
662 bplist
[bp_index
]->b_ops
= &xfs_inode_buf_ops
;
665 irec_offset
+= mp
->m_sb
.sb_inopblock
* blks_per_cluster
;
666 agbno
+= blks_per_cluster
;
668 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
671 * initialize counters
681 * verify inode chunk if necessary
685 agino
= irec_offset
+ ino_rec
->ino_startnum
;
687 /* no buffers for sparse clusters */
688 if (bplist
[bp_index
]) {
689 /* make inode pointer */
690 dino
= xfs_make_iptr(mp
, bplist
[bp_index
],
694 * we always think that the root and realtime
695 * inodes are verified even though we may have
696 * to reset them later to keep from losing the
697 * chunk that they're in
699 if (verify_dinode(mp
, dino
, agno
, agino
) == 0 ||
701 (mp
->m_sb
.sb_rootino
== agino
||
702 mp
->m_sb
.sb_rsumino
== agino
||
703 mp
->m_sb
.sb_rbmino
== agino
)))
711 if (icnt
== mp
->m_ialloc_inos
&&
712 irec_offset
== XFS_INODES_PER_CHUNK
) {
714 * done! - finished up irec and block
718 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
720 * get new irec (multiple chunks per block fs)
722 ino_rec
= next_ino_rec(ino_rec
);
723 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
726 if (cluster_offset
== inodes_per_cluster
) {
733 * if chunk/block is bad, blow it off. the inode records
734 * will be deleted by the caller if appropriate.
738 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++)
739 if (bplist
[bp_index
])
740 libxfs_putbuf(bplist
[bp_index
]);
746 * reset irec and counters
748 ino_rec
= first_irec
;
758 * mark block as an inode block in the incore bitmap
760 if (!is_inode_sparse(ino_rec
, irec_offset
)) {
761 pthread_mutex_lock(&ag_locks
[agno
].lock
);
762 state
= get_bmap(agno
, agbno
);
764 case XR_E_INO
: /* already marked */
769 set_bmap(agno
, agbno
, XR_E_INO
);
772 do_error(_("bad state in block map %d\n"), state
);
775 set_bmap(agno
, agbno
, XR_E_MULT
);
777 _("inode block %" PRIu64
" multiply claimed, state was %d\n"),
778 XFS_AGB_TO_FSB(mp
, agno
, agbno
), state
);
781 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
785 agino
= irec_offset
+ ino_rec
->ino_startnum
;
786 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
788 if (is_inode_sparse(ino_rec
, irec_offset
))
791 /* make inode pointer */
792 dino
= xfs_make_iptr(mp
, bplist
[bp_index
], cluster_offset
);
799 status
= process_dinode(mp
, dino
, agno
, agino
,
800 is_inode_free(ino_rec
, irec_offset
),
801 &ino_dirty
, &is_used
,ino_discovery
, check_dups
,
802 extra_attr_check
, &isa_dir
, &parent
);
804 ASSERT(is_used
!= 3);
807 libxfs_dinode_calc_crc(mp
, dino
);
811 * XXX - if we want to try and keep
812 * track of whether we need to bang on
813 * the inode maps (instead of just
814 * blindly reconstructing them like
815 * we do now, this is where to start.
820 if (is_inode_free(ino_rec
, irec_offset
)) {
821 if (verbose
|| no_modify
) {
823 _("imap claims in-use inode %" PRIu64
" is free, "),
827 if (verbose
|| !no_modify
)
828 do_warn(_("correcting imap\n"));
830 do_warn(_("would correct imap\n"));
832 set_inode_used(ino_rec
, irec_offset
);
835 * store the on-disk file type for comparing in
838 di_mode
= be16_to_cpu(dino
->di_mode
);
839 di_mode
= (di_mode
& S_IFMT
) >> S_SHIFT
;
840 set_inode_ftype(ino_rec
, irec_offset
,
841 xfs_mode_to_ftype
[di_mode
]);
844 * store on-disk nlink count for comparing in phase 7
846 set_inode_disk_nlinks(ino_rec
, irec_offset
,
848 ? be32_to_cpu(dino
->di_nlink
)
849 : be16_to_cpu(dino
->di_onlink
));
852 set_inode_free(ino_rec
, irec_offset
);
856 * if we lose the root inode, or it turns into
857 * a non-directory, that allows us to double-check
858 * later whether or not we need to reinitialize it.
861 set_inode_isadir(ino_rec
, irec_offset
);
863 * we always set the parent but
864 * we may as well wait until
865 * phase 4 (no inode discovery)
866 * because the parent info will
869 if (!ino_discovery
) {
871 set_inode_parent(ino_rec
, irec_offset
, parent
);
873 get_inode_parent(ino_rec
, irec_offset
));
876 clear_inode_isadir(ino_rec
, irec_offset
);
880 if (mp
->m_sb
.sb_rootino
== ino
) {
885 _("cleared root inode %" PRIu64
"\n"),
889 _("would clear root inode %" PRIu64
"\n"),
892 } else if (mp
->m_sb
.sb_rbmino
== ino
) {
897 _("cleared realtime bitmap inode %" PRIu64
"\n"),
901 _("would clear realtime bitmap inode %" PRIu64
"\n"),
904 } else if (mp
->m_sb
.sb_rsumino
== ino
) {
909 _("cleared realtime summary inode %" PRIu64
"\n"),
913 _("would clear realtime summary inode %" PRIu64
"\n"),
916 } else if (!no_modify
) {
917 do_warn(_("cleared inode %" PRIu64
"\n"),
920 do_warn(_("would have cleared inode %" PRIu64
"\n"),
931 if (icnt
== mp
->m_ialloc_inos
&&
932 irec_offset
== XFS_INODES_PER_CHUNK
) {
934 * done! - finished up irec and block simultaneously
936 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
937 if (!bplist
[bp_index
])
940 pftrace("put/writebuf %p (%llu) in AG %d",
941 bplist
[bp_index
], (long long)
942 XFS_BUF_ADDR(bplist
[bp_index
]), agno
);
944 if (dirty
&& !no_modify
)
945 libxfs_writebuf(bplist
[bp_index
], 0);
947 libxfs_putbuf(bplist
[bp_index
]);
951 } else if (ibuf_offset
== mp
->m_sb
.sb_inopblock
) {
953 * mark block as an inode block in the incore bitmap
954 * and reset inode buffer offset counter
959 if (!is_inode_sparse(ino_rec
, irec_offset
)) {
960 pthread_mutex_lock(&ag_locks
[agno
].lock
);
961 state
= get_bmap(agno
, agbno
);
963 case XR_E_INO
: /* already marked */
968 set_bmap(agno
, agbno
, XR_E_INO
);
972 _("bad state in block map %d\n"),
976 set_bmap(agno
, agbno
, XR_E_MULT
);
978 _("inode block %" PRIu64
" multiply claimed, state was %d\n"),
979 XFS_AGB_TO_FSB(mp
, agno
, agbno
),
983 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
985 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
987 * get new irec (multiple chunks per block fs)
989 ino_rec
= next_ino_rec(ino_rec
);
990 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
993 if (cluster_offset
== inodes_per_cluster
) {
1002 * check all inodes mentioned in the ag's incore inode maps.
1003 * the map may be incomplete. If so, we'll catch the missing
1004 * inodes (hopefully) when we traverse the directory tree.
1005 * check_dirs is set to 1 if directory inodes should be
1006 * processed for internal consistency, parent setting and
1007 * discovery of unknown inodes. this only happens
1008 * in phase 3. check_dups is set to 1 if we're looking for
1009 * inodes that reference duplicate blocks so we can trash
1010 * the inode right then and there. this is set only in
1011 * phase 4 after we've run through and set the bitmap once.
1016 prefetch_args_t
*pf_args
,
1017 xfs_agnumber_t agno
,
1020 int extra_attr_check
)
1022 int num_inos
, bogus
;
1023 ino_tree_node_t
*ino_rec
, *first_ino_rec
, *prev_ino_rec
;
1027 first_ino_rec
= ino_rec
= findfirst_inode_rec(agno
);
1029 while (ino_rec
!= NULL
) {
1031 * paranoia - step through inode records until we step
1032 * through a full allocation of inodes. this could
1033 * be an issue in big-block filesystems where a block
1034 * can hold more than one inode chunk. make sure to
1035 * grab the record corresponding to the beginning of
1036 * the next block before we call the processing routines.
1038 num_inos
= XFS_INODES_PER_CHUNK
;
1039 while (num_inos
< mp
->m_ialloc_inos
&& ino_rec
!= NULL
) {
1041 * inodes chunks will always be aligned and sized
1044 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1045 num_inos
+= XFS_INODES_PER_CHUNK
;
1048 ASSERT(num_inos
== mp
->m_ialloc_inos
);
1051 sem_post(&pf_args
->ra_count
);
1053 sem_getvalue(&pf_args
->ra_count
, &count
);
1054 pftrace("processing inode chunk %p in AG %d (sem count = %d)",
1055 first_ino_rec
, agno
, count
);
1059 if (process_inode_chunk(mp
, agno
, num_inos
, first_ino_rec
,
1060 ino_discovery
, check_dups
, extra_attr_check
,
1062 /* XXX - i/o error, we've got a problem */
1067 first_ino_rec
= ino_rec
= next_ino_rec(ino_rec
);
1070 * inodes pointed to by this record are
1071 * completely bogus, blow the records for
1073 * the inode block(s) will get reclaimed
1074 * in phase 4 when the block map is
1075 * reconstructed after inodes claiming
1076 * duplicate blocks are deleted.
1079 ino_rec
= first_ino_rec
;
1080 while (num_inos
< mp
->m_ialloc_inos
&&
1082 prev_ino_rec
= ino_rec
;
1084 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1085 num_inos
+= XFS_INODES_PER_CHUNK
;
1087 get_inode_rec(mp
, agno
, prev_ino_rec
);
1088 free_inode_rec(agno
, prev_ino_rec
);
1091 first_ino_rec
= ino_rec
;
1093 PROG_RPT_INC(prog_rpt_done
[agno
], num_inos
);
1098 * verify the uncertain inode list for an ag.
1099 * Good inodes get moved into the good inode tree.
1100 * returns 0 if there are no uncertain inode records to
1101 * be processed, 1 otherwise. This routine destroys the
1102 * the entire uncertain inode tree for the ag as a side-effect.
1105 check_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1107 ino_tree_node_t
*irec
;
1108 ino_tree_node_t
*nrec
;
1117 clear_uncertain_ino_cache(agno
);
1119 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1123 * the trick here is to find a contiguous range
1124 * of inodes, make sure that it doesn't overlap
1125 * with a known to exist chunk, and then make
1126 * sure it is a number of entire chunks.
1127 * we check on-disk once we have an idea of what's
1128 * going on just to double-check.
1130 * process the uncertain inode record list and look
1131 * on disk to see if the referenced inodes are good
1134 do_warn(_("found inodes not in the inode allocation tree\n"));
1138 * check every confirmed (which in this case means
1139 * inode that we really suspect to be an inode) inode
1141 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1142 if (!is_inode_confirmed(irec
, i
))
1145 agino
= i
+ irec
->ino_startnum
;
1147 if (verify_aginum(mp
, agno
, agino
))
1150 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1151 agino
< nrec
->ino_startnum
+
1152 XFS_INODES_PER_CHUNK
)
1155 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) == NULL
)
1156 if (!verify_aginum(mp
, agno
, agino
))
1157 if (verify_aginode_chunk(mp
, agno
,
1162 get_uncertain_inode_rec(mp
, agno
, irec
);
1163 free_inode_rec(agno
, irec
);
1165 irec
= findfirst_uncertain_inode_rec(agno
);
1166 } while (irec
!= NULL
);
1169 do_warn(_("found inodes not in the inode allocation tree\n"));
1175 * verify and process the uncertain inodes for an ag.
1176 * this is different from check_ in that we can't just
1177 * move the good inodes into the good inode tree and let
1178 * process_aginodes() deal with them because this gets called
1179 * after process_aginodes() has been run on the ag inode tree.
1180 * So we have to process the inodes as well as verify since
1181 * we don't want to rerun process_aginodes() on a tree that has
1182 * mostly been processed.
1184 * Note that if this routine does process some inodes, it can
1185 * add uncertain inodes to any ag which would require that
1186 * the routine be called again to process those newly-added
1189 * returns 0 if no inodes were processed and 1 if inodes
1190 * were processed (and it is possible that new uncertain
1191 * inodes were discovered).
1193 * as a side-effect, this routine tears down the uncertain
1194 * inode tree for the ag.
1197 process_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1199 ino_tree_node_t
*irec
;
1200 ino_tree_node_t
*nrec
;
1207 #ifdef XR_INODE_TRACE
1208 fprintf(stderr
, "in process_uncertain_aginodes, agno = %d\n", agno
);
1213 clear_uncertain_ino_cache(agno
);
1215 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1222 * check every confirmed inode
1224 for (cnt
= i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1225 if (!is_inode_confirmed(irec
, i
))
1228 agino
= i
+ irec
->ino_startnum
;
1229 #ifdef XR_INODE_TRACE
1230 fprintf(stderr
, "ag inode = %d (0x%x)\n", agino
, agino
);
1233 * skip over inodes already processed (in the
1234 * good tree), bad inode numbers, and inode numbers
1235 * pointing to bogus inodes
1237 if (verify_aginum(mp
, agno
, agino
))
1240 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1241 agino
< nrec
->ino_startnum
+
1242 XFS_INODES_PER_CHUNK
)
1245 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) != NULL
)
1249 * verify the chunk. if good, it will be
1250 * added to the good inode tree.
1252 if ((nrec
= verify_aginode_chunk_irec(mp
,
1253 agno
, agino
)) == NULL
)
1259 * process the inode record we just added
1260 * to the good inode tree. The inode
1261 * processing may add more records to the
1262 * uncertain inode lists.
1264 if (process_inode_chunk(mp
, agno
, mp
->m_ialloc_inos
,
1265 nrec
, 1, 0, 0, &bogus
)) {
1266 /* XXX - i/o error, we've got a problem */
1273 * now return the uncertain inode record to the free pool
1274 * and pull another one off the list for processing
1276 get_uncertain_inode_rec(mp
, agno
, irec
);
1277 free_inode_rec(agno
, irec
);
1279 irec
= findfirst_uncertain_inode_rec(agno
);
1280 } while (irec
!= NULL
);
1283 do_warn(_("found inodes not in the inode allocation tree\n"));