diff mbox series

[6/7] btrfs: Call submit_bio_hook directly for metadata pages

Message ID 20200918133439.23187-7-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Remove struct extent_io_ops | expand

Commit Message

Nikolay Borisov Sept. 18, 2020, 1:34 p.m. UTC
No need to go through a function pointer indirection simply call
submit_bio_hook directly by exporting and renaming the helper to
btrfs_submit_metadata_bio. This makes the code more readable and should
result in somewhat faster code due to no longer paying the price for
specualtive attack mitigations that come with indirect function calls.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/disk-io.c   | 7 +++----
 fs/btrfs/disk-io.h   | 2 ++
 fs/btrfs/extent_io.c | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

Comments

Johannes Thumshirn Sept. 21, 2020, 3:04 p.m. UTC | #1
On 18/09/2020 15:34, Nikolay Borisov wrote:
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 8cabcb7642a9..4a00cfd4082f 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -172,8 +172,8 @@ int __must_check submit_one_bio(struct bio *bio, int mirror_num,
>  		ret = btrfs_submit_data_bio(tree->private_data, bio, mirror_num,
>  					    bio_flags);
>  	else
> -		ret = tree->ops->submit_bio_hook(tree->private_data, bio,
> -						 mirror_num, bio_flags);
> +		ret = btrfs_submit_metadata_bio(tree->private_data, bio,
> +						mirror_num, bio_flags);
>  


Hmm we could even turn this into a little helper calling either
btrfs_submit_data_bio or btrfs_submit_metadata_bio. But that's just stylistic
preference I guess.
David Sterba Sept. 21, 2020, 8:32 p.m. UTC | #2
On Mon, Sep 21, 2020 at 03:04:54PM +0000, Johannes Thumshirn wrote:
> On 18/09/2020 15:34, Nikolay Borisov wrote:
> > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> > index 8cabcb7642a9..4a00cfd4082f 100644
> > --- a/fs/btrfs/extent_io.c
> > +++ b/fs/btrfs/extent_io.c
> > @@ -172,8 +172,8 @@ int __must_check submit_one_bio(struct bio *bio, int mirror_num,
> >  		ret = btrfs_submit_data_bio(tree->private_data, bio, mirror_num,
> >  					    bio_flags);
> >  	else
> > -		ret = tree->ops->submit_bio_hook(tree->private_data, bio,
> > -						 mirror_num, bio_flags);
> > +		ret = btrfs_submit_metadata_bio(tree->private_data, bio,
> > +						mirror_num, bio_flags);
> >  
> 
> 
> Hmm we could even turn this into a little helper calling either
> btrfs_submit_data_bio or btrfs_submit_metadata_bio. But that's just stylistic
> preference I guess.

Yeah a helper could be here but I think it's fine without that extra
indirection, the code is clear that for data inode it's some "data"
function, with the same set of parameters. If there's just one location
switching the two, the helper would not help much IMHO.
Nikolay Borisov Sept. 23, 2020, 6:24 a.m. UTC | #3
On 21.09.20 г. 23:32 ч., David Sterba wrote:
> On Mon, Sep 21, 2020 at 03:04:54PM +0000, Johannes Thumshirn wrote:
>> On 18/09/2020 15:34, Nikolay Borisov wrote:
>>> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
>>> index 8cabcb7642a9..4a00cfd4082f 100644
>>> --- a/fs/btrfs/extent_io.c
>>> +++ b/fs/btrfs/extent_io.c
>>> @@ -172,8 +172,8 @@ int __must_check submit_one_bio(struct bio *bio, int mirror_num,
>>>  		ret = btrfs_submit_data_bio(tree->private_data, bio, mirror_num,
>>>  					    bio_flags);
>>>  	else
>>> -		ret = tree->ops->submit_bio_hook(tree->private_data, bio,
>>> -						 mirror_num, bio_flags);
>>> +		ret = btrfs_submit_metadata_bio(tree->private_data, bio,
>>> +						mirror_num, bio_flags);
>>>  
>>
>>
>> Hmm we could even turn this into a little helper calling either
>> btrfs_submit_data_bio or btrfs_submit_metadata_bio. But that's just stylistic
>> preference I guess.
> 
> Yeah a helper could be here but I think it's fine without that extra
> indirection, the code is clear that for data inode it's some "data"
> function, with the same set of parameters. If there's just one location
> switching the two, the helper would not help much IMHO.
> 

<NOD> The idea here is to have less functions in the way, if there were
more places that this change was necessary I would have gone the helper
way.
diff mbox series

Patch

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 73937954f464..54f2b95cc305 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -815,9 +815,8 @@  static int check_async_write(struct btrfs_fs_info *fs_info,
 	return 1;
 }
 
-static blk_status_t btree_submit_bio_hook(struct inode *inode, struct bio *bio,
-					  int mirror_num,
-					  unsigned long bio_flags)
+blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio,
+				       int mirror_num, unsigned long bio_flags)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	int async = check_async_write(fs_info, BTRFS_I(inode));
@@ -4637,5 +4636,5 @@  static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info)
 }
 
 static const struct extent_io_ops btree_extent_io_ops = {
-	.submit_bio_hook = btree_submit_bio_hook
+	.submit_bio_hook = NULL
 };
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index bc2e49246199..fee69ced58b4 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -79,6 +79,8 @@  void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
 int btrfs_validate_metadata_buffer(struct btrfs_io_bio *io_bio, u64 phy_offset,
 				   struct page *page, u64 start, u64 end,
 				   int mirror);
+blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio,
+				       int mirror_num, unsigned long bio_flags);
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
 #endif
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 8cabcb7642a9..4a00cfd4082f 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -172,8 +172,8 @@  int __must_check submit_one_bio(struct bio *bio, int mirror_num,
 		ret = btrfs_submit_data_bio(tree->private_data, bio, mirror_num,
 					    bio_flags);
 	else
-		ret = tree->ops->submit_bio_hook(tree->private_data, bio,
-						 mirror_num, bio_flags);
+		ret = btrfs_submit_metadata_bio(tree->private_data, bio,
+						mirror_num, bio_flags);
 
 	return blk_status_to_errno(ret);
 }