diff mbox series

[1/2] xfs: don't free rt blocks when we're doing a REMAP bunmapi call

Message ID 160031331319.3624286.3971628628820322437.stgit@magnolia (mailing list archive)
State Superseded
Headers show
Series xfs: random fixes | expand

Commit Message

Darrick J. Wong Sept. 17, 2020, 3:28 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

When callers pass XFS_BMAPI_REMAP into xfs_bunmapi, they want the extent
to be unmapped from the given file fork without the extent being freed.
We do this for non-rt files, but we forgot to do this for realtime
files.  So far this isn't a big deal since nobody makes a bunmapi call
to a rt file with the REMAP flag set, but don't leave a logic bomb.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_bmap.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Dave Chinner Sept. 17, 2020, 4:43 a.m. UTC | #1
On Wed, Sep 16, 2020 at 08:28:33PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> When callers pass XFS_BMAPI_REMAP into xfs_bunmapi, they want the extent
> to be unmapped from the given file fork without the extent being freed.
> We do this for non-rt files, but we forgot to do this for realtime
> files.  So far this isn't a big deal since nobody makes a bunmapi call
> to a rt file with the REMAP flag set, but don't leave a logic bomb.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/libxfs/xfs_bmap.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Reasonable.

Reviewed-by: Dave Chinner <dchinner@redhat.com>
Christoph Hellwig Sept. 17, 2020, 8:11 a.m. UTC | #2
On Wed, Sep 16, 2020 at 08:28:33PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> When callers pass XFS_BMAPI_REMAP into xfs_bunmapi, they want the extent
> to be unmapped from the given file fork without the extent being freed.
> We do this for non-rt files, but we forgot to do this for realtime
> files.  So far this isn't a big deal since nobody makes a bunmapi call
> to a rt file with the REMAP flag set, but don't leave a logic bomb.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/libxfs/xfs_bmap.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> 
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index 1b0a01b06a05..e8cd0012a017 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -5057,9 +5057,12 @@ xfs_bmap_del_extent_real(
>  				  &mod);
>  		ASSERT(mod == 0);
>  
> -		error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
> -		if (error)
> -			goto done;
> +		if (!(bflags & XFS_BMAPI_REMAP)) {
> +			error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
> +			if (error)
> +				goto done;
> +		}
> +
>  		do_fx = 0;
>  		nblks = len * mp->m_sb.sb_rextsize;
>  		qfield = XFS_TRANS_DQ_RTBCOUNT;

We also don't need to calculate bno for this case.
Darrick J. Wong Sept. 17, 2020, 5:42 p.m. UTC | #3
On Thu, Sep 17, 2020 at 09:11:34AM +0100, Christoph Hellwig wrote:
> On Wed, Sep 16, 2020 at 08:28:33PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > When callers pass XFS_BMAPI_REMAP into xfs_bunmapi, they want the extent
> > to be unmapped from the given file fork without the extent being freed.
> > We do this for non-rt files, but we forgot to do this for realtime
> > files.  So far this isn't a big deal since nobody makes a bunmapi call
> > to a rt file with the REMAP flag set, but don't leave a logic bomb.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  fs/xfs/libxfs/xfs_bmap.c |    9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > 
> > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> > index 1b0a01b06a05..e8cd0012a017 100644
> > --- a/fs/xfs/libxfs/xfs_bmap.c
> > +++ b/fs/xfs/libxfs/xfs_bmap.c
> > @@ -5057,9 +5057,12 @@ xfs_bmap_del_extent_real(
> >  				  &mod);
> >  		ASSERT(mod == 0);
> >  
> > -		error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
> > -		if (error)
> > -			goto done;
> > +		if (!(bflags & XFS_BMAPI_REMAP)) {
> > +			error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
> > +			if (error)
> > +				goto done;
> > +		}
> > +
> >  		do_fx = 0;
> >  		nblks = len * mp->m_sb.sb_rextsize;
> >  		qfield = XFS_TRANS_DQ_RTBCOUNT;
> 
> We also don't need to calculate bno for this case.

Fixed.

--D
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 1b0a01b06a05..e8cd0012a017 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -5057,9 +5057,12 @@  xfs_bmap_del_extent_real(
 				  &mod);
 		ASSERT(mod == 0);
 
-		error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
-		if (error)
-			goto done;
+		if (!(bflags & XFS_BMAPI_REMAP)) {
+			error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
+			if (error)
+				goto done;
+		}
+
 		do_fx = 0;
 		nblks = len * mp->m_sb.sb_rextsize;
 		qfield = XFS_TRANS_DQ_RTBCOUNT;