All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
@ 2023-02-19 18:10 Christoph Hellwig
  2023-02-20  8:17 ` Johannes Thumshirn
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Christoph Hellwig @ 2023-02-19 18:10 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs

Move the remaining code that deals with initializing the btree
inode into btrfs_init_btree_inode instead of splitting it between
that helpers and its only caller.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/disk-io.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b53f0e30ce2b3b..981973b40b065a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2125,11 +2125,16 @@ static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
 	atomic_set(&fs_info->reloc_cancel_req, 0);
 }
 
-static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
+static int btrfs_init_btree_inode(struct super_block *sb)
 {
-	struct inode *inode = fs_info->btree_inode;
+	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
 	unsigned long hash = btrfs_inode_hash(BTRFS_BTREE_INODE_OBJECTID,
 					      fs_info->tree_root);
+	struct inode *inode;
+
+	inode = new_inode(sb);
+	if (!inode)
+		return -ENOMEM;
 
 	inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
 	set_nlink(inode, 1);
@@ -2140,6 +2145,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
 	 */
 	inode->i_size = OFFSET_MAX;
 	inode->i_mapping->a_ops = &btree_aops;
+	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
 
 	RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node);
 	extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree,
@@ -2152,6 +2158,8 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
 	BTRFS_I(inode)->location.offset = 0;
 	set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
 	__insert_inode_hash(inode, hash);
+	fs_info->btree_inode = inode;
+	return 0;
 }
 
 static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
@@ -3351,13 +3359,9 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 		goto fail;
 	}
 
-	fs_info->btree_inode = new_inode(sb);
-	if (!fs_info->btree_inode) {
-		err = -ENOMEM;
+	err = btrfs_init_btree_inode(sb);
+	if (err)
 		goto fail;
-	}
-	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
-	btrfs_init_btree_inode(fs_info);
 
 	invalidate_bdev(fs_devices->latest_dev->bdev);
 
-- 
2.39.1


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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-19 18:10 [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode Christoph Hellwig
@ 2023-02-20  8:17 ` Johannes Thumshirn
  2023-02-20 20:19 ` David Sterba
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2023-02-20  8:17 UTC (permalink / raw)
  To: Christoph Hellwig, clm, josef, dsterba; +Cc: linux-btrfs

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-19 18:10 [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode Christoph Hellwig
  2023-02-20  8:17 ` Johannes Thumshirn
@ 2023-02-20 20:19 ` David Sterba
  2023-02-21 14:28   ` Christoph Hellwig
  2023-02-27  7:35 ` Anand Jain
  2024-02-14  6:28 ` Qu Wenruo
  3 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2023-02-20 20:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: clm, josef, dsterba, linux-btrfs

On Sun, Feb 19, 2023 at 07:10:22PM +0100, Christoph Hellwig wrote:
> Move the remaining code that deals with initializing the btree
> inode into btrfs_init_btree_inode instead of splitting it between
> that helpers and its only caller.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Added to misc-next, thanks.

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-20 20:19 ` David Sterba
@ 2023-02-21 14:28   ` Christoph Hellwig
  2023-02-21 14:51     ` David Sterba
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2023-02-21 14:28 UTC (permalink / raw)
  To: David Sterba; +Cc: Christoph Hellwig, clm, josef, dsterba, linux-btrfs

On Mon, Feb 20, 2023 at 09:19:05PM +0100, David Sterba wrote:
> On Sun, Feb 19, 2023 at 07:10:22PM +0100, Christoph Hellwig wrote:
> > Move the remaining code that deals with initializing the btree
> > inode into btrfs_init_btree_inode instead of splitting it between
> > that helpers and its only caller.
> > 
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Added to misc-next, thanks.

Btw, in case you need to rebase again, the subject needs a
'inode' after 'btree'.

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-21 14:28   ` Christoph Hellwig
@ 2023-02-21 14:51     ` David Sterba
  0 siblings, 0 replies; 11+ messages in thread
From: David Sterba @ 2023-02-21 14:51 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: David Sterba, clm, josef, dsterba, linux-btrfs

On Tue, Feb 21, 2023 at 03:28:18PM +0100, Christoph Hellwig wrote:
> On Mon, Feb 20, 2023 at 09:19:05PM +0100, David Sterba wrote:
> > On Sun, Feb 19, 2023 at 07:10:22PM +0100, Christoph Hellwig wrote:
> > > Move the remaining code that deals with initializing the btree
> > > inode into btrfs_init_btree_inode instead of splitting it between
> > > that helpers and its only caller.
> > > 
> > > Signed-off-by: Christoph Hellwig <hch@lst.de>
> > 
> > Added to misc-next, thanks.
> 
> Btw, in case you need to rebase again, the subject needs a
> 'inode' after 'btree'.

I see, fixed, thanks.

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-19 18:10 [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode Christoph Hellwig
  2023-02-20  8:17 ` Johannes Thumshirn
  2023-02-20 20:19 ` David Sterba
@ 2023-02-27  7:35 ` Anand Jain
  2023-02-27 13:39   ` Christoph Hellwig
  2023-02-27 18:41   ` David Sterba
  2024-02-14  6:28 ` Qu Wenruo
  3 siblings, 2 replies; 11+ messages in thread
From: Anand Jain @ 2023-02-27  7:35 UTC (permalink / raw)
  To: Christoph Hellwig, dsterba; +Cc: linux-btrfs, clm, josef

On 2/20/23 02:10, Christoph Hellwig wrote:
> Move the remaining code that deals with initializing the btree
> inode into btrfs_init_btree_inode instead of splitting it between
> that helpers and its only caller.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   fs/btrfs/disk-io.c | 20 ++++++++++++--------
>   1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index b53f0e30ce2b3b..981973b40b065a 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -2125,11 +2125,16 @@ static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
>   	atomic_set(&fs_info->reloc_cancel_req, 0);
>   }
>   
> -static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
> +static int btrfs_init_btree_inode(struct super_block *sb)
>   {
> -	struct inode *inode = fs_info->btree_inode;
> +	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
>   	unsigned long hash = btrfs_inode_hash(BTRFS_BTREE_INODE_OBJECTID,
>   					      fs_info->tree_root);
> +	struct inode *inode;
> +
> +	inode = new_inode(sb);
> +	if (!inode)
> +		return -ENOMEM;
>   
>   	inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
>   	set_nlink(inode, 1);
> @@ -2140,6 +2145,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
>   	 */
>   	inode->i_size = OFFSET_MAX;
>   	inode->i_mapping->a_ops = &btree_aops;
> +	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
>   
>   	RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node);
>   	extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree,
> @@ -2152,6 +2158,8 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
>   	BTRFS_I(inode)->location.offset = 0;
>   	set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
>   	__insert_inode_hash(inode, hash);
> +	fs_info->btree_inode = inode;
> +	return 0;
>   }
>   
>   static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
> @@ -3351,13 +3359,9 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
>   		goto fail;
>   	}
>   
> -	fs_info->btree_inode = new_inode(sb);
> -	if (!fs_info->btree_inode) {
> -		err = -ENOMEM;
> +	err = btrfs_init_btree_inode(sb);
> +	if (err)
>   		goto fail;
> -	}
> -	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
> -	btrfs_init_btree_inode(fs_info);
>   
>   	invalidate_bdev(fs_devices->latest_dev->bdev);
>   

Dave,

  This patch is causing a regression, as reported here:

 
https://patchwork.kernel.org/project/linux-btrfs/patch/2de92bdcebd36e4119467797dedae8a9d97a9df3.1677314616.git.wqu@suse.com/

  There are many child functions in open_ctree() that rely on the default
  value of @err, which is -EINVAL, to return an error instead of ret.
  The issue is that @err is being overwritten by the return value of
  btrfs_init_btree_inode() in this patch.

  To fix this issue, please fold the following diff into the patch.

  Once that's done, you can add:


  Reviewed-by: Anand Jain <anand.jain@oracle.com>


diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 48368d4bc331..0e0c30fe6df6 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3360,9 +3360,11 @@ int __cold open_ctree(struct super_block *sb, 
struct btrfs_fs_devices *fs_device
                 goto fail;
         }

-       err = btrfs_init_btree_inode(sb);
-       if (err)
+       ret = btrfs_init_btree_inode(sb);
+       if (ret) {
+               err = ret;
                 goto fail;
+       }

         invalidate_bdev(fs_devices->latest_dev->bdev);




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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-27  7:35 ` Anand Jain
@ 2023-02-27 13:39   ` Christoph Hellwig
  2023-02-27 18:41   ` David Sterba
  1 sibling, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2023-02-27 13:39 UTC (permalink / raw)
  To: Anand Jain; +Cc: Christoph Hellwig, dsterba, linux-btrfs, clm, josef

Thanks Anand.  The fix looks good to me.  The error handling is a bit
confsing and hopefully we can get it fixed up eventually.

Just curious how you found the error as I didn't see anything in
xfstest runs.

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-27  7:35 ` Anand Jain
  2023-02-27 13:39   ` Christoph Hellwig
@ 2023-02-27 18:41   ` David Sterba
  1 sibling, 0 replies; 11+ messages in thread
From: David Sterba @ 2023-02-27 18:41 UTC (permalink / raw)
  To: Anand Jain; +Cc: Christoph Hellwig, dsterba, linux-btrfs, clm, josef

On Mon, Feb 27, 2023 at 03:35:53PM +0800, Anand Jain wrote:
> On 2/20/23 02:10, Christoph Hellwig wrote:
> >   
> 
> Dave,
> 
>   This patch is causing a regression, as reported here:
> 
>  
> https://patchwork.kernel.org/project/linux-btrfs/patch/2de92bdcebd36e4119467797dedae8a9d97a9df3.1677314616.git.wqu@suse.com/
> 
>   There are many child functions in open_ctree() that rely on the default
>   value of @err, which is -EINVAL, to return an error instead of ret.
>   The issue is that @err is being overwritten by the return value of
>   btrfs_init_btree_inode() in this patch.
> 
>   To fix this issue, please fold the following diff into the patch.

Thanks. open_ctree has mixed the original and newish style of error
variables. In some btrfs functions but more widely seen in other VFS
code the error value is set once and the errors only go to return, while
what I think we should unify is the error set right before goto or
inherited from the call itself. It's a few lines more but the exact
error value is at the place where it happens and not somewhere in the
function and possibly changed on any line between. Feel free to clean up
open_ctree().

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2023-02-19 18:10 [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode Christoph Hellwig
                   ` (2 preceding siblings ...)
  2023-02-27  7:35 ` Anand Jain
@ 2024-02-14  6:28 ` Qu Wenruo
  2024-02-14  7:12   ` David Sterba
  3 siblings, 1 reply; 11+ messages in thread
From: Qu Wenruo @ 2024-02-14  6:28 UTC (permalink / raw)
  To: Christoph Hellwig, clm, josef, dsterba; +Cc: linux-btrfs



在 2023/2/20 04:40, Christoph Hellwig 写道:
> Move the remaining code that deals with initializing the btree
> inode into btrfs_init_btree_inode instead of splitting it between
> that helpers and its only caller.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

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

Just one small nitpick.

> ---
>   fs/btrfs/disk-io.c | 20 ++++++++++++--------
>   1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index b53f0e30ce2b3b..981973b40b065a 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -2125,11 +2125,16 @@ static void btrfs_init_balance(struct btrfs_fs_info *fs_info)
>   	atomic_set(&fs_info->reloc_cancel_req, 0);
>   }
>
> -static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
> +static int btrfs_init_btree_inode(struct super_block *sb)

It's preferred to use btrfs_fs_info * as a parameter, just to keep the
consistency of all btrfs interfaces.

Thanks,
Qu

>   {
> -	struct inode *inode = fs_info->btree_inode;
> +	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
>   	unsigned long hash = btrfs_inode_hash(BTRFS_BTREE_INODE_OBJECTID,
>   					      fs_info->tree_root);
> +	struct inode *inode;
> +
> +	inode = new_inode(sb);
> +	if (!inode)
> +		return -ENOMEM;
>
>   	inode->i_ino = BTRFS_BTREE_INODE_OBJECTID;
>   	set_nlink(inode, 1);
> @@ -2140,6 +2145,7 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
>   	 */
>   	inode->i_size = OFFSET_MAX;
>   	inode->i_mapping->a_ops = &btree_aops;
> +	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
>
>   	RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node);
>   	extent_io_tree_init(fs_info, &BTRFS_I(inode)->io_tree,
> @@ -2152,6 +2158,8 @@ static void btrfs_init_btree_inode(struct btrfs_fs_info *fs_info)
>   	BTRFS_I(inode)->location.offset = 0;
>   	set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
>   	__insert_inode_hash(inode, hash);
> +	fs_info->btree_inode = inode;
> +	return 0;
>   }
>
>   static void btrfs_init_dev_replace_locks(struct btrfs_fs_info *fs_info)
> @@ -3351,13 +3359,9 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
>   		goto fail;
>   	}
>
> -	fs_info->btree_inode = new_inode(sb);
> -	if (!fs_info->btree_inode) {
> -		err = -ENOMEM;
> +	err = btrfs_init_btree_inode(sb);
> +	if (err)
>   		goto fail;
> -	}
> -	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
> -	btrfs_init_btree_inode(fs_info);
>
>   	invalidate_bdev(fs_devices->latest_dev->bdev);
>

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2024-02-14  6:28 ` Qu Wenruo
@ 2024-02-14  7:12   ` David Sterba
  2024-02-14  8:32     ` Qu Wenruo
  0 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2024-02-14  7:12 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: Christoph Hellwig, clm, josef, dsterba, linux-btrfs

On Wed, Feb 14, 2024 at 04:58:55PM +1030, Qu Wenruo wrote:
> 
> 
> 在 2023/2/20 04:40, Christoph Hellwig 写道:
> > Move the remaining code that deals with initializing the btree
> > inode into btrfs_init_btree_inode instead of splitting it between
> > that helpers and its only caller.
> >
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> 
> Just one small nitpick.

The patch is almost one year old, it does not make much sense to send
reviews, if there's something to be fixed please send a new patch.

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

* Re: [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode
  2024-02-14  7:12   ` David Sterba
@ 2024-02-14  8:32     ` Qu Wenruo
  0 siblings, 0 replies; 11+ messages in thread
From: Qu Wenruo @ 2024-02-14  8:32 UTC (permalink / raw)
  To: dsterba; +Cc: Christoph Hellwig, clm, josef, dsterba, linux-btrfs



在 2024/2/14 17:42, David Sterba 写道:
> On Wed, Feb 14, 2024 at 04:58:55PM +1030, Qu Wenruo wrote:
>>
>>
>> 在 2023/2/20 04:40, Christoph Hellwig 写道:
>>> Move the remaining code that deals with initializing the btree
>>> inode into btrfs_init_btree_inode instead of splitting it between
>>> that helpers and its only caller.
>>>
>>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>>
>> Reviewed-by: Qu Wenruo <wqu@suse.com>
>>
>> Just one small nitpick.
>
> The patch is almost one year old, it does not make much sense to send
> reviews, if there's something to be fixed please send a new patch.

My bad, I'm re-setting up my mail client, and this one popped up and I
thought it's new...

Sorry for the noise,
Qu

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

end of thread, other threads:[~2024-02-14  8:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 18:10 [PATCH] btrfs: move all btree initialization into btrfs_init_btree_inode Christoph Hellwig
2023-02-20  8:17 ` Johannes Thumshirn
2023-02-20 20:19 ` David Sterba
2023-02-21 14:28   ` Christoph Hellwig
2023-02-21 14:51     ` David Sterba
2023-02-27  7:35 ` Anand Jain
2023-02-27 13:39   ` Christoph Hellwig
2023-02-27 18:41   ` David Sterba
2024-02-14  6:28 ` Qu Wenruo
2024-02-14  7:12   ` David Sterba
2024-02-14  8:32     ` Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.