linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device
@ 2023-11-27  6:21 Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 01/16] block: add a new helper to get inode " Yu Kuai
                   ` (9 more replies)
  0 siblings, 10 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Changes in v2:
 - split different portions into different patches, as greg k-h
 suggested.
 - use container_of() instead of "bdev + 1" to get the address of
 bd_inode in the new helper, as grep k-h suggested.

Yu Kuai (16):
  block: add a new helper to get inode from block_device
  xen/blkback: use new helper to get inode from block_device
  bcache: use new helper to get inode from block_device
  mtd: block2mtd: use new helper to get inode from block_device
  s390/dasd: use new helper to get inode from block_device
  scsicam: use new helper to get inode from block_device
  bcachefs: use new helper to get inode from block_device
  btrfs: use new helper to get inode from block_device
  cramfs: use new helper to get inode from block_device
  erofs: use new helper to get inode from block_device
  ext4: use new helper to get inode from block_device
  gfs2: use new helper to get inode from block_device
  jbd2: use new helper to get inode from block_device
  nilfs2: use new helper to get inode from block_device
  buffer: use new helper to get inode from block_device
  block: use new helper to get inode from block_device

 block/bdev.c                       | 44 +++++++++++++++---------------
 block/blk-zoned.c                  |  4 +--
 block/fops.c                       |  4 +--
 block/genhd.c                      |  8 +++---
 block/ioctl.c                      |  8 +++---
 block/partitions/core.c            |  9 +++---
 drivers/block/xen-blkback/xenbus.c |  2 +-
 drivers/md/bcache/super.c          |  2 +-
 drivers/mtd/devices/block2mtd.c    | 12 ++++----
 drivers/s390/block/dasd_ioctl.c    |  2 +-
 drivers/scsi/scsicam.c             |  2 +-
 fs/bcachefs/util.h                 |  2 +-
 fs/btrfs/disk-io.c                 |  6 ++--
 fs/btrfs/volumes.c                 |  4 +--
 fs/btrfs/zoned.c                   |  2 +-
 fs/buffer.c                        |  8 +++---
 fs/cramfs/inode.c                  |  2 +-
 fs/erofs/data.c                    |  2 +-
 fs/ext4/dir.c                      |  2 +-
 fs/ext4/ext4_jbd2.c                |  2 +-
 fs/ext4/super.c                    |  8 +++---
 fs/gfs2/glock.c                    |  2 +-
 fs/gfs2/ops_fstype.c               |  2 +-
 fs/jbd2/journal.c                  |  3 +-
 fs/jbd2/recovery.c                 |  2 +-
 fs/nilfs2/segment.c                |  2 +-
 include/linux/blk_types.h          | 15 ++++++++--
 include/linux/blkdev.h             |  4 +--
 include/linux/buffer_head.h        |  4 +--
 29 files changed, 91 insertions(+), 78 deletions(-)

-- 
2.39.2


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

* [PATCH block/for-next v2 01/16] block: add a new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  7:21   ` Christoph Hellwig
  2023-11-27  6:21 ` [PATCH block/for-next v2 02/16] xen/blkback: use " Yu Kuai
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

block_devcie is allocated from bdev_alloc() by bdev_alloc_inode(), and
currently block_device contains a pointer that point to the address of
inode, while such inode is allocated together:

bdev_alloc
 inode = new_inode()
  // inode is &bdev_inode->vfs_inode
 bdev = I_BDEV(inode)
  // bdev is &bdev_inode->bdev
 bdev->inode = inode

Add a new helper to get address of inode from bdev by add operation
instead of memory access, which is more efficiency.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/bdev.c              |  5 -----
 include/linux/blk_types.h | 12 ++++++++++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/block/bdev.c b/block/bdev.c
index e4cfb7adb645..7509389095b7 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -30,11 +30,6 @@
 #include "../fs/internal.h"
 #include "blk.h"
 
-struct bdev_inode {
-	struct block_device bdev;
-	struct inode vfs_inode;
-};
-
 static inline struct bdev_inode *BDEV_I(struct inode *inode)
 {
 	return container_of(inode, struct bdev_inode, vfs_inode);
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index d5c5e59ddbd2..06de8393dcd1 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -85,6 +85,18 @@ struct block_device {
 #define bdev_kobj(_bdev) \
 	(&((_bdev)->bd_device.kobj))
 
+struct bdev_inode {
+	struct block_device bdev;
+	struct inode vfs_inode;
+};
+
+static inline struct inode *bdev_inode(struct block_device *bdev)
+{
+	struct bdev_inode *bi = container_of(bdev, struct bdev_inode, bdev);
+
+	return &bi->vfs_inode;
+}
+
 /*
  * Block error status values.  See block/blk-core:blk_errors for the details.
  * Alpha cannot write a byte atomically, so we need to use 32-bit value.
-- 
2.39.2


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

* [PATCH block/for-next v2 02/16] xen/blkback: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 01/16] block: add a new helper to get inode " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-28 10:05   ` Roger Pau Monné
  2023-11-27  6:21 ` [PATCH block/for-next v2 03/16] bcache: " Yu Kuai
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/block/xen-blkback/xenbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index e34219ea2b05..e11f8123d213 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -105,7 +105,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
 		return;
 	}
 	invalidate_inode_pages2(
-			blkif->vbd.bdev_handle->bdev->bd_inode->i_mapping);
+			bdev_inode(blkif->vbd.bdev_handle->bdev)->i_mapping);
 
 	for (i = 0; i < blkif->nr_rings; i++) {
 		ring = &blkif->rings[i];
-- 
2.39.2


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

* [PATCH block/for-next v2 03/16] bcache: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 01/16] block: add a new helper to get inode " Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 02/16] xen/blkback: use " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 04/16] mtd: block2mtd: " Yu Kuai
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index bfe1685dbae5..3ab8bae049ee 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -171,7 +171,7 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
 	struct page *page;
 	unsigned int i;
 
-	page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
+	page = read_cache_page_gfp(bdev_inode(bdev)->i_mapping,
 				   SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL);
 	if (IS_ERR(page))
 		return "IO error";
-- 
2.39.2


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

* [PATCH block/for-next v2 04/16] mtd: block2mtd: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (2 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 03/16] bcache: " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 05/16] s390/dasd: " Yu Kuai
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/mtd/devices/block2mtd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index aa44a23ec045..d4f7a4339a70 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -56,7 +56,7 @@ static struct page *page_read(struct address_space *mapping, pgoff_t index)
 static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
 {
 	struct address_space *mapping =
-				dev->bdev_handle->bdev->bd_inode->i_mapping;
+				bdev_inode(dev->bdev_handle->bdev)->i_mapping;
 	struct page *page;
 	pgoff_t index = to >> PAGE_SHIFT;	// page index
 	int pages = len >> PAGE_SHIFT;
@@ -107,7 +107,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
 {
 	struct block2mtd_dev *dev = mtd->priv;
 	struct address_space *mapping =
-				dev->bdev_handle->bdev->bd_inode->i_mapping;
+				bdev_inode(dev->bdev_handle->bdev)->i_mapping;
 	struct page *page;
 	pgoff_t index = from >> PAGE_SHIFT;
 	int offset = from & (PAGE_SIZE-1);
@@ -143,7 +143,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
 {
 	struct page *page;
 	struct address_space *mapping =
-				dev->bdev_handle->bdev->bd_inode->i_mapping;
+				bdev_inode(dev->bdev_handle->bdev)->i_mapping;
 	pgoff_t index = to >> PAGE_SHIFT;	// page index
 	int offset = to & ~PAGE_MASK;	// page offset
 	int cpylen;
@@ -212,7 +212,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
 
 	if (dev->bdev_handle) {
 		invalidate_mapping_pages(
-			dev->bdev_handle->bdev->bd_inode->i_mapping, 0, -1);
+			bdev_inode(dev->bdev_handle->bdev)->i_mapping, 0, -1);
 		bdev_release(dev->bdev_handle);
 	}
 
@@ -295,7 +295,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
 		goto err_free_block2mtd;
 	}
 
-	if ((long)bdev->bd_inode->i_size % erase_size) {
+	if ((long)bdev_inode(bdev)->i_size % erase_size) {
 		pr_err("erasesize must be a divisor of device size\n");
 		goto err_free_block2mtd;
 	}
@@ -313,7 +313,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
 
 	dev->mtd.name = name;
 
-	dev->mtd.size = bdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = bdev_inode(bdev)->i_size & PAGE_MASK;
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;
-- 
2.39.2


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

* [PATCH block/for-next v2 05/16] s390/dasd: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (3 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 04/16] mtd: block2mtd: " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 06/16] scsicam: " Yu Kuai
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/s390/block/dasd_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 61b9675e2a67..a34554ace310 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -221,7 +221,7 @@ dasd_format(struct dasd_block *block, struct format_data_t *fdata)
 	 * enabling the device later.
 	 */
 	if (fdata->start_unit == 0) {
-		block->gdp->part0->bd_inode->i_blkbits =
+		bdev_inode(block->gdp->part0)->i_blkbits =
 			blksize_bits(fdata->blksize);
 	}
 
-- 
2.39.2


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

* [PATCH block/for-next v2 06/16] scsicam: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (4 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 05/16] s390/dasd: " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 07/16] bcachefs: " Yu Kuai
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/scsi/scsicam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c
index e2c7d8ef205f..de40a5ef7d96 100644
--- a/drivers/scsi/scsicam.c
+++ b/drivers/scsi/scsicam.c
@@ -32,7 +32,7 @@
  */
 unsigned char *scsi_bios_ptable(struct block_device *dev)
 {
-	struct address_space *mapping = bdev_whole(dev)->bd_inode->i_mapping;
+	struct address_space *mapping = bdev_inode(bdev_whole(dev))->i_mapping;
 	unsigned char *res = NULL;
 	struct folio *folio;
 
-- 
2.39.2


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

* [PATCH block/for-next v2 07/16] bcachefs: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (5 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 06/16] scsicam: " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:49   ` Kent Overstreet
  2023-11-27  7:09   ` Damien Le Moal
  2023-11-27  6:21 ` [PATCH block/for-next v2 08/16] btrfs: " Yu Kuai
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 fs/bcachefs/util.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
index 2984b57b2958..fe7ccb3a3517 100644
--- a/fs/bcachefs/util.h
+++ b/fs/bcachefs/util.h
@@ -518,7 +518,7 @@ int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t);
 
 static inline sector_t bdev_sectors(struct block_device *bdev)
 {
-	return bdev->bd_inode->i_size >> 9;
+	return bdev_inode(bdev)->i_size >> 9;
 }
 
 #define closure_bio_submit(bio, cl)					\
-- 
2.39.2


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

* [PATCH block/for-next v2 08/16] btrfs: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (6 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 07/16] bcachefs: " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:21 ` [PATCH block/for-next v2 09/16] cramfs: " Yu Kuai
  2023-11-27  6:47 ` [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' " Al Viro
  9 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 fs/btrfs/disk-io.c | 6 +++---
 fs/btrfs/volumes.c | 4 ++--
 fs/btrfs/zoned.c   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 401ea09ae4b8..88b20cd4d046 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3653,7 +3653,7 @@ struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
 	struct btrfs_super_block *super;
 	struct page *page;
 	u64 bytenr, bytenr_orig;
-	struct address_space *mapping = bdev->bd_inode->i_mapping;
+	struct address_space *mapping = bdev_inode(bdev)->i_mapping;
 	int ret;
 
 	bytenr_orig = btrfs_sb_offset(copy_num);
@@ -3740,7 +3740,7 @@ static int write_dev_supers(struct btrfs_device *device,
 			    struct btrfs_super_block *sb, int max_mirrors)
 {
 	struct btrfs_fs_info *fs_info = device->fs_info;
-	struct address_space *mapping = device->bdev->bd_inode->i_mapping;
+	struct address_space *mapping = bdev_inode(device->bdev)->i_mapping;
 	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
 	int i;
 	int errors = 0;
@@ -3857,7 +3857,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors)
 		    device->commit_total_bytes)
 			break;
 
-		page = find_get_page(device->bdev->bd_inode->i_mapping,
+		page = find_get_page(bdev_inode(device->bdev)->i_mapping,
 				     bytenr >> PAGE_SHIFT);
 		if (!page) {
 			errors++;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c6f16625af51..bbf157cedab7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1257,8 +1257,8 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev
 		return ERR_PTR(-EINVAL);
 
 	/* pull in the page with our super */
-	page = read_cache_page_gfp(bdev->bd_inode->i_mapping, index, GFP_KERNEL);
-
+	page = read_cache_page_gfp(bdev_inode(bdev)->i_mapping, index,
+				   GFP_KERNEL);
 	if (IS_ERR(page))
 		return ERR_CAST(page);
 
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 188378ca19c7..a5f7f1458edf 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -120,7 +120,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
 		return -ENOENT;
 	} else if (full[0] && full[1]) {
 		/* Compare two super blocks */
-		struct address_space *mapping = bdev->bd_inode->i_mapping;
+		struct address_space *mapping = bdev_inode(bdev)->i_mapping;
 		struct page *page[BTRFS_NR_SB_LOG_ZONES];
 		struct btrfs_super_block *super[BTRFS_NR_SB_LOG_ZONES];
 		int i;
-- 
2.39.2


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

* [PATCH block/for-next v2 09/16] cramfs: use new helper to get inode from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (7 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 08/16] btrfs: " Yu Kuai
@ 2023-11-27  6:21 ` Yu Kuai
  2023-11-27  6:47 ` [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' " Al Viro
  9 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  6:21 UTC (permalink / raw)
  To: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Which is more efficiency, and also prepare to remove the field
'bd_inode' from block_device.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 fs/cramfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 60dbfa0f8805..e9ed1e24c9e4 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -183,7 +183,7 @@ static int next_buffer;
 static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
 				unsigned int len)
 {
-	struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
+	struct address_space *mapping = bdev_inode(sb->s_bdev)->i_mapping;
 	struct file_ra_state ra = {};
 	struct page *pages[BLKS_PER_BUF];
 	unsigned i, blocknr, buffer;
-- 
2.39.2


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

* Re: [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device
  2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
                   ` (8 preceding siblings ...)
  2023-11-27  6:21 ` [PATCH block/for-next v2 09/16] cramfs: " Yu Kuai
@ 2023-11-27  6:47 ` Al Viro
  9 siblings, 0 replies; 21+ messages in thread
From: Al Viro @ 2023-11-27  6:47 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, brauner,
	nico, xiang, chao, tytso, adilger.kernel, agruenba, jack,
	konishi.ryusuke, dchinner, linux, min15.li, yukuai3, dlemoal,
	willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun

On Mon, Nov 27, 2023 at 02:21:00PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Changes in v2:
>  - split different portions into different patches, as greg k-h
>  suggested.
>  - use container_of() instead of "bdev + 1" to get the address of
>  bd_inode in the new helper, as grep k-h suggested.

You might have misinterpreted gregkh - in your place I would rather
do a one-patch never-rebased branch (introduction of bdev_inode() in
form that returns bdev->bd_inode), with followup in your branch that
switches it to your variant.  Then conversions of ->bd_inode users,
to be either picked by individual filesystems of staying in your branch.
Any filesystem tree could merge from your never-rebased branch, after
which they could switch their ->bd_inode uses to the new helper, without
introducing any bisection hazards or interdependencies.
After the next -rc1, once all ->bd_inode users are gone from the tree -
remove the field.

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

* Re: [PATCH block/for-next v2 07/16] bcachefs: use new helper to get inode from block_device
  2023-11-27  6:21 ` [PATCH block/for-next v2 07/16] bcachefs: " Yu Kuai
@ 2023-11-27  6:49   ` Kent Overstreet
  2023-11-27  7:09   ` Damien Le Moal
  1 sibling, 0 replies; 21+ messages in thread
From: Kent Overstreet @ 2023-11-27  6:49 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun

On Mon, Nov 27, 2023 at 02:21:07PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Which is more efficiency, and also prepare to remove the field
> 'bd_inode' from block_device.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Acked-by: Kent Overstreet <kent.overstreet@linux.dev>

> ---
>  fs/bcachefs/util.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
> index 2984b57b2958..fe7ccb3a3517 100644
> --- a/fs/bcachefs/util.h
> +++ b/fs/bcachefs/util.h
> @@ -518,7 +518,7 @@ int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t);
>  
>  static inline sector_t bdev_sectors(struct block_device *bdev)
>  {
> -	return bdev->bd_inode->i_size >> 9;
> +	return bdev_inode(bdev)->i_size >> 9;
>  }
>  
>  #define closure_bio_submit(bio, cl)					\
> -- 
> 2.39.2
> 

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

* Re: [PATCH block/for-next v2 07/16] bcachefs: use new helper to get inode from block_device
  2023-11-27  6:21 ` [PATCH block/for-next v2 07/16] bcachefs: " Yu Kuai
  2023-11-27  6:49   ` Kent Overstreet
@ 2023-11-27  7:09   ` Damien Le Moal
  2023-11-27  7:24     ` Kent Overstreet
  1 sibling, 1 reply; 21+ messages in thread
From: Damien Le Moal @ 2023-11-27  7:09 UTC (permalink / raw)
  To: Yu Kuai, hch, ming.lei, axboe, roger.pau, colyli,
	kent.overstreet, joern, miquel.raynal, richard, vigneshr, sth,
	hoeppner, hca, gor, agordeev, jejb, martin.petersen, clm, josef,
	dsterba, viro, brauner, nico, xiang, chao, tytso, adilger.kernel,
	agruenba, jack, konishi.ryusuke, dchinner, linux, min15.li,
	yukuai3, willy, akpm, hare, p.raghav
  Cc: linux-block, linux-kernel, xen-devel, linux-bcache, linux-mtd,
	linux-s390, linux-scsi, linux-bcachefs, linux-btrfs,
	linux-fsdevel, linux-erofs, linux-ext4, gfs2, linux-nilfs,
	yi.zhang, yangerkun

On 11/27/23 15:21, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Which is more efficiency, and also prepare to remove the field
> 'bd_inode' from block_device.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  fs/bcachefs/util.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
> index 2984b57b2958..fe7ccb3a3517 100644
> --- a/fs/bcachefs/util.h
> +++ b/fs/bcachefs/util.h
> @@ -518,7 +518,7 @@ int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t);
>  
>  static inline sector_t bdev_sectors(struct block_device *bdev)
>  {
> -	return bdev->bd_inode->i_size >> 9;
> +	return bdev_inode(bdev)->i_size >> 9;

shouldn't this use i_size_read() ?

I missed the history with this but why not use bdev_nr_sectors() and delete this
helper ?

>  }
>  
>  #define closure_bio_submit(bio, cl)					\

-- 
Damien Le Moal
Western Digital Research


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

* Re: [PATCH block/for-next v2 01/16] block: add a new helper to get inode from block_device
  2023-11-27  6:21 ` [PATCH block/for-next v2 01/16] block: add a new helper to get inode " Yu Kuai
@ 2023-11-27  7:21   ` Christoph Hellwig
  2023-11-27 13:07     ` Yu Kuai
  0 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2023-11-27  7:21 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun

On Mon, Nov 27, 2023 at 02:21:01PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> block_devcie is allocated from bdev_alloc() by bdev_alloc_inode(), and
> currently block_device contains a pointer that point to the address of
> inode, while such inode is allocated together:

This is going the wrong way.  Nothing outside of core block layer code
should ever directly use the bdev inode.  We've been rather sloppy
and added a lot of direct reference to it, but they really need to
go away and be replaced with well defined high level operation on
struct block_device.  Once that is done we can remove the bd_inode
pointer, but replacing it with something that pokes even more deeply
into bdev internals is a bad idea.

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

* Re: [PATCH block/for-next v2 07/16] bcachefs: use new helper to get inode from block_device
  2023-11-27  7:09   ` Damien Le Moal
@ 2023-11-27  7:24     ` Kent Overstreet
  2023-11-27  7:52       ` Yu Kuai
  0 siblings, 1 reply; 21+ messages in thread
From: Kent Overstreet @ 2023-11-27  7:24 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: Yu Kuai, hch, ming.lei, axboe, roger.pau, colyli,
	kent.overstreet, joern, miquel.raynal, richard, vigneshr, sth,
	hoeppner, hca, gor, agordeev, jejb, martin.petersen, clm, josef,
	dsterba, viro, brauner, nico, xiang, chao, tytso, adilger.kernel,
	agruenba, jack, konishi.ryusuke, dchinner, linux, min15.li,
	yukuai3, willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun

On Mon, Nov 27, 2023 at 04:09:47PM +0900, Damien Le Moal wrote:
> On 11/27/23 15:21, Yu Kuai wrote:
> > From: Yu Kuai <yukuai3@huawei.com>
> > 
> > Which is more efficiency, and also prepare to remove the field
> > 'bd_inode' from block_device.
> > 
> > Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> > ---
> >  fs/bcachefs/util.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
> > index 2984b57b2958..fe7ccb3a3517 100644
> > --- a/fs/bcachefs/util.h
> > +++ b/fs/bcachefs/util.h
> > @@ -518,7 +518,7 @@ int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t);
> >  
> >  static inline sector_t bdev_sectors(struct block_device *bdev)
> >  {
> > -	return bdev->bd_inode->i_size >> 9;
> > +	return bdev_inode(bdev)->i_size >> 9;
> 
> shouldn't this use i_size_read() ?
> 
> I missed the history with this but why not use bdev_nr_sectors() and delete this
> helper ?

Actually, this helper seems to be dead code.

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

* Re: [PATCH block/for-next v2 07/16] bcachefs: use new helper to get inode from block_device
  2023-11-27  7:24     ` Kent Overstreet
@ 2023-11-27  7:52       ` Yu Kuai
  0 siblings, 0 replies; 21+ messages in thread
From: Yu Kuai @ 2023-11-27  7:52 UTC (permalink / raw)
  To: Kent Overstreet, Damien Le Moal
  Cc: Yu Kuai, hch, ming.lei, axboe, roger.pau, colyli,
	kent.overstreet, joern, miquel.raynal, richard, vigneshr, sth,
	hoeppner, hca, gor, agordeev, jejb, martin.petersen, clm, josef,
	dsterba, viro, brauner, nico, xiang, chao, tytso, adilger.kernel,
	agruenba, jack, konishi.ryusuke, dchinner, linux, min15.li,
	willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun, yukuai (C)

Hi,

在 2023/11/27 15:24, Kent Overstreet 写道:
> On Mon, Nov 27, 2023 at 04:09:47PM +0900, Damien Le Moal wrote:
>> On 11/27/23 15:21, Yu Kuai wrote:
>>> From: Yu Kuai <yukuai3@huawei.com>
>>>
>>> Which is more efficiency, and also prepare to remove the field
>>> 'bd_inode' from block_device.
>>>
>>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>>> ---
>>>   fs/bcachefs/util.h | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
>>> index 2984b57b2958..fe7ccb3a3517 100644
>>> --- a/fs/bcachefs/util.h
>>> +++ b/fs/bcachefs/util.h
>>> @@ -518,7 +518,7 @@ int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t);
>>>   
>>>   static inline sector_t bdev_sectors(struct block_device *bdev)
>>>   {
>>> -	return bdev->bd_inode->i_size >> 9;
>>> +	return bdev_inode(bdev)->i_size >> 9;
>>
>> shouldn't this use i_size_read() ?
>>
>> I missed the history with this but why not use bdev_nr_sectors() and delete this
>> helper ?
> 
> Actually, this helper seems to be dead code.

Yes, there is no caller of this helper, I'll remove this helper.

Thanks,
Kuai

> .
> 


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

* Re: [PATCH block/for-next v2 01/16] block: add a new helper to get inode from block_device
  2023-11-27  7:21   ` Christoph Hellwig
@ 2023-11-27 13:07     ` Yu Kuai
  2023-11-27 16:32       ` Christoph Hellwig
  0 siblings, 1 reply; 21+ messages in thread
From: Yu Kuai @ 2023-11-27 13:07 UTC (permalink / raw)
  To: Christoph Hellwig, Yu Kuai
  Cc: ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, dlemoal, willy,
	akpm, hare, p.raghav, linux-block, linux-kernel, xen-devel,
	linux-bcache, linux-mtd, linux-s390, linux-scsi, linux-bcachefs,
	linux-btrfs, linux-fsdevel, linux-erofs, linux-ext4, gfs2,
	linux-nilfs, yi.zhang, yangerkun, yukuai (C)

Hi,

在 2023/11/27 15:21, Christoph Hellwig 写道:
> On Mon, Nov 27, 2023 at 02:21:01PM +0800, Yu Kuai wrote:
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> block_devcie is allocated from bdev_alloc() by bdev_alloc_inode(), and
>> currently block_device contains a pointer that point to the address of
>> inode, while such inode is allocated together:
> 
> This is going the wrong way.  Nothing outside of core block layer code
> should ever directly use the bdev inode.  We've been rather sloppy
> and added a lot of direct reference to it, but they really need to
> go away and be replaced with well defined high level operation on
> struct block_device.  Once that is done we can remove the bd_inode
> pointer, but replacing it with something that pokes even more deeply
> into bdev internals is a bad idea.

Thanks for the advice, however, after collecting how other modules are
using bdev inode, I got two main questions:

1) Is't okay to add a new helper to pass in bdev for following apis?
If so, then almost all the fs and driver can avoid to access bd_inode
dirctly.

errseq_check(&bdev->bd_inode->i_mapping->wb_err, wb_err);
errseq_check_and_advance(&bdev->bd_inode->i_mapping->wb_err, &wb_err);
mapping_gfp_constraint(bdev->bd_inode->i_mapping, gfp);
i_size_read(bdev->bd_inode)
find_get_page(bdev->bd_inode->i_mapping, offset);
find_or_create_page(bdev->bd_inode->i_mapping, index, gfp);
read_cache_page_gfp(bdev->bd_inode->i_mapping, index, gfp);
invalidate_inode_pages2(bdev->bd_inode->i_mapping);
invalidate_inode_pages2_range(bdev->bd_inode->i_mapping, start, end);
read_mapping_folio(bdev->bd_inode->i_mapping, index, file);
read_mapping_page(bdev->bd_inode->i_mapping, index, file);
balance_dirty_pages_ratelimited(bdev->bd_inode->i_mapping)
file_ra_state_init(ra, bdev->bd_inode->i_mapping);
page_cache_sync_readahead(bdev->bd_inode->i_mapping, ra, file, index, 
req_count);
inode_to_bdi(bdev->bd_inode)

2) For the file fs/buffer.c, there are some special usage like
following that I don't think it's good to add a helper:

spin_lock(&bd_inode->i_mapping->private_lock);

Is't okay to move following apis from fs/buffer.c directly to
block/bdev.c?

__find_get_block
bdev_getblk

Thanks,
Kuai

> .
> 


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

* Re: [PATCH block/for-next v2 01/16] block: add a new helper to get inode from block_device
  2023-11-27 13:07     ` Yu Kuai
@ 2023-11-27 16:32       ` Christoph Hellwig
  2023-11-28  1:35         ` Yu Kuai
  0 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2023-11-27 16:32 UTC (permalink / raw)
  To: Yu Kuai
  Cc: Christoph Hellwig, ming.lei, axboe, roger.pau, colyli,
	kent.overstreet, joern, miquel.raynal, richard, vigneshr, sth,
	hoeppner, hca, gor, agordeev, jejb, martin.petersen, clm, josef,
	dsterba, viro, brauner, nico, xiang, chao, tytso, adilger.kernel,
	agruenba, jack, konishi.ryusuke, dchinner, linux, min15.li,
	dlemoal, willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun, yukuai (C)

On Mon, Nov 27, 2023 at 09:07:22PM +0800, Yu Kuai wrote:
> 1) Is't okay to add a new helper to pass in bdev for following apis?


For some we already have them (e.g. bdev_nr_bytes to read the bdev)
size, for some we need to add them.  The big thing that seems to
stick out is page cache API, and I think that is where we need to
define maintainable APIs for file systems and others to use the
block device page cache.  Probably only in folio versions and not
pages once if we're touching the code anyay

> 2) For the file fs/buffer.c, there are some special usage like
> following that I don't think it's good to add a helper:
> 
> spin_lock(&bd_inode->i_mapping->private_lock);
> 
> Is't okay to move following apis from fs/buffer.c directly to
> block/bdev.c?
> 
> __find_get_block
> bdev_getblk

I'm not sure moving is a good idea, but we might end up the
some kind of low-level access from buffer.c, be that special
helpers, a separate header or something else.  Let's sort out
the rest of the kernel first.


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

* Re: [PATCH block/for-next v2 01/16] block: add a new helper to get inode from block_device
  2023-11-27 16:32       ` Christoph Hellwig
@ 2023-11-28  1:35         ` Yu Kuai
  2023-11-28  5:48           ` Christoph Hellwig
  0 siblings, 1 reply; 21+ messages in thread
From: Yu Kuai @ 2023-11-28  1:35 UTC (permalink / raw)
  To: Christoph Hellwig, Yu Kuai
  Cc: ming.lei, axboe, roger.pau, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, dlemoal, willy,
	akpm, hare, p.raghav, linux-block, linux-kernel, xen-devel,
	linux-bcache, linux-mtd, linux-s390, linux-scsi, linux-bcachefs,
	linux-btrfs, linux-fsdevel, linux-erofs, linux-ext4, gfs2,
	linux-nilfs, yi.zhang, yangerkun, yukuai (C)

Hi,

在 2023/11/28 0:32, Christoph Hellwig 写道:
> On Mon, Nov 27, 2023 at 09:07:22PM +0800, Yu Kuai wrote:
>> 1) Is't okay to add a new helper to pass in bdev for following apis?
> 
> 
> For some we already have them (e.g. bdev_nr_bytes to read the bdev)
> size, for some we need to add them.  The big thing that seems to
> stick out is page cache API, and I think that is where we need to
> define maintainable APIs for file systems and others to use the
> block device page cache.  Probably only in folio versions and not
> pages once if we're touching the code anyay

Thanks for the advice! In case I'm understanding correctly, do you mean
that all other fs/drivers that is using pages versions can safely switch
to folio versions now?

By the way, my orginal idea was trying to add a new field 'bd_flags'
in block_devcie, and then add a new bit so that bio_check_ro() will
only warn once for each partition. Now that this patchset will be quite
complex, I'll add a new bool field 'bd_ro_warned' to fix the above
problem first, and then add 'bd_flags' once this patchset is done.

Thanks,
Kuai

> 
>> 2) For the file fs/buffer.c, there are some special usage like
>> following that I don't think it's good to add a helper:
>>
>> spin_lock(&bd_inode->i_mapping->private_lock);
>>
>> Is't okay to move following apis from fs/buffer.c directly to
>> block/bdev.c?
>>
>> __find_get_block
>> bdev_getblk
> 
> I'm not sure moving is a good idea, but we might end up the
> some kind of low-level access from buffer.c, be that special
> helpers, a separate header or something else.  Let's sort out
> the rest of the kernel first.
> 
> .
> 


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

* Re: [PATCH block/for-next v2 01/16] block: add a new helper to get inode from block_device
  2023-11-28  1:35         ` Yu Kuai
@ 2023-11-28  5:48           ` Christoph Hellwig
  0 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-11-28  5:48 UTC (permalink / raw)
  To: Yu Kuai
  Cc: Christoph Hellwig, ming.lei, axboe, roger.pau, colyli,
	kent.overstreet, joern, miquel.raynal, richard, vigneshr, sth,
	hoeppner, hca, gor, agordeev, jejb, martin.petersen, clm, josef,
	dsterba, viro, brauner, nico, xiang, chao, tytso, adilger.kernel,
	agruenba, jack, konishi.ryusuke, dchinner, linux, min15.li,
	dlemoal, willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun, yukuai (C)

On Tue, Nov 28, 2023 at 09:35:56AM +0800, Yu Kuai wrote:
> Thanks for the advice! In case I'm understanding correctly, do you mean
> that all other fs/drivers that is using pages versions can safely switch
> to folio versions now?

If you never allocate a high-order folio pages are identical to folios.
So yes, we can do folio based interfaces only, and also use that as
an opportunity to convert over the callers.

> By the way, my orginal idea was trying to add a new field 'bd_flags'
> in block_devcie, and then add a new bit so that bio_check_ro() will
> only warn once for each partition. Now that this patchset will be quite
> complex, I'll add a new bool field 'bd_ro_warned' to fix the above
> problem first, and then add 'bd_flags' once this patchset is done.

Yes, please do a minimal version if you can find space where the
rmw cycles don't cause damage to neighbouring fields.  Or just leave
the current set of warnings in if it's too hard.


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

* Re: [PATCH block/for-next v2 02/16] xen/blkback: use new helper to get inode from block_device
  2023-11-27  6:21 ` [PATCH block/for-next v2 02/16] xen/blkback: use " Yu Kuai
@ 2023-11-28 10:05   ` Roger Pau Monné
  0 siblings, 0 replies; 21+ messages in thread
From: Roger Pau Monné @ 2023-11-28 10:05 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, ming.lei, axboe, colyli, kent.overstreet, joern,
	miquel.raynal, richard, vigneshr, sth, hoeppner, hca, gor,
	agordeev, jejb, martin.petersen, clm, josef, dsterba, viro,
	brauner, nico, xiang, chao, tytso, adilger.kernel, agruenba,
	jack, konishi.ryusuke, dchinner, linux, min15.li, yukuai3,
	dlemoal, willy, akpm, hare, p.raghav, linux-block, linux-kernel,
	xen-devel, linux-bcache, linux-mtd, linux-s390, linux-scsi,
	linux-bcachefs, linux-btrfs, linux-fsdevel, linux-erofs,
	linux-ext4, gfs2, linux-nilfs, yi.zhang, yangerkun

On Mon, Nov 27, 2023 at 02:21:02PM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Which is more efficiency, and also prepare to remove the field
> 'bd_inode' from block_device.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.

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

end of thread, other threads:[~2023-11-28 10:05 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-27  6:21 [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' from block_device Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 01/16] block: add a new helper to get inode " Yu Kuai
2023-11-27  7:21   ` Christoph Hellwig
2023-11-27 13:07     ` Yu Kuai
2023-11-27 16:32       ` Christoph Hellwig
2023-11-28  1:35         ` Yu Kuai
2023-11-28  5:48           ` Christoph Hellwig
2023-11-27  6:21 ` [PATCH block/for-next v2 02/16] xen/blkback: use " Yu Kuai
2023-11-28 10:05   ` Roger Pau Monné
2023-11-27  6:21 ` [PATCH block/for-next v2 03/16] bcache: " Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 04/16] mtd: block2mtd: " Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 05/16] s390/dasd: " Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 06/16] scsicam: " Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 07/16] bcachefs: " Yu Kuai
2023-11-27  6:49   ` Kent Overstreet
2023-11-27  7:09   ` Damien Le Moal
2023-11-27  7:24     ` Kent Overstreet
2023-11-27  7:52       ` Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 08/16] btrfs: " Yu Kuai
2023-11-27  6:21 ` [PATCH block/for-next v2 09/16] cramfs: " Yu Kuai
2023-11-27  6:47 ` [PATCH block/for-next v2 00/16] block: remove field 'bd_inode' " Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).