2019-07-31 23:57:31 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2018-07-26 20:21:47 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
2020-07-13 15:09:44 +02:00
|
|
|
* https://www.huawei.com/
|
2021-08-20 18:00:19 +08:00
|
|
|
* Copyright (C) 2021, Alibaba Cloud
|
2018-07-26 20:21:47 +08:00
|
|
|
*/
|
|
|
|
|
#include "internal.h"
|
2026-01-08 12:12:59 -05:00
|
|
|
#include <linux/filelock.h>
|
2022-04-25 20:21:39 +08:00
|
|
|
#include <linux/sched/mm.h>
|
2018-07-26 20:21:55 +08:00
|
|
|
#include <trace/events/erofs.h>
|
|
|
|
|
|
2022-01-02 12:00:13 +08:00
|
|
|
void erofs_unmap_metabuf(struct erofs_buf *buf)
|
|
|
|
|
{
|
2024-11-14 17:58:13 +08:00
|
|
|
if (!buf->base)
|
|
|
|
|
return;
|
|
|
|
|
kunmap_local(buf->base);
|
2022-01-02 12:00:13 +08:00
|
|
|
buf->base = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void erofs_put_metabuf(struct erofs_buf *buf)
|
|
|
|
|
{
|
|
|
|
|
if (!buf->page)
|
|
|
|
|
return;
|
|
|
|
|
erofs_unmap_metabuf(buf);
|
2024-07-23 15:30:24 +08:00
|
|
|
folio_put(page_folio(buf->page));
|
2022-01-02 12:00:13 +08:00
|
|
|
buf->page = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 04:31:41 -05:00
|
|
|
void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
|
2022-01-02 12:00:13 +08:00
|
|
|
{
|
2025-05-17 17:05:43 +08:00
|
|
|
pgoff_t index = (buf->off + offset) >> PAGE_SHIFT;
|
2024-07-23 15:30:24 +08:00
|
|
|
struct folio *folio = NULL;
|
2022-01-02 12:00:13 +08:00
|
|
|
|
2024-07-23 15:30:24 +08:00
|
|
|
if (buf->page) {
|
|
|
|
|
folio = page_folio(buf->page);
|
|
|
|
|
if (folio_file_page(folio, index) != buf->page)
|
|
|
|
|
erofs_unmap_metabuf(buf);
|
|
|
|
|
}
|
|
|
|
|
if (!folio || !folio_contains(folio, index)) {
|
2022-01-02 12:00:13 +08:00
|
|
|
erofs_put_metabuf(buf);
|
2024-11-15 07:49:05 +08:00
|
|
|
folio = read_mapping_folio(buf->mapping, index, buf->file);
|
2022-04-25 20:21:39 +08:00
|
|
|
if (IS_ERR(folio))
|
|
|
|
|
return folio;
|
2022-01-02 12:00:13 +08:00
|
|
|
}
|
2024-07-23 15:30:24 +08:00
|
|
|
buf->page = folio_file_page(folio, index);
|
2025-02-17 04:31:41 -05:00
|
|
|
if (!need_kmap)
|
2022-01-02 12:00:13 +08:00
|
|
|
return NULL;
|
2025-02-17 04:31:41 -05:00
|
|
|
if (!buf->base)
|
|
|
|
|
buf->base = kmap_local_page(buf->page);
|
2022-01-02 12:00:13 +08:00
|
|
|
return buf->base + (offset & ~PAGE_MASK);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 08:32:29 +08:00
|
|
|
int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb,
|
|
|
|
|
bool in_metabox)
|
2023-04-07 22:17:04 +08:00
|
|
|
{
|
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/cover.1723670362.git.josef@toxicpanda.com
Closes: https://github.com/containers/composefs/issues/144
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240830032840.3783206-1-hsiangkao@linux.alibaba.com
2024-08-30 11:28:37 +08:00
|
|
|
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
|
|
|
|
2024-11-15 07:49:05 +08:00
|
|
|
buf->file = NULL;
|
2025-07-22 08:32:29 +08:00
|
|
|
if (in_metabox) {
|
|
|
|
|
if (unlikely(!sbi->metabox_inode))
|
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
|
buf->mapping = sbi->metabox_inode->i_mapping;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-05-17 17:05:43 +08:00
|
|
|
buf->off = sbi->dif0.fsoff;
|
2024-11-15 07:49:05 +08:00
|
|
|
if (erofs_is_fileio_mode(sbi)) {
|
2024-12-16 20:53:08 +08:00
|
|
|
buf->file = sbi->dif0.file; /* some fs like FUSE needs it */
|
2024-11-15 07:49:05 +08:00
|
|
|
buf->mapping = buf->file->f_mapping;
|
|
|
|
|
} else if (erofs_is_fscache_mode(sb))
|
2024-12-16 20:53:08 +08:00
|
|
|
buf->mapping = sbi->dif0.fscache->inode->i_mapping;
|
2023-04-07 22:17:04 +08:00
|
|
|
else
|
2024-04-11 15:53:37 +01:00
|
|
|
buf->mapping = sb->s_bdev->bd_mapping;
|
2025-07-22 08:32:29 +08:00
|
|
|
return 0;
|
2023-04-07 22:17:04 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-16 09:22:45 +08:00
|
|
|
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
|
2025-07-22 08:32:29 +08:00
|
|
|
erofs_off_t offset, bool in_metabox)
|
2022-03-16 09:22:45 +08:00
|
|
|
{
|
2025-07-22 08:32:29 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = erofs_init_metabuf(buf, sb, in_metabox);
|
|
|
|
|
if (err)
|
|
|
|
|
return ERR_PTR(err);
|
2025-07-14 17:09:06 +08:00
|
|
|
return erofs_bread(buf, offset, true);
|
2022-03-16 09:22:45 +08:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 10:48:25 +08:00
|
|
|
int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map)
|
2021-08-20 18:00:19 +08:00
|
|
|
{
|
2025-03-10 17:54:51 +08:00
|
|
|
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
|
2021-08-20 18:00:19 +08:00
|
|
|
struct super_block *sb = inode->i_sb;
|
2025-03-10 17:54:51 +08:00
|
|
|
unsigned int unit, blksz = sb->s_blocksize;
|
2021-08-20 18:00:19 +08:00
|
|
|
struct erofs_inode *vi = EROFS_I(inode);
|
|
|
|
|
struct erofs_inode_chunk_index *idx;
|
2025-03-10 17:54:54 +08:00
|
|
|
erofs_blk_t startblk, addrmask;
|
2025-03-10 17:54:51 +08:00
|
|
|
bool tailpacking;
|
2021-08-20 18:00:19 +08:00
|
|
|
erofs_off_t pos;
|
2025-03-10 17:54:51 +08:00
|
|
|
u64 chunknr;
|
2021-08-20 18:00:19 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
2023-02-09 10:48:25 +08:00
|
|
|
trace_erofs_map_blocks_enter(inode, map, 0);
|
2021-10-14 16:10:10 +08:00
|
|
|
map->m_deviceid = 0;
|
2025-03-10 17:54:51 +08:00
|
|
|
map->m_flags = 0;
|
|
|
|
|
if (map->m_la >= inode->i_size)
|
2021-08-20 18:00:19 +08:00
|
|
|
goto out;
|
|
|
|
|
|
2021-12-09 09:29:18 +08:00
|
|
|
if (vi->datalayout != EROFS_INODE_CHUNK_BASED) {
|
2025-03-10 17:54:51 +08:00
|
|
|
tailpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
|
2025-03-10 17:54:54 +08:00
|
|
|
if (!tailpacking && vi->startblk == EROFS_NULL_ADDR)
|
|
|
|
|
goto out;
|
2025-03-10 17:54:51 +08:00
|
|
|
pos = erofs_pos(sb, erofs_iblks(inode) - tailpacking);
|
|
|
|
|
|
|
|
|
|
map->m_flags = EROFS_MAP_MAPPED;
|
|
|
|
|
if (map->m_la < pos) {
|
2025-03-10 17:54:53 +08:00
|
|
|
map->m_pa = erofs_pos(sb, vi->startblk) + map->m_la;
|
2025-03-10 17:54:51 +08:00
|
|
|
map->m_llen = pos - map->m_la;
|
|
|
|
|
} else {
|
|
|
|
|
map->m_pa = erofs_iloc(inode) + vi->inode_isize +
|
|
|
|
|
vi->xattr_isize + erofs_blkoff(sb, map->m_la);
|
|
|
|
|
map->m_llen = inode->i_size - map->m_la;
|
|
|
|
|
map->m_flags |= EROFS_MAP_META;
|
|
|
|
|
}
|
2021-12-09 09:29:18 +08:00
|
|
|
goto out;
|
|
|
|
|
}
|
2021-08-20 18:00:19 +08:00
|
|
|
|
|
|
|
|
if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
|
|
|
|
|
unit = sizeof(*idx); /* chunk index */
|
|
|
|
|
else
|
|
|
|
|
unit = EROFS_BLOCK_MAP_ENTRY_SIZE; /* block map */
|
|
|
|
|
|
|
|
|
|
chunknr = map->m_la >> vi->chunkbits;
|
2023-01-14 23:08:23 +08:00
|
|
|
pos = ALIGN(erofs_iloc(inode) + vi->inode_isize +
|
2021-08-20 18:00:19 +08:00
|
|
|
vi->xattr_isize, unit) + unit * chunknr;
|
|
|
|
|
|
2025-07-22 08:32:29 +08:00
|
|
|
idx = erofs_read_metabuf(&buf, sb, pos, erofs_inode_in_metabox(inode));
|
2025-03-10 17:54:51 +08:00
|
|
|
if (IS_ERR(idx)) {
|
|
|
|
|
err = PTR_ERR(idx);
|
2021-12-09 09:29:18 +08:00
|
|
|
goto out;
|
|
|
|
|
}
|
2021-08-20 18:00:19 +08:00
|
|
|
map->m_la = chunknr << vi->chunkbits;
|
2025-03-10 17:54:51 +08:00
|
|
|
map->m_llen = min_t(erofs_off_t, 1UL << vi->chunkbits,
|
|
|
|
|
round_up(inode->i_size - map->m_la, blksz));
|
|
|
|
|
if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES) {
|
2025-03-10 17:54:54 +08:00
|
|
|
addrmask = (vi->chunkformat & EROFS_CHUNK_FORMAT_48BIT) ?
|
|
|
|
|
BIT_ULL(48) - 1 : BIT_ULL(32) - 1;
|
|
|
|
|
startblk = (((u64)le16_to_cpu(idx->startblk_hi) << 32) |
|
|
|
|
|
le32_to_cpu(idx->startblk_lo)) & addrmask;
|
|
|
|
|
if ((startblk ^ EROFS_NULL_ADDR) & addrmask) {
|
2025-03-10 17:54:51 +08:00
|
|
|
map->m_deviceid = le16_to_cpu(idx->device_id) &
|
|
|
|
|
EROFS_SB(sb)->device_id_mask;
|
|
|
|
|
map->m_pa = erofs_pos(sb, startblk);
|
|
|
|
|
map->m_flags = EROFS_MAP_MAPPED;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
startblk = le32_to_cpu(*(__le32 *)idx);
|
2025-03-10 17:54:54 +08:00
|
|
|
if (startblk != (u32)EROFS_NULL_ADDR) {
|
2025-03-10 17:54:51 +08:00
|
|
|
map->m_pa = erofs_pos(sb, startblk);
|
2021-08-20 18:00:19 +08:00
|
|
|
map->m_flags = EROFS_MAP_MAPPED;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-02 12:00:13 +08:00
|
|
|
erofs_put_metabuf(&buf);
|
2021-08-20 18:00:19 +08:00
|
|
|
out:
|
2025-03-10 17:54:51 +08:00
|
|
|
if (!err) {
|
|
|
|
|
map->m_plen = map->m_llen;
|
|
|
|
|
/* inline data should be located in the same meta block */
|
|
|
|
|
if ((map->m_flags & EROFS_MAP_META) &&
|
|
|
|
|
erofs_blkoff(sb, map->m_pa) + map->m_plen > blksz) {
|
|
|
|
|
erofs_err(sb, "inline data across blocks @ nid %llu", vi->nid);
|
|
|
|
|
DBG_BUGON(1);
|
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-09 10:48:25 +08:00
|
|
|
trace_erofs_map_blocks_exit(inode, map, 0, err);
|
2021-08-20 18:00:19 +08:00
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
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/cover.1723670362.git.josef@toxicpanda.com
Closes: https://github.com/containers/composefs/issues/144
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240830032840.3783206-1-hsiangkao@linux.alibaba.com
2024-08-30 11:28:37 +08:00
|
|
|
static void erofs_fill_from_devinfo(struct erofs_map_dev *map,
|
2024-12-13 07:54:01 +08:00
|
|
|
struct super_block *sb, struct erofs_device_info *dif)
|
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/cover.1723670362.git.josef@toxicpanda.com
Closes: https://github.com/containers/composefs/issues/144
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240830032840.3783206-1-hsiangkao@linux.alibaba.com
2024-08-30 11:28:37 +08:00
|
|
|
{
|
2024-12-13 07:54:01 +08:00
|
|
|
map->m_sb = sb;
|
|
|
|
|
map->m_dif = dif;
|
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/cover.1723670362.git.josef@toxicpanda.com
Closes: https://github.com/containers/composefs/issues/144
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240830032840.3783206-1-hsiangkao@linux.alibaba.com
2024-08-30 11:28:37 +08:00
|
|
|
map->m_bdev = NULL;
|
2024-12-13 07:54:01 +08:00
|
|
|
if (dif->file && S_ISBLK(file_inode(dif->file)->i_mode))
|
|
|
|
|
map->m_bdev = file_bdev(dif->file);
|
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/cover.1723670362.git.josef@toxicpanda.com
Closes: https://github.com/containers/composefs/issues/144
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240830032840.3783206-1-hsiangkao@linux.alibaba.com
2024-08-30 11:28:37 +08:00
|
|
|
}
|
|
|
|
|
|
2021-10-14 16:10:10 +08:00
|
|
|
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;
|
2025-03-10 17:54:53 +08:00
|
|
|
erofs_off_t startoff;
|
2021-10-14 16:10:10 +08:00
|
|
|
int id;
|
|
|
|
|
|
2024-12-13 07:54:01 +08:00
|
|
|
erofs_fill_from_devinfo(map, sb, &EROFS_SB(sb)->dif0);
|
2024-12-16 20:53:08 +08:00
|
|
|
map->m_bdev = sb->s_bdev; /* use s_bdev for the primary device */
|
2021-10-14 16:10:10 +08:00
|
|
|
if (map->m_deviceid) {
|
|
|
|
|
down_read(&devs->rwsem);
|
|
|
|
|
dif = idr_find(&devs->tree, map->m_deviceid - 1);
|
|
|
|
|
if (!dif) {
|
|
|
|
|
up_read(&devs->rwsem);
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
2023-03-02 15:17:51 +08:00
|
|
|
if (devs->flatdev) {
|
2025-03-10 17:54:53 +08:00
|
|
|
map->m_pa += erofs_pos(sb, dif->uniaddr);
|
2023-03-02 15:17:51 +08:00
|
|
|
up_read(&devs->rwsem);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-12-13 07:54:01 +08:00
|
|
|
erofs_fill_from_devinfo(map, sb, dif);
|
2021-10-14 16:10:10 +08:00
|
|
|
up_read(&devs->rwsem);
|
2023-03-02 15:17:51 +08:00
|
|
|
} else if (devs->extra_devices && !devs->flatdev) {
|
2021-10-14 16:10:10 +08:00
|
|
|
down_read(&devs->rwsem);
|
|
|
|
|
idr_for_each_entry(&devs->tree, dif, id) {
|
2025-03-10 17:54:53 +08:00
|
|
|
if (!dif->uniaddr)
|
2021-10-14 16:10:10 +08:00
|
|
|
continue;
|
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/cover.1723670362.git.josef@toxicpanda.com
Closes: https://github.com/containers/composefs/issues/144
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240830032840.3783206-1-hsiangkao@linux.alibaba.com
2024-08-30 11:28:37 +08:00
|
|
|
|
2025-03-10 17:54:53 +08:00
|
|
|
startoff = erofs_pos(sb, dif->uniaddr);
|
2021-10-14 16:10:10 +08:00
|
|
|
if (map->m_pa >= startoff &&
|
2025-03-10 17:54:53 +08:00
|
|
|
map->m_pa < startoff + erofs_pos(sb, dif->blocks)) {
|
2021-10-14 16:10:10 +08:00
|
|
|
map->m_pa -= startoff;
|
2024-12-13 07:54:01 +08:00
|
|
|
erofs_fill_from_devinfo(map, sb, dif);
|
2021-10-14 16:10:10 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
up_read(&devs->rwsem);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-05 17:30:31 +08:00
|
|
|
/*
|
|
|
|
|
* bit 30: I/O error occurred on this folio
|
2025-07-09 11:46:14 +08:00
|
|
|
* bit 29: CPU has dirty data in D-cache (needs aliasing handling);
|
2024-09-05 17:30:31 +08:00
|
|
|
* bit 0 - 29: remaining parts to complete this folio
|
|
|
|
|
*/
|
2025-07-09 11:46:14 +08:00
|
|
|
#define EROFS_ONLINEFOLIO_EIO 30
|
|
|
|
|
#define EROFS_ONLINEFOLIO_DIRTY 29
|
2024-09-05 17:30:31 +08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-09 11:46:14 +08:00
|
|
|
void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)
|
2024-09-05 17:30:31 +08:00
|
|
|
{
|
|
|
|
|
int orig, v;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
orig = atomic_read((atomic_t *)&folio->private);
|
2025-07-09 11:46:14 +08:00
|
|
|
DBG_BUGON(orig <= 0);
|
|
|
|
|
v = dirty << EROFS_ONLINEFOLIO_DIRTY;
|
|
|
|
|
v |= (orig - 1) | (!!err << EROFS_ONLINEFOLIO_EIO);
|
2024-09-05 17:30:31 +08:00
|
|
|
} while (atomic_cmpxchg((atomic_t *)&folio->private, orig, v) != orig);
|
|
|
|
|
|
2025-07-09 11:46:14 +08:00
|
|
|
if (v & (BIT(EROFS_ONLINEFOLIO_DIRTY) - 1))
|
2024-09-05 17:30:31 +08:00
|
|
|
return;
|
|
|
|
|
folio->private = 0;
|
2025-07-09 11:46:14 +08:00
|
|
|
if (v & BIT(EROFS_ONLINEFOLIO_DIRTY))
|
|
|
|
|
flush_dcache_folio(folio);
|
|
|
|
|
folio_end_read(folio, !(v & BIT(EROFS_ONLINEFOLIO_EIO)));
|
2024-09-05 17:30:31 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 10:28:48 +00:00
|
|
|
struct erofs_iomap_iter_ctx {
|
|
|
|
|
struct page *page;
|
|
|
|
|
void *base;
|
2026-01-23 01:31:30 +00:00
|
|
|
struct inode *realinode;
|
2026-01-09 10:28:48 +00:00
|
|
|
};
|
|
|
|
|
|
2021-08-05 08:35:59 +08:00
|
|
|
static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
|
|
|
|
|
unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
|
|
|
|
|
{
|
2026-01-09 10:28:48 +00:00
|
|
|
struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
|
|
|
|
|
struct erofs_iomap_iter_ctx *ctx = iter->private;
|
2026-01-23 01:31:30 +00:00
|
|
|
struct inode *realinode = ctx ? ctx->realinode : inode;
|
|
|
|
|
struct super_block *sb = realinode->i_sb;
|
2021-08-05 08:35:59 +08:00
|
|
|
struct erofs_map_blocks map;
|
2021-10-14 16:10:10 +08:00
|
|
|
struct erofs_map_dev mdev;
|
2026-01-09 10:28:48 +00:00
|
|
|
int ret;
|
2021-08-05 08:35:59 +08:00
|
|
|
|
|
|
|
|
map.m_la = offset;
|
|
|
|
|
map.m_llen = length;
|
2026-01-23 01:31:30 +00:00
|
|
|
ret = erofs_map_blocks(realinode, &map);
|
2021-08-05 08:35:59 +08:00
|
|
|
if (ret < 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2025-07-16 17:22:54 +08:00
|
|
|
iomap->offset = map.m_la;
|
|
|
|
|
iomap->length = map.m_llen;
|
|
|
|
|
iomap->flags = 0;
|
2025-07-22 08:32:29 +08:00
|
|
|
iomap->addr = IOMAP_NULL_ADDR;
|
2025-07-16 17:22:54 +08:00
|
|
|
if (!(map.m_flags & EROFS_MAP_MAPPED)) {
|
|
|
|
|
iomap->type = IOMAP_HOLE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 01:31:30 +00:00
|
|
|
if (!(map.m_flags & EROFS_MAP_META) || !erofs_inode_in_metabox(realinode)) {
|
2025-07-22 08:32:29 +08:00
|
|
|
mdev = (struct erofs_map_dev) {
|
|
|
|
|
.m_deviceid = map.m_deviceid,
|
|
|
|
|
.m_pa = map.m_pa,
|
|
|
|
|
};
|
|
|
|
|
ret = erofs_map_dev(sb, &mdev);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
2021-10-14 16:10:10 +08:00
|
|
|
|
2025-07-22 08:32:29 +08:00
|
|
|
if (flags & IOMAP_DAX)
|
|
|
|
|
iomap->dax_dev = mdev.m_dif->dax_dev;
|
|
|
|
|
else
|
|
|
|
|
iomap->bdev = mdev.m_bdev;
|
|
|
|
|
iomap->addr = mdev.m_dif->fsoff + mdev.m_pa;
|
|
|
|
|
if (flags & IOMAP_DAX)
|
|
|
|
|
iomap->addr += mdev.m_dif->dax_part_off;
|
|
|
|
|
}
|
2021-08-05 08:35:59 +08:00
|
|
|
|
|
|
|
|
if (map.m_flags & EROFS_MAP_META) {
|
2021-08-05 08:36:01 +08:00
|
|
|
iomap->type = IOMAP_INLINE;
|
2026-01-09 10:28:48 +00:00
|
|
|
/* read context should read the inlined data */
|
|
|
|
|
if (ctx) {
|
|
|
|
|
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
|
|
ptr = erofs_read_metabuf(&buf, sb, map.m_pa,
|
2026-01-23 01:31:30 +00:00
|
|
|
erofs_inode_in_metabox(realinode));
|
2026-01-09 10:28:48 +00:00
|
|
|
if (IS_ERR(ptr))
|
|
|
|
|
return PTR_ERR(ptr);
|
|
|
|
|
iomap->inline_data = ptr;
|
|
|
|
|
ctx->page = buf.page;
|
|
|
|
|
ctx->base = buf.base;
|
|
|
|
|
}
|
2021-08-05 08:36:01 +08:00
|
|
|
} else {
|
|
|
|
|
iomap->type = IOMAP_MAPPED;
|
2021-08-05 08:35:59 +08:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 08:36:01 +08:00
|
|
|
static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length,
|
|
|
|
|
ssize_t written, unsigned int flags, struct iomap *iomap)
|
|
|
|
|
{
|
2026-01-09 10:28:48 +00:00
|
|
|
struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
|
|
|
|
|
struct erofs_iomap_iter_ctx *ctx = iter->private;
|
2022-01-02 12:00:13 +08:00
|
|
|
|
2026-01-09 10:28:48 +00:00
|
|
|
if (ctx && ctx->base) {
|
2022-01-02 12:00:13 +08:00
|
|
|
struct erofs_buf buf = {
|
2026-01-09 10:28:48 +00:00
|
|
|
.page = ctx->page,
|
|
|
|
|
.base = ctx->base,
|
2022-01-02 12:00:13 +08:00
|
|
|
};
|
2021-08-05 08:36:01 +08:00
|
|
|
|
|
|
|
|
DBG_BUGON(iomap->type != IOMAP_INLINE);
|
2022-01-02 12:00:13 +08:00
|
|
|
erofs_put_metabuf(&buf);
|
2026-01-09 10:28:48 +00:00
|
|
|
ctx->base = NULL;
|
2021-08-05 08:36:01 +08:00
|
|
|
}
|
|
|
|
|
return written;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 08:35:59 +08:00
|
|
|
static const struct iomap_ops erofs_iomap_ops = {
|
|
|
|
|
.iomap_begin = erofs_iomap_begin,
|
2021-08-05 08:36:01 +08:00
|
|
|
.iomap_end = erofs_iomap_end,
|
2021-08-05 08:35:59 +08:00
|
|
|
};
|
|
|
|
|
|
2021-08-13 13:29:31 +08:00
|
|
|
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
|
|
|
|
u64 start, u64 len)
|
|
|
|
|
{
|
|
|
|
|
if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
|
2026-02-02 11:09:09 +08:00
|
|
|
if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP))
|
|
|
|
|
return -EOPNOTSUPP;
|
2021-08-13 13:29:31 +08:00
|
|
|
return iomap_fiemap(inode, fieinfo, start, len,
|
|
|
|
|
&z_erofs_iomap_report_ops);
|
|
|
|
|
}
|
|
|
|
|
return iomap_fiemap(inode, fieinfo, start, len, &erofs_iomap_ops);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 08:36:01 +08:00
|
|
|
/*
|
|
|
|
|
* since we dont have write or truncate flows, so no inode
|
|
|
|
|
* locking needs to be held at the moment.
|
|
|
|
|
*/
|
2022-04-29 08:54:32 -04:00
|
|
|
static int erofs_read_folio(struct file *file, struct folio *folio)
|
2021-08-05 08:36:01 +08:00
|
|
|
{
|
2026-01-09 10:28:48 +00:00
|
|
|
struct iomap_read_folio_ctx read_ctx = {
|
|
|
|
|
.ops = &iomap_bio_read_ops,
|
|
|
|
|
.cur_folio = folio,
|
|
|
|
|
};
|
2026-01-23 01:31:30 +00:00
|
|
|
bool need_iput;
|
|
|
|
|
struct erofs_iomap_iter_ctx iter_ctx = {
|
|
|
|
|
.realinode = erofs_real_inode(folio_inode(folio), &need_iput),
|
|
|
|
|
};
|
2025-07-08 19:19:42 +08:00
|
|
|
|
2026-01-23 01:31:30 +00:00
|
|
|
trace_erofs_read_folio(iter_ctx.realinode, folio, true);
|
2026-01-09 10:28:48 +00:00
|
|
|
iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx);
|
2026-01-23 01:31:30 +00:00
|
|
|
if (need_iput)
|
|
|
|
|
iput(iter_ctx.realinode);
|
2025-09-25 17:26:04 -07:00
|
|
|
return 0;
|
2021-08-05 08:36:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void erofs_readahead(struct readahead_control *rac)
|
|
|
|
|
{
|
2026-01-09 10:28:48 +00:00
|
|
|
struct iomap_read_folio_ctx read_ctx = {
|
|
|
|
|
.ops = &iomap_bio_read_ops,
|
|
|
|
|
.rac = rac,
|
|
|
|
|
};
|
2026-01-23 01:31:30 +00:00
|
|
|
bool need_iput;
|
|
|
|
|
struct erofs_iomap_iter_ctx iter_ctx = {
|
|
|
|
|
.realinode = erofs_real_inode(rac->mapping->host, &need_iput),
|
|
|
|
|
};
|
2025-07-07 16:48:32 +08:00
|
|
|
|
2026-01-23 01:31:30 +00:00
|
|
|
trace_erofs_readahead(iter_ctx.realinode, readahead_index(rac),
|
2026-01-23 01:31:29 +00:00
|
|
|
readahead_count(rac), true);
|
2026-01-09 10:28:48 +00:00
|
|
|
iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx);
|
2026-01-23 01:31:30 +00:00
|
|
|
if (need_iput)
|
|
|
|
|
iput(iter_ctx.realinode);
|
2021-08-05 08:36:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
|
|
|
|
|
{
|
|
|
|
|
return iomap_bmap(mapping, block, &erofs_iomap_ops);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 08:35:59 +08:00
|
|
|
static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
|
|
|
|
{
|
2022-07-20 16:22:29 +08:00
|
|
|
struct inode *inode = file_inode(iocb->ki_filp);
|
|
|
|
|
|
2021-08-05 08:35:59 +08:00
|
|
|
/* no need taking (shared) inode lock since it's a ro filesystem */
|
|
|
|
|
if (!iov_iter_count(to))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2026-02-02 11:09:09 +08:00
|
|
|
if (IS_ENABLED(CONFIG_FS_DAX) && IS_DAX(inode))
|
2021-08-05 08:36:00 +08:00
|
|
|
return dax_iomap_rw(iocb, to, &erofs_iomap_ops);
|
2026-02-02 11:09:09 +08:00
|
|
|
|
2026-01-09 10:28:48 +00:00
|
|
|
if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) {
|
2026-01-23 01:31:30 +00:00
|
|
|
struct erofs_iomap_iter_ctx iter_ctx = {
|
|
|
|
|
.realinode = inode,
|
|
|
|
|
};
|
2026-01-09 10:28:48 +00:00
|
|
|
|
2022-07-20 16:22:29 +08:00
|
|
|
return iomap_dio_rw(iocb, to, &erofs_iomap_ops,
|
2026-01-09 10:28:48 +00:00
|
|
|
NULL, 0, &iter_ctx, 0);
|
|
|
|
|
}
|
2021-08-05 08:35:59 +08:00
|
|
|
return filemap_read(iocb, to, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 20:21:47 +08:00
|
|
|
/* for uncompressed (aligned) files and raw access for other files */
|
2024-09-05 17:30:31 +08:00
|
|
|
const struct address_space_operations erofs_aops = {
|
2022-04-29 08:54:32 -04:00
|
|
|
.read_folio = erofs_read_folio,
|
2021-08-05 08:36:01 +08:00
|
|
|
.readahead = erofs_readahead,
|
2019-07-16 17:32:56 +08:00
|
|
|
.bmap = erofs_bmap,
|
2021-08-05 08:35:59 +08:00
|
|
|
.direct_IO = noop_direct_IO,
|
2022-11-30 14:04:55 +08:00
|
|
|
.release_folio = iomap_release_folio,
|
|
|
|
|
.invalidate_folio = iomap_invalidate_folio,
|
2021-08-05 08:35:59 +08:00
|
|
|
};
|
|
|
|
|
|
2021-08-05 08:36:00 +08:00
|
|
|
#ifdef CONFIG_FS_DAX
|
|
|
|
|
static vm_fault_t erofs_dax_huge_fault(struct vm_fault *vmf,
|
2023-08-18 21:23:35 +01:00
|
|
|
unsigned int order)
|
2021-08-05 08:36:00 +08:00
|
|
|
{
|
2023-08-18 21:23:35 +01:00
|
|
|
return dax_iomap_fault(vmf, order, NULL, NULL, &erofs_iomap_ops);
|
2021-08-05 08:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vm_fault_t erofs_dax_fault(struct vm_fault *vmf)
|
|
|
|
|
{
|
2023-08-18 21:23:35 +01:00
|
|
|
return erofs_dax_huge_fault(vmf, 0);
|
2021-08-05 08:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct vm_operations_struct erofs_dax_vm_ops = {
|
|
|
|
|
.fault = erofs_dax_fault,
|
|
|
|
|
.huge_fault = erofs_dax_huge_fault,
|
|
|
|
|
};
|
|
|
|
|
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
static int erofs_file_mmap_prepare(struct vm_area_desc *desc)
|
2021-08-05 08:36:00 +08:00
|
|
|
{
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
if (!IS_DAX(file_inode(desc->file)))
|
|
|
|
|
return generic_file_readonly_mmap_prepare(desc);
|
2021-08-05 08:36:00 +08:00
|
|
|
|
2026-01-22 16:06:18 +00:00
|
|
|
if (vma_desc_test_flags(desc, VMA_SHARED_BIT) &&
|
|
|
|
|
vma_desc_test_flags(desc, VMA_MAYWRITE_BIT))
|
2021-08-05 08:36:00 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
desc->vm_ops = &erofs_dax_vm_ops;
|
2026-01-22 16:06:18 +00:00
|
|
|
vma_desc_set_flags(desc, VMA_HUGEPAGE_BIT);
|
2021-08-05 08:36:00 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
#define erofs_file_mmap_prepare generic_file_readonly_mmap_prepare
|
2021-08-05 08:36:00 +08:00
|
|
|
#endif
|
|
|
|
|
|
2024-10-11 14:51:28 +08:00
|
|
|
static loff_t erofs_file_llseek(struct file *file, loff_t offset, int whence)
|
|
|
|
|
{
|
|
|
|
|
struct inode *inode = file->f_mapping->host;
|
|
|
|
|
const struct iomap_ops *ops = &erofs_iomap_ops;
|
|
|
|
|
|
2026-02-02 11:09:09 +08:00
|
|
|
if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
|
|
|
|
|
if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP))
|
|
|
|
|
return generic_file_llseek(file, offset, whence);
|
2024-10-11 14:51:28 +08:00
|
|
|
ops = &z_erofs_iomap_report_ops;
|
2026-02-02 11:09:09 +08:00
|
|
|
}
|
2024-10-11 14:51:28 +08:00
|
|
|
|
|
|
|
|
if (whence == SEEK_HOLE)
|
|
|
|
|
offset = iomap_seek_hole(inode, offset, ops);
|
|
|
|
|
else if (whence == SEEK_DATA)
|
|
|
|
|
offset = iomap_seek_data(inode, offset, ops);
|
|
|
|
|
else
|
|
|
|
|
return generic_file_llseek(file, offset, whence);
|
|
|
|
|
|
|
|
|
|
if (offset < 0)
|
|
|
|
|
return offset;
|
|
|
|
|
return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 08:35:59 +08:00
|
|
|
const struct file_operations erofs_file_fops = {
|
2024-10-11 14:51:28 +08:00
|
|
|
.llseek = erofs_file_llseek,
|
2021-08-05 08:35:59 +08:00
|
|
|
.read_iter = erofs_file_read_iter,
|
2025-09-23 15:01:12 +08:00
|
|
|
.unlocked_ioctl = erofs_ioctl,
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
|
.compat_ioctl = erofs_compat_ioctl,
|
|
|
|
|
#endif
|
fs: convert most other generic_file_*mmap() users to .mmap_prepare()
Update nearly all generic_file_mmap() and generic_file_readonly_mmap()
callers to use generic_file_mmap_prepare() and
generic_file_readonly_mmap_prepare() respectively.
We update blkdev, 9p, afs, erofs, ext2, nfs, ntfs3, smb, ubifs and vboxsf
file systems this way.
Remaining users we cannot yet update are ecryptfs, fuse and cramfs. The
former two are nested file systems that must support any underlying file
ssytem, and cramfs inserts a mixed mapping which currently requires a VMA.
Once all file systems have been converted to mmap_prepare(), we can then
update nested file systems.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/08db85970d89b17a995d2cffae96fb4cc462377f.1750099179.git.lorenzo.stoakes@oracle.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-06-16 20:33:28 +01:00
|
|
|
.mmap_prepare = erofs_file_mmap_prepare,
|
2024-03-06 13:31:38 +08:00
|
|
|
.get_unmapped_area = thp_get_unmapped_area,
|
2023-05-22 14:50:15 +01:00
|
|
|
.splice_read = filemap_splice_read,
|
2026-01-08 12:12:59 -05:00
|
|
|
.setlease = generic_setlease,
|
2018-07-26 20:21:47 +08:00
|
|
|
};
|