Btrfs: only exclude supers in the range of our block group
authorJosef Bacik <jbacik@fusionio.com>
Tue, 23 Apr 2013 16:55:21 +0000 (12:55 -0400)
committerJosef Bacik <jbacik@fusionio.com>
Mon, 6 May 2013 19:55:06 +0000 (15:55 -0400)
If we fail to load block groups halfway through we can leave extent_state's on
the excluded tree.  This is because we just lookup the supers and add them to
the excluded tree regardless of which block group we are looking at currently.
This is a problem because we remove the excluded extents for the range of the
block group only, so if we don't ever load a block group for one of the excluded
extents we won't ever free it.  This fixes the problem by only adding excluded
extents if it falls in the block group range we care about.  With this patch
we're no longer leaking space when we fail to read all of the block groups.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
fs/btrfs/extent-tree.c

index fa57965f60a33c20670e555bb1dc6b28439143a3..94bed61b799f8d1253610987e7aa52a6c5258704 100644 (file)
@@ -270,9 +270,27 @@ static int exclude_super_stripes(struct btrfs_root *root,
                        return ret;
 
                while (nr--) {
-                       cache->bytes_super += stripe_len;
-                       ret = add_excluded_extent(root, logical[nr],
-                                                 stripe_len);
+                       u64 start, len;
+
+                       if (logical[nr] > cache->key.objectid +
+                           cache->key.offset)
+                               continue;
+
+                       if (logical[nr] + stripe_len <= cache->key.objectid)
+                               continue;
+
+                       start = logical[nr];
+                       if (start < cache->key.objectid) {
+                               start = cache->key.objectid;
+                               len = (logical[nr] + stripe_len) - start;
+                       } else {
+                               len = min_t(u64, stripe_len,
+                                           cache->key.objectid +
+                                           cache->key.offset - start);
+                       }
+
+                       cache->bytes_super += len;
+                       ret = add_excluded_extent(root, start, len);
                        if (ret) {
                                kfree(logical);
                                return ret;