diff mbox series

[RFC,1/4] bdev: replace export of blockdev_superblock with BDEVFS_MAGIC

Message ID 20230608032404.1887046-2-mcgrof@kernel.org (mailing list archive)
State New, archived
Headers show
Series bdev: allow buffer-head & iomap aops to co-exist | expand

Commit Message

Luis Chamberlain June 8, 2023, 3:24 a.m. UTC
There is no need to export blockdev_superblock because we can just
use the magic value of the block device cache super block, which is
already in place, BDEVFS_MAGIC. So just check for that.

This let's us remove the export of blockdev_superblock and also
let's this block dev cache scale as it wishes internally. For
instance in the future we may have different super block for each
block device. Right now it is all shared on one super block.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 block/bdev.c       | 1 -
 include/linux/fs.h | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

Comments

Jan Kara June 8, 2023, 10:22 a.m. UTC | #1
On Wed 07-06-23 20:24:01, Luis Chamberlain wrote:
> There is no need to export blockdev_superblock because we can just
> use the magic value of the block device cache super block, which is
> already in place, BDEVFS_MAGIC. So just check for that.
> 
> This let's us remove the export of blockdev_superblock and also
> let's this block dev cache scale as it wishes internally. For
> instance in the future we may have different super block for each
> block device. Right now it is all shared on one super block.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>  block/bdev.c       | 1 -
>  include/linux/fs.h | 4 ++--
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/block/bdev.c b/block/bdev.c
> index 21c63bfef323..91477c3849d2 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -379,7 +379,6 @@ static struct file_system_type bd_type = {
>  };
>  
>  struct super_block *blockdev_superblock __read_mostly;
> -EXPORT_SYMBOL_GPL(blockdev_superblock);

You can even make blockdev_superblock static. I like this! Otherwise the
patch looks good.

								Honza
Christoph Hellwig June 8, 2023, 1:53 p.m. UTC | #2
On Wed, Jun 07, 2023 at 08:24:01PM -0700, Luis Chamberlain wrote:
> -extern struct super_block *blockdev_superblock;
>  static inline bool sb_is_blkdev_sb(struct super_block *sb)
>  {
> -	return IS_ENABLED(CONFIG_BLOCK) && sb == blockdev_superblock;
> +	return IS_ENABLED(CONFIG_BLOCK) && sb->s_magic == BDEVFS_MAGIC;
>  }

So while I'd love to be able to make blockdev_superblock, I think
the existing code is the better idea here.  BDEVFS_MAGIC can easily
end up in any other s_magic as it's a free-form field.
blockdev_superblock can't accidentally have the same address as a
random non-bdev sb.
diff mbox series

Patch

diff --git a/block/bdev.c b/block/bdev.c
index 21c63bfef323..91477c3849d2 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -379,7 +379,6 @@  static struct file_system_type bd_type = {
 };
 
 struct super_block *blockdev_superblock __read_mostly;
-EXPORT_SYMBOL_GPL(blockdev_superblock);
 
 void __init bdev_cache_init(void)
 {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0b54ac1d331b..948a384af8a3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -43,6 +43,7 @@ 
 #include <linux/cred.h>
 #include <linux/mnt_idmapping.h>
 #include <linux/slab.h>
+#include <uapi/linux/magic.h>
 
 #include <asm/byteorder.h>
 #include <uapi/linux/fs.h>
@@ -2388,10 +2389,9 @@  extern struct kmem_cache *names_cachep;
 #define __getname()		kmem_cache_alloc(names_cachep, GFP_KERNEL)
 #define __putname(name)		kmem_cache_free(names_cachep, (void *)(name))
 
-extern struct super_block *blockdev_superblock;
 static inline bool sb_is_blkdev_sb(struct super_block *sb)
 {
-	return IS_ENABLED(CONFIG_BLOCK) && sb == blockdev_superblock;
+	return IS_ENABLED(CONFIG_BLOCK) && sb->s_magic == BDEVFS_MAGIC;
 }
 
 void emergency_thaw_all(void);