ocfs2-devel.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [Ocfs2-devel] [PATCH v2] ocfs2: fix non-auto defrag path not working issue
@ 2023-02-20  5:05 Heming Zhao via Ocfs2-devel
  2023-02-20  6:26 ` Joseph Qi via Ocfs2-devel
  0 siblings, 1 reply; 4+ messages in thread
From: Heming Zhao via Ocfs2-devel @ 2023-02-20  5:05 UTC (permalink / raw)
  To: joseph.qi, ocfs2-devel

This fixes three issues on move extents ioctl without auto defrag:

a) In ocfs2_find_victim_alloc_group(), we have to convert bits to block
first in case of global bitmap.
b) In ocfs2_probe_alloc_group(), when finding enough bits in block group
bitmap, we have to back off move_len to start pos as well, otherwise it
may corrupt filesystem.
c) In ocfs2_ioctl_move_extents(), set me_threshold both for non-auto and
auto defrag paths. Otherwise it will set move_max_hop to 0 and finally
cause unexpectedly ENOSPC error.

Currently there is no tools triggering the above issues since
defragfs.ocfs2 enables auto defrag by default. Test with manually
changing defragfs.ocfs2 to run non auto defrag path.

Signed-off-by: Heming Zhao <heming.zhao@suse.com>
---
v2: revise commit log under review comment

---
 fs/ocfs2/move_extents.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
index 6251748c695b..b1e32ec4a9d4 100644
--- a/fs/ocfs2/move_extents.c
+++ b/fs/ocfs2/move_extents.c
@@ -434,7 +434,7 @@ static int ocfs2_find_victim_alloc_group(struct inode *inode,
 			bg = (struct ocfs2_group_desc *)gd_bh->b_data;
 
 			if (vict_blkno < (le64_to_cpu(bg->bg_blkno) +
-						le16_to_cpu(bg->bg_bits))) {
+						(le16_to_cpu(bg->bg_bits) << bits_per_unit))) {
 
 				*ret_bh = gd_bh;
 				*vict_bit = (vict_blkno - blkno) >>
@@ -549,6 +549,7 @@ static void ocfs2_probe_alloc_group(struct inode *inode, struct buffer_head *bh,
 			last_free_bits++;
 
 		if (last_free_bits == move_len) {
+			i -= move_len;
 			*goal_bit = i;
 			*phys_cpos = base_cpos + i;
 			break;
@@ -1020,18 +1021,19 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
 
 	context->range = &range;
 
+	/*
+	 * ok, the default theshold for the defragmentation
+	 * is 1M, since our maximum clustersize was 1M also.
+	 * any thought?
+	 */
+	if (!range.me_threshold)
+		range.me_threshold = 1024 * 1024;
+
+	if (range.me_threshold > i_size_read(inode))
+		range.me_threshold = i_size_read(inode);
+
 	if (range.me_flags & OCFS2_MOVE_EXT_FL_AUTO_DEFRAG) {
 		context->auto_defrag = 1;
-		/*
-		 * ok, the default theshold for the defragmentation
-		 * is 1M, since our maximum clustersize was 1M also.
-		 * any thought?
-		 */
-		if (!range.me_threshold)
-			range.me_threshold = 1024 * 1024;
-
-		if (range.me_threshold > i_size_read(inode))
-			range.me_threshold = i_size_read(inode);
 
 		if (range.me_flags & OCFS2_MOVE_EXT_FL_PART_DEFRAG)
 			context->partial = 1;
-- 
2.39.0


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v2] ocfs2: fix non-auto defrag path not working issue
  2023-02-20  5:05 [Ocfs2-devel] [PATCH v2] ocfs2: fix non-auto defrag path not working issue Heming Zhao via Ocfs2-devel
@ 2023-02-20  6:26 ` Joseph Qi via Ocfs2-devel
  2023-02-23 21:07   ` Andrew Morton via Ocfs2-devel
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2023-02-20  6:26 UTC (permalink / raw)
  To: Heming Zhao, akpm; +Cc: ocfs2-devel



On 2/20/23 1:05 PM, Heming Zhao wrote:
> This fixes three issues on move extents ioctl without auto defrag:
> 
> a) In ocfs2_find_victim_alloc_group(), we have to convert bits to block
> first in case of global bitmap.
> b) In ocfs2_probe_alloc_group(), when finding enough bits in block group
> bitmap, we have to back off move_len to start pos as well, otherwise it
> may corrupt filesystem.
> c) In ocfs2_ioctl_move_extents(), set me_threshold both for non-auto and
> auto defrag paths. Otherwise it will set move_max_hop to 0 and finally
> cause unexpectedly ENOSPC error.
> 
> Currently there is no tools triggering the above issues since
> defragfs.ocfs2 enables auto defrag by default. Test with manually
> changing defragfs.ocfs2 to run non auto defrag path.
> 
> Signed-off-by: Heming Zhao <heming.zhao@suse.com>

Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
> v2: revise commit log under review comment
> 
> ---
>  fs/ocfs2/move_extents.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
> index 6251748c695b..b1e32ec4a9d4 100644
> --- a/fs/ocfs2/move_extents.c
> +++ b/fs/ocfs2/move_extents.c
> @@ -434,7 +434,7 @@ static int ocfs2_find_victim_alloc_group(struct inode *inode,
>  			bg = (struct ocfs2_group_desc *)gd_bh->b_data;
>  
>  			if (vict_blkno < (le64_to_cpu(bg->bg_blkno) +
> -						le16_to_cpu(bg->bg_bits))) {
> +						(le16_to_cpu(bg->bg_bits) << bits_per_unit))) {
>  
>  				*ret_bh = gd_bh;
>  				*vict_bit = (vict_blkno - blkno) >>
> @@ -549,6 +549,7 @@ static void ocfs2_probe_alloc_group(struct inode *inode, struct buffer_head *bh,
>  			last_free_bits++;
>  
>  		if (last_free_bits == move_len) {
> +			i -= move_len;
>  			*goal_bit = i;
>  			*phys_cpos = base_cpos + i;
>  			break;
> @@ -1020,18 +1021,19 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
>  
>  	context->range = &range;
>  
> +	/*
> +	 * ok, the default theshold for the defragmentation
> +	 * is 1M, since our maximum clustersize was 1M also.
> +	 * any thought?
> +	 */
> +	if (!range.me_threshold)
> +		range.me_threshold = 1024 * 1024;
> +
> +	if (range.me_threshold > i_size_read(inode))
> +		range.me_threshold = i_size_read(inode);
> +
>  	if (range.me_flags & OCFS2_MOVE_EXT_FL_AUTO_DEFRAG) {
>  		context->auto_defrag = 1;
> -		/*
> -		 * ok, the default theshold for the defragmentation
> -		 * is 1M, since our maximum clustersize was 1M also.
> -		 * any thought?
> -		 */
> -		if (!range.me_threshold)
> -			range.me_threshold = 1024 * 1024;
> -
> -		if (range.me_threshold > i_size_read(inode))
> -			range.me_threshold = i_size_read(inode);
>  
>  		if (range.me_flags & OCFS2_MOVE_EXT_FL_PART_DEFRAG)
>  			context->partial = 1;

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v2] ocfs2: fix non-auto defrag path not working issue
  2023-02-20  6:26 ` Joseph Qi via Ocfs2-devel
@ 2023-02-23 21:07   ` Andrew Morton via Ocfs2-devel
  2023-02-24  2:09     ` Joseph Qi via Ocfs2-devel
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton via Ocfs2-devel @ 2023-02-23 21:07 UTC (permalink / raw)
  To: Joseph Qi; +Cc: ocfs2-devel

On Mon, 20 Feb 2023 14:26:19 +0800 Joseph Qi <joseph.qi@linux.alibaba.com> wrote:

> > Currently there is no tools triggering the above issues since
> > defragfs.ocfs2 enables auto defrag by default. Test with manually
> > changing defragfs.ocfs2 to run non auto defrag path.
> > 
> > Signed-off-by: Heming Zhao <heming.zhao@suse.com>
> 
> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>

Thanks.  I added a cc:stable tag to both these patches so the
fixes get backported into earlier kernels.

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [PATCH v2] ocfs2: fix non-auto defrag path not working issue
  2023-02-23 21:07   ` Andrew Morton via Ocfs2-devel
@ 2023-02-24  2:09     ` Joseph Qi via Ocfs2-devel
  0 siblings, 0 replies; 4+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2023-02-24  2:09 UTC (permalink / raw)
  To: Andrew Morton; +Cc: ocfs2-devel



On 2/24/23 5:07 AM, Andrew Morton wrote:
> On Mon, 20 Feb 2023 14:26:19 +0800 Joseph Qi <joseph.qi@linux.alibaba.com> wrote:
> 
>>> Currently there is no tools triggering the above issues since
>>> defragfs.ocfs2 enables auto defrag by default. Test with manually
>>> changing defragfs.ocfs2 to run non auto defrag path.
>>>
>>> Signed-off-by: Heming Zhao <heming.zhao@suse.com>
>>
>> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> 
> Thanks.  I added a cc:stable tag to both these patches so the
> fixes get backported into earlier kernels.

Thanks for your meticulousness.

Joseph

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

end of thread, other threads:[~2023-02-24  2:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20  5:05 [Ocfs2-devel] [PATCH v2] ocfs2: fix non-auto defrag path not working issue Heming Zhao via Ocfs2-devel
2023-02-20  6:26 ` Joseph Qi via Ocfs2-devel
2023-02-23 21:07   ` Andrew Morton via Ocfs2-devel
2023-02-24  2:09     ` Joseph Qi via Ocfs2-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).