diff mbox series

[3/4] btrfs: handle logged extent failure properly

Message ID 20200211214042.4645-4-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Error condition failure fixes | expand

Commit Message

Josef Bacik Feb. 11, 2020, 9:40 p.m. UTC
If we're allocating a logged extent we attempt to insert an extent
record for the file extent directly.  We increase
space_info->bytes_reserved, because the extent entry addition will call
btrfs_update_block_group(), which will convert the ->bytes_reserved to
->bytes_used.  However if we fail at any point while inserting the
extent entry we will bail and leave space on ->bytes_reserved, which
will trigger a WARN_ON() on umount.  Fix this by pinning the space if we
fail to insert, which is what happens in every other failure case that
involves adding the extent entry.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Qu Wenruo Feb. 12, 2020, 12:58 a.m. UTC | #1
On 2020/2/12 上午5:40, Josef Bacik wrote:
> If we're allocating a logged extent we attempt to insert an extent
> record for the file extent directly.  We increase
> space_info->bytes_reserved, because the extent entry addition will call
> btrfs_update_block_group(), which will convert the ->bytes_reserved to
> ->bytes_used.  However if we fail at any point while inserting the
> extent entry we will bail and leave space on ->bytes_reserved, which
> will trigger a WARN_ON() on umount.  Fix this by pinning the space if we
> fail to insert, which is what happens in every other failure case that
> involves adding the extent entry.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>  fs/btrfs/extent-tree.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index c43acb329fa6..2b4c3ca5e651 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -4430,6 +4430,8 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
>  
>  	ret = alloc_reserved_file_extent(trans, 0, root_objectid, 0, owner,
>  					 offset, ins, 1);
> +	if (ret)
> +		btrfs_pin_extent(fs_info, ins->objectid, ins->offset, 1);
>  	btrfs_put_block_group(block_group);
>  	return ret;
>  }
>
Nikolay Borisov Feb. 13, 2020, 10:26 a.m. UTC | #2
On 11.02.20 г. 23:40 ч., Josef Bacik wrote:
> If we're allocating a logged extent we attempt to insert an extent
> record for the file extent directly.  We increase
> space_info->bytes_reserved, because the extent entry addition will call
> btrfs_update_block_group(), which will convert the ->bytes_reserved to
> ->bytes_used.  However if we fail at any point while inserting the
> extent entry we will bail and leave space on ->bytes_reserved, which
> will trigger a WARN_ON() on umount.  Fix this by pinning the space if we
> fail to insert, which is what happens in every other failure case that
> involves adding the extent entry.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Johannes Thumshirn Feb. 13, 2020, 11:16 a.m. UTC | #3
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c43acb329fa6..2b4c3ca5e651 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4430,6 +4430,8 @@  int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
 
 	ret = alloc_reserved_file_extent(trans, 0, root_objectid, 0, owner,
 					 offset, ins, 1);
+	if (ret)
+		btrfs_pin_extent(fs_info, ins->objectid, ins->offset, 1);
 	btrfs_put_block_group(block_group);
 	return ret;
 }