Commit 236b9254 authored by Heming Zhao via Ocfs2-devel's avatar Heming Zhao via Ocfs2-devel Committed by Andrew Morton

ocfs2: fix non-auto defrag path not working issue

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 are no tools triggering the above issues since
defragfs.ocfs2 enables auto defrag by default.  Tested with manually
changing defragfs.ocfs2 to run non auto defrag path.

Link: https://lkml.kernel.org/r/20230220050526.22020-1-heming.zhao@suse.comSigned-off-by: default avatarHeming Zhao <heming.zhao@suse.com>
Reviewed-by: default avatarJoseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 60eed1e3
...@@ -434,7 +434,7 @@ static int ocfs2_find_victim_alloc_group(struct inode *inode, ...@@ -434,7 +434,7 @@ static int ocfs2_find_victim_alloc_group(struct inode *inode,
bg = (struct ocfs2_group_desc *)gd_bh->b_data; bg = (struct ocfs2_group_desc *)gd_bh->b_data;
if (vict_blkno < (le64_to_cpu(bg->bg_blkno) + 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; *ret_bh = gd_bh;
*vict_bit = (vict_blkno - blkno) >> *vict_bit = (vict_blkno - blkno) >>
...@@ -549,6 +549,7 @@ static void ocfs2_probe_alloc_group(struct inode *inode, struct buffer_head *bh, ...@@ -549,6 +549,7 @@ static void ocfs2_probe_alloc_group(struct inode *inode, struct buffer_head *bh,
last_free_bits++; last_free_bits++;
if (last_free_bits == move_len) { if (last_free_bits == move_len) {
i -= move_len;
*goal_bit = i; *goal_bit = i;
*phys_cpos = base_cpos + i; *phys_cpos = base_cpos + i;
break; break;
...@@ -1020,8 +1021,6 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) ...@@ -1020,8 +1021,6 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
context->range = &range; context->range = &range;
if (range.me_flags & OCFS2_MOVE_EXT_FL_AUTO_DEFRAG) {
context->auto_defrag = 1;
/* /*
* ok, the default theshold for the defragmentation * ok, the default theshold for the defragmentation
* is 1M, since our maximum clustersize was 1M also. * is 1M, since our maximum clustersize was 1M also.
...@@ -1033,6 +1032,9 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp) ...@@ -1033,6 +1032,9 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
if (range.me_threshold > i_size_read(inode)) if (range.me_threshold > i_size_read(inode))
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;
if (range.me_flags & OCFS2_MOVE_EXT_FL_PART_DEFRAG) if (range.me_flags & OCFS2_MOVE_EXT_FL_PART_DEFRAG)
context->partial = 1; context->partial = 1;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment