1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
13 #include "err_protos.h"
20 * validates inode block or chunk, returns # of good inodes
21 * the dinodes are verified using verify_uncertain_dinode() which
22 * means only the basic inode info is checked, no fork checks.
30 struct xfs_dinode
*dino_p
;
37 * it's ok to read these possible inode blocks in one at
38 * a time because they don't belong to known inodes (if
39 * they did, we'd know about them courtesy of the incore inode
40 * tree and we wouldn't be here and we stale the buffers out
41 * so no one else will overlap them.
43 error
= -libxfs_buf_read(mp
->m_dev
, XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
44 XFS_FSB_TO_BB(mp
, 1), LIBXFS_READBUF_SALVAGE
, &bp
,
47 do_warn(_("cannot read agbno (%u/%u), disk block %" PRId64
"\n"),
48 agno
, agbno
, XFS_AGB_TO_DADDR(mp
, agno
, agbno
));
52 for (i
= 0; i
< mp
->m_sb
.sb_inopblock
; i
++) {
53 dino_p
= xfs_make_iptr(mp
, bp
, i
);
54 if (!verify_uncertain_dinode(mp
, dino_p
, agno
,
55 XFS_OFFBNO_TO_AGINO(mp
, agbno
, i
)))
59 bp
->b_ops
= &xfs_inode_buf_ops
;
66 * tries to establish if the inode really exists in a valid
67 * inode chunk. returns number of new inodes if things are good
68 * and 0 if bad. start is the start of the discovered inode chunk.
69 * routine assumes that ino is a legal inode number
70 * (verified by libxfs_verify_ino()). If the inode chunk turns out
71 * to be good, this routine will put the inode chunk into
72 * the good inode chunk tree if required.
74 * the verify_(ag)inode* family of routines are utility
75 * routines called by check_uncertain_aginodes() and
76 * process_uncertain_aginodes().
79 verify_inode_chunk(xfs_mount_t
*mp
,
85 xfs_agino_t start_agino
;
87 xfs_agblock_t start_agbno
= 0;
88 xfs_agblock_t end_agbno
;
89 xfs_agblock_t max_agbno
;
90 xfs_agblock_t cur_agbno
;
91 xfs_agblock_t chunk_start_agbno
;
92 xfs_agblock_t chunk_stop_agbno
;
93 ino_tree_node_t
*irec_before_p
= NULL
;
94 ino_tree_node_t
*irec_after_p
= NULL
;
95 ino_tree_node_t
*irec_p
;
96 ino_tree_node_t
*irec_next_p
;
104 struct xfs_ino_geometry
*igeo
= M_IGEO(mp
);
106 agno
= XFS_INO_TO_AGNO(mp
, ino
);
107 agino
= XFS_INO_TO_AGINO(mp
, ino
);
108 agbno
= XFS_INO_TO_AGBNO(mp
, ino
);
109 *start_ino
= NULLFSINO
;
111 ASSERT(igeo
->ialloc_blks
> 0);
113 if (agno
== mp
->m_sb
.sb_agcount
- 1)
114 max_agbno
= mp
->m_sb
.sb_dblocks
-
115 (xfs_rfsblock_t
) mp
->m_sb
.sb_agblocks
* agno
;
117 max_agbno
= mp
->m_sb
.sb_agblocks
;
120 * is the inode beyond the end of the AG?
122 if (agbno
>= max_agbno
)
126 * check for the easy case, inodes per block >= XFS_INODES_PER_CHUNK
127 * (multiple chunks per block)
129 if (igeo
->ialloc_blks
== 1) {
130 if (agbno
> max_agbno
)
132 if (check_aginode_block(mp
, agno
, agino
) == 0)
135 pthread_mutex_lock(&ag_locks
[agno
].lock
);
137 state
= get_bmap(agno
, agbno
);
141 _("uncertain inode block %d/%d already known\n"),
147 set_bmap(agno
, agbno
, XR_E_INO
);
154 * if block is already claimed, forget it.
157 _("inode block %d/%d multiply claimed, (state %d)\n"),
159 set_bmap(agno
, agbno
, XR_E_MULT
);
160 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
164 _("inode block %d/%d bad state, (state %d)\n"),
166 set_bmap(agno
, agbno
, XR_E_INO
);
170 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
172 start_agino
= XFS_AGB_TO_AGINO(mp
, agbno
);
173 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
176 * put new inode record(s) into inode tree
178 for (j
= 0; j
< chunks_pblock
; j
++) {
179 if ((irec_p
= find_inode_rec(mp
, agno
, start_agino
))
181 irec_p
= set_inode_free_alloc(mp
, agno
,
183 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
184 set_inode_free(irec_p
, i
);
186 if (start_agino
<= agino
&& agino
<
187 start_agino
+ XFS_INODES_PER_CHUNK
)
188 set_inode_used(irec_p
, agino
- start_agino
);
190 start_agino
+= XFS_INODES_PER_CHUNK
;
191 ino_cnt
+= XFS_INODES_PER_CHUNK
;
195 } else if (fs_aligned_inodes
) {
197 * next easy case -- aligned inode filesystem.
198 * just check out the chunk
200 start_agbno
= rounddown(XFS_INO_TO_AGBNO(mp
, ino
),
202 end_agbno
= start_agbno
+ igeo
->ialloc_blks
;
205 * if this fs has aligned inodes but the end of the
206 * chunk is beyond the end of the ag, this is a bad
209 if (end_agbno
> max_agbno
)
213 * check out all blocks in chunk
216 for (cur_agbno
= start_agbno
; cur_agbno
< end_agbno
;
218 ino_cnt
+= check_aginode_block(mp
, agno
, cur_agbno
);
222 * if we lose either 2 blocks worth of inodes or >25% of
223 * the chunk, just forget it.
225 if (ino_cnt
< XFS_INODES_PER_CHUNK
- 2 * mp
->m_sb
.sb_inopblock
226 || ino_cnt
< XFS_INODES_PER_CHUNK
- 16)
230 * ok, put the record into the tree, if no conflict.
232 if (find_inode_rec(mp
, agno
, XFS_AGB_TO_AGINO(mp
, start_agbno
)))
235 start_agino
= XFS_AGB_TO_AGINO(mp
, start_agbno
);
236 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
238 irec_p
= set_inode_free_alloc(mp
, agno
,
239 XFS_AGB_TO_AGINO(mp
, start_agbno
));
241 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
242 set_inode_free(irec_p
, i
);
244 ASSERT(start_agino
<= agino
&&
245 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
247 set_inode_used(irec_p
, agino
- start_agino
);
249 return(XFS_INODES_PER_CHUNK
);
253 * hard case -- pre-6.3 filesystem.
254 * set default start/end agbnos and ensure agbnos are legal.
255 * we're setting a range [start_agbno, end_agbno) such that
256 * a discovered inode chunk completely within that range
257 * would include the inode passed into us.
259 if (igeo
->ialloc_blks
> 1) {
260 if (agino
> igeo
->ialloc_inos
)
261 start_agbno
= agbno
- igeo
->ialloc_blks
+ 1;
266 end_agbno
= agbno
+ igeo
->ialloc_blks
;
268 if (end_agbno
> max_agbno
)
269 end_agbno
= max_agbno
;
272 * search tree for known inodes within +/- 1 inode chunk range
274 irec_before_p
= irec_after_p
= NULL
;
276 find_inode_rec_range(mp
, agno
, XFS_AGB_TO_AGINO(mp
, start_agbno
),
277 XFS_OFFBNO_TO_AGINO(mp
, end_agbno
, mp
->m_sb
.sb_inopblock
- 1),
278 &irec_before_p
, &irec_after_p
);
281 * if we have known inode chunks in our search range, establish
282 * their start and end-points to tighten our search range. range
283 * is [start, end) -- e.g. max/end agbno is one beyond the
284 * last block to be examined. the avl routines work this way.
288 * only one inode record in the range, move one boundary in
290 if (irec_before_p
== irec_after_p
) {
291 if (irec_before_p
->ino_startnum
< agino
)
292 start_agbno
= XFS_AGINO_TO_AGBNO(mp
,
293 irec_before_p
->ino_startnum
+
294 XFS_INODES_PER_CHUNK
);
296 end_agbno
= XFS_AGINO_TO_AGBNO(mp
,
297 irec_before_p
->ino_startnum
);
301 * find the start of the gap in the search range (which
302 * should contain our unknown inode). if the only irec
303 * within +/- 1 chunks starts after the inode we're
304 * looking for, skip this stuff since the end_agbno
305 * of the range has already been trimmed in to not
308 if (irec_before_p
->ino_startnum
< agino
) {
309 irec_p
= irec_before_p
;
310 irec_next_p
= next_ino_rec(irec_p
);
312 while(irec_next_p
!= NULL
&&
313 irec_p
->ino_startnum
+ XFS_INODES_PER_CHUNK
==
314 irec_next_p
->ino_startnum
) {
315 irec_p
= irec_next_p
;
316 irec_next_p
= next_ino_rec(irec_next_p
);
319 start_agbno
= XFS_AGINO_TO_AGBNO(mp
,
320 irec_p
->ino_startnum
) +
324 * we know that the inode we're trying to verify isn't
325 * in an inode chunk so the next ino_rec marks the end
326 * of the gap -- is it within the search range?
328 if (irec_next_p
!= NULL
&&
329 agino
+ igeo
->ialloc_inos
>=
330 irec_next_p
->ino_startnum
)
331 end_agbno
= XFS_AGINO_TO_AGBNO(mp
,
332 irec_next_p
->ino_startnum
);
335 ASSERT(start_agbno
< end_agbno
);
339 * if the gap is too small to contain a chunk, we lose.
340 * this means that inode chunks known to be good surround
341 * the inode in question and that the space between them
342 * is too small for a legal inode chunk
344 if (end_agbno
- start_agbno
< igeo
->ialloc_blks
)
348 * now grunge around the disk, start at the inode block and
349 * go in each direction until you hit a non-inode block or
350 * run into a range boundary. A non-inode block is block
351 * with *no* good inodes in it. Unfortunately, we can't
352 * co-opt bad blocks into inode chunks (which might take
353 * care of disk blocks that turn into zeroes) because the
354 * filesystem could very well allocate two inode chunks
355 * with a one block file in between and we'd zap the file.
356 * We're better off just losing the rest of the
357 * inode chunk instead.
359 for (cur_agbno
= agbno
; cur_agbno
>= start_agbno
; cur_agbno
--) {
361 * if the block has no inodes, it's a bad block so
362 * break out now without decrementing cur_agbno so
363 * chunk start blockno will be set to the last good block
365 if (!(irec_cnt
= check_aginode_block(mp
, agno
, cur_agbno
)))
370 chunk_start_agbno
= cur_agbno
+ 1;
372 for (cur_agbno
= agbno
+ 1; cur_agbno
< end_agbno
; cur_agbno
++) {
374 * if the block has no inodes, it's a bad block so
375 * break out now without incrementing cur_agbno so
376 * chunk start blockno will be set to the block
377 * immediately after the last good block.
379 if (!(irec_cnt
= check_aginode_block(mp
, agno
, cur_agbno
)))
384 chunk_stop_agbno
= cur_agbno
;
386 num_blks
= chunk_stop_agbno
- chunk_start_agbno
;
388 if (num_blks
< igeo
->ialloc_blks
|| ino_cnt
== 0)
392 * XXX - later - if the entire range is selected and they're all
393 * good inodes, keep searching in either direction.
394 * until you the range of inodes end, then split into chunks
395 * for now, just take one chunk's worth starting at the lowest
396 * possible point and hopefully we'll pick the rest up later.
398 * XXX - if we were going to fix up an inode chunk for
399 * any good inodes in the chunk, this is where we would
400 * do it. For now, keep it simple and lose the rest of
404 if (num_blks
% igeo
->ialloc_blks
!= 0) {
405 num_blks
= rounddown(num_blks
, igeo
->ialloc_blks
);
406 chunk_stop_agbno
= chunk_start_agbno
+ num_blks
;
410 * ok, we've got a candidate inode chunk. now we have to
411 * verify that we aren't trying to use blocks that are already
412 * in use. If so, mark them as multiply claimed since odds
413 * are very low that we found this chunk by stumbling across
414 * user data -- we're probably here as a result of a directory
415 * entry or an iunlinked pointer
417 pthread_mutex_lock(&ag_locks
[agno
].lock
);
418 for (cur_agbno
= chunk_start_agbno
;
419 cur_agbno
< chunk_stop_agbno
;
421 state
= get_bmap_ext(agno
, cur_agbno
, chunk_stop_agbno
, &blen
);
428 _("inode block %d/%d multiply claimed, (state %d)\n"),
429 agno
, cur_agbno
, state
);
430 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_MULT
);
431 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
435 _("uncertain inode block overlap, agbno = %d, ino = %" PRIu64
"\n"),
442 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
445 * ok, chunk is good. put the record into the tree if required,
446 * and fill in the bitmap. All inodes will be marked as "free"
447 * except for the one that led us to discover the chunk. That's
448 * ok because we'll override the free setting later if the
449 * contents of the inode indicate it's in use.
451 start_agino
= XFS_AGB_TO_AGINO(mp
, chunk_start_agbno
);
452 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
454 ASSERT(find_inode_rec(mp
, agno
, start_agino
) == NULL
);
456 irec_p
= set_inode_free_alloc(mp
, agno
, start_agino
);
457 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
458 set_inode_free(irec_p
, i
);
460 ASSERT(start_agino
<= agino
&&
461 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
463 set_inode_used(irec_p
, agino
- start_agino
);
465 pthread_mutex_lock(&ag_locks
[agno
].lock
);
467 for (cur_agbno
= chunk_start_agbno
;
468 cur_agbno
< chunk_stop_agbno
;
470 state
= get_bmap_ext(agno
, cur_agbno
, chunk_stop_agbno
, &blen
);
474 _("uncertain inode block %" PRIu64
" already known\n"),
475 XFS_AGB_TO_FSB(mp
, agno
, cur_agbno
));
480 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_INO
);
487 _("inode block %d/%d multiply claimed, (state %d)\n"),
488 agno
, cur_agbno
, state
);
492 _("inode block %d/%d bad state, (state %d)\n"),
493 agno
, cur_agbno
, state
);
494 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_INO
);
498 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
504 * same as above only for ag inode chunks
507 verify_aginode_chunk(xfs_mount_t
*mp
,
510 xfs_agino_t
*agino_start
)
515 res
= verify_inode_chunk(mp
, XFS_AGINO_TO_INO(mp
, agno
, agino
), &ino
);
518 *agino_start
= XFS_INO_TO_AGINO(mp
, ino
);
520 *agino_start
= NULLAGINO
;
526 * this does the same as the two above only it returns a pointer
527 * to the inode record in the good inode tree
529 static ino_tree_node_t
*
530 verify_aginode_chunk_irec(xfs_mount_t
*mp
,
534 xfs_agino_t start_agino
;
535 ino_tree_node_t
*irec
= NULL
;
537 if (verify_aginode_chunk(mp
, agno
, agino
, &start_agino
))
538 irec
= find_inode_rec(mp
, agno
, start_agino
);
544 * Set the state of an inode block during inode chunk processing. The block is
545 * expected to be in the free or inode state. If free, it transitions to the
546 * inode state. Warn if the block is in neither expected state as this indicates
547 * multiply claimed blocks.
550 process_inode_agbno_state(
551 struct xfs_mount
*mp
,
557 pthread_mutex_lock(&ag_locks
[agno
].lock
);
558 state
= get_bmap(agno
, agbno
);
560 case XR_E_INO
: /* already marked */
565 set_bmap(agno
, agbno
, XR_E_INO
);
568 do_error(_("bad state in block map %d\n"), state
);
571 set_bmap(agno
, agbno
, XR_E_MULT
);
573 _("inode block %" PRIu64
" multiply claimed, state was %d\n"),
574 XFS_AGB_TO_FSB(mp
, agno
, agbno
), state
);
577 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
581 * processes an inode allocation chunk/block, returns 1 on I/O errors,
584 * *bogus is set to 1 if the entire set of inodes is bad.
591 ino_tree_node_t
*first_irec
,
594 int extra_attr_check
,
598 ino_tree_node_t
*ino_rec
;
599 struct xfs_buf
**bplist
;
600 struct xfs_dinode
*dino
;
616 struct xfs_ino_geometry
*igeo
= M_IGEO(mp
);
617 bool can_punch_sparse
= false;
620 ASSERT(first_irec
!= NULL
);
621 ASSERT(XFS_AGINO_TO_OFFSET(mp
, first_irec
->ino_startnum
) == 0);
624 ASSERT(igeo
->ialloc_blks
> 0);
626 cluster_count
= XFS_INODES_PER_CHUNK
/ M_IGEO(mp
)->inodes_per_cluster
;
627 if (cluster_count
== 0)
630 if (xfs_has_sparseinodes(mp
) &&
631 M_IGEO(mp
)->inodes_per_cluster
>= XFS_INODES_PER_HOLEMASK_BIT
)
632 can_punch_sparse
= true;
635 * get all blocks required to read in this chunk (may wind up
636 * having to process more chunks in a multi-chunk per block fs)
638 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
643 ino_rec
= first_irec
;
646 bplist
= malloc(cluster_count
* sizeof(struct xfs_buf
*));
648 do_error(_("failed to allocate %zd bytes of memory\n"),
649 cluster_count
* sizeof(struct xfs_buf
*));
651 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
653 * Skip the cluster buffer if the first inode is sparse. The
654 * remaining inodes in the cluster share the same state as
655 * sparse inodes occur at cluster granularity.
657 if (is_inode_sparse(ino_rec
, irec_offset
)) {
658 pftrace("skip sparse inode, startnum 0x%x idx %d",
659 ino_rec
->ino_startnum
, irec_offset
);
660 bplist
[bp_index
] = NULL
;
664 pftrace("about to read off %llu in AG %d",
665 XFS_AGB_TO_DADDR(mp
, agno
, agbno
), agno
);
667 error
= -libxfs_buf_read(mp
->m_dev
,
668 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
670 M_IGEO(mp
)->blocks_per_cluster
),
671 LIBXFS_READBUF_SALVAGE
, &bplist
[bp_index
],
674 do_warn(_("cannot read inode %" PRIu64
", disk block %" PRId64
", cnt %d\n"),
675 XFS_AGINO_TO_INO(mp
, agno
, first_irec
->ino_startnum
),
676 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
678 M_IGEO(mp
)->blocks_per_cluster
));
679 while (bp_index
> 0) {
681 libxfs_buf_relse(bplist
[bp_index
]);
687 pftrace("readbuf %p (%llu, %d) in AG %d", bplist
[bp_index
],
688 (long long)xfs_buf_daddr(bplist
[bp_index
]),
689 bplist
[bp_index
]->b_length
, agno
);
691 bplist
[bp_index
]->b_ops
= &xfs_inode_buf_ops
;
694 irec_offset
+= mp
->m_sb
.sb_inopblock
*
695 M_IGEO(mp
)->blocks_per_cluster
;
696 agbno
+= M_IGEO(mp
)->blocks_per_cluster
;
698 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
701 * initialize counters
712 * verify inode chunk if necessary
716 agino
= irec_offset
+ ino_rec
->ino_startnum
;
718 /* no buffers for sparse clusters */
719 if (bplist
[bp_index
]) {
720 /* make inode pointer */
721 dino
= xfs_make_iptr(mp
, bplist
[bp_index
],
725 * we always think that the root and realtime
726 * inodes are verified even though we may have
727 * to reset them later to keep from losing the
728 * chunk that they're in
730 if (verify_dinode(mp
, dino
, agno
, agino
) == 0 ||
732 (mp
->m_sb
.sb_rootino
== agino
||
733 mp
->m_sb
.sb_rsumino
== agino
||
734 mp
->m_sb
.sb_rbmino
== agino
))) {
744 if (icnt
== igeo
->ialloc_inos
&&
745 irec_offset
== XFS_INODES_PER_CHUNK
) {
747 * done! - finished up irec and block
751 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
753 * get new irec (multiple chunks per block fs)
755 ino_rec
= next_ino_rec(ino_rec
);
756 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
759 if (cluster_offset
== M_IGEO(mp
)->inodes_per_cluster
) {
760 if (can_punch_sparse
&&
761 bplist
[bp_index
] != NULL
&&
764 * We didn't find any good inodes in
765 * this cluster, blow it away before
766 * moving on to the next one.
768 libxfs_buf_relse(bplist
[bp_index
]);
769 bplist
[bp_index
] = NULL
;
777 if (can_punch_sparse
&&
778 bp_index
< cluster_count
&&
779 bplist
[bp_index
] != NULL
&&
782 * We didn't find any good inodes in this cluster, blow
785 libxfs_buf_relse(bplist
[bp_index
]);
786 bplist
[bp_index
] = NULL
;
790 * if chunk/block is bad, blow it off. the inode records
791 * will be deleted by the caller if appropriate.
795 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++)
796 if (bplist
[bp_index
])
797 libxfs_buf_relse(bplist
[bp_index
]);
803 * reset irec and counters
805 ino_rec
= first_irec
;
815 * mark block as an inode block in the incore bitmap
817 if (!is_inode_sparse(ino_rec
, irec_offset
))
818 process_inode_agbno_state(mp
, agno
, agbno
);
821 agino
= irec_offset
+ ino_rec
->ino_startnum
;
822 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
824 if (is_inode_sparse(ino_rec
, irec_offset
))
828 * Repair skips reading the cluster buffer if the first inode
829 * in the cluster is marked as sparse. If subsequent inodes in
830 * the cluster buffer are /not/ marked sparse, there won't be
831 * a buffer, so we need to avoid the null pointer dereference.
833 if (bplist
[bp_index
] == NULL
) {
835 _("imap claims inode %" PRIu64
" is present, but inode cluster is sparse, "),
838 do_warn(_("correcting imap\n"));
840 do_warn(_("would correct imap\n"));
841 set_inode_sparse(ino_rec
, irec_offset
);
842 set_inode_free(ino_rec
, irec_offset
);
846 /* make inode pointer */
847 dino
= xfs_make_iptr(mp
, bplist
[bp_index
], cluster_offset
);
854 status
= process_dinode(mp
, dino
, agno
, agino
,
855 is_inode_free(ino_rec
, irec_offset
),
856 &ino_dirty
, &is_used
,ino_discovery
, check_dups
,
857 extra_attr_check
, &isa_dir
, &parent
);
859 ASSERT(is_used
!= 3);
862 libxfs_dinode_calc_crc(mp
, dino
);
866 * XXX - if we want to try and keep
867 * track of whether we need to bang on
868 * the inode maps (instead of just
869 * blindly reconstructing them like
870 * we do now, this is where to start.
873 if (is_inode_free(ino_rec
, irec_offset
)) {
875 _("imap claims in-use inode %" PRIu64
" is free, "),
879 do_warn(_("correcting imap\n"));
881 do_warn(_("would correct imap\n"));
883 set_inode_used(ino_rec
, irec_offset
);
886 * store the on-disk file type for comparing in
889 set_inode_ftype(ino_rec
, irec_offset
,
890 libxfs_mode_to_ftype(be16_to_cpu(dino
->di_mode
)));
893 * store on-disk nlink count for comparing in phase 7
895 set_inode_disk_nlinks(ino_rec
, irec_offset
,
897 ? be32_to_cpu(dino
->di_nlink
)
898 : be16_to_cpu(dino
->di_onlink
));
901 set_inode_free(ino_rec
, irec_offset
);
905 * if we lose the root inode, or it turns into
906 * a non-directory, that allows us to double-check
907 * later whether or not we need to reinitialize it.
910 set_inode_isadir(ino_rec
, irec_offset
);
913 set_inode_parent(ino_rec
, irec_offset
, parent
);
915 get_inode_parent(ino_rec
, irec_offset
));
918 clear_inode_isadir(ino_rec
, irec_offset
);
922 if (mp
->m_sb
.sb_rootino
== ino
) {
927 _("cleared root inode %" PRIu64
"\n"),
931 _("would clear root inode %" PRIu64
"\n"),
934 } else if (mp
->m_sb
.sb_rbmino
== ino
) {
939 _("cleared realtime bitmap inode %" PRIu64
"\n"),
943 _("would clear realtime bitmap inode %" PRIu64
"\n"),
946 } else if (mp
->m_sb
.sb_rsumino
== ino
) {
951 _("cleared realtime summary inode %" PRIu64
"\n"),
955 _("would clear realtime summary inode %" PRIu64
"\n"),
958 } else if (!no_modify
) {
959 do_warn(_("cleared inode %" PRIu64
"\n"),
962 do_warn(_("would have cleared inode %" PRIu64
"\n"),
965 clear_inode_was_rl(ino_rec
, irec_offset
);
974 if (icnt
== igeo
->ialloc_inos
&&
975 irec_offset
== XFS_INODES_PER_CHUNK
) {
977 * done! - finished up irec and block simultaneously
979 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
980 if (!bplist
[bp_index
])
983 pftrace("put/writebuf %p (%llu) in AG %d",
984 bplist
[bp_index
], (long long)
985 xfs_buf_daddr(bplist
[bp_index
]), agno
);
987 if (dirty
&& !no_modify
) {
988 libxfs_buf_mark_dirty(bplist
[bp_index
]);
989 libxfs_buf_relse(bplist
[bp_index
]);
992 libxfs_buf_relse(bplist
[bp_index
]);
996 } else if (ibuf_offset
== mp
->m_sb
.sb_inopblock
) {
998 * mark block as an inode block in the incore bitmap
999 * and reset inode buffer offset counter
1004 if (!is_inode_sparse(ino_rec
, irec_offset
))
1005 process_inode_agbno_state(mp
, agno
, agbno
);
1006 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
1008 * get new irec (multiple chunks per block fs)
1010 ino_rec
= next_ino_rec(ino_rec
);
1011 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
1014 if (cluster_offset
== M_IGEO(mp
)->inodes_per_cluster
) {
1023 * check all inodes mentioned in the ag's incore inode maps.
1024 * the map may be incomplete. If so, we'll catch the missing
1025 * inodes (hopefully) when we traverse the directory tree.
1026 * check_dirs is set to 1 if directory inodes should be
1027 * processed for internal consistency, parent setting and
1028 * discovery of unknown inodes. this only happens
1029 * in phase 3. check_dups is set to 1 if we're looking for
1030 * inodes that reference duplicate blocks so we can trash
1031 * the inode right then and there. this is set only in
1032 * phase 4 after we've run through and set the bitmap once.
1037 prefetch_args_t
*pf_args
,
1038 xfs_agnumber_t agno
,
1041 int extra_attr_check
)
1043 int num_inos
, bogus
;
1044 ino_tree_node_t
*ino_rec
, *first_ino_rec
, *prev_ino_rec
;
1045 struct xfs_ino_geometry
*igeo
= M_IGEO(mp
);
1049 first_ino_rec
= ino_rec
= findfirst_inode_rec(agno
);
1051 while (ino_rec
!= NULL
) {
1053 * paranoia - step through inode records until we step
1054 * through a full allocation of inodes. this could
1055 * be an issue in big-block filesystems where a block
1056 * can hold more than one inode chunk. make sure to
1057 * grab the record corresponding to the beginning of
1058 * the next block before we call the processing routines.
1060 num_inos
= XFS_INODES_PER_CHUNK
;
1061 while (num_inos
< igeo
->ialloc_inos
&& ino_rec
!= NULL
) {
1063 * inodes chunks will always be aligned and sized
1066 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1067 num_inos
+= XFS_INODES_PER_CHUNK
;
1070 ASSERT(num_inos
== igeo
->ialloc_inos
);
1073 sem_post(&pf_args
->ra_count
);
1075 sem_getvalue(&pf_args
->ra_count
, &count
);
1076 pftrace("processing inode chunk %p in AG %d (sem count = %d)",
1077 first_ino_rec
, agno
, count
);
1081 if (process_inode_chunk(mp
, agno
, num_inos
, first_ino_rec
,
1082 ino_discovery
, check_dups
, extra_attr_check
,
1084 /* XXX - i/o error, we've got a problem */
1089 first_ino_rec
= ino_rec
= next_ino_rec(ino_rec
);
1092 * inodes pointed to by this record are
1093 * completely bogus, blow the records for
1095 * the inode block(s) will get reclaimed
1096 * in phase 4 when the block map is
1097 * reconstructed after inodes claiming
1098 * duplicate blocks are deleted.
1101 ino_rec
= first_ino_rec
;
1102 while (num_inos
< igeo
->ialloc_inos
&&
1104 prev_ino_rec
= ino_rec
;
1106 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1107 num_inos
+= XFS_INODES_PER_CHUNK
;
1109 get_inode_rec(mp
, agno
, prev_ino_rec
);
1110 free_inode_rec(agno
, prev_ino_rec
);
1113 first_ino_rec
= ino_rec
;
1115 PROG_RPT_INC(prog_rpt_done
[agno
], num_inos
);
1120 * verify the uncertain inode list for an ag.
1121 * Good inodes get moved into the good inode tree.
1122 * returns 0 if there are no uncertain inode records to
1123 * be processed, 1 otherwise. This routine destroys the
1124 * the entire uncertain inode tree for the ag as a side-effect.
1127 check_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1129 ino_tree_node_t
*irec
;
1130 ino_tree_node_t
*nrec
;
1135 struct xfs_perag
*pag
;
1140 clear_uncertain_ino_cache(agno
);
1142 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1146 * the trick here is to find a contiguous range
1147 * of inodes, make sure that it doesn't overlap
1148 * with a known to exist chunk, and then make
1149 * sure it is a number of entire chunks.
1150 * we check on-disk once we have an idea of what's
1151 * going on just to double-check.
1153 * process the uncertain inode record list and look
1154 * on disk to see if the referenced inodes are good
1157 do_warn(_("found inodes not in the inode allocation tree\n"));
1159 pag
= libxfs_perag_get(mp
, agno
);
1162 * check every confirmed (which in this case means
1163 * inode that we really suspect to be an inode) inode
1165 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1166 if (!is_inode_confirmed(irec
, i
))
1169 agino
= i
+ irec
->ino_startnum
;
1171 if (!libxfs_verify_agino(pag
, agino
))
1174 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1175 agino
< nrec
->ino_startnum
+
1176 XFS_INODES_PER_CHUNK
)
1179 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) == NULL
)
1180 if (libxfs_verify_agino(pag
, agino
))
1181 if (verify_aginode_chunk(mp
, agno
,
1186 get_uncertain_inode_rec(mp
, agno
, irec
);
1187 free_inode_rec(agno
, irec
);
1189 irec
= findfirst_uncertain_inode_rec(agno
);
1190 } while (irec
!= NULL
);
1191 libxfs_perag_put(pag
);
1194 do_warn(_("found inodes not in the inode allocation tree\n"));
1200 * verify and process the uncertain inodes for an ag.
1201 * this is different from check_ in that we can't just
1202 * move the good inodes into the good inode tree and let
1203 * process_aginodes() deal with them because this gets called
1204 * after process_aginodes() has been run on the ag inode tree.
1205 * So we have to process the inodes as well as verify since
1206 * we don't want to rerun process_aginodes() on a tree that has
1207 * mostly been processed.
1209 * Note that if this routine does process some inodes, it can
1210 * add uncertain inodes to any ag which would require that
1211 * the routine be called again to process those newly-added
1214 * returns 0 if no inodes were processed and 1 if inodes
1215 * were processed (and it is possible that new uncertain
1216 * inodes were discovered).
1218 * as a side-effect, this routine tears down the uncertain
1219 * inode tree for the ag.
1222 process_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1224 ino_tree_node_t
*irec
;
1225 ino_tree_node_t
*nrec
;
1231 struct xfs_ino_geometry
*igeo
= M_IGEO(mp
);
1232 struct xfs_perag
*pag
;
1234 #ifdef XR_INODE_TRACE
1235 fprintf(stderr
, "in process_uncertain_aginodes, agno = %d\n", agno
);
1240 clear_uncertain_ino_cache(agno
);
1242 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1247 pag
= libxfs_perag_get(mp
, agno
);
1250 * check every confirmed inode
1252 for (cnt
= i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1253 if (!is_inode_confirmed(irec
, i
))
1256 agino
= i
+ irec
->ino_startnum
;
1257 #ifdef XR_INODE_TRACE
1258 fprintf(stderr
, "ag inode = %d (0x%x)\n", agino
, agino
);
1261 * skip over inodes already processed (in the
1262 * good tree), bad inode numbers, and inode numbers
1263 * pointing to bogus inodes
1265 if (!libxfs_verify_agino(pag
, agino
))
1268 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1269 agino
< nrec
->ino_startnum
+
1270 XFS_INODES_PER_CHUNK
)
1273 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) != NULL
)
1277 * verify the chunk. if good, it will be
1278 * added to the good inode tree.
1280 if ((nrec
= verify_aginode_chunk_irec(mp
,
1281 agno
, agino
)) == NULL
)
1287 * process the inode record we just added
1288 * to the good inode tree. The inode
1289 * processing may add more records to the
1290 * uncertain inode lists. always process the
1291 * extended attribute structure because we might
1292 * decide that some inodes are still in use
1294 if (process_inode_chunk(mp
, agno
, igeo
->ialloc_inos
,
1295 nrec
, 1, 0, 1, &bogus
)) {
1296 /* XXX - i/o error, we've got a problem */
1303 * now return the uncertain inode record to the free pool
1304 * and pull another one off the list for processing
1306 get_uncertain_inode_rec(mp
, agno
, irec
);
1307 free_inode_rec(agno
, irec
);
1309 irec
= findfirst_uncertain_inode_rec(agno
);
1310 } while (irec
!= NULL
);
1311 libxfs_perag_put(pag
);
1314 do_warn(_("found inodes not in the inode allocation tree\n"));