mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-06 05:06:29 +00:00
erofs: simplify z_erofs_read_fragment()
A trivial cleanup to make the fragment handling logic more clear. Reviewed-by: Yue Hu <huyue2@coolpad.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230817082813.81180-1-hsiangkao@linux.alibaba.com
This commit is contained in:
parent
d442495c96
commit
8b00be163f
@ -932,34 +932,27 @@ static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int z_erofs_read_fragment(struct inode *inode, erofs_off_t pos,
|
||||
struct page *page, unsigned int pageofs,
|
||||
unsigned int len)
|
||||
static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
|
||||
unsigned int cur, unsigned int end, erofs_off_t pos)
|
||||
{
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct inode *packed_inode = EROFS_I_SB(inode)->packed_inode;
|
||||
struct inode *packed_inode = EROFS_SB(sb)->packed_inode;
|
||||
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
|
||||
u8 *src, *dst;
|
||||
unsigned int i, cnt;
|
||||
unsigned int cnt;
|
||||
u8 *src;
|
||||
|
||||
if (!packed_inode)
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
buf.inode = packed_inode;
|
||||
pos += EROFS_I(inode)->z_fragmentoff;
|
||||
for (i = 0; i < len; i += cnt) {
|
||||
cnt = min_t(unsigned int, len - i,
|
||||
for (; cur < end; cur += cnt, pos += cnt) {
|
||||
cnt = min_t(unsigned int, end - cur,
|
||||
sb->s_blocksize - erofs_blkoff(sb, pos));
|
||||
src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP);
|
||||
if (IS_ERR(src)) {
|
||||
erofs_put_metabuf(&buf);
|
||||
return PTR_ERR(src);
|
||||
}
|
||||
|
||||
dst = kmap_local_page(page);
|
||||
memcpy(dst + pageofs + i, src + erofs_blkoff(sb, pos), cnt);
|
||||
kunmap_local(dst);
|
||||
pos += cnt;
|
||||
memcpy_to_page(page, cur, src + erofs_blkoff(sb, pos), cnt);
|
||||
}
|
||||
erofs_put_metabuf(&buf);
|
||||
return 0;
|
||||
@ -972,7 +965,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
|
||||
struct erofs_map_blocks *const map = &fe->map;
|
||||
const loff_t offset = page_offset(page);
|
||||
bool tight = true, exclusive;
|
||||
unsigned int cur, end, spiltted;
|
||||
unsigned int cur, end, len, spiltted;
|
||||
int err = 0;
|
||||
|
||||
/* register locked file pages as online pages in pack */
|
||||
@ -1041,17 +1034,11 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
|
||||
goto next_part;
|
||||
}
|
||||
if (map->m_flags & EROFS_MAP_FRAGMENT) {
|
||||
unsigned int pageofs, skip, len;
|
||||
erofs_off_t fpos = offset + cur - map->m_la;
|
||||
|
||||
if (offset > map->m_la) {
|
||||
pageofs = 0;
|
||||
skip = offset - map->m_la;
|
||||
} else {
|
||||
pageofs = map->m_la & ~PAGE_MASK;
|
||||
skip = 0;
|
||||
}
|
||||
len = min_t(unsigned int, map->m_llen - skip, end - cur);
|
||||
err = z_erofs_read_fragment(inode, skip, page, pageofs, len);
|
||||
len = min_t(unsigned int, map->m_llen - fpos, end - cur);
|
||||
err = z_erofs_read_fragment(inode->i_sb, page, cur, cur + len,
|
||||
EROFS_I(inode)->z_fragmentoff + fpos);
|
||||
if (err)
|
||||
goto out;
|
||||
++spiltted;
|
||||
|
Loading…
Reference in New Issue
Block a user