* [PATCH] xfs_db: teach the frag command about sparse inode chunks
@ 2018-12-03 23:01 Eric Sandeen
2018-12-04 13:32 ` Brian Foster
0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2018-12-03 23:01 UTC (permalink / raw)
To: linux-xfs; +Cc: Matthias Bodenbinder
This is the equivalent of:
ea8a48f xfs_check: process sparse inode chunks correctly
for the frag_f() command in xfs_db.
Without this, the xfs_db frag command shows corruption as it
wanders into blocks that are not inodes.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201823
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/db/frag.c b/db/frag.c
index 6792d47..5f33cb7 100644
--- a/db/frag.c
+++ b/db/frag.c
@@ -466,29 +466,56 @@ scanfunc_ino(
int off;
xfs_inobt_ptr_t *pp;
xfs_inobt_rec_t *rp;
+ xfs_agblock_t agbno;
+ xfs_agblock_t end_agbno;
+ struct xfs_dinode *dip;
+ int blks_per_buf;
+ int inodes_per_buf;
+ int ioff;
+
+ if (xfs_sb_version_hassparseinodes(&mp->m_sb))
+ blks_per_buf = xfs_icluster_size_fsb(mp);
+ else
+ blks_per_buf = mp->m_ialloc_blks;
+ inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog,
+ XFS_INODES_PER_CHUNK);
if (level == 0) {
rp = XFS_INOBT_REC_ADDR(mp, block, 1);
for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++) {
agino = be32_to_cpu(rp[i].ir_startino);
- off = XFS_INO_TO_OFFSET(mp, agino);
+ agbno = XFS_AGINO_TO_AGBNO(mp, agino);
+ off = XFS_AGINO_TO_OFFSET(mp, agino);
+ end_agbno = agbno + mp->m_ialloc_blks;
+
push_cur();
- set_cur(&typtab[TYP_INODE],
- XFS_AGB_TO_DADDR(mp, seqno,
- XFS_AGINO_TO_AGBNO(mp, agino)),
- XFS_FSB_TO_BB(mp, mp->m_ialloc_blks),
- DB_RING_IGN, NULL);
- if (iocur_top->data == NULL) {
- dbprintf(_("can't read inode block %u/%u\n"),
- seqno, XFS_AGINO_TO_AGBNO(mp, agino));
- continue;
- }
- for (j = 0; j < XFS_INODES_PER_CHUNK; j++) {
- if (XFS_INOBT_IS_FREE_DISK(&rp[i], j))
- continue;
- process_inode(agf, agino + j, (xfs_dinode_t *)
- ((char *)iocur_top->data +
- ((off + j) << mp->m_sb.sb_inodelog)));
+ ioff = 0;
+ while (agbno < end_agbno &&
+ ioff < XFS_INODES_PER_CHUNK) {
+ if (xfs_inobt_is_sparse_disk(&rp[i], ioff))
+ goto next_buf;
+
+ set_cur(&typtab[TYP_INODE],
+ XFS_AGB_TO_DADDR(mp, seqno, agbno),
+ XFS_FSB_TO_BB(mp, blks_per_buf),
+ DB_RING_IGN, NULL);
+ if (iocur_top->data == NULL) {
+ dbprintf(_("can't read inode block %u/%u\n"),
+ seqno, agbno);
+ goto next_buf;
+ }
+
+ for (j = 0; j < inodes_per_buf; j++) {
+ if (XFS_INOBT_IS_FREE_DISK(&rp[i], ioff + j))
+ goto next_buf;
+ dip = (xfs_dinode_t *)((char *)iocur_top->data +
+ ((off + j) << mp->m_sb.sb_inodelog));
+ process_inode(agf, agino + ioff + j, dip);
+ }
+
+next_buf:
+ agbno += blks_per_buf;
+ ioff += inodes_per_buf;
}
pop_cur();
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xfs_db: teach the frag command about sparse inode chunks
2018-12-03 23:01 [PATCH] xfs_db: teach the frag command about sparse inode chunks Eric Sandeen
@ 2018-12-04 13:32 ` Brian Foster
0 siblings, 0 replies; 2+ messages in thread
From: Brian Foster @ 2018-12-04 13:32 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-xfs, Matthias Bodenbinder
On Mon, Dec 03, 2018 at 05:01:33PM -0600, Eric Sandeen wrote:
> This is the equivalent of:
>
> ea8a48f xfs_check: process sparse inode chunks correctly
>
> for the frag_f() command in xfs_db.
>
> Without this, the xfs_db frag command shows corruption as it
> wanders into blocks that are not inodes.
>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201823
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
Looks good to me, thanks.
Reviewed-by: Brian Foster <bfoster@redhat.com>
>
> diff --git a/db/frag.c b/db/frag.c
> index 6792d47..5f33cb7 100644
> --- a/db/frag.c
> +++ b/db/frag.c
> @@ -466,29 +466,56 @@ scanfunc_ino(
> int off;
> xfs_inobt_ptr_t *pp;
> xfs_inobt_rec_t *rp;
> + xfs_agblock_t agbno;
> + xfs_agblock_t end_agbno;
> + struct xfs_dinode *dip;
> + int blks_per_buf;
> + int inodes_per_buf;
> + int ioff;
> +
> + if (xfs_sb_version_hassparseinodes(&mp->m_sb))
> + blks_per_buf = xfs_icluster_size_fsb(mp);
> + else
> + blks_per_buf = mp->m_ialloc_blks;
> + inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog,
> + XFS_INODES_PER_CHUNK);
>
> if (level == 0) {
> rp = XFS_INOBT_REC_ADDR(mp, block, 1);
> for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++) {
> agino = be32_to_cpu(rp[i].ir_startino);
> - off = XFS_INO_TO_OFFSET(mp, agino);
> + agbno = XFS_AGINO_TO_AGBNO(mp, agino);
> + off = XFS_AGINO_TO_OFFSET(mp, agino);
> + end_agbno = agbno + mp->m_ialloc_blks;
> +
> push_cur();
> - set_cur(&typtab[TYP_INODE],
> - XFS_AGB_TO_DADDR(mp, seqno,
> - XFS_AGINO_TO_AGBNO(mp, agino)),
> - XFS_FSB_TO_BB(mp, mp->m_ialloc_blks),
> - DB_RING_IGN, NULL);
> - if (iocur_top->data == NULL) {
> - dbprintf(_("can't read inode block %u/%u\n"),
> - seqno, XFS_AGINO_TO_AGBNO(mp, agino));
> - continue;
> - }
> - for (j = 0; j < XFS_INODES_PER_CHUNK; j++) {
> - if (XFS_INOBT_IS_FREE_DISK(&rp[i], j))
> - continue;
> - process_inode(agf, agino + j, (xfs_dinode_t *)
> - ((char *)iocur_top->data +
> - ((off + j) << mp->m_sb.sb_inodelog)));
> + ioff = 0;
> + while (agbno < end_agbno &&
> + ioff < XFS_INODES_PER_CHUNK) {
> + if (xfs_inobt_is_sparse_disk(&rp[i], ioff))
> + goto next_buf;
> +
> + set_cur(&typtab[TYP_INODE],
> + XFS_AGB_TO_DADDR(mp, seqno, agbno),
> + XFS_FSB_TO_BB(mp, blks_per_buf),
> + DB_RING_IGN, NULL);
> + if (iocur_top->data == NULL) {
> + dbprintf(_("can't read inode block %u/%u\n"),
> + seqno, agbno);
> + goto next_buf;
> + }
> +
> + for (j = 0; j < inodes_per_buf; j++) {
> + if (XFS_INOBT_IS_FREE_DISK(&rp[i], ioff + j))
> + goto next_buf;
> + dip = (xfs_dinode_t *)((char *)iocur_top->data +
> + ((off + j) << mp->m_sb.sb_inodelog));
> + process_inode(agf, agino + ioff + j, dip);
> + }
> +
> +next_buf:
> + agbno += blks_per_buf;
> + ioff += inodes_per_buf;
> }
> pop_cur();
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-12-04 13:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-03 23:01 [PATCH] xfs_db: teach the frag command about sparse inode chunks Eric Sandeen
2018-12-04 13:32 ` Brian Foster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox