linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Btrfs: fix enospc in hole punching
@ 2016-10-28  2:32 robbieko
  2016-11-30 16:14 ` Filipe Manana
  0 siblings, 1 reply; 2+ messages in thread
From: robbieko @ 2016-10-28  2:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Robbie Ko

From: Robbie Ko <robbieko@synology.com>

The hole punching can result in adding new leafs (and as a consequence
new nodes) to the tree because when we find file extent items that span
beyond the hole range we may end up not deleting them (just adjusting them)
and add new file extent items representing holes.

That after splitting a leaf (therefore creating a new one), a new node
might be added to each level of the tree (since there's a new key and
every parent node was full).

Fix this by use btrfs_calc_trans_metadata_size instead of
btrfs_calc_trunc_metadata_size.

v2:
* Improve the change log

Signed-off-by: Robbie Ko <robbieko@synology.com>
---
 fs/btrfs/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index fea31a4..809ca85 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2322,7 +2322,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 	u64 tail_len;
 	u64 orig_start = offset;
 	u64 cur_offset;
-	u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
+	u64 min_size = btrfs_calc_trans_metadata_size(root, 1);
 	u64 drop_end;
 	int ret = 0;
 	int err = 0;
@@ -2469,7 +2469,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
 		ret = -ENOMEM;
 		goto out_free;
 	}
-	rsv->size = btrfs_calc_trunc_metadata_size(root, 1);
+	rsv->size = btrfs_calc_trans_metadata_size(root, 1);
 	rsv->failfast = 1;
 
 	/*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Btrfs: fix enospc in hole punching
  2016-10-28  2:32 [PATCH v2] Btrfs: fix enospc in hole punching robbieko
@ 2016-11-30 16:14 ` Filipe Manana
  0 siblings, 0 replies; 2+ messages in thread
From: Filipe Manana @ 2016-11-30 16:14 UTC (permalink / raw)
  To: robbieko; +Cc: linux-btrfs@vger.kernel.org

On Fri, Oct 28, 2016 at 3:32 AM, robbieko <robbieko@synology.com> wrote:
> From: Robbie Ko <robbieko@synology.com>
>
> The hole punching can result in adding new leafs (and as a consequence
> new nodes) to the tree because when we find file extent items that span
> beyond the hole range we may end up not deleting them (just adjusting them)
> and add new file extent items representing holes.
>
> That after splitting a leaf (therefore creating a new one), a new node
> might be added to each level of the tree (since there's a new key and
> every parent node was full).
>
> Fix this by use btrfs_calc_trans_metadata_size instead of
> btrfs_calc_trunc_metadata_size.
>
> v2:
> * Improve the change log

Version information does not belong in the changelog but after the ---
below (it wouldn't make sense to have it in the git changelogs...).
See https://btrfs.wiki.kernel.org/index.php/Developer's_FAQ#Repeated_submissions
and examples from others that submit patches to this list.

>
> Signed-off-by: Robbie Ko <robbieko@synology.com>

I've reworded the changelog for clarity and added it to my branch at:
https://git.kernel.org/cgit/linux/kernel/git/fdmanana/linux.git/log/?h=for-chris-4.10

Thanks.

> ---
>  fs/btrfs/file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index fea31a4..809ca85 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -2322,7 +2322,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
>         u64 tail_len;
>         u64 orig_start = offset;
>         u64 cur_offset;
> -       u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
> +       u64 min_size = btrfs_calc_trans_metadata_size(root, 1);
>         u64 drop_end;
>         int ret = 0;
>         int err = 0;
> @@ -2469,7 +2469,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
>                 ret = -ENOMEM;
>                 goto out_free;
>         }
> -       rsv->size = btrfs_calc_trunc_metadata_size(root, 1);
> +       rsv->size = btrfs_calc_trans_metadata_size(root, 1);
>         rsv->failfast = 1;
>
>         /*
> --
> 1.9.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



-- 
Filipe David Manana,

"People will forget what you said,
 people will forget what you did,
 but people will never forget how you made them feel."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-30 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-28  2:32 [PATCH v2] Btrfs: fix enospc in hole punching robbieko
2016-11-30 16:14 ` Filipe Manana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).