[RFC,v2,2/4] btrfs: don't BUG_ON() in btrfs_link_subvol()
diff mbox series

Message ID 20180911112903.25985-3-lufq.fnst@cn.fujitsu.com
State New
Headers show
Series
  • undelete subvolume online version
Related show

Commit Message

Lu Fengqi Sept. 11, 2018, 11:29 a.m. UTC
Both of btrfs_update_inode() and btrfs_add_root_ref() may fail because
of ENOMEM. So there's no reason to panic here, we can replace BUG_ON()
with btrfs_abort_transaction() here.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
 fs/btrfs/ioctl.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Qu Wenruo Sept. 11, 2018, 11:54 a.m. UTC | #1
On 2018/9/11 下午7:29, Lu Fengqi wrote:
> Both of btrfs_update_inode() and btrfs_add_root_ref() may fail because
> of ENOMEM.

Not only ENOMEM, but also EEXIST/EIO from btrfs_insert_empty_item().

> So there's no reason to panic here, we can replace BUG_ON()
> with btrfs_abort_transaction() here.

Valid cleanup.

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

Thanks,
Qu

> 
> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
> ---
>  fs/btrfs/ioctl.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 1b03d07acde2..f6173d4e7ced 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -572,11 +572,17 @@ static int btrfs_link_subvol(struct btrfs_trans_handle *trans,
>  
>  	btrfs_i_size_write(BTRFS_I(dir), dir->i_size + namelen * 2);
>  	ret = btrfs_update_inode(trans, root, dir);
> -	BUG_ON(ret);
> +	if (ret) {
> +		btrfs_abort_transaction(trans, ret);
> +		return ret;
> +	}
>  
>  	ret = btrfs_add_root_ref(trans, objectid, root->root_key.objectid,
>  				 btrfs_ino(BTRFS_I(dir)), index, name, namelen);
> -	BUG_ON(ret);
> +	if (ret) {
> +		btrfs_abort_transaction(trans, ret);
> +		return ret;
> +	}
>  
>  	return ret;
>  }
>

Patch
diff mbox series

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 1b03d07acde2..f6173d4e7ced 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -572,11 +572,17 @@  static int btrfs_link_subvol(struct btrfs_trans_handle *trans,
 
 	btrfs_i_size_write(BTRFS_I(dir), dir->i_size + namelen * 2);
 	ret = btrfs_update_inode(trans, root, dir);
-	BUG_ON(ret);
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
 
 	ret = btrfs_add_root_ref(trans, objectid, root->root_key.objectid,
 				 btrfs_ino(BTRFS_I(dir)), index, name, namelen);
-	BUG_ON(ret);
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
 
 	return ret;
 }