]> git.hungrycats.org Git - linux/commitdiff
btrfs: Fix tail space processing in find_free_dev_extent()
authorZhao Lei <zhaolei@cn.fujitsu.com>
Mon, 16 Feb 2015 10:52:17 +0000 (18:52 +0800)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Fri, 17 Apr 2015 15:59:53 +0000 (11:59 -0400)
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>
(cherry picked from commit f2ab76188ec185dde84e7fe7c533ef2f5d668a32)

fs/btrfs/volumes.c

index bff66e38fa43458354484edc8d82dc0842ae419b..41957ae3c2b518c15909b92d16e74d06addf068a 100644 (file)
@@ -1138,11 +1138,11 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
        path = btrfs_alloc_path();
        if (!path)
                return -ENOMEM;
-again:
+
        max_hole_start = search_start;
        max_hole_size = 0;
-       hole_size = 0;
 
+again:
        if (search_start >= search_end || device->is_tgtdev_for_dev_replace) {
                ret = -ENOSPC;
                goto out;
@@ -1235,21 +1235,23 @@ next:
         * allocated dev extents, and when shrinking the device,
         * search_end may be smaller than search_start.
         */
-       if (search_end > search_start)
+       if (search_end > search_start) {
                hole_size = search_end - search_start;
 
-       if (hole_size > max_hole_size) {
-               max_hole_start = search_start;
-               max_hole_size = hole_size;
-       }
+               if (contains_pending_extent(trans, device, &search_start,
+                                           hole_size)) {
+                       btrfs_release_path(path);
+                       goto again;
+               }
 
-       if (contains_pending_extent(trans, device, &search_start, hole_size)) {
-               btrfs_release_path(path);
-               goto again;
+               if (hole_size > max_hole_size) {
+                       max_hole_start = search_start;
+                       max_hole_size = hole_size;
+               }
        }
 
        /* See above. */
-       if (hole_size < num_bytes)
+       if (max_hole_size < num_bytes)
                ret = -ENOSPC;
        else
                ret = 0;