Skip to content

Commit 236b925

Browse files
Heming Zhao via Ocfs2-develakpm00
authored andcommitted
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/[email protected] Signed-off-by: Heming Zhao <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Jun Piao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 60eed1e commit 236b925

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

fs/ocfs2/move_extents.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static int ocfs2_find_victim_alloc_group(struct inode *inode,
434434
bg = (struct ocfs2_group_desc *)gd_bh->b_data;
435435

436436
if (vict_blkno < (le64_to_cpu(bg->bg_blkno) +
437-
le16_to_cpu(bg->bg_bits))) {
437+
(le16_to_cpu(bg->bg_bits) << bits_per_unit))) {
438438

439439
*ret_bh = gd_bh;
440440
*vict_bit = (vict_blkno - blkno) >>
@@ -549,6 +549,7 @@ static void ocfs2_probe_alloc_group(struct inode *inode, struct buffer_head *bh,
549549
last_free_bits++;
550550

551551
if (last_free_bits == move_len) {
552+
i -= move_len;
552553
*goal_bit = i;
553554
*phys_cpos = base_cpos + i;
554555
break;
@@ -1020,18 +1021,19 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
10201021

10211022
context->range = &range;
10221023

1024+
/*
1025+
* ok, the default theshold for the defragmentation
1026+
* is 1M, since our maximum clustersize was 1M also.
1027+
* any thought?
1028+
*/
1029+
if (!range.me_threshold)
1030+
range.me_threshold = 1024 * 1024;
1031+
1032+
if (range.me_threshold > i_size_read(inode))
1033+
range.me_threshold = i_size_read(inode);
1034+
10231035
if (range.me_flags & OCFS2_MOVE_EXT_FL_AUTO_DEFRAG) {
10241036
context->auto_defrag = 1;
1025-
/*
1026-
* ok, the default theshold for the defragmentation
1027-
* is 1M, since our maximum clustersize was 1M also.
1028-
* any thought?
1029-
*/
1030-
if (!range.me_threshold)
1031-
range.me_threshold = 1024 * 1024;
1032-
1033-
if (range.me_threshold > i_size_read(inode))
1034-
range.me_threshold = i_size_read(inode);
10351037

10361038
if (range.me_flags & OCFS2_MOVE_EXT_FL_PART_DEFRAG)
10371039
context->partial = 1;

0 commit comments

Comments
 (0)