Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
d76bb1e
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
9p
adfs
affs
afs
autofs
bcachefs
befs
bfs
btrfs
cachefiles
ceph
coda
configfs
cramfs
crypto
debugfs
devpts
dlm
ecryptfs
efivarfs
efs
erofs
Kconfig
Makefile
compress.h
data.c
decompressor.c
decompressor_deflate.c
decompressor_lzma.c
decompressor_zstd.c
dir.c
erofs_fs.h
fileio.c
fscache.c
inode.c
internal.h
namei.c
super.c
sysfs.c
xattr.c
xattr.h
zdata.c
zmap.c
zutil.c
exfat
exportfs
ext2
ext4
f2fs
fat
freevxfs
fuse
gfs2
hfs
hfsplus
hostfs
hpfs
hugetlbfs
iomap
isofs
jbd2
jffs2
jfs
kernfs
lockd
minix
netfs
nfs
nfs_common
nfsd
nilfs2
nls
notify
ntfs3
ocfs2
omfs
openpromfs
orangefs
overlayfs
proc
pstore
qnx4
qnx6
quota
ramfs
romfs
smb
squashfs
sysfs
tests
tracefs
ubifs
udf
ufs
unicode
vboxsf
verity
xfs
zonefs
Kconfig
Kconfig.binfmt
Makefile
aio.c
anon_inodes.c
attr.c
backing-file.c
bad_inode.c
binfmt_elf.c
binfmt_elf_fdpic.c
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
bpf_fs_kfuncs.c
buffer.c
char_dev.c
compat_binfmt_elf.c
coredump.c
d_path.c
dax.c
dcache.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c
fcntl.c
fhandle.c
file.c
file_table.c
filesystems.c
fs-writeback.c
fs_context.c
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fsopen.c
init.c
inode.c
internal.h
ioctl.c
kernel_read_file.c
libfs.c
locks.c
mbcache.c
mnt_idmapping.c
mount.h
mpage.c
namei.c
namespace.c
nsfs.c
open.c
pidfs.c
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
remap_range.c
select.c
seq_file.c
signalfd.c
splice.c
stack.c
stat.c
statfs.c
super.c
sync.c
sysctls.c
timerfd.c
userfaultfd.c
utimes.c
xattr.c
include
init
io_uring
ipc
kernel
lib
mm
net
rust
samples
scripts
security
sound
tools
usr
virt
.clang-format
.clippy.toml
.cocciconfig
.editorconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
fs
/
erofs
/
fileio.c
Blame
Blame
Latest commit
Max Kellermann
and
Gao Xiang
fs/erofs/fileio: call erofs_onlinefolio_split() after bio_add_folio()
Apr 29, 2025
bbfe756
·
Apr 29, 2025
History
History
197 lines (177 loc) · 5.01 KB
Breadcrumbs
linux
/
fs
/
erofs
/
fileio.c
Top
File metadata and controls
Code
Blame
197 lines (177 loc) · 5.01 KB
Raw
// 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[16]; struct bio bio; struct kiocb iocb; struct super_block *sb; }; 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; if (ret > 0) { if (ret != rq->bio.bi_iter.bi_size) { bio_advance(&rq->bio, ret); zero_fill_bio(&rq->bio); } ret = 0; } if (rq->bio.bi_end_io) { if (ret < 0 && !rq->bio.bi_status) rq->bio.bi_status = errno_to_blk_status(ret); 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); } } bio_uninit(&rq->bio); 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 << SECTOR_SHIFT; rq->iocb.ki_ioprio = get_current_ioprio(); rq->iocb.ki_complete = erofs_fileio_ki_complete; if (test_opt(&EROFS_SB(rq->sb)->opt, DIRECT_IO) && rq->iocb.ki_filp->f_mode & FMODE_CAN_ODIRECT) rq->iocb.ki_flags = IOCB_DIRECT; 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 | __GFP_NOFAIL); bio_init(&rq->bio, NULL, rq->bvecs, ARRAY_SIZE(rq->bvecs), REQ_OP_READ); rq->iocb.ki_filp = mdev->m_dif->file; rq->sb = mdev->m_sb; return rq; } struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev) { return &erofs_fileio_rq_alloc(mdev)->bio; } 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); 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, true); 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); attached = 0; } 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); io->rq->bio.bi_iter.bi_sector = io->dev.m_pa >> 9; attached = 0; } if (!bio_add_folio(&io->rq->bio, folio, len, cur)) goto io_retry; if (!attached++) erofs_onlinefolio_split(folio); 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, true); 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), true); 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, };
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
You can’t perform that action at this time.