diff mbox

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

Message ID 4E003112.9050702@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Li Zefan June 21, 2011, 5:50 a.m. UTC
When the end of an extent exceeds the end of the specified range,
the extent will be accidentally truncated.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 fs/btrfs/free-space-cache.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

-- 1.7.3.1 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Li Dongyang June 21, 2011, 9:45 a.m. UTC | #1
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 <lizf@cn.fujitsu.com>
> ---
>  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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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);