aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-02-16 05:52:17 -0500
committerChris Mason <clm@fb.com>2015-04-13 10:27:18 -0400
commitf2ab76188ec185dde84e7fe7c533ef2f5d668a32 (patch)
tree220b4e911a81b77792f565b2d6ada98cf7950cbf /fs/btrfs/volumes.c
parent94b947b2f3f84f3bba25d34c4e2a229fc2276830 (diff)
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: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a73acf496e10..8bcd2a007517 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1134,11 +1134,11 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
1134 path = btrfs_alloc_path(); 1134 path = btrfs_alloc_path();
1135 if (!path) 1135 if (!path)
1136 return -ENOMEM; 1136 return -ENOMEM;
1137again: 1137
1138 max_hole_start = search_start; 1138 max_hole_start = search_start;
1139 max_hole_size = 0; 1139 max_hole_size = 0;
1140 hole_size = 0;
1141 1140
1141again:
1142 if (search_start >= search_end || device->is_tgtdev_for_dev_replace) { 1142 if (search_start >= search_end || device->is_tgtdev_for_dev_replace) {
1143 ret = -ENOSPC; 1143 ret = -ENOSPC;
1144 goto out; 1144 goto out;
@@ -1231,21 +1231,23 @@ next:
1231 * allocated dev extents, and when shrinking the device, 1231 * allocated dev extents, and when shrinking the device,
1232 * search_end may be smaller than search_start. 1232 * search_end may be smaller than search_start.
1233 */ 1233 */
1234 if (search_end > search_start) 1234 if (search_end > search_start) {
1235 hole_size = search_end - search_start; 1235 hole_size = search_end - search_start;
1236 1236
1237 if (hole_size > max_hole_size) { 1237 if (contains_pending_extent(trans, device, &search_start,
1238 max_hole_start = search_start; 1238 hole_size)) {
1239 max_hole_size = hole_size; 1239 btrfs_release_path(path);
1240 } 1240 goto again;
1241 }
1241 1242
1242 if (contains_pending_extent(trans, device, &search_start, hole_size)) { 1243 if (hole_size > max_hole_size) {
1243 btrfs_release_path(path); 1244 max_hole_start = search_start;
1244 goto again; 1245 max_hole_size = hole_size;
1246 }
1245 } 1247 }
1246 1248
1247 /* See above. */ 1249 /* See above. */
1248 if (hole_size < num_bytes) 1250 if (max_hole_size < num_bytes)
1249 ret = -ENOSPC; 1251 ret = -ENOSPC;
1250 else 1252 else
1251 ret = 0; 1253 ret = 0;