mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] xfs: check the remaining length of extent after roundup
@ 2024-11-07  8:40 Jinliang Zheng
  2024-11-07 20:05 ` Darrick J. Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Jinliang Zheng @ 2024-11-07  8:40 UTC (permalink / raw)
  To: dchinner
  Cc: cem, djwong, chandanbabu, linux-xfs, linux-kernel, Jinliang Zheng

In xfs_alloc_compute_diff(), ensure that the remaining length of extent
still meets the wantlen requirements after newbno1 is rounded.

Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
Changelog:

V2: Fix the error logic

V1: https://lore.kernel.org/linux-xfs/20241107070300.13535-1-alexjlzheng@tencent.com/#R
---
 fs/xfs/libxfs/xfs_alloc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 22bdbb3e9980..1d4cc75b7318 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -393,7 +393,8 @@ xfs_alloc_compute_diff(
 	 * grows in the short term.
 	 */
 	if (freebno >= wantbno || (userdata && freeend < wantend)) {
-		if ((newbno1 = roundup(freebno, alignment)) >= freeend)
+		newbno1 = roundup(freebno, alignment);
+		if (newbno1 >= freeend || newbno1 > freeend - wantlen)
 			newbno1 = NULLAGBLOCK;
 	} else if (freeend >= wantend && alignment > 1) {
 		newbno1 = roundup(wantbno, alignment);
@@ -414,6 +415,8 @@ xfs_alloc_compute_diff(
 				newbno1 = newbno2;
 		} else if (newbno2 != NULLAGBLOCK)
 			newbno1 = newbno2;
+		if (newbno1 > freeend - wantlen)
+			newbno1 = NULLAGBLOCK;
 	} else if (freeend >= wantend) {
 		newbno1 = wantbno;
 	} else if (alignment > 1) {
-- 
2.41.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] xfs: check the remaining length of extent after roundup
  2024-11-07  8:40 [PATCH v2] xfs: check the remaining length of extent after roundup Jinliang Zheng
@ 2024-11-07 20:05 ` Darrick J. Wong
  2024-11-08  9:32   ` Jinliang Zheng
  0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2024-11-07 20:05 UTC (permalink / raw)
  To: Jinliang Zheng
  Cc: dchinner, cem, chandanbabu, linux-xfs, linux-kernel, Jinliang Zheng

On Thu, Nov 07, 2024 at 04:40:44PM +0800, Jinliang Zheng wrote:
> In xfs_alloc_compute_diff(), ensure that the remaining length of extent
> still meets the wantlen requirements after newbno1 is rounded.

What problem are you observing?

--D

> Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
> ---
> Changelog:
> 
> V2: Fix the error logic
> 
> V1: https://lore.kernel.org/linux-xfs/20241107070300.13535-1-alexjlzheng@tencent.com/#R
> ---
>  fs/xfs/libxfs/xfs_alloc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index 22bdbb3e9980..1d4cc75b7318 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -393,7 +393,8 @@ xfs_alloc_compute_diff(
>  	 * grows in the short term.
>  	 */
>  	if (freebno >= wantbno || (userdata && freeend < wantend)) {
> -		if ((newbno1 = roundup(freebno, alignment)) >= freeend)
> +		newbno1 = roundup(freebno, alignment);
> +		if (newbno1 >= freeend || newbno1 > freeend - wantlen)
>  			newbno1 = NULLAGBLOCK;
>  	} else if (freeend >= wantend && alignment > 1) {
>  		newbno1 = roundup(wantbno, alignment);
> @@ -414,6 +415,8 @@ xfs_alloc_compute_diff(
>  				newbno1 = newbno2;
>  		} else if (newbno2 != NULLAGBLOCK)
>  			newbno1 = newbno2;
> +		if (newbno1 > freeend - wantlen)
> +			newbno1 = NULLAGBLOCK;
>  	} else if (freeend >= wantend) {
>  		newbno1 = wantbno;
>  	} else if (alignment > 1) {
> -- 
> 2.41.1
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] xfs: check the remaining length of extent after roundup
  2024-11-07 20:05 ` Darrick J. Wong
@ 2024-11-08  9:32   ` Jinliang Zheng
  0 siblings, 0 replies; 3+ messages in thread
From: Jinliang Zheng @ 2024-11-08  9:32 UTC (permalink / raw)
  To: djwong
  Cc: alexjlzheng, alexjlzheng, cem, chandanbabu, dchinner,
	linux-kernel, linux-xfs

On Thu, 7 Nov 2024 12:05:39 -0800, Darrick J. Wong wrote:
> On Thu, Nov 07, 2024 at 04:40:44PM +0800, Jinliang Zheng wrote:
> > In xfs_alloc_compute_diff(), ensure that the remaining length of extent
> > still meets the wantlen requirements after newbno1 is rounded.
> 
> What problem are you observing?
> 
> --D

Thank you for your reply. :)

In fact, I haven't encountered any issues with this in production.

My starting point is I was wondering what will happen if
xfs_alloc_compute_diff()'s changes to bnew cause the extent's remaining
length to be less than args->len?

I wonder if this will happen? Am I missing some code to ensure this doesn't
happen?

If it will happen, I think we'd better check it out here; if it doesn't,
please ignore this patch.

Thank you again.
Jinliang Zheng :)

> 
> > Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
> > ---
> > Changelog:
> > 
> > V2: Fix the error logic
> > 
> > V1: https://lore.kernel.org/linux-xfs/20241107070300.13535-1-alexjlzheng@tencent.com/#R
> > ---
> >  fs/xfs/libxfs/xfs_alloc.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> > index 22bdbb3e9980..1d4cc75b7318 100644
> > --- a/fs/xfs/libxfs/xfs_alloc.c
> > +++ b/fs/xfs/libxfs/xfs_alloc.c
> > @@ -393,7 +393,8 @@ xfs_alloc_compute_diff(
> >  	 * grows in the short term.
> >  	 */
> >  	if (freebno >= wantbno || (userdata && freeend < wantend)) {
> > -		if ((newbno1 = roundup(freebno, alignment)) >= freeend)
> > +		newbno1 = roundup(freebno, alignment);
> > +		if (newbno1 >= freeend || newbno1 > freeend - wantlen)
> >  			newbno1 = NULLAGBLOCK;
> >  	} else if (freeend >= wantend && alignment > 1) {
> >  		newbno1 = roundup(wantbno, alignment);
> > @@ -414,6 +415,8 @@ xfs_alloc_compute_diff(
> >  				newbno1 = newbno2;
> >  		} else if (newbno2 != NULLAGBLOCK)
> >  			newbno1 = newbno2;
> > +		if (newbno1 > freeend - wantlen)
> > +			newbno1 = NULLAGBLOCK;
> >  	} else if (freeend >= wantend) {
> >  		newbno1 = wantbno;
> >  	} else if (alignment > 1) {
> > -- 
> > 2.41.1
> > 
> > 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-08  9:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-07  8:40 [PATCH v2] xfs: check the remaining length of extent after roundup Jinliang Zheng
2024-11-07 20:05 ` Darrick J. Wong
2024-11-08  9:32   ` Jinliang Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®