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.
25 check_aginode_block(xfs_mount_t
*mp
,
36 * it's ok to read these possible inode blocks in one at
37 * a time because they don't belong to known inodes (if
38 * they did, we'd know about them courtesy of the incore inode
39 * tree and we wouldn't be here and we stale the buffers out
40 * so no one else will overlap them.
42 bp
= libxfs_readbuf(mp
->m_dev
, XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
43 XFS_FSB_TO_BB(mp
, 1), 0, NULL
);
45 do_warn(_("cannot read agbno (%u/%u), disk block %" PRId64
"\n"),
46 agno
, agbno
, XFS_AGB_TO_DADDR(mp
, agno
, agbno
));
50 for (i
= 0; i
< mp
->m_sb
.sb_inopblock
; i
++) {
51 dino_p
= xfs_make_iptr(mp
, bp
, i
);
52 if (!verify_uncertain_dinode(mp
, dino_p
, agno
,
53 XFS_OFFBNO_TO_AGINO(mp
, agbno
, i
)))
57 bp
->b_ops
= &xfs_inode_buf_ops
;
64 * tries to establish if the inode really exists in a valid
65 * inode chunk. returns number of new inodes if things are good
66 * and 0 if bad. start is the start of the discovered inode chunk.
67 * routine assumes that ino is a legal inode number
68 * (verified by verify_inum()). If the inode chunk turns out
69 * to be good, this routine will put the inode chunk into
70 * the good inode chunk tree if required.
72 * the verify_(ag)inode* family of routines are utility
73 * routines called by check_uncertain_aginodes() and
74 * process_uncertain_aginodes().
77 verify_inode_chunk(xfs_mount_t
*mp
,
83 xfs_agino_t start_agino
;
85 xfs_agblock_t start_agbno
= 0;
86 xfs_agblock_t end_agbno
;
87 xfs_agblock_t max_agbno
;
88 xfs_agblock_t cur_agbno
;
89 xfs_agblock_t chunk_start_agbno
;
90 xfs_agblock_t chunk_stop_agbno
;
91 ino_tree_node_t
*irec_before_p
= NULL
;
92 ino_tree_node_t
*irec_after_p
= NULL
;
93 ino_tree_node_t
*irec_p
;
94 ino_tree_node_t
*irec_next_p
;
103 agno
= XFS_INO_TO_AGNO(mp
, ino
);
104 agino
= XFS_INO_TO_AGINO(mp
, ino
);
105 agbno
= XFS_INO_TO_AGBNO(mp
, ino
);
106 *start_ino
= NULLFSINO
;
108 ASSERT(mp
->m_ialloc_blks
> 0);
110 if (agno
== mp
->m_sb
.sb_agcount
- 1)
111 max_agbno
= mp
->m_sb
.sb_dblocks
-
112 (xfs_rfsblock_t
) mp
->m_sb
.sb_agblocks
* agno
;
114 max_agbno
= mp
->m_sb
.sb_agblocks
;
117 * is the inode beyond the end of the AG?
119 if (agbno
>= max_agbno
)
123 * check for the easy case, inodes per block >= XFS_INODES_PER_CHUNK
124 * (multiple chunks per block)
126 if (mp
->m_ialloc_blks
== 1) {
127 if (agbno
> max_agbno
)
129 if (check_aginode_block(mp
, agno
, agino
) == 0)
132 pthread_mutex_lock(&ag_locks
[agno
].lock
);
134 state
= get_bmap(agno
, agbno
);
138 _("uncertain inode block %d/%d already known\n"),
144 set_bmap(agno
, agbno
, XR_E_INO
);
151 * if block is already claimed, forget it.
154 _("inode block %d/%d multiply claimed, (state %d)\n"),
156 set_bmap(agno
, agbno
, XR_E_MULT
);
157 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
161 _("inode block %d/%d bad state, (state %d)\n"),
163 set_bmap(agno
, agbno
, XR_E_INO
);
167 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
169 start_agino
= XFS_AGB_TO_AGINO(mp
, agbno
);
170 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
173 * put new inode record(s) into inode tree
175 for (j
= 0; j
< chunks_pblock
; j
++) {
176 if ((irec_p
= find_inode_rec(mp
, agno
, start_agino
))
178 irec_p
= set_inode_free_alloc(mp
, agno
,
180 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
181 set_inode_free(irec_p
, i
);
183 if (start_agino
<= agino
&& agino
<
184 start_agino
+ XFS_INODES_PER_CHUNK
)
185 set_inode_used(irec_p
, agino
- start_agino
);
187 start_agino
+= XFS_INODES_PER_CHUNK
;
188 ino_cnt
+= XFS_INODES_PER_CHUNK
;
192 } else if (fs_aligned_inodes
) {
194 * next easy case -- aligned inode filesystem.
195 * just check out the chunk
197 start_agbno
= rounddown(XFS_INO_TO_AGBNO(mp
, ino
),
199 end_agbno
= start_agbno
+ mp
->m_ialloc_blks
;
202 * if this fs has aligned inodes but the end of the
203 * chunk is beyond the end of the ag, this is a bad
206 if (end_agbno
> max_agbno
)
210 * check out all blocks in chunk
213 for (cur_agbno
= start_agbno
; cur_agbno
< end_agbno
;
215 ino_cnt
+= check_aginode_block(mp
, agno
, cur_agbno
);
219 * if we lose either 2 blocks worth of inodes or >25% of
220 * the chunk, just forget it.
222 if (ino_cnt
< XFS_INODES_PER_CHUNK
- 2 * mp
->m_sb
.sb_inopblock
223 || ino_cnt
< XFS_INODES_PER_CHUNK
- 16)
227 * ok, put the record into the tree, if no conflict.
229 if (find_uncertain_inode_rec(agno
,
230 XFS_AGB_TO_AGINO(mp
, start_agbno
)))
233 start_agino
= XFS_AGB_TO_AGINO(mp
, start_agbno
);
234 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
236 irec_p
= set_inode_free_alloc(mp
, agno
,
237 XFS_AGB_TO_AGINO(mp
, start_agbno
));
239 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
240 set_inode_free(irec_p
, i
);
242 ASSERT(start_agino
<= agino
&&
243 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
245 set_inode_used(irec_p
, agino
- start_agino
);
247 return(XFS_INODES_PER_CHUNK
);
251 * hard case -- pre-6.3 filesystem.
252 * set default start/end agbnos and ensure agbnos are legal.
253 * we're setting a range [start_agbno, end_agbno) such that
254 * a discovered inode chunk completely within that range
255 * would include the inode passed into us.
257 if (mp
->m_ialloc_blks
> 1) {
258 if (agino
> mp
->m_ialloc_inos
)
259 start_agbno
= agbno
- mp
->m_ialloc_blks
+ 1;
264 end_agbno
= agbno
+ mp
->m_ialloc_blks
;
266 if (end_agbno
> max_agbno
)
267 end_agbno
= max_agbno
;
270 * search tree for known inodes within +/- 1 inode chunk range
272 irec_before_p
= irec_after_p
= NULL
;
274 find_inode_rec_range(mp
, agno
, XFS_AGB_TO_AGINO(mp
, start_agbno
),
275 XFS_OFFBNO_TO_AGINO(mp
, end_agbno
, mp
->m_sb
.sb_inopblock
- 1),
276 &irec_before_p
, &irec_after_p
);
279 * if we have known inode chunks in our search range, establish
280 * their start and end-points to tighten our search range. range
281 * is [start, end) -- e.g. max/end agbno is one beyond the
282 * last block to be examined. the avl routines work this way.
286 * only one inode record in the range, move one boundary in
288 if (irec_before_p
== irec_after_p
) {
289 if (irec_before_p
->ino_startnum
< agino
)
290 start_agbno
= XFS_AGINO_TO_AGBNO(mp
,
291 irec_before_p
->ino_startnum
+
292 XFS_INODES_PER_CHUNK
);
294 end_agbno
= XFS_AGINO_TO_AGBNO(mp
,
295 irec_before_p
->ino_startnum
);
299 * find the start of the gap in the search range (which
300 * should contain our unknown inode). if the only irec
301 * within +/- 1 chunks starts after the inode we're
302 * looking for, skip this stuff since the end_agbno
303 * of the range has already been trimmed in to not
306 if (irec_before_p
->ino_startnum
< agino
) {
307 irec_p
= irec_before_p
;
308 irec_next_p
= next_ino_rec(irec_p
);
310 while(irec_next_p
!= NULL
&&
311 irec_p
->ino_startnum
+ XFS_INODES_PER_CHUNK
==
312 irec_next_p
->ino_startnum
) {
313 irec_p
= irec_next_p
;
314 irec_next_p
= next_ino_rec(irec_next_p
);
317 start_agbno
= XFS_AGINO_TO_AGBNO(mp
,
318 irec_p
->ino_startnum
) +
322 * we know that the inode we're trying to verify isn't
323 * in an inode chunk so the next ino_rec marks the end
324 * of the gap -- is it within the search range?
326 if (irec_next_p
!= NULL
&&
327 agino
+ mp
->m_ialloc_inos
>=
328 irec_next_p
->ino_startnum
)
329 end_agbno
= XFS_AGINO_TO_AGBNO(mp
,
330 irec_next_p
->ino_startnum
);
333 ASSERT(start_agbno
< end_agbno
);
337 * if the gap is too small to contain a chunk, we lose.
338 * this means that inode chunks known to be good surround
339 * the inode in question and that the space between them
340 * is too small for a legal inode chunk
342 if (end_agbno
- start_agbno
< mp
->m_ialloc_blks
)
346 * now grunge around the disk, start at the inode block and
347 * go in each direction until you hit a non-inode block or
348 * run into a range boundary. A non-inode block is block
349 * with *no* good inodes in it. Unfortunately, we can't
350 * co-opt bad blocks into inode chunks (which might take
351 * care of disk blocks that turn into zeroes) because the
352 * filesystem could very well allocate two inode chunks
353 * with a one block file in between and we'd zap the file.
354 * We're better off just losing the rest of the
355 * inode chunk instead.
357 for (cur_agbno
= agbno
; cur_agbno
>= start_agbno
; cur_agbno
--) {
359 * if the block has no inodes, it's a bad block so
360 * break out now without decrementing cur_agbno so
361 * chunk start blockno will be set to the last good block
363 if (!(irec_cnt
= check_aginode_block(mp
, agno
, cur_agbno
)))
368 chunk_start_agbno
= cur_agbno
+ 1;
370 for (cur_agbno
= agbno
+ 1; cur_agbno
< end_agbno
; cur_agbno
++) {
372 * if the block has no inodes, it's a bad block so
373 * break out now without incrementing cur_agbno so
374 * chunk start blockno will be set to the block
375 * immediately after the last good block.
377 if (!(irec_cnt
= check_aginode_block(mp
, agno
, cur_agbno
)))
382 chunk_stop_agbno
= cur_agbno
;
384 num_blks
= chunk_stop_agbno
- chunk_start_agbno
;
386 if (num_blks
< mp
->m_ialloc_blks
|| ino_cnt
== 0)
390 * XXX - later - if the entire range is selected and they're all
391 * good inodes, keep searching in either direction.
392 * until you the range of inodes end, then split into chunks
393 * for now, just take one chunk's worth starting at the lowest
394 * possible point and hopefully we'll pick the rest up later.
396 * XXX - if we were going to fix up an inode chunk for
397 * any good inodes in the chunk, this is where we would
398 * do it. For now, keep it simple and lose the rest of
402 if (num_blks
% mp
->m_ialloc_blks
!= 0) {
403 num_blks
= rounddown(num_blks
, mp
->m_ialloc_blks
);
404 chunk_stop_agbno
= chunk_start_agbno
+ num_blks
;
408 * ok, we've got a candidate inode chunk. now we have to
409 * verify that we aren't trying to use blocks that are already
410 * in use. If so, mark them as multiply claimed since odds
411 * are very low that we found this chunk by stumbling across
412 * user data -- we're probably here as a result of a directory
413 * entry or an iunlinked pointer
415 pthread_mutex_lock(&ag_locks
[agno
].lock
);
416 for (cur_agbno
= chunk_start_agbno
;
417 cur_agbno
< chunk_stop_agbno
;
419 state
= get_bmap_ext(agno
, cur_agbno
, chunk_stop_agbno
, &blen
);
426 _("inode block %d/%d multiply claimed, (state %d)\n"),
427 agno
, cur_agbno
, state
);
428 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_MULT
);
429 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
433 _("uncertain inode block overlap, agbno = %d, ino = %" PRIu64
"\n"),
440 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
443 * ok, chunk is good. put the record into the tree if required,
444 * and fill in the bitmap. All inodes will be marked as "free"
445 * except for the one that led us to discover the chunk. That's
446 * ok because we'll override the free setting later if the
447 * contents of the inode indicate it's in use.
449 start_agino
= XFS_AGB_TO_AGINO(mp
, chunk_start_agbno
);
450 *start_ino
= XFS_AGINO_TO_INO(mp
, agno
, start_agino
);
452 ASSERT(find_inode_rec(mp
, agno
, start_agino
) == NULL
);
454 irec_p
= set_inode_free_alloc(mp
, agno
, start_agino
);
455 for (i
= 1; i
< XFS_INODES_PER_CHUNK
; i
++)
456 set_inode_free(irec_p
, i
);
458 ASSERT(start_agino
<= agino
&&
459 start_agino
+ XFS_INODES_PER_CHUNK
> agino
);
461 set_inode_used(irec_p
, agino
- start_agino
);
463 pthread_mutex_lock(&ag_locks
[agno
].lock
);
465 for (cur_agbno
= chunk_start_agbno
;
466 cur_agbno
< chunk_stop_agbno
;
468 state
= get_bmap_ext(agno
, cur_agbno
, chunk_stop_agbno
, &blen
);
472 _("uncertain inode block %" PRIu64
" already known\n"),
473 XFS_AGB_TO_FSB(mp
, agno
, cur_agbno
));
478 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_INO
);
485 _("inode block %d/%d multiply claimed, (state %d)\n"),
486 agno
, cur_agbno
, state
);
490 _("inode block %d/%d bad state, (state %d)\n"),
491 agno
, cur_agbno
, state
);
492 set_bmap_ext(agno
, cur_agbno
, blen
, XR_E_INO
);
496 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
502 * same as above only for ag inode chunks
505 verify_aginode_chunk(xfs_mount_t
*mp
,
508 xfs_agino_t
*agino_start
)
513 res
= verify_inode_chunk(mp
, XFS_AGINO_TO_INO(mp
, agno
, agino
), &ino
);
516 *agino_start
= XFS_INO_TO_AGINO(mp
, ino
);
518 *agino_start
= NULLAGINO
;
524 * this does the same as the two above only it returns a pointer
525 * to the inode record in the good inode tree
527 static ino_tree_node_t
*
528 verify_aginode_chunk_irec(xfs_mount_t
*mp
,
532 xfs_agino_t start_agino
;
533 ino_tree_node_t
*irec
= NULL
;
535 if (verify_aginode_chunk(mp
, agno
, agino
, &start_agino
))
536 irec
= find_inode_rec(mp
, agno
, start_agino
);
542 * Set the state of an inode block during inode chunk processing. The block is
543 * expected to be in the free or inode state. If free, it transitions to the
544 * inode state. Warn if the block is in neither expected state as this indicates
545 * multiply claimed blocks.
548 process_inode_agbno_state(
549 struct xfs_mount
*mp
,
555 pthread_mutex_lock(&ag_locks
[agno
].lock
);
556 state
= get_bmap(agno
, agbno
);
558 case XR_E_INO
: /* already marked */
563 set_bmap(agno
, agbno
, XR_E_INO
);
566 do_error(_("bad state in block map %d\n"), state
);
569 set_bmap(agno
, agbno
, XR_E_MULT
);
571 _("inode block %" PRIu64
" multiply claimed, state was %d\n"),
572 XFS_AGB_TO_FSB(mp
, agno
, agbno
), state
);
575 pthread_mutex_unlock(&ag_locks
[agno
].lock
);
579 * processes an inode allocation chunk/block, returns 1 on I/O errors,
582 * *bogus is set to 1 if the entire set of inodes is bad.
589 ino_tree_node_t
*first_irec
,
592 int extra_attr_check
,
596 ino_tree_node_t
*ino_rec
;
610 int blks_per_cluster
;
615 ASSERT(first_irec
!= NULL
);
616 ASSERT(XFS_AGINO_TO_OFFSET(mp
, first_irec
->ino_startnum
) == 0);
619 ASSERT(mp
->m_ialloc_blks
> 0);
621 blks_per_cluster
= mp
->m_inode_cluster_size
>> mp
->m_sb
.sb_blocklog
;
622 if (blks_per_cluster
== 0)
623 blks_per_cluster
= 1;
624 cluster_count
= XFS_INODES_PER_CHUNK
/ inodes_per_cluster
;
625 if (cluster_count
== 0)
629 * get all blocks required to read in this chunk (may wind up
630 * having to process more chunks in a multi-chunk per block fs)
632 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
637 ino_rec
= first_irec
;
640 bplist
= malloc(cluster_count
* sizeof(xfs_buf_t
*));
642 do_error(_("failed to allocate %zd bytes of memory\n"),
643 cluster_count
* sizeof(xfs_buf_t
*));
645 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
647 * Skip the cluster buffer if the first inode is sparse. The
648 * remaining inodes in the cluster share the same state as
649 * sparse inodes occur at cluster granularity.
651 if (is_inode_sparse(ino_rec
, irec_offset
)) {
652 pftrace("skip sparse inode, startnum 0x%x idx %d",
653 ino_rec
->ino_startnum
, irec_offset
);
654 bplist
[bp_index
] = NULL
;
658 pftrace("about to read off %llu in AG %d",
659 XFS_AGB_TO_DADDR(mp
, agno
, agbno
), agno
);
661 bplist
[bp_index
] = libxfs_readbuf(mp
->m_dev
,
662 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
663 XFS_FSB_TO_BB(mp
, blks_per_cluster
), 0,
665 if (!bplist
[bp_index
]) {
666 do_warn(_("cannot read inode %" PRIu64
", disk block %" PRId64
", cnt %d\n"),
667 XFS_AGINO_TO_INO(mp
, agno
, first_irec
->ino_startnum
),
668 XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
669 XFS_FSB_TO_BB(mp
, blks_per_cluster
));
670 while (bp_index
> 0) {
672 libxfs_putbuf(bplist
[bp_index
]);
678 pftrace("readbuf %p (%llu, %d) in AG %d", bplist
[bp_index
],
679 (long long)XFS_BUF_ADDR(bplist
[bp_index
]),
680 bplist
[bp_index
]->b_bcount
, agno
);
682 bplist
[bp_index
]->b_ops
= &xfs_inode_buf_ops
;
685 irec_offset
+= mp
->m_sb
.sb_inopblock
* blks_per_cluster
;
686 agbno
+= blks_per_cluster
;
688 agbno
= XFS_AGINO_TO_AGBNO(mp
, first_irec
->ino_startnum
);
691 * initialize counters
701 * verify inode chunk if necessary
705 agino
= irec_offset
+ ino_rec
->ino_startnum
;
707 /* no buffers for sparse clusters */
708 if (bplist
[bp_index
]) {
709 /* make inode pointer */
710 dino
= xfs_make_iptr(mp
, bplist
[bp_index
],
714 * we always think that the root and realtime
715 * inodes are verified even though we may have
716 * to reset them later to keep from losing the
717 * chunk that they're in
719 if (verify_dinode(mp
, dino
, agno
, agino
) == 0 ||
721 (mp
->m_sb
.sb_rootino
== agino
||
722 mp
->m_sb
.sb_rsumino
== agino
||
723 mp
->m_sb
.sb_rbmino
== agino
)))
731 if (icnt
== mp
->m_ialloc_inos
&&
732 irec_offset
== XFS_INODES_PER_CHUNK
) {
734 * done! - finished up irec and block
738 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
740 * get new irec (multiple chunks per block fs)
742 ino_rec
= next_ino_rec(ino_rec
);
743 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
746 if (cluster_offset
== inodes_per_cluster
) {
753 * if chunk/block is bad, blow it off. the inode records
754 * will be deleted by the caller if appropriate.
758 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++)
759 if (bplist
[bp_index
])
760 libxfs_putbuf(bplist
[bp_index
]);
766 * reset irec and counters
768 ino_rec
= first_irec
;
778 * mark block as an inode block in the incore bitmap
780 if (!is_inode_sparse(ino_rec
, irec_offset
))
781 process_inode_agbno_state(mp
, agno
, agbno
);
784 agino
= irec_offset
+ ino_rec
->ino_startnum
;
785 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
787 if (is_inode_sparse(ino_rec
, irec_offset
))
790 /* make inode pointer */
791 dino
= xfs_make_iptr(mp
, bplist
[bp_index
], cluster_offset
);
798 status
= process_dinode(mp
, dino
, agno
, agino
,
799 is_inode_free(ino_rec
, irec_offset
),
800 &ino_dirty
, &is_used
,ino_discovery
, check_dups
,
801 extra_attr_check
, &isa_dir
, &parent
);
803 ASSERT(is_used
!= 3);
806 libxfs_dinode_calc_crc(mp
, dino
);
810 * XXX - if we want to try and keep
811 * track of whether we need to bang on
812 * the inode maps (instead of just
813 * blindly reconstructing them like
814 * we do now, this is where to start.
817 if (is_inode_free(ino_rec
, irec_offset
)) {
818 if (verbose
|| no_modify
) {
820 _("imap claims in-use inode %" PRIu64
" is free, "),
824 if (verbose
|| !no_modify
)
825 do_warn(_("correcting imap\n"));
827 do_warn(_("would correct imap\n"));
829 set_inode_used(ino_rec
, irec_offset
);
832 * store the on-disk file type for comparing in
835 set_inode_ftype(ino_rec
, irec_offset
,
836 libxfs_mode_to_ftype(be16_to_cpu(dino
->di_mode
)));
839 * store on-disk nlink count for comparing in phase 7
841 set_inode_disk_nlinks(ino_rec
, irec_offset
,
843 ? be32_to_cpu(dino
->di_nlink
)
844 : be16_to_cpu(dino
->di_onlink
));
847 set_inode_free(ino_rec
, irec_offset
);
851 * if we lose the root inode, or it turns into
852 * a non-directory, that allows us to double-check
853 * later whether or not we need to reinitialize it.
856 set_inode_isadir(ino_rec
, irec_offset
);
858 * we always set the parent but
859 * we may as well wait until
860 * phase 4 (no inode discovery)
861 * because the parent info will
864 if (!ino_discovery
) {
866 set_inode_parent(ino_rec
, irec_offset
, parent
);
868 get_inode_parent(ino_rec
, irec_offset
));
871 clear_inode_isadir(ino_rec
, irec_offset
);
875 if (mp
->m_sb
.sb_rootino
== ino
) {
880 _("cleared root inode %" PRIu64
"\n"),
884 _("would clear root inode %" PRIu64
"\n"),
887 } else if (mp
->m_sb
.sb_rbmino
== ino
) {
892 _("cleared realtime bitmap inode %" PRIu64
"\n"),
896 _("would clear realtime bitmap inode %" PRIu64
"\n"),
899 } else if (mp
->m_sb
.sb_rsumino
== ino
) {
904 _("cleared realtime summary inode %" PRIu64
"\n"),
908 _("would clear realtime summary inode %" PRIu64
"\n"),
911 } else if (!no_modify
) {
912 do_warn(_("cleared inode %" PRIu64
"\n"),
915 do_warn(_("would have cleared inode %" PRIu64
"\n"),
918 clear_inode_was_rl(ino_rec
, irec_offset
);
927 if (icnt
== mp
->m_ialloc_inos
&&
928 irec_offset
== XFS_INODES_PER_CHUNK
) {
930 * done! - finished up irec and block simultaneously
932 for (bp_index
= 0; bp_index
< cluster_count
; bp_index
++) {
933 if (!bplist
[bp_index
])
936 pftrace("put/writebuf %p (%llu) in AG %d",
937 bplist
[bp_index
], (long long)
938 XFS_BUF_ADDR(bplist
[bp_index
]), agno
);
940 if (dirty
&& !no_modify
)
941 libxfs_writebuf(bplist
[bp_index
], 0);
943 libxfs_putbuf(bplist
[bp_index
]);
947 } else if (ibuf_offset
== mp
->m_sb
.sb_inopblock
) {
949 * mark block as an inode block in the incore bitmap
950 * and reset inode buffer offset counter
955 if (!is_inode_sparse(ino_rec
, irec_offset
))
956 process_inode_agbno_state(mp
, agno
, agbno
);
957 } else if (irec_offset
== XFS_INODES_PER_CHUNK
) {
959 * get new irec (multiple chunks per block fs)
961 ino_rec
= next_ino_rec(ino_rec
);
962 ASSERT(ino_rec
->ino_startnum
== agino
+ 1);
965 if (cluster_offset
== inodes_per_cluster
) {
974 * check all inodes mentioned in the ag's incore inode maps.
975 * the map may be incomplete. If so, we'll catch the missing
976 * inodes (hopefully) when we traverse the directory tree.
977 * check_dirs is set to 1 if directory inodes should be
978 * processed for internal consistency, parent setting and
979 * discovery of unknown inodes. this only happens
980 * in phase 3. check_dups is set to 1 if we're looking for
981 * inodes that reference duplicate blocks so we can trash
982 * the inode right then and there. this is set only in
983 * phase 4 after we've run through and set the bitmap once.
988 prefetch_args_t
*pf_args
,
992 int extra_attr_check
)
995 ino_tree_node_t
*ino_rec
, *first_ino_rec
, *prev_ino_rec
;
999 first_ino_rec
= ino_rec
= findfirst_inode_rec(agno
);
1001 while (ino_rec
!= NULL
) {
1003 * paranoia - step through inode records until we step
1004 * through a full allocation of inodes. this could
1005 * be an issue in big-block filesystems where a block
1006 * can hold more than one inode chunk. make sure to
1007 * grab the record corresponding to the beginning of
1008 * the next block before we call the processing routines.
1010 num_inos
= XFS_INODES_PER_CHUNK
;
1011 while (num_inos
< mp
->m_ialloc_inos
&& ino_rec
!= NULL
) {
1013 * inodes chunks will always be aligned and sized
1016 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1017 num_inos
+= XFS_INODES_PER_CHUNK
;
1020 ASSERT(num_inos
== mp
->m_ialloc_inos
);
1023 sem_post(&pf_args
->ra_count
);
1025 sem_getvalue(&pf_args
->ra_count
, &count
);
1026 pftrace("processing inode chunk %p in AG %d (sem count = %d)",
1027 first_ino_rec
, agno
, count
);
1031 if (process_inode_chunk(mp
, agno
, num_inos
, first_ino_rec
,
1032 ino_discovery
, check_dups
, extra_attr_check
,
1034 /* XXX - i/o error, we've got a problem */
1039 first_ino_rec
= ino_rec
= next_ino_rec(ino_rec
);
1042 * inodes pointed to by this record are
1043 * completely bogus, blow the records for
1045 * the inode block(s) will get reclaimed
1046 * in phase 4 when the block map is
1047 * reconstructed after inodes claiming
1048 * duplicate blocks are deleted.
1051 ino_rec
= first_ino_rec
;
1052 while (num_inos
< mp
->m_ialloc_inos
&&
1054 prev_ino_rec
= ino_rec
;
1056 if ((ino_rec
= next_ino_rec(ino_rec
)) != NULL
)
1057 num_inos
+= XFS_INODES_PER_CHUNK
;
1059 get_inode_rec(mp
, agno
, prev_ino_rec
);
1060 free_inode_rec(agno
, prev_ino_rec
);
1063 first_ino_rec
= ino_rec
;
1065 PROG_RPT_INC(prog_rpt_done
[agno
], num_inos
);
1070 * verify the uncertain inode list for an ag.
1071 * Good inodes get moved into the good inode tree.
1072 * returns 0 if there are no uncertain inode records to
1073 * be processed, 1 otherwise. This routine destroys the
1074 * the entire uncertain inode tree for the ag as a side-effect.
1077 check_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1079 ino_tree_node_t
*irec
;
1080 ino_tree_node_t
*nrec
;
1089 clear_uncertain_ino_cache(agno
);
1091 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1095 * the trick here is to find a contiguous range
1096 * of inodes, make sure that it doesn't overlap
1097 * with a known to exist chunk, and then make
1098 * sure it is a number of entire chunks.
1099 * we check on-disk once we have an idea of what's
1100 * going on just to double-check.
1102 * process the uncertain inode record list and look
1103 * on disk to see if the referenced inodes are good
1106 do_warn(_("found inodes not in the inode allocation tree\n"));
1110 * check every confirmed (which in this case means
1111 * inode that we really suspect to be an inode) inode
1113 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1114 if (!is_inode_confirmed(irec
, i
))
1117 agino
= i
+ irec
->ino_startnum
;
1119 if (verify_aginum(mp
, agno
, agino
))
1122 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1123 agino
< nrec
->ino_startnum
+
1124 XFS_INODES_PER_CHUNK
)
1127 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) == NULL
)
1128 if (!verify_aginum(mp
, agno
, agino
))
1129 if (verify_aginode_chunk(mp
, agno
,
1134 get_uncertain_inode_rec(mp
, agno
, irec
);
1135 free_inode_rec(agno
, irec
);
1137 irec
= findfirst_uncertain_inode_rec(agno
);
1138 } while (irec
!= NULL
);
1141 do_warn(_("found inodes not in the inode allocation tree\n"));
1147 * verify and process the uncertain inodes for an ag.
1148 * this is different from check_ in that we can't just
1149 * move the good inodes into the good inode tree and let
1150 * process_aginodes() deal with them because this gets called
1151 * after process_aginodes() has been run on the ag inode tree.
1152 * So we have to process the inodes as well as verify since
1153 * we don't want to rerun process_aginodes() on a tree that has
1154 * mostly been processed.
1156 * Note that if this routine does process some inodes, it can
1157 * add uncertain inodes to any ag which would require that
1158 * the routine be called again to process those newly-added
1161 * returns 0 if no inodes were processed and 1 if inodes
1162 * were processed (and it is possible that new uncertain
1163 * inodes were discovered).
1165 * as a side-effect, this routine tears down the uncertain
1166 * inode tree for the ag.
1169 process_uncertain_aginodes(xfs_mount_t
*mp
, xfs_agnumber_t agno
)
1171 ino_tree_node_t
*irec
;
1172 ino_tree_node_t
*nrec
;
1179 #ifdef XR_INODE_TRACE
1180 fprintf(stderr
, "in process_uncertain_aginodes, agno = %d\n", agno
);
1185 clear_uncertain_ino_cache(agno
);
1187 if ((irec
= findfirst_uncertain_inode_rec(agno
)) == NULL
)
1194 * check every confirmed inode
1196 for (cnt
= i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
1197 if (!is_inode_confirmed(irec
, i
))
1200 agino
= i
+ irec
->ino_startnum
;
1201 #ifdef XR_INODE_TRACE
1202 fprintf(stderr
, "ag inode = %d (0x%x)\n", agino
, agino
);
1205 * skip over inodes already processed (in the
1206 * good tree), bad inode numbers, and inode numbers
1207 * pointing to bogus inodes
1209 if (verify_aginum(mp
, agno
, agino
))
1212 if (nrec
!= NULL
&& nrec
->ino_startnum
<= agino
&&
1213 agino
< nrec
->ino_startnum
+
1214 XFS_INODES_PER_CHUNK
)
1217 if ((nrec
= find_inode_rec(mp
, agno
, agino
)) != NULL
)
1221 * verify the chunk. if good, it will be
1222 * added to the good inode tree.
1224 if ((nrec
= verify_aginode_chunk_irec(mp
,
1225 agno
, agino
)) == NULL
)
1231 * process the inode record we just added
1232 * to the good inode tree. The inode
1233 * processing may add more records to the
1234 * uncertain inode lists.
1236 if (process_inode_chunk(mp
, agno
, mp
->m_ialloc_inos
,
1237 nrec
, 1, 0, 0, &bogus
)) {
1238 /* XXX - i/o error, we've got a problem */
1245 * now return the uncertain inode record to the free pool
1246 * and pull another one off the list for processing
1248 get_uncertain_inode_rec(mp
, agno
, irec
);
1249 free_inode_rec(agno
, irec
);
1251 irec
= findfirst_uncertain_inode_rec(agno
);
1252 } while (irec
!= NULL
);
1255 do_warn(_("found inodes not in the inode allocation tree\n"));