|
@@ -863,6 +863,7 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
|
|
|
|
|
|
max_hole_start = search_start;
|
|
max_hole_start = search_start;
|
|
max_hole_size = 0;
|
|
max_hole_size = 0;
|
|
|
|
+ hole_size = 0;
|
|
|
|
|
|
if (search_start >= search_end) {
|
|
if (search_start >= search_end) {
|
|
ret = -ENOSPC;
|
|
ret = -ENOSPC;
|
|
@@ -945,7 +946,14 @@ next:
|
|
cond_resched();
|
|
cond_resched();
|
|
}
|
|
}
|
|
|
|
|
|
- hole_size = search_end- search_start;
|
|
|
|
|
|
+ /*
|
|
|
|
+ * At this point, search_start should be the end of
|
|
|
|
+ * allocated dev extents, and when shrinking the device,
|
|
|
|
+ * search_end may be smaller than search_start.
|
|
|
|
+ */
|
|
|
|
+ if (search_end > search_start)
|
|
|
|
+ hole_size = search_end - search_start;
|
|
|
|
+
|
|
if (hole_size > max_hole_size) {
|
|
if (hole_size > max_hole_size) {
|
|
max_hole_start = search_start;
|
|
max_hole_start = search_start;
|
|
max_hole_size = hole_size;
|
|
max_hole_size = hole_size;
|
|
@@ -2447,9 +2455,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
|
|
total_avail = device->total_bytes - device->bytes_used;
|
|
total_avail = device->total_bytes - device->bytes_used;
|
|
else
|
|
else
|
|
total_avail = 0;
|
|
total_avail = 0;
|
|
- /* avail is off by max(alloc_start, 1MB), but that is the same
|
|
|
|
- * for all devices, so it doesn't hurt the sorting later on
|
|
|
|
- */
|
|
|
|
|
|
+
|
|
|
|
+ /* If there is no space on this device, skip it. */
|
|
|
|
+ if (total_avail == 0)
|
|
|
|
+ continue;
|
|
|
|
|
|
ret = find_free_dev_extent(trans, device,
|
|
ret = find_free_dev_extent(trans, device,
|
|
max_stripe_size * dev_stripes,
|
|
max_stripe_size * dev_stripes,
|