Re: [PATCH vfs.all 22/26] block: stash a bdev_file to read/write raw blcok_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

在 2024/04/09 18:23, Christian Brauner 写道:
+static int __stash_bdev_file(struct block_device *bdev)

I've said that on the previous version. I think that this is really
error prone and seems overall like an unpleasant solution. I would
really like to avoid going down that route.

Yes, I see your point, and it's indeed reasonable.


I think a chunk of this series is good though specicially simple
conversions of individual filesystems where file_inode() or f_mapping
makes sense. There's a few exceptions where we might be better of
replacing the current apis with something else (I think Al touched on
that somewhere further down the thread.).

I'd suggest the straightforward bd_inode removals into a separate series
that I can take.

Thanks for working on all of this. It's certainly a contentious area.

How about following simple patch to expose bdev_mapping() for
fs/buffer.c for now?

Thanks,
Kuai

diff --git a/block/blk.h b/block/blk.h
index a34bb590cce6..f8bcb43a12c6 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -428,7 +428,6 @@ static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,
 #endif /* CONFIG_BLK_DEV_ZONED */

 struct inode *bdev_inode(struct block_device *bdev);
-struct address_space *bdev_mapping(struct block_device *bdev);
 struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
 void bdev_add(struct block_device *bdev, dev_t dev);

diff --git a/fs/buffer.c b/fs/buffer.c
index 4f73d23c2c46..e2bd19e3fe48 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -189,8 +189,8 @@ EXPORT_SYMBOL(end_buffer_write_sync);
 static struct buffer_head *
 __find_get_block_slow(struct block_device *bdev, sector_t block)
 {
-       struct inode *bd_inode = bdev->bd_inode;
-       struct address_space *bd_mapping = bd_inode->i_mapping;
+       struct address_space *bd_mapping = bdev_mapping(bdev);
+       struct inode *bd_inode = bd_mapping->host;
        struct buffer_head *ret = NULL;
        pgoff_t index;
        struct buffer_head *bh;
@@ -1034,12 +1034,12 @@ static sector_t folio_init_buffers(struct folio *folio,
 static bool grow_dev_folio(struct block_device *bdev, sector_t block,
                pgoff_t index, unsigned size, gfp_t gfp)
 {
-       struct inode *inode = bdev->bd_inode;
+       struct address_space *bd_mapping = bdev_mapping(bdev);
        struct folio *folio;
        struct buffer_head *bh;
        sector_t end_block = 0;

-       folio = __filemap_get_folio(inode->i_mapping, index,
+       folio = __filemap_get_folio(bd_mapping, index,
                        FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
        if (IS_ERR(folio))
                return false;
@@ -1073,10 +1073,10 @@ static bool grow_dev_folio(struct block_device *bdev, sector_t block,
         * lock to be atomic wrt __find_get_block(), which does not
         * run under the folio lock.
         */
-       spin_lock(&inode->i_mapping->i_private_lock);
+       spin_lock(&bd_mapping->i_private_lock);
        link_dev_buffers(folio, bh);
        end_block = folio_init_buffers(folio, bdev, size);
-       spin_unlock(&inode->i_mapping->i_private_lock);
+       spin_unlock(&bd_mapping->i_private_lock);
 unlock:
        folio_unlock(folio);
        folio_put(folio);
@@ -1463,7 +1463,7 @@ __bread_gfp(struct block_device *bdev, sector_t block,
 {
        struct buffer_head *bh;

-       gfp |= mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS);
+       gfp |= mapping_gfp_constraint(bdev_mapping(bdev), ~__GFP_FS);

        /*
         * Prefer looping in the allocator rather than here, at least that
@@ -1696,8 +1696,8 @@ EXPORT_SYMBOL(create_empty_buffers);
  */
void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
 {
-       struct inode *bd_inode = bdev->bd_inode;
-       struct address_space *bd_mapping = bd_inode->i_mapping;
+       struct address_space *bd_mapping = bdev_mapping(bdev);
+       struct inode *bd_inode = bd_mapping->host;
        struct folio_batch fbatch;
        pgoff_t index = ((loff_t)block << bd_inode->i_blkbits) / PAGE_SIZE;
        pgoff_t end;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index bc840e0fb6e5..bbae55535d53 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1527,6 +1527,7 @@ void blkdev_put_no_open(struct block_device *bdev);

 struct block_device *I_BDEV(struct inode *inode);
 struct block_device *file_bdev(struct file *bdev_file);
+struct address_space *bdev_mapping(struct block_device *bdev);
 bool disk_live(struct gendisk *disk);
 unsigned int block_size(struct block_device *bdev);

.






[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux