diff mbox series

[3/4] xfs_repair: refactor attr root block pointer check

Message ID 158086358798.2079557.6562544272527988911.stgit@magnolia (mailing list archive)
State Accepted, archived
Headers show
Series xfsprogs: random fixes | expand

Commit Message

Darrick J. Wong Feb. 5, 2020, 12:46 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

In process_longform_attr, replace the agcount check with a call to the
fsblock verification function in libxfs.  Now we can also catch blocks
that point to static FS metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 repair/attr_repair.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Allison Henderson Feb. 5, 2020, 5:28 a.m. UTC | #1
On 2/4/20 5:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In process_longform_attr, replace the agcount check with a call to the
> fsblock verification function in libxfs.  Now we can also catch blocks
> that point to static FS metadata.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Ok, looks good
Reviewed-by: Allison Collins <allison.henderson@oracle.com>

> ---
>   repair/attr_repair.c |   10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> 
> diff --git a/repair/attr_repair.c b/repair/attr_repair.c
> index 9a44f610..7b26df33 100644
> --- a/repair/attr_repair.c
> +++ b/repair/attr_repair.c
> @@ -980,21 +980,21 @@ process_longform_attr(
>   	*repair = 0;
>   
>   	bno = blkmap_get(blkmap, 0);
> -
> -	if ( bno == NULLFSBLOCK ) {
> +	if (bno == NULLFSBLOCK) {
>   		if (dip->di_aformat == XFS_DINODE_FMT_EXTENTS &&
>   				be16_to_cpu(dip->di_anextents) == 0)
>   			return(0); /* the kernel can handle this state */
>   		do_warn(
>   	_("block 0 of inode %" PRIu64 " attribute fork is missing\n"),
>   			ino);
> -		return(1);
> +		return 1;
>   	}
> +
>   	/* FIX FOR bug 653709 -- EKN */
> -	if (mp->m_sb.sb_agcount < XFS_FSB_TO_AGNO(mp, bno)) {
> +	if (!xfs_verify_fsbno(mp, bno)) {
>   		do_warn(
>   	_("agno of attribute fork of inode %" PRIu64 " out of regular partition\n"), ino);
> -		return(1);
> +		return 1;
>   	}
>   
>   	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
>
Eric Sandeen Feb. 13, 2020, 11:14 p.m. UTC | #2
On 2/4/20 6:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In process_longform_attr, replace the agcount check with a call to the
> fsblock verification function in libxfs.  Now we can also catch blocks
> that point to static FS metadata.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  repair/attr_repair.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> 
> diff --git a/repair/attr_repair.c b/repair/attr_repair.c
> index 9a44f610..7b26df33 100644
> --- a/repair/attr_repair.c
> +++ b/repair/attr_repair.c
> @@ -980,21 +980,21 @@ process_longform_attr(
>  	*repair = 0;
>  
>  	bno = blkmap_get(blkmap, 0);
> -
> -	if ( bno == NULLFSBLOCK ) {
> +	if (bno == NULLFSBLOCK) {
>  		if (dip->di_aformat == XFS_DINODE_FMT_EXTENTS &&
>  				be16_to_cpu(dip->di_anextents) == 0)
>  			return(0); /* the kernel can handle this state */
>  		do_warn(
>  	_("block 0 of inode %" PRIu64 " attribute fork is missing\n"),
>  			ino);
> -		return(1);
> +		return 1;
>  	}
> +
>  	/* FIX FOR bug 653709 -- EKN */
> -	if (mp->m_sb.sb_agcount < XFS_FSB_TO_AGNO(mp, bno)) {
> +	if (!xfs_verify_fsbno(mp, bno)) {
>  		do_warn(
>  	_("agno of attribute fork of inode %" PRIu64 " out of regular partition\n"), ino);

I'll change this to

"block in attribute fork of inode %" PRIu64 " is not valid"

ok?

> -		return(1);
> +		return 1;
>  	}
>  
>  	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
>
Darrick J. Wong Feb. 14, 2020, 4:24 a.m. UTC | #3
On Thu, Feb 13, 2020 at 05:14:57PM -0600, Eric Sandeen wrote:
> On 2/4/20 6:46 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > In process_longform_attr, replace the agcount check with a call to the
> > fsblock verification function in libxfs.  Now we can also catch blocks
> > that point to static FS metadata.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  repair/attr_repair.c |   10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > 
> > diff --git a/repair/attr_repair.c b/repair/attr_repair.c
> > index 9a44f610..7b26df33 100644
> > --- a/repair/attr_repair.c
> > +++ b/repair/attr_repair.c
> > @@ -980,21 +980,21 @@ process_longform_attr(
> >  	*repair = 0;
> >  
> >  	bno = blkmap_get(blkmap, 0);
> > -
> > -	if ( bno == NULLFSBLOCK ) {
> > +	if (bno == NULLFSBLOCK) {
> >  		if (dip->di_aformat == XFS_DINODE_FMT_EXTENTS &&
> >  				be16_to_cpu(dip->di_anextents) == 0)
> >  			return(0); /* the kernel can handle this state */
> >  		do_warn(
> >  	_("block 0 of inode %" PRIu64 " attribute fork is missing\n"),
> >  			ino);
> > -		return(1);
> > +		return 1;
> >  	}
> > +
> >  	/* FIX FOR bug 653709 -- EKN */
> > -	if (mp->m_sb.sb_agcount < XFS_FSB_TO_AGNO(mp, bno)) {
> > +	if (!xfs_verify_fsbno(mp, bno)) {
> >  		do_warn(
> >  	_("agno of attribute fork of inode %" PRIu64 " out of regular partition\n"), ino);
> 
> I'll change this to
> 
> "block in attribute fork of inode %" PRIu64 " is not valid"

Sounds good!

--D

> ok?
> 
> > -		return(1);
> > +		return 1;
> >  	}
> >  
> >  	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
> >
Christoph Hellwig Feb. 17, 2020, 1:47 p.m. UTC | #4
On Tue, Feb 04, 2020 at 04:46:28PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In process_longform_attr, replace the agcount check with a call to the
> fsblock verification function in libxfs.  Now we can also catch blocks
> that point to static FS metadata.

Looks good (especially with the fixup from Eric):

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index 9a44f610..7b26df33 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -980,21 +980,21 @@  process_longform_attr(
 	*repair = 0;
 
 	bno = blkmap_get(blkmap, 0);
-
-	if ( bno == NULLFSBLOCK ) {
+	if (bno == NULLFSBLOCK) {
 		if (dip->di_aformat == XFS_DINODE_FMT_EXTENTS &&
 				be16_to_cpu(dip->di_anextents) == 0)
 			return(0); /* the kernel can handle this state */
 		do_warn(
 	_("block 0 of inode %" PRIu64 " attribute fork is missing\n"),
 			ino);
-		return(1);
+		return 1;
 	}
+
 	/* FIX FOR bug 653709 -- EKN */
-	if (mp->m_sb.sb_agcount < XFS_FSB_TO_AGNO(mp, bno)) {
+	if (!xfs_verify_fsbno(mp, bno)) {
 		do_warn(
 	_("agno of attribute fork of inode %" PRIu64 " out of regular partition\n"), ino);
-		return(1);
+		return 1;
 	}
 
 	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),