erofs: using iomap mechanisms in fileio for reading unencoded data
PATCH 1/1 erofs: using iomap mechanisms in fileio for reading unencoded data
In EROFS file-backend mount mode, the whole folio may trigger multiple backend file I/Os. The original read process mainly uses the @erofs_fileio_scan_folio, which employs a custom iteration mechanism on the folio and then to handle the I/Os. It requires complex mechanisms to manage the synchronization of multiple split file I/Os. This way couples the iteration operation with the data reading operation. We can decouple these two steps by using the iomap mechanism, thereby simplifying the implementation of the read process.
--- fs/erofs/data.c | 11 +-- fs/erofs/fileio.c | 174 ++++++++++++++++++++++---------------------- fs/erofs/internal.h | 8 ++ 3 files changed, 99 insertions(+), 94 deletions(-)
fs/erofs/data.c +4 -7
@@ -267,12 +267,6 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)folio_end_read (folio, !(v &BIT (EROFS_ONLINEFOLIO_EIO ))); } -struct erofs_iomap_iter_ctx { -struct page *page; -void *base; -struct inode *realinode; -}; -static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {
@@ -313,6 +307,9 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,else iomap->bdev = mdev.m_bdev; iomap->addr = mdev.m_dif->fsoff + mdev.m_pa; +/* keep device context when mapping to device */ +if (ctx) + ctx->dif = mdev.m_dif;if (flags &IOMAP_DAX ) iomap->addr += mdev.m_dif->dax_part_off; }
@@ -357,7 +354,7 @@ static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length,return written; } -static const struct iomap_ops erofs_iomap_ops = { +const struct iomap_ops erofs_iomap_ops = { .iomap_begin = erofs_iomap_begin, .iomap_end = erofs_iomap_end, };
fs/erofs/fileio.c +87 -87
212 lines not on this page · raw message
fs/erofs/internal.h +8 -0
@@ -411,6 +411,13 @@ struct erofs_map_dev {unsigned int m_deviceid; }; +struct erofs_iomap_iter_ctx { +struct page *page; +void *base; +struct inode *realinode; +struct erofs_device_info *dif; +}; +extern const struct super_operations erofs_sops;extern const struct address_space_operations erofs_aops;
@@ -427,6 +434,7 @@ extern const struct file_operations erofs_file_fops;extern const struct file_operations erofs_dir_fops;extern const struct file_operations erofs_ishare_fops; +extern const struct iomap_ops erofs_iomap_ops;extern const struct iomap_ops z_erofs_iomap_report_ops;/* flags for erofs_fscache_register_cookie() */
Signature · 1 line
2.22.0
PATCH v2 1/1 erofs: using iomap mechanisms in fileio for reading unencoded data
In EROFS file-backend mount mode, the whole folio may trigger multiple backend file I/Os. The original read process mainly uses the @erofs_fileio_scan_folio, which employs a custom iteration mechanism on the folio and then to handle the I/Os. It requires complex mechanisms to manage the synchronization of multiple split file I/Os. This way couples the iteration operation with the data reading operation. We can decouple these two steps by using the iomap mechanism, thereby simplifying the implementation of the read process.
---
Changes from v1:
- add folio release/invalidate hook.
--- fs/erofs/data.c | 11 +-- fs/erofs/fileio.c | 176 ++++++++++++++++++++++---------------------- fs/erofs/internal.h | 8 ++ 3 files changed, 101 insertions(+), 94 deletions(-)
fs/erofs/data.c +4 -7
@@ -267,12 +267,6 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)folio_end_read (folio, !(v &BIT (EROFS_ONLINEFOLIO_EIO ))); } -struct erofs_iomap_iter_ctx { -struct page *page; -void *base; -struct inode *realinode; -}; -static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {
@@ -313,6 +307,9 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,else iomap->bdev = mdev.m_bdev; iomap->addr = mdev.m_dif->fsoff + mdev.m_pa; +/* keep device context when mapping to device */ +if (ctx) + ctx->dif = mdev.m_dif;if (flags &IOMAP_DAX ) iomap->addr += mdev.m_dif->dax_part_off; }
@@ -357,7 +354,7 @@ static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length,return written; } -static const struct iomap_ops erofs_iomap_ops = { +const struct iomap_ops erofs_iomap_ops = { .iomap_begin = erofs_iomap_begin, .iomap_end = erofs_iomap_end, };
fs/erofs/fileio.c +89 -87
217 lines not on this page · raw message
fs/erofs/internal.h +8 -0
@@ -411,6 +411,13 @@ struct erofs_map_dev {unsigned int m_deviceid; }; +struct erofs_iomap_iter_ctx { +struct page *page; +void *base; +struct inode *realinode; +struct erofs_device_info *dif; +}; +extern const struct super_operations erofs_sops;extern const struct address_space_operations erofs_aops;
@@ -427,6 +434,7 @@ extern const struct file_operations erofs_file_fops;extern const struct file_operations erofs_dir_fops;extern const struct file_operations erofs_ishare_fops; +extern const struct iomap_ops erofs_iomap_ops;extern const struct iomap_ops z_erofs_iomap_report_ops;/* flags for erofs_fscache_register_cookie() */
Signature · 1 line
2.22.0