Skip to contentSkip to conversation

ocfs2: fix non-auto defrag path not working issue

PATCH Superseded Heming Zhao via Ocfs2-devel 1 participant 3 messages Feb 17, 2023 – Feb 20, 2023 OCFS2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: fix non-auto defrag path not working issue

This commit fixes three issues on non-auto defrag path (defragfs.ocfs2 doesn't set OCFS2_MOVE_EXT_FL_AUTO_DEFRAG on range.me_flags):
- For ocfs2_find_victim_alloc_group(), old code forgot enlarge bitmap range for global_bitmap case. Old code could generate negative vict_bit.
- For ocfs2_probe_alloc_group(), old code forgot back off move_len when finding enough bitmap space. Old code has possibility to make data corruption.
- For ocfs2_ioctl_move_extents(), this func should set me_threshold for both auto & non-auto path. Without setting me_threshold, ocfs2_move_extent() will make 'move_max_hop = 0', then ocfs2_probe_alloc_group() returns 'phys_cpos == 0' under max_hop is 0.

Another info is current defragfs.ocfs2 doesn't have ability to trigger non-auto defrag path. I modified defragfs.ocfs2 source code ".me_flags" and hardcode ".me_goal" for running test.

---
 fs/ocfs2/move_extents.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
fs/ocfs2/move_extents.c +13 -11
index 6251748c695b..b1e32ec4a9d4 100644
@@ -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;
Signature · 7 lines
2.39.0


_______________________________________________
Ocfs2-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
#1 lore raw
Quoted 13 lines · Heming Zhao

This commit fixes three issues on non-auto defrag path (defragfs.ocfs2 doesn't set OCFS2_MOVE_EXT_FL_AUTO_DEFRAG on range.me_flags):
- For ocfs2_find_victim_alloc_group(), old code forgot enlarge bitmap range for global_bitmap case. Old code could generate negative vict_bit.
- For ocfs2_probe_alloc_group(), old code forgot back off move_len when finding enough bitmap space. Old code has possibility to make data corruption.
- For ocfs2_ioctl_move_extents(), this func should set me_threshold for both auto & non-auto path. Without setting me_threshold, ocfs2_move_extent() will make 'move_max_hop = 0', then ocfs2_probe_alloc_group() returns 'phys_cpos == 0' under max_hop is 0.

Quoted 4 lines

Another info is current defragfs.ocfs2 doesn't have ability to trigger non-auto defrag path. I modified defragfs.ocfs2 source code ".me_flags" and hardcode ".me_goal" for running test.

I'm fine with the code changes. But the commit log needs improve. How about the following?

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.

Thanks,
Joseph

Quoted 46 lines
---
 fs/ocfs2/move_extents.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
fs/ocfs2/move_extents.c +13 -4
index 6251748c695b..b1e32ec4a9d4 100644
@@ -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.

fs/ocfs2/move_extents.c int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) · line 1039

Quoted 10 lines
fs/ocfs2/move_extents.c +0 -7
-		 * 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
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

#2 lore raw
Quoted 16 lines · Joseph Qi
Quoted 13 lines · Heming Zhao

This commit fixes three issues on non-auto defrag path (defragfs.ocfs2 doesn't set OCFS2_MOVE_EXT_FL_AUTO_DEFRAG on range.me_flags):
- For ocfs2_find_victim_alloc_group(), old code forgot enlarge bitmap range for global_bitmap case. Old code could generate negative vict_bit.
- For ocfs2_probe_alloc_group(), old code forgot back off move_len when finding enough bitmap space. Old code has possibility to make data corruption.
- For ocfs2_ioctl_move_extents(), this func should set me_threshold for both auto & non-auto path. Without setting me_threshold, ocfs2_move_extent() will make 'move_max_hop = 0', then ocfs2_probe_alloc_group() returns 'phys_cpos == 0' under max_hop is 0.

Quoted 7 lines
Quoted 4 lines

Another info is current defragfs.ocfs2 doesn't have ability to trigger non-auto defrag path. I modified defragfs.ocfs2 source code ".me_flags" and hardcode ".me_goal" for running test.

I'm fine with the code changes. But the commit log needs improve. How about the following?

OK, I will send v2 patch.
Thank you for your review and spent time to revise my commit log.

Thanks,
Heming

Quoted 12 lines

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.

Quoted 13 lines

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.

Thanks,
Joseph

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

_______________________________________________
Ocfs2-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel