Commit f2ab7618 authored by Zhao Lei's avatar Zhao Lei Committed by Chris Mason

btrfs: Fix tail space processing in find_free_dev_extent()

It is another reason for NO_SPACE case.

When we found enough free space in loop and saved them to
max_hole_start/size before, and tail space contains pending extent,
origional innocent max_hole_start/size are reset in retry.

As a result, find_free_dev_extent() returns less space than it can,
and cause NO_SPACE in user program.
Reviewed-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarZhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 94b947b2
...@@ -1134,11 +1134,11 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans, ...@@ -1134,11 +1134,11 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
again:
max_hole_start = search_start; max_hole_start = search_start;
max_hole_size = 0; max_hole_size = 0;
hole_size = 0;
again:
if (search_start >= search_end || device->is_tgtdev_for_dev_replace) { if (search_start >= search_end || device->is_tgtdev_for_dev_replace) {
ret = -ENOSPC; ret = -ENOSPC;
goto out; goto out;
...@@ -1231,21 +1231,23 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans, ...@@ -1231,21 +1231,23 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
* allocated dev extents, and when shrinking the device, * allocated dev extents, and when shrinking the device,
* search_end may be smaller than search_start. * search_end may be smaller than search_start.
*/ */
if (search_end > search_start) if (search_end > search_start) {
hole_size = search_end - search_start; hole_size = search_end - search_start;
if (hole_size > max_hole_size) { if (contains_pending_extent(trans, device, &search_start,
max_hole_start = search_start; hole_size)) {
max_hole_size = hole_size; btrfs_release_path(path);
} goto again;
}
if (contains_pending_extent(trans, device, &search_start, hole_size)) { if (hole_size > max_hole_size) {
btrfs_release_path(path); max_hole_start = search_start;
goto again; max_hole_size = hole_size;
}
} }
/* See above. */ /* See above. */
if (hole_size < num_bytes) if (max_hole_size < num_bytes)
ret = -ENOSPC; ret = -ENOSPC;
else else
ret = 0; ret = 0;
......
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