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
);
554 * Set the state of an inode block during inode chunk processing. The block is
555 * expected to be in the free or inode state. If free, it transitions to the
556 * inode state. Warn if the block is in neither expected state as this indicates
557 * multiply claimed blocks.
560 process_inode_agbno_state(
561 struct xfs_mount
*mp
,
567 pthread_mutex_lock(&ag_locks
[agno
].lock
);
568 state
= get_bmap(agno
, agbno
);
570 case XR_E_INO
: /* already marked */
575 set_bmap(agno
, agbno
, XR_E_INO
);
578 do_error(_("bad state in block map %d\n"), state
);
581 set_bmap(agno
, agbno
, XR_E_MULT
);
583 _("inode block %" PRIu64
" multiply claimed, state was %d\n"),
584 XFS_AGB_TO_FSB(mp
, agno
, agbno
), state
);
587 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
591 * processes an inode allocation chunk/block, returns 1 on I/O errors,
594 * *bogus is set to 1 if the entire set of inodes is bad.
601 ino_tree_node_t
*first_irec
,
604 int extra_attr_check
,
608 ino_tree_node_t
*ino_rec
;
622 int blks_per_cluster
;
627 ASSERT(first_irec
!= NULL
);
628 ASSERT(XFS_AGINO_TO_OFFSET(mp
, first_irec
->ino_startnum
) == 0);
631 ASSERT(mp
->m_ialloc_blks
> 0);
633 blks_per_cluster
= mp
->m_inode_cluster_size
>> mp
->m_sb
.sb_blocklog
;
634 if (blks_per_cluster
== 0)
635 blks_per_cluster
= 1;
636 cluster_count
= XFS_INODES_PER_CHUNK
/ inodes_per_cluster
;
637 if (cluster_count
== 0)
641 * get all blocks required to read in this chunk (may wind up
642 * having to process more chunks in a multi-chunk per block fs)
644 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
649 ino_rec
= first_irec
;
652 bplist
= malloc(cluster_count
* sizeof(xfs_buf_t
*));
654 do_error(_("failed to allocate %zd bytes of memory\n"),
655 cluster_count
* sizeof(xfs_buf_t
*));
657 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
659 * Skip the cluster buffer if the first inode is sparse. The
660 * remaining inodes in the cluster share the same state as
661 * sparse inodes occur at cluster granularity.
663 if (is_inode_sparse(ino_rec
, irec_offset
)) {
664 pftrace("skip sparse inode, startnum 0x%x idx %d",
665 ino_rec
->ino_startnum
, irec_offset
);
666 bplist
[bp_index
] = NULL
;
670 pftrace("about to read off %llu in AG %d",
671 XFS_AGB_TO_DADDR(mp
, agno
, agbno
), agno
);
673 bplist
[bp_index
] = libxfs_readbuf(mp
->m_dev
,
674 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
675 XFS_FSB_TO_BB(mp
, blks_per_cluster
), 0,
677 if (!bplist
[bp_index
]) {
678 do_warn(_("cannot read inode %" PRIu64
", disk block %" PRId64
", cnt %d\n"),
679 XFS_AGINO_TO_INO(mp
, agno
, first_irec
->ino_startnum
),
680 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
681 XFS_FSB_TO_BB(mp
, blks_per_cluster
));
682 while (bp_index
> 0) {
684 libxfs_putbuf(bplist
[bp_index
]);
690 pftrace("readbuf %p (%llu, %d) in AG %d", bplist
[bp_index
],
691 (long long)XFS_BUF_ADDR(bplist
[bp_index
]),
692 XFS_BUF_COUNT(bplist
[bp_index
]), agno
);
694 bplist
[bp_index
]->b_ops
= &xfs_inode_buf_ops
;
697 irec_offset
+= mp
->m_sb
.sb_inopblock
* blks_per_cluster
;
698 agbno
+= blks_per_cluster
;
700 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
703 * initialize counters
713 * verify inode chunk if necessary
717 agino
= irec_offset
+ ino_rec
->ino_startnum
;
719 /* no buffers for sparse clusters */
720 if (bplist
[bp_index
]) {
721 /* make inode pointer */
722 dino
= xfs_make_iptr(mp
, bplist
[bp_index
],
726 * we always think that the root and realtime
727 * inodes are verified even though we may have
728 * to reset them later to keep from losing the
729 * chunk that they're in
731 if (verify_dinode(mp
, dino
, agno
, agino
) == 0 ||
733 (mp
->m_sb
.sb_rootino
== agino
||
734 mp
->m_sb
.sb_rsumino
== agino
||
735 mp
->m_sb
.sb_rbmino
== agino
)))
743 if (icnt
== mp
->m_ialloc_inos
&&
744 irec_offset
== XFS_INODES_PER_CHUNK
) {
746 * done! - finished up irec and block
750 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
752 * get new irec (multiple chunks per block fs)
754 ino_rec
= next_ino_rec(ino_rec
);
755 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
758 if (cluster_offset
== inodes_per_cluster
) {
765 * if chunk/block is bad, blow it off. the inode records
766 * will be deleted by the caller if appropriate.
770 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++)
771 if (bplist
[bp_index
])
772 libxfs_putbuf(bplist
[bp_index
]);
778 * reset irec and counters
780 ino_rec
= first_irec
;
790 * mark block as an inode block in the incore bitmap
792 if (!is_inode_sparse(ino_rec
, irec_offset
))
793 process_inode_agbno_state(mp
, agno
, agbno
);
796 agino
= irec_offset
+ ino_rec
->ino_startnum
;
797 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
799 if (is_inode_sparse(ino_rec
, irec_offset
))
802 /* make inode pointer */
803 dino
= xfs_make_iptr(mp
, bplist
[bp_index
], cluster_offset
);
810 status
= process_dinode(mp
, dino
, agno
, agino
,
811 is_inode_free(ino_rec
, irec_offset
),
812 &ino_dirty
, &is_used
,ino_discovery
, check_dups
,
813 extra_attr_check
, &isa_dir
, &parent
);
815 ASSERT(is_used
!= 3);
818 libxfs_dinode_calc_crc(mp
, dino
);
822 * XXX - if we want to try and keep
823 * track of whether we need to bang on
824 * the inode maps (instead of just
825 * blindly reconstructing them like
826 * we do now, this is where to start.
829 if (is_inode_free(ino_rec
, irec_offset
)) {
830 if (verbose
|| no_modify
) {
832 _("imap claims in-use inode %" PRIu64
" is free, "),
836 if (verbose
|| !no_modify
)
837 do_warn(_("correcting imap\n"));
839 do_warn(_("would correct imap\n"));
841 set_inode_used(ino_rec
, irec_offset
);
844 * store the on-disk file type for comparing in
847 set_inode_ftype(ino_rec
, irec_offset
,
848 libxfs_mode_to_ftype(be16_to_cpu(dino
->di_mode
)));
851 * store on-disk nlink count for comparing in phase 7
853 set_inode_disk_nlinks(ino_rec
, irec_offset
,
855 ? be32_to_cpu(dino
->di_nlink
)
856 : be16_to_cpu(dino
->di_onlink
));
859 set_inode_free(ino_rec
, irec_offset
);
863 * if we lose the root inode, or it turns into
864 * a non-directory, that allows us to double-check
865 * later whether or not we need to reinitialize it.
868 set_inode_isadir(ino_rec
, irec_offset
);
870 * we always set the parent but
871 * we may as well wait until
872 * phase 4 (no inode discovery)
873 * because the parent info will
876 if (!ino_discovery
) {
878 set_inode_parent(ino_rec
, irec_offset
, parent
);
880 get_inode_parent(ino_rec
, irec_offset
));
883 clear_inode_isadir(ino_rec
, irec_offset
);
887 if (mp
->m_sb
.sb_rootino
== ino
) {
892 _("cleared root inode %" PRIu64
"\n"),
896 _("would clear root inode %" PRIu64
"\n"),
899 } else if (mp
->m_sb
.sb_rbmino
== ino
) {
904 _("cleared realtime bitmap inode %" PRIu64
"\n"),
908 _("would clear realtime bitmap inode %" PRIu64
"\n"),
911 } else if (mp
->m_sb
.sb_rsumino
== ino
) {
916 _("cleared realtime summary inode %" PRIu64
"\n"),
920 _("would clear realtime summary inode %" PRIu64
"\n"),
923 } else if (!no_modify
) {
924 do_warn(_("cleared inode %" PRIu64
"\n"),
927 do_warn(_("would have cleared inode %" PRIu64
"\n"),
930 clear_inode_was_rl(ino_rec
, irec_offset
);
939 if (icnt
== mp
->m_ialloc_inos
&&
940 irec_offset
== XFS_INODES_PER_CHUNK
) {
942 * done! - finished up irec and block simultaneously
944 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
945 if (!bplist
[bp_index
])
948 pftrace("put/writebuf %p (%llu) in AG %d",
949 bplist
[bp_index
], (long long)
950 XFS_BUF_ADDR(bplist
[bp_index
]), agno
);
952 if (dirty
&& !no_modify
)
953 libxfs_writebuf(bplist
[bp_index
], 0);
955 libxfs_putbuf(bplist
[bp_index
]);
959 } else if (ibuf_offset
== mp
->m_sb
.sb_inopblock
) {
961 * mark block as an inode block in the incore bitmap
962 * and reset inode buffer offset counter
967 if (!is_inode_sparse(ino_rec
, irec_offset
))
968 process_inode_agbno_state(mp
, agno
, agbno
);
969 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
971 * get new irec (multiple chunks per block fs)
973 ino_rec
= next_ino_rec(ino_rec
);
974 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
977 if (cluster_offset
== inodes_per_cluster
) {
986 * check all inodes mentioned in the ag's incore inode maps.
987 * the map may be incomplete. If so, we'll catch the missing
988 * inodes (hopefully) when we traverse the directory tree.
989 * check_dirs is set to 1 if directory inodes should be
990 * processed for internal consistency, parent setting and
991 * discovery of unknown inodes. this only happens
992 * in phase 3. check_dups is set to 1 if we're looking for
993 * inodes that reference duplicate blocks so we can trash
994 * the inode right then and there. this is set only in
995 * phase 4 after we've run through and set the bitmap once.
1000 prefetch_args_t
*pf_args
,
1001 xfs_agnumber_t agno
,
1004 int extra_attr_check
)
1006 int num_inos
, bogus
;
1007 ino_tree_node_t
*ino_rec
, *first_ino_rec
, *prev_ino_rec
;
1011 first_ino_rec
= ino_rec
= findfirst_inode_rec(agno
);
1013 while (ino_rec
!= NULL
) {
1015 * paranoia - step through inode records until we step
1016 * through a full allocation of inodes. this could
1017 * be an issue in big-block filesystems where a block
1018 * can hold more than one inode chunk. make sure to
1019 * grab the record corresponding to the beginning of
1020 * the next block before we call the processing routines.
1022 num_inos
= XFS_INODES_PER_CHUNK
;
1023 while (num_inos
< mp
->m_ialloc_inos
&& ino_rec
!= NULL
) {
1025 * inodes chunks will always be aligned and sized
1028 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1029 num_inos
+= XFS_INODES_PER_CHUNK
;
1032 ASSERT(num_inos
== mp
->m_ialloc_inos
);
1035 sem_post(&pf_args
->ra_count
);
1037 sem_getvalue(&pf_args
->ra_count
, &count
);
1038 pftrace("processing inode chunk %p in AG %d (sem count = %d)",
1039 first_ino_rec
, agno
, count
);
1043 if (process_inode_chunk(mp
, agno
, num_inos
, first_ino_rec
,
1044 ino_discovery
, check_dups
, extra_attr_check
,
1046 /* XXX - i/o error, we've got a problem */
1051 first_ino_rec
= ino_rec
= next_ino_rec(ino_rec
);
1054 * inodes pointed to by this record are
1055 * completely bogus, blow the records for
1057 * the inode block(s) will get reclaimed
1058 * in phase 4 when the block map is
1059 * reconstructed after inodes claiming
1060 * duplicate blocks are deleted.
1063 ino_rec
= first_ino_rec
;
1064 while (num_inos
< mp
->m_ialloc_inos
&&
1066 prev_ino_rec
= ino_rec
;
1068 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1069 num_inos
+= XFS_INODES_PER_CHUNK
;
1071 get_inode_rec(mp
, agno
, prev_ino_rec
);
1072 free_inode_rec(agno
, prev_ino_rec
);
1075 first_ino_rec
= ino_rec
;
1077 PROG_RPT_INC(prog_rpt_done
[agno
], num_inos
);
1082 * verify the uncertain inode list for an ag.
1083 * Good inodes get moved into the good inode tree.
1084 * returns 0 if there are no uncertain inode records to
1085 * be processed, 1 otherwise. This routine destroys the
1086 * the entire uncertain inode tree for the ag as a side-effect.
1089 check_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1091 ino_tree_node_t
*irec
;
1092 ino_tree_node_t
*nrec
;
1101 clear_uncertain_ino_cache(agno
);
1103 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1107 * the trick here is to find a contiguous range
1108 * of inodes, make sure that it doesn't overlap
1109 * with a known to exist chunk, and then make
1110 * sure it is a number of entire chunks.
1111 * we check on-disk once we have an idea of what's
1112 * going on just to double-check.
1114 * process the uncertain inode record list and look
1115 * on disk to see if the referenced inodes are good
1118 do_warn(_("found inodes not in the inode allocation tree\n"));
1122 * check every confirmed (which in this case means
1123 * inode that we really suspect to be an inode) inode
1125 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1126 if (!is_inode_confirmed(irec
, i
))
1129 agino
= i
+ irec
->ino_startnum
;
1131 if (verify_aginum(mp
, agno
, agino
))
1134 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1135 agino
< nrec
->ino_startnum
+
1136 XFS_INODES_PER_CHUNK
)
1139 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) == NULL
)
1140 if (!verify_aginum(mp
, agno
, agino
))
1141 if (verify_aginode_chunk(mp
, agno
,
1146 get_uncertain_inode_rec(mp
, agno
, irec
);
1147 free_inode_rec(agno
, irec
);
1149 irec
= findfirst_uncertain_inode_rec(agno
);
1150 } while (irec
!= NULL
);
1153 do_warn(_("found inodes not in the inode allocation tree\n"));
1159 * verify and process the uncertain inodes for an ag.
1160 * this is different from check_ in that we can't just
1161 * move the good inodes into the good inode tree and let
1162 * process_aginodes() deal with them because this gets called
1163 * after process_aginodes() has been run on the ag inode tree.
1164 * So we have to process the inodes as well as verify since
1165 * we don't want to rerun process_aginodes() on a tree that has
1166 * mostly been processed.
1168 * Note that if this routine does process some inodes, it can
1169 * add uncertain inodes to any ag which would require that
1170 * the routine be called again to process those newly-added
1173 * returns 0 if no inodes were processed and 1 if inodes
1174 * were processed (and it is possible that new uncertain
1175 * inodes were discovered).
1177 * as a side-effect, this routine tears down the uncertain
1178 * inode tree for the ag.
1181 process_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1183 ino_tree_node_t
*irec
;
1184 ino_tree_node_t
*nrec
;
1191 #ifdef XR_INODE_TRACE
1192 fprintf(stderr
, "in process_uncertain_aginodes, agno = %d\n", agno
);
1197 clear_uncertain_ino_cache(agno
);
1199 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1206 * check every confirmed inode
1208 for (cnt
= i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1209 if (!is_inode_confirmed(irec
, i
))
1212 agino
= i
+ irec
->ino_startnum
;
1213 #ifdef XR_INODE_TRACE
1214 fprintf(stderr
, "ag inode = %d (0x%x)\n", agino
, agino
);
1217 * skip over inodes already processed (in the
1218 * good tree), bad inode numbers, and inode numbers
1219 * pointing to bogus inodes
1221 if (verify_aginum(mp
, agno
, agino
))
1224 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1225 agino
< nrec
->ino_startnum
+
1226 XFS_INODES_PER_CHUNK
)
1229 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) != NULL
)
1233 * verify the chunk. if good, it will be
1234 * added to the good inode tree.
1236 if ((nrec
= verify_aginode_chunk_irec(mp
,
1237 agno
, agino
)) == NULL
)
1243 * process the inode record we just added
1244 * to the good inode tree. The inode
1245 * processing may add more records to the
1246 * uncertain inode lists.
1248 if (process_inode_chunk(mp
, agno
, mp
->m_ialloc_inos
,
1249 nrec
, 1, 0, 0, &bogus
)) {
1250 /* XXX - i/o error, we've got a problem */
1257 * now return the uncertain inode record to the free pool
1258 * and pull another one off the list for processing
1260 get_uncertain_inode_rec(mp
, agno
, irec
);
1261 free_inode_rec(agno
, irec
);
1263 irec
= findfirst_uncertain_inode_rec(agno
);
1264 } while (irec
!= NULL
);
1267 do_warn(_("found inodes not in the inode allocation tree\n"));