[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231211140552.973290-2-yukuai1@huaweicloud.com>
Date: Mon, 11 Dec 2023 22:05:35 +0800
From: Yu Kuai <yukuai1@...weicloud.com>
To: axboe@...nel.dk,
roger.pau@...rix.com,
colyli@...e.de,
kent.overstreet@...il.com,
joern@...ybastard.org,
miquel.raynal@...tlin.com,
richard@....at,
vigneshr@...com,
sth@...ux.ibm.com,
hoeppner@...ux.ibm.com,
hca@...ux.ibm.com,
gor@...ux.ibm.com,
agordeev@...ux.ibm.com,
jejb@...ux.ibm.com,
martin.petersen@...cle.com,
clm@...com,
josef@...icpanda.com,
dsterba@...e.com,
viro@...iv.linux.org.uk,
brauner@...nel.org,
nico@...xnic.net,
xiang@...nel.org,
chao@...nel.org,
tytso@....edu,
adilger.kernel@...ger.ca,
agruenba@...hat.com,
jack@...e.com,
konishi.ryusuke@...il.com,
willy@...radead.org,
akpm@...ux-foundation.org,
p.raghav@...sung.com,
hare@...e.de
Cc: linux-block@...r.kernel.org,
linux-kernel@...r.kernel.org,
xen-devel@...ts.xenproject.org,
linux-bcache@...r.kernel.org,
linux-mtd@...ts.infradead.org,
linux-s390@...r.kernel.org,
linux-scsi@...r.kernel.org,
linux-bcachefs@...r.kernel.org,
linux-btrfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-erofs@...ts.ozlabs.org,
linux-ext4@...r.kernel.org,
gfs2@...ts.linux.dev,
linux-nilfs@...r.kernel.org,
yukuai3@...wei.com,
yukuai1@...weicloud.com,
yi.zhang@...wei.com,
yangerkun@...wei.com
Subject: [PATCH RFC v2 for-6.8/block 01/18] block: add some bdev apis
From: Yu Kuai <yukuai3@...wei.com>
Those apis will be used for other modules, so that bd_inode won't be
accessed directly from other modules.
Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
block/bdev.c | 70 ++++++++++++++++++++++++++++++++++++++++++
block/blk.h | 2 --
include/linux/blkdev.h | 17 ++++++++++
3 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 750aec178b6a..9a469753eb4b 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -89,6 +89,13 @@ void invalidate_bdev(struct block_device *bdev)
}
EXPORT_SYMBOL(invalidate_bdev);
+void invalidate_bdev_range(struct block_device *bdev, pgoff_t start,
+ pgoff_t end)
+{
+ invalidate_mapping_pages(bdev->bd_inode->i_mapping, start, end);
+}
+EXPORT_SYMBOL_GPL(invalidate_bdev_range);
+
/*
* Drop all buffers & page cache for given bdev range. This function bails
* with error if bdev has other exclusive owner (such as filesystem).
@@ -121,6 +128,7 @@ int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode,
lstart >> PAGE_SHIFT,
lend >> PAGE_SHIFT);
}
+EXPORT_SYMBOL_GPL(truncate_bdev_range);
static void set_init_blocksize(struct block_device *bdev)
{
@@ -1102,3 +1110,65 @@ void bdev_statx_dioalign(struct inode *inode, struct kstat *stat)
blkdev_put_no_open(bdev);
}
+
+struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos)
+{
+ return mapping_read_folio_gfp(bdev->bd_inode->i_mapping,
+ pos >> PAGE_SHIFT, GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(bdev_read_folio);
+
+struct folio *__bdev_get_folio(struct block_device *bdev, loff_t pos,
+ fgf_t fgp_flags, gfp_t gfp)
+{
+ return __filemap_get_folio(bdev->bd_inode->i_mapping, pos >> PAGE_SHIFT,
+ fgp_flags, gfp);
+}
+EXPORT_SYMBOL_GPL(__bdev_get_folio);
+
+int bdev_wb_err_check(struct block_device *bdev, errseq_t since)
+{
+ return errseq_check(&bdev->bd_inode->i_mapping->wb_err, since);
+}
+EXPORT_SYMBOL_GPL(bdev_wb_err_check);
+
+int bdev_wb_err_check_and_advance(struct block_device *bdev, errseq_t *since)
+{
+ return errseq_check_and_advance(&bdev->bd_inode->i_mapping->wb_err,
+ since);
+}
+EXPORT_SYMBOL_GPL(bdev_wb_err_check_and_advance);
+
+void bdev_balance_dirty_pages_ratelimited(struct block_device *bdev)
+{
+ return balance_dirty_pages_ratelimited(bdev->bd_inode->i_mapping);
+}
+EXPORT_SYMBOL_GPL(bdev_balance_dirty_pages_ratelimited);
+
+void bdev_sync_readahead(struct block_device *bdev, struct file_ra_state *ra,
+ struct file *file, pgoff_t index,
+ unsigned long req_count)
+{
+ struct file_ra_state tmp_ra = {};
+
+ if (!ra) {
+ ra = &tmp_ra;
+ file_ra_state_init(ra, bdev->bd_inode->i_mapping);
+ }
+ page_cache_sync_readahead(bdev->bd_inode->i_mapping, ra, file, index,
+ req_count);
+}
+EXPORT_SYMBOL_GPL(bdev_sync_readahead);
+
+void bdev_attach_wb(struct block_device *bdev)
+{
+ inode_attach_wb(bdev->bd_inode, NULL);
+}
+EXPORT_SYMBOL_GPL(bdev_attach_wb);
+
+void bdev_associated_mapping(struct block_device *bdev,
+ struct address_space *mapping)
+{
+ mapping->host = bdev->bd_inode;
+}
+EXPORT_SYMBOL_GPL(bdev_associated_mapping);
diff --git a/block/blk.h b/block/blk.h
index 08a358bc0919..da4becd4f7e9 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -467,8 +467,6 @@ extern struct device_attribute dev_attr_events_poll_msecs;
extern struct attribute_group blk_trace_attr_group;
blk_mode_t file_to_blk_mode(struct file *file);
-int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode,
- loff_t lstart, loff_t lend);
long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg);
long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 17c0a7d0d319..d2453424a9eb 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -24,6 +24,7 @@
#include <linux/sbitmap.h>
#include <linux/uuid.h>
#include <linux/xarray.h>
+#include <linux/pagemap.h>
struct module;
struct request_queue;
@@ -1502,6 +1503,22 @@ struct block_device *blkdev_get_no_open(dev_t dev);
void blkdev_put_no_open(struct block_device *bdev);
struct block_device *I_BDEV(struct inode *inode);
+void invalidate_bdev_range(struct block_device *bdev, pgoff_t start,
+ pgoff_t end);
+int truncate_bdev_range(struct block_device *bdev, blk_mode_t mode,
+ loff_t lstart, loff_t lend);
+struct folio *bdev_read_folio(struct block_device *bdev, loff_t pos);
+struct folio *__bdev_get_folio(struct block_device *bdev, loff_t pos,
+ fgf_t fgp_flags, gfp_t gfp);
+int bdev_wb_err_check(struct block_device *bdev, errseq_t since);
+int bdev_wb_err_check_and_advance(struct block_device *bdev, errseq_t *since);
+void bdev_balance_dirty_pages_ratelimited(struct block_device *bdev);
+void bdev_sync_readahead(struct block_device *bdev, struct file_ra_state *ra,
+ struct file *file, pgoff_t index,
+ unsigned long req_count);
+void bdev_attach_wb(struct block_device *bdev);
+void bdev_associated_mapping(struct block_device *bdev,
+ struct address_space *mapping);
#ifdef CONFIG_BLOCK
void invalidate_bdev(struct block_device *bdev);
--
2.39.2
Powered by blists - more mailing lists