Message ID | 20240222124555.2049140-19-yukuai1@huaweicloud.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fs & block: remove bdev->bd_inode | expand |
Can you split this in a block layer patch adding the helper and scsi
one using it?
Otherwise looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
Hi, 在 2024/03/18 5:36, Christoph Hellwig 写道: > Can you split this in a block layer patch adding the helper and scsi > one using it? Of course, if you don't mind, I'll add your reviewed tag as well, since there will be no functional change. Thanks, Kuai > > Otherwise looks good: > > Reviewed-by: Christoph Hellwig <hch@lst.de> > . >
On Thu 22-02-24 20:45:54, Yu Kuai wrote: > From: Yu Kuai <yukuai3@huawei.com> > > scsi_bios_ptable() is reading without opening disk as file, factor out > a helper to read into block device page cache to prevent access bd_inode > directly from scsi. > > Signed-off-by: Yu Kuai <yukuai3@huawei.com> Looks good to me. Either before or after split feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza > --- > block/bdev.c | 19 +++++++++++++++++++ > drivers/scsi/scsicam.c | 3 +-- > include/linux/blkdev.h | 1 + > 3 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/block/bdev.c b/block/bdev.c > index 60a1479eae83..b7af04d34af2 100644 > --- a/block/bdev.c > +++ b/block/bdev.c > @@ -1211,6 +1211,25 @@ unsigned int block_size(struct block_device *bdev) > } > EXPORT_SYMBOL_GPL(block_size); > > +/** > + * bdev_read_folio - Read into block device page cache. > + * @bdev: the block device which holds the cache to read. > + * @pos: the offset that allocated folio will contain. > + * > + * Read one page into the block device page cache. If it succeeds, the folio > + * returned will contain @pos; > + * > + * This is only used for scsi_bios_ptable(), the bdev is not opened as files. > + * > + * Return: Uptodate folio on success, ERR_PTR() on failure. > + */ > +struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos) > +{ > + return mapping_read_folio_gfp(bdev_mapping(bdev), > + pos >> PAGE_SHIFT, GFP_KERNEL); > +} > +EXPORT_SYMBOL_GPL(bdev_read_folio); > + > static int __init setup_bdev_allow_write_mounted(char *str) > { > if (kstrtobool(str, &bdev_allow_write_mounted)) > diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c > index e2c7d8ef205f..1c99b964a0eb 100644 > --- a/drivers/scsi/scsicam.c > +++ b/drivers/scsi/scsicam.c > @@ -32,11 +32,10 @@ > */ > unsigned char *scsi_bios_ptable(struct block_device *dev) > { > - struct address_space *mapping = bdev_whole(dev)->bd_inode->i_mapping; > unsigned char *res = NULL; > struct folio *folio; > > - folio = read_mapping_folio(mapping, 0, NULL); > + folio = bdev_read_folio(bdev_whole(dev), 0); > if (IS_ERR(folio)) > return NULL; > > diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h > index c510f334c84f..3fb02e3a527a 100644 > --- a/include/linux/blkdev.h > +++ b/include/linux/blkdev.h > @@ -1514,6 +1514,7 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, > int bd_prepare_to_claim(struct block_device *bdev, void *holder, > const struct blk_holder_ops *hops); > void bd_abort_claiming(struct block_device *bdev, void *holder); > +struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos); > > /* just for blk-cgroup, don't use elsewhere */ > struct block_device *blkdev_get_no_open(dev_t dev); > -- > 2.39.2 >
diff --git a/block/bdev.c b/block/bdev.c index 60a1479eae83..b7af04d34af2 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1211,6 +1211,25 @@ unsigned int block_size(struct block_device *bdev) } EXPORT_SYMBOL_GPL(block_size); +/** + * bdev_read_folio - Read into block device page cache. + * @bdev: the block device which holds the cache to read. + * @pos: the offset that allocated folio will contain. + * + * Read one page into the block device page cache. If it succeeds, the folio + * returned will contain @pos; + * + * This is only used for scsi_bios_ptable(), the bdev is not opened as files. + * + * Return: Uptodate folio on success, ERR_PTR() on failure. + */ +struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos) +{ + return mapping_read_folio_gfp(bdev_mapping(bdev), + pos >> PAGE_SHIFT, GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(bdev_read_folio); + static int __init setup_bdev_allow_write_mounted(char *str) { if (kstrtobool(str, &bdev_allow_write_mounted)) diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c index e2c7d8ef205f..1c99b964a0eb 100644 --- a/drivers/scsi/scsicam.c +++ b/drivers/scsi/scsicam.c @@ -32,11 +32,10 @@ */ unsigned char *scsi_bios_ptable(struct block_device *dev) { - struct address_space *mapping = bdev_whole(dev)->bd_inode->i_mapping; unsigned char *res = NULL; struct folio *folio; - folio = read_mapping_folio(mapping, 0, NULL); + folio = bdev_read_folio(bdev_whole(dev), 0); if (IS_ERR(folio)) return NULL; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c510f334c84f..3fb02e3a527a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1514,6 +1514,7 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, int bd_prepare_to_claim(struct block_device *bdev, void *holder, const struct blk_holder_ops *hops); void bd_abort_claiming(struct block_device *bdev, void *holder); +struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos); /* just for blk-cgroup, don't use elsewhere */ struct block_device *blkdev_get_no_open(dev_t dev);