Commit 8b00be16 authored by Gao Xiang's avatar Gao Xiang

erofs: simplify z_erofs_read_fragment()

A trivial cleanup to make the fragment handling logic more clear.
Reviewed-by: default avatarYue Hu <huyue2@coolpad.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230817082813.81180-1-hsiangkao@linux.alibaba.com
parent d442495c
...@@ -932,34 +932,27 @@ static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe) ...@@ -932,34 +932,27 @@ static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe)
return true; return true;
} }
static int z_erofs_read_fragment(struct inode *inode, erofs_off_t pos, static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
struct page *page, unsigned int pageofs, unsigned int cur, unsigned int end, erofs_off_t pos)
unsigned int len)
{ {
struct super_block *sb = inode->i_sb; struct inode *packed_inode = EROFS_SB(sb)->packed_inode;
struct inode *packed_inode = EROFS_I_SB(inode)->packed_inode;
struct erofs_buf buf = __EROFS_BUF_INITIALIZER; struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
u8 *src, *dst; unsigned int cnt;
unsigned int i, cnt; u8 *src;
if (!packed_inode) if (!packed_inode)
return -EFSCORRUPTED; return -EFSCORRUPTED;
buf.inode = packed_inode; buf.inode = packed_inode;
pos += EROFS_I(inode)->z_fragmentoff; for (; cur < end; cur += cnt, pos += cnt) {
for (i = 0; i < len; i += cnt) { cnt = min_t(unsigned int, end - cur,
cnt = min_t(unsigned int, len - i,
sb->s_blocksize - erofs_blkoff(sb, pos)); sb->s_blocksize - erofs_blkoff(sb, pos));
src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP); src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP);
if (IS_ERR(src)) { if (IS_ERR(src)) {
erofs_put_metabuf(&buf); erofs_put_metabuf(&buf);
return PTR_ERR(src); return PTR_ERR(src);
} }
memcpy_to_page(page, cur, src + erofs_blkoff(sb, pos), cnt);
dst = kmap_local_page(page);
memcpy(dst + pageofs + i, src + erofs_blkoff(sb, pos), cnt);
kunmap_local(dst);
pos += cnt;
} }
erofs_put_metabuf(&buf); erofs_put_metabuf(&buf);
return 0; return 0;
...@@ -972,7 +965,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, ...@@ -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; struct erofs_map_blocks *const map = &fe->map;
const loff_t offset = page_offset(page); const loff_t offset = page_offset(page);
bool tight = true, exclusive; bool tight = true, exclusive;
unsigned int cur, end, spiltted; unsigned int cur, end, len, spiltted;
int err = 0; int err = 0;
/* register locked file pages as online pages in pack */ /* 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, ...@@ -1041,17 +1034,11 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
goto next_part; goto next_part;
} }
if (map->m_flags & EROFS_MAP_FRAGMENT) { 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) { len = min_t(unsigned int, map->m_llen - fpos, end - cur);
pageofs = 0; err = z_erofs_read_fragment(inode->i_sb, page, cur, cur + len,
skip = offset - map->m_la; EROFS_I(inode)->z_fragmentoff + fpos);
} 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);
if (err) if (err)
goto out; goto out;
++spiltted; ++spiltted;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment