During defragment, we missed to trigger fragmented blocks migration
for below condition:
In defragment region:
- total number of valid blocks is smaller than 512;
- the tail part of the region are all holes;
In addtion, return zero to user via range->len if there is no
fragmented blocks.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
                map.m_lblk += map.m_len;
        }
 
-       if (!fragmented)
+       if (!fragmented) {
+               total = 0;
                goto out;
+       }
 
        sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi));
 
 
                if (!(map.m_flags & F2FS_MAP_FLAGS)) {
                        map.m_lblk = next_pgofs;
-                       continue;
+                       goto check;
                }
 
                set_inode_flag(inode, FI_DO_DEFRAG);
                }
 
                map.m_lblk = idx;
-
-               if (idx < pg_end && cnt < blk_per_seg)
+check:
+               if (map.m_lblk < pg_end && cnt < blk_per_seg)
                        goto do_map;
 
                clear_inode_flag(inode, FI_DO_DEFRAG);