Re: [PATCH 2/2] Btrfs: fix space leak when trimming free extents

2011-06-21 Thread Li Dongyang
On Tuesday, June 21, 2011 01:50:10 PM Li Zefan wrote:
> When the end of an extent exceeds the end of the specified range,
> the extent will be accidentally truncated.
> 
> Signed-off-by: Li Zefan 
> ---
>  fs/btrfs/free-space-cache.c |9 -
>  1 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 292c0d9..185cf8e 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -2509,8 +2509,15 @@ int btrfs_trim_block_group(struct 
> btrfs_block_group_cache *block_group,
>   bytes = min(entry->bytes, end - start);
>   if (bytes < minlen)
>   goto next;
> +
>   unlink_free_space(ctl, entry);
> - kmem_cache_free(btrfs_free_space_cachep, entry);
> + if (bytes < entry->bytes) {
> + entry->offset = entry->offset + bytes;
> + entry->bytes = entry->bytes - bytes;
> + link_free_space(ctl, entry);
yes, I forgot to link the rest extent to the free space cache.
Thanks for the fix!
> + } else {
> + kmem_cache_free(btrfs_free_space_cachep, entry);
> + }
>   }
>  
>   spin_unlock(&ctl->tree_lock);
> -- 1.7.3.1 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] Btrfs: fix space leak when trimming free extents

2011-06-20 Thread Li Zefan
When the end of an extent exceeds the end of the specified range,
the extent will be accidentally truncated.

Signed-off-by: Li Zefan 
---
 fs/btrfs/free-space-cache.c |9 -
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 292c0d9..185cf8e 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -2509,8 +2509,15 @@ int btrfs_trim_block_group(struct 
btrfs_block_group_cache *block_group,
bytes = min(entry->bytes, end - start);
if (bytes < minlen)
goto next;
+
unlink_free_space(ctl, entry);
-   kmem_cache_free(btrfs_free_space_cachep, entry);
+   if (bytes < entry->bytes) {
+   entry->offset = entry->offset + bytes;
+   entry->bytes = entry->bytes - bytes;
+   link_free_space(ctl, entry);
+   } else {
+   kmem_cache_free(btrfs_free_space_cachep, entry);
+   }
}
 
spin_unlock(&ctl->tree_lock);
-- 1.7.3.1 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html