diff mbox series

xfs: fix extent length after xfs_alloc_compute_diff()

Message ID 20241107070300.13535-1-alexjlzheng@tencent.com (mailing list archive)
State New
Headers show
Series xfs: fix extent length after xfs_alloc_compute_diff() | expand

Commit Message

Jinliang Zheng Nov. 7, 2024, 7:03 a.m. UTC
After xfs_alloc_compute_diff(), the length of the candidate extent
may change, so make necessary corrections to args->len.

Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
 fs/xfs/libxfs/xfs_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jinliang Zheng Nov. 7, 2024, 8:46 a.m. UTC | #1
On Thu,  7 Nov 2024 15:03:00 +0800, alexjlzheng@gmail.com wrote:
> After xfs_alloc_compute_diff(), the length of the candidate extent
> may change, so make necessary corrections to args->len.
> 
> Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
> ---
>  fs/xfs/libxfs/xfs_alloc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index 22bdbb3e9980..6a5e6cc7a259 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -1069,6 +1069,10 @@ xfs_alloc_cur_check(
>  	if (bnew == NULLAGBLOCK)
>  		goto out;
>  
> +	args->len = XFS_EXTLEN_MIN(bnoa + lena - bnew, args->maxlen);
> +	if (args->len < acur->len)
> +		goto out;
> +
>  	/*
>  	 * Deactivate a bnobt cursor with worse locality than the current best.
>  	 */
> -- 
> 2.41.1

Sorry, I must have misunderstood the intent of the code when sending this
patch. In fact, args->len should not be changed.

But 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? So I have send a new patch:
https://lore.kernel.org/linux-xfs/20241107084044.182463-1-alexjlzheng@tencent.com/T/#u

Also, am I missing some key code to ensure that the above situation does
not occur?

Jinliang Zheng :)
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 22bdbb3e9980..6a5e6cc7a259 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -1069,6 +1069,10 @@  xfs_alloc_cur_check(
 	if (bnew == NULLAGBLOCK)
 		goto out;
 
+	args->len = XFS_EXTLEN_MIN(bnoa + lena - bnew, args->maxlen);
+	if (args->len < acur->len)
+		goto out;
+
 	/*
 	 * Deactivate a bnobt cursor with worse locality than the current best.
 	 */