erofs: add file-backed mount support
Subsystems (2)
PATCH v2 1/4 erofs: add file-backed mount support
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]
- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]
---
v2:
- should use kill_anon_super();
- add O_LARGEFILE to support large files.
fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)
fs/erofs/Kconfig +17 -0
@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N. +config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default y + help + This allows EROFS to use filesystem image files directly, without + the intercession of loopback block devices or likewise. It is + particularly useful for container images with numerous blobs and + other sandboxes, where loop devices behave intricately. It can also + be used to simplify error-prone lifetime management of unnecessary + virtual block devices. + + Note that this feature, along with ongoing fanotify pre-content + hooks, will eventually replace "EROFS over fscache." + + If you don't want to enable this feature, say N. + config EROFS_FS_ZIP bool "EROFS Data Compression Support" depends on EROFS_FS
fs/erofs/data.c +21 -14
@@ -59,8 +59,12 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,void erofs_init_metabuf (struct erofs_buf *buf,struct super_block *sb) { -if (erofs_is_fscache_mode (sb)) - buf->mapping =EROFS_SB (sb)->s_fscache->inode->i_mapping; +struct erofs_sb_info *sbi =EROFS_SB (sb); + +if (erofs_is_fileio_mode (sbi)) + buf->mapping =file_inode (sbi->fdev)->i_mapping; +else if (erofs_is_fscache_mode (sb)) + buf->mapping = sbi->s_fscache->inode->i_mapping;else buf->mapping = sb->s_bdev->bd_mapping; }
@@ -189,10 +193,22 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)return err; } +static void erofs_fill_from_devinfo (struct erofs_map_dev *map, +struct erofs_device_info *dif) +{ + map->m_bdev =NULL ; +if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); + map->m_daxdev = dif->dax_dev; + map->m_dax_part_off = dif->dax_part_off; + map->m_fscache = dif->fscache; +} +int erofs_map_dev (struct super_block *sb,struct erofs_map_dev *map) {struct erofs_dev_context *devs =EROFS_SB (sb)->devs;struct erofs_device_info *dif; +erofs_off_t startoff, length;int id; map->m_bdev = sb->s_bdev;
@@ -212,29 +228,20 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)up_read (&devs->rwsem);return 0 ; } - map->m_bdev = dif->bdev_file ?file_bdev (dif->bdev_file) :NULL ; - map->m_daxdev = dif->dax_dev; - map->m_dax_part_off = dif->dax_part_off; - map->m_fscache = dif->fscache; +erofs_fill_from_devinfo (map, dif);up_read (&devs->rwsem); }else if (devs->extra_devices && !devs->flatdev) {down_read (&devs->rwsem);idr_for_each_entry (&devs->tree, dif, id) { -erofs_off_t startoff, length; -if (!dif->mapped_blkaddr)continue ; + startoff =erofs_pos (sb, dif->mapped_blkaddr); length =erofs_pos (sb, dif->blocks); -if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; - map->m_bdev = dif->bdev_file ? -file_bdev (dif->bdev_file) :NULL ; - map->m_daxdev = dif->dax_dev; - map->m_dax_part_off = dif->dax_part_off; - map->m_fscache = dif->fscache; +erofs_fill_from_devinfo (map, dif);break ; } }
fs/erofs/inode.c +4 -1
@@ -258,7 +258,10 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { +/* XXX: data I/Os will be implemented in the following patches */ + err = -EOPNOTSUPP ; + }else if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP DO_ONCE_LITE_IF(inode->i_blkbits != PAGE_SHIFT, erofs_info, inode->i_sb,
fs/erofs/internal.h +9 -2
@@ -49,7 +49,7 @@ typedef u32 erofs_blk_t;struct erofs_device_info {char *path;struct erofs_fscache *fscache; -struct file *bdev_file; +struct file *file;struct dax_device *dax_dev;u64 dax_part_off;
@@ -130,6 +130,7 @@ struct erofs_sb_info {struct erofs_sb_lz4_info lz4;#endif /* CONFIG_EROFS_FS_ZIP */ +struct file *fdev;struct inode *packed_inode;struct erofs_dev_context *devs;struct dax_device *dax_dev;
@@ -190,9 +191,15 @@ struct erofs_sb_info {#define set_opt (opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)#define test_opt (opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option) +static inline bool erofs_is_fileio_mode (struct erofs_sb_info *sbi) +{ +return IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) && sbi->fdev; +} +static inline bool erofs_is_fscache_mode (struct super_block *sb) { -return IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && !sb->s_bdev; +return IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && + !erofs_is_fileio_mode (EROFS_SB (sb)) && !sb->s_bdev; }enum {
fs/erofs/super.c +49 -27
143 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 2/4 erofs: support unencoded inodes for fileio
Since EROFS only needs to handle read requests in simple contexts, Just directly use vfs_iocb_iter_read() for data I/Os.
---
v2:
- fix redundant refcount which cause hanging on chunked inodes.
fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 +++++++++++- fs/erofs/fileio.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++--------- 6 files changed, 251 insertions(+), 51 deletions(-) create mode 100644 fs/erofs/fileio.c
fs/erofs/Makefile +1 -0
@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o
fs/erofs/data.c +46 -4
80 lines not on this page · raw message
fs/erofs/fileio.c new file +181 -0
181 lines not on this page · raw message
fs/erofs/inode.c +12 -5
@@ -258,11 +258,14 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { -/* XXX: data I/Os will be implemented in the following patches */ - err = -EOPNOTSUPP ; - }else if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { + err = -EOPNOTSUPP ; + goto out_unlock; + } +#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );
@@ -271,10 +274,14 @@ static int erofs_fill_inode(struct inode *inode) err = -EOPNOTSUPP ;#endif }else { - inode->i_mapping->a_ops = &erofs_raw_access_aops; + inode->i_mapping->a_ops = &erofs_aops;#ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode (inode->i_sb)) inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) + inode->i_mapping->a_ops = &erofs_fileio_aops;#endif } out_unlock:
fs/erofs/internal.h +6 -1
@@ -372,6 +372,7 @@ struct erofs_map_dev {struct erofs_fscache *m_fscache;struct block_device *m_bdev;struct dax_device *m_daxdev; +struct file *m_fp;u64 m_dax_part_off;erofs_off_t m_pa;
@@ -380,7 +381,8 @@ struct erofs_map_dev {extern const struct super_operations erofs_sops; -extern const struct address_space_operations erofs_raw_access_aops; +extern const struct address_space_operations erofs_aops; +extern const struct address_space_operations erofs_fileio_aops;extern const struct address_space_operations z_erofs_aops;extern const struct address_space_operations erofs_fscache_access_aops;
@@ -411,6 +413,9 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);int erofs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len);int erofs_map_blocks (struct inode *inode,struct erofs_map_blocks *map); +void erofs_onlinefolio_init (struct folio *folio); +void erofs_onlinefolio_split (struct folio *folio); +void erofs_onlinefolio_end (struct folio *folio,int err);struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid); int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask,
fs/erofs/zdata.c +5 -41
82 lines not on this page · raw message
Signature · 1 line
2.43.5
Sandeep Dhavale
reviewerRe: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
Quoted 165 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Signed-off-by Gao Xiang <[email protected]>---
v2:
- fix redundant refcount which cause hanging on chunked inodes.fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 +++++++++++- fs/erofs/fileio.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++--------- 6 files changed, 251 insertions(+), 51 deletions(-) create mode 100644 fs/erofs/fileio.cfs/erofs/Makefile +1
-0@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/data.c +46
-4@@ -132,7 +132,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)if (map->m_la >= inode->i_size) {/* leave out-of-bound access unmapped */ map->m_flags =0 ; - map->m_plen =0 ; + map->m_plen = map->m_llen; goto out; }@@ -197,8 +197,13 @@ static void erofs_fill_from_devinfo(struct erofs_map_dev *map, struct erofs_device_info *dif) { map->m_bdev =NULL ; -if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) - map->m_bdev =file_bdev (dif->file); + map->m_fp =NULL ; +if (dif->file) { +if (S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); +else + map->m_fp = dif->file; + } map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache;@@ -215,6 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) map->m_daxdev =EROFS_SB (sb)->dax_dev; map->m_dax_part_off =EROFS_SB (sb)->dax_part_off; map->m_fscache =EROFS_SB (sb)->s_fscache; + map->m_fp =EROFS_SB (sb)->fdev;if (map->m_deviceid) {down_read (&devs->rwsem);@@ -250,6 +256,42 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)return 0 ; } +/* +* bit 30: I/O error occurred on this folio +* bit 0 - 29: remaining parts to complete this folio +*/ +#define EROFS_ONLINEFOLIO_EIO (1 << 30) + +void erofs_onlinefolio_init (struct folio *folio) +{ +union { +atomic_t o; +void *v; + } u = { .o =ATOMIC_INIT (1 ) }; + + folio->private = u.v;/* valid only if file-backed folio is locked */ +} + +void erofs_onlinefolio_split (struct folio *folio) +{ +atomic_inc ((atomic_t *)&folio->private); +} + +void erofs_onlinefolio_end (struct folio *folio,int err) +{ +int orig, v; + +do { + orig =atomic_read ((atomic_t *)&folio->private); + v = (orig -1 ) | (err ?EROFS_ONLINEFOLIO_EIO :0 ); + }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); + +if (v & ~EROFS_ONLINEFOLIO_EIO ) +return ; + folio->private =0 ; +folio_end_read (folio, !(v &EROFS_ONLINEFOLIO_EIO )); +} +static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {@@ -399,7 +441,7 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) }/* for uncompressed (aligned) files and raw access for other files */ -const struct address_space_operations erofs_raw_access_aops = { +const struct address_space_operations erofs_aops = { .read_folio = erofs_read_folio, .readahead = erofs_readahead, .bmap = erofs_bmap,fs/erofs/fileio.c new file +42
-0@@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#include "internal.h" +#include <trace/events/erofs.h> + +struct erofs_fileio_rq { +struct bio_vec bvecs[BIO_MAX_VECS ]; +struct bio bio; +struct kiocb iocb; +}; + +struct erofs_fileio { +struct erofs_map_blocks map; +struct erofs_map_dev dev; +struct erofs_fileio_rq *rq; +}; + +static void erofs_fileio_ki_complete (struct kiocb *iocb,long ret) +{ +struct erofs_fileio_rq *rq = + container_of(iocb, struct erofs_fileio_rq, iocb); +struct folio_iter fi; + +DBG_BUGON (rq->bio.bi_end_io); +if (ret >0 ) { +if (ret != rq->bio.bi_iter.bi_size) { +bio_advance (&rq->bio, ret); +zero_fill_bio (&rq->bio); + } + ret =0 ; + } +bio_for_each_folio_all (fi, &rq->bio) { +DBG_BUGON (folio_test_uptodate (fi.folio)); +erofs_onlinefolio_end (fi.folio, ret); + } +kfree (rq); +} + +static void erofs_fileio_rq_submit (struct erofs_fileio_rq *rq) +{
fs/erofs/fileio.c line 52
Quoted 10 lines
fs/erofs/fileio.c new file +10
-0+struct iov_iter iter; +int ret; + +if (!rq) +return ; + rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector <<9 ; + rq->iocb.ki_ioprio =get_current_ioprio (); + rq->iocb.ki_complete = erofs_fileio_ki_complete; + rq->iocb.ki_flags = (rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) ? +IOCB_DIRECT :0 ;
Hi Gao,
Does this mean, direct IO by default if the backing file supports it (technically filesystem where image/backing file reside)?
Thanks,
Sandeep.
Quoted 295 lines
fs/erofs/fileio.c new file +129
-0+iov_iter_bvec (&iter,ITER_DEST , rq->bvecs, rq->bio.bi_vcnt, + rq->bio.bi_iter.bi_size); + ret =vfs_iocb_iter_read (rq->iocb.ki_filp, &rq->iocb, &iter); +if (ret != -EIOCBQUEUED ) +erofs_fileio_ki_complete (&rq->iocb, ret); +} + +static struct erofs_fileio_rq *erofs_fileio_rq_alloc (struct erofs_map_dev *mdev) +{ +struct erofs_fileio_rq *rq =kzalloc (sizeof (*rq),GFP_KERNEL ); + +if (!rq) +return NULL ; +bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); + rq->iocb.ki_filp = mdev->m_fp; +return rq; +} + +static int erofs_fileio_scan_folio (struct erofs_fileio *io,struct folio *folio) +{ +struct inode *inode =folio_inode (folio); +struct erofs_map_blocks *map = &io->map; +unsigned int cur =0 , end =folio_size (folio), len, attached =0 ; +loff_t pos =folio_pos (folio), ofs; +struct iov_iter iter; +struct bio_vec bv; +int err =0 ; + +erofs_onlinefolio_init (folio); +while (cur < end) { +if (!in_range (pos + cur, map->m_la, map->m_llen)) { + map->m_la = pos + cur; + map->m_llen = end - cur; + err =erofs_map_blocks (inode, map); +if (err) +break ; + } + + ofs =folio_pos (folio) + cur - map->m_la; + len =min_t (loff_t, map->m_llen - ofs, end - cur); +if (map->m_flags &EROFS_MAP_META ) { +struct erofs_buf buf = __EROFS_BUF_INITIALIZER; +void *src; + + src =erofs_read_metabuf (&buf, inode->i_sb, + map->m_pa + ofs,EROFS_KMAP ); +if (IS_ERR (src)) { + err =PTR_ERR (src); +break ; + } +bvec_set_folio (&bv, folio, len, cur); +iov_iter_bvec (&iter,ITER_DEST , &bv,1 , len); +if (copy_to_iter (src, len, &iter) != len) { +erofs_put_metabuf (&buf); + err = -EIO ; +break ; + } +erofs_put_metabuf (&buf); + }else if (!(map->m_flags &EROFS_MAP_MAPPED )) { +folio_zero_segment (folio, cur, cur + len); + }else { +if (io->rq && (map->m_pa + ofs != io->dev.m_pa || + map->m_deviceid != io->dev.m_deviceid)) { +io_retry: +erofs_fileio_rq_submit (io->rq); + io->rq =NULL ; + } + +if (!io->rq) { + io->dev = (struct erofs_map_dev ) { + .m_pa = io->map.m_pa + ofs, + .m_deviceid = io->map.m_deviceid, + }; + err =erofs_map_dev (inode->i_sb, &io->dev); +if (err) +break ; + io->rq =erofs_fileio_rq_alloc (&io->dev); +if (!io->rq) { + err = -ENOMEM ; +break ; + } + io->rq->bio.bi_iter.bi_sector = io->dev.m_pa >>9 ; + attached =0 ; + } +if (!attached++) +erofs_onlinefolio_split (folio); +if (!bio_add_folio (&io->rq->bio, folio, len, cur)) + goto io_retry; + io->dev.m_pa += len; + } + cur += len; + } +erofs_onlinefolio_end (folio, err); +return err; +} + +static int erofs_fileio_read_folio (struct file *file,struct folio *folio) +{ +struct erofs_fileio io = {}; +int err; + +trace_erofs_read_folio (folio, false); + err =erofs_fileio_scan_folio (&io, folio); +erofs_fileio_rq_submit (io.rq); +return err; +} + +static void erofs_fileio_readahead (struct readahead_control *rac) +{ +struct inode *inode = rac->mapping->host; +struct erofs_fileio io = {}; +struct folio *folio; +int err; + +trace_erofs_readpages (inode,readahead_index (rac), +readahead_count (rac), false); +while ((folio =readahead_folio (rac))) { + err =erofs_fileio_scan_folio (&io, folio); +if (err && err != -EINTR ) +erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , + folio->index,EROFS_I (inode)->nid); + } +erofs_fileio_rq_submit (io.rq); +} + +const struct address_space_operations erofs_fileio_aops = { + .read_folio = erofs_fileio_read_folio, + .readahead = erofs_fileio_readahead, +};fs/erofs/inode.c +12
-5@@ -258,11 +258,14 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { -/* XXX: data I/Os will be implemented in the following patches */ - err = -EOPNOTSUPP ; - }else if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { + err = -EOPNOTSUPP ; + goto out_unlock; + } +#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );@@ -271,10 +274,14 @@ static int erofs_fill_inode(struct inode *inode) err = -EOPNOTSUPP ;#endif }else { - inode->i_mapping->a_ops = &erofs_raw_access_aops; + inode->i_mapping->a_ops = &erofs_aops;#ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode (inode->i_sb)) inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) + inode->i_mapping->a_ops = &erofs_fileio_aops;#endif } out_unlock:fs/erofs/internal.h +6
-1@@ -372,6 +372,7 @@ struct erofs_map_dev {struct erofs_fscache *m_fscache;struct block_device *m_bdev;struct dax_device *m_daxdev; +struct file *m_fp;u64 m_dax_part_off;erofs_off_t m_pa;@@ -380,7 +381,8 @@ struct erofs_map_dev {extern const struct super_operations erofs_sops; -extern const struct address_space_operations erofs_raw_access_aops; +extern const struct address_space_operations erofs_aops; +extern const struct address_space_operations erofs_fileio_aops;extern const struct address_space_operations z_erofs_aops;extern const struct address_space_operations erofs_fscache_access_aops;@@ -411,6 +413,9 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);int erofs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len);int erofs_map_blocks (struct inode *inode,struct erofs_map_blocks *map); +void erofs_onlinefolio_init (struct folio *folio); +void erofs_onlinefolio_split (struct folio *folio); +void erofs_onlinefolio_end (struct folio *folio,int err);struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid); int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask,fs/erofs/zdata.c +5
-42@@ -122,42 +122,6 @@ static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio *fo)return fo->mapping ==MNGD_MAPPING (sbi); } -/* -* bit 30: I/O error occurred on this folio -* bit 0 - 29: remaining parts to complete this folio -*/ -#define Z_EROFS_FOLIO_EIO (1 << 30) - -static void z_erofs_onlinefolio_init (struct folio *folio) -{ -union { -atomic_t o; -void *v; - } u = { .o =ATOMIC_INIT (1 ) }; - - folio->private = u.v;/* valid only if file-backed folio is locked */ -} - -static void z_erofs_onlinefolio_split (struct folio *folio) -{ -atomic_inc ((atomic_t *)&folio->private); -} - -static void z_erofs_onlinefolio_end (struct folio *folio,int err) -{ -int orig, v; - -do { - orig =atomic_read ((atomic_t *)&folio->private); - v = (orig -1 ) | (err ?Z_EROFS_FOLIO_EIO :0 ); - }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); - -if (v & ~Z_EROFS_FOLIO_EIO ) -return ; - folio->private =0 ; -folio_end_read (folio, !(v &Z_EROFS_FOLIO_EIO )); -} -#define Z_EROFS_ONSTACK_PAGES 32/* @@ -965,7 +929,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,int err =0 ; tight = (bs ==PAGE_SIZE ); -z_erofs_onlinefolio_init (folio); +erofs_onlinefolio_init (folio); do { if (offset + end - 1 < map->m_la || offset + end - 1 >= map->m_la + map->m_llen) {@@ -1024,7 +988,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,if (err)break ; -z_erofs_onlinefolio_split (folio); +erofs_onlinefolio_split (folio);if (f->pcl->pageofs_out != (map->m_la & ~PAGE_MASK )) f->pcl->multibases = true;if (f->pcl->length < offset + end - map->m_la) {@@ -1044,7 +1008,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f, tight = (bs ==PAGE_SIZE ); } }while ((end = cur) >0 ); -z_erofs_onlinefolio_end (folio, err); +erofs_onlinefolio_end (folio, err);return err; }@@ -1147,7 +1111,7 @@ static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be, cur += len; }kunmap_local (dst); -z_erofs_onlinefolio_end (page_folio (bvi->bvec.page), err); +erofs_onlinefolio_end (page_folio (bvi->bvec.page), err);list_del (p);kfree (bvi); }@@ -1302,7 +1266,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,DBG_BUGON (z_erofs_page_is_invalidated (page));if (!z_erofs_is_shortlived_page (page)) { -z_erofs_onlinefolio_end (page_folio (page), err); +erofs_onlinefolio_end (page_folio (page), err);continue ; }if (pcl->algorithmformat !=Z_EROFS_COMPRESSION_LZ4 ) { --2.43.5
Re: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
Quoted 171 lines · Sandeep Dhavale
Quoted 170 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Signed-off-by Gao Xiang <[email protected]>---
v2:
- fix redundant refcount which cause hanging on chunked inodes.fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 +++++++++++- fs/erofs/fileio.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++--------- 6 files changed, 251 insertions(+), 51 deletions(-)create mode 100644
fs/erofs/fileio.cfs/erofs/Makefile +1
-0@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/data.c +46
-4@@ -132,7 +132,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)if (map->m_la >= inode->i_size) {/* leave out-of-bound access unmapped */ map->m_flags =0 ; - map->m_plen =0 ; + map->m_plen = map->m_llen; goto out; }@@ -197,8 +197,13 @@ static void erofs_fill_from_devinfo(struct erofs_map_dev *map, struct erofs_device_info *dif) { map->m_bdev =NULL ; -if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) - map->m_bdev =file_bdev (dif->file); + map->m_fp =NULL ; +if (dif->file) { +if (S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); +else + map->m_fp = dif->file; + } map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache;@@ -215,6 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) map->m_daxdev =EROFS_SB (sb)->dax_dev; map->m_dax_part_off =EROFS_SB (sb)->dax_part_off; map->m_fscache =EROFS_SB (sb)->s_fscache; + map->m_fp =EROFS_SB (sb)->fdev;if (map->m_deviceid) {down_read (&devs->rwsem);@@ -250,6 +256,42 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)return 0 ; } +/* +* bit 30: I/O error occurred on this folio +* bit 0 - 29: remaining parts to complete this folio +*/ +#define EROFS_ONLINEFOLIO_EIO (1 << 30) + +void erofs_onlinefolio_init (struct folio *folio) +{ +union { +atomic_t o; +void *v; + } u = { .o =ATOMIC_INIT (1 ) }; + + folio->private = u.v;/* valid only if file-backed folio is locked */ +} + +void erofs_onlinefolio_split (struct folio *folio) +{ +atomic_inc ((atomic_t *)&folio->private); +} + +void erofs_onlinefolio_end (struct folio *folio,int err) +{ +int orig, v; + +do { + orig =atomic_read ((atomic_t *)&folio->private); + v = (orig -1 ) | (err ?EROFS_ONLINEFOLIO_EIO :0 ); + }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); + +if (v & ~EROFS_ONLINEFOLIO_EIO ) +return ; + folio->private =0 ; +folio_end_read (folio, !(v &EROFS_ONLINEFOLIO_EIO )); +} +static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {@@ -399,7 +441,7 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) }/* for uncompressed (aligned) files and raw access for other files */ -const struct address_space_operations erofs_raw_access_aops = { +const struct address_space_operations erofs_aops = { .read_folio = erofs_read_folio, .readahead = erofs_readahead, .bmap = erofs_bmap,fs/erofs/fileio.c new file +47
-0@@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#include "internal.h" +#include <trace/events/erofs.h> + +struct erofs_fileio_rq { +struct bio_vec bvecs[BIO_MAX_VECS ]; +struct bio bio; +struct kiocb iocb; +}; + +struct erofs_fileio { +struct erofs_map_blocks map; +struct erofs_map_dev dev; +struct erofs_fileio_rq *rq; +}; + +static void erofs_fileio_ki_complete (struct kiocb *iocb,long ret) +{ +struct erofs_fileio_rq *rq = + container_of(iocb, struct erofs_fileio_rq, iocb); +struct folio_iter fi; + +DBG_BUGON (rq->bio.bi_end_io); +if (ret >0 ) { +if (ret != rq->bio.bi_iter.bi_size) { +bio_advance (&rq->bio, ret); +zero_fill_bio (&rq->bio); + } + ret =0 ; + } +bio_for_each_folio_all (fi, &rq->bio) { +DBG_BUGON (folio_test_uptodate (fi.folio)); +erofs_onlinefolio_end (fi.folio, ret); + } +kfree (rq); +} + +static void erofs_fileio_rq_submit (struct erofs_fileio_rq *rq) +{ +struct iov_iter iter; +int ret; + +if (!rq) +return ;
Quoted 8 lines
fs/erofs/fileio.c line 52
Quoted 5 lines
fs/erofs/fileio.c new file +5
-0+ rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector <<9 ; + rq->iocb.ki_ioprio =get_current_ioprio (); + rq->iocb.ki_complete = erofs_fileio_ki_complete; + rq->iocb.ki_flags = (rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) ? +IOCB_DIRECT :0 ;Hi Gao,
Does this mean, direct IO by default if the backing file supports it (technically filesystem where image/backing file reside)?
Yes.
Thanks,
Gao Xiang
Sandeep Dhavale
reviewerRe: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
In reply to Gao XiangQuoted 33 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Signed-off-by Gao Xiang <[email protected]>---
v2:
- fix redundant refcount which cause hanging on chunked inodes.fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 +++++++++++- fs/erofs/fileio.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++--------- 6 files changed, 251 insertions(+), 51 deletions(-) create mode 100644 fs/erofs/fileio.cfs/erofs/Makefile +1
-0@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/data.c +0
-0
fs/erofs/data.c int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map) · line 135
Quoted 5 lines
fs/erofs/data.c +1
-1@@ -132,7 +132,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)if (map->m_la >= inode->i_size) {/* leave out-of-bound access unmapped */ map->m_flags =0 ; - map->m_plen =0 ; + map->m_plen = map->m_llen;
Hi Gao,
Is this change intentional? At out label, we set this again as err is 0.
Quoted 432 lines
fs/erofs/data.c +45
-3goto out; }@@ -197,8 +197,13 @@ static void erofs_fill_from_devinfo(struct erofs_map_dev *map, struct erofs_device_info *dif) { map->m_bdev =NULL ; -if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) - map->m_bdev =file_bdev (dif->file); + map->m_fp =NULL ; +if (dif->file) { +if (S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); +else + map->m_fp = dif->file; + } map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache;@@ -215,6 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) map->m_daxdev =EROFS_SB (sb)->dax_dev; map->m_dax_part_off =EROFS_SB (sb)->dax_part_off; map->m_fscache =EROFS_SB (sb)->s_fscache; + map->m_fp =EROFS_SB (sb)->fdev;if (map->m_deviceid) {down_read (&devs->rwsem);@@ -250,6 +256,42 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)return 0 ; } +/* +* bit 30: I/O error occurred on this folio +* bit 0 - 29: remaining parts to complete this folio +*/ +#define EROFS_ONLINEFOLIO_EIO (1 << 30) + +void erofs_onlinefolio_init (struct folio *folio) +{ +union { +atomic_t o; +void *v; + } u = { .o =ATOMIC_INIT (1 ) }; + + folio->private = u.v;/* valid only if file-backed folio is locked */ +} + +void erofs_onlinefolio_split (struct folio *folio) +{ +atomic_inc ((atomic_t *)&folio->private); +} + +void erofs_onlinefolio_end (struct folio *folio,int err) +{ +int orig, v; + +do { + orig =atomic_read ((atomic_t *)&folio->private); + v = (orig -1 ) | (err ?EROFS_ONLINEFOLIO_EIO :0 ); + }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); + +if (v & ~EROFS_ONLINEFOLIO_EIO ) +return ; + folio->private =0 ; +folio_end_read (folio, !(v &EROFS_ONLINEFOLIO_EIO )); +} +static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {@@ -399,7 +441,7 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) }/* for uncompressed (aligned) files and raw access for other files */ -const struct address_space_operations erofs_raw_access_aops = { +const struct address_space_operations erofs_aops = { .read_folio = erofs_read_folio, .readahead = erofs_readahead, .bmap = erofs_bmap,fs/erofs/fileio.c new file +181
-0@@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#include "internal.h" +#include <trace/events/erofs.h> + +struct erofs_fileio_rq { +struct bio_vec bvecs[BIO_MAX_VECS ]; +struct bio bio; +struct kiocb iocb; +}; + +struct erofs_fileio { +struct erofs_map_blocks map; +struct erofs_map_dev dev; +struct erofs_fileio_rq *rq; +}; + +static void erofs_fileio_ki_complete (struct kiocb *iocb,long ret) +{ +struct erofs_fileio_rq *rq = + container_of(iocb, struct erofs_fileio_rq, iocb); +struct folio_iter fi; + +DBG_BUGON (rq->bio.bi_end_io); +if (ret >0 ) { +if (ret != rq->bio.bi_iter.bi_size) { +bio_advance (&rq->bio, ret); +zero_fill_bio (&rq->bio); + } + ret =0 ; + } +bio_for_each_folio_all (fi, &rq->bio) { +DBG_BUGON (folio_test_uptodate (fi.folio)); +erofs_onlinefolio_end (fi.folio, ret); + } +kfree (rq); +} + +static void erofs_fileio_rq_submit (struct erofs_fileio_rq *rq) +{ +struct iov_iter iter; +int ret; + +if (!rq) +return ; + rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector <<9 ; + rq->iocb.ki_ioprio =get_current_ioprio (); + rq->iocb.ki_complete = erofs_fileio_ki_complete; + rq->iocb.ki_flags = (rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) ? +IOCB_DIRECT :0 ; +iov_iter_bvec (&iter,ITER_DEST , rq->bvecs, rq->bio.bi_vcnt, + rq->bio.bi_iter.bi_size); + ret =vfs_iocb_iter_read (rq->iocb.ki_filp, &rq->iocb, &iter); +if (ret != -EIOCBQUEUED ) +erofs_fileio_ki_complete (&rq->iocb, ret); +} + +static struct erofs_fileio_rq *erofs_fileio_rq_alloc (struct erofs_map_dev *mdev) +{ +struct erofs_fileio_rq *rq =kzalloc (sizeof (*rq),GFP_KERNEL ); + +if (!rq) +return NULL ; +bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); + rq->iocb.ki_filp = mdev->m_fp; +return rq; +} + +static int erofs_fileio_scan_folio (struct erofs_fileio *io,struct folio *folio) +{ +struct inode *inode =folio_inode (folio); +struct erofs_map_blocks *map = &io->map; +unsigned int cur =0 , end =folio_size (folio), len, attached =0 ; +loff_t pos =folio_pos (folio), ofs; +struct iov_iter iter; +struct bio_vec bv; +int err =0 ; + +erofs_onlinefolio_init (folio); +while (cur < end) { +if (!in_range (pos + cur, map->m_la, map->m_llen)) { + map->m_la = pos + cur; + map->m_llen = end - cur; + err =erofs_map_blocks (inode, map); +if (err) +break ; + } + + ofs =folio_pos (folio) + cur - map->m_la; + len =min_t (loff_t, map->m_llen - ofs, end - cur); +if (map->m_flags &EROFS_MAP_META ) { +struct erofs_buf buf = __EROFS_BUF_INITIALIZER; +void *src; + + src =erofs_read_metabuf (&buf, inode->i_sb, + map->m_pa + ofs,EROFS_KMAP ); +if (IS_ERR (src)) { + err =PTR_ERR (src); +break ; + } +bvec_set_folio (&bv, folio, len, cur); +iov_iter_bvec (&iter,ITER_DEST , &bv,1 , len); +if (copy_to_iter (src, len, &iter) != len) { +erofs_put_metabuf (&buf); + err = -EIO ; +break ; + } +erofs_put_metabuf (&buf); + }else if (!(map->m_flags &EROFS_MAP_MAPPED )) { +folio_zero_segment (folio, cur, cur + len); + }else { +if (io->rq && (map->m_pa + ofs != io->dev.m_pa || + map->m_deviceid != io->dev.m_deviceid)) { +io_retry: +erofs_fileio_rq_submit (io->rq); + io->rq =NULL ; + } + +if (!io->rq) { + io->dev = (struct erofs_map_dev ) { + .m_pa = io->map.m_pa + ofs, + .m_deviceid = io->map.m_deviceid, + }; + err =erofs_map_dev (inode->i_sb, &io->dev); +if (err) +break ; + io->rq =erofs_fileio_rq_alloc (&io->dev); +if (!io->rq) { + err = -ENOMEM ; +break ; + } + io->rq->bio.bi_iter.bi_sector = io->dev.m_pa >>9 ; + attached =0 ; + } +if (!attached++) +erofs_onlinefolio_split (folio); +if (!bio_add_folio (&io->rq->bio, folio, len, cur)) + goto io_retry; + io->dev.m_pa += len; + } + cur += len; + } +erofs_onlinefolio_end (folio, err); +return err; +} + +static int erofs_fileio_read_folio (struct file *file,struct folio *folio) +{ +struct erofs_fileio io = {}; +int err; + +trace_erofs_read_folio (folio, false); + err =erofs_fileio_scan_folio (&io, folio); +erofs_fileio_rq_submit (io.rq); +return err; +} + +static void erofs_fileio_readahead (struct readahead_control *rac) +{ +struct inode *inode = rac->mapping->host; +struct erofs_fileio io = {}; +struct folio *folio; +int err; + +trace_erofs_readpages (inode,readahead_index (rac), +readahead_count (rac), false); +while ((folio =readahead_folio (rac))) { + err =erofs_fileio_scan_folio (&io, folio); +if (err && err != -EINTR ) +erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , + folio->index,EROFS_I (inode)->nid); + } +erofs_fileio_rq_submit (io.rq); +} + +const struct address_space_operations erofs_fileio_aops = { + .read_folio = erofs_fileio_read_folio, + .readahead = erofs_fileio_readahead, +};fs/erofs/inode.c +12
-5@@ -258,11 +258,14 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { -/* XXX: data I/Os will be implemented in the following patches */ - err = -EOPNOTSUPP ; - }else if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { + err = -EOPNOTSUPP ; + goto out_unlock; + } +#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );@@ -271,10 +274,14 @@ static int erofs_fill_inode(struct inode *inode) err = -EOPNOTSUPP ;#endif }else { - inode->i_mapping->a_ops = &erofs_raw_access_aops; + inode->i_mapping->a_ops = &erofs_aops;#ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode (inode->i_sb)) inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) + inode->i_mapping->a_ops = &erofs_fileio_aops;#endif } out_unlock:fs/erofs/internal.h +6
-1@@ -372,6 +372,7 @@ struct erofs_map_dev {struct erofs_fscache *m_fscache;struct block_device *m_bdev;struct dax_device *m_daxdev; +struct file *m_fp;u64 m_dax_part_off;erofs_off_t m_pa;@@ -380,7 +381,8 @@ struct erofs_map_dev {extern const struct super_operations erofs_sops; -extern const struct address_space_operations erofs_raw_access_aops; +extern const struct address_space_operations erofs_aops; +extern const struct address_space_operations erofs_fileio_aops;extern const struct address_space_operations z_erofs_aops;extern const struct address_space_operations erofs_fscache_access_aops;@@ -411,6 +413,9 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);int erofs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len);int erofs_map_blocks (struct inode *inode,struct erofs_map_blocks *map); +void erofs_onlinefolio_init (struct folio *folio); +void erofs_onlinefolio_split (struct folio *folio); +void erofs_onlinefolio_end (struct folio *folio,int err);struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid); int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask,fs/erofs/zdata.c +5
-42@@ -122,42 +122,6 @@ static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio *fo)return fo->mapping ==MNGD_MAPPING (sbi); } -/* -* bit 30: I/O error occurred on this folio -* bit 0 - 29: remaining parts to complete this folio -*/ -#define Z_EROFS_FOLIO_EIO (1 << 30) - -static void z_erofs_onlinefolio_init (struct folio *folio) -{ -union { -atomic_t o; -void *v; - } u = { .o =ATOMIC_INIT (1 ) }; - - folio->private = u.v;/* valid only if file-backed folio is locked */ -} - -static void z_erofs_onlinefolio_split (struct folio *folio) -{ -atomic_inc ((atomic_t *)&folio->private); -} - -static void z_erofs_onlinefolio_end (struct folio *folio,int err) -{ -int orig, v; - -do { - orig =atomic_read ((atomic_t *)&folio->private); - v = (orig -1 ) | (err ?Z_EROFS_FOLIO_EIO :0 ); - }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); - -if (v & ~Z_EROFS_FOLIO_EIO ) -return ; - folio->private =0 ; -folio_end_read (folio, !(v &Z_EROFS_FOLIO_EIO )); -} -#define Z_EROFS_ONSTACK_PAGES 32/* @@ -965,7 +929,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,int err =0 ; tight = (bs ==PAGE_SIZE ); -z_erofs_onlinefolio_init (folio); +erofs_onlinefolio_init (folio); do { if (offset + end - 1 < map->m_la || offset + end - 1 >= map->m_la + map->m_llen) {@@ -1024,7 +988,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,if (err)break ; -z_erofs_onlinefolio_split (folio); +erofs_onlinefolio_split (folio);if (f->pcl->pageofs_out != (map->m_la & ~PAGE_MASK )) f->pcl->multibases = true;if (f->pcl->length < offset + end - map->m_la) {@@ -1044,7 +1008,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f, tight = (bs ==PAGE_SIZE ); } }while ((end = cur) >0 ); -z_erofs_onlinefolio_end (folio, err); +erofs_onlinefolio_end (folio, err);return err; }@@ -1147,7 +1111,7 @@ static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be, cur += len; }kunmap_local (dst); -z_erofs_onlinefolio_end (page_folio (bvi->bvec.page), err); +erofs_onlinefolio_end (page_folio (bvi->bvec.page), err);list_del (p);kfree (bvi); }@@ -1302,7 +1266,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,DBG_BUGON (z_erofs_page_is_invalidated (page));if (!z_erofs_is_shortlived_page (page)) { -z_erofs_onlinefolio_end (page_folio (page), err); +erofs_onlinefolio_end (page_folio (page), err);continue ; }if (pcl->algorithmformat !=Z_EROFS_COMPRESSION_LZ4 ) { --2.43.5
Re: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
Quoted 33 lines · Sandeep Dhavale
Quoted 32 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Signed-off-by Gao Xiang <[email protected]>---
v2:
- fix redundant refcount which cause hanging on chunked inodes.fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 +++++++++++- fs/erofs/fileio.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++--------- 6 files changed, 251 insertions(+), 51 deletions(-)create mode 100644
fs/erofs/fileio.cfs/erofs/Makefile +1
-0@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/data.c +0
-0
Quoted 8 lines
fs/erofs/data.c int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map) · line 135
Quoted 6 lines
fs/erofs/data.c +1
-1@@ -132,7 +132,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)if (map->m_la >= inode->i_size) {/* leave out-of-bound access unmapped */ map->m_flags =0 ; - map->m_plen =0 ; + map->m_plen = map->m_llen;Hi Gao,
Is this change intentional? At out label, we set this again as err is 0.
Yes, that is intentional, we will return the post-EOF extent as m_plen == map->m_llen == passed in m_llen and an unmapped extent
so that the logic can be simplified and it's still compatible.
Thanks,
Gao Xiang
Re: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
Thanks,
Sandeep.
Re: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
In reply to Gao XiangQuoted 4 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Signed-off-by Gao Xiang <[email protected]>
Unmapped extent could actually split, already fixed as below:
fs/erofs/fileio.c +1 -0
@@ -127,6 +127,7 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio)erofs_put_metabuf (&buf); }else if (!(map->m_flags &EROFS_MAP_MAPPED )) {folio_zero_segment (folio, cur, cur + len); + attached =0 ; }else {if (io->rq && (map->m_pa + ofs != io->dev.m_pa || map->m_deviceid != io->dev.m_deviceid)) {
Chao Yu
maintainerRe: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
In reply to Gao XiangQuoted 160 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Signed-off-by Gao Xiang <[email protected]>---
v2:
- fix redundant refcount which cause hanging on chunked inodes.fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 +++++++++++- fs/erofs/fileio.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++--------- 6 files changed, 251 insertions(+), 51 deletions(-)create mode 100644
fs/erofs/fileio.cfs/erofs/Makefile +1
-0@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/data.c +46
-4@@ -132,7 +132,7 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)if (map->m_la >= inode->i_size) {/* leave out-of-bound access unmapped */ map->m_flags =0 ; - map->m_plen =0 ; + map->m_plen = map->m_llen; goto out; }@@ -197,8 +197,13 @@ static void erofs_fill_from_devinfo(struct erofs_map_dev *map, struct erofs_device_info *dif) { map->m_bdev =NULL ; -if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) - map->m_bdev =file_bdev (dif->file); + map->m_fp =NULL ; +if (dif->file) { +if (S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); +else + map->m_fp = dif->file; + } map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache;@@ -215,6 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) map->m_daxdev =EROFS_SB (sb)->dax_dev; map->m_dax_part_off =EROFS_SB (sb)->dax_part_off; map->m_fscache =EROFS_SB (sb)->s_fscache; + map->m_fp =EROFS_SB (sb)->fdev;if (map->m_deviceid) {down_read (&devs->rwsem);@@ -250,6 +256,42 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)return 0 ; } +/* +* bit 30: I/O error occurred on this folio +* bit 0 - 29: remaining parts to complete this folio +*/ +#define EROFS_ONLINEFOLIO_EIO (1 << 30) + +void erofs_onlinefolio_init (struct folio *folio) +{ +union { +atomic_t o; +void *v; + } u = { .o =ATOMIC_INIT (1 ) }; + + folio->private = u.v;/* valid only if file-backed folio is locked */ +} + +void erofs_onlinefolio_split (struct folio *folio) +{ +atomic_inc ((atomic_t *)&folio->private); +} + +void erofs_onlinefolio_end (struct folio *folio,int err) +{ +int orig, v; + +do { + orig =atomic_read ((atomic_t *)&folio->private); + v = (orig -1 ) | (err ?EROFS_ONLINEFOLIO_EIO :0 ); + }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); + +if (v & ~EROFS_ONLINEFOLIO_EIO ) +return ; + folio->private =0 ; +folio_end_read (folio, !(v &EROFS_ONLINEFOLIO_EIO )); +} +static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) {@@ -399,7 +441,7 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) }/* for uncompressed (aligned) files and raw access for other files */ -const struct address_space_operations erofs_raw_access_aops = { +const struct address_space_operations erofs_aops = { .read_folio = erofs_read_folio, .readahead = erofs_readahead, .bmap = erofs_bmap,fs/erofs/fileio.c new file +38
-0@@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#include "internal.h" +#include <trace/events/erofs.h> + +struct erofs_fileio_rq { +struct bio_vec bvecs[BIO_MAX_VECS ]; +struct bio bio; +struct kiocb iocb; +}; + +struct erofs_fileio { +struct erofs_map_blocks map; +struct erofs_map_dev dev; +struct erofs_fileio_rq *rq; +}; + +static void erofs_fileio_ki_complete (struct kiocb *iocb,long ret) +{ +struct erofs_fileio_rq *rq = + container_of(iocb, struct erofs_fileio_rq, iocb); +struct folio_iter fi; + +DBG_BUGON (rq->bio.bi_end_io); +if (ret >0 ) { +if (ret != rq->bio.bi_iter.bi_size) { +bio_advance (&rq->bio, ret); +zero_fill_bio (&rq->bio); + } + ret =0 ; + } +bio_for_each_folio_all (fi, &rq->bio) { +DBG_BUGON (folio_test_uptodate (fi.folio)); +erofs_onlinefolio_end (fi.folio, ret); + } +kfree (rq);
fs/erofs/fileio.c line 48
Quoted 10 lines
fs/erofs/fileio.c new file +10
-0+} + +static void erofs_fileio_rq_submit (struct erofs_fileio_rq *rq) +{ +struct iov_iter iter; +int ret; + +if (!rq) +return ; + rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector <<9 ;
Trivial cleanup,
rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector << SECTOR_SHIFT;
fs/erofs/fileio.c line 57
Quoted 9 lines
fs/erofs/fileio.c new file +9
-0+ rq->iocb.ki_ioprio =get_current_ioprio (); + rq->iocb.ki_complete = erofs_fileio_ki_complete; + rq->iocb.ki_flags = (rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) ? +IOCB_DIRECT :0 ; +iov_iter_bvec (&iter,ITER_DEST , rq->bvecs, rq->bio.bi_vcnt, + rq->bio.bi_iter.bi_size); + ret =vfs_iocb_iter_read (rq->iocb.ki_filp, &rq->iocb, &iter); +if (ret != -EIOCBQUEUED ) +erofs_fileio_ki_complete (&rq->iocb, ret);
Shouldn't we pass return value to caller?
Thanks,
Quoted 287 lines
fs/erofs/fileio.c new file +124
-0+} + +static struct erofs_fileio_rq *erofs_fileio_rq_alloc (struct erofs_map_dev *mdev) +{ +struct erofs_fileio_rq *rq =kzalloc (sizeof (*rq),GFP_KERNEL ); + +if (!rq) +return NULL ; +bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); + rq->iocb.ki_filp = mdev->m_fp; +return rq; +} + +static int erofs_fileio_scan_folio (struct erofs_fileio *io,struct folio *folio) +{ +struct inode *inode =folio_inode (folio); +struct erofs_map_blocks *map = &io->map; +unsigned int cur =0 , end =folio_size (folio), len, attached =0 ; +loff_t pos =folio_pos (folio), ofs; +struct iov_iter iter; +struct bio_vec bv; +int err =0 ; + +erofs_onlinefolio_init (folio); +while (cur < end) { +if (!in_range (pos + cur, map->m_la, map->m_llen)) { + map->m_la = pos + cur; + map->m_llen = end - cur; + err =erofs_map_blocks (inode, map); +if (err) +break ; + } + + ofs =folio_pos (folio) + cur - map->m_la; + len =min_t (loff_t, map->m_llen - ofs, end - cur); +if (map->m_flags &EROFS_MAP_META ) { +struct erofs_buf buf = __EROFS_BUF_INITIALIZER; +void *src; + + src =erofs_read_metabuf (&buf, inode->i_sb, + map->m_pa + ofs,EROFS_KMAP ); +if (IS_ERR (src)) { + err =PTR_ERR (src); +break ; + } +bvec_set_folio (&bv, folio, len, cur); +iov_iter_bvec (&iter,ITER_DEST , &bv,1 , len); +if (copy_to_iter (src, len, &iter) != len) { +erofs_put_metabuf (&buf); + err = -EIO ; +break ; + } +erofs_put_metabuf (&buf); + }else if (!(map->m_flags &EROFS_MAP_MAPPED )) { +folio_zero_segment (folio, cur, cur + len); + }else { +if (io->rq && (map->m_pa + ofs != io->dev.m_pa || + map->m_deviceid != io->dev.m_deviceid)) { +io_retry: +erofs_fileio_rq_submit (io->rq); + io->rq =NULL ; + } + +if (!io->rq) { + io->dev = (struct erofs_map_dev ) { + .m_pa = io->map.m_pa + ofs, + .m_deviceid = io->map.m_deviceid, + }; + err =erofs_map_dev (inode->i_sb, &io->dev); +if (err) +break ; + io->rq =erofs_fileio_rq_alloc (&io->dev); +if (!io->rq) { + err = -ENOMEM ; +break ; + } + io->rq->bio.bi_iter.bi_sector = io->dev.m_pa >>9 ; + attached =0 ; + } +if (!attached++) +erofs_onlinefolio_split (folio); +if (!bio_add_folio (&io->rq->bio, folio, len, cur)) + goto io_retry; + io->dev.m_pa += len; + } + cur += len; + } +erofs_onlinefolio_end (folio, err); +return err; +} + +static int erofs_fileio_read_folio (struct file *file,struct folio *folio) +{ +struct erofs_fileio io = {}; +int err; + +trace_erofs_read_folio (folio, false); + err =erofs_fileio_scan_folio (&io, folio); +erofs_fileio_rq_submit (io.rq); +return err; +} + +static void erofs_fileio_readahead (struct readahead_control *rac) +{ +struct inode *inode = rac->mapping->host; +struct erofs_fileio io = {}; +struct folio *folio; +int err; + +trace_erofs_readpages (inode,readahead_index (rac), +readahead_count (rac), false); +while ((folio =readahead_folio (rac))) { + err =erofs_fileio_scan_folio (&io, folio); +if (err && err != -EINTR ) +erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , + folio->index,EROFS_I (inode)->nid); + } +erofs_fileio_rq_submit (io.rq); +} + +const struct address_space_operations erofs_fileio_aops = { + .read_folio = erofs_fileio_read_folio, + .readahead = erofs_fileio_readahead, +};fs/erofs/inode.c +12
-5@@ -258,11 +258,14 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { -/* XXX: data I/Os will be implemented in the following patches */ - err = -EOPNOTSUPP ; - }else if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { + err = -EOPNOTSUPP ; + goto out_unlock; + } +#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );@@ -271,10 +274,14 @@ static int erofs_fill_inode(struct inode *inode) err = -EOPNOTSUPP ;#endif }else { - inode->i_mapping->a_ops = &erofs_raw_access_aops; + inode->i_mapping->a_ops = &erofs_aops;#ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode (inode->i_sb)) inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) + inode->i_mapping->a_ops = &erofs_fileio_aops;#endif } out_unlock:fs/erofs/internal.h +6
-1@@ -372,6 +372,7 @@ struct erofs_map_dev {struct erofs_fscache *m_fscache;struct block_device *m_bdev;struct dax_device *m_daxdev; +struct file *m_fp;u64 m_dax_part_off;erofs_off_t m_pa;@@ -380,7 +381,8 @@ struct erofs_map_dev {extern const struct super_operations erofs_sops; -extern const struct address_space_operations erofs_raw_access_aops; +extern const struct address_space_operations erofs_aops; +extern const struct address_space_operations erofs_fileio_aops;extern const struct address_space_operations z_erofs_aops;extern const struct address_space_operations erofs_fscache_access_aops;@@ -411,6 +413,9 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);int erofs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len);int erofs_map_blocks (struct inode *inode,struct erofs_map_blocks *map); +void erofs_onlinefolio_init (struct folio *folio); +void erofs_onlinefolio_split (struct folio *folio); +void erofs_onlinefolio_end (struct folio *folio,int err);struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid); int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask,fs/erofs/zdata.c +5
-41@@ -122,42 +122,6 @@ static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio *fo)return fo->mapping ==MNGD_MAPPING (sbi); } -/* -* bit 30: I/O error occurred on this folio -* bit 0 - 29: remaining parts to complete this folio -*/ -#define Z_EROFS_FOLIO_EIO (1 << 30) - -static void z_erofs_onlinefolio_init (struct folio *folio) -{ -union { -atomic_t o; -void *v; - } u = { .o =ATOMIC_INIT (1 ) }; - - folio->private = u.v;/* valid only if file-backed folio is locked */ -} - -static void z_erofs_onlinefolio_split (struct folio *folio) -{ -atomic_inc ((atomic_t *)&folio->private); -} - -static void z_erofs_onlinefolio_end (struct folio *folio,int err) -{ -int orig, v; - -do { - orig =atomic_read ((atomic_t *)&folio->private); - v = (orig -1 ) | (err ?Z_EROFS_FOLIO_EIO :0 ); - }while (atomic_cmpxchg ((atomic_t *)&folio->private, orig, v) != orig); - -if (v & ~Z_EROFS_FOLIO_EIO ) -return ; - folio->private =0 ; -folio_end_read (folio, !(v &Z_EROFS_FOLIO_EIO )); -} -#define Z_EROFS_ONSTACK_PAGES 32/* @@ -965,7 +929,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,int err =0 ; tight = (bs ==PAGE_SIZE ); -z_erofs_onlinefolio_init (folio); +erofs_onlinefolio_init (folio); do { if (offset + end - 1 < map->m_la || offset + end - 1 >= map->m_la + map->m_llen) {@@ -1024,7 +988,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,if (err)break ; -z_erofs_onlinefolio_split (folio); +erofs_onlinefolio_split (folio);if (f->pcl->pageofs_out != (map->m_la & ~PAGE_MASK )) f->pcl->multibases = true;if (f->pcl->length < offset + end - map->m_la) {@@ -1044,7 +1008,7 @@ static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f, tight = (bs ==PAGE_SIZE ); } }while ((end = cur) >0 ); -z_erofs_onlinefolio_end (folio, err); +erofs_onlinefolio_end (folio, err);return err; }@@ -1147,7 +1111,7 @@ static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be, cur += len; }kunmap_local (dst); -z_erofs_onlinefolio_end (page_folio (bvi->bvec.page), err); +erofs_onlinefolio_end (page_folio (bvi->bvec.page), err);list_del (p);kfree (bvi); }@@ -1302,7 +1266,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,DBG_BUGON (z_erofs_page_is_invalidated (page));if (!z_erofs_is_shortlived_page (page)) { -z_erofs_onlinefolio_end (page_folio (page), err); +erofs_onlinefolio_end (page_folio (page), err);continue ; }if (pcl->algorithmformat !=Z_EROFS_COMPRESSION_LZ4 ) {
Re: [PATCH v2 2/4] erofs: support unencoded inodes for fileio
Hi Chao,
Quoted 1 line · Chao Yu
On 2024/8/30 11:28, Gao Xiang wrote:
..
Quoted 12 lines
fs/erofs/fileio.c line 48
Quoted 9 lines
fs/erofs/fileio.c new file +9
-0+ +static void erofs_fileio_rq_submit (struct erofs_fileio_rq *rq) +{ + struct iov_iter iter; + int ret; + + if (!rq) + return; + rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector << 9;Trivial cleanup,
Quoted 1 line
rq->iocb.ki_pos=rq->bio.bi_iter.bi_sector<<SECTOR_SHIFT;
Will send a quick fix version.
Quoted 11 lines
Quoted 10 lines
+
rq->iocb.ki_ioprio=get_current_ioprio();
+rq->iocb.ki_complete=erofs_fileio_ki_complete;
+rq->iocb.ki_flags= (rq->iocb.ki_filp->f_mode&FMODE_CAN_ODIRECT) ? +IOCB_DIRECT: 0;
+iov_iter_bvec(&iter, ITER_DEST, rq->bvecs, rq->bio.bi_vcnt, + rq->bio.bi_iter.bi_size);
+ ret =vfs_iocb_iter_read(rq->iocb.ki_filp, &rq->iocb, &iter); + if (ret !=-EIOCBQUEUED)
+erofs_fileio_ki_complete(&rq->iocb, ret);
Quoted 1 line
Shouldn't we pass return value to caller?
I don't think it's needed. Since ki_complete will handle error cases for both (a)sync I/Os.
Thanks,
Gao Xiang
Quoted 3 lines
Thanks,
PATCH v2 3/4 erofs: support compressed inodes for fileio
In reply to Gao XiangUse pseudo bios just like the previous fscache approach since merged bio_vecs can be filled properly with unique interfaces.
--- fs/erofs/fileio.c | 25 +++++++++++++++++++++---- fs/erofs/inode.c | 6 ------ fs/erofs/internal.h | 8 ++++++++ fs/erofs/zdata.c | 27 +++++++++++++++++---------- 4 files changed, 46 insertions(+), 20 deletions(-)
fs/erofs/fileio.c +21 -4
@@ -23,7 +23,6 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) container_of(iocb, struct erofs_fileio_rq, iocb);struct folio_iter fi; -DBG_BUGON (rq->bio.bi_end_io);if (ret >0 ) {if (ret != rq->bio.bi_iter.bi_size) {bio_advance (&rq->bio, ret);
@@ -31,9 +30,13 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) } ret =0 ; } -bio_for_each_folio_all (fi, &rq->bio) { -DBG_BUGON (folio_test_uptodate (fi.folio)); -erofs_onlinefolio_end (fi.folio, ret); +if (rq->bio.bi_end_io) { + rq->bio.bi_end_io (&rq->bio); + }else { +bio_for_each_folio_all (fi, &rq->bio) { +DBG_BUGON (folio_test_uptodate (fi.folio)); +erofs_onlinefolio_end (fi.folio, ret); + } }kfree (rq); }
@@ -68,6 +71,20 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev)return rq; } +struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev) +{ +struct erofs_fileio_rq *rq; + + rq =erofs_fileio_rq_alloc (mdev); +return rq ? &rq->bio :NULL ; +} + +void erofs_fileio_submit_bio (struct bio *bio) +{ + return erofs_fileio_rq_submit(container_of(bio, struct erofs_fileio_rq, + bio)); +} +static int erofs_fileio_scan_folio (struct erofs_fileio *io,struct folio *folio) {struct inode *inode =folio_inode (folio);
fs/erofs/inode.c +0 -6
@@ -260,12 +260,6 @@ static int erofs_fill_inode(struct inode *inode)mapping_set_large_folios (inode->i_mapping);if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP -#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { - err = -EOPNOTSUPP ; - goto out_unlock; - } -#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );
fs/erofs/internal.h +8 -0
@@ -489,6 +489,14 @@ static inline void z_erofs_exit_subsystem(void) {}static inline int erofs_init_managed_cache (struct super_block *sb) {return 0 ; }#endif /* !CONFIG_EROFS_FS_ZIP */ +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev); +void erofs_fileio_submit_bio (struct bio *bio); +#else +static inline struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev) {return NULL ; } +static inline void erofs_fileio_submit_bio (struct bio *bio) {} +#endif +#ifdef CONFIG_EROFS_FS_ONDEMAND int erofs_fscache_register_fs (struct super_block *sb);void erofs_fscache_unregister_fs (struct super_block *sb);
fs/erofs/zdata.c +17 -10
@@ -1618,10 +1618,12 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,if (bio && (cur != last_pa || bio->bi_bdev != mdev.m_bdev)) { io_retry: -if (!erofs_is_fscache_mode (sb)) -submit_bio (bio); -else +if (erofs_is_fileio_mode (EROFS_SB (sb))) +erofs_fileio_submit_bio (bio); +else if (erofs_is_fscache_mode (sb))erofs_fscache_submit_bio (bio); +else +submit_bio (bio);if (memstall) {psi_memstall_leave (&pflags);
@@ -1637,10 +1639,13 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, }if (!bio) { - bio =erofs_is_fscache_mode (sb) ? -erofs_fscache_bio_alloc (&mdev) : -bio_alloc (mdev.m_bdev,BIO_MAX_VECS , -REQ_OP_READ ,GFP_NOIO ); +if (erofs_is_fileio_mode (EROFS_SB (sb))) + bio =erofs_fileio_bio_alloc (&mdev); +else if (erofs_is_fscache_mode (sb)) + bio =erofs_fscache_bio_alloc (&mdev); +else + bio =bio_alloc (mdev.m_bdev,BIO_MAX_VECS , +REQ_OP_READ ,GFP_NOIO ); bio->bi_end_io = z_erofs_endio; bio->bi_iter.bi_sector = cur >>9 ; bio->bi_private = q[JQ_SUBMIT ];
@@ -1667,10 +1672,12 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, }while (owned_head !=Z_EROFS_PCLUSTER_TAIL );if (bio) { -if (!erofs_is_fscache_mode (sb)) -submit_bio (bio); -else +if (erofs_is_fileio_mode (EROFS_SB (sb))) +erofs_fileio_submit_bio (bio); +else if (erofs_is_fscache_mode (sb))erofs_fscache_submit_bio (bio); +else +submit_bio (bio);if (memstall)psi_memstall_leave (&pflags); }
Signature · 1 line
2.43.5
Re: [PATCH v2 3/4] erofs: support compressed inodes for fileio
Thanks,
Sandeep.
Chao Yu
maintainerRe: [PATCH v2 3/4] erofs: support compressed inodes for fileio
In reply to Gao XiangQuoted 118 lines · Gao Xiang
Use pseudo bios just like the previous fscache approach since merged
bio_vecscan be filled properly with unique interfaces.Signed-off-by Gao Xiang <[email protected]>--- fs/erofs/fileio.c | 25 +++++++++++++++++++++---- fs/erofs/inode.c | 6 ------ fs/erofs/internal.h | 8 ++++++++ fs/erofs/zdata.c | 27 +++++++++++++++++---------- 4 files changed, 46 insertions(+), 20 deletions(-)fs/erofs/fileio.c +21
-4@@ -23,7 +23,6 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) container_of(iocb, struct erofs_fileio_rq, iocb);struct folio_iter fi; -DBG_BUGON (rq->bio.bi_end_io);if (ret >0 ) {if (ret != rq->bio.bi_iter.bi_size) {bio_advance (&rq->bio, ret);@@ -31,9 +30,13 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) } ret =0 ; } -bio_for_each_folio_all (fi, &rq->bio) { -DBG_BUGON (folio_test_uptodate (fi.folio)); -erofs_onlinefolio_end (fi.folio, ret); +if (rq->bio.bi_end_io) { + rq->bio.bi_end_io (&rq->bio); + }else { +bio_for_each_folio_all (fi, &rq->bio) { +DBG_BUGON (folio_test_uptodate (fi.folio)); +erofs_onlinefolio_end (fi.folio, ret); + } }kfree (rq); }@@ -68,6 +71,20 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev)return rq; } +struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev) +{ +struct erofs_fileio_rq *rq; + + rq =erofs_fileio_rq_alloc (mdev); +return rq ? &rq->bio :NULL ; +} + +void erofs_fileio_submit_bio (struct bio *bio) +{ + return erofs_fileio_rq_submit(container_of(bio, struct erofs_fileio_rq, + bio)); +} +static int erofs_fileio_scan_folio (struct erofs_fileio *io,struct folio *folio) {struct inode *inode =folio_inode (folio);fs/erofs/inode.c +0
-6@@ -260,12 +260,6 @@ static int erofs_fill_inode(struct inode *inode)mapping_set_large_folios (inode->i_mapping);if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP -#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { - err = -EOPNOTSUPP ; - goto out_unlock; - } -#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );fs/erofs/internal.h +8
-0@@ -489,6 +489,14 @@ static inline void z_erofs_exit_subsystem(void) {}static inline int erofs_init_managed_cache (struct super_block *sb) {return 0 ; }#endif /* !CONFIG_EROFS_FS_ZIP */ +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev); +void erofs_fileio_submit_bio (struct bio *bio); +#else +static inline struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev) {return NULL ; } +static inline void erofs_fileio_submit_bio (struct bio *bio) {} +#endif +#ifdef CONFIG_EROFS_FS_ONDEMAND int erofs_fscache_register_fs (struct super_block *sb);void erofs_fscache_unregister_fs (struct super_block *sb);fs/erofs/zdata.c +5
-3@@ -1618,10 +1618,12 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,if (bio && (cur != last_pa || bio->bi_bdev != mdev.m_bdev)) { io_retry: -if (!erofs_is_fscache_mode (sb)) -submit_bio (bio); -else +if (erofs_is_fileio_mode (EROFS_SB (sb))) +erofs_fileio_submit_bio (bio); +else if (erofs_is_fscache_mode (sb))erofs_fscache_submit_bio (bio); +else +submit_bio (bio);if (memstall) {psi_memstall_leave (&pflags);
fs/erofs/zdata.c static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, · line 1643
Quoted 9 lines
fs/erofs/zdata.c +2
-4@@ -1637,10 +1639,13 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, }if (!bio) { - bio =erofs_is_fscache_mode (sb) ? -erofs_fscache_bio_alloc (&mdev) : -bio_alloc (mdev.m_bdev,BIO_MAX_VECS , -REQ_OP_READ ,GFP_NOIO ); +if (erofs_is_fileio_mode (EROFS_SB (sb))) + bio =erofs_fileio_bio_alloc (&mdev);
It seems erofs_fileio_bio_alloc() can fail, it needs to handle NULL bio here?
Thanks,
Quoted 24 lines
fs/erofs/zdata.c +10
-3+else if (erofs_is_fscache_mode (sb)) + bio =erofs_fscache_bio_alloc (&mdev); +else + bio =bio_alloc (mdev.m_bdev,BIO_MAX_VECS , +REQ_OP_READ ,GFP_NOIO ); bio->bi_end_io = z_erofs_endio; bio->bi_iter.bi_sector = cur >>9 ; bio->bi_private = q[JQ_SUBMIT ];@@ -1667,10 +1672,12 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, }while (owned_head !=Z_EROFS_PCLUSTER_TAIL );if (bio) { -if (!erofs_is_fscache_mode (sb)) -submit_bio (bio); -else +if (erofs_is_fileio_mode (EROFS_SB (sb))) +erofs_fileio_submit_bio (bio); +else if (erofs_is_fscache_mode (sb))erofs_fscache_submit_bio (bio); +else +submit_bio (bio);if (memstall)psi_memstall_leave (&pflags); }
Re: [PATCH v2 3/4] erofs: support compressed inodes for fileio
Quoted 118 lines · Chao Yu
Quoted 117 lines · Gao Xiang
Use pseudo bios just like the previous fscache approach since merged
bio_vecscan be filled properly with unique interfaces.Signed-off-by Gao Xiang <[email protected]>---
fs/erofs/fileio.c | 25 +++++++++++++++++++++---- fs/erofs/inode.c | 6 ------fs/erofs/internal.h| 8 ++++++++ fs/erofs/zdata.c | 27 +++++++++++++++++----------4 files changed, 46 insertions(+), 20 deletions(-)fs/erofs/fileio.c +21
-4@@ -23,7 +23,6 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) container_of(iocb, struct erofs_fileio_rq, iocb); struct folio_iter fi; - DBG_BUGON(rq->bio.bi_end_io); if (ret > 0) { if (ret != rq->bio.bi_iter.bi_size) { bio_advance(&rq->bio, ret);@@ -31,9 +30,13 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) } ret = 0; } - bio_for_each_folio_all(fi, &rq->bio) { - DBG_BUGON(folio_test_uptodate(fi.folio)); - erofs_onlinefolio_end(fi.folio, ret); + if (rq->bio.bi_end_io) { + rq->bio.bi_end_io(&rq->bio); + } else { + bio_for_each_folio_all(fi, &rq->bio) { + DBG_BUGON(folio_test_uptodate(fi.folio)); + erofs_onlinefolio_end(fi.folio, ret); + } } kfree(rq); }@@ -68,6 +71,20 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev) return rq; } +struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev) +{ + struct erofs_fileio_rq *rq; + + rq = erofs_fileio_rq_alloc(mdev); + return rq ? &rq->bio : NULL; +} + +void erofs_fileio_submit_bio (struct bio *bio) +{ + return erofs_fileio_rq_submit(container_of(bio, struct erofs_fileio_rq, + bio)); +} + static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio) { struct inode *inode = folio_inode(folio);fs/erofs/inode.c +0
-6@@ -260,12 +260,6 @@ static int erofs_fill_inode(struct inode *inode) mapping_set_large_folios(inode->i_mapping); if (erofs_inode_is_data_compressed(vi->datalayout)) { #ifdef CONFIG_EROFS_FS_ZIP -#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE - if (erofs_is_fileio_mode(EROFS_SB(inode->i_sb))) { - err = -EOPNOTSUPP; - goto out_unlock; - } -#endif DO_ONCE_LITE_IF(inode->i_blkbits != PAGE_SHIFT, erofs_info, inode->i_sb, "EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!");fs/erofs/internal.h +8
-0@@ -489,6 +489,14 @@ static inline void z_erofs_exit_subsystem(void) {} static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; } #endif /* !CONFIG_EROFS_FS_ZIP */ +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev); +void erofs_fileio_submit_bio (struct bio *bio); +#else +static inline struct bio *erofs_fileio_bio_alloc (struct erofs_map_dev *mdev) {return NULL ; } +static inline void erofs_fileio_submit_bio (struct bio *bio) {} +#endif + #ifdef CONFIG_EROFS_FS_ONDEMAND int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb);fs/erofs/zdata.c +0
-0@@ -1618,10 +1618,12 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,if (bio && (cur !=
last_pa||bio->bi_bdev!= mdev.m_bdev)) {io_retry:
- if (!erofs_is_fscache_mode(sb)) -submit_bio(bio);
- else
+ if (erofs_is_fileio_mode(EROFS_SB(sb))) +erofs_fileio_submit_bio(bio); + else if (erofs_is_fscache_mode(sb))erofs_fscache_submit_bio(bio); + else
+submit_bio(bio);
if (memstall) {psi_memstall_leave(&pflags);fs/erofs/zdata.c +0
-1@@ -1637,10 +1639,13 @@ static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, } if (!bio) { - bio = erofs_is_fscache_mode(sb) ?
Quoted 8 lines
fs/erofs/zdata.c static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, · line 1643
Quoted 5 lines
fs/erofs/zdata.c +2
-3- erofs_fscache_bio_alloc(&mdev) : - bio_alloc(mdev.m_bdev, BIO_MAX_VECS, - REQ_OP_READ, GFP_NOIO); + if (erofs_is_fileio_mode(EROFS_SB(sb))) + bio = erofs_fileio_bio_alloc(&mdev);It seems
erofs_fileio_bio_alloc()can fail, it needs to handle NULL bio here?
I will mark it as __GFP_NOFAIL too in the previous patch.
Thanks,
Gao Xiang
Re: [PATCH v2 3/4] erofs: support compressed inodes for fileio
In reply to Gao XiangQuoted 4 lines · Gao Xiang
Use pseudo bios just like the previous fscache approach since merged
bio_vecscan be filled properly with unique interfaces.Signed-off-by Gao Xiang <[email protected]>
Thanks,
PATCH v2 4/4 erofs: mark experimental fscache backend deprecated
In reply to Gao XiangAlthough fscache is still described as "General Filesystem Caching" for network filesystems and other things such as ISO9660 filesystems, it has actually become a part of netfslib recently, which was unexpected at the time when "EROFS over fscache" proposed (2021) since EROFS is entirely a disk filesystem and the dependency is redundant.
Mark it deprecated and it will be removed after "fanotify pre-content hooks" lands, which will provide the same functionality for EROFS.
--- fs/erofs/Kconfig | 5 ++++- fs/erofs/super.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
fs/erofs/Kconfig +4 -1
@@ -145,7 +145,7 @@ config EROFS_FS_ZIP_ZSTD If unsure, say N. config EROFS_FS_ONDEMAND - bool "EROFS fscache-based on-demand read support" + bool "EROFS fscache-based on-demand read support (deprecated)" depends on EROFS_FS select NETFS_SUPPORT select FSCACHE
@@ -155,6 +155,9 @@ config EROFS_FS_ONDEMAND This permits EROFS to use fscache-backed data blobs with on-demand read support. + It is now deprecated and scheduled to be removed from the kernel + after fanotify pre-content hooks are landed. + If unsure, say N. config EROFS_FS_PCPU_KTHREAD
fs/erofs/super.c +1 -1
@@ -353,7 +353,7 @@ static int erofs_read_superblock(struct super_block *sb) ret =erofs_scan_devices (sb, dsb);if (erofs_is_fscache_mode (sb)) -erofs_info (sb,"EXPERIMENTAL fscache-based on-demand read feature in use. Use at your own risk!" ); +erofs_info (sb,"[deprecated] fscache-based on-demand read feature in use. Use at your own risk!" ); out:erofs_put_metabuf (&buf);return ret;
Signature · 1 line
2.43.5
Re: [PATCH v2 4/4] erofs: mark experimental fscache backend deprecated
Thanks,
Sandeep.
Re: [PATCH v2 4/4] erofs: mark experimental fscache backend deprecated
In reply to Gao XiangQuoted 10 lines · Gao Xiang
Although fscache is still described as "General Filesystem Caching" for network filesystems and other things such as ISO9660 filesystems, it has actually become a part of netfslib recently, which was unexpected at the time when "EROFS over fscache" proposed (2021) since EROFS is entirely a disk filesystem and the dependency is redundant.
Mark it deprecated and it will be removed after "fanotify pre-content hooks" lands, which will provide the same functionality for EROFS.
Signed-off-by Gao Xiang <[email protected]>
Thanks,
Sandeep Dhavale
reviewerQuoted 5 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Quoted 11 lines
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
Hi Gao,
Thank you for the series! This is an interesting idea and will definitely help the Android ecosystem for APEXes if we can remove the loopback device. I will take a deeper look and provide comments soon.
Thanks,
Sandeep.
Quoted 360 lines
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>---
v2:
- should usekill_anon_super();
- addO_LARGEFILEto support large files.fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)fs/erofs/Kconfig +17
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N. +config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default y + help + This allows EROFS to use filesystem image files directly, without + the intercession of loopback block devices or likewise. It is + particularly useful for container images with numerous blobs and + other sandboxes, where loop devices behave intricately. It can also + be used to simplify error-prone lifetime management of unnecessary + virtual block devices. + + Note that this feature, along with ongoing fanotify pre-content + hooks, will eventually replace "EROFS over fscache." + + If you don't want to enable this feature, say N. + config EROFS_FS_ZIP bool "EROFS Data Compression Support" depends on EROFS_FSfs/erofs/data.c +21
-14@@ -59,8 +59,12 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,void erofs_init_metabuf (struct erofs_buf *buf,struct super_block *sb) { -if (erofs_is_fscache_mode (sb)) - buf->mapping =EROFS_SB (sb)->s_fscache->inode->i_mapping; +struct erofs_sb_info *sbi =EROFS_SB (sb); + +if (erofs_is_fileio_mode (sbi)) + buf->mapping =file_inode (sbi->fdev)->i_mapping; +else if (erofs_is_fscache_mode (sb)) + buf->mapping = sbi->s_fscache->inode->i_mapping;else buf->mapping = sb->s_bdev->bd_mapping; }@@ -189,10 +193,22 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)return err; } +static void erofs_fill_from_devinfo (struct erofs_map_dev *map, +struct erofs_device_info *dif) +{ + map->m_bdev =NULL ; +if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); + map->m_daxdev = dif->dax_dev; + map->m_dax_part_off = dif->dax_part_off; + map->m_fscache = dif->fscache; +} +int erofs_map_dev (struct super_block *sb,struct erofs_map_dev *map) {struct erofs_dev_context *devs =EROFS_SB (sb)->devs;struct erofs_device_info *dif; +erofs_off_t startoff, length;int id; map->m_bdev = sb->s_bdev;@@ -212,29 +228,20 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)up_read (&devs->rwsem);return 0 ; } - map->m_bdev = dif->bdev_file ?file_bdev (dif->bdev_file) :NULL ; - map->m_daxdev = dif->dax_dev; - map->m_dax_part_off = dif->dax_part_off; - map->m_fscache = dif->fscache; +erofs_fill_from_devinfo (map, dif);up_read (&devs->rwsem); }else if (devs->extra_devices && !devs->flatdev) {down_read (&devs->rwsem);idr_for_each_entry (&devs->tree, dif, id) { -erofs_off_t startoff, length; -if (!dif->mapped_blkaddr)continue ; + startoff =erofs_pos (sb, dif->mapped_blkaddr); length =erofs_pos (sb, dif->blocks); -if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; - map->m_bdev = dif->bdev_file ? -file_bdev (dif->bdev_file) :NULL ; - map->m_daxdev = dif->dax_dev; - map->m_dax_part_off = dif->dax_part_off; - map->m_fscache = dif->fscache; +erofs_fill_from_devinfo (map, dif);break ; } }fs/erofs/inode.c +4
-1@@ -258,7 +258,10 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { +/* XXX: data I/Os will be implemented in the following patches */ + err = -EOPNOTSUPP ; + }else if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP DO_ONCE_LITE_IF(inode->i_blkbits != PAGE_SHIFT, erofs_info, inode->i_sb,fs/erofs/internal.h +9
-2@@ -49,7 +49,7 @@ typedef u32 erofs_blk_t;struct erofs_device_info {char *path;struct erofs_fscache *fscache; -struct file *bdev_file; +struct file *file;struct dax_device *dax_dev;u64 dax_part_off;@@ -130,6 +130,7 @@ struct erofs_sb_info {struct erofs_sb_lz4_info lz4;#endif /* CONFIG_EROFS_FS_ZIP */ +struct file *fdev;struct inode *packed_inode;struct erofs_dev_context *devs;struct dax_device *dax_dev;@@ -190,9 +191,15 @@ struct erofs_sb_info {#define set_opt (opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)#define test_opt (opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option) +static inline bool erofs_is_fileio_mode (struct erofs_sb_info *sbi) +{ +return IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) && sbi->fdev; +} +static inline bool erofs_is_fscache_mode (struct super_block *sb) { -return IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && !sb->s_bdev; +return IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && + !erofs_is_fileio_mode (EROFS_SB (sb)) && !sb->s_bdev; }enum {fs/erofs/super.c +49
-28@@ -10,6 +10,7 @@#include <linux/fs_context.h> #include <linux/fs_parser.h> #include <linux/exportfs.h> +#include <linux/backing-dev.h> #include "xattr.h" #define CREATE_TRACE_POINTS @@ -161,7 +162,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,struct erofs_sb_info *sbi =EROFS_SB (sb);struct erofs_fscache *fscache;struct erofs_deviceslot *dis; -struct file *bdev_file; +struct file *file; dis =erofs_read_metabuf (buf, sb, *pos,EROFS_KMAP );if (IS_ERR (dis))@@ -183,13 +184,17 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,return PTR_ERR (fscache); dif->fscache = fscache; }else if (!sbi->devs->flatdev) { - bdev_file =bdev_file_open_by_path (dif->path,BLK_OPEN_READ , - sb->s_type,NULL ); -if (IS_ERR (bdev_file)) -return PTR_ERR (bdev_file); - dif->bdev_file = bdev_file; - dif->dax_dev =fs_dax_get_by_bdev (file_bdev (bdev_file), - &dif->dax_part_off,NULL ,NULL ); + file =erofs_is_fileio_mode (sbi) ? +filp_open (dif->path,O_RDONLY |O_LARGEFILE ,0 ) : +bdev_file_open_by_path (dif->path, +BLK_OPEN_READ , sb->s_type,NULL ); +if (IS_ERR (file)) +return PTR_ERR (file); + + dif->file = file; +if (!erofs_is_fileio_mode (sbi)) + dif->dax_dev =fs_dax_get_by_bdev (file_bdev (file), + &dif->dax_part_off,NULL ,NULL ); } dif->blocks =le32_to_cpu (dis->blocks);@@ -566,15 +571,16 @@ static void erofs_set_sysfs_name(struct super_block *sb) {struct erofs_sb_info *sbi =EROFS_SB (sb); -if (erofs_is_fscache_mode (sb)) { -if (sbi->domain_id) -super_set_sysfs_name_generic (sb,"%s,%s" ,sbi->domain_id, - sbi->fsid); -else -super_set_sysfs_name_generic (sb,"%s" , sbi->fsid); -return ; - } -super_set_sysfs_name_id (sb); +if (sbi->domain_id) +super_set_sysfs_name_generic (sb,"%s,%s" , sbi->domain_id, + sbi->fsid); +else if (sbi->fsid) +super_set_sysfs_name_generic (sb,"%s" , sbi->fsid); +else if (erofs_is_fileio_mode (sbi)) +super_set_sysfs_name_generic (sb,"%s" , +bdi_dev_name (sb->s_bdi)); +else +super_set_sysfs_name_id (sb); }static int erofs_fc_fill_super (struct super_block *sb,struct fs_context *fc)@@ -589,14 +595,15 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_op = &erofs_sops; sbi->blkszbits =PAGE_SHIFT ; -if (erofs_is_fscache_mode (sb)) { +if (!sb->s_bdev) { sb->s_blocksize =PAGE_SIZE ; sb->s_blocksize_bits =PAGE_SHIFT ; - err =erofs_fscache_register_fs (sb); -if (err) -return err; - +if (erofs_is_fscache_mode (sb)) { + err =erofs_fscache_register_fs (sb); +if (err) +return err; + } err =super_setup_bdi (sb);if (err)return err;@@ -693,11 +700,24 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)static int erofs_fc_get_tree (struct fs_context *fc) {struct erofs_sb_info *sbi = fc->s_fs_info; +int ret;if (IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && sbi->fsid)return get_tree_nodev (fc, erofs_fc_fill_super); -return get_tree_bdev (fc, erofs_fc_fill_super); + ret =get_tree_bdev (fc, erofs_fc_fill_super); +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (ret == -ENOTBLK ) { +if (!fc->source) +return invalf (fc,"No source specified" ); + sbi->fdev =filp_open (fc->source,O_RDONLY |O_LARGEFILE ,0 ); +if (IS_ERR (sbi->fdev)) +return PTR_ERR (sbi->fdev); + +return get_tree_nodev (fc, erofs_fc_fill_super); + } +#endif +return ret; }static int erofs_fc_reconfigure (struct fs_context *fc)@@ -727,8 +747,8 @@ static int erofs_release_device_info(int id, void *ptr, void *data)struct erofs_device_info *dif = ptr;fs_put_dax (dif->dax_dev,NULL ); -if (dif->bdev_file) -fput (dif->bdev_file); +if (dif->file) +fput (dif->file);erofs_fscache_unregister_cookie (dif->fscache); dif->fscache =NULL ;kfree (dif->path);@@ -791,7 +811,7 @@ static void erofs_kill_sb(struct super_block *sb) {struct erofs_sb_info *sbi =EROFS_SB (sb); -if (IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && sbi->fsid) +if ((IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && sbi->fsid) || sbi->fdev)kill_anon_super (sb);else kill_block_super (sb);@@ -801,6 +821,8 @@ static void erofs_kill_sb(struct super_block *sb)erofs_fscache_unregister_fs (sb);kfree (sbi->fsid);kfree (sbi->domain_id); +if (sbi->fdev) +fput (sbi->fdev);kfree (sbi); sb->s_fs_info =NULL ; }@@ -903,7 +925,7 @@ static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_namelen =EROFS_NAME_LEN ;if (uuid_is_null (&sb->s_uuid)) - buf->f_fsid =u64_to_fsid (erofs_is_fscache_mode (sb) ?0 : + buf->f_fsid =u64_to_fsid (!sb->s_bdev ?0 :huge_encode_dev (sb->s_bdev->bd_dev));else buf->f_fsid =uuid_to_fsid (sb->s_uuid.b); --2.43.5
Hi Sandeep,
Quoted 17 lines · Sandeep Dhavale via Linux-erofs
Quoted 5 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Quoted 11 lines
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
Quoted 4 lines
Hi Gao,
Thank you for the series! This is an interesting idea and will definitely help the Android ecosystem for APEXes if we can remove the loopback device. I will take a deeper look and provide comments soon.
Yes, I've seen no issue so far, and it will be submited for 6.12 since there are many users which really need this and wait for it.
Thanks,
Gao Xiang
Thanks,
Sandeep.
Quoted 39 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
Quoted 7 lines
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>
Thanks,
PATCH v3 2/4 erofs: support unencoded inodes for fileio
In reply to Gao XiangSince EROFS only needs to handle read requests in simple contexts, Just directly use vfs_iocb_iter_read() for data I/Os.
---
changes since v2 (Chao):
- erofs_fileio_rq_alloc() always succeeds;
- use SECTOR_SHIFT constant.
fs/erofs/Makefile | 1 + fs/erofs/data.c | 50 ++++++++++++- fs/erofs/fileio.c | 177 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 17 +++-- fs/erofs/internal.h | 7 +- fs/erofs/zdata.c | 46 ++---------- 6 files changed, 247 insertions(+), 51 deletions(-) create mode 100644 fs/erofs/fileio.c
fs/erofs/Makefile +1 -0
@@ -7,4 +7,5 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o
fs/erofs/data.c +46 -4
80 lines not on this page · raw message
fs/erofs/fileio.c new file +177 -0
177 lines not on this page · raw message
fs/erofs/inode.c +12 -5
@@ -258,11 +258,14 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { -/* XXX: data I/Os will be implemented in the following patches */ - err = -EOPNOTSUPP ; - }else if (erofs_inode_is_data_compressed (vi->datalayout)) { +if (erofs_inode_is_data_compressed (vi->datalayout)) {#ifdef CONFIG_EROFS_FS_ZIP +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) { + err = -EOPNOTSUPP ; + goto out_unlock; + } +#endif DO_ONCE_LITE_IF (inode->i_blkbits !=PAGE_SHIFT , erofs_info, inode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" );
@@ -271,10 +274,14 @@ static int erofs_fill_inode(struct inode *inode) err = -EOPNOTSUPP ;#endif }else { - inode->i_mapping->a_ops = &erofs_raw_access_aops; + inode->i_mapping->a_ops = &erofs_aops;#ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode (inode->i_sb)) inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (erofs_is_fileio_mode (EROFS_SB (inode->i_sb))) + inode->i_mapping->a_ops = &erofs_fileio_aops;#endif } out_unlock:
fs/erofs/internal.h +6 -1
@@ -372,6 +372,7 @@ struct erofs_map_dev {struct erofs_fscache *m_fscache;struct block_device *m_bdev;struct dax_device *m_daxdev; +struct file *m_fp;u64 m_dax_part_off;erofs_off_t m_pa;
@@ -380,7 +381,8 @@ struct erofs_map_dev {extern const struct super_operations erofs_sops; -extern const struct address_space_operations erofs_raw_access_aops; +extern const struct address_space_operations erofs_aops; +extern const struct address_space_operations erofs_fileio_aops;extern const struct address_space_operations z_erofs_aops;extern const struct address_space_operations erofs_fscache_access_aops;
@@ -411,6 +413,9 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);int erofs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len);int erofs_map_blocks (struct inode *inode,struct erofs_map_blocks *map); +void erofs_onlinefolio_init (struct folio *folio); +void erofs_onlinefolio_split (struct folio *folio); +void erofs_onlinefolio_end (struct folio *folio,int err);struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid); int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask,
fs/erofs/zdata.c +5 -41
82 lines not on this page · raw message
Signature · 1 line
2.43.5
Re: [PATCH v3 2/4] erofs: support unencoded inodes for fileio
Quoted 5 lines · Gao Xiang
Since EROFS only needs to handle read requests in simple contexts, Just directly use
vfs_iocb_iter_read()for data I/Os.Reviewed-by Sandeep Dhavale <[email protected]>Signed-off-by Gao Xiang <[email protected]>
Thanks,
Hi Gao,
CC vfs
Quoted 39 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
Quoted 7 lines
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>
Thanks for your patch, which is now commit fb176750266a3d7f ("erofs: add file-backed mount support").
Quoted 17 lines
---
v2:
- should usekill_anon_super();
- addO_LARGEFILEto support large files.fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)fs/erofs/Kconfig +0
-0
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 80
Quoted 7 lines
fs/erofs/Kconfig +4
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N. +config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default y
I am a bit reluctant to have this default to y, without an ack from the VFS maintainers.
Quoted 6 lines
fs/erofs/Kconfig +6
-0+ help + This allows EROFS to use filesystem image files directly, without + the intercession of loopback block devices or likewise. It is + particularly useful for container images with numerous blobs and + other sandboxes, where loop devices behave intricately. It can also + be used to simplify error-prone lifetime management of unnecessary
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 96
Quoted 10 lines
fs/erofs/Kconfig +7
-0+ virtual block devices. + + Note that this feature, along with ongoing fanotify pre-content + hooks, will eventually replace "EROFS over fscache." + + If you don't want to enable this feature, say N. + config EROFS_FS_ZIP bool "EROFS Data Compression Support" depends on EROFS_FS
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Hi Geert,
Quoted 75 lines · Geert Uytterhoeven
Hi Gao,
CC vfs
Quoted 39 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
Quoted 7 lines
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>Thanks for your patch, which is now commit
fb176750266a3d7f("erofs: add file-backed mount support").Quoted 20 lines
---
v2:
- should usekill_anon_super();
- addO_LARGEFILEto support large files.fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)fs/erofs/Kconfig +0
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N.
Quoted 7 lines
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 80
Quoted 4 lines
fs/erofs/Kconfig +4
-0+config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default yI am a bit reluctant to have this default to y, without an ack from the VFS maintainers.
It don't touch any VFS stuffs so I didn't cc -fsdevel.
Okay, if VFS maintainers have any objection of this, I could turn it into "default n", if not, I tend to leave it as "y" since I believe it shouldn't be any risk of this feature (since EROFS is only an immutable filesystem and I don't think out a context which could be risky) with clear use cases and I've clearly documented and showed in the commit message and upstream pull request.
Thanks,
Gao Xiang
Jan Kara
reviewerHi!
Quoted 71 lines · Geert Uytterhoeven
Quoted 39 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
Quoted 7 lines
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>Thanks for your patch, which is now commit
fb176750266a3d7f("erofs: add file-backed mount support").Quoted 20 lines
---
v2:
- should usekill_anon_super();
- addO_LARGEFILEto support large files.fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)fs/erofs/Kconfig +0
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N.
Quoted 7 lines
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 80
Quoted 4 lines
fs/erofs/Kconfig +4
-0+config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default yI am a bit reluctant to have this default to y, without an ack from the VFS maintainers.
Well, we generally let filesystems do whatever they decide to do unless it is a affecting stability / security / maintainability of the whole system. In this case I don't see anything that would be substantially different than if we go through a loop device. So although the feature looks somewhat unusual I don't see a reason to nack it or otherwise interfere with whatever the fs maintainer wants to do. Are you concerned about a particular problem?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Hi Jan,
Quoted 80 lines · Jan Kara
Quoted 71 lines · Geert Uytterhoeven
Quoted 39 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
Quoted 7 lines
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>Thanks for your patch, which is now commit
fb176750266a3d7f("erofs: add file-backed mount support").Quoted 20 lines
---
v2:
- should usekill_anon_super();
- addO_LARGEFILEto support large files.fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)fs/erofs/Kconfig +0
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N.Quoted 7 lines
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 80
Quoted 4 lines
fs/erofs/Kconfig +4
-0+config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default yI am a bit reluctant to have this default to y, without an ack from the VFS maintainers.
Quoted 7 lines
Well, we generally let filesystems do whatever they decide to do unless it is a affecting stability / security / maintainability of the whole system. In this case I don't see anything that would be substantially different than if we go through a loop device. So although the feature looks somewhat unusual I don't see a reason to nack it or otherwise interfere with whatever the fs maintainer wants to do. Are you concerned about a particular problem?
I was just wondering if there are any issues with accessing files directly. If you're fine with it, I am, too.
Thanks!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Christian Brauner
maintainerQuoted 82 lines · Jan Kara
Hi!
Quoted 71 lines · Geert Uytterhoeven
Quoted 39 lines · Gao Xiang
It actually has been around for years: For containers and other sandbox use cases, there will be thousands (and even more) of authenticated (sub)images running on the same host, unlike OS images.
Of course, all scenarios can use the same EROFS on-disk format, but bdev-backed mounts just work well for OS images since golden data is dumped into real block devices. However, it's somewhat hard for container runtimes to manage and isolate so many unnecessary virtual block devices safely and efficiently [1]: they just look like a burden to orchestrators and file-backed mounts are preferred indeed. There were already enough attempts such as Incremental FS, the original ComposeFS and PuzzleFS acting in the same way for immutable fses. As for current EROFS users, ComposeFS, containerd and Android APEXs will be directly benefited from it.
On the other hand, previous experimental feature "erofs over fscache" was once also intended to provide a similar solution (inspired by Incremental FS discussion [2]), but the following facts show file-backed mounts will be a better approach:
- Fscache infrastructure has recently been moved into new Netfslib which is an unexpected dependency to EROFS really, although it originally claims "it could be used for caching other things such as ISO9660 filesystems too." [3]- It takes an unexpectedly long time to upstream Fscache/Cachefiles enhancements. For example, the failover feature took more than one year, and the deamonless feature is still far behind now;
- Ongoing HSM "fanotify pre-content hooks" [4] together with this will perfectly supersede "erofs over fscache" in a simpler way since developers (mainly containerd folks) could leverage their existing caching mechanism entirely in userspace instead of strictly following the predefined in-kernel caching tree hierarchy.
After "fanotify pre-content hooks" lands upstream to provide the same functionality, "erofs over fscache" will be removed then (as an EROFS internal improvement and EROFS will not have to bother with on-demand fetching and/or caching improvements anymore.)
Quoted 7 lines
[1] https://github.com/containers/storage/pull/2039
[2] https://lore.kernel.org/r/CAOQ4uxjbVxnubaPjVaGYiSwoGDTdpWbB=w_AeM6YM=zVixsUfQ@mail.gmail.com
[3] https://docs.kernel.org/filesystems/caching/fscache.html
[4] https://lore.kernel.org/r/[email protected]Signed-off-by Gao Xiang <[email protected]>Thanks for your patch, which is now commit
fb176750266a3d7f("erofs: add file-backed mount support").Quoted 20 lines
---
v2:
- should usekill_anon_super();
- addO_LARGEFILEto support large files.fs/erofs/Kconfig | 17 ++++++++++ fs/erofs/data.c | 35 ++++++++++++--------- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 11 +++++-- fs/erofs/super.c | 76 +++++++++++++++++++++++++++++---------------- 5 files changed, 100 insertions(+), 44 deletions(-)fs/erofs/Kconfig +0
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N.Quoted 7 lines
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 80
Quoted 4 lines
fs/erofs/Kconfig +4
-0+config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default yI am a bit reluctant to have this default to y, without an ack from the VFS maintainers.
Quoted 7 lines
Well, we generally let filesystems do whatever they decide to do unless it is a affecting stability / security / maintainability of the whole system. In this case I don't see anything that would be substantially different than if we go through a loop device. So although the feature looks somewhat unusual I don't see a reason to nack it or otherwise interfere with whatever the fs maintainer wants to do. Are you concerned about a particular problem?
I see no reason to nak it either.
Quoted 1 line · Christian Brauner
On Mon, Sep 30, 2024 at 04:18:19PM GMT, Jan Kara wrote:
..
Quoted 25 lines
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
fs/erofs/Kconfig +0
-0@@ -74,6 +74,23 @@ config EROFS_FS_SECURITY If you are not using a security module, say N.Quoted 7 lines
fs/erofs/Kconfig config EROFS_FS_SECURITY · line 80
Quoted 4 lines
fs/erofs/Kconfig +4
-0+config EROFS_FS_BACKED_BY_FILE + bool "File-backed EROFS filesystem support" + depends on EROFS_FS + default yI am a bit reluctant to have this default to y, without an ack from the VFS maintainers.
Quoted 7 lines
Well, we generally let filesystems do whatever they decide to do unless it is a affecting stability / security / maintainability of the whole system. In this case I don't see anything that would be substantially different than if we go through a loop device. So although the feature looks somewhat unusual I don't see a reason to nack it or otherwise interfere with whatever the fs maintainer wants to do. Are you concerned about a particular problem?
Quoted 1 line
I see no reason to nak it either.
Thanks all for taking time on writing down these!
Unfortunately, fanotify pre-content hooks was't landed in 6.12 cycle (which I think will be used in a lot of scenarios)..
I do hope it could be landed in the next cycle so I could clean up the codebase then.
Thanks,
Gao Xiang